Skip to content

Commit

Permalink
Fixed IBL sampled pdf term.
Browse files Browse the repository at this point in the history
  • Loading branch information
ScatteredRay committed Jul 19, 2016
1 parent eaad9d6 commit 29202b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions shaders/montecarlo.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ vec4 CosWeightedHemisphereTangentSpace(vec2 e)
float r = sqrt(e.x);
float th = 2.0 * PI * e.y;

float pdf = r / (2.0 * PI);

return vec4(
vec4 ret = vec4(
r * cos(th),
r * sin(th),
sqrt(max(0.0, 1.0 - e.x)),
pdf);
0);

float pdf = ret.z / PI;
ret.w = pdf;
return ret;
}


Expand Down
4 changes: 2 additions & 2 deletions shaders/surface_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ void main()
r += rand2(vScreenPos.xy);
r = fract(r);
vec4 d = CosWeightedHemisphere(r, nz, nx, ny);
float cosine = max(0.0, dot(d.xyz, nz)) / (2.0 * PI);
float cosine = max(0.0, dot(d.xyz, nz)) / (PI);
float pdf = d.w;
vec3 l = max(BRDF(d.xyz, V, nz, nx, ny), vec3(0.0)) * pdf * 24.0;
vec3 l = max(BRDF(d.xyz, V, nz, nx, ny), vec3(0.0)) / pdf;
color += l * textureCube(envMap, d.xyz).rgb / float(numSamples);
}

Expand Down

0 comments on commit 29202b2

Please sign in to comment.