diff options
author | Lukas Stockner <lukas.stockner@freenet.de> | 2016-09-03 23:40:07 +0300 |
---|---|---|
committer | Lukas Stockner <lukas.stockner@freenet.de> | 2016-09-09 02:39:09 +0300 |
commit | 1558f5b6602ebe8ba31455b1837b2594d5c7f264 (patch) | |
tree | 7cc89f0098577099d916e4f3e27d2e2885444252 /intern/cycles/render/shader.cpp | |
parent | 6de08f6cd1cb9e50736a0a43bf37d621c6eb2b87 (diff) |
Cycles: Don't run full shader evaluation for constant emission lamps
Most of the time, Lamps in Cycles are just a constant emission closure, no texturing etc. Therefore, running a full shader evaluation is wasteful.
To avoid that, Cycles now detects these constant emission shaders and stores their value in the lamp data along with a flag in the shader.
Then, at runtime, if this flag is set, the lamp code just uses this value and only runs the full shader evaluation if it is neccessary.
In scenes with a lot of lamps and with "Sample all direct/indirect" enabled, this saves up to 20% of rendering time in my tests.
Reviewers: #cycles
Differential Revision: https://developer.blender.org/D2193
Diffstat (limited to 'intern/cycles/render/shader.cpp')
-rw-r--r-- | intern/cycles/render/shader.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/intern/cycles/render/shader.cpp b/intern/cycles/render/shader.cpp index 70e1443be2c..1849161ead9 100644 --- a/intern/cycles/render/shader.cpp +++ b/intern/cycles/render/shader.cpp @@ -194,6 +194,28 @@ Shader::~Shader() delete graph_bump; } +bool Shader::is_constant_emission(float3 *emission) +{ + ShaderInput *surf = graph->output()->input("Surface"); + + if(!surf->link || surf->link->parent->type != EmissionNode::node_type) { + return false; + } + + EmissionNode *node = (EmissionNode*) surf->link->parent; + + assert(node->input("Color")); + assert(node->input("Strength")); + + if(node->input("Color")->link || node->input("Strength")->link) { + return false; + } + + *emission = node->color*node->strength; + + return true; +} + void Shader::set_graph(ShaderGraph *graph_) { /* do this here already so that we can detect if mesh or object attributes |