const std = @import("std"); const sketchbook = @import("sketchbook"); /// The Book of Shaders examples, each written twice: `shaders/zig/.zig` /// and `shaders/glsl/.frag`. const examples = [_][]const u8{ "expo", "hsb_wheel", "polar", "truchet", "clouds" }; pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const sb = sketchbook.init(b, .{ .target = target, .optimize = optimize }); const uniforms = b.createModule(.{ .root_source_file = b.path("src/uniforms.zig") }); var glsl_sources: std.ArrayList(std.Build.LazyPath) = .empty; var zig_sources: std.ArrayList(std.Build.LazyPath) = .empty; glsl_sources.append(b.graph.arena, b.path("shaders/glsl/fullscreen.vert")) catch @panic("OOM"); zig_sources.append(b.graph.arena, b.path("shaders/zig/fullscreen.zig")) catch @panic("OOM"); for (examples) |name| { glsl_sources.append(b.graph.arena, b.path(b.fmt("shaders/glsl/{s}.frag", .{name}))) catch @panic("OOM"); zig_sources.append(b.graph.arena, b.path(b.fmt("shaders/zig/{s}.zig", .{name}))) catch @panic("OOM"); } const glsl = sb.addShaders(.{ .layouts = .{ .module = uniforms, .types = &.{"Uniforms"} }, .sources = glsl_sources.items }); const gl = b.createModule(.{ .root_source_file = b.path("shaders/zig/gl.zig"), .imports = &.{.{ .name = "uniforms", .module = uniforms }} }); const zig = sb.addZigShaders(.{ .sources = zig_sources.items, .imports = &.{.{ .name = "gl", .module = gl }} }); const app = sb.app(.{ .name = "shaders", .root_source_file = b.path("src/main.zig"), .imports = &.{ .{ .name = "uniforms", .module = uniforms }, .{ .name = "glsl_shaders", .module = glsl.module }, .{ .name = "zig_shaders", .module = zig.module }, } }); const steps = app.addSteps(.{ .web = .{}, .scripts = &.{ b.path("test/shaders.script"), b.path("test/timeline.script") } }); // Hot reload keeps State through an edit of each kind: a Zig shader, a // GLSL shader, and the sketch's own Zig code. const reload = app.addReloadCheck(.{ .script = b.path("test/reload.script"), .edits = &.{ .{ .file = "shaders/zig/expo.zig", .old = ".{ 0, 1, 0 }", .new = ".{ 1, 0, 0 }" }, .{ .file = "shaders/glsl/expo.frag", .old = "vec3(0.0, 1.0, 0.0)", .new = "vec3(1.0, 0.0, 0.0)" }, .{ .file = "src/main.zig", .old = "0xff8040", .new = "0x40c0ff" }, } }); steps.e2e.dependOn(&reload.run.step); }