2020-01-12 11:42:47 +04:00
|
|
|
#version 120
|
|
|
|
|
2021-03-14 21:42:34 -07:00
|
|
|
#if @useUBO
|
|
|
|
#extension GL_ARB_uniform_buffer_object : require
|
|
|
|
#endif
|
|
|
|
|
2021-03-13 01:31:35 +00:00
|
|
|
#if @useGPUShader4
|
2021-03-13 23:02:48 +00:00
|
|
|
#extension GL_EXT_gpu_shader4: require
|
2021-03-13 01:31:35 +00:00
|
|
|
#endif
|
2020-01-12 11:42:47 +04:00
|
|
|
|
|
|
|
#define GROUNDCOVER
|
|
|
|
|
|
|
|
#if @diffuseMap
|
|
|
|
uniform sampler2D diffuseMap;
|
|
|
|
varying vec2 diffuseMapUV;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if @normalMap
|
|
|
|
uniform sampler2D normalMap;
|
|
|
|
varying vec2 normalMapUV;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Other shaders respect forcePPL, but legacy groundcover mods were designed to work with vertex lighting.
|
|
|
|
// They may do not look as intended with per-pixel lighting, so ignore this setting for now.
|
|
|
|
#define PER_PIXEL_LIGHTING @normalMap
|
|
|
|
|
|
|
|
varying float euclideanDepth;
|
|
|
|
varying float linearDepth;
|
2022-06-06 22:40:38 +02:00
|
|
|
uniform vec2 screenRes;
|
2023-02-25 11:03:39 -08:00
|
|
|
uniform float far;
|
|
|
|
uniform float alphaRef;
|
2020-01-12 11:42:47 +04:00
|
|
|
|
|
|
|
#if PER_PIXEL_LIGHTING
|
|
|
|
varying vec3 passViewPos;
|
|
|
|
#else
|
|
|
|
centroid varying vec3 passLighting;
|
|
|
|
centroid varying vec3 shadowDiffuseLighting;
|
|
|
|
#endif
|
|
|
|
|
2022-05-13 18:58:00 -07:00
|
|
|
varying vec3 passNormal;
|
|
|
|
|
2020-01-12 11:42:47 +04:00
|
|
|
#include "shadows_fragment.glsl"
|
2023-02-25 11:03:39 -08:00
|
|
|
#include "lib/light/lighting.glsl"
|
|
|
|
#include "lib/material/alpha.glsl"
|
2022-06-06 22:40:38 +02:00
|
|
|
#include "fog.glsl"
|
2023-12-10 21:45:15 +03:00
|
|
|
#include "compatibility/normals.glsl"
|
2020-01-12 11:42:47 +04:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
#if @diffuseMap
|
|
|
|
gl_FragData[0] = texture2D(diffuseMap, diffuseMapUV);
|
|
|
|
#else
|
|
|
|
gl_FragData[0] = vec4(1.0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (euclideanDepth > @groundcoverFadeStart)
|
|
|
|
gl_FragData[0].a *= 1.0-smoothstep(@groundcoverFadeStart, @groundcoverFadeEnd, euclideanDepth);
|
|
|
|
|
2023-02-26 14:31:41 -08:00
|
|
|
gl_FragData[0].a = alphaTest(gl_FragData[0].a, alphaRef);
|
2021-02-14 23:32:04 +00:00
|
|
|
|
2023-12-10 21:45:15 +03:00
|
|
|
#if @normalMap
|
2024-03-23 19:46:31 +03:00
|
|
|
vec4 normalTex = texture2D(normalMap, normalMapUV);
|
2024-04-18 11:23:21 +03:00
|
|
|
vec3 normal = normalTex.xyz * 2.0 - 1.0;
|
2024-03-23 19:46:31 +03:00
|
|
|
#if @reconstructNormalZ
|
2024-04-18 11:23:21 +03:00
|
|
|
normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
|
2024-03-23 19:46:31 +03:00
|
|
|
#endif
|
2024-04-18 11:23:21 +03:00
|
|
|
vec3 viewNormal = normalToView(normal);
|
2023-12-10 21:45:15 +03:00
|
|
|
#else
|
|
|
|
vec3 viewNormal = normalToView(normalize(passNormal));
|
|
|
|
#endif
|
|
|
|
|
2021-02-14 23:32:04 +00:00
|
|
|
float shadowing = unshadowedLightRatio(linearDepth);
|
|
|
|
|
2020-01-12 11:42:47 +04:00
|
|
|
vec3 lighting;
|
|
|
|
#if !PER_PIXEL_LIGHTING
|
|
|
|
lighting = passLighting + shadowDiffuseLighting * shadowing;
|
|
|
|
#else
|
2023-12-15 10:23:10 +03:00
|
|
|
vec3 diffuseLight, ambientLight, specularLight;
|
|
|
|
doLighting(passViewPos, viewNormal, gl_FrontMaterial.shininess, shadowing, diffuseLight, ambientLight, specularLight);
|
2020-01-12 11:42:47 +04:00
|
|
|
lighting = diffuseLight + ambientLight;
|
|
|
|
#endif
|
|
|
|
|
2022-04-28 20:02:13 -07:00
|
|
|
clampLightingResult(lighting);
|
|
|
|
|
2020-01-12 11:42:47 +04:00
|
|
|
gl_FragData[0].xyz *= lighting;
|
2023-02-25 11:03:39 -08:00
|
|
|
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth, far);
|
2020-01-12 11:42:47 +04:00
|
|
|
|
2022-05-13 18:58:00 -07:00
|
|
|
#if !@disableNormals
|
2023-01-19 08:39:38 -08:00
|
|
|
gl_FragData[1].xyz = viewNormal * 0.5 + 0.5;
|
2022-05-13 18:58:00 -07:00
|
|
|
#endif
|
|
|
|
|
2020-01-12 11:42:47 +04:00
|
|
|
applyShadowDebugOverlay();
|
|
|
|
}
|