Skip to content

Commit d164f1b

Browse files
author
pdavidc
committed
Modified the GLSL surface texture program to use multiple varyings instead of an array of varyings
1 parent fad289e commit d164f1b

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

worldwind/src/main/res/raw/gov_nasa_worldwind_surfacetextureprogram_frag.glsl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,25 @@ uniform bool enableTexture;
1010
uniform vec4 color;
1111
uniform sampler2D texSampler;
1212

13-
varying vec2 texCoord[2];
13+
varying vec2 texCoord;
14+
varying vec2 tileCoord;
1415

1516
void main() {
1617
/* Using the second texture coordinate, compute a mask that's 1.0 when the fragment is inside the surface tile, and
1718
0.0 otherwise. */
18-
float sMask = step(0.0, texCoord[1].s) * (1.0 - step(1.0, texCoord[1].s));
19-
float tMask = step(0.0, texCoord[1].t) * (1.0 - step(1.0, texCoord[1].t));
19+
float sMask = step(0.0, tileCoord.s) * (1.0 - step(1.0, tileCoord.s));
20+
float tMask = step(0.0, tileCoord.t) * (1.0 - step(1.0, tileCoord.t));
2021
float tileMask = sMask * tMask;
2122

2223
if (enablePickMode && enableTexture) {
2324
/* Using the first texture coordinate, modulate the RGBA color with the 2D texture's Alpha component (rounded to
2425
0.0 or 1.0). Finally, modulate the result by the tile mask to suppress fragments outside the surface tile. */
25-
float texMask = floor(texture2D(texSampler, texCoord[0]).a + 0.5);
26+
float texMask = floor(texture2D(texSampler, texCoord).a + 0.5);
2627
gl_FragColor = color * texMask * tileMask;
2728
} else if (!enablePickMode && enableTexture) {
2829
/* Using the first texture coordinate, modulate the RGBA color with the 2D texture's RGBA color. Finally,
2930
modulate by the tile mask to suppress fragments outside the surface tile. */
30-
gl_FragColor = color * texture2D(texSampler, texCoord[0]) * tileMask;
31+
gl_FragColor = color * texture2D(texSampler, texCoord) * tileMask;
3132
} else {
3233
/* Modulate the RGBA color by the tile mask to suppress fragments outside the surface tile. */
3334
gl_FragColor = color * tileMask;

worldwind/src/main/res/raw/gov_nasa_worldwind_surfacetextureprogram_vert.glsl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ uniform mat3 texCoordMatrix[2];
1212
attribute vec4 vertexPoint;
1313
attribute vec2 vertexTexCoord;
1414

15-
varying vec2 texCoord[2];
15+
varying vec2 texCoord;
16+
varying vec2 tileCoord;
1617

1718
void main() {
1819
/* Transform the vertex position by the modelview-projection matrix. */
@@ -21,7 +22,7 @@ void main() {
2122
/* Transform the vertex tex coord by the tex coord matrices. */
2223
if (enableTexture) {
2324
vec3 texCoord3 = vec3(vertexTexCoord, 1.0);
24-
texCoord[0] = (texCoordMatrix[0] * texCoord3).st;
25-
texCoord[1] = (texCoordMatrix[1] * texCoord3).st;
25+
texCoord = (texCoordMatrix[0] * texCoord3).st;
26+
tileCoord = (texCoordMatrix[1] * texCoord3).st;
2627
}
2728
}

0 commit comments

Comments
 (0)