Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2020-04-14 21:44:45 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-04-14 21:44:56 +0300
commit21c658b718b9bd0f79f435a6a8a8603c365264a5 (patch)
treebcaa239369d799368236d4303f33d674c3cb14f3 /source/blender/gpu/shaders
parentbf49bb354fca4ad96f8f3e6802ecf733b29ac3e3 (diff)
GPUShader: Implement workaround for gizmo drawing on sRGB framebuffer
This solution involves adding a uniform to each fragment shader that is used by gizmo drawing and use the framebuffer state to set this uniform accordingly. This solution can also be carried to external shaders (addons). A single line of code would then be enough to fix the issue. The only trickery here is the dummy define: `#define srgb_to_framebuffer_space(a)` This is in order to avoid breaking other DRW shaders that use the same fragment shader code but do not need the tranformation. Related to T74139 Reviewed By: brecht, campbellbarton Differential Revision: https://developer.blender.org/D7261
Diffstat (limited to 'source/blender/gpu/shaders')
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl1
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl1
-rw-r--r--source/blender/gpu/shaders/gpu_shader_colorspace_lib.glsl16
-rw-r--r--source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl1
-rw-r--r--source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl1
5 files changed, 20 insertions, 0 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl
index 4f275c5b220..1333c00682c 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl
@@ -5,4 +5,5 @@ out vec4 fragColor;
void main()
{
fragColor = finalColor;
+ fragColor = blender_srgb_to_framebuffer_space(fragColor);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl
index 7bd44ba9b88..3a2d96c9929 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl
@@ -5,4 +5,5 @@ out vec4 fragColor;
void main()
{
fragColor = finalColor;
+ fragColor = blender_srgb_to_framebuffer_space(fragColor);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_colorspace_lib.glsl b/source/blender/gpu/shaders/gpu_shader_colorspace_lib.glsl
new file mode 100644
index 00000000000..aae659516bb
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_colorspace_lib.glsl
@@ -0,0 +1,16 @@
+
+/* Undefine the macro that avoids compilation errors. */
+#undef blender_srgb_to_framebuffer_space
+
+uniform bool srgbTarget = false;
+
+vec4 blender_srgb_to_framebuffer_space(vec4 color)
+{
+ if (srgbTarget) {
+ vec3 c = max(color.rgb, vec3(0.0));
+ vec3 c1 = c * (1.0 / 12.92);
+ vec3 c2 = pow((c + 0.055) * (1.0 / 1.055), vec3(2.4));
+ color.rgb = mix(c1, c2, step(vec3(0.04045), c));
+ }
+ return color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl
index 6c214534812..99d8b6ab685 100644
--- a/source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl
@@ -5,4 +5,5 @@ out vec4 fragColor;
void main()
{
fragColor = finalColor;
+ fragColor = blender_srgb_to_framebuffer_space(fragColor);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl
index d9f84964eb4..2033401db67 100644
--- a/source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl
@@ -17,4 +17,5 @@ void main()
#else
fragColor = color;
#endif
+ fragColor = blender_srgb_to_framebuffer_space(fragColor);
}