This works as kinda glare but... not really

This commit is contained in:
numzero 2025-01-06 02:13:06 +03:00
parent 973c505f0c
commit 60f648cfb9
4 changed files with 33 additions and 14 deletions

View File

@ -21,7 +21,7 @@ fn on_vertex(in: Vertex) -> Varying {
return Varying(uv, vec4(xy, 0., 1.));
}
const CUTOFF: i32 = 10000;
const CUTOFF: i32 = 200;
@fragment
fn pass_h(in: Varying) -> @location(0) vec4f {
@ -60,10 +60,16 @@ fn pass_v(in: Varying) -> @location(0) vec4f {
// return .1 * w;
// }
fn weight(dist: i32) -> f32 {
let σ = params.sigma / 1e5;
let d = f32(dist) / σ;
return 3. / (1. + d*d);
}
// fn weight(dist: i32) -> f32 {
// let σ = params.sigma / 3000.;
// let σ = params.sigma / 1e8;
// let d = f32(dist) / σ;
// return .1 / (1. + d*d) / σ;
// return 3. / (1. + abs(d));
// }
// fn weight(dist: i32) -> f32 {
@ -72,10 +78,15 @@ fn pass_v(in: Varying) -> @location(0) vec4f {
// return 1. / (1. + d*d*d) / σ;
// }
fn weight(dist: i32) -> f32 {
let d = f32(abs(dist));
let c = mix(.01, 1., exp(-d*d));
// return c * pow(1.2, -d);
return c / (1. + pow(d, 2.0));
// return .25 * c / (1. + pow(.1 * d, 4.0));
}
// fn weight(dist: i32) -> f32 {
// let d = f32(abs(dist));
// let c = mix(.01, 1., exp(-d*d));
// // return c * pow(1.2, -d);
// return c / (1. + pow(d, 2.0));
// // return .25 * c / (1. + pow(.1 * d, 4.0));
// }
// fn weight(dist: i32) -> f32 {
// let d = 2. * f32(dist);
// return exp(-d*d);
// }

View File

@ -24,7 +24,7 @@ fn on_vertex(in: Vertex) -> Varying {
@fragment
fn on_fragment(in: Varying) -> @location(0) vec4f {
let pixel = textureSample(tex, smp, in.tex) / params.divisor;
let pixel = .1 * textureSample(tex, smp, in.tex) / params.divisor;
return vec4(rational_tone_map(pixel.xyz), 1.0);
}

View File

@ -109,7 +109,14 @@ impl Renderer {
let forward = target - eye;
let viewport = make_viewport(size.x, size.y);
let location = convert_location(CamLoc { eye, forward, right });
let spheres: Vec<_> = scene.spheres.iter().map(|p| p.to_sphere(time)).collect();
let mut spheres: Vec<_> = scene.spheres.iter().map(|p| p.to_sphere(time)).collect();
spheres.push(crate::Sphere {
center: vec3(0., 215e3, 0.),
radius: 1e3,
emit_color: Vec3::splat(1.0e6),
reflect_color: Vec3::splat(0.),
glossiness: 0.,
});
let data = TracerData::new(&device, &self.tracer, &spheres);
self.tracer.render(
&mut render_pass.0,
@ -118,7 +125,7 @@ impl Renderer {
trace::Params {
max_reflections: 3,
min_strength: 0.1,
sphere_count: N_SPHERES,
sphere_count: spheres.len() as u32,
seed,
},
viewport,

View File

@ -96,7 +96,8 @@ fn trace_fragment(in: Varying) -> vec3f {
}
if (sphere == -1) {
let env = textureSampleLevel(env_texture, env_sampler, ray, 0.0);
result += 3.0 * color * env.xyz;
// result += (vec3(5.0) + 0.001 * env.xyz) * color;
result += 5.0 * env.xyz * color;
break;
}
let s = spheres[sphere];