2016-02-16 17:18:48 +00:00
|
|
|
#version 120
|
|
|
|
|
2021-03-15 04:42:34 +00:00
|
|
|
#if @useUBO
|
|
|
|
#extension GL_ARB_uniform_buffer_object : require
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if @useGPUShader4
|
|
|
|
#extension GL_EXT_gpu_shader4: require
|
|
|
|
#endif
|
2021-02-21 18:38:15 +00:00
|
|
|
|
2021-07-09 17:05:27 +00:00
|
|
|
uniform mat4 projectionMatrix;
|
|
|
|
|
2016-02-16 17:18:48 +00:00
|
|
|
#if @diffuseMap
|
|
|
|
varying vec2 diffuseMapUV;
|
|
|
|
#endif
|
2016-02-16 21:32:59 +00:00
|
|
|
|
2016-02-17 01:52:44 +00:00
|
|
|
#if @darkMap
|
|
|
|
varying vec2 darkMapUV;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if @detailMap
|
|
|
|
varying vec2 detailMapUV;
|
|
|
|
#endif
|
|
|
|
|
2016-03-01 17:41:36 +00:00
|
|
|
#if @decalMap
|
|
|
|
varying vec2 decalMapUV;
|
|
|
|
#endif
|
|
|
|
|
2016-02-17 01:52:44 +00:00
|
|
|
#if @emissiveMap
|
|
|
|
varying vec2 emissiveMapUV;
|
|
|
|
#endif
|
|
|
|
|
2016-02-17 23:00:12 +00:00
|
|
|
#if @normalMap
|
|
|
|
varying vec2 normalMapUV;
|
2016-06-16 16:07:10 +00:00
|
|
|
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
|
|
|
|
|
2020-03-02 01:03:36 +00:00
|
|
|
#if @bumpMap
|
|
|
|
varying vec2 bumpMapUV;
|
|
|
|
#endif
|
|
|
|
|
2016-02-20 18:02:11 +00:00
|
|
|
#if @specularMap
|
|
|
|
varying vec2 specularMapUV;
|
|
|
|
#endif
|
|
|
|
|
2020-03-14 12:39:32 +00:00
|
|
|
varying float euclideanDepth;
|
|
|
|
varying float linearDepth;
|
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
|
2020-12-19 17:17:42 +00:00
|
|
|
centroid varying vec3 passLighting;
|
2018-05-11 18:15:04 +00:00
|
|
|
centroid varying vec3 shadowDiffuseLighting;
|
2020-12-16 21:46:09 +00:00
|
|
|
uniform float emissiveMult;
|
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
|
|
|
|
2020-12-19 17:17:42 +00:00
|
|
|
#include "vertexcolors.glsl"
|
2018-06-24 22:40:52 +00:00
|
|
|
#include "shadows_vertex.glsl"
|
2021-03-28 18:06:00 +00:00
|
|
|
|
2016-02-17 22:29:26 +00:00
|
|
|
#include "lighting.glsl"
|
2021-06-01 19:15:25 +00:00
|
|
|
#include "depth.glsl"
|
2016-02-16 22:30:23 +00:00
|
|
|
|
2016-02-16 17:18:48 +00:00
|
|
|
void main(void)
|
|
|
|
{
|
2021-07-09 17:05:27 +00:00
|
|
|
gl_Position = projectionMatrix * (gl_ModelViewMatrix * gl_Vertex);
|
2016-02-16 17:18:48 +00:00
|
|
|
|
2016-02-17 01:04:30 +00:00
|
|
|
vec4 viewPos = (gl_ModelViewMatrix * gl_Vertex);
|
2021-07-09 17:05:27 +00:00
|
|
|
|
2016-02-17 01:04:30 +00:00
|
|
|
gl_ClipVertex = viewPos;
|
2020-03-14 12:39:32 +00:00
|
|
|
euclideanDepth = length(viewPos.xyz);
|
2021-07-09 17:05:27 +00:00
|
|
|
linearDepth = getLinearDepth(gl_Position.z, viewPos.z);
|
2020-03-14 12:39:32 +00:00
|
|
|
|
2020-06-15 08:43:51 +00:00
|
|
|
#if (@envMap || !PER_PIXEL_LIGHTING || @shadows_enabled)
|
2016-02-17 01:04:30 +00:00
|
|
|
vec3 viewNormal = normalize((gl_NormalMatrix * gl_Normal).xyz);
|
2020-06-15 08:43:51 +00:00
|
|
|
#endif
|
2016-02-17 01:04:30 +00:00
|
|
|
|
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
|
|
|
|
|
2016-02-16 17:18:48 +00:00
|
|
|
#if @diffuseMap
|
2016-02-17 01:46:47 +00:00
|
|
|
diffuseMapUV = (gl_TextureMatrix[@diffuseMapUV] * gl_MultiTexCoord@diffuseMapUV).xy;
|
2016-02-16 17:18:48 +00:00
|
|
|
#endif
|
2016-02-16 22:30:23 +00:00
|
|
|
|
2016-02-17 01:52:44 +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;
|
2016-02-17 01:52:44 +00:00
|
|
|
#endif
|
|
|
|
|
2016-03-01 17:41:36 +00:00
|
|
|
#if @decalMap
|
|
|
|
decalMapUV = (gl_TextureMatrix[@decalMapUV] * gl_MultiTexCoord@decalMapUV).xy;
|
|
|
|
#endif
|
|
|
|
|
2016-02-17 01:52:44 +00:00
|
|
|
#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;
|
2016-06-16 16:07:10 +00:00
|
|
|
passTangent = gl_MultiTexCoord7.xyzw;
|
2016-02-17 23:00:12 +00:00
|
|
|
#endif
|
|
|
|
|
2020-03-02 01:03:36 +00:00
|
|
|
#if @bumpMap
|
|
|
|
bumpMapUV = (gl_TextureMatrix[@bumpMapUV] * gl_MultiTexCoord@bumpMapUV).xy;
|
|
|
|
#endif
|
|
|
|
|
2016-02-20 18:02:11 +00:00
|
|
|
#if @specularMap
|
|
|
|
specularMapUV = (gl_TextureMatrix[@specularMapUV] * gl_MultiTexCoord@specularMapUV).xy;
|
|
|
|
#endif
|
|
|
|
|
2020-05-12 15:21:02 +00:00
|
|
|
passColor = gl_Color;
|
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
|
|
|
|
2020-12-19 17:17:42 +00:00
|
|
|
#if !PER_PIXEL_LIGHTING
|
|
|
|
vec3 diffuseLight, ambientLight;
|
|
|
|
doLighting(viewPos.xyz, viewNormal, diffuseLight, ambientLight, shadowDiffuseLighting);
|
2020-12-16 21:46:09 +00:00
|
|
|
vec3 emission = getEmissionColor().xyz * emissiveMult;
|
|
|
|
passLighting = getDiffuseColor().xyz * diffuseLight + getAmbientColor().xyz * ambientLight + emission;
|
2021-04-22 23:49:06 +00:00
|
|
|
clampLightingResult(passLighting);
|
2020-12-19 17:17:42 +00:00
|
|
|
shadowDiffuseLighting *= getDiffuseColor().xyz;
|
|
|
|
#endif
|
|
|
|
|
2020-06-15 08:43:51 +00:00
|
|
|
#if (@shadows_enabled)
|
2019-01-30 22:28:00 +00:00
|
|
|
setupShadowCoords(viewPos, viewNormal);
|
2020-06-15 08:43:51 +00:00
|
|
|
#endif
|
2016-02-16 17:18:48 +00:00
|
|
|
}
|