55 mesh_bindings :: mesh
66}
77
8- fn sample_depth_map (uv : vec2 <f32 >, instance_index : u32 ) -> f32 {
9- let slot = mesh [instance_index ]. material_and_lightmap_bind_group_slot & 0xffffu ;
8+ fn sample_depth_map (uv : vec2 <f32 >, material_bind_group_slot : u32 ) -> f32 {
109 // We use `textureSampleLevel` over `textureSample` because the wgpu DX12
1110 // backend (Fxc) panics when using "gradient instructions" inside a loop.
1211 // It results in the whole loop being unrolled by the shader compiler,
@@ -19,8 +18,8 @@ fn sample_depth_map(uv: vec2<f32>, instance_index: u32) -> f32 {
1918 // See https://stackoverflow.com/questions/56581141/direct3d11-gradient-instruction-used-in-a-loop-with-varying-iteration-forcing
2019 return textureSampleLevel (
2120#ifdef BINDLESS
22- depth_map_texture [slot ],
23- depth_map_sampler [slot ],
21+ depth_map_texture [material_bind_group_slot ],
22+ depth_map_sampler [material_bind_group_slot ],
2423#else // BINDLESS
2524 depth_map_texture ,
2625 depth_map_sampler ,
@@ -40,7 +39,7 @@ fn parallaxed_uv(
4039 original_uv : vec2 <f32 >,
4140 // The vector from the camera to the fragment at the surface in tangent space
4241 Vt : vec3 <f32 >,
43- instance_index : u32 ,
42+ material_bind_group_slot : u32 ,
4443) -> vec2 <f32 > {
4544 if max_layer_count < 1 .0 {
4645 return original_uv ;
@@ -68,15 +67,15 @@ fn parallaxed_uv(
6867 var delta_uv = depth_scale * layer_depth * Vt . xy * vec2 (1 .0 , - 1 .0 ) / view_steepness ;
6968
7069 var current_layer_depth = 0 .0 ;
71- var texture_depth = sample_depth_map (uv , instance_index );
70+ var texture_depth = sample_depth_map (uv , material_bind_group_slot );
7271
7372 // texture_depth > current_layer_depth means the depth map depth is deeper
7473 // than the depth the ray would be at this UV offset so the ray has not
7574 // intersected the surface
7675 for (var i : i32 = 0 ; texture_depth > current_layer_depth && i <= i32 (layer_count ); i ++ ) {
7776 current_layer_depth += layer_depth ;
7877 uv += delta_uv ;
79- texture_depth = sample_depth_map (uv , instance_index );
78+ texture_depth = sample_depth_map (uv , material_bind_group_slot );
8079 }
8180
8281#ifdef RELIEF_MAPPING
@@ -94,7 +93,7 @@ fn parallaxed_uv(
9493 current_layer_depth -= delta_depth ;
9594
9695 for (var i : u32 = 0u ; i < max_steps ; i ++ ) {
97- texture_depth = sample_depth_map (uv , instance_index );
96+ texture_depth = sample_depth_map (uv , material_bind_group_slot );
9897
9998 // Halve the deltas for the next step
10099 delta_uv *= 0 .5 ;
@@ -118,7 +117,8 @@ fn parallaxed_uv(
118117 // may skip small details and result in writhing material artifacts.
119118 let previous_uv = uv - delta_uv ;
120119 let next_depth = texture_depth - current_layer_depth ;
121- let previous_depth = sample_depth_map (previous_uv , instance_index ) - current_layer_depth + layer_depth ;
120+ let previous_depth = sample_depth_map (previous_uv , material_bind_group_slot ) -
121+ current_layer_depth + layer_depth ;
122122
123123 let weight = next_depth / (next_depth - previous_depth );
124124
0 commit comments