Skip to content

Commit

Permalink
Fix depth precision issue with Metal by not let binding entire instan…
Browse files Browse the repository at this point in the history
…ce struct.
  • Loading branch information
komadori committed Aug 3, 2024
1 parent 2f371ce commit f644e86
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/outline.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn model_origin_z(plane: vec3<f32>, view_proj: mat4x4<f32>) -> f32 {

@vertex
fn vertex(vertex_no_morph: Vertex) -> VertexOutput {
let instance = mesh[vertex_no_morph.instance_index];
let iid = vertex_no_morph.instance_index;
#ifdef MORPH_TARGETS
var vertex = morph_vertex(vertex_no_morph);
#else
Expand All @@ -84,13 +84,13 @@ fn vertex(vertex_no_morph: Vertex) -> VertexOutput {
#ifdef SKINNED
let model = bevy_pbr::skinning::skin_model(vertex.joint_indices, vertex.joint_weights);
#else
let model = bevy_render::maths::affine3_to_square(instance.world_from_local);
let model = bevy_render::maths::affine3_to_square(mesh[iid].world_from_local);
#endif
let clip_pos = view_uniform.clip_from_world * (model * vec4<f32>(vertex.position, 1.0));
#ifdef VOLUME
let offset = instance.volume_offset;
let offset = mesh[iid].volume_offset;
#else
let offset = instance.stencil_offset;
let offset = mesh[iid].stencil_offset;
#endif
#ifdef OFFSET_ZERO
let out_xy = clip_pos.xy;
Expand All @@ -102,10 +102,10 @@ fn vertex(vertex_no_morph: Vertex) -> VertexOutput {
var out: VertexOutput;
out.position = vec4<f32>(out_xy, clip_pos.zw);
#ifdef FLAT_DEPTH
out.flat_depth = model_origin_z(instance.origin_in_world, view_uniform.clip_from_world);
out.flat_depth = model_origin_z(mesh[iid].origin_in_world, view_uniform.clip_from_world);
#endif
#ifdef VOLUME
out.volume_colour = instance.volume_colour;
out.volume_colour = mesh[iid].volume_colour;
#endif
return out;
}

0 comments on commit f644e86

Please sign in to comment.