Cleanup: EEVEE: Make bsdf_sampling_lib.glsl more tidy

This commit is contained in:
Clément Foucault
2021-03-12 14:31:39 +01:00
parent ba3a0dc9ba
commit 5fee9dae5d
2 changed files with 12 additions and 12 deletions

View File

@@ -42,11 +42,6 @@ float pdf_ggx_reflect(float NH, float NV, float VH, float alpha)
#endif
}
float pdf_hemisphere()
{
return 0.5 * M_1_PI;
}
vec3 sample_ggx(vec3 rand, float alpha, vec3 Vt)
{
#if USE_VISIBLE_NORMAL
@@ -94,20 +89,24 @@ vec3 sample_ggx(vec3 rand, float alpha, vec3 V, vec3 N, vec3 T, vec3 B, out floa
return tangent_to_world(Ht, N, T, B);
}
float pdf_hemisphere()
{
return 0.5 * M_1_PI;
}
vec3 sample_hemisphere(vec3 rand)
{
/* Theta is the cone angle. */
float z = rand.x; /* cos theta */
float r = sqrt(max(0.0, 1.0 - z * z)); /* sin theta */
float x = r * rand.y;
float y = r * rand.z;
return vec3(x, y, z);
}
vec3 sample_hemisphere(vec3 rand, vec3 N, vec3 T, vec3 B)
vec3 sample_hemisphere(vec3 rand, vec3 N, vec3 T, vec3 B, out float pdf)
{
vec3 Ht = sample_hemisphere(rand);
pdf = pdf_hemisphere();
return tangent_to_world(Ht, N, T, B);
}
@@ -125,10 +124,11 @@ vec3 sample_ggx(float nsample,
return sample_ggx(Xi, alpha, V, N, T, B, pdf);
}
vec3 sample_hemisphere(float nsample, float inv_sample_count, vec3 N, vec3 T, vec3 B)
vec3 sample_hemisphere(
float nsample, float inv_sample_count, vec3 N, vec3 T, vec3 B, out float pdf)
{
vec3 Xi = hammersley_3d(nsample, inv_sample_count);
return sample_hemisphere(Xi, N, T, B);
return sample_hemisphere(Xi, N, T, B, pdf);
}
vec3 sample_cone(float nsample, float inv_sample_count, float angle, vec3 N, vec3 T, vec3 B)

View File

@@ -147,14 +147,14 @@ void main()
float weight = 0.0;
vec3 out_radiance = vec3(0.0);
for (float i = 0; i < sampleCount; i++) {
vec3 L = sample_hemisphere(i, invSampleCount, N, T, B); /* Microfacet normal */
float pdf;
vec3 L = sample_hemisphere(i, invSampleCount, N, T, B, pdf);
float NL = dot(N, L);
if (NL > 0.0) {
/* Coarse Approximation of the mapping distortion
* Unit Sphere -> Cubemap Face */
const float dist = 4.0 * M_PI / 6.0;
float pdf = pdf_hemisphere();
/* http://http.developer.nvidia.com/GPUGems3/gpugems3_ch20.html : Equation 13 */
float lod = clamp(lodFactor - 0.5 * log2(pdf * dist), 0.0, lodMax);