Simplify varyings

This commit is contained in:
numzero 2024-12-30 04:07:44 +03:00
parent 50144c7b02
commit 0767eec826

View File

@ -20,8 +20,7 @@ struct Vertex {
} }
struct Varying { struct Varying {
@location(0) eye: vec3f, @location(0) dir: vec3f,
@location(1) world: vec3f,
@builtin(position) screen: vec4f, @builtin(position) screen: vec4f,
} }
@ -32,7 +31,7 @@ var<push_constant> params: Params;
@vertex @vertex
fn on_vertex(in: Vertex) -> Varying { fn on_vertex(in: Vertex) -> Varying {
return Varying(params.eye, params.eye + params.view * vec3(1.0, in.screen), vec4(in.screen, 0.0, 1.0)); return Varying(params.view * vec3(1.0, in.screen), vec4(in.screen, 0.0, 1.0));
} }
@fragment @fragment
@ -68,10 +67,10 @@ fn trace_fragment(in: Varying) -> vec4f {
var result = vec4(0.0, 0.0, 0.0, 0.0); var result = vec4(0.0, 0.0, 0.0, 0.0);
var color = vec3(1.0, 1.0, 1.0); var color = vec3(1.0, 1.0, 1.0);
pos = in.eye; pos = params.eye;
let off_px = vec2(rand_float(), rand_float()) - .5; let off_px = vec2(rand_float(), rand_float()) - .5;
let off_w = mat2x3(dpdx(in.world), dpdy(in.world)); let off_w = mat2x3(dpdx(in.dir), dpdy(in.dir));
ray = normalize(in.world + off_w * off_px - in.eye); ray = normalize(in.dir + off_w * off_px);
for (var k = 0; k < params.max_reflections; k++) { for (var k = 0; k < params.max_reflections; k++) {
var sphere = -1; var sphere = -1;