2013-06-23 09:13:01 +00:00
2014-07-14 23:02:48 +00:00
in vec4 aPosition;
2014-07-14 22:59:01 +00:00
in vec2 aTexCoord;
2014-07-14 22:37:13 +00:00
in vec4 aColor;
2014-07-10 08:33:07 +00:00
#ifndef SIMPLE // we do not need these for simple shaders
2014-06-29 09:00:21 +00:00
in vec4 aVertex2;
2014-05-12 12:45:41 +00:00
out vec4 pixelpos;
out vec2 glowdist;
2014-07-10 08:33:07 +00:00
#endif
2013-06-23 09:13:01 +00:00
2014-07-14 22:19:41 +00:00
out vec4 vTexCoord;
out vec4 vColor;
2013-06-23 09:13:01 +00:00
void main()
{
2016-08-22 12:00:25 +00:00
vec2 parmTexCoord;
vec4 parmPosition;
2016-08-22 13:31:23 +00:00
2016-08-22 12:00:25 +00:00
#ifndef USE_QUAD_DRAWER
parmTexCoord = aTexCoord;
parmPosition = aPosition;
#else
if (uQuadMode == 0)
{
parmTexCoord = aTexCoord;
parmPosition = aPosition;
}
else
{
2016-08-22 13:31:23 +00:00
parmPosition = uQuadVertices[int(aPosition.x)];
parmTexCoord = uQuadTexCoords[int(aPosition.x)].st;
2016-08-22 12:00:25 +00:00
}
#endif
2014-07-10 08:33:07 +00:00
#ifndef SIMPLE
2016-08-22 12:00:25 +00:00
vec4 worldcoord = ModelMatrix * mix(parmPosition, aVertex2, uInterpolationFactor);
2014-07-10 08:33:07 +00:00
#else
2016-08-22 12:00:25 +00:00
vec4 worldcoord = ModelMatrix * parmPosition;
2014-07-10 08:33:07 +00:00
#endif
2014-05-12 12:45:41 +00:00
vec4 eyeCoordPos = ViewMatrix * worldcoord;
2013-06-23 09:13:01 +00:00
2014-07-14 22:37:13 +00:00
vColor = aColor;
2014-05-12 12:45:41 +00:00
2014-07-10 08:33:07 +00:00
#ifndef SIMPLE
pixelpos.xyz = worldcoord.xyz;
pixelpos.w = -eyeCoordPos.z/eyeCoordPos.w;
glowdist.x = -((uGlowTopPlane.w + uGlowTopPlane.x * worldcoord.x + uGlowTopPlane.y * worldcoord.z) * uGlowTopPlane.z) - worldcoord.y;
glowdist.y = worldcoord.y + ((uGlowBottomPlane.w + uGlowBottomPlane.x * worldcoord.x + uGlowBottomPlane.y * worldcoord.z) * uGlowBottomPlane.z);
2016-01-30 22:01:11 +00:00
2016-04-26 09:31:27 +00:00
if (uSplitBottomPlane.z != 0.0)
2016-01-30 22:01:11 +00:00
{
gl_ClipDistance[3] = -((uSplitTopPlane.w + uSplitTopPlane.x * worldcoord.x + uSplitTopPlane.y * worldcoord.z) * uSplitTopPlane.z) - worldcoord.y;
gl_ClipDistance[4] = worldcoord.y + ((uSplitBottomPlane.w + uSplitBottomPlane.x * worldcoord.x + uSplitBottomPlane.y * worldcoord.z) * uSplitBottomPlane.z);
}
2014-07-10 08:33:07 +00:00
#endif
2013-06-23 09:13:01 +00:00
#ifdef SPHEREMAP
vec3 u = normalize(eyeCoordPos.xyz);
2016-08-22 12:00:25 +00:00
vec4 n = normalize(TextureMatrix * vec4(parmTexCoord.x, 0.0, parmTexCoord.y, 0.0)); // use texture matrix and coordinates for our normal. Since this is only used on walls, the normal's y coordinate is always 0.
2014-07-14 19:14:43 +00:00
vec3 r = reflect(u, n.xyz);
2013-06-23 09:13:01 +00:00
float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );
vec2 sst = vec2(r.x/m + 0.5, r.y/m + 0.5);
2014-07-14 22:19:41 +00:00
vTexCoord.xy = sst;
2014-05-12 12:45:41 +00:00
#else
2016-08-22 12:00:25 +00:00
vTexCoord = TextureMatrix * vec4(parmTexCoord, 0.0, 1.0);
2013-06-23 09:13:01 +00:00
#endif
2014-05-12 12:45:41 +00:00
gl_Position = ProjectionMatrix * eyeCoordPos;
2016-08-22 13:31:23 +00:00
2016-04-29 10:26:57 +00:00
if (uClipHeightDirection != 0.0) // clip planes used for reflective flats
2016-01-27 11:30:55 +00:00
{
2016-04-27 00:10:42 +00:00
gl_ClipDistance[0] = (worldcoord.y - uClipHeight) * uClipHeightDirection;
2016-01-27 11:30:55 +00:00
}
2016-04-29 10:26:57 +00:00
else if (uClipLine.x > -1000000.0) // and for line portals - this will never be active at the same time as the reflective planes clipping so it can use the same hardware clip plane.
{
gl_ClipDistance[0] = -( (worldcoord.z - uClipLine.y) * uClipLine.z + (uClipLine.x - worldcoord.x) * uClipLine.w ) + 1.0/32768.0; // allow a tiny bit of imprecisions for colinear linedefs.
}
2016-04-27 00:10:42 +00:00
// clip planes used for translucency splitting
2016-01-27 11:32:39 +00:00
gl_ClipDistance[1] = worldcoord.y - uClipSplit.x;
gl_ClipDistance[2] = uClipSplit.y - worldcoord.y;
2016-01-30 22:01:11 +00:00
2013-06-23 09:13:01 +00:00
}