Skip to content

Commit

Permalink
OpenGL ES float precision
Browse files Browse the repository at this point in the history
  • Loading branch information
HybridDog committed Dec 10, 2023
1 parent 39d09a0 commit 343957e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions builtin/settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,8 @@ exposure_compensation (Exposure compensation) float 0.0 -1.0 1.0
# screenshots and it works incorrectly if the display or operating system
# performs additional dithering or if the color channels are not quantized
# to 8 bits.
# With OpenGL ES, dithering only works if the shader supports high
# floating-point precision.
#
# Requires: shaders
debanding (Enable Debanding) bool true
Expand Down
11 changes: 9 additions & 2 deletions client/shaders/second_stage/opengl_fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#define rendered texture0
#define bloom texture1

#ifdef GL_ES
// Dithering requires sufficient floating-point precision
#if GL_FRAGMENT_PRECISION_HIGH != 1
#undef ENABLE_DITHERING
#endif
#endif

struct ExposureParams {
float compensationFactor;
};
Expand Down Expand Up @@ -83,9 +90,9 @@ vec3 applySaturation(vec3 color, float factor)
// 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(vec2 frag_coord) {
vec3 screen_space_dither(highp vec2 frag_coord) {
// Iestyn's RGB dither (7 asm instructions) from Portal 2 X360, slightly modified for VR.
vec3 dither = vec3(dot(vec2(171.0, 231.0), frag_coord));
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.
Expand Down

0 comments on commit 343957e

Please sign in to comment.