Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Dinges <blender@dingto.org>2015-02-17 19:44:32 +0300
committerThomas Dinges <blender@dingto.org>2015-02-17 19:48:18 +0300
commita0d7db503d82c1a5b56a5723da90364f11569b37 (patch)
tree3b66620b4692970cac29a86b9644dc3301ad2035 /intern/cycles/kernel/closure/volume.h
parentea2fc5b9d6000a61dba5e8c37a36231a2f22e6d4 (diff)
Cycles: Small tweaks for Henyey Greenstein closure code.
* Avoid duplicative fabs(g) check in sample code. * Avoid dot product in eval code. Helps like ~1% when Scatter Anisotropy is 0.
Diffstat (limited to 'intern/cycles/kernel/closure/volume.h')
-rw-r--r--intern/cycles/kernel/closure/volume.h16
1 files changed, 9 insertions, 7 deletions
diff --git a/intern/cycles/kernel/closure/volume.h b/intern/cycles/kernel/closure/volume.h
index 9f519e2e2b1..1cf5e17b8f7 100644
--- a/intern/cycles/kernel/closure/volume.h
+++ b/intern/cycles/kernel/closure/volume.h
@@ -26,9 +26,6 @@ CCL_NAMESPACE_BEGIN
* uniform sphere. g=0 uniform diffuse-like, g=1 close to sharp single ray. */
ccl_device float single_peaked_henyey_greenstein(float cos_theta, float g)
{
- if(fabsf(g) < 1e-3f)
- return M_1_PI_F * 0.25f;
-
return ((1.0f - g * g) / safe_powf(1.0f + g * g - 2.0f * g * cos_theta, 1.5f)) * (M_1_PI_F * 0.25f);
};
@@ -47,9 +44,13 @@ ccl_device float3 volume_henyey_greenstein_eval_phase(const ShaderClosure *sc, c
float g = sc->data0;
/* note that I points towards the viewer */
- float cos_theta = dot(-I, omega_in);
-
- *pdf = single_peaked_henyey_greenstein(cos_theta, g);
+ if(fabsf(g) < 1e-3f) {
+ *pdf = M_1_PI_F * 0.25f;
+ }
+ else {
+ float cos_theta = dot(-I, omega_in);
+ *pdf = single_peaked_henyey_greenstein(cos_theta, g);
+ }
return make_float3(*pdf, *pdf, *pdf);
}
@@ -63,10 +64,12 @@ ccl_device int volume_henyey_greenstein_sample(const ShaderClosure *sc, float3 I
/* match pdf for small g */
if(fabsf(g) < 1e-3f) {
cos_theta = (1.0f - 2.0f * randu);
+ *pdf = M_1_PI_F * 0.25f;
}
else {
float k = (1.0f - g * g) / (1.0f - g + 2.0f * g * randu);
cos_theta = (1.0f + g * g - k * k) / (2.0f * g);
+ *pdf = single_peaked_henyey_greenstein(cos_theta, g);
}
float sin_theta = safe_sqrtf(1.0f - cos_theta * cos_theta);
@@ -80,7 +83,6 @@ ccl_device int volume_henyey_greenstein_sample(const ShaderClosure *sc, float3 I
make_orthonormals(-I, &T, &B);
*omega_in = sin_theta * cos_phi * T + sin_theta * sin_phi * B + cos_theta * (-I);
- *pdf = single_peaked_henyey_greenstein(cos_theta, g);
*eval = make_float3(*pdf, *pdf, *pdf); /* perfect importance sampling */
#ifdef __RAY_DIFFERENTIALS__