Cycles / Blackbody node:
authorThomas Dinges <blender@dingto.org>
Thu, 13 Jun 2013 08:55:51 +0000 (08:55 +0000)
committerThomas Dinges <blender@dingto.org>
Thu, 13 Jun 2013 08:55:51 +0000 (08:55 +0000)
* First step towards a Blackbody to RGB converter. You can specify a color in Kelvin inside the node.
* Only implemented for OSL atm, SVM will follow.

13 files changed:
intern/cycles/blender/blender_shader.cpp
intern/cycles/kernel/shaders/CMakeLists.txt
intern/cycles/kernel/shaders/node_blackbody.osl [new file with mode: 0644]
intern/cycles/kernel/svm/svm_types.h
intern/cycles/render/nodes.cpp
intern/cycles/render/nodes.h
release/scripts/startup/nodeitems_builtins.py
source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/node.c
source/blender/nodes/CMakeLists.txt
source/blender/nodes/NOD_shader.h
source/blender/nodes/NOD_static_types.h
source/blender/nodes/shader/nodes/node_shader_blackbody.c [new file with mode: 0644]

index a9db10b21d77d426a9f6f8f526c1c54d6e51112b..f267118530179f0b5d24d56d40af6057702c465d 100644 (file)
@@ -400,6 +400,9 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen
        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();
        }
index f2beb3da9c03922beddceb2a4d750729d72f69d8..f8454d3ad4083cd4b6a1b70fdc2bc8e35965f6e5 100644 (file)
@@ -68,6 +68,7 @@ set(SRC_OSL
        node_voronoi_texture.osl
        node_ward_bsdf.osl
        node_wavelength.osl
+       node_blackbody.osl
        node_wave_texture.osl
        node_wireframe.osl
 )
diff --git a/intern/cycles/kernel/shaders/node_blackbody.osl b/intern/cycles/kernel/shaders/node_blackbody.osl
new file mode 100644 (file)
index 0000000..7a6e71c
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * 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 = blackbody(Temperature);
+}
+
index e5b3e2b972f4773de09cdb8ad2fd788811d943b1..e4bc7efd272cfdda2b137c73c833f1ebe1480b28 100644 (file)
@@ -53,6 +53,7 @@ typedef enum NodeType {
        NODE_FRESNEL,
        NODE_WIREFRAME,
        NODE_WAVELENGTH,
+       NODE_BLACKBODY,
        NODE_EMISSION_WEIGHT,
        NODE_TEX_GRADIENT,
        NODE_TEX_VORONOI,
index 74033d5c2fa91e7124bf7bf5641ea77519305a27..d7a98bfba90446ff192f622050d65e26246ac7d1 100644 (file)
@@ -2977,6 +2977,32 @@ void WavelengthNode::compile(OSLCompiler& compiler)
        compiler.add(this, "node_wavelength");
 }
 
+/* Blackbody */
+
+BlackbodyNode::BlackbodyNode()
+: ShaderNode("Blackbody")
+{
+       add_input("Temperature", SHADER_SOCKET_FLOAT, 1200.0f);
+       add_output("Color", SHADER_SOCKET_COLOR);
+}
+
+void BlackbodyNode::compile(SVMCompiler& compiler)
+{
+/*
+       ShaderInput *temperature in = input("Temperature");
+       ShaderOutput *color_out = output("Color");
+
+       compiler.stack_assign(temperature_in);
+       compiler.stack_assign(color_out);
+       compiler.add_node(NODE_BLACKBODY, temperature_in->stack_offset, color_out->stack_offset);
+*/
+}
+
+void BlackbodyNode::compile(OSLCompiler& compiler)
+{
+       compiler.add(this, "node_blackbody");
+}
+
 /* Output */
 
 OutputNode::OutputNode()
index f19e07429067db1882780bc77d7566b4485f50e8..843e6c1c153235c84c7e948d7817978c481b83b1 100644 (file)
@@ -462,6 +462,11 @@ public:
        SHADER_NODE_CLASS(WavelengthNode)
 };
 
