Index: intern/cycles/app/cycles_xml.cpp =================================================================== --- intern/cycles/app/cycles_xml.cpp (revision 43210) +++ intern/cycles/app/cycles_xml.cpp (working copy) @@ -349,6 +349,9 @@ else if(string_iequals(node.name(), "noise_texture")) { snode = new NoiseTextureNode(); } + else if(string_iequals(node.name(), "checker_texture")) { + snode = new CheckerTextureNode(); + } else if(string_iequals(node.name(), "gradient_texture")) { GradientTextureNode *blend = new GradientTextureNode(); xml_read_enum(&blend->type, GradientTextureNode::type_enum, node, "type"); Index: intern/cycles/blender/blender_shader.cpp =================================================================== --- intern/cycles/blender/blender_shader.cpp (revision 43210) +++ intern/cycles/blender/blender_shader.cpp (working copy) @@ -364,6 +364,13 @@ node = wave; 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: { BL::ShaderNodeTexNoise b_noise_node(b_node); NoiseTextureNode *noise = new NoiseTextureNode(); Index: intern/cycles/kernel/CMakeLists.txt =================================================================== --- intern/cycles/kernel/CMakeLists.txt (revision 43210) +++ intern/cycles/kernel/CMakeLists.txt (working copy) @@ -57,6 +57,7 @@ svm/svm_camera.h svm/svm_closure.h svm/svm_convert.h + svm/svm_checker.h svm/svm_displace.h svm/svm_fresnel.h svm/svm_gamma.h Index: intern/cycles/kernel/svm/svm.h =================================================================== --- intern/cycles/kernel/svm/svm.h (revision 43210) +++ intern/cycles/kernel/svm/svm.h (working copy) @@ -145,6 +145,7 @@ #include "svm_tex_coord.h" #include "svm_value.h" #include "svm_voronoi.h" +#include "svm_checker.h" CCL_NAMESPACE_BEGIN @@ -235,6 +236,9 @@ case NODE_TEX_MAGIC: svm_node_tex_magic(kg, sd, stack, node, &offset); break; + case NODE_TEX_CHECKER: + svm_node_tex_checker(kg, sd, stack, node, &offset); + break; #endif case NODE_CAMERA: svm_node_camera(kg, sd, stack, node.y, node.z, node.w); Index: intern/cycles/kernel/svm/svm_checker.h =================================================================== --- intern/cycles/kernel/svm/svm_checker.h (revision 0) +++ intern/cycles/kernel/svm/svm_checker.h (revision 0) @@ -0,0 +1,68 @@ +/* + * 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 float3 svm_checker(float3 p, float3 col1, float3 col2, float s) +{ + float x = p.x; + float y = p.y; + float z = p.y; + + /* 0.00001 because of unit sized stuff */ + int xi = (int)fabsf(floor(0.00001f + x / s)); + int yi = (int)fabsf(floor(0.00001f + y / s)); + int zi = (int)fabsf(floor(0.00001f + z / s)); + + if( (xi % 2 == yi % 2) == (zi % 2) ) { + //tex_input_rgba(out, in[0], p, thread); + return col1; + } else { + //tex_input_rgba(out, in[1], p, thread); + return col2; + } +} + + +__device void svm_node_tex_checker(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) +{ + uint4 node2 = read_node(kg, offset); + + uint co_offset, color1_offset, color2_offset, size_offset; + uint color_offset, fac_offset; + + decode_node_uchar4(node.y, &co_offset, &color1_offset, &color2_offset, &size_offset); + decode_node_uchar4(node.z, &color_offset, &fac_offset, NULL, NULL); + + float3 co = stack_load_float3(stack, co_offset); + float3 c1 = stack_load_float3(stack, color1_offset); + float3 c2 = stack_load_float3(stack, color2_offset); + float size = stack_load_float_default(stack, size_offset, node2.x); + + float3 f = svm_checker(co, c1, c2, size_offset); + //f = clamp(f, 0.0f, 1.0f); + + if(stack_valid(color_offset)) + stack_store_float3(stack, color_offset, f); +} + +CCL_NAMESPACE_END + Index: intern/cycles/kernel/svm/svm_types.h =================================================================== --- intern/cycles/kernel/svm/svm_types.h (revision 43210) +++ intern/cycles/kernel/svm/svm_types.h (working copy) @@ -86,7 +86,8 @@ NODE_CAMERA = 5300, NODE_INVERT = 5400, NODE_NORMAL = 5500, - NODE_GAMMA = 5600 + NODE_GAMMA = 5600, + NODE_TEX_CHECKER = 5700 } NodeType; typedef enum NodeAttributeType { Index: intern/cycles/render/nodes.cpp =================================================================== --- intern/cycles/render/nodes.cpp (revision 43210) +++ intern/cycles/render/nodes.cpp (working copy) @@ -712,6 +712,56 @@ 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("Size", 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 *size_in = input("Size"); + + ShaderOutput *color_out = output("Color"); + ShaderOutput *fac_out = output("Fac"); + + if(vector_in->link) compiler.stack_assign(vector_in); + compiler.stack_assign(color1_in); + compiler.stack_assign(color2_in); + if(size_in->link) compiler.stack_assign(size_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, size_in->stack_offset), + compiler.encode_uchar4(color_out->stack_offset, fac_out->stack_offset)); + compiler.add_node( + __float_as_int(size_in->value.x)); +} + +void CheckerTextureNode::compile(OSLCompiler& compiler) +{ + compiler.add(this, "node_checker_texture"); +} + /* Normal */ NormalNode::NormalNode() Index: intern/cycles/render/nodes.h =================================================================== --- intern/cycles/render/nodes.h (revision 43210) +++ intern/cycles/render/nodes.h (working copy) @@ -143,6 +143,11 @@ int depth; }; +class CheckerTextureNode : public TextureNode { +public: + SHADER_NODE_CLASS(CheckerTextureNode) +}; + class MappingNode : public ShaderNode { public: SHADER_NODE_CLASS(MappingNode) Index: source/blender/blenkernel/BKE_node.h =================================================================== --- source/blender/blenkernel/BKE_node.h (revision 43210) +++ source/blender/blenkernel/BKE_node.h (working copy) @@ -520,6 +520,7 @@ #define SH_NODE_VOLUME_TRANSPARENT 161 #define SH_NODE_VOLUME_ISOTROPIC 162 #define SH_NODE_GAMMA 163 +#define SH_NODE_TEX_CHECKER 164 /* custom defines options for Material node */ #define SH_NODE_MAT_DIFF 1 Index: source/blender/blenkernel/intern/node.c =================================================================== --- source/blender/blenkernel/intern/node.c (revision 43210) +++ source/blender/blenkernel/intern/node.c (working copy) @@ -1940,6 +1940,7 @@ register_node_type_sh_tex_musgrave(ttype); register_node_type_sh_tex_gradient(ttype); register_node_type_sh_tex_magic(ttype); + register_node_type_sh_tex_checker(ttype); } static void registerTextureNodes(bNodeTreeType *ttype) Index: source/blender/makesdna/DNA_node_types.h =================================================================== --- source/blender/makesdna/DNA_node_types.h (revision 43210) +++ source/blender/makesdna/DNA_node_types.h (working copy) @@ -446,6 +446,10 @@ int color_space, pad; } NodeTexImage; +typedef struct NodeTexChecker { + NodeTexBase base; +} NodeTexChecker; + typedef struct NodeTexEnvironment { NodeTexBase base; int color_space, pad; Index: source/blender/makesrna/intern/rna_nodetree.c =================================================================== --- source/blender/makesrna/intern/rna_nodetree.c (revision 43210) +++ source/blender/makesrna/intern/rna_nodetree.c (working copy) @@ -1333,6 +1333,12 @@ 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) { PropertyRNA *prop; Index: source/blender/makesrna/intern/rna_nodetree_types.h =================================================================== --- source/blender/makesrna/intern/rna_nodetree_types.h (revision 43210) +++ source/blender/makesrna/intern/rna_nodetree_types.h (working copy) @@ -85,6 +85,7 @@ 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_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( CompositorNode, CMP_NODE_VIEWER, 0, "VIEWER", Viewer, "Viewer", "" ) Index: source/blender/nodes/CMakeLists.txt =================================================================== --- source/blender/nodes/CMakeLists.txt (revision 43210) +++ source/blender/nodes/CMakeLists.txt (working copy) @@ -162,6 +162,7 @@ shader/nodes/node_shader_tex_sky.c shader/nodes/node_shader_tex_voronoi.c shader/nodes/node_shader_tex_wave.c + shader/nodes/node_shader_tex_checker.c shader/node_shader_tree.c shader/node_shader_util.c Index: source/blender/nodes/NOD_shader.h =================================================================== --- source/blender/nodes/NOD_shader.h (revision 43210) +++ source/blender/nodes/NOD_shader.h (working copy) @@ -103,6 +103,7 @@ 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_noise(struct bNodeTreeType *ttype); +void register_node_type_sh_tex_checker(struct bNodeTreeType *ttype); #endif Index: source/blender/nodes/shader/nodes/node_shader_tex_checker.c =================================================================== --- source/blender/nodes/shader/nodes/node_shader_tex_checker.c (revision 0) +++ source/blender/nodes/shader/nodes/node_shader_tex_checker.c (revision 0) @@ -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.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, + { SOCK_FLOAT, 1, "Size", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.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); +}