Skip to content

Commit b96de95

Browse files
committed
Fix Monte Carlo intensity computation
1 parent 4dcc40d commit b96de95

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/scripts/modules/light/monte_carlo_path_tracing/propagate.wgsl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ struct StagingBuffer {
1212

1313
const PI = 3.14159265359;
1414

15-
const SAMPLES = 2;
1615
const MAXDEPTH = 700;
1716

1817
var<private> seed: u32 = 0u;
@@ -50,9 +49,12 @@ fn radiance(_p: vec2f) -> vec3<f32> {
5049
if ((pi.x < 0) || (pi.x > dims.x-1) || (pi.y < 0) || (pi.y >= dims.y-1)) {
5150
break;
5251
}
53-
let Em = textureLoad(scene, pi, 0, 0).rgb * 0.3;
52+
let Em = textureLoad(scene, pi, 0, 0).rgb;
5453
acc += att * Em;
55-
let translucency = textureLoad(scene, pi, 1, 0).a;
54+
let colorTexture = textureLoad(scene, pi, 1, 0);
55+
let translucency = colorTexture.a;
56+
let color = colorTexture.rgb;
57+
5658
if (translucency < rand()) {
5759
/*
5860
if (rand() > 0.8) {
@@ -61,10 +63,9 @@ fn radiance(_p: vec2f) -> vec3<f32> {
6163
*/
6264
let phi = 2. * PI * rand();
6365
d = vec2f(cos(phi), sin(phi));
64-
att.r *= 0.9;
65-
att.g *= 0.;
66-
att.b *= 0.;
67-
66+
att.r *= color.r;
67+
att.g *= color.g;
68+
att.b *= color.b;
6869
}
6970
p = p + d;
7071
}
@@ -82,7 +83,7 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
8283
for(var i: i32 = 0; i<i32(staging.samples); i++) {
8384
color = color + radiance(p);
8485
}
85-
color = mix(previousColor, color / f32(SAMPLES), 1. / (staging.iFrame + 1.));
86+
color = mix(previousColor, color / f32(staging.samples), 1. / (staging.iFrame + 1.));
8687

8788
textureStore(img_output, vec2i(global_id.xy), 0, vec4<f32>(color, 1.0));
8889
}

0 commit comments

Comments
 (0)