mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add dithering (#9014)
This commit is contained in:
parent
5d3e830176
commit
b1aec1b5c8
4 changed files with 42 additions and 0 deletions
|
@ -1,6 +1,13 @@
|
|||
#define rendered texture0
|
||||
#define bloom texture1
|
||||
|
||||
#ifdef GL_ES
|
||||
// Dithering requires sufficient floating-point precision
|
||||
#ifndef GL_FRAGMENT_PRECISION_HIGH
|
||||
#undef ENABLE_DITHERING
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct ExposureParams {
|
||||
float compensationFactor;
|
||||
};
|
||||
|
@ -79,6 +86,20 @@ vec3 applySaturation(vec3 color, float factor)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_DITHERING
|
||||
// From http://alex.vlachos.com/graphics/Alex_Vlachos_Advanced_VR_Rendering_GDC2015.pdf
|
||||
// and https://www.shadertoy.com/view/MslGR8 (5th one starting from the bottom)
|
||||
// NOTE: `frag_coord` is in pixels (i.e. not normalized UV).
|
||||
vec3 screen_space_dither(highp vec2 frag_coord) {
|
||||
// Iestyn's RGB dither (7 asm instructions) from Portal 2 X360, slightly modified for VR.
|
||||
highp vec3 dither = vec3(dot(vec2(171.0, 231.0), frag_coord));
|
||||
dither.rgb = fract(dither.rgb / vec3(103.0, 71.0, 97.0));
|
||||
|
||||
// Subtract 0.5 to avoid slightly brightening the whole viewport.
|
||||
return (dither.rgb - 0.5) / 255.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec2 uv = varTexCoord.st;
|
||||
|
@ -125,5 +146,10 @@ void main(void)
|
|||
// return to sRGB colorspace (approximate)
|
||||
color.rgb = pow(color.rgb, vec3(1.0 / 2.2));
|
||||
|
||||
#ifdef ENABLE_DITHERING
|
||||
// Apply dithering just before quantisation
|
||||
color.rgb += screen_space_dither(gl_FragCoord.xy);
|
||||
#endif
|
||||
|
||||
gl_FragColor = vec4(color.rgb, 1.0); // force full alpha to avoid holes in the image.
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue