diff options
-rw-r--r-- | intern/cycles/kernel/svm/svm_gamma.h | 7 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_math_util.h | 12 | ||||
-rw-r--r-- | intern/cycles/render/nodes.cpp | 17 | ||||
-rw-r--r-- | intern/cycles/render/nodes.h | 3 |
4 files changed, 33 insertions, 6 deletions
diff --git a/intern/cycles/kernel/svm/svm_gamma.h b/intern/cycles/kernel/svm/svm_gamma.h index b645ff3f0f9..171945a60bc 100644 --- a/intern/cycles/kernel/svm/svm_gamma.h +++ b/intern/cycles/kernel/svm/svm_gamma.h @@ -21,12 +21,7 @@ ccl_device void svm_node_gamma(ShaderData *sd, float *stack, uint in_gamma, uint float3 color = stack_load_float3(stack, in_color); float gamma = stack_load_float(stack, in_gamma); - if(color.x > 0.0f) - color.x = powf(color.x, gamma); - if(color.y > 0.0f) - color.y = powf(color.y, gamma); - if(color.z > 0.0f) - color.z = powf(color.z, gamma); + color = svm_math_gamma_color(color, gamma); if(stack_valid(out_color)) stack_store_float3(stack, out_color, color); diff --git a/intern/cycles/kernel/svm/svm_math_util.h b/intern/cycles/kernel/svm/svm_math_util.h index 645cbd3fc73..3f7d18a02fe 100644 --- a/intern/cycles/kernel/svm/svm_math_util.h +++ b/intern/cycles/kernel/svm/svm_math_util.h @@ -166,5 +166,17 @@ ccl_device float3 svm_math_blackbody_color(float t) { return make_float3(4.70366907f, 0.0f, 0.0f); } +ccl_device_inline float3 svm_math_gamma_color(float3 color, float gamma) +{ + if(color.x > 0.0f) + color.x = powf(color.x, gamma); + if(color.y > 0.0f) + color.y = powf(color.y, gamma); + if(color.z > 0.0f) + color.z = powf(color.z, gamma); + + return color; +} + CCL_NAMESPACE_END diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 2771d35990e..678f7b31334 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -3516,6 +3516,23 @@ GammaNode::GammaNode() add_output("Color", SHADER_SOCKET_COLOR); } +bool GammaNode::constant_fold(ShaderOutput *socket, float3 *optimized_value) +{ + ShaderInput *color_in = input("Color"); + ShaderInput *gamma_in = input("Gamma"); + + if(socket == output("Color")) { + if(color_in->link == NULL && gamma_in->link == NULL) { + *optimized_value = svm_math_gamma_color(color_in->value, + gamma_in->value.x); + + return true; + } + } + + return false; +} + void GammaNode::compile(SVMCompiler& compiler) { ShaderInput *color_in = input("Color"); diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h index 51efbc37f38..8c5f6651463 100644 --- a/intern/cycles/render/nodes.h +++ b/intern/cycles/render/nodes.h @@ -557,6 +557,9 @@ public: class GammaNode : public ShaderNode { public: SHADER_NODE_CLASS(GammaNode) + + bool constant_fold(ShaderOutput *socket, float3 *optimized_value); + virtual int get_group() { return NODE_GROUP_LEVEL_1; } }; |