[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59214] branches/soc-2013-dingto: Cycles / Sky Model:
Thomas Dinges
blender at dingto.org
Sat Aug 17 18:08:03 CEST 2013
Revision: 59214
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59214
Author: dingto
Date: 2013-08-17 16:08:03 +0000 (Sat, 17 Aug 2013)
Log Message:
-----------
Cycles / Sky Model:
* Replaced the Preetham model with the newer Hosek / Wilkie model:
"An Analytic Model for Full Spectral Sky-Dome Radiance" http://cgg.mff.cuni.cz/projects/SkylightModelling/
* We use the sample code data, which comes with the paper, but removed some unnecessary parts, we only need the xyz version.
* New "Albedo" UI paraemeter, to control the ground albedo (between 0 and 1).
* Works with SVM only atm (CPU and CUDA).
Example render:
http://www.pasteall.org/pic/show.php?id=57635
ToDo / Open Questions:
* OSL still uses the old model, will be done later. In the meantime it's useful to compare the two models this way.
* The new model needs a much weaker Strength value (0.01), otherwise it's white. Can this be fixed?
* Code cleanup.
Modified Paths:
--------------
branches/soc-2013-dingto/intern/cycles/blender/blender_shader.cpp
branches/soc-2013-dingto/intern/cycles/kernel/kernel_types.h
branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_sky.h
branches/soc-2013-dingto/intern/cycles/render/CMakeLists.txt
branches/soc-2013-dingto/intern/cycles/render/nodes.cpp
branches/soc-2013-dingto/intern/cycles/render/nodes.h
branches/soc-2013-dingto/source/blender/editors/space_node/drawnode.c
branches/soc-2013-dingto/source/blender/makesdna/DNA_node_types.h
branches/soc-2013-dingto/source/blender/makesrna/intern/rna_nodetree.c
branches/soc-2013-dingto/source/blender/nodes/shader/nodes/node_shader_tex_sky.c
Added Paths:
-----------
branches/soc-2013-dingto/intern/cycles/render/sky_model.cpp
branches/soc-2013-dingto/intern/cycles/render/sky_model.h
branches/soc-2013-dingto/intern/cycles/render/sky_model_data.h
Modified: branches/soc-2013-dingto/intern/cycles/blender/blender_shader.cpp
===================================================================
--- branches/soc-2013-dingto/intern/cycles/blender/blender_shader.cpp 2013-08-17 13:32:56 UTC (rev 59213)
+++ branches/soc-2013-dingto/intern/cycles/blender/blender_shader.cpp 2013-08-17 16:08:03 UTC (rev 59214)
@@ -620,6 +620,7 @@
SkyTextureNode *sky = new SkyTextureNode();
sky->sun_direction = get_float3(b_sky_node.sun_direction());
sky->turbidity = b_sky_node.turbidity();
+ sky->albedo = b_sky_node.albedo();
get_tex_mapping(&sky->tex_mapping, b_sky_node.texture_mapping());
node = sky;
}
Modified: branches/soc-2013-dingto/intern/cycles/kernel/kernel_types.h
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/kernel_types.h 2013-08-17 13:32:56 UTC (rev 59213)
+++ branches/soc-2013-dingto/intern/cycles/kernel/kernel_types.h 2013-08-17 16:08:03 UTC (rev 59214)
@@ -718,12 +718,11 @@
typedef struct KernelSunSky {
/* sun direction in spherical and cartesian */
- float theta, phi, pad3, pad4;
+ float theta, phi;
/* perez function parameters */
- float zenith_Y, zenith_x, zenith_y, pad2;
- float perez_Y[5], perez_x[5], perez_y[5];
- float pad5;
+ float radiance_x, radiance_y, radiance_z;
+ float config_x[9], config_y[9], config_z[9];
} KernelSunSky;
typedef struct KernelIntegrator {
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-17 13:32:56 UTC (rev 59213)
+++ branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_sky.h 2013-08-17 16:08:03 UTC (rev 59214)
@@ -19,8 +19,8 @@
CCL_NAMESPACE_BEGIN
/*
- * "A Practical Analytic Model for Daylight"
- * A. J. Preetham, Peter Shirley, Brian Smits
+ * "An Analytic Model for Full Spectral Sky-Dome Radiance"
+ * Lukas Hosek, Alexander Wilkie
*/
__device float sky_angle_between(float thetav, float phiv, float theta, float phi)
@@ -29,12 +29,16 @@
return safe_acosf(cospsi);
}
-__device float sky_perez_function(__constant float *lam, float theta, float gamma)
+/* ArHosekSkyModel_GetRadianceInternal */
+__device float sky_radiance_internal(__constant float *configuration, float theta, float gamma)
{
- float ctheta = cosf(theta);
- float cgamma = cosf(gamma);
+ const float expM = expf(configuration[4] * gamma);
+ const float rayM = cosf(gamma)*cosf(gamma);
+ const float mieM = (1.0f + cosf(gamma)*cosf(gamma)) / powf((1.0f + configuration[8]*configuration[8] - 2.0f*configuration[8]*cosf(gamma)), 1.5f);
+ const float zenith = sqrt(cosf(theta));
- return (1.0f + lam[0]*expf(lam[1]/ctheta)) * (1.0f + lam[2]*expf(lam[3]*gamma) + lam[4]*cgamma*cgamma);
+ return (1.0f + configuration[0] * expf(configuration[1] / (cosf(theta) + 0.01f))) *
+ (configuration[2] + configuration[3] * expM + configuration[5] * rayM + configuration[6] * mieM + configuration[7] * zenith);
}
__device float3 sky_radiance(KernelGlobals *kg, float3 dir)
@@ -50,14 +54,13 @@
/* clamp theta to horizon */
theta = min(theta, M_PI_2_F - 0.001f);
- /* compute xyY color space values */
- float x = kernel_data.sunsky.zenith_x * sky_perez_function(kernel_data.sunsky.perez_x, theta, gamma);
- float y = kernel_data.sunsky.zenith_y * sky_perez_function(kernel_data.sunsky.perez_y, theta, gamma);
- float Y = kernel_data.sunsky.zenith_Y * sky_perez_function(kernel_data.sunsky.perez_Y, theta, gamma);
+ /* compute xyz color space values */
+ float x = sky_radiance_internal(kernel_data.sunsky.config_x, theta, gamma) * kernel_data.sunsky.radiance_x;
+ float y = sky_radiance_internal(kernel_data.sunsky.config_y, theta, gamma) * kernel_data.sunsky.radiance_y;
+ float z = sky_radiance_internal(kernel_data.sunsky.config_z, theta, gamma) * kernel_data.sunsky.radiance_z;
/* convert to RGB */
- float3 xyz = xyY_to_xyz(x, y, Y);
- return xyz_to_rgb(xyz.x, xyz.y, xyz.z);
+ return xyz_to_rgb(x, y, z);
}
__device void svm_node_tex_sky(KernelGlobals *kg, ShaderData *sd, float *stack, uint dir_offset, uint out_offset)
Modified: branches/soc-2013-dingto/intern/cycles/render/CMakeLists.txt
===================================================================
--- branches/soc-2013-dingto/intern/cycles/render/CMakeLists.txt 2013-08-17 13:32:56 UTC (rev 59213)
+++ branches/soc-2013-dingto/intern/cycles/render/CMakeLists.txt 2013-08-17 16:08:03 UTC (rev 59214)
@@ -35,6 +35,7 @@
scene.cpp
session.cpp
shader.cpp
+ sky_model.cpp
sobol.cpp
svm.cpp
tables.cpp
@@ -62,6 +63,8 @@
scene.h
session.h
shader.h
+ sky_model.h
+ sky_model_data.h
sobol.h
svm.h
tables.h
Modified: branches/soc-2013-dingto/intern/cycles/render/nodes.cpp
===================================================================
--- branches/soc-2013-dingto/intern/cycles/render/nodes.cpp 2013-08-17 13:32:56 UTC (rev 59213)
+++ branches/soc-2013-dingto/intern/cycles/render/nodes.cpp 2013-08-17 16:08:03 UTC (rev 59214)
@@ -20,6 +20,7 @@
#include "nodes.h"
#include "svm.h"
#include "osl.h"
+#include "sky_model.h"
#include "util_transform.h"
@@ -386,13 +387,9 @@
return make_float2(acosf(dir.z), atan2f(dir.x, dir.y));
}
-static float sky_perez_function(float lam[6], float theta, float gamma)
+static void sky_texture_precompute(KernelSunSky *ksunsky, float3 dir, float turbidity, float albedo)
{
- return (1.0f + lam[0]*expf(lam[1]/cosf(theta))) * (1.0f + lam[2]*expf(lam[3]*gamma) + lam[4]*cosf(gamma)*cosf(gamma));
-}
-
-static void sky_texture_precompute(KernelSunSky *ksunsky, float3 dir, float turbidity)
-{
+ /* Calculate Sun Direction and save coordinates */
float2 spherical = sky_spherical_coordinates(dir);
float theta = spherical.x;
float phi = spherical.y;
@@ -400,46 +397,49 @@
ksunsky->theta = theta;
ksunsky->phi = phi;
- float theta2 = theta*theta;
- float theta3 = theta2*theta;
- float T = turbidity;
- float T2 = T * T;
+ double solarElevation = M_PI_2_F - theta;
- float chi = (4.0f / 9.0f - T / 120.0f) * (M_PI_F - 2.0f * theta);
- ksunsky->zenith_Y = (4.0453f * T - 4.9710f) * tanf(chi) - 0.2155f * T + 2.4192f;
- ksunsky->zenith_Y *= 0.06f;
+ /* Initialize Sky Model */
+ ArHosekSkyModelState *sky_state;
+ sky_state = arhosek_xyz_skymodelstate_alloc_init(turbidity, albedo, solarElevation);
- ksunsky->zenith_x =
- (0.00166f * theta3 - 0.00375f * theta2 + 0.00209f * theta) * T2 +
- (-0.02903f * theta3 + 0.06377f * theta2 - 0.03202f * theta + 0.00394f) * T +
- (0.11693f * theta3 - 0.21196f * theta2 + 0.06052f * theta + 0.25886f);
+ /* Copy values from sky_state to kernel_data */
+ ksunsky->config_x[0] = sky_state->configs[0][0];
+ ksunsky->config_x[1] = sky_state->configs[0][1];
+ ksunsky->config_x[2] = sky_state->configs[0][2];
+ ksunsky->config_x[3] = sky_state->configs[0][3];
+ ksunsky->config_x[4] = sky_state->configs[0][4];
+ ksunsky->config_x[5] = sky_state->configs[0][5];
+ ksunsky->config_x[6] = sky_state->configs[0][6];
+ ksunsky->config_x[7] = sky_state->configs[0][7];
+ ksunsky->config_x[8] = sky_state->configs[0][8];
- ksunsky->zenith_y =
- (0.00275f * theta3 - 0.00610f * theta2 + 0.00317f * theta) * T2 +
- (-0.04214f * theta3 + 0.08970f * theta2 - 0.04153f * theta + 0.00516f) * T +
- (0.15346f * theta3 - 0.26756f * theta2 + 0.06670f * theta + 0.26688f);
+ ksunsky->config_y[0] = sky_state->configs[1][0];
+ ksunsky->config_y[1] = sky_state->configs[1][1];
+ ksunsky->config_y[2] = sky_state->configs[1][2];
+ ksunsky->config_y[3] = sky_state->configs[1][3];
+ ksunsky->config_y[4] = sky_state->configs[1][4];
+ ksunsky->config_y[5] = sky_state->configs[1][5];
+ ksunsky->config_y[6] = sky_state->configs[1][6];
+ ksunsky->config_y[7] = sky_state->configs[1][7];
+ ksunsky->config_y[8] = sky_state->configs[1][8];
- ksunsky->perez_Y[0] = (0.1787f * T - 1.4630f);
- ksunsky->perez_Y[1] = (-0.3554f * T + 0.4275f);
- ksunsky->perez_Y[2] = (-0.0227f * T + 5.3251f);
- ksunsky->perez_Y[3] = (0.1206f * T - 2.5771f);
- ksunsky->perez_Y[4] = (-0.0670f * T + 0.3703f);
+ ksunsky->config_z[0] = sky_state->configs[2][0];
+ ksunsky->config_z[1] = sky_state->configs[2][1];
+ ksunsky->config_z[2] = sky_state->configs[2][2];
+ ksunsky->config_z[3] = sky_state->configs[2][3];
+ ksunsky->config_z[4] = sky_state->configs[2][4];
+ ksunsky->config_z[5] = sky_state->configs[2][5];
+ ksunsky->config_z[6] = sky_state->configs[2][6];
+ ksunsky->config_z[7] = sky_state->configs[2][7];
+ ksunsky->config_z[8] = sky_state->configs[2][8];
- ksunsky->perez_x[0] = (-0.0193f * T - 0.2592f);
- ksunsky->perez_x[1] = (-0.0665f * T + 0.0008f);
- ksunsky->perez_x[2] = (-0.0004f * T + 0.2125f);
- ksunsky->perez_x[3] = (-0.0641f * T - 0.8989f);
- ksunsky->perez_x[4] = (-0.0033f * T + 0.0452f);
+ ksunsky->radiance_x = sky_state->radiances[0];
+ ksunsky->radiance_y = sky_state->radiances[1];
+ ksunsky->radiance_z = sky_state->radiances[2];
- ksunsky->perez_y[0] = (-0.0167f * T - 0.2608f);
- ksunsky->perez_y[1] = (-0.0950f * T + 0.0092f);
- ksunsky->perez_y[2] = (-0.0079f * T + 0.2102f);
- ksunsky->perez_y[3] = (-0.0441f * T - 1.6537f);
- ksunsky->perez_y[4] = (-0.0109f * T + 0.0529f);
-
- ksunsky->zenith_Y /= sky_perez_function(ksunsky->perez_Y, 0, theta);
- ksunsky->zenith_x /= sky_perez_function(ksunsky->perez_x, 0, theta);
- ksunsky->zenith_y /= sky_perez_function(ksunsky->perez_y, 0, theta);
+ /* Free sky_state */
+ arhosekskymodelstate_free(sky_state);
}
SkyTextureNode::SkyTextureNode()
@@ -447,6 +447,7 @@
{
sun_direction = make_float3(0.0f, 0.0f, 1.0f);
turbidity = 2.2f;
+ albedo = 0.3f;
add_input("Vector", SHADER_SOCKET_VECTOR, ShaderInput::POSITION);
add_output("Color", SHADER_SOCKET_COLOR);
@@ -458,7 +459,7 @@
ShaderOutput *color_out = output("Color");
if(compiler.sunsky) {
- sky_texture_precompute(compiler.sunsky, sun_direction, turbidity);
+ sky_texture_precompute(compiler.sunsky, sun_direction, turbidity, albedo);
compiler.sunsky = NULL;
}
Modified: branches/soc-2013-dingto/intern/cycles/render/nodes.h
===================================================================
--- branches/soc-2013-dingto/intern/cycles/render/nodes.h 2013-08-17 13:32:56 UTC (rev 59213)
+++ branches/soc-2013-dingto/intern/cycles/render/nodes.h 2013-08-17 16:08:03 UTC (rev 59214)
@@ -107,6 +107,7 @@
float3 sun_direction;
float turbidity;
+ float albedo;
};
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list