]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Fix MSAA stripes (#9247)
authorHybridDog <3192173+HybridDog@users.noreply.github.com>
Fri, 4 Dec 2020 19:16:12 +0000 (20:16 +0100)
committerGitHub <noreply@github.com>
Fri, 4 Dec 2020 19:16:12 +0000 (20:16 +0100)
This only works when shaders are enabled.
The centroid varying avoids that the textures (which repeat themselves out of bounds) are sampled out of bounds in MSAA.
If MSAA (called FSAA in minetest) is disabled, the centroid keyword does nothing.

builtin/settingtypes.txt
client/shaders/nodes_shader/opengl_fragment.glsl
client/shaders/nodes_shader/opengl_vertex.glsl
client/shaders/object_shader/opengl_fragment.glsl
client/shaders/object_shader/opengl_vertex.glsl

index dd49142018d89e8d5c5a8f42444f3fedf59a89e3..384d12a1a7155d20a04acbd4d4d4ed232a7ab0f9 100644 (file)
@@ -517,8 +517,8 @@ texture_min_size (Minimum texture size) int 64
 #    This algorithm smooths out the 3D viewport while keeping the image sharp,
 #    but it doesn't affect the insides of textures
 #    (which is especially noticeable with transparent textures).
-#    This option is experimental and might cause visible spaces between blocks
-#    when set above 0.
+#    Visible spaces appear between nodes when shaders are disabled.
+#    If set to 0, MSAA is disabled.
 #    A restart is required after changing this option.
 fsaa (FSAA) enum 0 0,1,2,4,8,16
 
index 82c87073aa2a66b8359cad633d1f3f22e43ee07b..b0f6d45d0af46b659a6ad38069a3bc38975bbf21 100644 (file)
@@ -16,7 +16,7 @@ varying vec3 vPosition;
 // precision must be considered).
 varying vec3 worldPosition;
 varying lowp vec4 varColor;
-varying mediump vec2 varTexCoord;
+centroid varying mediump vec2 varTexCoord;
 varying vec3 eyeVec;
 
 const float fogStart = FOG_START;
@@ -46,7 +46,7 @@ vec4 applyToneMapping(vec4 color)
        const float gamma = 1.6;
        const float exposureBias = 5.5;
        color.rgb = uncharted2Tonemap(exposureBias * color.rgb);
-       // Precalculated white_scale from 
+       // Precalculated white_scale from
        //vec3 whiteScale = 1.0 / uncharted2Tonemap(vec3(W));
        vec3 whiteScale = vec3(1.036015346);
        color.rgb *= whiteScale;
@@ -72,7 +72,7 @@ void main(void)
        color = base.rgb;
 
        vec4 col = vec4(color.rgb * varColor.rgb, 1.0);
-       
+
 #ifdef ENABLE_TONE_MAPPING
        col = applyToneMapping(col);
 #endif
index cb344f6e6e36d3e42e9ca5662e0c343e48c94499..5742ec1d34d17c966dfe09d5487c8fd3db217028 100644 (file)
@@ -16,7 +16,10 @@ varying vec3 vPosition;
 // precision must be considered).
 varying vec3 worldPosition;
 varying lowp vec4 varColor;
-varying mediump vec2 varTexCoord;
+// The centroid keyword ensures that after interpolation the texture coordinates
+// lie within the same bounds when MSAA is en- and disabled.
+// This fixes the stripes problem with nearest-neighbour textures and MSAA.
+centroid varying mediump vec2 varTexCoord;
 varying vec3 eyeVec;
 
 // Color of the light emitted by the light sources.
@@ -142,7 +145,7 @@ void main(void)
        vec4 color;
        // The alpha gives the ratio of sunlight in the incoming light.
        float nightRatio = 1.0 - inVertexColor.a;
-       color.rgb = inVertexColor.rgb * (inVertexColor.a * dayLight.rgb + 
+       color.rgb = inVertexColor.rgb * (inVertexColor.a * dayLight.rgb +
                nightRatio * artificialLight.rgb) * 2.0;
        color.a = 1.0;
 
index 7ac182a632ea5de38a08b4d0d42174710f9bd99c..bf18c1499a6c2652dbdb8873e5e21f422f8cc5f2 100644 (file)
@@ -9,7 +9,7 @@ varying vec3 vNormal;
 varying vec3 vPosition;
 varying vec3 worldPosition;
 varying lowp vec4 varColor;
-varying mediump vec2 varTexCoord;
+centroid varying mediump vec2 varTexCoord;
 
 varying vec3 eyeVec;
 varying float vIDiff;
@@ -43,7 +43,7 @@ vec4 applyToneMapping(vec4 color)
        const float gamma = 1.6;
        const float exposureBias = 5.5;
        color.rgb = uncharted2Tonemap(exposureBias * color.rgb);
-       // Precalculated white_scale from 
+       // Precalculated white_scale from
        //vec3 whiteScale = 1.0 / uncharted2Tonemap(vec3(W));
        vec3 whiteScale = vec3(1.036015346);
        color.rgb *= whiteScale;
index e44984dc89d17689f780d174bac9ee36e17b2bdd..f31b842ee99c8236e24f92aba18fc9b3ab658f05 100644 (file)
@@ -7,7 +7,7 @@ varying vec3 vNormal;
 varying vec3 vPosition;
 varying vec3 worldPosition;
 varying lowp vec4 varColor;
-varying mediump vec2 varTexCoord;
+centroid varying mediump vec2 varTexCoord;
 
 varying vec3 eyeVec;
 varying float vIDiff;