diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-08 00:24:38 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-08 00:24:38 +0400 |
commit | e6a84eb1b542e7cafe5e760530882bb806f3c433 (patch) | |
tree | e3d7b9f8dab6c2d55ec0d45297ba281599f3e92f /intern/cycles/kernel | |
parent | f44e80e6387601dea6e4e0801d0a387455a02d31 (diff) |
Cycles: add light falloff node, with quadratic/linear/constant falloff and a
smoothing factor to reduce high values near the light.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/More#Light_Falloff
Note that this was already possible to do manually with the Ray Length, but
this adds a convenient node for it. This commit also makes the mapping node
min/max option work, fixing #31348.
Diffstat (limited to 'intern/cycles/kernel')
-rw-r--r-- | intern/cycles/kernel/svm/svm.h | 6 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_light_path.h | 27 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_mapping.h | 11 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_types.h | 10 |
4 files changed, 53 insertions, 1 deletions
diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h index 50181c0cf2c..5f4d7bbd0c4 100644 --- a/intern/cycles/kernel/svm/svm.h +++ b/intern/cycles/kernel/svm/svm.h @@ -326,6 +326,9 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT case NODE_MAPPING: svm_node_mapping(kg, sd, stack, node.y, node.z, &offset); break; + case NODE_MIN_MAX: + svm_node_min_max(kg, sd, stack, node.y, node.z, &offset); + break; case NODE_TEX_COORD: svm_node_tex_coord(kg, sd, stack, node.y, node.z); break; @@ -344,6 +347,9 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT case NODE_RGB_CURVES: svm_node_rgb_curves(kg, sd, stack, node, &offset); break; + case NODE_LIGHT_FALLOFF: + svm_node_light_falloff(sd, stack, node); + break; case NODE_END: default: #ifndef __MULTI_CLOSURE__ diff --git a/intern/cycles/kernel/svm/svm_light_path.h b/intern/cycles/kernel/svm/svm_light_path.h index ebbcb5be61f..b29dc9cbd45 100644 --- a/intern/cycles/kernel/svm/svm_light_path.h +++ b/intern/cycles/kernel/svm/svm_light_path.h @@ -39,5 +39,32 @@ __device void svm_node_light_path(ShaderData *sd, float *stack, uint type, uint stack_store_float(stack, out_offset, info); } +/* Light Falloff Node */ + +__device void svm_node_light_falloff(ShaderData *sd, float *stack, uint4 node) +{ + uint strength_offset, out_offset, smooth_offset; + + decode_node_uchar4(node.z, &strength_offset, &smooth_offset, &out_offset, NULL); + + float strength = stack_load_float(stack, strength_offset); + uint type = node.y; + + switch(type) { + case NODE_LIGHT_FALLOFF_QUADRATIC: break; + case NODE_LIGHT_FALLOFF_LINEAR: strength *= sd->ray_length; break; + case NODE_LIGHT_FALLOFF_CONSTANT: strength *= sd->ray_length*sd->ray_length; break; + } + + float smooth = stack_load_float(stack, smooth_offset); + + if(smooth > 0.0f) { + float squared = sd->ray_length*sd->ray_length; + strength *= squared/(smooth + squared); + } + + stack_store_float(stack, out_offset, strength); +} + CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/svm_mapping.h b/intern/cycles/kernel/svm/svm_mapping.h index 6dc74aece08..96645ac97db 100644 --- a/intern/cycles/kernel/svm/svm_mapping.h +++ b/intern/cycles/kernel/svm/svm_mapping.h @@ -34,5 +34,16 @@ __device void svm_node_mapping(KernelGlobals *kg, ShaderData *sd, float *stack, stack_store_float3(stack, out_offset, r); } +__device void svm_node_min_max(KernelGlobals *kg, ShaderData *sd, float *stack, uint vec_offset, uint out_offset, int *offset) +{ + float3 v = stack_load_float3(stack, vec_offset); + + float3 mn = float4_to_float3(read_node_float(kg, offset)); + float3 mx = float4_to_float3(read_node_float(kg, offset)); + + float3 r = min(max(mn, v), mx); + stack_store_float3(stack, out_offset, r); +} + CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h index 8037c3964a9..867709f29e0 100644 --- a/intern/cycles/kernel/svm/svm_types.h +++ b/intern/cycles/kernel/svm/svm_types.h @@ -90,7 +90,9 @@ typedef enum NodeType { NODE_TEX_CHECKER = 5700, NODE_BRIGHTCONTRAST = 5800, NODE_RGB_RAMP = 5900, - NODE_RGB_CURVES = 6000 + NODE_RGB_CURVES = 6000, + NODE_MIN_MAX = 6100, + NODE_LIGHT_FALLOFF = 6200 } NodeType; typedef enum NodeAttributeType { @@ -119,6 +121,12 @@ typedef enum NodeLightPath { NODE_LP_ray_length } NodeLightPath; +typedef enum NodeLightFalloff { + NODE_LIGHT_FALLOFF_QUADRATIC, + NODE_LIGHT_FALLOFF_LINEAR, + NODE_LIGHT_FALLOFF_CONSTANT +} NodeLightFalloff; + typedef enum NodeTexCoord { NODE_TEXCO_NORMAL, NODE_TEXCO_OBJECT, |