diff --git a/examples/Animometer.cpp b/examples/Animometer.cpp index 4af226119f..616eb3dddd 100644 --- a/examples/Animometer.cpp +++ b/examples/Animometer.cpp @@ -56,51 +56,56 @@ void init() { 640, 480); wgpu::ShaderModule vsModule = - utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( - #version 450 + utils::CreateShaderModuleFromWGSL(device, R"( + [[block]] struct Constants { + scale : f32; + time : f32; + offsetX : f32; + offsetY : f32; + scalar : f32; + scalarOffset : f32; + }; + [[set(0), binding(0)]] var c : Constants; - layout(std140, set = 0, binding = 0) uniform Constants { - float scale; - float time; - float offsetX; - float offsetY; - float scalar; - float scalarOffset; - } c; + [[location(0)]] var v_color : vec4; + [[builtin(vertex_idx)]] var VertexIndex : u32; + [[builtin(position)]] var Position : vec4; - layout(location = 0) out vec4 v_color; + [[stage(vertex)]] fn main() -> void { + var positions : array, 3> = array, 3>( + vec4( 0.0, 0.1, 0.0, 1.0), + vec4(-0.1, -0.1, 0.0, 1.0), + vec4( 0.1, -0.1, 0.0, 1.0) + ); - const vec4 positions[3] = vec4[3]( - vec4( 0.0f, 0.1f, 0.0f, 1.0f), - vec4(-0.1f, -0.1f, 0.0f, 1.0f), - vec4( 0.1f, -0.1f, 0.0f, 1.0f) - ); + var colors : array, 3> = array, 3>( + vec4(1.0, 0.0, 0.0, 1.0), + vec4(0.0, 1.0, 0.0, 1.0), + vec4(0.0, 0.0, 1.0, 1.0) + ); - const vec4 colors[3] = vec4[3]( - vec4(1.0f, 0.0f, 0.0f, 1.0f), - vec4(0.0f, 1.0f, 0.0f, 1.0f), - vec4(0.0f, 0.0f, 1.0f, 1.0f) - ); + var position : vec4 = positions[VertexIndex]; + var color : vec4 = colors[VertexIndex]; - void main() { - vec4 position = positions[gl_VertexIndex]; - vec4 color = colors[gl_VertexIndex]; - - float fade = mod(c.scalarOffset + c.time * c.scalar / 10.0, 1.0); + // TODO(dawn:572): Revisit once modf has been reworked in WGSL. + var fade : f32 = c.scalarOffset + c.time * c.scalar / 10.0; + fade = fade - floor(fade); if (fade < 0.5) { fade = fade * 2.0; } else { fade = (1.0 - fade) * 2.0; } - float xpos = position.x * c.scale; - float ypos = position.y * c.scale; - float angle = 3.14159 * 2.0 * fade; - float xrot = xpos * cos(angle) - ypos * sin(angle); - float yrot = xpos * sin(angle) + ypos * cos(angle); + + var xpos : f32 = position.x * c.scale; + var ypos : f32 = position.y * c.scale; + const angle : f32 = 3.14159 * 2.0 * fade; + const xrot : f32 = xpos * cos(angle) - ypos * sin(angle); + const yrot : f32 = xpos * sin(angle) + ypos * cos(angle); xpos = xrot + c.offsetX; ypos = yrot + c.offsetY; - v_color = vec4(fade, 1.0 - fade, 0.0, 1.0) + color; - gl_Position = vec4(xpos, ypos, 0.0, 1.0); + + v_color = vec4(fade, 1.0 - fade, 0.0, 1.0) + color; + Position = vec4(xpos, ypos, 0.0, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"( @@ -109,7 +114,6 @@ void init() { [[stage(fragment)]] fn main() -> void { FragColor = v_color; - return; })"); wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(