Revision: 50204
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50204
Author:   dingto
Date:     2012-08-25 16:52:55 +0000 (Sat, 25 Aug 2012)
Log Message:
-----------
Tomato Cycles:
* Added a Brick Texture Node to Cycles.
* Based on the Blender Internal Brick Texture with some modifications. 
* Tested on CPU and GPU (CUDA & OpenCL)

Documentation: http://wiki.blender.org/index.php/User:DingTo/CyclesBrickTexture

ToDo: Only works correct on flat surfaces, like a Plane. If you attach the 
shader to 3D objects like a cube, the mapping is not correct on the Y/Z vector. 

Thanks to Lukas Toenne for fixing a issue I had with the Node code! :)

Modified Paths:
--------------
    branches/soc-2011-tomato/intern/cycles/app/cycles_xml.cpp
    branches/soc-2011-tomato/intern/cycles/blender/blender_shader.cpp
    branches/soc-2011-tomato/intern/cycles/kernel/CMakeLists.txt
    branches/soc-2011-tomato/intern/cycles/kernel/svm/svm.h
    branches/soc-2011-tomato/intern/cycles/kernel/svm/svm_types.h
    branches/soc-2011-tomato/intern/cycles/render/nodes.cpp
    branches/soc-2011-tomato/intern/cycles/render/nodes.h
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_node.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/node.c
    branches/soc-2011-tomato/source/blender/editors/space_node/drawnode.c
    branches/soc-2011-tomato/source/blender/makesdna/DNA_node_types.h
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_nodetree.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_nodetree_types.h
    branches/soc-2011-tomato/source/blender/nodes/CMakeLists.txt
    branches/soc-2011-tomato/source/blender/nodes/NOD_shader.h

Added Paths:
-----------
    branches/soc-2011-tomato/intern/cycles/kernel/svm/svm_brick.h
    
branches/soc-2011-tomato/source/blender/nodes/shader/nodes/node_shader_tex_brick.c

Modified: branches/soc-2011-tomato/intern/cycles/app/cycles_xml.cpp
===================================================================
--- branches/soc-2011-tomato/intern/cycles/app/cycles_xml.cpp   2012-08-25 
15:00:41 UTC (rev 50203)
+++ branches/soc-2011-tomato/intern/cycles/app/cycles_xml.cpp   2012-08-25 
16:52:55 UTC (rev 50204)
@@ -379,6 +379,9 @@
                else if(string_iequals(node.name(), "checker_texture")) {
                        snode = new CheckerTextureNode();
                }
+               else if(string_iequals(node.name(), "brick_texture")) {
+                       snode = new BrickTextureNode();
+               }
                else if(string_iequals(node.name(), "gradient_texture")) {
                        GradientTextureNode *blend = new GradientTextureNode();
                        xml_read_enum(&blend->type, 
GradientTextureNode::type_enum, node, "type");

Modified: branches/soc-2011-tomato/intern/cycles/blender/blender_shader.cpp
===================================================================
--- branches/soc-2011-tomato/intern/cycles/blender/blender_shader.cpp   
2012-08-25 15:00:41 UTC (rev 50203)
+++ branches/soc-2011-tomato/intern/cycles/blender/blender_shader.cpp   
2012-08-25 16:52:55 UTC (rev 50204)
@@ -461,6 +461,17 @@
                        node = checker;
                        break;
                }
