Z prepass
This commit is contained in:
+14
-2
@@ -6,7 +6,8 @@ struct VertexOutput
|
||||
@location(2) cam_pos: vec3<f32>,
|
||||
@location(3) world_pos: vec3<f32>,
|
||||
@location(4) @interpolate(flat) structure_id: u32,
|
||||
@location(5) chunk_position: vec3<f32>
|
||||
@location(5) chunk_position: vec3<f32>,
|
||||
@location(6) ndc: vec4<f32>
|
||||
}
|
||||
|
||||
struct ChunkImmediate
|
||||
@@ -123,6 +124,7 @@ fn chunk(@builtin(vertex_index) index: u32, @location(0) position: vec3<f32>, @l
|
||||
output.world_pos = vertex + position;
|
||||
output.structure_id = id;
|
||||
output.chunk_position = position;
|
||||
output.ndc = output_vertex;
|
||||
|
||||
//let output = vec4<f32>(vertex, 1.0f);
|
||||
return output;
|
||||
@@ -389,6 +391,14 @@ fn fragment_prepass(in: VertexOutput) -> FragmentPrepassOutput
|
||||
@fragment
|
||||
fn fragment(in: VertexOutput) -> FragmentOutput
|
||||
{
|
||||
let surface_depth = in.ndc.z;
|
||||
let prepass_depth = textureSample(prepass_depth, prepass_depth_sampler, in.ndc.xy).x;
|
||||
|
||||
if surface_depth <= prepass_depth
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
//frag_out.color = vec4<f32>(2 * 0.01 / (100. + 0.01 - depth * (100. - 0.01)));
|
||||
let ray_dir = normalize(in.world_pos - in.cam_pos);
|
||||
let interp = box_inter(in.cam_pos - in.chunk_position, ray_dir, vec3(0.), vec3(1));
|
||||
@@ -401,7 +411,9 @@ fn fragment(in: VertexOutput) -> FragmentOutput
|
||||
var frag_out: FragmentOutput;
|
||||
//frag_out.color = result.color;
|
||||
frag_out.color = result.color;
|
||||
frag_out.depth = depth;
|
||||
//frag_out.color = vec4<f32>(smpl);
|
||||
//frag_out.color = vec4<f32>((2. * 0.01 * 100.) / (0.01 + 100. - prepass_depth * (100. - 0.01)));
|
||||
//frag_out.depth = depth;
|
||||
return frag_out;
|
||||
|
||||
//return vec4<f32>(ray_origin, 1.);
|
||||
|
||||
+15
-11
@@ -429,23 +429,27 @@ impl State
|
||||
@compute @workgroup_size(8, 8)
|
||||
fn main(@builtin(global_invocation_id) id: vec3<u32>)
|
||||
{{
|
||||
let dp = vec2<i32>(id.xy);
|
||||
let sp = dp * {prepass_downsampling};
|
||||
|
||||
let source_pos = vec2<i32>(id.xy);
|
||||
var depth = 1.;
|
||||
depth = min(depth, textureLoad(input_tex, source_pos + vec2<i32>(0, 0)).x);
|
||||
depth = min(depth, textureLoad(input_tex, source_pos + vec2<i32>(1, 0)).x);
|
||||
depth = min(depth, textureLoad(input_tex, source_pos + vec2<i32>(0, 1)).x);
|
||||
depth = min(depth, textureLoad(input_tex, source_pos + vec2<i32>(1, 1)).x);
|
||||
|
||||
let dest_pos = source_pos * {prepass_downsampling};
|
||||
|
||||
for(var ox = 0; ox < {prepass_downsampling}; ox ++)
|
||||
{{
|
||||
for(var oy = 0; oy < {prepass_downsampling}; oy ++)
|
||||
{{
|
||||
depth = min(depth, textureLoad(input_tex, sp + vec2<i32>(ox, oy)).x);
|
||||
textureStore(
|
||||
output_tex,
|
||||
dest_pos + vec2<i32>(ox, oy),
|
||||
vec4<f32>(depth)
|
||||
);
|
||||
}}
|
||||
}}
|
||||
|
||||
textureStore(
|
||||
output_tex,
|
||||
dp,
|
||||
vec4<f32>(depth)
|
||||
);
|
||||
}}
|
||||
"
|
||||
)
|
||||
@@ -688,7 +692,7 @@ impl State
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 1,
|
||||
resource: wgpu::BindingResource::TextureView(&self.upsampled_prepass_depth.1),
|
||||
resource: wgpu::BindingResource::TextureView(&self.prepass_depth.1),
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -783,7 +787,7 @@ impl State
|
||||
},
|
||||
})],
|
||||
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
|
||||
view: &self.depth_buffer.1,
|
||||
view: &self.prepass_depth_buffer.1,
|
||||
depth_ops: Some(Operations {
|
||||
load: wgpu::LoadOp::Clear(1.),
|
||||
store: wgpu::StoreOp::Store,
|
||||
|
||||
Reference in New Issue
Block a user