[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57322] branches/soc-2013-dingto: Cycles / Wavelength to RGB node:
Thomas Dinges
blender at dingto.org
Sun Jun 9 22:46:22 CEST 2013
Revision: 57322
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57322
Author: dingto
Date: 2013-06-09 20:46:22 +0000 (Sun, 09 Jun 2013)
Log Message:
-----------
Cycles / Wavelength to RGB node:
* Added a node to convert wavelength (in nanometer, from 380nm to 780nm) to RGB values. This can be useful to match real world colors easier.
Example render:
http://www.pasteall.org/pic/show.php?id=53202
ToDo:
* Move some functions into an util file, maybe a common util_color.h or so.
* Test GPU, unfortunately sm_21 doesn't work for me yet.
Modified Paths:
--------------
branches/soc-2013-dingto/intern/cycles/blender/blender_shader.cpp
branches/soc-2013-dingto/intern/cycles/kernel/CMakeLists.txt
branches/soc-2013-dingto/intern/cycles/kernel/shaders/CMakeLists.txt
branches/soc-2013-dingto/intern/cycles/kernel/svm/svm.h
branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_types.h
branches/soc-2013-dingto/intern/cycles/render/nodes.cpp
branches/soc-2013-dingto/intern/cycles/render/nodes.h
branches/soc-2013-dingto/release/scripts/startup/nodeitems_builtins.py
branches/soc-2013-dingto/source/blender/blenkernel/BKE_node.h
branches/soc-2013-dingto/source/blender/blenkernel/intern/node.c
branches/soc-2013-dingto/source/blender/nodes/CMakeLists.txt
branches/soc-2013-dingto/source/blender/nodes/NOD_shader.h
branches/soc-2013-dingto/source/blender/nodes/NOD_static_types.h
Added Paths:
-----------
branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_wavelength.osl
branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_wavelength.h
branches/soc-2013-dingto/source/blender/nodes/shader/nodes/node_shader_wavelength.c
Modified: branches/soc-2013-dingto/intern/cycles/blender/blender_shader.cpp
===================================================================
--- branches/soc-2013-dingto/intern/cycles/blender/blender_shader.cpp 2013-06-09 20:28:16 UTC (rev 57321)
+++ branches/soc-2013-dingto/intern/cycles/blender/blender_shader.cpp 2013-06-09 20:46:22 UTC (rev 57322)
@@ -397,6 +397,9 @@
wire->use_pixel_size = b_wireframe_node.use_pixel_size();
node = wire;
}
+ else if (b_node.is_a(&RNA_ShaderNodeWavelength)) {
+ node = new WavelengthNode();
+ }
else if (b_node.is_a(&RNA_ShaderNodeLightPath)) {
node = new LightPathNode();
}
Modified: branches/soc-2013-dingto/intern/cycles/kernel/CMakeLists.txt
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/CMakeLists.txt 2013-06-09 20:28:16 UTC (rev 57321)
+++ branches/soc-2013-dingto/intern/cycles/kernel/CMakeLists.txt 2013-06-09 20:46:22 UTC (rev 57322)
@@ -80,6 +80,7 @@
svm/svm_displace.h
svm/svm_fresnel.h
svm/svm_wireframe.h
+ svm/svm_wavelength.h
svm/svm_gamma.h
svm/svm_brightness.h
svm/svm_geometry.h
Modified: branches/soc-2013-dingto/intern/cycles/kernel/shaders/CMakeLists.txt
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/shaders/CMakeLists.txt 2013-06-09 20:28:16 UTC (rev 57321)
+++ branches/soc-2013-dingto/intern/cycles/kernel/shaders/CMakeLists.txt 2013-06-09 20:46:22 UTC (rev 57322)
@@ -67,6 +67,7 @@
node_velvet_bsdf.osl
node_voronoi_texture.osl
node_ward_bsdf.osl
+ node_wavelength.osl
node_wave_texture.osl
node_wireframe.osl
)
Added: branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_wavelength.osl
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_wavelength.osl (rev 0)
+++ branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_wavelength.osl 2013-06-09 20:46:22 UTC (rev 57322)
@@ -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_wavelength(
+ float Wavelength = 500.0,
+ output color Color = 0.0)
+{
+ Color = wavelength_color(Wavelength);
+}
+
Modified: branches/soc-2013-dingto/intern/cycles/kernel/svm/svm.h
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/svm/svm.h 2013-06-09 20:28:16 UTC (rev 57321)
+++ branches/soc-2013-dingto/intern/cycles/kernel/svm/svm.h 2013-06-09 20:46:22 UTC (rev 57322)
@@ -152,6 +152,7 @@
#include "svm_displace.h"
#include "svm_fresnel.h"
#include "svm_wireframe.h"
+#include "svm_wavelength.h"
#include "svm_camera.h"
#include "svm_geometry.h"
#include "svm_hsv.h"
@@ -362,6 +363,9 @@
svm_node_wireframe(kg, sd, stack, node.y, node.z, node.w);
break;
#ifdef __EXTRA_NODES__
+ case NODE_WAVELENGTH:
+ svm_node_wavelength(sd, stack, node.y, node.z);
+ break;
case NODE_SET_DISPLACEMENT:
svm_node_set_displacement(sd, stack, node.y);
break;
Modified: branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_types.h
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_types.h 2013-06-09 20:28:16 UTC (rev 57321)
+++ branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_types.h 2013-06-09 20:46:22 UTC (rev 57322)
@@ -52,6 +52,7 @@
NODE_CONVERT,
NODE_FRESNEL,
NODE_WIREFRAME,
+ NODE_WAVELENGTH,
NODE_EMISSION_WEIGHT,
NODE_TEX_GRADIENT,
NODE_TEX_VORONOI,
Added: branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_wavelength.h
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_wavelength.h (rev 0)
+++ branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_wavelength.h 2013-06-09 20:46:22 UTC (rev 57322)
@@ -0,0 +1,113 @@
+/*
+ * 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
+
+/* Wavelength to RGB */
+
+/* ToDo: Move these 2 functions to an util file */
+__device float3 xyz_to_rgb_wave(float x, float y, float z)
+{
+ return make_float3(3.240479f * x + -1.537150f * y + -0.498535f * z,
+ -0.969256f * x + 1.875991f * y + 0.041556f * z,
+ 0.055648f * x + -0.204043f * y + 1.057311f * z);
+}
+
+__device float3 wavelength_lerp(const float3 a, const float3 b, float t)
+{
+ return (a * (1.0f - t) + b * t);
+}
+
+__device void svm_node_wavelength(ShaderData *sd, float *stack, uint wavelength, uint color_out)
+{
+ // CIE colour matching functions xBar, yBar, and zBar for
+ // wavelengths from 380 through 780 nanometers, every 5
+ // nanometers. For a wavelength lambda in this range:
+ // cie_colour_match[(lambda - 380) / 5][0] = xBar
+ // cie_colour_match[(lambda - 380) / 5][1] = yBar
+ // cie_colour_match[(lambda - 380) / 5][2] = zBar
+ float cie_colour_match[81][3] = {
+ {0.0014,0.0000,0.0065}, {0.0022,0.0001,0.0105}, {0.0042,0.0001,0.0201},
+ {0.0076,0.0002,0.0362}, {0.0143,0.0004,0.0679}, {0.0232,0.0006,0.1102},
+ {0.0435,0.0012,0.2074}, {0.0776,0.0022,0.3713}, {0.1344,0.0040,0.6456},
+ {0.2148,0.0073,1.0391}, {0.2839,0.0116,1.3856}, {0.3285,0.0168,1.6230},
+ {0.3483,0.0230,1.7471}, {0.3481,0.0298,1.7826}, {0.3362,0.0380,1.7721},
+ {0.3187,0.0480,1.7441}, {0.2908,0.0600,1.6692}, {0.2511,0.0739,1.5281},
+ {0.1954,0.0910,1.2876}, {0.1421,0.1126,1.0419}, {0.0956,0.1390,0.8130},
+ {0.0580,0.1693,0.6162}, {0.0320,0.2080,0.4652}, {0.0147,0.2586,0.3533},
+ {0.0049,0.3230,0.2720}, {0.0024,0.4073,0.2123}, {0.0093,0.5030,0.1582},
+ {0.0291,0.6082,0.1117}, {0.0633,0.7100,0.0782}, {0.1096,0.7932,0.0573},
+ {0.1655,0.8620,0.0422}, {0.2257,0.9149,0.0298}, {0.2904,0.9540,0.0203},
+ {0.3597,0.9803,0.0134}, {0.4334,0.9950,0.0087}, {0.5121,1.0000,0.0057},
+ {0.5945,0.9950,0.0039}, {0.6784,0.9786,0.0027}, {0.7621,0.9520,0.0021},
+ {0.8425,0.9154,0.0018}, {0.9163,0.8700,0.0017}, {0.9786,0.8163,0.0014},
+ {1.0263,0.7570,0.0011}, {1.0567,0.6949,0.0010}, {1.0622,0.6310,0.0008},
+ {1.0456,0.5668,0.0006}, {1.0026,0.5030,0.0003}, {0.9384,0.4412,0.0002},
+ {0.8544,0.3810,0.0002}, {0.7514,0.3210,0.0001}, {0.6424,0.2650,0.0000},
+ {0.5419,0.2170,0.0000}, {0.4479,0.1750,0.0000}, {0.3608,0.1382,0.0000},
+ {0.2835,0.1070,0.0000}, {0.2187,0.0816,0.0000}, {0.1649,0.0610,0.0000},
+ {0.1212,0.0446,0.0000}, {0.0874,0.0320,0.0000}, {0.0636,0.0232,0.0000},
+ {0.0468,0.0170,0.0000}, {0.0329,0.0119,0.0000}, {0.0227,0.0082,0.0000},
+ {0.0158,0.0057,0.0000}, {0.0114,0.0041,0.0000}, {0.0081,0.0029,0.0000},
+ {0.0058,0.0021,0.0000}, {0.0041,0.0015,0.0000}, {0.0029,0.0010,0.0000},
+ {0.0020,0.0007,0.0000}, {0.0014,0.0005,0.0000}, {0.0010,0.0004,0.0000},
+ {0.0007,0.0002,0.0000}, {0.0005,0.0002,0.0000}, {0.0003,0.0001,0.0000},
+ {0.0002,0.0001,0.0000}, {0.0002,0.0001,0.0000}, {0.0001,0.0000,0.0000},
+ {0.0001,0.0000,0.0000}, {0.0001,0.0000,0.0000}, {0.0000,0.0000,0.0000}
+ };
+
+ float lambda_nm = stack_load_float(stack, wavelength);
+ float3 rgb;
+
+ float ii = (lambda_nm-380.0f) / 5.0f; // scaled 0..80
+ int i = float_to_int(ii);
+ if (i < 0 || i >= 80) {
+ rgb = make_float3(0.0f, 0.0f, 0.0f);
+ }
+ else {
+ ii -= i;
+ float *c = cie_colour_match[i];
+ rgb = wavelength_lerp(make_float3(c[0], c[1], c[2]), make_float3(c[3], c[4], c[5]), ii);
+ }
+
+ rgb = xyz_to_rgb_wave(rgb.x, rgb.y, rgb.z);
+ rgb *= 1.0/2.52; // Empirical scale from lg to make all comps <= 1
+
+ /* Clamp to Zero if values are smaller */
+ rgb = max(rgb, make_float3(0.0f, 0.0f, 0.0f));
+
+ if(stack_valid(color_out))
+ stack_store_float3(stack, color_out, rgb);
+}
+
+CCL_NAMESPACE_END
+
Modified: branches/soc-2013-dingto/intern/cycles/render/nodes.cpp
===================================================================
--- branches/soc-2013-dingto/intern/cycles/render/nodes.cpp 2013-06-09 20:28:16 UTC (rev 57321)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list