Cycles: Add dedicated nodes to split/combine vectors.

This was already possible via the RGB nodes, but that seems weird.
This commit is contained in:
Thomas Dinges 2014-06-13 21:44:48 +02:00
parent 49df707496
commit 3de3987ea1
Notes: blender-bot 2023-02-14 11:00:17 +01:00
Referenced by issue #41280, Discrepancy in release process
18 changed files with 298 additions and 2 deletions

View File

@ -633,6 +633,12 @@ static void xml_read_shader_graph(const XMLReadState& state, Shader *shader, pug
else if(string_iequals(node.name(), "separate_hsv")) {
snode = new SeparateHSVNode();
}
else if(string_iequals(node.name(), "combine_xyz")) {
snode = new CombineHSVNode();
}
else if(string_iequals(node.name(), "separate_xyz")) {
snode = new SeparateHSVNode();
}
else if(string_iequals(node.name(), "hsv")) {
snode = new HSVNode();
}

View File

@ -244,6 +244,12 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen
else if (b_node.is_a(&RNA_ShaderNodeCombineHSV)) {
node = new CombineHSVNode();
}
else if (b_node.is_a(&RNA_ShaderNodeSeparateXYZ)) {
node = new SeparateXYZNode();
}
else if (b_node.is_a(&RNA_ShaderNodeCombineXYZ)) {
node = new CombineXYZNode();
}
else if (b_node.is_a(&RNA_ShaderNodeHueSaturation)) {
node = new HSVNode();
}

View File

@ -97,6 +97,7 @@ set(SRC_SVM_HEADERS
svm/svm_ramp.h
svm/svm_sepcomb_rgb.h
svm/svm_sepcomb_hsv.h
svm/svm_sepcomb_xyz.h
svm/svm_sky.h
svm/svm_tex_coord.h
svm/svm_texture.h

View File

@ -13,6 +13,7 @@ set(SRC_OSL
node_checker_texture.osl
node_combine_rgb.osl
node_combine_hsv.osl
node_combine_xyz.osl
node_convert_from_color.osl
node_convert_from_float.osl
node_convert_from_int.osl
@ -57,6 +58,7 @@ set(SRC_OSL
node_rgb_ramp.osl
node_separate_rgb.osl
node_separate_hsv.osl
node_separate_xyz.osl
node_set_normal.osl
node_sky_texture.osl
node_subsurface_scattering.osl

View File

@ -0,0 +1,27 @@
/*
* Copyright 2011-2014 Blender Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
#include "stdosl.h"
shader node_combine_xyz(
float X = 0.0,
float Y = 0.0,
float Z = 0.0,
output vector Vector = 0.8)
{
Vector = vector(X, Y, Z);
}

View File

@ -0,0 +1,28 @@
/*
* Copyright 2011-2013 Blender Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
#include "stdosl.h"
shader node_separate_xyz(
vector Vector = 0.8,
output float X = 0.0,
output float Y = 0.0,
output float Z = 0.0)
{
X = Vector[0];
Y = Vector[1];
Z = Vector[2];
}

View File

@ -169,6 +169,7 @@ CCL_NAMESPACE_END
#include "svm_ramp.h"
#include "svm_sepcomb_rgb.h"
#include "svm_sepcomb_hsv.h"
#include "svm_sepcomb_xyz.h"
#include "svm_musgrave.h"
#include "svm_sky.h"
#include "svm_tex_coord.h"
@ -333,6 +334,12 @@ ccl_device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, Shade
case NODE_COMBINE_RGB:
svm_node_combine_rgb(sd, stack, node.y, node.z, node.w);
break;
case NODE_SEPARATE_XYZ:
svm_node_separate_xyz(sd, stack, node.y, node.z, node.w);
break;
case NODE_COMBINE_XYZ:
svm_node_combine_xyz(sd, stack, node.y, node.z, node.w);
break;
case NODE_SEPARATE_HSV:
svm_node_separate_hsv(kg, sd, stack, node.y, node.z, node.w, &offset);
break;

View File

@ -0,0 +1,42 @@
/*
* Copyright 2011-2014 Blender Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
CCL_NAMESPACE_BEGIN
ccl_device void svm_node_combine_xyz(ShaderData *sd, float *stack, uint in_offset, uint vector_index, uint out_offset)
{
float vector = stack_load_float(stack, in_offset);
if (stack_valid(out_offset))
stack_store_float(stack, out_offset+vector_index, vector);
}
ccl_device void svm_node_separate_xyz(ShaderData *sd, float *stack, uint ivector_offset, uint vector_index, uint out_offset)
{
float3 vector = stack_load_float3(stack, ivector_offset);
if (stack_valid(out_offset)) {
if (vector_index == 0)
stack_store_float(stack, out_offset, vector.x);
else if (vector_index == 1)
stack_store_float(stack, out_offset, vector.y);
else
stack_store_float(stack, out_offset, vector.z);
}
}
CCL_NAMESPACE_END

View File

@ -80,6 +80,8 @@ typedef enum NodeType {
NODE_CLOSURE_VOLUME,
NODE_SEPARATE_RGB,
NODE_COMBINE_RGB,
NODE_SEPARATE_XYZ,
NODE_COMBINE_XYZ,
NODE_SEPARATE_HSV,
NODE_COMBINE_HSV,
NODE_HSV,

View File

@ -3056,6 +3056,40 @@ void CombineRGBNode::compile(OSLCompiler& compiler)
compiler.add(this, "node_combine_rgb");
}
/* Combine XYZ */
CombineXYZNode::CombineXYZNode()
: ShaderNode("combine_xyz")
{
add_input("X", SHADER_SOCKET_FLOAT);
add_input("Y", SHADER_SOCKET_FLOAT);
add_input("Z", SHADER_SOCKET_FLOAT);
add_output("Vector", SHADER_SOCKET_VECTOR);
}
void CombineXYZNode::compile(SVMCompiler& compiler)
{
ShaderInput *x_in = input("X");
ShaderInput *y_in = input("Y");
ShaderInput *z_in = input("Z");
ShaderOutput *vector_out = output("Vector");
compiler.stack_assign(vector_out);
compiler.stack_assign(x_in);
compiler.add_node(NODE_COMBINE_XYZ, x_in->stack_offset, 0, vector_out->stack_offset);
compiler.stack_assign(y_in);
compiler.add_node(NODE_COMBINE_XYZ, y_in->stack_offset, 1, vector_out->stack_offset);
compiler.stack_assign(z_in);
compiler.add_node(NODE_COMBINE_XYZ, z_in->stack_offset, 2, vector_out->stack_offset);
}
void CombineXYZNode::compile(OSLCompiler& compiler)
{
compiler.add(this, "node_combine_xyz");
}
/* Combine HSV */
CombineHSVNode::CombineHSVNode()
: ShaderNode("combine_hsv")
@ -3180,6 +3214,40 @@ void SeparateRGBNode::compile(OSLCompiler& compiler)
compiler.add(this, "node_separate_rgb");
}
/* Separate XYZ */
SeparateXYZNode::SeparateXYZNode()
: ShaderNode("separate_xyz")
{
add_input("Vector", SHADER_SOCKET_VECTOR);
add_output("X", SHADER_SOCKET_FLOAT);
add_output("Y", SHADER_SOCKET_FLOAT);
add_output("Z", SHADER_SOCKET_FLOAT);
}
void SeparateXYZNode::compile(SVMCompiler& compiler)
{
ShaderInput *vector_in = input("Vector");
ShaderOutput *x_out = output("X");
ShaderOutput *y_out = output("Y");
ShaderOutput *z_out = output("Z");
compiler.stack_assign(vector_in);
compiler.stack_assign(x_out);
compiler.add_node(NODE_SEPARATE_XYZ, vector_in->stack_offset, 0, x_out->stack_offset);
compiler.stack_assign(y_out);
compiler.add_node(NODE_SEPARATE_XYZ, vector_in->stack_offset, 1, y_out->stack_offset);
compiler.stack_assign(z_out);
compiler.add_node(NODE_SEPARATE_XYZ, vector_in->stack_offset, 2, z_out->stack_offset);
}
void SeparateXYZNode::compile(OSLCompiler& compiler)
{
compiler.add(this, "node_separate_xyz");
}
/* Separate HSV */
SeparateHSVNode::SeparateHSVNode()
: ShaderNode("separate_hsv")

View File

@ -451,6 +451,11 @@ public:
SHADER_NODE_CLASS(CombineHSVNode)
};
class CombineXYZNode : public ShaderNode {
public:
SHADER_NODE_CLASS(CombineXYZNode)
};
class GammaNode : public ShaderNode {
public:
SHADER_NODE_CLASS(GammaNode)
@ -471,6 +476,11 @@ public:
SHADER_NODE_CLASS(SeparateHSVNode)
};
class SeparateXYZNode : public ShaderNode {
public:
SHADER_NODE_CLASS(SeparateXYZNode)
};
class HSVNode : public ShaderNode {
public:
SHADER_NODE_CLASS(HSVNode)

View File

@ -234,6 +234,8 @@ shader_node_categories = [
NodeItem("ShaderNodeVectorMath"),
NodeItem("ShaderNodeSeparateRGB"),
NodeItem("ShaderNodeCombineRGB"),
NodeItem("ShaderNodeSeparateXYZ"),
NodeItem("ShaderNodeCombineXYZ"),
NodeItem("ShaderNodeSeparateHSV"),
NodeItem("ShaderNodeCombineHSV"),
NodeItem("ShaderNodeWavelength"),

View File

@ -727,7 +727,7 @@ struct ShadeResult;
#define SH_NODE_BRIGHTCONTRAST 165
#define SH_NODE_LIGHT_FALLOFF 166
#define SH_NODE_OBJECT_INFO 167
#define SH_NODE_PARTICLE_INFO 168
#define SH_NODE_PARTICLE_INFO 168
#define SH_NODE_TEX_BRICK 169
#define SH_NODE_BUMP 170
#define SH_NODE_SCRIPT 171
@ -746,7 +746,9 @@ struct ShadeResult;
#define SH_NODE_COMBHSV 184
#define SH_NODE_BSDF_HAIR 185
#define SH_NODE_LAMP 186
#define SH_NODE_UVMAP 187
#define SH_NODE_UVMAP 187
#define SH_NODE_SEPXYZ 188
#define SH_NODE_COMBXYZ 189
/* custom defines options for Material node */
#define SH_NODE_MAT_DIFF 1

View File

@ -3495,6 +3495,8 @@ static void registerShaderNodes(void)
register_node_type_sh_combrgb();
register_node_type_sh_sephsv();
register_node_type_sh_combhsv();
register_node_type_sh_sepxyz();
register_node_type_sh_combxyz();
register_node_type_sh_hue_sat();
register_node_type_sh_attribute();

View File

@ -144,6 +144,7 @@ set(SRC
shader/nodes/node_shader_rgb.c
shader/nodes/node_shader_sepcombRGB.c
shader/nodes/node_shader_sepcombHSV.c
shader/nodes/node_shader_sepcombXYZ.c
shader/nodes/node_shader_squeeze.c
shader/nodes/node_shader_texture.c
shader/nodes/node_shader_valToRgb.c

View File

@ -71,6 +71,8 @@ void register_node_type_sh_seprgb(void);
void register_node_type_sh_combrgb(void);
void register_node_type_sh_sephsv(void);
void register_node_type_sh_combhsv(void);
void register_node_type_sh_sepxyz(void);
void register_node_type_sh_combxyz(void);
void register_node_type_sh_hue_sat(void);
void register_node_type_sh_tex_brick(void);

View File

@ -120,6 +120,8 @@ DefNode( ShaderNode, SH_NODE_VECT_TRANSFORM, def_sh_vect_transform, "VE
DefNode( ShaderNode, SH_NODE_SEPHSV, 0, "SEPHSV", SeparateHSV, "Separate HSV", "" )
DefNode( ShaderNode, SH_NODE_COMBHSV, 0, "COMBHSV", CombineHSV, "Combine HSV", "" )
DefNode( ShaderNode, SH_NODE_UVMAP, def_sh_uvmap, "UVMAP", UVMap, "UV Map", "" )
DefNode( ShaderNode, SH_NODE_SEPXYZ, 0, "SEPXYZ", SeparateXYZ, "Separate XYZ", "" )
DefNode( ShaderNode, SH_NODE_COMBXYZ, 0, "COMBXYZ", CombineXYZ, "Combine XYZ", "" )
DefNode( CompositorNode, CMP_NODE_VIEWER, def_cmp_viewer, "VIEWER", Viewer, "Viewer", "" )
DefNode( CompositorNode, CMP_NODE_RGB, 0, "RGB", RGB, "RGB", "" )

View File

@ -0,0 +1,86 @@
/*
* ***** 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) 2014 Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): Thomas Dinges
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/nodes/shader/nodes/node_shader_sepcombXYZ.c
* \ingroup shdnodes
*/
#include "node_shader_util.h"
/* **************** SEPARATE XYZ ******************** */
static bNodeSocketTemplate sh_node_sepxyz_in[] = {
{ SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f},
{ -1, 0, "" }
};
static bNodeSocketTemplate sh_node_sepxyz_out[] = {
{ SOCK_FLOAT, 0, N_("X")},
{ SOCK_FLOAT, 0, N_("Y")},
{ SOCK_FLOAT, 0, N_("Z")},
{ -1, 0, "" }
};
static int gpu_shader_sep(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "separate_xyz", in, out);
}
void register_node_type_sh_sepxyz(void)
{
static bNodeType ntype;
sh_node_type_base(&ntype, SH_NODE_SEPXYZ, "Separate XYZ", NODE_CLASS_CONVERTOR, 0);
node_type_compatibility(&ntype, NODE_NEW_SHADING);
node_type_socket_templates(&ntype, sh_node_sepxyz_in, sh_node_sepxyz_out);
nodeRegisterType(&ntype);
}
/* **************** COMBINE XYZ ******************** */
static bNodeSocketTemplate sh_node_combxyz_in[] = {
{ SOCK_FLOAT, 1, N_("X"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_UNSIGNED},
{ SOCK_FLOAT, 1, N_("Y"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_UNSIGNED},
{ SOCK_FLOAT, 1, N_("Z"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_UNSIGNED},
{ -1, 0, "" }
};
static bNodeSocketTemplate sh_node_combxyz_out[] = {
{ SOCK_VECTOR, 0, N_("Vector")},
{ -1, 0, "" }
};
void register_node_type_sh_combxyz(void)
{
static bNodeType ntype;
sh_node_type_base(&ntype, SH_NODE_COMBXYZ, "Combine XYZ", NODE_CLASS_CONVERTOR, 0);
node_type_compatibility(&ntype, NODE_NEW_SHADING);
node_type_socket_templates(&ntype, sh_node_combxyz_in, sh_node_combxyz_out);
nodeRegisterType(&ntype);
}