Fix #35282: cycles color ramp set to constant interpolation did not work well.
This commit is contained in:
@@ -193,6 +193,7 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen
|
|||||||
RGBRampNode *ramp = new RGBRampNode();
|
RGBRampNode *ramp = new RGBRampNode();
|
||||||
BL::ShaderNodeValToRGB b_ramp_node(b_node);
|
BL::ShaderNodeValToRGB b_ramp_node(b_node);
|
||||||
colorramp_to_array(b_ramp_node.color_ramp(), ramp->ramp, RAMP_TABLE_SIZE);
|
colorramp_to_array(b_ramp_node.color_ramp(), ramp->ramp, RAMP_TABLE_SIZE);
|
||||||
|
ramp->interpolate = b_ramp_node.color_ramp().interpolation() != BL::ColorRamp::interpolation_CONSTANT;
|
||||||
node = ramp;
|
node = ramp;
|
||||||
}
|
}
|
||||||
else if (b_node.is_a(&RNA_ShaderNodeRGB)) {
|
else if (b_node.is_a(&RNA_ShaderNodeRGB)) {
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
shader node_rgb_ramp(
|
shader node_rgb_ramp(
|
||||||
color ramp_color[RAMP_TABLE_SIZE] = {0.0},
|
color ramp_color[RAMP_TABLE_SIZE] = {0.0},
|
||||||
float ramp_alpha[RAMP_TABLE_SIZE] = {0.0},
|
float ramp_alpha[RAMP_TABLE_SIZE] = {0.0},
|
||||||
|
int ramp_interpolate = 1,
|
||||||
|
|
||||||
float Fac = 0.0,
|
float Fac = 0.0,
|
||||||
output color Color = 0.0,
|
output color Color = 0.0,
|
||||||
@@ -38,7 +39,7 @@ shader node_rgb_ramp(
|
|||||||
Color = ramp_color[i];
|
Color = ramp_color[i];
|
||||||
Alpha = ramp_alpha[i];
|
Alpha = ramp_alpha[i];
|
||||||
|
|
||||||
if (t > 0.0) {
|
if (ramp_interpolate && t > 0.0) {
|
||||||
Color = (1.0 - t) * Color + t * ramp_color[i + 1];
|
Color = (1.0 - t) * Color + t * ramp_color[i + 1];
|
||||||
Alpha = (1.0 - t) * Alpha + t * ramp_alpha[i + 1];
|
Alpha = (1.0 - t) * Alpha + t * ramp_alpha[i + 1];
|
||||||
}
|
}
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
CCL_NAMESPACE_BEGIN
|
CCL_NAMESPACE_BEGIN
|
||||||
|
|
||||||
__device float4 rgb_ramp_lookup(KernelGlobals *kg, int offset, float f)
|
__device float4 rgb_ramp_lookup(KernelGlobals *kg, int offset, float f, bool interpolate)
|
||||||
{
|
{
|
||||||
f = clamp(f, 0.0f, 1.0f)*(RAMP_TABLE_SIZE-1);
|
f = clamp(f, 0.0f, 1.0f)*(RAMP_TABLE_SIZE-1);
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ __device float4 rgb_ramp_lookup(KernelGlobals *kg, int offset, float f)
|
|||||||
|
|
||||||
float4 a = fetch_node_float(kg, offset+i);
|
float4 a = fetch_node_float(kg, offset+i);
|
||||||
|
|
||||||
if(t > 0.0f)
|
if(interpolate && t > 0.0f)
|
||||||
a = (1.0f - t)*a + t*fetch_node_float(kg, offset+i+1);
|
a = (1.0f - t)*a + t*fetch_node_float(kg, offset+i+1);
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
@@ -39,12 +39,13 @@ __device float4 rgb_ramp_lookup(KernelGlobals *kg, int offset, float f)
|
|||||||
|
|
||||||
__device void svm_node_rgb_ramp(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
|
__device void svm_node_rgb_ramp(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
|
||||||
{
|
{
|
||||||
uint fac_offset = node.y;
|
uint fac_offset, color_offset, alpha_offset;
|
||||||
uint color_offset = node.z;
|
uint interpolate = node.z;
|
||||||
uint alpha_offset = node.w;
|
|
||||||
|
decode_node_uchar4(node.y, &fac_offset, &color_offset, &alpha_offset, NULL);
|
||||||
|
|
||||||
float fac = stack_load_float(stack, fac_offset);
|
float fac = stack_load_float(stack, fac_offset);
|
||||||
float4 color = rgb_ramp_lookup(kg, *offset, fac);
|
float4 color = rgb_ramp_lookup(kg, *offset, fac, interpolate);
|
||||||
|
|
||||||
if(stack_valid(color_offset))
|
if(stack_valid(color_offset))
|
||||||
stack_store_float3(stack, color_offset, float4_to_float3(color));
|
stack_store_float3(stack, color_offset, float4_to_float3(color));
|
||||||
@@ -63,9 +64,9 @@ __device void svm_node_rgb_curves(KernelGlobals *kg, ShaderData *sd, float *stac
|
|||||||
float fac = stack_load_float(stack, fac_offset);
|
float fac = stack_load_float(stack, fac_offset);
|
||||||
float3 color = stack_load_float3(stack, color_offset);
|
float3 color = stack_load_float3(stack, color_offset);
|
||||||
|
|
||||||
float r = rgb_ramp_lookup(kg, *offset, color.x).x;
|
float r = rgb_ramp_lookup(kg, *offset, color.x, true).x;
|
||||||
float g = rgb_ramp_lookup(kg, *offset, color.y).y;
|
float g = rgb_ramp_lookup(kg, *offset, color.y, true).y;
|
||||||
float b = rgb_ramp_lookup(kg, *offset, color.z).z;
|
float b = rgb_ramp_lookup(kg, *offset, color.z, true).z;
|
||||||
|
|
||||||
color = (1.0f - fac)*color + fac*make_float3(r, g, b);
|
color = (1.0f - fac)*color + fac*make_float3(r, g, b);
|
||||||
stack_store_float3(stack, out_offset, color);
|
stack_store_float3(stack, out_offset, color);
|
||||||
@@ -82,9 +83,9 @@ __device void svm_node_vector_curves(KernelGlobals *kg, ShaderData *sd, float *s
|
|||||||
float fac = stack_load_float(stack, fac_offset);
|
float fac = stack_load_float(stack, fac_offset);
|
||||||
float3 color = stack_load_float3(stack, color_offset);
|
float3 color = stack_load_float3(stack, color_offset);
|
||||||
|
|
||||||
float r = rgb_ramp_lookup(kg, *offset, (color.x + 1.0f)*0.5f).x;
|
float r = rgb_ramp_lookup(kg, *offset, (color.x + 1.0f)*0.5f, true).x;
|
||||||
float g = rgb_ramp_lookup(kg, *offset, (color.y + 1.0f)*0.5f).y;
|
float g = rgb_ramp_lookup(kg, *offset, (color.y + 1.0f)*0.5f, true).y;
|
||||||
float b = rgb_ramp_lookup(kg, *offset, (color.z + 1.0f)*0.5f).z;
|
float b = rgb_ramp_lookup(kg, *offset, (color.z + 1.0f)*0.5f, true).z;
|
||||||
|
|
||||||
color = (1.0f - fac)*color + fac*make_float3(r*2.0f - 1.0f, g*2.0f - 1.0f, b*2.0f - 1.0f);
|
color = (1.0f - fac)*color + fac*make_float3(r*2.0f - 1.0f, g*2.0f - 1.0f, b*2.0f - 1.0f);
|
||||||
stack_store_float3(stack, out_offset, color);
|
stack_store_float3(stack, out_offset, color);
|
||||||
|
@@ -3175,6 +3175,8 @@ RGBRampNode::RGBRampNode()
|
|||||||
add_input("Fac", SHADER_SOCKET_FLOAT);
|
add_input("Fac", SHADER_SOCKET_FLOAT);
|
||||||
add_output("Color", SHADER_SOCKET_COLOR);
|
add_output("Color", SHADER_SOCKET_COLOR);
|
||||||
add_output("Alpha", SHADER_SOCKET_FLOAT);
|
add_output("Alpha", SHADER_SOCKET_FLOAT);
|
||||||
|
|
||||||
|
interpolate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RGBRampNode::compile(SVMCompiler& compiler)
|
void RGBRampNode::compile(SVMCompiler& compiler)
|
||||||
@@ -3189,7 +3191,12 @@ void RGBRampNode::compile(SVMCompiler& compiler)
|
|||||||
if(!alpha_out->links.empty())
|
if(!alpha_out->links.empty())
|
||||||
compiler.stack_assign(alpha_out);
|
compiler.stack_assign(alpha_out);
|
||||||
|
|
||||||
compiler.add_node(NODE_RGB_RAMP, fac_in->stack_offset, color_out->stack_offset, alpha_out->stack_offset);
|
compiler.add_node(NODE_RGB_RAMP,
|
||||||
|
compiler.encode_uchar4(
|
||||||
|
fac_in->stack_offset,
|
||||||
|
color_out->stack_offset,
|
||||||
|
alpha_out->stack_offset),
|
||||||
|
interpolate);
|
||||||
compiler.add_array(ramp, RAMP_TABLE_SIZE);
|
compiler.add_array(ramp, RAMP_TABLE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3209,6 +3216,7 @@ void RGBRampNode::compile(OSLCompiler& compiler)
|
|||||||
|
|
||||||
compiler.parameter_color_array("ramp_color", ramp_color, RAMP_TABLE_SIZE);
|
compiler.parameter_color_array("ramp_color", ramp_color, RAMP_TABLE_SIZE);
|
||||||
compiler.parameter_array("ramp_alpha", ramp_alpha, RAMP_TABLE_SIZE);
|
compiler.parameter_array("ramp_alpha", ramp_alpha, RAMP_TABLE_SIZE);
|
||||||
|
compiler.parameter("ramp_interpolate", interpolate);
|
||||||
|
|
||||||
compiler.add(this, "node_rgb_ramp");
|
compiler.add(this, "node_rgb_ramp");
|
||||||
}
|
}
|
||||||
|
@@ -488,6 +488,7 @@ class RGBRampNode : public ShaderNode {
|
|||||||
public:
|
public:
|
||||||
SHADER_NODE_CLASS(RGBRampNode)
|
SHADER_NODE_CLASS(RGBRampNode)
|
||||||
float4 ramp[RAMP_TABLE_SIZE];
|
float4 ramp[RAMP_TABLE_SIZE];
|
||||||
|
bool interpolate;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SetNormalNode : public ShaderNode {
|
class SetNormalNode : public ShaderNode {
|
||||||
|
Reference in New Issue
Block a user