Fix T78956: banding artifacts of vertex colors in Cycles
Byte colors must be encoded in sRGB and converted to linear on lookup, to avoid precision loss.
This commit is contained in:
parent
dfe50ef2d8
commit
ec6a9322e8
Notes:
blender-bot
2023-02-14 04:46:12 +01:00
Referenced by issue #78956, Subdivision Surface Modifier causes vertex color map to display a lot of banding in cycles. (Eevee is fine)
|
@ -346,7 +346,7 @@ static void attr_create_vertex_color(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh,
|
|||
for (int i = 0; i < n; i++) {
|
||||
float4 color = get_float4(l->data[p->loop_start() + i].color());
|
||||
/* Compress/encode vertex color using the sRGB curve. */
|
||||
*(cdata++) = color_float4_to_uchar4(color_srgb_to_linear_v4(color));
|
||||
*(cdata++) = color_float4_to_uchar4(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -368,9 +368,10 @@ static void attr_create_vertex_color(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh,
|
|||
float4 c3 = get_float4(l->data[li[2]].color());
|
||||
|
||||
/* Compress/encode vertex color using the sRGB curve. */
|
||||
cdata[0] = color_float4_to_uchar4(color_srgb_to_linear_v4(c1));
|
||||
cdata[1] = color_float4_to_uchar4(color_srgb_to_linear_v4(c2));
|
||||
cdata[2] = color_float4_to_uchar4(color_srgb_to_linear_v4(c3));
|
||||
cdata[0] = color_float4_to_uchar4(c1);
|
||||
cdata[1] = color_float4_to_uchar4(c2);
|
||||
cdata[2] = color_float4_to_uchar4(c3);
|
||||
|
||||
cdata += 3;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -405,7 +405,8 @@ ccl_device float4 patch_eval_uchar4(KernelGlobals *kg,
|
|||
*dv = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
for (int i = 0; i < num_control; i++) {
|
||||
float4 v = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, offset + indices[i]));
|
||||
float4 v = color_srgb_to_linear_v4(
|
||||
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, offset + indices[i])));
|
||||
|
||||
val += v * weights[i];
|
||||
if (du)
|
||||
|
|
|
@ -581,14 +581,14 @@ ccl_device_noinline float4 subd_triangle_attribute_float4(KernelGlobals *kg,
|
|||
int corners[4];
|
||||
subd_triangle_patch_corners(kg, patch, corners);
|
||||
|
||||
float4 f0 = color_uchar4_to_float4(
|
||||
kernel_tex_fetch(__attributes_uchar4, corners[0] + desc.offset));
|
||||
float4 f1 = color_uchar4_to_float4(
|
||||
kernel_tex_fetch(__attributes_uchar4, corners[1] + desc.offset));
|
||||
float4 f2 = color_uchar4_to_float4(
|
||||
kernel_tex_fetch(__attributes_uchar4, corners[2] + desc.offset));
|
||||
float4 f3 = color_uchar4_to_float4(
|
||||
kernel_tex_fetch(__attributes_uchar4, corners[3] + desc.offset));
|
||||
float4 f0 = color_srgb_to_linear_v4(
|
||||
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[0] + desc.offset)));
|
||||
float4 f1 = color_srgb_to_linear_v4(
|
||||
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[1] + desc.offset)));
|
||||
float4 f2 = color_srgb_to_linear_v4(
|
||||
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[2] + desc.offset)));
|
||||
float4 f3 = color_srgb_to_linear_v4(
|
||||
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[3] + desc.offset)));
|
||||
|
||||
if (subd_triangle_patch_num_corners(kg, patch) != 4) {
|
||||
f1 = (f1 + f0) * 0.5f;
|
||||
|
@ -614,7 +614,8 @@ ccl_device_noinline float4 subd_triangle_attribute_float4(KernelGlobals *kg,
|
|||
if (dy)
|
||||
*dy = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
return color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, desc.offset));
|
||||
return color_srgb_to_linear_v4(
|
||||
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, desc.offset)));
|
||||
}
|
||||
else {
|
||||
if (dx)
|
||||
|
|
|
@ -317,9 +317,12 @@ ccl_device float4 triangle_attribute_float4(KernelGlobals *kg,
|
|||
|
||||
if (desc.element == ATTR_ELEMENT_CORNER_BYTE) {
|
||||
int tri = desc.offset + sd->prim * 3;
|
||||
f0 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 0));
|
||||
f1 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 1));
|
||||
f2 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 2));
|
||||
f0 = color_srgb_to_linear_v4(
|
||||
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 0)));
|
||||
f1 = color_srgb_to_linear_v4(
|
||||
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 1)));
|
||||
f2 = color_srgb_to_linear_v4(
|
||||
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 2)));
|
||||
}
|
||||
else {
|
||||
uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
|
||||
|
@ -343,7 +346,8 @@ ccl_device float4 triangle_attribute_float4(KernelGlobals *kg,
|
|||
if (dy)
|
||||
*dy = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
return color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, desc.offset));
|
||||
return color_srgb_to_linear_v4(
|
||||
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, desc.offset)));
|
||||
}
|
||||
else {
|
||||
if (dx)
|
||||
|
|
Loading…
Reference in New Issue