Minor shader fixes

master
Mark 2024-01-13 18:57:02 -08:00
parent ac4eb7d67d
commit 45e3513ed3
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
2 changed files with 12 additions and 6 deletions

View File

@ -30,7 +30,10 @@ var sampler_array: binding_array<sampler>;
fn transform_vertex(obj: ObjectData, vertex_position: vec2<f32>, sprite_index: u32) -> vec4<f32> { fn transform_vertex(obj: ObjectData, vertex_position: vec2<f32>, sprite_index: u32) -> vec4<f32> {
// Object scale // Object scale
let scale = obj.size / (global_data.camera_zoom.x * obj.zpos); var scale: f32 = obj.size / (global_data.camera_zoom.x * obj.zpos);
if obj.is_child == 1u {
scale /= objects[obj.parent].zpos;
}
// 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!
@ -70,14 +73,15 @@ fn transform_vertex(obj: ObjectData, vertex_position: vec2<f32>, sprite_index: u
} }
if obj.is_child == u32(1) { if obj.is_child == u32(1) {
let parent = objects[obj.parent];
// Apply translation relative to parent // Apply translation relative to parent
// Note that obj.zpos is ignored // Note that obj.zpos is ignored
pos = pos + vec2( pos = pos + vec2(
obj.xpos / (global_data.camera_zoom.x / 2.0) / global_data.window_aspect.x, obj.xpos / (global_data.camera_zoom.x / 2.0) / global_data.window_aspect.x,
obj.ypos / (global_data.camera_zoom.x / 2.0) obj.ypos / (global_data.camera_zoom.x / 2.0)
); ) / parent.zpos;
let parent = objects[obj.parent];
// Apply parent's rotation // Apply parent's rotation
pos = mat2x2( pos = mat2x2(

View File

@ -66,9 +66,11 @@ fn vertex_main(
vertex.position.x * scale * global_sprites[instance.sprite_index].aspect, vertex.position.x * scale * global_sprites[instance.sprite_index].aspect,
vertex.position.y * scale vertex.position.y * scale
); );
// Correct angle, since sprites point north and zero degrees is east
pos = mat2x2( pos = mat2x2(
vec2(cos(angle), sin(angle)), vec2(cos(angle - 1.5708), sin(angle - 1.5708)),
vec2(-sin(angle), cos(angle)) vec2(-sin(angle - 1.5708), cos(angle - 1.5708))
) * pos; ) * pos;
var trans: vec2<f32> = (instance.position + (instance.velocity * age) - global_data.camera_position); var trans: vec2<f32> = (instance.position + (instance.velocity * age) - global_data.camera_position);