diff options
author | Thomas Dinges <blender@dingto.org> | 2016-04-05 13:25:54 +0300 |
---|---|---|
committer | Thomas Dinges <blender@dingto.org> | 2016-04-05 13:25:54 +0300 |
commit | b8ca4819b2e9288cb86988c01b0b6a2a5b39fe8a (patch) | |
tree | 4e6e0c8659108725dc10e14324530d6a1595483e /intern/cycles/kernel/svm/svm_sky.h | |
parent | 46aaa539984231021a2e895afa8c04734de96c86 (diff) |
Revert "Cycles: Remove the Preetham Sky model."
This reverts commit d91316dc672dc1ee69fbd24d2f00124a24b75c6b.
Diffstat (limited to 'intern/cycles/kernel/svm/svm_sky.h')
-rw-r--r-- | intern/cycles/kernel/svm/svm_sky.h | 60 |
1 files changed, 53 insertions, 7 deletions
diff --git a/intern/cycles/kernel/svm/svm_sky.h b/intern/cycles/kernel/svm/svm_sky.h index 28599f550b6..854e85fd326 100644 --- a/intern/cycles/kernel/svm/svm_sky.h +++ b/intern/cycles/kernel/svm/svm_sky.h @@ -25,6 +25,44 @@ ccl_device float sky_angle_between(float thetav, float phiv, float theta, float } /* + * "A Practical Analytic Model for Daylight" + * A. J. Preetham, Peter Shirley, Brian Smits + */ +ccl_device float sky_perez_function(float *lam, float theta, float gamma) +{ + float ctheta = cosf(theta); + float cgamma = cosf(gamma); + + return (1.0f + lam[0]*expf(lam[1]/ctheta)) * (1.0f + lam[2]*expf(lam[3]*gamma) + lam[4]*cgamma*cgamma); +} + +ccl_device float3 sky_radiance_old(KernelGlobals *kg, float3 dir, + float sunphi, float suntheta, + float radiance_x, float radiance_y, float radiance_z, + float *config_x, float *config_y, float *config_z) +{ + /* convert vector to spherical coordinates */ + float2 spherical = direction_to_spherical(dir); + float theta = spherical.x; + float phi = spherical.y; + + /* angle between sun direction and dir */ + float gamma = sky_angle_between(theta, phi, suntheta, sunphi); + + /* clamp theta to horizon */ + theta = min(theta, M_PI_2_F - 0.001f); + + /* compute xyY color space values */ + float x = radiance_y * sky_perez_function(config_y, theta, gamma); + float y = radiance_z * sky_perez_function(config_z, theta, gamma); + float Y = radiance_x * sky_perez_function(config_x, theta, gamma); + + /* convert to RGB */ + float3 xyz = xyY_to_xyz(x, y, Y); + return xyz_to_rgb(xyz.x, xyz.y, xyz.z); +} + +/* * "An Analytic Model for Full Spectral Sky-Dome Radiance" * Lukas Hosek, Alexander Wilkie */ @@ -42,10 +80,10 @@ ccl_device float sky_radiance_internal(float *configuration, float theta, float (configuration[2] + configuration[3] * expM + configuration[5] * rayM + configuration[6] * mieM + configuration[7] * zenith); } -ccl_device float3 sky_radiance(KernelGlobals *kg, float3 dir, - float sunphi, float suntheta, - float radiance_x, float radiance_y, float radiance_z, - float *config_x, float *config_y, float *config_z) +ccl_device float3 sky_radiance_new(KernelGlobals *kg, float3 dir, + float sunphi, float suntheta, + float radiance_x, float radiance_y, float radiance_z, + float *config_x, float *config_y, float *config_z) { /* convert vector to spherical coordinates */ float2 spherical = direction_to_spherical(dir); @@ -76,6 +114,7 @@ ccl_device void svm_node_tex_sky(KernelGlobals *kg, ShaderData *sd, float *stack /* Load data */ uint dir_offset = node.y; uint out_offset = node.z; + int sky_model = node.w; float4 data = read_node_float(kg, offset); sunphi = data.x; @@ -129,9 +168,16 @@ ccl_device void svm_node_tex_sky(KernelGlobals *kg, ShaderData *sd, float *stack float3 f; /* Compute Sky */ - f = sky_radiance(kg, dir, sunphi, suntheta, - radiance_x, radiance_y, radiance_z, - config_x, config_y, config_z); + if(sky_model == 0) { + f = sky_radiance_old(kg, dir, sunphi, suntheta, + radiance_x, radiance_y, radiance_z, + config_x, config_y, config_z); + } + else { + f = sky_radiance_new(kg, dir, sunphi, suntheta, + radiance_x, radiance_y, radiance_z, + config_x, config_y, config_z); + } stack_store_float3(stack, out_offset, f); } |