Minor edits

master
Mark 2024-01-21 12:49:20 -08:00
parent 64f930b391
commit d09158a324
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
1 changed files with 28 additions and 12 deletions

View File

@ -33,12 +33,12 @@ var sampler_array: binding_array<sampler>;
// INCLUDE: anchor.wgsl // INCLUDE: anchor.wgsl
@vertex
fn vertex_main(
vertex: VertexInput,
instance: InstanceInput,
) -> VertexOutput {
fn transform_vertex(
instance: InstanceInput,
vertex_position: vec3<f32>,
texture_index: u32,
) -> vec4<f32> {
let window_dim = global_data.window_size / global_data.window_scale.x; let window_dim = global_data.window_size / global_data.window_scale.x;
let scale = instance.size / window_dim.y; let scale = instance.size / window_dim.y;
@ -50,8 +50,8 @@ fn vertex_main(
// Apply scale and sprite aspect // Apply scale and sprite aspect
// Note that our mesh starts centered at (0, 0). This is important! // Note that our mesh starts centered at (0, 0). This is important!
var pos: vec2<f32> = vec2( var pos: vec2<f32> = vec2(
vertex.position.x * scale * aspect, vertex_position.x * scale * aspect,
vertex.position.y * scale vertex_position.y * scale
); );
// Apply rotation (and adjust sprite angle, since sprites point north) // Apply rotation (and adjust sprite angle, since sprites point north)
@ -72,10 +72,27 @@ fn vertex_main(
vec2(instance.size * aspect, instance.size) vec2(instance.size * aspect, instance.size)
); );
var out: VertexOutput; return vec4<f32>(pos, 0.0, 1.0);
out.position = vec4<f32>(pos, 1.0, 1.0); }
out.color_transform = instance.color_transform;
@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 // TODO: function to get texture from sprite
@ -108,7 +125,6 @@ fn vertex_main(
out.mask_index = vec2(0u, 0u); out.mask_index = vec2(0u, 0u);
} }
return out; return out;
} }