Cycles / Shader graph: Fallback to Sharp closures for very small roughness.
We fallback to Sharp closures for Glossy, Glass and Refraction nodes now, in case the Roughness input is disconnected and 0 (< 1e-4f to be exact). This way we gain a few percentages of performance, in case the user did not manually set the closure type to "Sharp" in the UI. Sharp will probably be removed from the UI as a followup, not needed anymore with this internal optimization. Original idea by Lukas Stockner(Differential Revision: https://developer.blender.org/D1439), code implementation by myself.
This commit is contained in:
@@ -1878,6 +1878,18 @@ GlossyBsdfNode::GlossyBsdfNode()
|
||||
add_input("Roughness", SHADER_SOCKET_FLOAT, 0.2f);
|
||||
}
|
||||
|
||||
void GlossyBsdfNode::optimize()
|
||||
{
|
||||
/* Fallback to Sharp closure for Roughness close to 0.
|
||||
* Note: Keep the epsilon in sync with kernel!
|
||||
*/
|
||||
ShaderInput *roughness_input = get_input("Roughness");
|
||||
if(!roughness_input->link && roughness_input->value.x <= 1e-4f) {
|
||||
closure = CLOSURE_BSDF_REFLECTION_ID;
|
||||
distribution = ustring("Sharp");
|
||||
}
|
||||
}
|
||||
|
||||
void GlossyBsdfNode::compile(SVMCompiler& compiler)
|
||||
{
|
||||
closure = (ClosureType)distribution_enum[distribution];
|
||||
@@ -1918,6 +1930,18 @@ GlassBsdfNode::GlassBsdfNode()
|
||||
add_input("IOR", SHADER_SOCKET_FLOAT, 0.3f);
|
||||
}
|
||||
|
||||
void GlassBsdfNode::optimize()
|
||||
{
|
||||
/* Fallback to Sharp closure for Roughness close to 0.
|
||||
* Note: Keep the epsilon in sync with kernel!
|
||||
*/
|
||||
ShaderInput *roughness_input = get_input("Roughness");
|
||||
if(!roughness_input->link && roughness_input->value.x <= 1e-4f) {
|
||||
closure = CLOSURE_BSDF_SHARP_GLASS_ID;
|
||||
distribution = ustring("Sharp");
|
||||
}
|
||||
}
|
||||
|
||||
void GlassBsdfNode::compile(SVMCompiler& compiler)
|
||||
{
|
||||
closure = (ClosureType)distribution_enum[distribution];
|
||||
@@ -1958,6 +1982,18 @@ RefractionBsdfNode::RefractionBsdfNode()
|
||||
add_input("IOR", SHADER_SOCKET_FLOAT, 0.3f);
|
||||
}
|
||||
|
||||
void RefractionBsdfNode::optimize()
|
||||
{
|
||||
/* Fallback to Sharp closure for Roughness close to 0.
|
||||
* Note: Keep the epsilon in sync with kernel!
|
||||
*/
|
||||
ShaderInput *roughness_input = get_input("Roughness");
|
||||
if(!roughness_input->link && roughness_input->value.x <= 1e-4f) {
|
||||
closure = CLOSURE_BSDF_REFRACTION_ID;
|
||||
distribution = ustring("Sharp");
|
||||
}
|
||||
}
|
||||
|
||||
void RefractionBsdfNode::compile(SVMCompiler& compiler)
|
||||
{
|
||||
closure = (ClosureType)distribution_enum[distribution];
|
||||
|
Reference in New Issue
Block a user