forked from bartvdbraak/blender
Cycles: checker texture node, patch by Thomas.
This commit is contained in:
parent
4487103e61
commit
8bfa48384d
@ -349,6 +349,9 @@ static void xml_read_shader_graph(const XMLReadState& state, Shader *shader, pug
|
|||||||
else if(string_iequals(node.name(), "noise_texture")) {
|
else if(string_iequals(node.name(), "noise_texture")) {
|
||||||
snode = new NoiseTextureNode();
|
snode = new NoiseTextureNode();
|
||||||
}
|
}
|
||||||
|
else if(string_iequals(node.name(), "checker_texture")) {
|
||||||
|
snode = new CheckerTextureNode();
|
||||||
|
}
|
||||||
else if(string_iequals(node.name(), "gradient_texture")) {
|
else if(string_iequals(node.name(), "gradient_texture")) {
|
||||||
GradientTextureNode *blend = new GradientTextureNode();
|
GradientTextureNode *blend = new GradientTextureNode();
|
||||||
xml_read_enum(&blend->type, GradientTextureNode::type_enum, node, "type");
|
xml_read_enum(&blend->type, GradientTextureNode::type_enum, node, "type");
|
||||||
|
@ -364,6 +364,13 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Shader
|
|||||||
node = wave;
|
node = wave;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case BL::ShaderNode::type_TEX_CHECKER: {
|
||||||
|
BL::ShaderNodeTexChecker b_checker_node(b_node);
|
||||||
|
CheckerTextureNode *checker = new CheckerTextureNode();
|
||||||
|
get_tex_mapping(&checker->tex_mapping, b_checker_node.texture_mapping());
|
||||||
|
node = checker;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case BL::ShaderNode::type_TEX_NOISE: {
|
case BL::ShaderNode::type_TEX_NOISE: {
|
||||||
BL::ShaderNodeTexNoise b_noise_node(b_node);
|
BL::ShaderNodeTexNoise b_noise_node(b_node);
|
||||||
NoiseTextureNode *noise = new NoiseTextureNode();
|
NoiseTextureNode *noise = new NoiseTextureNode();
|
||||||
|
@ -57,6 +57,7 @@ set(SRC_SVM_HEADERS
|
|||||||
svm/svm_camera.h
|
svm/svm_camera.h
|
||||||
svm/svm_closure.h
|
svm/svm_closure.h
|
||||||
svm/svm_convert.h
|
svm/svm_convert.h
|
||||||
|
svm/svm_checker.h
|
||||||
svm/svm_displace.h
|
svm/svm_displace.h
|
||||||
svm/svm_fresnel.h
|
svm/svm_fresnel.h
|
||||||
svm/svm_gamma.h
|
svm/svm_gamma.h
|
||||||
|
@ -145,6 +145,7 @@ CCL_NAMESPACE_END
|
|||||||
#include "svm_tex_coord.h"
|
#include "svm_tex_coord.h"
|
||||||
#include "svm_value.h"
|
#include "svm_value.h"
|
||||||
#include "svm_voronoi.h"
|
#include "svm_voronoi.h"
|
||||||
|
#include "svm_checker.h"
|
||||||
|
|
||||||
CCL_NAMESPACE_BEGIN
|
CCL_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@ -235,6 +236,9 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT
|
|||||||
case NODE_TEX_MAGIC:
|
case NODE_TEX_MAGIC:
|
||||||
svm_node_tex_magic(kg, sd, stack, node, &offset);
|
svm_node_tex_magic(kg, sd, stack, node, &offset);
|
||||||
break;
|
break;
|
||||||
|
case NODE_TEX_CHECKER:
|
||||||
|
svm_node_tex_checker(kg, sd, stack, node, &offset);
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
case NODE_CAMERA:
|
case NODE_CAMERA:
|
||||||
svm_node_camera(kg, sd, stack, node.y, node.z, node.w);
|
svm_node_camera(kg, sd, stack, node.y, node.z, node.w);
|
||||||
|
57
intern/cycles/kernel/svm/svm_checker.h
Normal file
57
intern/cycles/kernel/svm/svm_checker.h
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
/* Checker */
|
||||||
|
|
||||||
|
__device_noinline float svm_checker(float3 p, float scale)
|
||||||
|
{
|
||||||
|
p *= scale;
|
||||||
|
|
||||||
|
/* 0.00001 because of unit sized stuff */
|
||||||
|
int xi = (int)fabsf(floor(0.00001f + p.x));
|
||||||
|
int yi = (int)fabsf(floor(0.00001f + p.y));
|
||||||
|
int zi = (int)fabsf(floor(0.00001f + p.z));
|
||||||
|
|
||||||
|
return ((xi % 2 == yi % 2) == (zi % 2))? 1.0f: 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
__device void svm_node_tex_checker(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
|
||||||
|
{
|
||||||
|
uint co_offset, color1_offset, color2_offset, scale_offset;
|
||||||
|
uint color_offset, fac_offset;
|
||||||
|
|
||||||
|
decode_node_uchar4(node.y, &co_offset, &color1_offset, &color2_offset, &scale_offset);
|
||||||
|
decode_node_uchar4(node.z, &color_offset, &fac_offset, NULL, NULL);
|
||||||
|
|
||||||
|
float3 co = stack_load_float3(stack, co_offset);
|
||||||
|
float3 color1 = stack_load_float3(stack, color1_offset);
|
||||||
|
float3 color2 = stack_load_float3(stack, color2_offset);
|
||||||
|
float scale = stack_load_float_default(stack, scale_offset, node.w);
|
||||||
|
|
||||||
|
float f = svm_checker(co, scale);
|
||||||
|
|
||||||
|
if(stack_valid(color_offset))
|
||||||
|
stack_store_float3(stack, color_offset, (f == 1.0f)? color1: color2);
|
||||||
|
if(stack_valid(fac_offset))
|
||||||
|
stack_store_float(stack, fac_offset, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
CCL_NAMESPACE_END
|
||||||
|
|
@ -86,7 +86,8 @@ typedef enum NodeType {
|
|||||||
NODE_CAMERA = 5300,
|
NODE_CAMERA = 5300,
|
||||||
NODE_INVERT = 5400,
|
NODE_INVERT = 5400,
|
||||||
NODE_NORMAL = 5500,
|
NODE_NORMAL = 5500,
|
||||||
NODE_GAMMA = 5600
|
NODE_GAMMA = 5600,
|
||||||
|
NODE_TEX_CHECKER = 5700
|
||||||
} NodeType;
|
} NodeType;
|
||||||
|
|
||||||
typedef enum NodeAttributeType {
|
typedef enum NodeAttributeType {
|
||||||
|
@ -712,6 +712,54 @@ void MagicTextureNode::compile(OSLCompiler& compiler)
|
|||||||
compiler.add(this, "node_magic_texture");
|
compiler.add(this, "node_magic_texture");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Checker Texture */
|
||||||
|
|
||||||
|
CheckerTextureNode::CheckerTextureNode()
|
||||||
|
: TextureNode("checker_texture")
|
||||||
|
{
|
||||||
|
add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_GENERATED);
|
||||||
|
add_input("Color1", SHADER_SOCKET_COLOR);
|
||||||
|
add_input("Color2", SHADER_SOCKET_COLOR);
|
||||||
|
add_input("Scale", SHADER_SOCKET_FLOAT, 1.0f);
|
||||||
|
|
||||||
|
add_output("Color", SHADER_SOCKET_COLOR);
|
||||||
|
add_output("Fac", SHADER_SOCKET_FLOAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckerTextureNode::compile(SVMCompiler& compiler)
|
||||||
|
{
|
||||||
|
ShaderInput *vector_in = input("Vector");
|
||||||
|
ShaderInput *color1_in = input("Color1");
|
||||||
|
ShaderInput *color2_in = input("Color2");
|
||||||
|
ShaderInput *scale_in = input("Scale");
|
||||||
|
|
||||||
|
ShaderOutput *color_out = output("Color");
|
||||||
|
ShaderOutput *fac_out = output("Fac");
|
||||||
|
|
||||||
|
compiler.stack_assign(vector_in);
|
||||||
|
compiler.stack_assign(color1_in);
|
||||||
|
compiler.stack_assign(color2_in);
|
||||||
|
if(scale_in->link) compiler.stack_assign(scale_in);
|
||||||
|
|
||||||
|
if(!tex_mapping.skip())
|
||||||
|
tex_mapping.compile(compiler, vector_in->stack_offset, vector_in->stack_offset);
|
||||||
|
|
||||||
|
if(!color_out->links.empty())
|
||||||
|
compiler.stack_assign(color_out);
|
||||||
|
if(!fac_out->links.empty())
|
||||||
|
compiler.stack_assign(fac_out);
|
||||||
|
|
||||||
|
compiler.add_node(NODE_TEX_CHECKER,
|
||||||
|
compiler.encode_uchar4(vector_in->stack_offset, color1_in->stack_offset, color2_in->stack_offset, scale_in->stack_offset),
|
||||||
|
compiler.encode_uchar4(color_out->stack_offset, fac_out->stack_offset),
|
||||||
|
__float_as_int(scale_in->value.x));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckerTextureNode::compile(OSLCompiler& compiler)
|
||||||
|
{
|
||||||
|
compiler.add(this, "node_checker_texture");
|
||||||
|
}
|
||||||
|
|
||||||
/* Normal */
|
/* Normal */
|
||||||
|
|
||||||
NormalNode::NormalNode()
|
NormalNode::NormalNode()
|
||||||
|
@ -143,6 +143,11 @@ public:
|
|||||||
int depth;
|
int depth;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CheckerTextureNode : public TextureNode {
|
||||||
|
public:
|
||||||
|
SHADER_NODE_CLASS(CheckerTextureNode)
|
||||||
|
};
|
||||||
|
|
||||||
class MappingNode : public ShaderNode {
|
class MappingNode : public ShaderNode {
|
||||||
public:
|
public:
|
||||||
SHADER_NODE_CLASS(MappingNode)
|
SHADER_NODE_CLASS(MappingNode)
|
||||||
|
@ -522,6 +522,7 @@ struct ShadeResult;
|
|||||||
#define SH_NODE_VOLUME_TRANSPARENT 161
|
#define SH_NODE_VOLUME_TRANSPARENT 161
|
||||||
#define SH_NODE_VOLUME_ISOTROPIC 162
|
#define SH_NODE_VOLUME_ISOTROPIC 162
|
||||||
#define SH_NODE_GAMMA 163
|
#define SH_NODE_GAMMA 163
|
||||||
|
#define SH_NODE_TEX_CHECKER 164
|
||||||
|
|
||||||
/* custom defines options for Material node */
|
/* custom defines options for Material node */
|
||||||
#define SH_NODE_MAT_DIFF 1
|
#define SH_NODE_MAT_DIFF 1
|
||||||
|
@ -1945,6 +1945,7 @@ static void registerShaderNodes(bNodeTreeType *ttype)
|
|||||||
register_node_type_sh_tex_musgrave(ttype);
|
register_node_type_sh_tex_musgrave(ttype);
|
||||||
register_node_type_sh_tex_gradient(ttype);
|
register_node_type_sh_tex_gradient(ttype);
|
||||||
register_node_type_sh_tex_magic(ttype);
|
register_node_type_sh_tex_magic(ttype);
|
||||||
|
register_node_type_sh_tex_checker(ttype);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void registerTextureNodes(bNodeTreeType *ttype)
|
static void registerTextureNodes(bNodeTreeType *ttype)
|
||||||
|
@ -448,6 +448,10 @@ typedef struct NodeTexImage {
|
|||||||
int color_space, pad;
|
int color_space, pad;
|
||||||
} NodeTexImage;
|
} NodeTexImage;
|
||||||
|
|
||||||
|
typedef struct NodeTexChecker {
|
||||||
|
NodeTexBase base;
|
||||||
|
} NodeTexChecker;
|
||||||
|
|
||||||
typedef struct NodeTexEnvironment {
|
typedef struct NodeTexEnvironment {
|
||||||
NodeTexBase base;
|
NodeTexBase base;
|
||||||
int color_space, pad;
|
int color_space, pad;
|
||||||
|
@ -1333,6 +1333,12 @@ static void def_sh_tex_noise(StructRNA *srna)
|
|||||||
def_sh_tex(srna);
|
def_sh_tex(srna);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void def_sh_tex_checker(StructRNA *srna)
|
||||||
|
{
|
||||||
|
RNA_def_struct_sdna_from(srna, "NodeTexChecker", "storage");
|
||||||
|
def_sh_tex(srna);
|
||||||
|
}
|
||||||
|
|
||||||
static void def_sh_tex_magic(StructRNA *srna)
|
static void def_sh_tex_magic(StructRNA *srna)
|
||||||
{
|
{
|
||||||
PropertyRNA *prop;
|
PropertyRNA *prop;
|
||||||
|
@ -85,6 +85,7 @@ DefNode( ShaderNode, SH_NODE_TEX_MAGIC, def_sh_tex_magic, "TE
|
|||||||
DefNode( ShaderNode, SH_NODE_TEX_WAVE, def_sh_tex_wave, "TEX_WAVE", TexWave, "Wave Texture", "" )
|
DefNode( ShaderNode, SH_NODE_TEX_WAVE, def_sh_tex_wave, "TEX_WAVE", TexWave, "Wave Texture", "" )
|
||||||
DefNode( ShaderNode, SH_NODE_TEX_MUSGRAVE, def_sh_tex_musgrave, "TEX_MUSGRAVE", TexMusgrave, "Musgrave Texture", "" )
|
DefNode( ShaderNode, SH_NODE_TEX_MUSGRAVE, def_sh_tex_musgrave, "TEX_MUSGRAVE", TexMusgrave, "Musgrave Texture", "" )
|
||||||
DefNode( ShaderNode, SH_NODE_TEX_VORONOI, def_sh_tex_voronoi, "TEX_VORONOI", TexVoronoi, "Voronoi Texture", "" )
|
DefNode( ShaderNode, SH_NODE_TEX_VORONOI, def_sh_tex_voronoi, "TEX_VORONOI", TexVoronoi, "Voronoi Texture", "" )
|
||||||
|
DefNode( ShaderNode, SH_NODE_TEX_CHECKER, def_sh_tex_checker, "TEX_CHECKER", TexChecker, "Checker Texture", "" )
|
||||||
DefNode( ShaderNode, SH_NODE_TEX_COORD, 0, "TEX_COORD", TexCoord, "Texture Coordinate","")
|
DefNode( ShaderNode, SH_NODE_TEX_COORD, 0, "TEX_COORD", TexCoord, "Texture Coordinate","")
|
||||||
|
|
||||||
DefNode( CompositorNode, CMP_NODE_VIEWER, 0, "VIEWER", Viewer, "Viewer", "" )
|
DefNode( CompositorNode, CMP_NODE_VIEWER, 0, "VIEWER", Viewer, "Viewer", "" )
|
||||||
|
@ -162,6 +162,7 @@ set(SRC
|
|||||||
shader/nodes/node_shader_tex_sky.c
|
shader/nodes/node_shader_tex_sky.c
|
||||||
shader/nodes/node_shader_tex_voronoi.c
|
shader/nodes/node_shader_tex_voronoi.c
|
||||||
shader/nodes/node_shader_tex_wave.c
|
shader/nodes/node_shader_tex_wave.c
|
||||||
|
shader/nodes/node_shader_tex_checker.c
|
||||||
shader/node_shader_tree.c
|
shader/node_shader_tree.c
|
||||||
shader/node_shader_util.c
|
shader/node_shader_util.c
|
||||||
|
|
||||||
|
@ -103,6 +103,7 @@ void register_node_type_sh_tex_magic(struct bNodeTreeType *ttype);
|
|||||||
void register_node_type_sh_tex_wave(struct bNodeTreeType *ttype);
|
void register_node_type_sh_tex_wave(struct bNodeTreeType *ttype);
|
||||||
void register_node_type_sh_tex_musgrave(struct bNodeTreeType *ttype);
|
void register_node_type_sh_tex_musgrave(struct bNodeTreeType *ttype);
|
||||||
void register_node_type_sh_tex_noise(struct bNodeTreeType *ttype);
|
void register_node_type_sh_tex_noise(struct bNodeTreeType *ttype);
|
||||||
|
void register_node_type_sh_tex_checker(struct bNodeTreeType *ttype);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
80
source/blender/nodes/shader/nodes/node_shader_tex_checker.c
Normal file
80
source/blender/nodes/shader/nodes/node_shader_tex_checker.c
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* ***** 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"
|
||||||
|
|
||||||
|
/* **************** OUTPUT ******************** */
|
||||||
|
|
||||||
|
static bNodeSocketTemplate sh_node_tex_checker_in[]= {
|
||||||
|
{ SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
|
||||||
|
{ SOCK_RGBA, 1, "Color1", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
|
||||||
|
{ SOCK_RGBA, 1, "Color2", 0.2f, 0.2f, 0.2f, 1.0f, 0.0f, 1.0f},
|
||||||
|
{ SOCK_FLOAT, 1, "Scale", 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f},
|
||||||
|
{ -1, 0, "" }
|
||||||
|
};
|
||||||
|
|
||||||
|
static bNodeSocketTemplate sh_node_tex_checker_out[]= {
|
||||||
|
{ SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
|
||||||
|
{ SOCK_FLOAT, 0, "Fac", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
|
||||||
|
{ -1, 0, "" }
|
||||||
|
};
|
||||||
|
|
||||||
|
static void node_shader_init_tex_checker(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
|
||||||
|
{
|
||||||
|
NodeTexChecker *tex = MEM_callocN(sizeof(NodeTexChecker), "NodeTexChecker");
|
||||||
|
default_tex_mapping(&tex->base.tex_mapping);
|
||||||
|
default_color_mapping(&tex->base.color_mapping);
|
||||||
|
|
||||||
|
node->storage = tex;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int node_shader_gpu_tex_checker(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
|
||||||
|
{
|
||||||
|
if(!in[0].link)
|
||||||
|
in[0].link = GPU_attribute(CD_ORCO, "");
|
||||||
|
|
||||||
|
node_shader_gpu_tex_mapping(mat, node, in, out);
|
||||||
|
|
||||||
|
return GPU_stack_link(mat, "node_tex_checker", in, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* node type definition */
|
||||||
|
void register_node_type_sh_tex_checker(bNodeTreeType *ttype)
|
||||||
|
{
|
||||||
|
static bNodeType ntype;
|
||||||
|
|
||||||
|
node_type_base(ttype, &ntype, SH_NODE_TEX_CHECKER, "Checker Texture", NODE_CLASS_TEXTURE, 0);
|
||||||
|
node_type_compatibility(&ntype, NODE_NEW_SHADING);
|
||||||
|
node_type_socket_templates(&ntype, sh_node_tex_checker_in, sh_node_tex_checker_out);
|
||||||
|
node_type_size(&ntype, 150, 60, 200);
|
||||||
|
node_type_init(&ntype, node_shader_init_tex_checker);
|
||||||
|
node_type_storage(&ntype, "NodeTexChecker", node_free_standard_storage, node_copy_standard_storage);
|
||||||
|
node_type_exec(&ntype, NULL);
|
||||||
|
node_type_gpu(&ntype, node_shader_gpu_tex_checker);
|
||||||
|
|
||||||
|
nodeRegisterType(ttype, &ntype);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user