Skip to content

Commit

Permalink
Modified the GLSL surface texture program to use multiple varyings in…
Browse files Browse the repository at this point in the history
…stead of an array of varyings
  • Loading branch information
pdavidc committed May 31, 2016
1 parent fad289e commit d164f1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@ uniform bool enableTexture;
uniform vec4 color;
uniform sampler2D texSampler;

varying vec2 texCoord[2];
varying vec2 texCoord;
varying vec2 tileCoord;

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

if (enablePickMode && enableTexture) {
/* Using the first texture coordinate, modulate the RGBA color with the 2D texture's Alpha component (rounded to
0.0 or 1.0). Finally, modulate the result by the tile mask to suppress fragments outside the surface tile. */
float texMask = floor(texture2D(texSampler, texCoord[0]).a + 0.5);
float texMask = floor(texture2D(texSampler, texCoord).a + 0.5);
gl_FragColor = color * texMask * tileMask;
} else if (!enablePickMode && enableTexture) {
/* Using the first texture coordinate, modulate the RGBA color with the 2D texture's RGBA color. Finally,
modulate by the tile mask to suppress fragments outside the surface tile. */
gl_FragColor = color * texture2D(texSampler, texCoord[0]) * tileMask;
gl_FragColor = color * texture2D(texSampler, texCoord) * tileMask;
} else {
/* Modulate the RGBA color by the tile mask to suppress fragments outside the surface tile. */
gl_FragColor = color * tileMask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ uniform mat3 texCoordMatrix[2];
attribute vec4 vertexPoint;
attribute vec2 vertexTexCoord;

varying vec2 texCoord[2];
varying vec2 texCoord;
varying vec2 tileCoord;

void main() {
/* Transform the vertex position by the modelview-projection matrix. */
Expand All @@ -21,7 +22,7 @@ void main() {
/* Transform the vertex tex coord by the tex coord matrices. */
if (enableTexture) {
vec3 texCoord3 = vec3(vertexTexCoord, 1.0);
texCoord[0] = (texCoordMatrix[0] * texCoord3).st;
texCoord[1] = (texCoordMatrix[1] * texCoord3).st;
texCoord = (texCoordMatrix[0] * texCoord3).st;
tileCoord = (texCoordMatrix[1] * texCoord3).st;
}
}

0 comments on commit d164f1b

Please sign in to comment.