+class BlackbodyNode : public ShaderNode {
+public:
+       SHADER_NODE_CLASS(BlackbodyNode)
+};
+
 class MathNode : public ShaderNode {
 public:
        SHADER_NODE_CLASS(MathNode)
index fe9e06301f3fa5ffe0c628c9f51825f7cefd7074..96cba2243ec3ed4f646e46e25e21d3b1bbb50838 100644 (file)
@@ -219,6 +219,7 @@ shader_node_categories = [
         NodeItem("ShaderNodeSeparateRGB"),
         NodeItem("ShaderNodeCombineRGB"),
         NodeItem("ShaderNodeWavelength"),
+        NodeItem("ShaderNodeBlackbody"),
         ]),
     ShaderNewNodeCategory("SH_NEW_SCRIPT", "Script", items=[
         NodeItem("ShaderNodeScript"),
index b43747ab33a4cd60c44339d309ed165dd59160b3..bc1ef7ac5c928d63888dd27367d7a5186082f87b 100644 (file)
@@ -742,6 +742,7 @@ struct ShadeResult;
 #define SH_NODE_WIREFRAME                              178
 #define SH_NODE_BSDF_TOON                              179
 #define SH_NODE_WAVELENGTH                             180
+#define SH_NODE_BLACKBODY                              181
 
 /* custom defines options for Material node */
 #define SH_NODE_MAT_DIFF   1
index d40e0daf247e86d2ccd77c155cc21c476aed72e4..150fc8e0c330f5907dfa7819a48263fcbdeeeba9 100644 (file)
@@ -3403,6 +3403,7 @@ static void registerShaderNodes(void)
        register_node_type_sh_rgb();
        register_node_type_sh_wireframe();
        register_node_type_sh_wavelength();
+       register_node_type_sh_blackbody();
        register_node_type_sh_mix_rgb();
        register_node_type_sh_valtorgb();
        register_node_type_sh_rgbtobw();
index cc1a5f8cee9a50679a48bdd4c2a0a7ce178b2f16..4b7ee2aed511746cfaaace2c09cee0534bc67794 100644 (file)
@@ -146,6 +146,7 @@ set(SRC
        shader/nodes/node_shader_value.c
        shader/nodes/node_shader_wireframe.c
        shader/nodes/node_shader_wavelength.c
+       shader/nodes/node_shader_blackbody.c
        shader/nodes/node_shader_vectMath.c
        shader/nodes/node_shader_add_shader.c
        shader/nodes/node_shader_ambient_occlusion.c
index edb0ba6f4759a203d45954628588f640738fbb5f..a56d78af309430303225a85d40e5fc5bc8b10c0d 100644 (file)
@@ -81,6 +81,7 @@ void register_node_type_sh_object_info(void);
 void register_node_type_sh_fresnel(void);
 void register_node_type_sh_wireframe(void);
 void register_node_type_sh_wavelength(void);
+void register_node_type_sh_blackbody(void);
 void register_node_type_sh_layer_weight(void);
 void register_node_type_sh_tex_coord(void);
 void register_node_type_sh_particle_info(void);
index 8e3896f40f79920f9a7d66bba3c948052ae5fb10..6d950d2a469a106fbb39d52d627afd40e741cefb 100644 (file)
@@ -97,6 +97,7 @@ DefNode( ShaderNode,     SH_NODE_PARTICLE_INFO,      0,                      "PA
 DefNode( ShaderNode,     SH_NODE_HAIR_INFO,          0,                      "HAIR_INFO",          HairInfo,         "Hair Info",         ""       )
 DefNode( ShaderNode,     SH_NODE_WIREFRAME,          def_sh_tex_wireframe,   "WIREFRAME",          Wireframe,        "Wireframe",         ""       )
 DefNode( ShaderNode,     SH_NODE_WAVELENGTH,         0,                      "WAVELENGTH",         Wavelength,       "Wavelength",        ""       )
+DefNode( ShaderNode,     SH_NODE_BLACKBODY,          0,                      "BLACKBODY",          Blackbody,        "Blackbody",         ""       )
 DefNode( ShaderNode,     SH_NODE_BUMP,               def_sh_bump,            "BUMP",               Bump,             "Bump",              ""       )
 DefNode( ShaderNode,     SH_NODE_NORMAL_MAP,         def_sh_normal_map,      "NORMAL_MAP",         NormalMap,        "Normal Map",        ""       )
 DefNode( ShaderNode,     SH_NODE_TANGENT,            def_sh_tangent,         "TANGENT",            Tangent,          "Tangent",           ""       )
diff --git a/source/blender/nodes/shader/nodes/node_shader_blackbody.c b/source/blender/nodes/shader/nodes/node_shader_blackbody.c
new file mode 100644 (file)
index 0000000..0a59032
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "../node_shader_util.h"
+
+/* **************** Blackbody ******************** */
+static bNodeSocketTemplate sh_node_blackbody_in[] = {
+       {       SOCK_FLOAT, 1, N_("Temperature"),       1200.0f, 0.0f, 0.0f, 0.0f, 1.0f, 10000.0f},
+       {       -1, 0, ""       }
+};
+
+static bNodeSocketTemplate sh_node_blackbody_out[] = {
+       {       SOCK_RGBA, 0, N_("Color")},
+       {       -1, 0, ""       }
+};
+
+/* node type definition */
+void register_node_type_sh_blackbody(void)
+{
+       static bNodeType ntype;
+
+       sh_node_type_base(&ntype, SH_NODE_BLACKBODY, "Blackbody", NODE_CLASS_CONVERTOR, 0);
+       node_type_compatibility(&ntype, NODE_NEW_SHADING);
+       node_type_size_preset(&ntype, NODE_SIZE_MIDDLE);
+       node_type_socket_templates(&ntype, sh_node_blackbody_in, sh_node_blackbody_out);
+       node_type_init(&ntype, NULL);
+       node_type_storage(&ntype, "", NULL, NULL);
+
+       nodeRegisterType(&ntype);
+}