Cycles: add constant folding to displacement nodes.

This commit is contained in:
Brecht Van Lommel 2018-03-11 22:42:38 +01:00
parent 629d44e049
commit e07dd9fd59
2 changed files with 21 additions and 0 deletions

View File

@ -5785,6 +5785,15 @@ DisplacementNode::DisplacementNode()
{
}
void DisplacementNode::constant_fold(const ConstantFolder& folder)
{
if(folder.all_inputs_constant()) {
if((height - midlevel == 0.0f) || (scale == 0.0f)) {
folder.make_zero();
}
}
}
void DisplacementNode::compile(SVMCompiler& compiler)
{
ShaderInput *height_in = input("Height");
@ -5836,6 +5845,16 @@ VectorDisplacementNode::VectorDisplacementNode()
{
}
void VectorDisplacementNode::constant_fold(const ConstantFolder& folder)
{
if(folder.all_inputs_constant()) {
if((vector == make_float3(0.0f, 0.0f, 0.0f) && midlevel == 0.0f) ||
(scale == 0.0f)) {
folder.make_zero();
}
}
}
void VectorDisplacementNode::attributes(Shader *shader, AttributeRequestSet *attributes)
{
if(shader->has_surface && space == NODE_NORMAL_MAP_TANGENT) {

View File

@ -1063,6 +1063,7 @@ public:
class DisplacementNode : public ShaderNode {
public:
SHADER_NODE_CLASS(DisplacementNode)
void constant_fold(const ConstantFolder& folder);
virtual int get_feature() {
return NODE_FEATURE_BUMP;
}
@ -1079,6 +1080,7 @@ public:
SHADER_NODE_CLASS(VectorDisplacementNode)
void attributes(Shader *shader, AttributeRequestSet *attributes);
bool has_attribute_dependency() { return true; }
void constant_fold(const ConstantFolder& folder);
virtual int get_feature() {
return NODE_FEATURE_BUMP;
}