+               case BL::ShaderNode::type_TEX_BRICK: {
+                       BL::ShaderNodeTexBrick b_brick_node(b_node);
+                       BrickTextureNode *brick = new BrickTextureNode();
+                       brick->offset = b_brick_node.offset();
+                       brick->offset_frequency = 
b_brick_node.offset_frequency();
+                       brick->squash = b_brick_node.squash();
+                       brick->squash_frequency = 
b_brick_node.squash_frequency();
+                       get_tex_mapping(&brick->tex_mapping, 
b_brick_node.texture_mapping());
+                       node = brick;
+                       break;
+               }
                case BL::ShaderNode::type_TEX_NOISE: {
                        BL::ShaderNodeTexNoise b_noise_node(b_node);
                        NoiseTextureNode *noise = new NoiseTextureNode();

Modified: branches/soc-2011-tomato/intern/cycles/kernel/CMakeLists.txt
===================================================================
--- branches/soc-2011-tomato/intern/cycles/kernel/CMakeLists.txt        
2012-08-25 15:00:41 UTC (rev 50203)
+++ branches/soc-2011-tomato/intern/cycles/kernel/CMakeLists.txt        
2012-08-25 16:52:55 UTC (rev 50204)
@@ -61,6 +61,7 @@
        svm/svm_closure.h
        svm/svm_convert.h
        svm/svm_checker.h
+       svm/svm_brick.h
        svm/svm_displace.h
        svm/svm_fresnel.h
        svm/svm_gamma.h

Modified: branches/soc-2011-tomato/intern/cycles/kernel/svm/svm.h
===================================================================
--- branches/soc-2011-tomato/intern/cycles/kernel/svm/svm.h     2012-08-25 
15:00:41 UTC (rev 50203)
+++ branches/soc-2011-tomato/intern/cycles/kernel/svm/svm.h     2012-08-25 
16:52:55 UTC (rev 50204)
@@ -154,6 +154,7 @@
 #include "svm_value.h"
 #include "svm_voronoi.h"
 #include "svm_checker.h"
+#include "svm_brick.h"
 
 CCL_NAMESPACE_BEGIN
 
@@ -252,6 +253,9 @@
                        case NODE_TEX_CHECKER:
                                svm_node_tex_checker(kg, sd, stack, node, 
&offset);
                                break;
+                       case NODE_TEX_BRICK:
+                               svm_node_tex_brick(kg, sd, stack, node, 
&offset);
+                               break;
 #endif
                        case NODE_CAMERA:
                                svm_node_camera(kg, sd, stack, node.y, node.z, 
node.w);

Added: branches/soc-2011-tomato/intern/cycles/kernel/svm/svm_brick.h
===================================================================
--- branches/soc-2011-tomato/intern/cycles/kernel/svm/svm_brick.h               
                (rev 0)
+++ branches/soc-2011-tomato/intern/cycles/kernel/svm/svm_brick.h       
2012-08-25 16:52:55 UTC (rev 50204)
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2012, 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
+
+/* Brick */
+
+__device_noinline float brick_noise(int n) /* fast integer noise */
+{
+       int nn;
+       n = (n >> 13) ^ n;
+       nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
+       return 0.5f * ((float)nn / 1073741824.0f);
+}
+
+__device_noinline float svm_brick(float3 p, float scale, float mortar_size, 
float bias,
+       float brick_width, float row_height, float offset_amount, int 
offset_frequency,
+       float squash_amount, int squash_frequency, float *tint)
+{      
+       p *= scale;
+
+       int bricknum, rownum;
+       float offset = 0.0f;
+       float x, y;
+
+       rownum = (int)floor(p.y / row_height);
+       
+       if(offset_frequency && squash_frequency) {
+               brick_width *= ((int)(rownum) % squash_frequency ) ? 1.0f : 
squash_amount; /* squash */
+               offset = ((int)(rownum) % offset_frequency ) ? 0 : 
(brick_width*offset_amount); /* offset */
+       }
+
+       bricknum = (int)floor((p.x+offset) / brick_width);
+
+       x = (p.x+offset) - brick_width*bricknum;
+       y = p.y - row_height*rownum;
+
+       *tint = clamp((brick_noise((rownum << 16) + (bricknum & 0xFFFF)) + 
bias), 0.0f, 1.0f);
+
+       return (x < mortar_size || y < mortar_size ||
+               x > (brick_width - mortar_size) ||
+               y > (row_height - mortar_size)) ? 1.0f : 0.0f;
+}
+
+__device void svm_node_tex_brick(KernelGlobals *kg, ShaderData *sd, float 
*stack, uint4 node, int *offset)
+{      
+       uint4 node2 = read_node(kg, offset);
+       uint4 node3 = read_node(kg, offset);
+       
+       /* Input and Output Sockets */
+       uint co_offset, color1_offset, color2_offset, mortar_offset, 
scale_offset;
+       uint mortar_size_offset, bias_offset, brick_width_offset, 
row_height_offset;
+       uint color_offset, fac_offset;
+       
+       /* RNA properties */
+       uint offset_frequency, squash_frequency;
+       
+       float tint = 0;
+
+       decode_node_uchar4(node.y, &co_offset, &color1_offset, &color2_offset, 
&mortar_offset);
+       decode_node_uchar4(node.z, &scale_offset, &mortar_size_offset, 
&bias_offset, &brick_width_offset);
+       decode_node_uchar4(node.w, &row_height_offset, &color_offset, 
&fac_offset, NULL);
+       
+       decode_node_uchar4(node2.x, &offset_frequency, &squash_frequency, 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);
+       float3 mortar = stack_load_float3(stack, mortar_offset);
+       
+       float scale = stack_load_float_default(stack, scale_offset, node2.y);
+       float mortar_size = stack_load_float_default(stack, mortar_size_offset, 
node2.z);
+       float bias = stack_load_float_default(stack, bias_offset, node2.w);
+       float brick_width = stack_load_float_default(stack, brick_width_offset, 
node3.x);
+       float row_height = stack_load_float_default(stack, row_height_offset, 
node3.y);
+       float offset_amount = __int_as_float(node3.z);
+       float squash_amount = __int_as_float(node3.w);
+       
+       float f = svm_brick(co, scale, mortar_size, bias, brick_width, 
row_height,
+               offset_amount, offset_frequency, squash_amount, 
squash_frequency,
+               &tint);
+       
+       if(f != 1.0f) {
+               float facm = 1.0f - tint;
+
+               color1.x = facm * (color1.x) + tint * color2.x;
+               color1.y = facm * (color1.y) + tint * color2.y;
+               color1.z = facm * (color1.z) + tint * color2.z;
+       }
+
+       if(stack_valid(color_offset))
+               stack_store_float3(stack, color_offset, (f == 1.0f)? mortar: 
color1);
+       if(stack_valid(fac_offset))
+               stack_store_float(stack, fac_offset, f);
+}
+
+CCL_NAMESPACE_END
+

Modified: branches/soc-2011-tomato/intern/cycles/kernel/svm/svm_types.h
===================================================================
--- branches/soc-2011-tomato/intern/cycles/kernel/svm/svm_types.h       
2012-08-25 15:00:41 UTC (rev 50203)
+++ branches/soc-2011-tomato/intern/cycles/kernel/svm/svm_types.h       
2012-08-25 16:52:55 UTC (rev 50204)
@@ -90,7 +90,8 @@
        NODE_MIN_MAX,
        NODE_LIGHT_FALLOFF,
        NODE_OBJECT_INFO,
-       NODE_PARTICLE_INFO
+       NODE_PARTICLE_INFO,
+       NODE_TEX_BRICK
 } NodeType;
 
 typedef enum NodeAttributeType {

Modified: branches/soc-2011-tomato/intern/cycles/render/nodes.cpp
===================================================================
--- branches/soc-2011-tomato/intern/cycles/render/nodes.cpp     2012-08-25 
15:00:41 UTC (rev 50203)
+++ branches/soc-2011-tomato/intern/cycles/render/nodes.cpp     2012-08-25 
16:52:55 UTC (rev 50204)
@@ -898,6 +898,98 @@
        compiler.add(this, "node_checker_texture");
 }
 
