[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57670] branches/soc-2013-dingto/intern/ cycles: Cycles / Vector Transform Node:
Sergey Sharybin
sergey.vfx at gmail.com
Sun Jun 23 20:40:37 CEST 2013
Hi,
Just quick brainstorm idea: instead of comparing the whole string to
convert it to lower-case, you could do comparison of the first letter only
and assign only that one? Would give some %% of boost :)
On Sun, Jun 23, 2013 at 11:51 PM, Thomas Dinges <blender at dingto.org> wrote:
> Revision: 57670
>
> http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57670
> Author: dingto
> Date: 2013-06-23 17:51:08 +0000 (Sun, 23 Jun 2013)
> Log Message:
> -----------
> Cycles / Vector Transform Node:
> * Implementation of Vector Transform Node into Cycles.
> * OSL backend is done, SVM needs the matrices still.
>
> Modified Paths:
> --------------
> branches/soc-2013-dingto/intern/cycles/blender/blender_shader.cpp
> branches/soc-2013-dingto/intern/cycles/kernel/CMakeLists.txt
> branches/soc-2013-dingto/intern/cycles/kernel/shaders/CMakeLists.txt
> branches/soc-2013-dingto/intern/cycles/kernel/svm/svm.h
> branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_types.h
> branches/soc-2013-dingto/intern/cycles/render/nodes.cpp
> branches/soc-2013-dingto/intern/cycles/render/nodes.h
>
> Added Paths:
> -----------
>
> branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_vector_transform.osl
>
> branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_vector_transform.h
>
> Modified: branches/soc-2013-dingto/intern/cycles/blender/blender_shader.cpp
> ===================================================================
> --- branches/soc-2013-dingto/intern/cycles/blender/blender_shader.cpp
> 2013-06-23 17:27:50 UTC (rev 57669)
> +++ branches/soc-2013-dingto/intern/cycles/blender/blender_shader.cpp
> 2013-06-23 17:51:08 UTC (rev 57670)
> @@ -250,6 +250,14 @@
> vmath->type =
> VectorMathNode::type_enum[b_vector_math_node.operation()];
> node = vmath;
> }
> + else if (b_node.is_a(&RNA_ShaderNodeVectorTransform)) {
> + BL::ShaderNodeVectorTransform
> b_vector_transform_node(b_node);
> + VectorTransformNode *vtransform = new
> VectorTransformNode();
> + vtransform->type =
> VectorTransformNode::type_enum[b_vector_transform_node.type()];
> + vtransform->convert_from =
> VectorTransformNode::convert_from_enum[b_vector_transform_node.convert_from()];
> + vtransform->convert_to =
> VectorTransformNode::convert_to_enum[b_vector_transform_node.convert_to()];
> + node = vtransform;
> + }
> else if (b_node.is_a(&RNA_ShaderNodeNormal)) {
> BL::Node::outputs_iterator out_it;
> b_node.outputs.begin(out_it);
>
> Modified: branches/soc-2013-dingto/intern/cycles/kernel/CMakeLists.txt
> ===================================================================
> --- branches/soc-2013-dingto/intern/cycles/kernel/CMakeLists.txt
> 2013-06-23 17:27:50 UTC (rev 57669)
> +++ branches/soc-2013-dingto/intern/cycles/kernel/CMakeLists.txt
> 2013-06-23 17:51:08 UTC (rev 57670)
> @@ -105,6 +105,7 @@
> svm/svm_texture.h
> svm/svm_types.h
> svm/svm_value.h
> + svm/svm_vector_transform.h
> svm/svm_voronoi.h
> svm/svm_wave.h
> )
>
> Modified:
> branches/soc-2013-dingto/intern/cycles/kernel/shaders/CMakeLists.txt
> ===================================================================
> --- branches/soc-2013-dingto/intern/cycles/kernel/shaders/CMakeLists.txt
> 2013-06-23 17:27:50 UTC (rev 57669)
> +++ branches/soc-2013-dingto/intern/cycles/kernel/shaders/CMakeLists.txt
> 2013-06-23 17:51:08 UTC (rev 57670)
> @@ -64,6 +64,7 @@
> node_value.osl
> node_vector_curves.osl
> node_vector_math.osl
> + node_vector_transform.osl
> node_velvet_bsdf.osl
> node_voronoi_texture.osl
> node_ward_bsdf.osl
>
> Added:
> branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_vector_transform.osl
> ===================================================================
> ---
> branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_vector_transform.osl
> (rev 0)
> +++
> branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_vector_transform.osl
> 2013-06-23 17:51:08 UTC (rev 57670)
> @@ -0,0 +1,50 @@
> +/*
> + * Copyright 2013, 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_vector_transform(
> + string type = "Vector",
> + string convert_from = "World",
> + string convert_to = "Object",
> + vector VectorIn = vector(0.0, 0.0, 0.0),
> + output vector VectorOut = vector(0.0, 0.0, 0.0))
> +{
> + /* OSL uses lower case variable names here */
> + string from = "world";
> + string to = "object";
> +
> + if (convert_from == "Object")
> + from = "object";
> + else if (convert_from == "Camera")
> + from = "camera";
> +
> + if (convert_to == "World")
> + to = "world";
> + else if (convert_to == "Camera")
> + to = "camera";
> +
> + if (type == "Vector") {
> + VectorOut = transform(from, to, VectorIn);
> + }
> + else if (type == "Point") {
> + point Point = point(VectorIn[0], VectorIn[1], VectorIn[2]);
> + VectorOut = transform(from, to, Point);
> + }
> +}
> +
>
> Modified: branches/soc-2013-dingto/intern/cycles/kernel/svm/svm.h
> ===================================================================
> --- branches/soc-2013-dingto/intern/cycles/kernel/svm/svm.h 2013-06-23
> 17:27:50 UTC (rev 57669)
> +++ branches/soc-2013-dingto/intern/cycles/kernel/svm/svm.h 2013-06-23
> 17:51:08 UTC (rev 57670)
> @@ -177,6 +177,7 @@
> #include "svm_voronoi.h"
> #include "svm_checker.h"
> #include "svm_brick.h"
> +#include "svm_vector_transform.h"
>
> CCL_NAMESPACE_BEGIN
>
> @@ -382,6 +383,9 @@
> case NODE_VECTOR_MATH:
> svm_node_vector_math(kg, sd, stack,
> node.y, node.z, node.w, &offset);
> break;
> + case NODE_VECTOR_TRANSFORM:
> + svm_node_vector_transform(kg, sd, stack,
> node);
> + break;
> case NODE_NORMAL:
> svm_node_normal(kg, sd, stack, node.y,
> node.z, node.w, &offset);
> break;
>
> Modified: branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_types.h
> ===================================================================
> --- branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_types.h
> 2013-06-23 17:27:50 UTC (rev 57669)
> +++ branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_types.h
> 2013-06-23 17:51:08 UTC (rev 57670)
> @@ -68,6 +68,7 @@
> NODE_SET_BUMP,
> NODE_MATH,
> NODE_VECTOR_MATH,
> + NODE_VECTOR_TRANSFORM,
> NODE_MAPPING,
> NODE_TEX_COORD,
> NODE_TEX_COORD_BUMP_DX,
> @@ -226,6 +227,23 @@
> NODE_VECTOR_MATH_NORMALIZE
> } NodeVectorMath;
>
> +typedef enum NodeVectorTransformType {
> + NODE_VECTOR_TRANSFORM_TYPE_VECTOR,
> + NODE_VECTOR_TRANSFORM_TYPE_POINT
> +} NodeVectorTransformType;
> +
> +typedef enum NodeVectorTransformConvertFrom {
> + NODE_VECTOR_TRANSFORM_CONVERT_FROM_WORLD,
> + NODE_VECTOR_TRANSFORM_CONVERT_FROM_OBJECT,
> + NODE_VECTOR_TRANSFORM_CONVERT_FROM_CAMERA
> +} NodeVectorTransformConvertFrom;
> +
> +typedef enum NodeVectorTransformConvertTo {
> + NODE_VECTOR_TRANSFORM_CONVERT_TO_WORLD,
> + NODE_VECTOR_TRANSFORM_CONVERT_TO_OBJECT,
> + NODE_VECTOR_TRANSFORM_CONVERT_TO_CAMERA
> +} NodeVectorTransformConvertTo;
> +
> typedef enum NodeConvert {
> NODE_CONVERT_FV,
> NODE_CONVERT_FI,
>
> Added:
> branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_vector_transform.h
> ===================================================================
> ---
> branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_vector_transform.h
> (rev 0)
> +++
> branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_vector_transform.h
> 2013-06-23 17:51:08 UTC (rev 57670)
> @@ -0,0 +1,44 @@
> +/*
> + * Copyright 2013, 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
> +
> +/* Vector Transform */
> +
> +__device void svm_node_vector_transform(KernelGlobals *kg, ShaderData
> *sd, float *stack, uint4 node)
> +{
> + uint itype, ifrom, ito;
> + uint vector_in, vector_out;
> +
> + float3 out = make_float3(0.0f, 0.0f, 0.0f);
> +
> + decode_node_uchar4(node.y, &itype, &ifrom, &ito, NULL);
> + decode_node_uchar4(node.z, &vector_in, &vector_out, NULL, NULL);
> +
> + NodeVectorTransformType type = (NodeVectorTransformType)itype;
> + NodeVectorTransformConvertFrom from =
> (NodeVectorTransformConvertFrom)ifrom;
> + NodeVectorTransformConvertTo to =
> (NodeVectorTransformConvertTo)ito;
> +
> + float3 vec_in = stack_load_float3(stack, vector_in);
> +
> + if(stack_valid(vector_out))
> + stack_store_float3(stack, vector_out, out);
> +}
> +
> +CCL_NAMESPACE_END
> +
>
> Modified: branches/soc-2013-dingto/intern/cycles/render/nodes.cpp
> ===================================================================
> --- branches/soc-2013-dingto/intern/cycles/render/nodes.cpp 2013-06-23
> 17:27:50 UTC (rev 57669)
> +++ branches/soc-2013-dingto/intern/cycles/render/nodes.cpp 2013-06-23
> 17:51:08 UTC (rev 57670)
> @@ -3153,6 +3153,76 @@
> compiler.add(this, "node_vector_math");
> }
>
> +/* VectorTransform */
> +
> +VectorTransformNode::VectorTransformNode()
> +: ShaderNode("vector_transform")
> +{
> + type = ustring("Vector");
> + convert_from = ustring("World");
> + convert_to = ustring("Object");
> +
> + add_input("Vector", SHADER_SOCKET_VECTOR);
> + add_output("Vector", SHADER_SOCKET_VECTOR);
> +}
> +
> +static ShaderEnum vector_transform_type_init()
> +{
> + ShaderEnum enm;
> +
> + enm.insert("Vector", NODE_VECTOR_TRANSFORM_TYPE_VECTOR);
> + enm.insert("Point", NODE_VECTOR_TRANSFORM_TYPE_POINT);
> +
> + return enm;
> +}
> +
> +static ShaderEnum vector_transform_convert_from_init()
> +{
> + ShaderEnum enm;
> +
> + enm.insert("World", NODE_VECTOR_TRANSFORM_CONVERT_FROM_WORLD);
> + enm.insert("Object", NODE_VECTOR_TRANSFORM_CONVERT_FROM_OBJECT);
> + enm.insert("Camera", NODE_VECTOR_TRANSFORM_CONVERT_FROM_CAMERA);
> +
> + return enm;
> +}
> +
> +static ShaderEnum vector_transform_convert_to_init()
> +{
> + ShaderEnum enm;
> +
> + enm.insert("World", NODE_VECTOR_TRANSFORM_CONVERT_TO_WORLD);
> + enm.insert("Object", NODE_VECTOR_TRANSFORM_CONVERT_TO_OBJECT);
> + enm.insert("Camera", NODE_VECTOR_TRANSFORM_CONVERT_TO_CAMERA);
> +
> + return enm;
> +}
> +
> +ShaderEnum VectorTransformNode::type_enum = vector_transform_type_init();
> +ShaderEnum VectorTransformNode::convert_from_enum =
> vector_transform_convert_from_init();
> +ShaderEnum VectorTransformNode::convert_to_enum =
> vector_transform_convert_to_init();
> +
> +void VectorTransformNode::compile(SVMCompiler& compiler)
> +{
> + ShaderInput *vector_in = input("Vector");
> + ShaderOutput *vector_out = output("Vector");
> +
> + compiler.stack_assign(vector_in);
> + compiler.stack_assign(vector_out);
> +
> + compiler.add_node(NODE_VECTOR_TRANSFORM,
> + compiler.encode_uchar4(type_enum[type],
> convert_from_enum[convert_from], convert_to_enum[convert_to]),
> + compiler.encode_uchar4(vector_in->stack_offset,
> vector_out->stack_offset));
> +}
> +
> +void VectorTransformNode::compile(OSLCompiler& compiler)
> +{
> + compiler.parameter("type", type);
> + compiler.parameter("convert_from", convert_from);
> + compiler.parameter("convert_to", convert_to);
>
> @@ Diff output truncated at 10240 characters. @@
> _______________________________________________
> Bf-blender-cvs mailing list
> Bf-blender-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-blender-cvs
>
--
With best regards, Sergey Sharybin
More information about the Bf-committers
mailing list