diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-21 16:52:28 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-21 16:52:28 +0400 |
commit | c3e1fce77552b5626d2939710cb6d0020891d218 (patch) | |
tree | 5d59df38ec009f21000a959531129aa511868773 /intern/cycles/kernel | |
parent | ea11bc980ad428950efb430618a6de439ffd5951 (diff) |
Cycles: add Object Info node, with outputs object location, object/material
pass index, and a random number unique to the instance of the object.
This can be useful to give some variation to a single material assigned to
multiple instances, either manually controlled through the object index, based
on the object location, or randomized for each instance.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/More#Object_Info
Diffstat (limited to 'intern/cycles/kernel')
-rw-r--r-- | intern/cycles/kernel/kernel_object.h | 25 | ||||
-rw-r--r-- | intern/cycles/kernel/kernel_shader.h | 5 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm.h | 3 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_geometry.h | 20 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_types.h | 10 |
5 files changed, 57 insertions, 6 deletions
diff --git a/intern/cycles/kernel/kernel_object.h b/intern/cycles/kernel/kernel_object.h index abe427d8345..05c45c490d8 100644 --- a/intern/cycles/kernel/kernel_object.h +++ b/intern/cycles/kernel/kernel_object.h @@ -117,6 +117,16 @@ __device_inline void object_dir_transform(KernelGlobals *kg, ShaderData *sd, flo #endif } +__device_inline float3 object_location(KernelGlobals *kg, ShaderData *sd) +{ +#ifdef __MOTION__ + return make_float3(sd->ob_tfm.x.w, sd->ob_tfm.y.w, sd->ob_tfm.z.w); +#else + Transform tfm = object_fetch_transform(kg, sd->object, 0.0f, OBJECT_TRANSFORM); + return make_float3(tfm.x.w, tfm.y.w, tfm.z.w); +#endif +} + __device_inline float object_surface_area(KernelGlobals *kg, int object) { int offset = object*OBJECT_SIZE + OBJECT_PROPERTIES; @@ -134,5 +144,20 @@ __device_inline float object_pass_id(KernelGlobals *kg, int object) return f.y; } +__device_inline float object_random_number(KernelGlobals *kg, int object) +{ + if(object == ~0) + return 0.0f; + + int offset = object*OBJECT_SIZE + OBJECT_PROPERTIES; + float4 f = kernel_tex_fetch(__objects, offset); + return f.z; +} + +__device int shader_pass_id(KernelGlobals *kg, ShaderData *sd) +{ + return kernel_tex_fetch(__shader_flag, (sd->shader & SHADER_MASK)*2 + 1); +} + CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/kernel_shader.h b/intern/cycles/kernel/kernel_shader.h index 2138038e49d..8e0d36705ad 100644 --- a/intern/cycles/kernel/kernel_shader.h +++ b/intern/cycles/kernel/kernel_shader.h @@ -679,11 +679,6 @@ __device bool shader_transparent_shadow(KernelGlobals *kg, Intersection *isect) } #endif -__device int shader_pass_id(KernelGlobals *kg, ShaderData *sd) -{ - return kernel_tex_fetch(__shader_flag, (sd->shader & SHADER_MASK)*2 + 1); -} - /* Free ShaderData */ __device void shader_release(KernelGlobals *kg, ShaderData *sd) diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h index 12ed61673d1..6a05639beb9 100644 --- a/intern/cycles/kernel/svm/svm.h +++ b/intern/cycles/kernel/svm/svm.h @@ -266,6 +266,9 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT case NODE_LIGHT_PATH: svm_node_light_path(sd, stack, node.y, node.z, path_flag); break; + case NODE_OBJECT_INFO: + svm_node_object_info(kg, sd, stack, node.y, node.z); + break; #endif case NODE_CONVERT: svm_node_convert(sd, stack, node.y, node.z, node.w); diff --git a/intern/cycles/kernel/svm/svm_geometry.h b/intern/cycles/kernel/svm/svm_geometry.h index 77fe26c809e..dab19983946 100644 --- a/intern/cycles/kernel/svm/svm_geometry.h +++ b/intern/cycles/kernel/svm/svm_geometry.h @@ -74,5 +74,25 @@ __device void svm_node_geometry_bump_dy(ShaderData *sd, float *stack, uint type, #endif } +/* Object Info */ + +__device void svm_node_object_info(KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset) +{ + float data; + + switch(type) { + case NODE_INFO_OB_LOCATION: { + stack_store_float3(stack, out_offset, object_location(kg, sd)); + return; + } + case NODE_INFO_OB_INDEX: data = object_pass_id(kg, sd->object); break; + case NODE_INFO_MAT_INDEX: data = shader_pass_id(kg, sd); break; + case NODE_INFO_OB_RANDOM: data = object_random_number(kg, sd->object); break; + default: data = 0.0f; break; + } + + stack_store_float(stack, out_offset, data); +} + CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h index 867709f29e0..97849736ef6 100644 --- a/intern/cycles/kernel/svm/svm_types.h +++ b/intern/cycles/kernel/svm/svm_types.h @@ -92,7 +92,8 @@ typedef enum NodeType { NODE_RGB_RAMP = 5900, NODE_RGB_CURVES = 6000, NODE_MIN_MAX = 6100, - NODE_LIGHT_FALLOFF = 6200 + NODE_LIGHT_FALLOFF = 6200, + NODE_OBJECT_INFO = 6300 } NodeType; typedef enum NodeAttributeType { @@ -109,6 +110,13 @@ typedef enum NodeGeometry { NODE_GEOM_uv } NodeGeometry; +typedef enum NodeObjectInfo { + NODE_INFO_OB_LOCATION, + NODE_INFO_OB_INDEX, + NODE_INFO_MAT_INDEX, + NODE_INFO_OB_RANDOM +} NodeObjectInfo; + typedef enum NodeLightPath { NODE_LP_camera = 0, NODE_LP_shadow, |