Skip to content

Commit

Permalink
Fix M_T PDF formula and move cos ray sampler to distribution_sampler
Browse files Browse the repository at this point in the history
The PDF formula was missing the "focus" term's denominator:
(etaI * iDotH + etaT * oDotH)^2
  • Loading branch information
Achilleas Anagnostopoulos committed Aug 24, 2016
1 parent 6cd70ee commit 15bad5d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
25 changes: 23 additions & 2 deletions tracer/opencl/CL/samplers/distribution_sampler.cl
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,31 @@ float ggxGetReflectionPdf(float roughness, float3 inRayDir, float3 outRayDir, fl
return denom == 0.0f ? 0.0f : ggxGetD(roughness, n, h) * nDotH / denom;
}

float ggxGetRefractionPdf(float roughness, float etaT, float3 inRayDir, float3 outRayDir, float3 n, float3 h) {
float ggxGetRefractionPdf(float roughness, float etaI, float etaT, float3 inRayDir, float3 outRayDir, float3 n, float3 h) {
float iDotH = fabs(dot(inRayDir, h));
float oDotH = fabs(dot(outRayDir, h));
float hDotN = fabs(dot(h, n));
return ggxGetD(roughness, n, h) * hDotN * oDotH * etaT * etaT;

// pdf = D * hDotN * focusTerm where
// focusTerm = etaT * etaT * oDotH / (etaI * iDotH + etaT * oDotH)^2
float denom = (etaI * iDotH + etaT * oDotH) * (etaI * iDotH + etaT * oDotH);
return denom > 0.0f ? ggxGetD(roughness, n, h) * hDotN * oDotH * etaT * etaT / denom : 0.0f;
}

// Sample hemisphere direction using a cosine weighted distribution
//
// PDF = cos(theta) / pi
float3 cosWeightedHemisphereGetSample(float3 normal, float2 randSample) {
// Generate point on disk
float rd = sqrt(randSample.x);
float phi = C_TWO_TIMES_PI*randSample.y;

// Generate tangent, bi-tangent vectors
float3 u = normalize(cross((fabs(normal.z) < .999f ? (float3)(0.0f, 0.0f, 1.0f) : (float3)(1.0f, 0.0f, 0.0f)), normal));
float3 v = cross(normal,u);

// Project disk point to unit hemisphere and rotate so that the normal points up
return normalize(u * rd * native_cos(phi) + v * rd * native_sin(phi) + normal * native_sqrt(1 - randSample.x));
}

#endif
25 changes: 0 additions & 25 deletions tracer/opencl/CL/samplers/ray_sampler.cl

This file was deleted.

3 changes: 1 addition & 2 deletions tracer/opencl/CL/samplers/samplers.cl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
#define SAMPLERS_CL

#include "random_sampler.cl"
#include "ray_sampler.cl"
#include "texture_sampler.cl"
#include "material_sampler.cl"
#include "emissive_sampler.cl"
#include "distribution_sampler.cl"
#include "emissive_sampler.cl"

#endif

0 comments on commit 15bad5d

Please sign in to comment.