+/* Brick Texture */
+
+BrickTextureNode::BrickTextureNode()
+: TextureNode("brick_texture")
+{
+       offset = 0.5f;
+       offset_frequency = 2;
+       squash = 1.0f;
+       squash_frequency = 2;
+       
+       add_input("Vector", SHADER_SOCKET_POINT, 
ShaderInput::TEXTURE_GENERATED);
+       add_input("Color1", SHADER_SOCKET_COLOR);
+       add_input("Color2", SHADER_SOCKET_COLOR);
+       add_input("Mortar", SHADER_SOCKET_COLOR);
+       add_input("Scale", SHADER_SOCKET_FLOAT, 5.0f);
+       add_input("Mortar Size", SHADER_SOCKET_FLOAT, 0.02f);
+       add_input("Bias", SHADER_SOCKET_FLOAT, 0.0f);
+       add_input("Brick Width", SHADER_SOCKET_FLOAT, 0.5f);
+       add_input("Row Height", SHADER_SOCKET_FLOAT, 0.25f);
+
+       add_output("Color", SHADER_SOCKET_COLOR);
+       add_output("Fac", SHADER_SOCKET_FLOAT);
+}
+
+void BrickTextureNode::compile(SVMCompiler& compiler)
+{
+       ShaderInput *vector_in = input("Vector");
+       ShaderInput *color1_in = input("Color1");
+       ShaderInput *color2_in = input("Color2");
+       ShaderInput *mortar_in = input("Mortar");
+       ShaderInput *scale_in = input("Scale");
+       ShaderInput *mortar_size_in = input("Mortar Size");
+       ShaderInput *bias_in = input("Bias");
+       ShaderInput *brick_width_in = input("Brick Width");
+       ShaderInput *row_height_in = input("Row Height");
+       
+       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);
+       compiler.stack_assign(mortar_in);
+       if(scale_in->link) compiler.stack_assign(scale_in);
+       if(mortar_size_in->link) compiler.stack_assign(mortar_size_in);
+       if(bias_in->link) compiler.stack_assign(bias_in);
+       if(brick_width_in->link) compiler.stack_assign(brick_width_in);
+       if(row_height_in->link) compiler.stack_assign(row_height_in);
+
+       int vector_offset = vector_in->stack_offset;
+
+       if(!tex_mapping.skip()) {
+               vector_offset = 
compiler.stack_find_offset(SHADER_SOCKET_VECTOR);
+               tex_mapping.compile(compiler, vector_in->stack_offset, 
vector_offset);
+       }
+

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to