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.);
|
||||
|
||||
Reference in New Issue
Block a user