[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58780] trunk/blender: Cycles / Blackbody to RGB node:

Thomas Dinges blender at dingto.org
Wed Jul 31 22:56:32 CEST 2013


Revision: 58780
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58780
Author:   dingto
Date:     2013-07-31 20:56:32 +0000 (Wed, 31 Jul 2013)
Log Message:
-----------
Cycles / Blackbody to RGB node:
* Added a node to convert a temperature in Kelvin to an RGB color. This can be used e.g. for lights, to easily find the right color temperature. 
= Some common temperatures =
Candle light: 1500 Kelvin
Sunset/Sunrise: 1850 Kelvin
Studio lamps: 3200 Kelvin
Horizon daylight: 5000 Kelvin

Documentation: http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/More#Blackbody

Thanks to Philipp Oeser (lichtwerk), who essentially contributed to this with a patch! :)

This is part of my GSoC 2013 project. SVN merge of r57424, r57487, r57507, r57525, r58253 and r58774

Revision Links:
--------------
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57424
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57487
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57507
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57525
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58253
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58774

Modified Paths:
--------------
    trunk/blender/intern/cycles/blender/blender_shader.cpp
    trunk/blender/intern/cycles/kernel/CMakeLists.txt
    trunk/blender/intern/cycles/kernel/kernel_types.h
    trunk/blender/intern/cycles/kernel/shaders/CMakeLists.txt
    trunk/blender/intern/cycles/kernel/svm/svm.h
    trunk/blender/intern/cycles/kernel/svm/svm_types.h
    trunk/blender/intern/cycles/render/CMakeLists.txt
    trunk/blender/intern/cycles/render/graph.h
    trunk/blender/intern/cycles/render/nodes.cpp
    trunk/blender/intern/cycles/render/nodes.h
    trunk/blender/intern/cycles/render/shader.cpp
    trunk/blender/intern/cycles/render/shader.h
    trunk/blender/intern/cycles/render/svm.cpp
    trunk/blender/release/scripts/startup/nodeitems_builtins.py
    trunk/blender/source/blender/blenkernel/BKE_node.h
    trunk/blender/source/blender/blenkernel/intern/node.c
    trunk/blender/source/blender/nodes/CMakeLists.txt
    trunk/blender/source/blender/nodes/NOD_shader.h
    trunk/blender/source/blender/nodes/NOD_static_types.h

Added Paths:
-----------
    trunk/blender/intern/cycles/kernel/shaders/node_blackbody.osl
    trunk/blender/intern/cycles/kernel/svm/svm_blackbody.h
    trunk/blender/intern/cycles/render/blackbody.cpp
    trunk/blender/intern/cycles/render/blackbody.h
    trunk/blender/source/blender/nodes/shader/nodes/node_shader_blackbody.c

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
/branches/soc-2013-depsgraph_mt:57516
/branches/soc-2013-dingto:58091,58772
/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
/branches/soc-2013-depsgraph_mt:57516
/branches/soc-2013-dingto:57424,57487,57507,57525,58091,58253,58772,58774
/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-07-31 20:50:55 UTC (rev 58779)
+++ trunk/blender/intern/cycles/blender/blender_shader.cpp	2013-07-31 20:56:32 UTC (rev 58780)
@@ -400,6 +400,9 @@
 	else if (b_node.is_a(&RNA_ShaderNodeWavelength)) {
 		node = new WavelengthNode();
 	}
+	else if (b_node.is_a(&RNA_ShaderNodeBlackbody)) {
+		node = new BlackbodyNode();
+	}
 	else if (b_node.is_a(&RNA_ShaderNodeLightPath)) {
 		node = new LightPathNode();
 	}

Modified: trunk/blender/intern/cycles/kernel/CMakeLists.txt
===================================================================
--- trunk/blender/intern/cycles/kernel/CMakeLists.txt	2013-07-31 20:50:55 UTC (rev 58779)
+++ trunk/blender/intern/cycles/kernel/CMakeLists.txt	2013-07-31 20:56:32 UTC (rev 58780)
@@ -72,6 +72,7 @@
 set(SRC_SVM_HEADERS
 	svm/svm.h
 	svm/svm_attribute.h
+	svm/svm_blackbody.h
 	svm/svm_camera.h
 	svm/svm_closure.h
 	svm/svm_convert.h

Modified: trunk/blender/intern/cycles/kernel/kernel_types.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_types.h	2013-07-31 20:50:55 UTC (rev 58779)
+++ trunk/blender/intern/cycles/kernel/kernel_types.h	2013-07-31 20:56:32 UTC (rev 58780)
@@ -44,6 +44,12 @@
 #define BSSRDF_MIN_RADIUS			1e-8f
 #define BSSRDF_MAX_ATTEMPTS			8
 
+#define BB_DRAPPER				800.0
+#define BB_MAX_TABLE_RANGE		12000.0
+#define BB_TABLE_XPOWER			1.5
+#define BB_TABLE_YPOWER			5.0
+#define BB_TABLE_SPACING		2.0
+
 #define TEX_NUM_FLOAT_IMAGES	5
 
 /* device capabilities */
@@ -810,6 +816,12 @@
 	int pad1, pad2;
 } KernelBSSRDF;
 
+typedef struct KernelBlackbody {
+	int table_offset;
+	int pad1, pad2, pad3;
+} KernelBLACKBODY;
+
+
 typedef struct KernelData {
 	KernelCamera cam;
 	KernelFilm film;
@@ -819,6 +831,7 @@
 	KernelBVH bvh;
 	KernelCurves curve_kernel_data;
 	KernelBSSRDF bssrdf;
+	KernelBlackbody blackbody;
 } KernelData;
 
 CCL_NAMESPACE_END

