2022-04-24 15:29:16 +00:00
|
|
|
#version 120
|
2022-04-04 22:51:23 +02:00
|
|
|
|
2021-03-14 21:42:34 -07:00
|
|
|
#if @useUBO
|
|
|
|
#extension GL_ARB_uniform_buffer_object : require
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if @useGPUShader4
|
|
|
|
#extension GL_EXT_gpu_shader4: require
|
|
|
|
#endif
|
2021-02-21 10:38:15 -08:00
|
|
|
|
2023-02-25 11:03:39 -08:00
|
|
|
#include "lib/core/vertex.h.glsl"
|
2016-02-19 01:30:15 +01:00
|
|
|
varying vec2 uv;
|
2020-03-14 16:39:32 +04:00
|
|
|
varying float euclideanDepth;
|
|
|
|
varying float linearDepth;
|
2016-02-19 01:30:15 +01:00
|
|
|
|
2023-12-15 10:23:10 +03:00
|
|
|
#define PER_PIXEL_LIGHTING (@normalMap || @specularMap || @forcePPL)
|
2016-02-19 01:30:15 +01:00
|
|
|
|
|
|
|
#if !PER_PIXEL_LIGHTING
|
2020-12-19 20:17:42 +03:00
|
|
|
centroid varying vec3 passLighting;
|
2023-12-15 10:23:10 +03:00
|
|
|
centroid varying vec3 passSpecular;
|
2018-05-11 19:15:04 +01:00
|
|
|
centroid varying vec3 shadowDiffuseLighting;
|
2023-12-15 10:23:10 +03:00
|
|
|
centroid varying vec3 shadowSpecularLighting;
|
2016-02-19 01:30:15 +01:00
|
|
|
#endif
|
2016-02-20 19:54:47 +01:00
|
|
|
varying vec3 passViewPos;
|
2016-03-22 21:00:31 +01:00
|
|
|
varying vec3 passNormal;
|
2016-02-19 01:30:15 +01:00
|
|
|
|
2020-12-19 20:17:42 +03:00
|
|
|
#include "vertexcolors.glsl"
|
2018-06-24 23:40:52 +01:00
|
|
|
#include "shadows_vertex.glsl"
|
2023-12-10 21:45:15 +03:00
|
|
|
#include "compatibility/normals.glsl"
|
2021-03-28 11:06:00 -07:00
|
|
|
|
2023-02-25 11:03:39 -08:00
|
|
|
#include "lib/light/lighting.glsl"
|
|
|
|
#include "lib/view/depth.glsl"
|
2016-02-19 01:30:15 +01:00
|
|
|
|
|
|
|
void main(void)
|
|
|
|
{
|
2023-02-25 11:03:39 -08:00
|
|
|
gl_Position = modelToClip(gl_Vertex);
|
2016-02-19 01:30:15 +01:00
|
|
|
|
2023-02-25 11:03:39 -08:00
|
|
|
vec4 viewPos = modelToView(gl_Vertex);
|
2016-02-19 01:30:15 +01:00
|
|
|
gl_ClipVertex = viewPos;
|
2020-03-14 16:39:32 +04:00
|
|
|
euclideanDepth = length(viewPos.xyz);
|
2021-07-09 10:05:27 -07:00
|
|
|
linearDepth = getLinearDepth(gl_Position.z, viewPos.z);
|
2020-06-15 12:43:51 +04:00
|
|
|
|
2020-05-12 18:21:02 +03:00
|
|
|
passColor = gl_Color;
|
2016-03-22 21:00:31 +01:00
|
|
|
passNormal = gl_Normal.xyz;
|
2016-02-20 19:54:47 +01:00
|
|
|
passViewPos = viewPos.xyz;
|
2023-12-10 21:45:15 +03:00
|
|
|
normalToViewMatrix = gl_NormalMatrix;
|
|
|
|
|
|
|
|
#if @normalMap
|
|
|
|
mat3 tbnMatrix = generateTangentSpace(vec4(1.0, 0.0, 0.0, 1.0), passNormal);
|
|
|
|
tbnMatrix[0] = normalize(cross(tbnMatrix[2], tbnMatrix[1])); // note, now we need to re-cross to derive tangent again because it wasn't orthonormal
|
|
|
|
normalToViewMatrix *= tbnMatrix;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !PER_PIXEL_LIGHTING || @shadows_enabled
|
2023-12-30 02:43:38 +03:00
|
|
|
vec3 viewNormal = normalize(gl_NormalMatrix * passNormal);
|
2023-12-10 21:45:15 +03:00
|
|
|
#endif
|
2016-02-19 01:30:15 +01:00
|
|
|
|
2020-12-19 20:17:42 +03:00
|
|
|
#if !PER_PIXEL_LIGHTING
|
2023-12-15 10:23:10 +03:00
|
|
|
vec3 diffuseLight, ambientLight, specularLight;
|
|
|
|
doLighting(viewPos.xyz, viewNormal, gl_FrontMaterial.shininess, diffuseLight, ambientLight, specularLight, shadowDiffuseLighting, shadowSpecularLighting);
|
2020-12-19 20:17:42 +03:00
|
|
|
passLighting = getDiffuseColor().xyz * diffuseLight + getAmbientColor().xyz * ambientLight + getEmissionColor().xyz;
|
2023-12-15 10:23:10 +03:00
|
|
|
passSpecular = getSpecularColor().xyz * specularLight;
|
2021-04-22 16:49:06 -07:00
|
|
|
clampLightingResult(passLighting);
|
2020-12-19 20:17:42 +03:00
|
|
|
shadowDiffuseLighting *= getDiffuseColor().xyz;
|
2023-12-15 10:23:10 +03:00
|
|
|
shadowSpecularLighting *= getSpecularColor().xyz;
|
2020-12-19 20:17:42 +03:00
|
|
|
#endif
|
|
|
|
|
2016-02-19 01:30:15 +01:00
|
|
|
uv = gl_MultiTexCoord0.xy;
|
2017-09-21 00:25:48 +01:00
|
|
|
|
2020-06-15 12:43:51 +04:00
|
|
|
#if (@shadows_enabled)
|
2019-01-30 22:28:00 +00:00
|
|
|
setupShadowCoords(viewPos, viewNormal);
|
2020-06-15 12:43:51 +04:00
|
|
|
#endif
|
2016-02-19 01:30:15 +01:00
|
|
|
}
|