| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- #include "Uniforms.vert"
- #include "Transform.vert"
- #include "ScreenPos.vert"
- #include "Lighting.vert"
- varying vec2 vTexCoord;
- #ifdef HEIGHTFOG
- varying vec3 vWorldPos;
- #endif
- #ifdef PERPIXEL
- varying vec4 vLightVec;
- #ifdef SPECULAR
- varying vec3 vEyeVec;
- #endif
- #ifndef NORMALMAP
- varying vec3 vNormal;
- #endif
- #ifdef SHADOW
- varying vec4 vShadowPos[NUMCASCADES];
- #endif
- #ifdef SPOTLIGHT
- varying vec4 vSpotPos;
- #endif
- #ifdef POINTLIGHT
- varying vec3 vCubeMaskVec;
- #endif
- #else
- varying vec4 vVertexLight;
- varying vec3 vNormal;
- #ifdef NORMALMAP
- varying vec3 vTangent;
- varying vec3 vBitangent;
- #endif
- varying vec4 vScreenPos;
- #ifdef ENVCUBEMAP
- varying vec3 vReflectionVec;
- #endif
- #if defined(LIGHTMAP) || defined(AO)
- varying vec2 vTexCoord2;
- #endif
- #endif
- void main()
- {
- mat4 modelMatrix = iModelMatrix;
- vec3 worldPos = GetWorldPos(modelMatrix);
- gl_Position = GetClipPos(worldPos);
- vTexCoord = GetTexCoord(iTexCoord);
-
- #ifdef HEIGHTFOG
- vWorldPos = worldPos;
- #endif
- #if defined(PERPIXEL) && defined(NORMALMAP)
- vec3 vNormal;
- vec3 vTangent;
- vec3 vBitangent;
- #endif
- vNormal = GetWorldNormal(modelMatrix);
- #ifdef NORMALMAP
- vTangent = GetWorldTangent(modelMatrix);
- vBitangent = cross(vTangent, vNormal) * iTangent.w;
- #endif
-
- #ifdef PERPIXEL
- // Per-pixel forward lighting
- vec4 projWorldPos = vec4(worldPos, 1.0);
- #ifdef SHADOW
- // Shadow projection: transform from world space to shadow space
- for (int i = 0; i < NUMCASCADES; i++)
- vShadowPos[i] = GetShadowPos(i, projWorldPos);
- #endif
- #ifdef SPOTLIGHT
- // Spotlight projection: transform from world space to projector texture coordinates
- vSpotPos = cLightMatrices[0] * projWorldPos;
- #endif
-
- #ifdef POINTLIGHT
- vCubeMaskVec = mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz) * (cLightPos.xyz - worldPos);
- #endif
-
- #ifdef NORMALMAP
- mat3 tbn = mat3(vTangent, vBitangent, vNormal);
- #ifdef DIRLIGHT
- vLightVec = vec4(cLightDir * tbn, GetDepth(gl_Position));
- #else
- vLightVec = vec4((cLightPos.xyz - worldPos) * tbn * cLightPos.w, GetDepth(gl_Position));
- #endif
- #ifdef SPECULAR
- vEyeVec = (cCameraPos - worldPos) * tbn;
- #endif
- #else
- #ifdef DIRLIGHT
- vLightVec = vec4(cLightDir, GetDepth(gl_Position));
- #else
- vLightVec = vec4((cLightPos.xyz - worldPos) * cLightPos.w, GetDepth(gl_Position));
- #endif
- #ifdef SPECULAR
- vEyeVec = cCameraPos - worldPos;
- #endif
- #endif
- #else
- // Ambient & per-vertex lighting
- #if defined(LIGHTMAP) || defined(AO)
- // If using lightmap, disregard zone ambient light
- // If using AO, calculate ambient in the PS
- vVertexLight = vec4(0.0, 0.0, 0.0, GetDepth(gl_Position));
- vTexCoord2 = iTexCoord2;
- #else
- vVertexLight = vec4(GetAmbient(GetZonePos(worldPos)), GetDepth(gl_Position));
- #endif
-
- #ifdef NUMVERTEXLIGHTS
- for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
- vVertexLight.rgb += GetVertexLight(i, worldPos, vNormal) * cVertexLights[i * 3].rgb;
- #endif
-
- vScreenPos = GetScreenPos(gl_Position);
- #ifdef ENVCUBEMAP
- vReflectionVec = worldPos - cCameraPos;
- #endif
- #endif
- }
|