[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59251] branches/soc-2013-dingto/intern/ cycles: Cycles / Sky Model:
Thomas Dinges
blender at dingto.org
Mon Aug 19 01:54:56 CEST 2013
Revision: 59251
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59251
Author: dingto
Date: 2013-08-18 23:54:56 +0000 (Sun, 18 Aug 2013)
Log Message:
-----------
Cycles / Sky Model:
* Remove the KernelSunSky struct, which limited us to 1 Sky texture for SVM. Now we can use more than 1 Sky shader, which allows some artificial effects like 2 Sun/Sky's or so.
* New and old model are now working in OSL as well.
Patch by Lukas T?\195?\182nne, with some small tweaks by me. Thanks!
ToDo:
* Code cleanup!
Modified Paths:
--------------
branches/soc-2013-dingto/intern/cycles/kernel/kernel_types.h
branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_sky_texture.osl
branches/soc-2013-dingto/intern/cycles/kernel/svm/svm.h
branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_sky.h
branches/soc-2013-dingto/intern/cycles/render/nodes.cpp
branches/soc-2013-dingto/intern/cycles/render/svm.cpp
branches/soc-2013-dingto/intern/cycles/render/svm.h
Modified: branches/soc-2013-dingto/intern/cycles/kernel/kernel_types.h
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/kernel_types.h 2013-08-18 22:44:43 UTC (rev 59250)
+++ branches/soc-2013-dingto/intern/cycles/kernel/kernel_types.h 2013-08-18 23:54:56 UTC (rev 59251)
@@ -716,15 +716,6 @@
float ao_distance;
} KernelBackground;
-typedef struct KernelSunSky {
- /* sun direction in spherical and cartesian */
- float theta, phi;
-
- /* perez function parameters */
- float radiance_x, radiance_y, radiance_z;
- float config_x[9], config_y[9], config_z[9];
-} KernelSunSky;
-
typedef struct KernelIntegrator {
/* emission */
int use_direct_light;
@@ -834,7 +825,6 @@
KernelCamera cam;
KernelFilm film;
KernelBackground background;
- KernelSunSky sunsky;
KernelIntegrator integrator;
KernelBVH bvh;
KernelCurves curve;
Modified: branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_sky_texture.osl
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_sky_texture.osl 2013-08-18 22:44:43 UTC (rev 59250)
+++ branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_sky_texture.osl 2013-08-18 23:54:56 UTC (rev 59251)
@@ -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 @@
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 @@
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 @@
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;
+ /* angle between sun direction and dir */
+ float gamma = sky_angle_between(theta, phi, suntheta, sunphi);
- float theta2 = theta * theta;
- float theta3 = theta2 * theta;
- float T = turbidity;
- float T2 = T * T;
+ /* clamp theta to horizon */
+ theta = min(theta, M_PI_2 - 0.001);
- 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;
+ /* 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];
- 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);
+ /* 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);
}
Modified: branches/soc-2013-dingto/intern/cycles/kernel/svm/svm.h
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/svm/svm.h 2013-08-18 22:44:43 UTC (rev 59250)
+++ branches/soc-2013-dingto/intern/cycles/kernel/svm/svm.h 2013-08-18 23:54:56 UTC (rev 59251)
@@ -255,7 +255,7 @@
#endif
#ifdef __PROCEDURAL_TEXTURES__
case NODE_TEX_SKY:
- svm_node_tex_sky(kg, sd, stack, node.y, node.z, node.w);
+ svm_node_tex_sky(kg, sd, stack, node, &offset);
break;
case NODE_TEX_GRADIENT:
svm_node_tex_gradient(sd, stack, node);
Modified: branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_sky.h
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_sky.h 2013-08-18 22:44:43 UTC (rev 59250)
+++ branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_sky.h 2013-08-18 23:54:56 UTC (rev 59251)
@@ -36,7 +36,10 @@
return (1.0f + lam[0]*expf(lam[1]/ctheta)) * (1.0f + lam[2]*expf(lam[3]*gamma) + lam[4]*cgamma*cgamma);
}
-__device float3 sky_radiance_old(KernelGlobals *kg, float3 dir)
+__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);
@@ -44,15 +47,15 @@
float phi = spherical.y;
/* angle between sun direction and dir */
- float gamma = sky_angle_between(theta, phi, kernel_data.sunsky.theta, kernel_data.sunsky.phi);
+ 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 = kernel_data.sunsky.radiance_y * sky_perez_function(kernel_data.sunsky.config_y, theta, gamma);
- float y = kernel_data.sunsky.radiance_z * sky_perez_function(kernel_data.sunsky.config_z, theta, gamma);
- float Y = kernel_data.sunsky.radiance_x * sky_perez_function(kernel_data.sunsky.config_x, theta, gamma);
+ 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);
@@ -77,7 +80,10 @@
(configuration[2] + configuration[3] * expM + configuration[5] * rayM + configuration[6] * mieM + configuration[7] * zenith);
}
-__device float3 sky_radiance_new(KernelGlobals *kg, float3 dir)
+__device float3 sky_radiance_new(KernelGlobals *kg, float3 dir,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list