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>2013-08-28 18:11:28 +0400
committerThomas Dinges <blender@dingto.org>2013-08-28 18:11:28 +0400
commitd539bd46729b3cdb85483f34f4aa362f2b64195a (patch)
tree9807785dddb1b92cc4fe1b82b8358cc60b09a80c /intern/cycles/kernel/shaders/node_sky_texture.osl
parent1a6b364c284c1d919e0184b18465d9b673d330c6 (diff)
parent8b955e9b19dd8616f61c27d5e9d2d80d66dacd96 (diff)
Cycles / Sky Texture:
* Added a new sky model by Hosek and Wilkie: "An Analytic Model for Full Spectral Sky-Dome Radiance" http://cgg.mff.cuni.cz/projects/SkylightModelling/ Example render: http://archive.dingto.org/2013/blender/code/new_sky_model.png Documentation: http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/Textures#Sky_Texture Details: * User can choose between the older Preetham and the new Hosek / Wilkie model via a dropdown. For older files, backwards compatibility is preserved. When we add a new Sky texture, it defaults to the new model though. * For the new model, you can specify the ground albedo (see documentation for details). * Turbidity now has a UI soft range between 1 and 10, higher values (up to 30) are still possible, but can result in weird colors or black. * Removed the limitation of 1 sky texture per SVM stack. (Patch by Lukas Tönne, thanks!) Thanks to Brecht for code review and some help! This is part of my GSoC 2013 project, SVN merge of r59214, r59220, r59251 and r59601.
Diffstat (limited to 'intern/cycles/kernel/shaders/node_sky_texture.osl')
-rw-r--r--intern/cycles/kernel/shaders/node_sky_texture.osl123
1 files changed, 54 insertions, 69 deletions
diff --git a/intern/cycles/kernel/shaders/node_sky_texture.osl b/intern/cycles/kernel/shaders/node_sky_texture.osl
index 9fa9f938b6a..3ed791fdc92 100644
--- a/intern/cycles/kernel/shaders/node_sky_texture.osl
+++ b/intern/cycles/kernel/shaders/node_sky_texture.osl
@@ -17,16 +17,6 @@
#include "stdosl.h"
#include "node_color.h"
-struct KernelSunSky {
- /* sun direction in spherical and cartesian */
- float theta, phi;
- vector dir;
-
- /* perez function parameters */
- float zenith_Y, zenith_x, zenith_y;
- float perez_Y[5], perez_x[5], perez_y[5];
-};
-
float sky_angle_between(float thetav, float phiv, float theta, float phi)
{
float cospsi = sin(thetav) * sin(theta) * cos(phi - phiv) + cos(thetav) * cos(theta);
@@ -44,7 +34,8 @@ vector sky_spherical_coordinates(vector dir)
return vector(acos(dir[2]), atan2(dir[0], dir[1]), 0);
}
-float sky_perez_function(float lam[5], float theta, float gamma)
+/* Preetham */
+float sky_perez_function(float lam[9], float theta, float gamma)
{
float ctheta = cos(theta);
float cgamma = cos(gamma);
@@ -52,7 +43,9 @@ float sky_perez_function(float lam[5], float theta, float gamma)
return (1.0 + lam[0] * exp(lam[1] / ctheta)) * (1.0 + lam[2] * exp(lam[3] * gamma) + lam[4] * cgamma * cgamma);
}
-color sky_xyz_radiance(KernelSunSky sunsky, vector dir)
+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);
@@ -60,89 +53,81 @@ color sky_xyz_radiance(KernelSunSky sunsky, vector dir)
float phi = spherical[1];
/* angle between sun direction and dir */
- float gamma = sky_angle_between(theta, phi, sunsky.theta, sunsky.phi);
+ 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 = sunsky.zenith_x * sky_perez_function(sunsky.perez_x, theta, gamma);
- float y = sunsky.zenith_y * sky_perez_function(sunsky.perez_y, theta, gamma);
- float Y = sunsky.zenith_Y * sky_perez_function(sunsky.perez_Y, theta, gamma);
+ 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]);
}
-void precompute_sunsky(vector dir, float turbidity, output KernelSunSky sunsky)
+/* Hosek / Wilkie */
+float sky_radiance_internal(float config[9], float theta, float gamma)
+{
+ float ctheta = cos(theta);
+ float cgamma = cos(gamma);
+
+ float expM = exp(config[4] * gamma);
+ float rayM = cgamma * cgamma;
+ float mieM = (1.0 + rayM) / pow((1.0 + config[8]*config[8] - 2.0*config[8]*cgamma), 1.5);
+ float zenith = sqrt(ctheta);
+
+ return (1.0 + config[0] * exp(config[1] / (ctheta + 0.01))) *
+ (config[2] + config[3] * expM + config[5] * rayM + config[6] * mieM + config[7] * zenith);
+}
+
+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);
float theta = spherical[0];
float phi = spherical[1];
- sunsky.theta = theta;
- sunsky.phi = phi;
- sunsky.dir = dir;
-
- float theta2 = theta * theta;
- float theta3 = theta2 * theta;
- float T = turbidity;
- float T2 = T * T;
-
- float chi = (4.0 / 9.0 - T / 120.0) * (M_PI - 2.0 * theta);
- sunsky.zenith_Y = (4.0453 * T - 4.9710) * tan(chi) - 0.2155 * T + 2.4192;
- sunsky.zenith_Y *= 0.06;
-
- sunsky.zenith_x =
- ( 0.00166 * theta3 - 0.00375 * theta2 + 0.00209 * theta) * T2 +
- (-0.02903 * theta3 + 0.06377 * theta2 - 0.03202 * theta + 0.00394) * T +
- ( 0.11693 * theta3 - 0.21196 * theta2 + 0.06052 * theta + 0.25886);
-
- sunsky.zenith_y =
- ( 0.00275 * theta3 - 0.00610 * theta2 + 0.00317 * theta) * T2 +
- (-0.04214 * theta3 + 0.08970 * theta2 - 0.04153 * theta + 0.00516) * T +
- ( 0.15346 * theta3 - 0.26756 * theta2 + 0.06670 * theta + 0.26688);
-
- sunsky.perez_Y[0] = ( 0.1787 * T - 1.4630);
- sunsky.perez_Y[1] = (-0.3554 * T + 0.4275);
- sunsky.perez_Y[2] = (-0.0227 * T + 5.3251);
- sunsky.perez_Y[3] = ( 0.1206 * T - 2.5771);
- sunsky.perez_Y[4] = (-0.0670 * T + 0.3703);
-
- sunsky.perez_x[0] = (-0.0193 * T - 0.2592);
- sunsky.perez_x[1] = (-0.0665 * T + 0.0008);
- sunsky.perez_x[2] = (-0.0004 * T + 0.2125);
- sunsky.perez_x[3] = (-0.0641 * T - 0.8989);
- sunsky.perez_x[4] = (-0.0033 * T + 0.0452);
-
- sunsky.perez_y[0] = (-0.0167 * T - 0.2608);
- sunsky.perez_y[1] = (-0.0950 * T + 0.0092);
- sunsky.perez_y[2] = (-0.0079 * T + 0.2102);
- sunsky.perez_y[3] = (-0.0441 * T - 1.6537);
- sunsky.perez_y[4] = (-0.0109 * T + 0.0529);
-
- sunsky.zenith_Y /= sky_perez_function(sunsky.perez_Y, 0, theta);
- sunsky.zenith_x /= sky_perez_function(sunsky.perez_x, 0, theta);
- sunsky.zenith_y /= sky_perez_function(sunsky.perez_y, 0, theta);
+ /* 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 xyz color space values */
+ float x = sky_radiance_internal(config_x, theta, gamma) * radiance[0];
+ float y = sky_radiance_internal(config_y, theta, gamma) * radiance[1];
+ float z = sky_radiance_internal(config_z, theta, gamma) * radiance[2];
+
+ /* convert to RGB and adjust strength */
+ return xyz_to_rgb(x, y, z) * (M_2PI/683);
}
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,
- vector sun_direction = vector(0, 0, 1),
- float turbidity = 2.2,
- output color Color = 0.0)
+ string sky_model = "Hosek / Wilkie",
+ float theta = 0.0,
+ float phi = 0.0,
+ color radiance = color(0.0, 0.0, 0.0),
+ float config_x[9] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+ float config_y[9] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+ float config_z[9] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
+ output color Color = color(0.0, 0.0, 0.0))
{
vector p = Vector;
if (use_mapping)
p = transform(mapping, p);
-
- KernelSunSky sunsky;
-
- precompute_sunsky(sun_direction, turbidity, sunsky);
- Color = sky_xyz_radiance(sunsky, p);
+
+ 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);
}