diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2011-12-03 00:36:13 +0400 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2011-12-03 00:36:13 +0400 |
commit | 78495ddf326af8b2404b9fd652f2ab4f7836f2c2 (patch) | |
tree | 6f33d7828918b2f8b40d35f5767adbf55cd6ec4b | |
parent | 1768a96774093a4b0d4674c683b2fb39564f0ad5 (diff) |
CameraData Input Cycles Node
----------------------------
reviewed and approved by Brecht
Important note:
the camera Z is reverted compared to Blender render.
Now it goes from zero (camera) to positive (in front of the camera)
-rw-r--r-- | intern/cycles/app/cycles_xml.cpp | 3 | ||||
-rw-r--r-- | intern/cycles/blender/blender_shader.cpp | 5 | ||||
-rw-r--r-- | intern/cycles/kernel/CMakeLists.txt | 1 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/nodes/CMakeLists.txt | 1 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/nodes/node_camera.osl | 33 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm.h | 4 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_camera.h | 43 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_types.h | 3 | ||||
-rw-r--r-- | intern/cycles/render/nodes.cpp | 27 | ||||
-rw-r--r-- | intern/cycles/render/nodes.h | 5 | ||||
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_camera.c | 2 |
11 files changed, 124 insertions, 3 deletions
diff --git a/intern/cycles/app/cycles_xml.cpp b/intern/cycles/app/cycles_xml.cpp index 00acae92955..8abc060af47 100644 --- a/intern/cycles/app/cycles_xml.cpp +++ b/intern/cycles/app/cycles_xml.cpp @@ -454,6 +454,9 @@ static void xml_read_shader_graph(const XMLReadState& state, Shader *shader, pug xml_read_ustring(&attr->attribute, node, "attribute"); snode = attr; } + else if(string_ieuals(node.name(), "camera")) { + snode = new CameraNode(); + } else if(string_iequals(node.name(), "fresnel")) { snode = new FresnelNode(); } diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index e081ad8bdee..43359bf5352 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -127,7 +127,6 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Node * switch(b_node.type()) { /* not supported */ - case BL::ShaderNode::type_CAMERA: break; case BL::ShaderNode::type_CURVE_RGB: break; case BL::ShaderNode::type_CURVE_VEC: break; case BL::ShaderNode::type_GEOMETRY: break; @@ -155,6 +154,10 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Node * node = value; break; } + case BL::ShaderNode::type_CAMERA: { + node = new CameraNode(); + break; + } case BL::ShaderNode::type_MIX_RGB: { BL::ShaderNodeMixRGB b_mix_node(b_node); MixNode *mix = new MixNode(); diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt index a09fe1d726e..59f7e04c9d8 100644 --- a/intern/cycles/kernel/CMakeLists.txt +++ b/intern/cycles/kernel/CMakeLists.txt @@ -54,6 +54,7 @@ set(SRC_SVM_HEADERS svm/svm.h svm/svm_attribute.h svm/svm_bsdf.h + svm/svm_camera.h svm/svm_closure.h svm/svm_convert.h svm/svm_displace.h diff --git a/intern/cycles/kernel/osl/nodes/CMakeLists.txt b/intern/cycles/kernel/osl/nodes/CMakeLists.txt index 50e763a6b83..02f4a5a55bf 100644 --- a/intern/cycles/kernel/osl/nodes/CMakeLists.txt +++ b/intern/cycles/kernel/osl/nodes/CMakeLists.txt @@ -7,6 +7,7 @@ set(SRC_OSL node_background.osl node_blend_texture.osl node_bump.osl + node_camera.osl node_clouds_texture.osl node_convert_from_color.osl node_convert_from_float.osl diff --git a/intern/cycles/kernel/osl/nodes/node_camera.osl b/intern/cycles/kernel/osl/nodes/node_camera.osl new file mode 100644 index 00000000000..0b50084db0f --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_camera.osl @@ -0,0 +1,33 @@ +/* + * 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. + */ + +#include "stdosl.h" + +shader node_camera( + output vector ViewVector = vector(0.0, 0.0, 0.0), + output float ViewZDepth = 0.0, + output float ViewDistance = 0.0) +{ + ViewVector = (vector)transform("world", "camera", P); + + ViewZDepth = fabs(ViewVector[2]); + ViewDistance = lenght(ViewVector); + + ViewVector = normalize(ViewVector); +} + diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h index 004875b0de5..443715600ca 100644 --- a/intern/cycles/kernel/svm/svm.h +++ b/intern/cycles/kernel/svm/svm.h @@ -126,6 +126,7 @@ CCL_NAMESPACE_END #include "svm_convert.h" #include "svm_displace.h" #include "svm_fresnel.h" +#include "svm_camera.h" #include "svm_geometry.h" #include "svm_hsv.h" #include "svm_image.h" @@ -232,6 +233,9 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT svm_node_tex_magic(kg, sd, stack, node, &offset); break; #endif + case NODE_CAMERA: + svm_node_camera(kg, sd, stack, node.y, node.z, node.w); + break; case NODE_GEOMETRY: svm_node_geometry(sd, stack, node.y, node.z); break; diff --git a/intern/cycles/kernel/svm/svm_camera.h b/intern/cycles/kernel/svm/svm_camera.h new file mode 100644 index 00000000000..cf161ddcd8c --- /dev/null +++ b/intern/cycles/kernel/svm/svm_camera.h @@ -0,0 +1,43 @@ +/* + * 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 + +__device void svm_node_camera(KernelGlobals *kg, ShaderData *sd, float *stack, uint out_vector, uint out_zdepth, uint out_distance) +{ + float distance; + float zdepth; + float3 vector; + + Transform tfm = kernel_data.cam.worldtocamera; + vector = transform(&tfm, sd->P); + zdepth = vector.z; + distance = len(vector); + + if (stack_valid(out_vector)) + stack_store_float3(stack, out_vector, normalize(vector)); + + if (stack_valid(out_zdepth)) + stack_store_float(stack, out_zdepth, zdepth); + + if (stack_valid(out_distance)) + stack_store_float(stack, out_distance, distance); +} + +CCL_NAMESPACE_END + diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h index 53bba644e41..fcd345b9359 100644 --- a/intern/cycles/kernel/svm/svm_types.h +++ b/intern/cycles/kernel/svm/svm_types.h @@ -82,7 +82,8 @@ typedef enum NodeType { NODE_CLOSURE_VOLUME = 4900, NODE_SEPARATE_RGB = 5000, NODE_COMBINE_RGB = 5100, - NODE_HSV = 5200 + NODE_HSV = 5200, + NODE_CAMERA = 5300 } NodeType; typedef enum NodeAttributeType { diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 45bb1511785..9f12fe6002f 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -1804,6 +1804,33 @@ void AttributeNode::compile(OSLCompiler& compiler) compiler.add(this, "node_attribute"); } +/* Camera */ + +CameraNode::CameraNode() +: ShaderNode("camera") +{ + add_output("View Vector", SHADER_SOCKET_VECTOR); + add_output("View Z Depth", SHADER_SOCKET_FLOAT); + add_output("View Distance", SHADER_SOCKET_FLOAT); +} + +void CameraNode::compile(SVMCompiler& compiler) +{ + ShaderOutput *vector_out = output("View Vector"); + ShaderOutput *z_depth_out = output("View Z Depth"); + ShaderOutput *distance_out = output("View Distance"); + + compiler.stack_assign(vector_out); + compiler.stack_assign(z_depth_out); + compiler.stack_assign(distance_out); + compiler.add_node(NODE_CAMERA, vector_out->stack_offset, z_depth_out->stack_offset, distance_out->stack_offset); +} + +void CameraNode::compile(OSLCompiler& compiler) +{ + compiler.add(this, "node_camera"); +} + /* Fresnel */ FresnelNode::FresnelNode() diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h index dfff955c4fe..fd5271d8434 100644 --- a/intern/cycles/render/nodes.h +++ b/intern/cycles/render/nodes.h @@ -315,6 +315,11 @@ public: ustring attribute; }; +class CameraNode : public ShaderNode { +public: + SHADER_NODE_CLASS(CameraNode) +}; + class FresnelNode : public ShaderNode { public: SHADER_NODE_CLASS(FresnelNode) diff --git a/source/blender/nodes/shader/nodes/node_shader_camera.c b/source/blender/nodes/shader/nodes/node_shader_camera.c index d95cc1460df..3ec75dfa4fd 100644 --- a/source/blender/nodes/shader/nodes/node_shader_camera.c +++ b/source/blender/nodes/shader/nodes/node_shader_camera.c @@ -62,7 +62,7 @@ void register_node_type_sh_camera(bNodeTreeType *ttype) static bNodeType ntype; node_type_base(ttype, &ntype, SH_NODE_CAMERA, "Camera Data", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING); + node_type_compatibility(&ntype, NODE_OLD_SHADING|NODE_NEW_SHADING); node_type_socket_templates(&ntype, NULL, sh_node_camera_out); node_type_size(&ntype, 95, 95, 120); node_type_storage(&ntype, "node_camera", NULL, NULL); |