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)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
@@ -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();
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
33
intern/cycles/kernel/osl/nodes/node_camera.osl
Normal file
33
intern/cycles/kernel/osl/nodes/node_camera.osl
Normal file
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
|
43
intern/cycles/kernel/svm/svm_camera.h
Normal file
43
intern/cycles/kernel/svm/svm_camera.h
Normal file
@@ -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
|
||||
|
@@ -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 {
|
||||
|
@@ -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()
|
||||
|
@@ -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)
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user