Skip to content

Commit e73c5d4

Browse files
authoredDec 4, 2020
Fix MSAA stripes (#9247)
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.
1 parent ecd4f45 commit e73c5d4

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed
 

Diff for: ‎builtin/settingtypes.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ texture_min_size (Minimum texture size) int 64
517517
# This algorithm smooths out the 3D viewport while keeping the image sharp,
518518
# but it doesn't affect the insides of textures
519519
# (which is especially noticeable with transparent textures).
520-
# This option is experimental and might cause visible spaces between blocks
521-
# when set above 0.
520+
# Visible spaces appear between nodes when shaders are disabled.
521+
# If set to 0, MSAA is disabled.
522522
# A restart is required after changing this option.
523523
fsaa (FSAA) enum 0 0,1,2,4,8,16
524524

Diff for: ‎client/shaders/nodes_shader/opengl_fragment.glsl

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ varying vec3 vPosition;
1616
// precision must be considered).
1717
varying vec3 worldPosition;
1818
varying lowp vec4 varColor;
19-
varying mediump vec2 varTexCoord;
19+
centroid varying mediump vec2 varTexCoord;
2020
varying vec3 eyeVec;
2121

2222
const float fogStart = FOG_START;
@@ -46,7 +46,7 @@ vec4 applyToneMapping(vec4 color)
4646
const float gamma = 1.6;
4747
const float exposureBias = 5.5;
4848
color.rgb = uncharted2Tonemap(exposureBias * color.rgb);
49-
// Precalculated white_scale from
49+
// Precalculated white_scale from
5050
//vec3 whiteScale = 1.0 / uncharted2Tonemap(vec3(W));
5151
vec3 whiteScale = vec3(1.036015346);
5252
color.rgb *= whiteScale;
@@ -72,7 +72,7 @@ void main(void)
7272
color = base.rgb;
7373

7474
vec4 col = vec4(color.rgb * varColor.rgb, 1.0);
75-
75+
7676
#ifdef ENABLE_TONE_MAPPING
7777
col = applyToneMapping(col);
7878
#endif

Diff for: ‎client/shaders/nodes_shader/opengl_vertex.glsl

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ varying vec3 vPosition;
1616
// precision must be considered).
1717
varying vec3 worldPosition;
1818
varying lowp vec4 varColor;
19-
varying mediump vec2 varTexCoord;
19+
// The centroid keyword ensures that after interpolation the texture coordinates
20+
// lie within the same bounds when MSAA is en- and disabled.
21+
// This fixes the stripes problem with nearest-neighbour textures and MSAA.
22+
centroid varying mediump vec2 varTexCoord;
2023
varying vec3 eyeVec;
2124

2225
// Color of the light emitted by the light sources.
@@ -142,7 +145,7 @@ void main(void)
142145
vec4 color;
143146
// The alpha gives the ratio of sunlight in the incoming light.
144147
float nightRatio = 1.0 - inVertexColor.a;
145-
color.rgb = inVertexColor.rgb * (inVertexColor.a * dayLight.rgb +
148+
color.rgb = inVertexColor.rgb * (inVertexColor.a * dayLight.rgb +
146149
nightRatio * artificialLight.rgb) * 2.0;
147150
color.a = 1.0;
148151

Diff for: ‎client/shaders/object_shader/opengl_fragment.glsl

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ varying vec3 vNormal;
99
varying vec3 vPosition;
1010
varying vec3 worldPosition;
1111
varying lowp vec4 varColor;
12-
varying mediump vec2 varTexCoord;
12+
centroid varying mediump vec2 varTexCoord;
1313

1414
varying vec3 eyeVec;
1515
varying float vIDiff;
@@ -43,7 +43,7 @@ vec4 applyToneMapping(vec4 color)
4343
const float gamma = 1.6;
4444
const float exposureBias = 5.5;
4545
color.rgb = uncharted2Tonemap(exposureBias * color.rgb);
46-
// Precalculated white_scale from
46+
// Precalculated white_scale from
4747
//vec3 whiteScale = 1.0 / uncharted2Tonemap(vec3(W));
4848
vec3 whiteScale = vec3(1.036015346);
4949
color.rgb *= whiteScale;

Diff for: ‎client/shaders/object_shader/opengl_vertex.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ varying vec3 vNormal;
77
varying vec3 vPosition;
88
varying vec3 worldPosition;
99
varying lowp vec4 varColor;
10-
varying mediump vec2 varTexCoord;
10+
centroid varying mediump vec2 varTexCoord;
1111

1212
varying vec3 eyeVec;
1313
varying float vIDiff;

0 commit comments

Comments
 (0)
Please sign in to comment.