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/shaders | |
parent | 46aaa539984231021a2e895afa8c04734de96c86 (diff) |
Revert "Cycles: Remove the Preetham Sky model."
This reverts commit d91316dc672dc1ee69fbd24d2f00124a24b75c6b.
Diffstat (limited to 'intern/cycles/kernel/shaders')
-rw-r--r-- | intern/cycles/kernel/shaders/node_sky_texture.osl | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/intern/cycles/kernel/shaders/node_sky_texture.osl b/intern/cycles/kernel/shaders/node_sky_texture.osl index 9ce9008ef4b..05eed23bea8 100644 --- a/intern/cycles/kernel/shaders/node_sky_texture.osl +++ b/intern/cycles/kernel/shaders/node_sky_texture.osl @@ -34,6 +34,40 @@ vector sky_spherical_coordinates(vector dir) return vector(acos(dir[2]), atan2(dir[0], dir[1]), 0); } +/* Preetham */ +float sky_perez_function(float lam[9], float theta, float gamma) +{ + float ctheta = cos(theta); + float cgamma = cos(gamma); + + return (1.0 + lam[0] * exp(lam[1] / ctheta)) * (1.0 + lam[2] * exp(lam[3] * gamma) + lam[4] * cgamma * cgamma); +} + +color sky_radiance_old(normal dir, + float sunphi, float suntheta, color radiance, + float config_x[9], float config_y[9], float config_z[9]) +{ + /* convert vector to spherical coordinates */ + vector spherical = sky_spherical_coordinates(dir); + float theta = spherical[0]; + float phi = spherical[1]; + + /* 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 - 0.001); + + /* compute xyY color space values */ + float x = radiance[1] * sky_perez_function(config_y, theta, gamma); + float y = radiance[2] * sky_perez_function(config_z, theta, gamma); + float Y = radiance[0] * sky_perez_function(config_x, theta, gamma); + + /* convert to RGB */ + color xyz = xyY_to_xyz(x, y, Y); + return xyz_to_rgb(xyz[0], xyz[1], xyz[2]); +} + /* Hosek / Wilkie */ float sky_radiance_internal(float config[9], float theta, float gamma) { @@ -49,9 +83,9 @@ float sky_radiance_internal(float config[9], float theta, float gamma) (config[2] + config[3] * expM + config[5] * rayM + config[6] * mieM + config[7] * zenith); } -color sky_radiance(normal dir, - float sunphi, float suntheta, color radiance, - float config_x[9], float config_y[9], float config_z[9]) +color sky_radiance_new(normal dir, + float sunphi, float suntheta, color radiance, + float config_x[9], float config_y[9], float config_z[9]) { /* convert vector to spherical coordinates */ vector spherical = sky_spherical_coordinates(dir); @@ -77,6 +111,7 @@ shader node_sky_texture( int use_mapping = 0, matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), vector Vector = P, + string sky_model = "Hosek / Wilkie", float theta = 0.0, float phi = 0.0, color radiance = color(0.0, 0.0, 0.0), @@ -89,7 +124,10 @@ shader node_sky_texture( if (use_mapping) p = transform(mapping, p); - - Color = sky_radiance(p, phi, theta, radiance, config_x, config_y, config_z); + + if (sky_model == "Hosek / Wilkie") + Color = sky_radiance_new(p, phi, theta, radiance, config_x, config_y, config_z); + else + Color = sky_radiance_old(p, phi, theta, radiance, config_x, config_y, config_z); } |