Workbench: Fix srgb texture not being color managed in texture color mode
This commit is contained in:
parent
0d511e05d3
commit
29877fb1a4
|
@ -141,3 +141,21 @@ vec2 matcap_uv_compute(vec3 I, vec3 N, bool flipped)
|
|||
}
|
||||
return matcap_uv * 0.496 + 0.5;
|
||||
}
|
||||
|
||||
float srgb_to_linearrgb(float c)
|
||||
{
|
||||
if (c < 0.04045)
|
||||
return (c < 0.0) ? 0.0 : c * (1.0 / 12.92);
|
||||
else
|
||||
return pow((c + 0.055) * (1.0 / 1.055), 2.4);
|
||||
}
|
||||
|
||||
vec4 srgb_to_linearrgb(vec4 col_from)
|
||||
{
|
||||
vec4 col_to;
|
||||
col_to.r = srgb_to_linearrgb(col_from.r);
|
||||
col_to.g = srgb_to_linearrgb(col_from.g);
|
||||
col_to.b = srgb_to_linearrgb(col_from.b);
|
||||
col_to.a = col_from.a;
|
||||
return col_to;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifdef V3D_SHADING_TEXTURE_COLOR
|
||||
uniform sampler2D image;
|
||||
uniform float ImageTransparencyCutoff = 0.1;
|
||||
|
||||
#endif
|
||||
uniform float ImageTransparencyCutoff = 0.1;
|
||||
uniform sampler2D image;
|
||||
uniform bool imageSrgb;
|
||||
|
||||
uniform mat4 ProjectionMatrix;
|
||||
uniform mat4 ViewMatrixInverse;
|
||||
uniform float alpha = 0.5;
|
||||
|
@ -39,6 +39,9 @@ void main()
|
|||
if (diffuse_color.a < ImageTransparencyCutoff) {
|
||||
discard;
|
||||
}
|
||||
if (imageSrgb) {
|
||||
diffuse_color = srgb_to_linearrgb(diffuse_color);
|
||||
}
|
||||
#else
|
||||
diffuse_color = vec4(materialDiffuseColor, 1.0);
|
||||
#endif /* V3D_SHADING_TEXTURE_COLOR */
|
||||
|
|
|
@ -6,6 +6,7 @@ uniform float materialRoughness;
|
|||
|
||||
uniform sampler2D image;
|
||||
uniform float ImageTransparencyCutoff = 0.1;
|
||||
uniform bool imageSrgb;
|
||||
|
||||
#ifdef NORMAL_VIEWPORT_PASS_ENABLED
|
||||
in vec3 normal_viewport;
|
||||
|
@ -40,6 +41,9 @@ void main()
|
|||
if (color.a < ImageTransparencyCutoff) {
|
||||
discard;
|
||||
}
|
||||
if (imageSrgb) {
|
||||
color = srgb_to_linearrgb(color);
|
||||
}
|
||||
# else
|
||||
color.rgb = materialDiffuseColor;
|
||||
# endif
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "BIF_gl.h"
|
||||
|
||||
#include "BKE_image.h"
|
||||
|
||||
#include "BLI_dynstr.h"
|
||||
#include "BLI_hash.h"
|
||||
|
||||
|
@ -189,8 +191,12 @@ void workbench_material_shgroup_uniform(
|
|||
}
|
||||
|
||||
if (workbench_material_determine_color_type(wpd, material->ima, ob) == V3D_SHADING_TEXTURE_COLOR) {
|
||||
ImBuf *ibuf = BKE_image_acquire_ibuf(material->ima, NULL, NULL);
|
||||
const bool do_color_correction = (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0);
|
||||
BKE_image_release_ibuf(material->ima, ibuf, NULL);
|
||||
GPUTexture *tex = GPU_texture_from_blender(material->ima, NULL, GL_TEXTURE_2D, false, 0.0f);
|
||||
DRW_shgroup_uniform_texture(grp, "image", tex);
|
||||
DRW_shgroup_uniform_bool_copy(grp, "imageSrgb", do_color_correction);
|
||||
}
|
||||
else {
|
||||
DRW_shgroup_uniform_vec3(grp, "materialDiffuseColor", (use_metallic) ? material->base_color : material->diffuse_color, 1);
|
||||
|
|
Loading…
Reference in New Issue