diff options
Diffstat (limited to 'intern/opencolorio/gpu_shader_display_transform.glsl')
-rw-r--r-- | intern/opencolorio/gpu_shader_display_transform.glsl | 40 |
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; } |