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:
authorSergey Sharybin <sergey.vfx@gmail.com>2013-12-13 10:36:45 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2013-12-13 10:36:45 +0400
commit5a91df32713b7ad9be6befa7124b31890063d91b (patch)
tree11309c67510bb0ffd29438318896cf86b8024c02 /intern/opencolorio/gpu_shader_display_transform.glsl
parent669b5902298f0f80159395d020657d6630a532ac (diff)
Implement GPU-side dither
Summary: Uses some magic pseudo-random which is actually a texture coordinate hashing function. TODOs: - Dither noise is the same for all the frames. - It's different from Floyd's dither we've been using before. - Currently CPU and GPU dithering used different implementation. Ideally we need to use the same dither in CPU. Reviewers: brecht Reviewed By: brecht Differential Revision: http://developer.blender.org/D58
Diffstat (limited to 'intern/opencolorio/gpu_shader_display_transform.glsl')
-rw-r--r--intern/opencolorio/gpu_shader_display_transform.glsl40
1 files changed, 39 insertions, 1 deletions
diff --git a/intern/opencolorio/gpu_shader_display_transform.glsl b/intern/opencolorio/gpu_shader_display_transform.glsl
index 6ba3fa55e8f..8a85d6cbffe 100644
--- a/intern/opencolorio/gpu_shader_display_transform.glsl
+++ b/intern/opencolorio/gpu_shader_display_transform.glsl
@@ -2,6 +2,10 @@ uniform sampler2D image_texture;
uniform sampler3D lut3d_texture;
uniform bool predivide;
+#ifdef USE_DITHER
+uniform float dither;
+#endif
+
#ifdef USE_CURVE_MAPPING
/* Curve mapping parameters
*
@@ -102,6 +106,33 @@ vec4 curvemapping_evaluate_premulRGBF(vec4 col)
}
#endif
+#ifdef USE_DITHER
+float dither_random_value(vec2 co)
+{
+ return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453) * 0.005 * dither;
+}
+
+vec2 round_to_pixel(vec2 st)
+{
+ vec2 result;
+ vec2 size = textureSize(image_texture, 0);
+ result.x = float(int(st.x * size.x)) / size.x;
+ result.y = float(int(st.y * size.y)) / size.y;
+ return result;
+}
+
+vec4 apply_dither(vec2 st, vec4 col)
+{
+ vec4 result;
+ float random_value = dither_random_value(round_to_pixel(st));
+ result.r = col.r + random_value;
+ result.g = col.g + random_value;
+ result.b = col.b + random_value;
+ result.a = col.a;
+ return result;
+}
+#endif
+
void main()
{
vec4 col = texture2D(image_texture, gl_TexCoord[0].st);
@@ -119,5 +150,12 @@ void main()
* and the reason is simple -- opengl is always configured
* for straight alpha at this moment
*/
- gl_FragColor = OCIODisplay(col, lut3d_texture);
+
+ vec4 result = OCIODisplay(col, lut3d_texture);
+
+#ifdef USE_DITHER
+ result = apply_dither(gl_TexCoord[0].st, result);
+#endif
+
+ gl_FragColor = result;
}