1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-23 23:23:52 +00:00
openmw-tes3mp/files/shaders/objects_vertex.glsl

122 lines
3.1 KiB
Text
Raw Normal View History

#version 120
#define SHADOWS @shadows_enabled
#if @diffuseMap
varying vec2 diffuseMapUV;
#endif
2016-02-16 21:32:59 +00:00
#if @darkMap
varying vec2 darkMapUV;
#endif
#if @detailMap
varying vec2 detailMapUV;
#endif
#if @decalMap
varying vec2 decalMapUV;
#endif
#if @emissiveMap
varying vec2 emissiveMapUV;
#endif
2016-02-17 23:00:12 +00:00
#if @normalMap
varying vec2 normalMapUV;
varying vec4 passTangent;
2016-02-17 23:00:12 +00:00
#endif
2016-02-18 22:05:44 +00:00
#if @envMap
varying vec2 envMapUV;
#endif
2016-02-20 18:02:11 +00:00
#if @specularMap
varying vec2 specularMapUV;
#endif
2016-02-16 21:32:59 +00:00
varying float depth;
2016-02-16 22:30:23 +00:00
2016-02-18 16:08:18 +00:00
#define PER_PIXEL_LIGHTING (@normalMap || @forcePPL)
2016-02-17 22:39:06 +00:00
#if !PER_PIXEL_LIGHTING
varying vec4 lighting;
varying vec3 shadowDiffuseLighting;
2016-02-17 22:39:06 +00:00
#else
2016-02-18 22:05:44 +00:00
varying vec4 passColor;
2016-02-17 22:39:06 +00:00
#endif
2016-02-20 18:02:11 +00:00
varying vec3 passViewPos;
2016-03-22 20:12:16 +00:00
varying vec3 passNormal;
2016-02-16 22:30:23 +00:00
#if SHADOWS
@foreach shadow_texture_unit_index @shadow_texture_unit_list
uniform int shadowTextureUnit@shadow_texture_unit_index;
varying vec4 shadowSpaceCoords@shadow_texture_unit_index;
@endforeach
#endif // SHADOWS
2017-09-20 23:25:48 +00:00
2016-02-17 22:29:26 +00:00
#include "lighting.glsl"
2016-02-16 22:30:23 +00:00
void main(void)
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
2016-02-16 21:32:59 +00:00
depth = gl_Position.z;
vec4 viewPos = (gl_ModelViewMatrix * gl_Vertex);
gl_ClipVertex = viewPos;
vec3 viewNormal = normalize((gl_NormalMatrix * gl_Normal).xyz);
2016-02-18 22:05:44 +00:00
#if @envMap
vec3 viewVec = normalize(viewPos.xyz);
vec3 r = reflect( viewVec, viewNormal );
float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );
envMapUV = vec2(r.x/m + 0.5, r.y/m + 0.5);
#endif
#if @diffuseMap
2016-02-17 01:46:47 +00:00
diffuseMapUV = (gl_TextureMatrix[@diffuseMapUV] * gl_MultiTexCoord@diffuseMapUV).xy;
#endif
2016-02-16 22:30:23 +00:00
#if @darkMap
darkMapUV = (gl_TextureMatrix[@darkMapUV] * gl_MultiTexCoord@darkMapUV).xy;
#endif
#if @detailMap
2016-03-01 17:40:18 +00:00
detailMapUV = (gl_TextureMatrix[@detailMapUV] * gl_MultiTexCoord@detailMapUV).xy;
#endif
#if @decalMap
decalMapUV = (gl_TextureMatrix[@decalMapUV] * gl_MultiTexCoord@decalMapUV).xy;
#endif
#if @emissiveMap
emissiveMapUV = (gl_TextureMatrix[@emissiveMapUV] * gl_MultiTexCoord@emissiveMapUV).xy;
#endif
2016-02-17 23:00:12 +00:00
#if @normalMap
normalMapUV = (gl_TextureMatrix[@normalMapUV] * gl_MultiTexCoord@normalMapUV).xy;
passTangent = gl_MultiTexCoord7.xyzw;
2016-02-17 23:00:12 +00:00
#endif
2016-02-20 18:02:11 +00:00
#if @specularMap
specularMapUV = (gl_TextureMatrix[@specularMapUV] * gl_MultiTexCoord@specularMapUV).xy;
#endif
2016-02-17 22:39:06 +00:00
#if !PER_PIXEL_LIGHTING
lighting = doLighting(viewPos.xyz, viewNormal, gl_Color, shadowDiffuseLighting);
2016-02-17 22:39:06 +00:00
#else
2016-02-18 22:05:44 +00:00
passColor = gl_Color;
2016-02-17 22:39:06 +00:00
#endif
2016-02-20 18:02:11 +00:00
passViewPos = viewPos.xyz;
2016-03-22 20:12:16 +00:00
passNormal = gl_Normal.xyz;
2017-09-20 23:25:48 +00:00
#if SHADOWS
2017-09-20 23:25:48 +00:00
// This matrix has the opposite handedness to the others used here, so multiplication must have the vector to the left. Alternatively it could be transposed after construction, but that's extra work for the GPU just to make the code look a tiny bit cleaner.
mat4 eyePlaneMat;
@foreach shadow_texture_unit_index @shadow_texture_unit_list
eyePlaneMat = mat4(gl_EyePlaneS[shadowTextureUnit@shadow_texture_unit_index], gl_EyePlaneT[shadowTextureUnit@shadow_texture_unit_index], gl_EyePlaneR[shadowTextureUnit@shadow_texture_unit_index], gl_EyePlaneQ[shadowTextureUnit@shadow_texture_unit_index]);
shadowSpaceCoords@shadow_texture_unit_index = viewPos * eyePlaneMat;
@endforeach
#endif // SHADOWS
}