[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59603] trunk/blender: Cycles / Sky Texture:

Thomas Dinges blender at dingto.org
Wed Aug 28 16:11:28 CEST 2013


Revision: 59603
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59603
Author:   dingto
Date:     2013-08-28 14:11:28 +0000 (Wed, 28 Aug 2013)
Log Message:
-----------
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?\195?\182nne, 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.

Revision Links:
--------------
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59214
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59220
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59251
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59601

Modified Paths:
--------------
    trunk/blender/intern/cycles/blender/blender_shader.cpp
    trunk/blender/intern/cycles/kernel/kernel_types.h
    trunk/blender/intern/cycles/kernel/shaders/node_sky_texture.osl
    trunk/blender/intern/cycles/kernel/svm/svm.h
    trunk/blender/intern/cycles/kernel/svm/svm_sky.h
    trunk/blender/intern/cycles/kernel/svm/svm_types.h
    trunk/blender/intern/cycles/render/CMakeLists.txt
    trunk/blender/intern/cycles/render/nodes.cpp
    trunk/blender/intern/cycles/render/nodes.h
    trunk/blender/intern/cycles/render/svm.cpp
    trunk/blender/intern/cycles/render/svm.h
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/makesdna/DNA_node_types.h
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
    trunk/blender/source/blender/nodes/shader/nodes/node_shader_tex_sky.c

Added Paths:
-----------
    trunk/blender/intern/cycles/render/sky_model.cpp
    trunk/blender/intern/cycles/render/sky_model.h
    trunk/blender/intern/cycles/render/sky_model_data.h

Property Changed:
----------------
    trunk/blender/


Property changes on: trunk/blender
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/ge_dev:58091-58422
/branches/ge_harmony:42255,42279-42282,42286,42302,42338,42349,42616,42620,42698-42699,42739,42753,42773-42774,42832,44568,44597-44598,44793-44794
/branches/soc-2011-cucumber:37517,38166-38167,38177,38179-38180,38187,38242,38384,38387,38403-38404,38407,38968,38970,38973,39045,40845,42997-42998,43439
/branches/soc-2011-tomato:42376,42378-42379,42383,42385,42395,42397-42400,42407,42411,42418,42443-42444,42446,42467,42472,42486,42650-42652,42654-42655,42709-42710,42733-42734,42801,43872,44130,44141,44147-44149,44151-44152,44229-44230,45623-45625,46037,48089,48092,48551-48552,48679,48790,48792-48793,49076,49087,49292,49294,49466,49894,50052,50126,52854-52856,54573,58822,58989
/branches/soc-2013-depsgraph_mt:57516,57900,57939-57940,57945,57958-57961,58151,58155-58156,58169,58277-58279,58282-58283,58711,58787,58789,58796,59086-59087,59163,59166,59170,59181,59259-59260
/branches/soc-2013-dingto:57424,57487,57507,57525,57599,57670,57918-57919,57981,58091,58245,58253,58587,58772,58774-58775,58828,58835,59032
/tags/blender-2.67b-release/blender:57122
   + /branches/ge_dev:58091-58422
/branches/ge_harmony:42255,42279-42282,42286,42302,42338,42349,42616,42620,42698-42699,42739,42753,42773-42774,42832,44568,44597-44598,44793-44794
/branches/soc-2011-cucumber:37517,38166-38167,38177,38179-38180,38187,38242,38384,38387,38403-38404,38407,38968,38970,38973,39045,40845,42997-42998,43439
/branches/soc-2011-tomato:42376,42378-42379,42383,42385,42395,42397-42400,42407,42411,42418,42443-42444,42446,42467,42472,42486,42650-42652,42654-42655,42709-42710,42733-42734,42801,43872,44130,44141,44147-44149,44151-44152,44229-44230,45623-45625,46037,48089,48092,48551-48552,48679,48790,48792-48793,49076,49087,49292,49294,49466,49894,50052,50126,52854-52856,54573,58822,58989
/branches/soc-2013-depsgraph_mt:57516,57900,57939-57940,57945,57958-57961,58151,58155-58156,58169,58277-58279,58282-58283,58711,58787,58789,58796,59086-59087,59163,59166,59170,59181,59259-59260
/branches/soc-2013-dingto:57424,57487,57507,57525,57599,57670,57918-57919,57981,58091,58245,58253,58587,58772,58774-58775,58828,58835,59032,59214,59220,59251,59601
/tags/blender-2.67b-release/blender:57122

Modified: trunk/blender/intern/cycles/blender/blender_shader.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_shader.cpp	2013-08-28 13:43:34 UTC (rev 59602)
+++ trunk/blender/intern/cycles/blender/blender_shader.cpp	2013-08-28 14:11:28 UTC (rev 59603)
@@ -632,8 +632,10 @@
 	else if (b_node.is_a(&RNA_ShaderNodeTexSky)) {
 		BL::ShaderNodeTexSky b_sky_node(b_node);
 		SkyTextureNode *sky = new SkyTextureNode();
+		sky->type = SkyTextureNode::type_enum[(int)b_sky_node.sky_type()];
 		sky->sun_direction = get_float3(b_sky_node.sun_direction());
 		sky->turbidity = b_sky_node.turbidity();
+		sky->ground_albedo = b_sky_node.ground_albedo();
 		get_tex_mapping(&sky->tex_mapping, b_sky_node.texture_mapping());
 		node = sky;
 	}

Modified: trunk/blender/intern/cycles/kernel/kernel_types.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_types.h	2013-08-28 13:43:34 UTC (rev 59602)
+++ trunk/blender/intern/cycles/kernel/kernel_types.h	2013-08-28 14:11:28 UTC (rev 59603)
@@ -717,16 +717,6 @@
 	float ao_distance;
 } KernelBackground;
 
-typedef struct KernelSunSky {
-	/* sun direction in spherical and cartesian */
-	float theta, phi, pad3, pad4;
-
-	/* perez function parameters */
-	float zenith_Y, zenith_x, zenith_y, pad2;
-	float perez_Y[5], perez_x[5], perez_y[5];
-	float pad5;
-} KernelSunSky;
-
 typedef struct KernelIntegrator {
 	/* emission */
 	int use_direct_light;
@@ -837,7 +827,6 @@
 	KernelCamera cam;
 	KernelFilm film;
 	KernelBackground background;
-	KernelSunSky sunsky;
 	KernelIntegrator integrator;
 	KernelBVH bvh;
 	KernelCurves curve;

Modified: trunk/blender/intern/cycles/kernel/shaders/node_sky_texture.osl
===================================================================
--- trunk/blender/intern/cycles/kernel/shaders/node_sky_texture.osl	2013-08-28 13:43:34 UTC (rev 59602)
+++ trunk/blender/intern/cycles/kernel/shaders/node_sky_texture.osl	2013-08-28 14:11:28 UTC (rev 59603)
@@ -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;
-

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list