From d09158a324b2542510b7d73610150737f33343a2 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 21 Jan 2024 12:49:20 -0800 Subject: [PATCH] Minor edits --- crates/render/shaders/ui.wgsl | 40 ++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/crates/render/shaders/ui.wgsl b/crates/render/shaders/ui.wgsl index 898f0aa..5c36d3e 100644 --- a/crates/render/shaders/ui.wgsl +++ b/crates/render/shaders/ui.wgsl @@ -33,13 +33,13 @@ var sampler_array: binding_array; // INCLUDE: anchor.wgsl -@vertex -fn vertex_main( - vertex: VertexInput, + +fn transform_vertex( instance: InstanceInput, -) -> VertexOutput { - - + vertex_position: vec3, + texture_index: u32, +) -> vec4 { + let window_dim = global_data.window_size / global_data.window_scale.x; let scale = instance.size / window_dim.y; let aspect = ( @@ -50,8 +50,8 @@ fn vertex_main( // Apply scale and sprite aspect // Note that our mesh starts centered at (0, 0). This is important! var pos: vec2 = vec2( - vertex.position.x * scale * aspect, - vertex.position.y * scale + vertex_position.x * scale * aspect, + vertex_position.y * scale ); // Apply rotation (and adjust sprite angle, since sprites point north) @@ -72,10 +72,27 @@ fn vertex_main( vec2(instance.size * aspect, instance.size) ); - var out: VertexOutput; - out.position = vec4(pos, 1.0, 1.0); - out.color_transform = instance.color_transform; + return vec4(pos, 0.0, 1.0); +} +@vertex +fn vertex_main( + vertex: VertexInput, + instance: InstanceInput, +) -> VertexOutput { + + // TODO: this will break if we try to use texture 0. + // implement animations for ui sprites & fix that here. + + let pos = transform_vertex( + instance, + vertex.position, + instance.texture_index.x, + ); + + var out: VertexOutput; + out.position = pos; + out.color_transform = instance.color_transform; // TODO: function to get texture from sprite @@ -108,7 +125,6 @@ fn vertex_main( out.mask_index = vec2(0u, 0u); } - return out; }