forked from bartvdbraak/blender
SeparateRGB and CombineRGB nodes for Cycles materials
reviewed and approved by Brecht my first OpenCL code \o/
This commit is contained in:
parent
b7db2587fb
commit
4db4a0933f
@ -471,6 +471,12 @@ static void xml_read_shader_graph(const XMLReadState& state, Shader *shader, pug
|
|||||||
xml_read_enum(&mix->type, MixNode::type_enum, node, "type");
|
xml_read_enum(&mix->type, MixNode::type_enum, node, "type");
|
||||||
snode = mix;
|
snode = mix;
|
||||||
}
|
}
|
||||||
|
else if(string_iequals(node.name(), "combine_rgb")) {
|
||||||
|
snode = new CombineRGBNode();
|
||||||
|
}
|
||||||
|
else if(string_iequals(node.name(), "separate_rgb")) {
|
||||||
|
snode = new SeparateRGBNode();
|
||||||
|
}
|
||||||
else if(string_iequals(node.name(), "attribute")) {
|
else if(string_iequals(node.name(), "attribute")) {
|
||||||
AttributeNode *attr = new AttributeNode();
|
AttributeNode *attr = new AttributeNode();
|
||||||
xml_read_ustring(&attr->attribute, node, "attribute");
|
xml_read_ustring(&attr->attribute, node, "attribute");
|
||||||
|
@ -128,7 +128,6 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Node *
|
|||||||
switch(b_node.type()) {
|
switch(b_node.type()) {
|
||||||
/* not supported */
|
/* not supported */
|
||||||
case BL::ShaderNode::type_CAMERA: break;
|
case BL::ShaderNode::type_CAMERA: break;
|
||||||
case BL::ShaderNode::type_COMBRGB: break;
|
|
||||||
case BL::ShaderNode::type_CURVE_RGB: break;
|
case BL::ShaderNode::type_CURVE_RGB: break;
|
||||||
case BL::ShaderNode::type_CURVE_VEC: break;
|
case BL::ShaderNode::type_CURVE_VEC: break;
|
||||||
case BL::ShaderNode::type_GEOMETRY: break;
|
case BL::ShaderNode::type_GEOMETRY: break;
|
||||||
@ -139,7 +138,6 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Node *
|
|||||||
case BL::ShaderNode::type_NORMAL: break;
|
case BL::ShaderNode::type_NORMAL: break;
|
||||||
case BL::ShaderNode::type_OUTPUT: break;
|
case BL::ShaderNode::type_OUTPUT: break;
|
||||||
case BL::ShaderNode::type_SCRIPT: break;
|
case BL::ShaderNode::type_SCRIPT: break;
|
||||||
case BL::ShaderNode::type_SEPRGB: break;
|
|
||||||
case BL::ShaderNode::type_SQUEEZE: break;
|
case BL::ShaderNode::type_SQUEEZE: break;
|
||||||
case BL::ShaderNode::type_TEXTURE: break;
|
case BL::ShaderNode::type_TEXTURE: break;
|
||||||
case BL::ShaderNode::type_VALTORGB: break;
|
case BL::ShaderNode::type_VALTORGB: break;
|
||||||
@ -165,6 +163,14 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Node *
|
|||||||
node = mix;
|
node = mix;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case BL::ShaderNode::type_SEPRGB: {
|
||||||
|
node = new SeparateRGBNode();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BL::ShaderNode::type_COMBRGB: {
|
||||||
|
node = new CombineRGBNode();
|
||||||
|
break;
|
||||||
|
}
|
||||||
case BL::ShaderNode::type_RGBTOBW: {
|
case BL::ShaderNode::type_RGBTOBW: {
|
||||||
node = new ConvertNode(SHADER_SOCKET_COLOR, SHADER_SOCKET_FLOAT);
|
node = new ConvertNode(SHADER_SOCKET_COLOR, SHADER_SOCKET_FLOAT);
|
||||||
break;
|
break;
|
||||||
|
@ -69,6 +69,7 @@ set(SRC_SVM_HEADERS
|
|||||||
svm/svm_musgrave.h
|
svm/svm_musgrave.h
|
||||||
svm/svm_noise.h
|
svm/svm_noise.h
|
||||||
svm/svm_noisetex.h
|
svm/svm_noisetex.h
|
||||||
|
svm/svm_sepcomb_rgb.h
|
||||||
svm/svm_sky.h
|
svm/svm_sky.h
|
||||||
svm/svm_tex_coord.h
|
svm/svm_tex_coord.h
|
||||||
svm/svm_texture.h
|
svm/svm_texture.h
|
||||||
|
@ -35,6 +35,7 @@ set(SRC_OSL
|
|||||||
node_output_displacement.osl
|
node_output_displacement.osl
|
||||||
node_output_surface.osl
|
node_output_surface.osl
|
||||||
node_output_volume.osl
|
node_output_volume.osl
|
||||||
|
node_sepcomb_rgb.osl
|
||||||
node_sky_texture.osl
|
node_sky_texture.osl
|
||||||
node_stucci_texture.osl
|
node_stucci_texture.osl
|
||||||
node_texture_coordinate.osl
|
node_texture_coordinate.osl
|
||||||
|
40
intern/cycles/kernel/osl/nodes/node_sepcomb_rgb.osl
Normal file
40
intern/cycles/kernel/osl/nodes/node_sepcomb_rgb.osl
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, 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_separate_rgb(
|
||||||
|
color Image = color(0.8, 0.8, 0.8),
|
||||||
|
output float R = 0.0,
|
||||||
|
output float G = 0.0,
|
||||||
|
output float B = 0.0)
|
||||||
|
{
|
||||||
|
R = Image[0];
|
||||||
|
G = Image[1];
|
||||||
|
B = Image[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
shader node_combine_rgb(
|
||||||
|
float R = 0.0,
|
||||||
|
float G = 0.0,
|
||||||
|
float B = 0.0,
|
||||||
|
output color Image = color(0.8, 0.8, 0.8)
|
||||||
|
{
|
||||||
|
Image = color(R, G, B)
|
||||||
|
}
|
||||||
|
|
@ -134,6 +134,7 @@ CCL_NAMESPACE_END
|
|||||||
#include "svm_wave.h"
|
#include "svm_wave.h"
|
||||||
#include "svm_math.h"
|
#include "svm_math.h"
|
||||||
#include "svm_mix.h"
|
#include "svm_mix.h"
|
||||||
|
#include "svm_sepcomb_rgb.h"
|
||||||
#include "svm_musgrave.h"
|
#include "svm_musgrave.h"
|
||||||
#include "svm_sky.h"
|
#include "svm_sky.h"
|
||||||
#include "svm_tex_coord.h"
|
#include "svm_tex_coord.h"
|
||||||
@ -254,6 +255,12 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT
|
|||||||
case NODE_MIX:
|
case NODE_MIX:
|
||||||
svm_node_mix(kg, sd, stack, node.y, node.z, node.w, &offset);
|
svm_node_mix(kg, sd, stack, node.y, node.z, node.w, &offset);
|
||||||
break;
|
break;
|
||||||
|
case NODE_SEPARATE_RGB:
|
||||||
|
svm_node_separate_rgb(sd, stack, node.y, node.z, node.w);
|
||||||
|
break;
|
||||||
|
case NODE_COMBINE_RGB:
|
||||||
|
svm_node_combine_rgb(sd, stack, node.y, node.z, node.w);
|
||||||
|
break;
|
||||||
case NODE_ATTR:
|
case NODE_ATTR:
|
||||||
svm_node_attr(kg, sd, stack, node);
|
svm_node_attr(kg, sd, stack, node);
|
||||||
break;
|
break;
|
||||||
|
38
intern/cycles/kernel/svm/svm_sepcomb_rgb.h
Normal file
38
intern/cycles/kernel/svm/svm_sepcomb_rgb.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
CCL_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
__device void svm_node_combine_rgb(ShaderData *sd, float *stack, uint in_offset, uint color_index, uint out_offset)
|
||||||
|
{
|
||||||
|
float color = stack_load_float(stack, in_offset);
|
||||||
|
|
||||||
|
if (stack_valid(out_offset))
|
||||||
|
stack_store_float(stack, out_offset+color_index, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device void svm_node_separate_rgb(ShaderData *sd, float *stack, uint icolor_offset, uint color_index, uint out_offset)
|
||||||
|
{
|
||||||
|
float3 color = stack_load_float3(stack, icolor_offset);
|
||||||
|
|
||||||
|
if (stack_valid(out_offset))
|
||||||
|
stack_store_float(stack, out_offset, color[color_index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
CCL_NAMESPACE_END
|
||||||
|
|
@ -79,7 +79,9 @@ typedef enum NodeType {
|
|||||||
NODE_TEX_ENVIRONMENT = 4600,
|
NODE_TEX_ENVIRONMENT = 4600,
|
||||||
NODE_CLOSURE_HOLDOUT = 4700,
|
NODE_CLOSURE_HOLDOUT = 4700,
|
||||||
NODE_LAYER_WEIGHT = 4800,
|
NODE_LAYER_WEIGHT = 4800,
|
||||||
NODE_CLOSURE_VOLUME = 4900
|
NODE_CLOSURE_VOLUME = 4900,
|
||||||
|
NODE_SEPARATE_RGB = 5000,
|
||||||
|
NODE_COMBINE_RGB = 5100
|
||||||
} NodeType;
|
} NodeType;
|
||||||
|
|
||||||
typedef enum NodeAttributeType {
|
typedef enum NodeAttributeType {
|
||||||
|
@ -1629,6 +1629,74 @@ void MixNode::compile(OSLCompiler& compiler)
|
|||||||
compiler.add(this, "node_mix");
|
compiler.add(this, "node_mix");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Combine RGB */
|
||||||
|
CombineRGBNode::CombineRGBNode()
|
||||||
|
: ShaderNode("combine_rgb")
|
||||||
|
{
|
||||||
|
add_input("R", SHADER_SOCKET_FLOAT);
|
||||||
|
add_input("G", SHADER_SOCKET_FLOAT);
|
||||||
|
add_input("B", SHADER_SOCKET_FLOAT);
|
||||||
|
add_output("Image", SHADER_SOCKET_COLOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CombineRGBNode::compile(SVMCompiler& compiler)
|
||||||
|
{
|
||||||
|
ShaderInput *red_in = input("R");
|
||||||
|
ShaderInput *green_in = input("G");
|
||||||
|
ShaderInput *blue_in = input("B");
|
||||||
|
ShaderOutput *color_out = output("Image");
|
||||||
|
|
||||||
|
compiler.stack_assign(color_out);
|
||||||
|
|
||||||
|
compiler.stack_assign(red_in);
|
||||||
|
compiler.add_node(NODE_COMBINE_RGB, red_in->stack_offset, 0, color_out->stack_offset);
|
||||||
|
|
||||||
|
compiler.stack_assign(green_in);
|
||||||
|
compiler.add_node(NODE_COMBINE_RGB, green_in->stack_offset, 1, color_out->stack_offset);
|
||||||
|
|
||||||
|
compiler.stack_assign(blue_in);
|
||||||
|
compiler.add_node(NODE_COMBINE_RGB, blue_in->stack_offset, 2, color_out->stack_offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CombineRGBNode::compile(OSLCompiler& compiler)
|
||||||
|
{
|
||||||
|
compiler.add(this, "node_combine_rgb");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Separate RGB */
|
||||||
|
SeparateRGBNode::SeparateRGBNode()
|
||||||
|
: ShaderNode("separate_rgb")
|
||||||
|
{
|
||||||
|
add_input("Image", SHADER_SOCKET_COLOR);
|
||||||
|
add_output("R", SHADER_SOCKET_FLOAT);
|
||||||
|
add_output("G", SHADER_SOCKET_FLOAT);
|
||||||
|
add_output("B", SHADER_SOCKET_FLOAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SeparateRGBNode::compile(SVMCompiler& compiler)
|
||||||
|
{
|
||||||
|
ShaderInput *color_in = input("Image");
|
||||||
|
ShaderOutput *red_out = output("R");
|
||||||
|
ShaderOutput *green_out = output("G");
|
||||||
|
ShaderOutput *blue_out = output("B");
|
||||||
|
|
||||||
|
compiler.stack_assign(color_in);
|
||||||
|
|
||||||
|
compiler.stack_assign(red_out);
|
||||||
|
compiler.add_node(NODE_SEPARATE_RGB, color_in->stack_offset, 0, red_out->stack_offset);
|
||||||
|
|
||||||
|
compiler.stack_assign(green_out);
|
||||||
|
compiler.add_node(NODE_SEPARATE_RGB, color_in->stack_offset, 1, green_out->stack_offset);
|
||||||
|
|
||||||
|
compiler.stack_assign(blue_out);
|
||||||
|
compiler.add_node(NODE_SEPARATE_RGB, color_in->stack_offset, 2, blue_out->stack_offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SeparateRGBNode::compile(OSLCompiler& compiler)
|
||||||
|
{
|
||||||
|
compiler.add(this, "node_separate_rgb");
|
||||||
|
}
|
||||||
|
|
||||||
/* Attribute */
|
/* Attribute */
|
||||||
|
|
||||||
AttributeNode::AttributeNode()
|
AttributeNode::AttributeNode()
|
||||||
|
@ -292,6 +292,16 @@ public:
|
|||||||
static ShaderEnum type_enum;
|
static ShaderEnum type_enum;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CombineRGBNode : public ShaderNode {
|
||||||
|
public:
|
||||||
|
SHADER_NODE_CLASS(CombineRGBNode)
|
||||||
|
};
|
||||||
|
|
||||||
|
class SeparateRGBNode : public ShaderNode {
|
||||||
|
public:
|
||||||
|
SHADER_NODE_CLASS(SeparateRGBNode)
|
||||||
|
};
|
||||||
|
|
||||||
class AttributeNode : public ShaderNode {
|
class AttributeNode : public ShaderNode {
|
||||||
public:
|
public:
|
||||||
SHADER_NODE_CLASS(AttributeNode)
|
SHADER_NODE_CLASS(AttributeNode)
|
||||||
|
@ -61,7 +61,7 @@ void register_node_type_sh_seprgb(bNodeTreeType *ttype)
|
|||||||
static bNodeType ntype;
|
static bNodeType ntype;
|
||||||
|
|
||||||
node_type_base(ttype, &ntype, SH_NODE_SEPRGB, "Separate RGB", NODE_CLASS_CONVERTOR, 0);
|
node_type_base(ttype, &ntype, SH_NODE_SEPRGB, "Separate RGB", NODE_CLASS_CONVERTOR, 0);
|
||||||
node_type_compatibility(&ntype, NODE_OLD_SHADING);
|
node_type_compatibility(&ntype, NODE_OLD_SHADING|NODE_NEW_SHADING);
|
||||||
node_type_socket_templates(&ntype, sh_node_seprgb_in, sh_node_seprgb_out);
|
node_type_socket_templates(&ntype, sh_node_seprgb_in, sh_node_seprgb_out);
|
||||||
node_type_size(&ntype, 80, 40, 140);
|
node_type_size(&ntype, 80, 40, 140);
|
||||||
node_type_exec(&ntype, node_shader_exec_seprgb);
|
node_type_exec(&ntype, node_shader_exec_seprgb);
|
||||||
@ -101,7 +101,7 @@ void register_node_type_sh_combrgb(bNodeTreeType *ttype)
|
|||||||
static bNodeType ntype;
|
static bNodeType ntype;
|
||||||
|
|
||||||
node_type_base(ttype, &ntype, SH_NODE_COMBRGB, "Combine RGB", NODE_CLASS_CONVERTOR, NODE_OPTIONS);
|
node_type_base(ttype, &ntype, SH_NODE_COMBRGB, "Combine RGB", NODE_CLASS_CONVERTOR, NODE_OPTIONS);
|
||||||
node_type_compatibility(&ntype, NODE_OLD_SHADING);
|
node_type_compatibility(&ntype, NODE_OLD_SHADING|NODE_NEW_SHADING);
|
||||||
node_type_socket_templates(&ntype, sh_node_combrgb_in, sh_node_combrgb_out);
|
node_type_socket_templates(&ntype, sh_node_combrgb_in, sh_node_combrgb_out);
|
||||||
node_type_size(&ntype, 80, 40, 140);
|
node_type_size(&ntype, 80, 40, 140);
|
||||||
node_type_exec(&ntype, node_shader_exec_combrgb);
|
node_type_exec(&ntype, node_shader_exec_combrgb);
|
||||||
|
Loading…
Reference in New Issue
Block a user