2013-06-23 09:13:01 +00:00
2018-06-13 06:40:04 +00:00
layout(location = 0) in vec4 aPosition;
layout(location = 1) in vec2 aTexCoord;
layout(location = 2) in vec4 aColor;
2019-02-22 10:30:48 +00:00
layout(location = 0) out vec4 vTexCoord;
layout(location = 1) out vec4 vColor;
2014-07-10 08:33:07 +00:00
#ifndef SIMPLE // we do not need these for simple shaders
2018-06-13 06:40:04 +00:00
layout(location = 3) in vec4 aVertex2;
layout(location = 4) in vec4 aNormal;
2018-11-20 12:41:27 +00:00
layout(location = 5) in vec4 aNormal2;
2016-10-03 14:09:32 +00:00
2019-02-22 10:30:48 +00:00
layout(location = 2) out vec4 pixelpos;
layout(location = 3) out vec3 glowdist;
layout(location = 4) out vec3 gradientdist;
layout(location = 5) out vec4 vWorldNormal;
layout(location = 6) out vec4 vEyeNormal;
2014-07-10 08:33:07 +00:00
#endif
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
2018-10-20 09:59:12 +00:00
parmTexCoord = aTexCoord;
parmPosition = aPosition;
2016-08-22 12:00:25 +00:00
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
2019-03-02 00:56:08 +00:00
#ifdef HAS_UNIFORM_VERTEX_DATA
if (useVertexData == 0)
vColor = uVertexColor;
else
vColor = aColor;
#else
vColor = aColor;
#endif
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;
2018-11-11 15:04:05 +00:00
if (uGlowTopColor.a > 0 || uGlowBottomColor.a > 0)
{
float topatpoint = (uGlowTopPlane.w + uGlowTopPlane.x * worldcoord.x + uGlowTopPlane.y * worldcoord.z) * uGlowTopPlane.z;
float bottomatpoint = (uGlowBottomPlane.w + uGlowBottomPlane.x * worldcoord.x + uGlowBottomPlane.y * worldcoord.z) * uGlowBottomPlane.z;
glowdist.x = topatpoint - worldcoord.y;
glowdist.y = worldcoord.y - bottomatpoint;
glowdist.z = clamp(glowdist.x / (topatpoint - bottomatpoint), 0.0, 1.0);
}
if (uObjectColor2.a != 0)
{
float topatpoint = (uGradientTopPlane.w + uGradientTopPlane.x * worldcoord.x + uGradientTopPlane.y * worldcoord.z) * uGradientTopPlane.z;
float bottomatpoint = (uGradientBottomPlane.w + uGradientBottomPlane.x * worldcoord.x + uGradientBottomPlane.y * worldcoord.z) * uGradientBottomPlane.z;
gradientdist.x = topatpoint - worldcoord.y;
gradientdist.y = worldcoord.y - bottomatpoint;
gradientdist.z = clamp(gradientdist.x / (topatpoint - bottomatpoint), 0.0, 1.0);
}
2017-01-28 17:19:58 +00:00
2016-04-26 09:31:27 +00:00
if (uSplitBottomPlane.z != 0.0)
2016-01-30 22:01:11 +00:00
{
2018-11-11 15:04:05 +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);
2016-01-30 22:01:11 +00:00
}
2016-10-03 14:09:32 +00:00
2019-03-02 00:56:08 +00:00
#ifdef HAS_UNIFORM_VERTEX_DATA
if (useVertexData == 0)
vWorldNormal = NormalModelMatrix * vec4(uVertexNormal.xyz, 1.0);
else
vWorldNormal = NormalModelMatrix * vec4(normalize(mix(aNormal.xyz, aNormal2.xyz, uInterpolationFactor)), 1.0);
#else
vWorldNormal = NormalModelMatrix * vec4(normalize(mix(aNormal.xyz, aNormal2.xyz, uInterpolationFactor)), 1.0);
#endif
2016-10-03 14:09:32 +00:00
vEyeNormal = NormalViewMatrix * vWorldNormal;
2014-07-10 08:33:07 +00:00
#endif
2013-06-23 09:13:01 +00:00
#ifdef SPHEREMAP
vec3 u = normalize(eyeCoordPos.xyz);
2018-06-21 18:54:34 +00:00
vec4 n = normalize(NormalViewMatrix * vec4(parmTexCoord.x, 0.0, parmTexCoord.y, 0.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;
2019-02-26 19:19:54 +00:00
#ifdef VULKAN_COORDINATE_SYSTEM
gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;
gl_Position.y = -gl_Position.y;
#endif
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.
}
2018-08-11 16:25:15 +00:00
else
{
gl_ClipDistance[0] = 1;
}
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;
2019-03-02 13:16:11 +00:00
if (uSplitTopPlane == vec4(0.0))
{
gl_ClipDistance[3] = 1;
gl_ClipDistance[4] = 1;
}
2019-03-03 22:30:36 +00:00
gl_PointSize = 1.0;
2013-06-23 09:13:01 +00:00
}