diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-03-26 16:45:14 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-03-26 16:45:14 +0400 |
commit | bbc3d820f44ca62810c1800cf7caa3905b6116a6 (patch) | |
tree | 3cb45928cc5e8e758b3cabd18ebe79a763f162d5 /intern/cycles/kernel/svm | |
parent | 56baed13da0e3cf1206afd17f65bba00ec4a287c (diff) |
Cycles: add ColorRamp node.
Diffstat (limited to 'intern/cycles/kernel/svm')
-rw-r--r-- | intern/cycles/kernel/svm/svm.h | 13 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_ramp.h | 74 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_types.h | 4 |
3 files changed, 90 insertions, 1 deletions
diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h index f1bae9c8d9f..50181c0cf2c 100644 --- a/intern/cycles/kernel/svm/svm.h +++ b/intern/cycles/kernel/svm/svm.h @@ -104,6 +104,12 @@ __device_inline float4 read_node_float(KernelGlobals *kg, int *offset) return f; } +__device_inline float4 fetch_node_float(KernelGlobals *kg, int offset) +{ + uint4 node = kernel_tex_fetch(__svm_nodes, offset); + return make_float4(__int_as_float(node.x), __int_as_float(node.y), __int_as_float(node.z), __int_as_float(node.w)); +} + __device_inline void decode_node_uchar4(uint i, uint *x, uint *y, uint *z, uint *w) { if(x) *x = (i & 0xFF); @@ -140,6 +146,7 @@ CCL_NAMESPACE_END #include "svm_wave.h" #include "svm_math.h" #include "svm_mix.h" +#include "svm_ramp.h" #include "svm_sepcomb_rgb.h" #include "svm_musgrave.h" #include "svm_sky.h" @@ -331,6 +338,12 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT case NODE_EMISSION_SET_WEIGHT_TOTAL: svm_node_emission_set_weight_total(kg, sd, node.y, node.z, node.w); break; + case NODE_RGB_RAMP: + svm_node_rgb_ramp(kg, sd, stack, node, &offset); + break; + case NODE_RGB_CURVES: + svm_node_rgb_curves(kg, sd, stack, node, &offset); + break; case NODE_END: default: #ifndef __MULTI_CLOSURE__ diff --git a/intern/cycles/kernel/svm/svm_ramp.h b/intern/cycles/kernel/svm/svm_ramp.h new file mode 100644 index 00000000000..0654240c21b --- /dev/null +++ b/intern/cycles/kernel/svm/svm_ramp.h @@ -0,0 +1,74 @@ +/* + * 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. + */ + +#ifndef __SVM_RAMP_H__ +#define __SVM_RAMP_H__ + +CCL_NAMESPACE_BEGIN + +__device float4 rgb_ramp_lookup(KernelGlobals *kg, int offset, float f) +{ + f = clamp(f, 0.0f, 1.0f)*(RAMP_TABLE_SIZE-1); + + int i = (int)f; + float t = f - (float)i; + + float4 a = fetch_node_float(kg, offset+i); + + if(t > 0.0f) + a = (1.0f - t)*a + t*fetch_node_float(kg, offset+i+1); + + return a; +} + +__device void svm_node_rgb_ramp(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) +{ + uint fac_offset = node.y; + uint color_offset = node.z; + + float fac = stack_load_float(stack, fac_offset); + float4 color = rgb_ramp_lookup(kg, *offset, fac); + + stack_store_float3(stack, color_offset, float4_to_float3(color)); + + *offset += RAMP_TABLE_SIZE; +} + +__device void svm_node_rgb_curves(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) +{ + uint fac_offset = node.y; + uint color_offset = node.z; + uint out_offset = node.w; + + float fac = stack_load_float(stack, fac_offset); + float3 color = stack_load_float3(stack, color_offset); + + float r = rgb_ramp_lookup(kg, *offset, rgb_ramp_lookup(kg, *offset, color.x).w).x; + float g = rgb_ramp_lookup(kg, *offset, rgb_ramp_lookup(kg, *offset, color.y).w).y; + float b = rgb_ramp_lookup(kg, *offset, rgb_ramp_lookup(kg, *offset, color.z).w).z; + + color = (1.0f - fac)*color + fac*make_float3(r, g, b); + stack_store_float3(stack, out_offset, color); + + *offset += RAMP_TABLE_SIZE; +} + +CCL_NAMESPACE_END + +#endif /* __SVM_RAMP_H__ */ + diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h index 533a2944557..13d72307765 100644 --- a/intern/cycles/kernel/svm/svm_types.h +++ b/intern/cycles/kernel/svm/svm_types.h @@ -88,7 +88,9 @@ typedef enum NodeType { NODE_NORMAL = 5500, NODE_GAMMA = 5600, NODE_TEX_CHECKER = 5700, - NODE_BRIGHTCONTRAST = 5800 + NODE_BRIGHTCONTRAST = 5800, + NODE_RGB_RAMP = 5900, + NODE_RGB_CURVES = 6000 } NodeType; typedef enum NodeAttributeType { |