Modified: trunk/blender/intern/cycles/kernel/shaders/CMakeLists.txt
===================================================================
--- trunk/blender/intern/cycles/kernel/shaders/CMakeLists.txt	2013-07-31 20:50:55 UTC (rev 58779)
+++ trunk/blender/intern/cycles/kernel/shaders/CMakeLists.txt	2013-07-31 20:56:32 UTC (rev 58780)
@@ -68,6 +68,7 @@
 	node_voronoi_texture.osl
 	node_ward_bsdf.osl
 	node_wavelength.osl
+	node_blackbody.osl
 	node_wave_texture.osl
 	node_wireframe.osl
 )

Copied: trunk/blender/intern/cycles/kernel/shaders/node_blackbody.osl (from rev 57424, branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_blackbody.osl)
===================================================================
--- trunk/blender/intern/cycles/kernel/shaders/node_blackbody.osl	                        (rev 0)
+++ trunk/blender/intern/cycles/kernel/shaders/node_blackbody.osl	2013-07-31 20:56:32 UTC (rev 58780)
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2013, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "stdosl.h"
+
+shader node_blackbody(
+	float Temperature = 1200.0,
+	output color Color = 0.0)
+{
+	color rgb = blackbody(Temperature);
+	
+	/* Scale by luminance */
+	float l = luminance(rgb);
+	if (l != 0.0)
+		rgb /= l;
+	Color = rgb;
+}
+

Modified: trunk/blender/intern/cycles/kernel/svm/svm.h
===================================================================
--- trunk/blender/intern/cycles/kernel/svm/svm.h	2013-07-31 20:50:55 UTC (rev 58779)
+++ trunk/blender/intern/cycles/kernel/svm/svm.h	2013-07-31 20:56:32 UTC (rev 58780)
@@ -146,6 +146,7 @@
 
 #include "svm_attribute.h"
 #include "svm_gradient.h"
+#include "svm_blackbody.h"
 #include "svm_closure.h"
 #include "svm_noisetex.h"
 #include "svm_convert.h"
@@ -366,6 +367,9 @@
 			case NODE_WAVELENGTH:
 				svm_node_wavelength(sd, stack, node.y, node.z);
 				break;
+			case NODE_BLACKBODY:
+				svm_node_blackbody(kg, sd, stack, node.y, node.z);
+				break;
 			case NODE_SET_DISPLACEMENT:
 				svm_node_set_displacement(sd, stack, node.y);
 				break;

Copied: trunk/blender/intern/cycles/kernel/svm/svm_blackbody.h (from rev 57487, branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_blackbody.h)
===================================================================
--- trunk/blender/intern/cycles/kernel/svm/svm_blackbody.h	                        (rev 0)
+++ trunk/blender/intern/cycles/kernel/svm/svm_blackbody.h	2013-07-31 20:56:32 UTC (rev 58780)
@@ -0,0 +1,84 @@
+/*
+ * Adapted from Open Shading Language with this license:
+ *
+ * Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
+ * All Rights Reserved.
+ *
+ * Modifications Copyright 2013, Blender Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of Sony Pictures Imageworks nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+CCL_NAMESPACE_BEGIN
+
+/* Blackbody Node */
+
+__device void svm_node_blackbody(KernelGlobals *kg, ShaderData *sd, float *stack, uint temperature_offset, uint col_offset)
+{
+	/* Output */
+	float3 color_rgb = make_float3(0.0f, 0.0f, 0.0f);
+
+	/* Input */
+	float temperature = stack_load_float(stack, temperature_offset);
+
+	if (temperature < BB_DRAPPER) {
+		/* just return very very dim red */
+		color_rgb = make_float3(1.0e-6f,0.0f,0.0f);
+	}
+	else if (temperature <= BB_MAX_TABLE_RANGE) {
+		/* This is the overall size of the table */
+		const int lookuptablesize = 956;
+		const float lookuptablenormalize = 1.0f/956.0f;
+
+		/* reconstruct a proper index for the table lookup, compared to OSL we don't look up two colors
+		just one (the OSL-lerp is also automatically done for us by "lookup_table_read") */
+		float t = powf((temperature - BB_DRAPPER) * (1.0f / BB_TABLE_SPACING), 1.0f/BB_TABLE_XPOWER);
+
+		int blackbody_table_offset = kernel_data.blackbody.table_offset;
+
+		/* Retrieve colors from the lookup table */
+		float lutval = t*lookuptablenormalize;
+		float R = lookup_table_read(kg, lutval, blackbody_table_offset, lookuptablesize);
+		lutval = (t + 319.0f*1.0f)*lookuptablenormalize;
+		float G = lookup_table_read(kg, lutval, blackbody_table_offset, lookuptablesize);
+		lutval = (t + 319.0f*2.0f)*lookuptablenormalize;
+		float B = lookup_table_read(kg, lutval, blackbody_table_offset, lookuptablesize);
+
+		R = powf(R, BB_TABLE_YPOWER);
+		G = powf(G, BB_TABLE_YPOWER);
+		B = powf(B, BB_TABLE_YPOWER);
+
+		color_rgb = make_float3(R, G, B);
+	}
+
+	/* Luminance */
+	float l = linear_rgb_to_gray(color_rgb);
+	if (l != 0.0f)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list