2016-02-19 00:30:15 +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
|
|
|
|
2016-02-19 00:30:15 +00:00
|
|
|
varying vec2 uv;
|
|
|
|
|
|
|
|
uniform sampler2D diffuseMap;
|
|
|
|
|
|
|
|
#if @normalMap
|
|
|
|
uniform sampler2D normalMap;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if @blendMap
|
|
|
|
uniform sampler2D blendMap;
|
|
|
|
#endif
|
|
|
|
|
2020-03-14 12:39:32 +00:00
|
|
|
varying float euclideanDepth;
|
|
|
|
varying float linearDepth;
|
2016-02-19 00:30:15 +00:00
|
|
|
|
2023-12-15 07:23:10 +00:00
|
|
|
#define PER_PIXEL_LIGHTING (@normalMap || @specularMap || @forcePPL)
|
2016-02-19 00:30:15 +00:00
|
|
|
|
|
|
|
#if !PER_PIXEL_LIGHTING
|
2020-12-19 17:17:42 +00:00
|
|
|
centroid varying vec3 passLighting;
|
2023-12-15 07:23:10 +00:00
|
|
|
centroid varying vec3 passSpecular;
|
2018-05-11 18:15:04 +00:00
|
|
|
centroid varying vec3 shadowDiffuseLighting;
|
2023-12-15 07:23:10 +00:00
|
|
|
centroid varying vec3 shadowSpecularLighting;
|
2016-02-19 00:30:15 +00:00
|
|
|
#endif
|
2016-02-20 18:54:47 +00:00
|
|
|
varying vec3 passViewPos;
|
2016-03-22 20:00:31 +00:00
|
|
|
varying vec3 passNormal;
|
|
|
|
|
2022-06-06 20:40:38 +00:00
|
|
|
uniform vec2 screenRes;
|
2023-02-25 19:03:39 +00:00
|
|
|
uniform float far;
|
2022-06-06 20:40:38 +00:00
|
|
|
|
2020-12-19 17:17:42 +00:00
|
|
|
#include "vertexcolors.glsl"
|
2018-06-24 22:40:52 +00:00
|
|
|
#include "shadows_fragment.glsl"
|
2023-02-25 19:03:39 +00:00
|
|
|
#include "lib/light/lighting.glsl"
|
|
|
|
#include "lib/material/parallax.glsl"
|
2022-06-06 20:40:38 +00:00
|
|
|
#include "fog.glsl"
|
2023-12-10 18:45:15 +00:00
|
|
|
#include "compatibility/normals.glsl"
|
2016-02-19 00:30:15 +00:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2016-03-22 20:00:31 +00:00
|
|
|
vec2 adjustedUV = (gl_TextureMatrix[0] * vec4(uv, 0.0, 1.0)).xy;
|
2016-02-19 00:30:15 +00:00
|
|
|
|
2016-03-22 20:00:31 +00:00
|
|
|
#if @parallax
|
2023-12-10 18:45:15 +00:00
|
|
|
adjustedUV += getParallaxOffset(transpose(normalToViewMatrix) * normalize(-passViewPos), texture2D(normalMap, adjustedUV).a, 1.f);
|
2016-02-19 00:30:15 +00:00
|
|
|
#endif
|
2016-03-22 20:00:31 +00:00
|
|
|
vec4 diffuseTex = texture2D(diffuseMap, adjustedUV);
|
|
|
|
gl_FragData[0] = vec4(diffuseTex.xyz, 1.0);
|
|
|
|
|
2023-12-10 18:45:15 +00:00
|
|
|
vec4 diffuseColor = getDiffuseColor();
|
|
|
|
gl_FragData[0].a *= diffuseColor.a;
|
|
|
|
|
2016-03-22 20:00:31 +00:00
|
|
|
#if @blendMap
|
|
|
|
vec2 blendMapUV = (gl_TextureMatrix[1] * vec4(uv, 0.0, 1.0)).xy;
|
|
|
|
gl_FragData[0].a *= texture2D(blendMap, blendMapUV).a;
|
|
|
|
#endif
|
2016-02-19 00:30:15 +00:00
|
|
|
|
2023-12-10 18:45:15 +00:00
|
|
|
#if @normalMap
|
2024-03-23 16:46:31 +00:00
|
|
|
vec4 normalTex = texture2D(normalMap, adjustedUV);
|
2024-04-18 08:23:21 +00:00
|
|
|
vec3 normal = normalTex.xyz * 2.0 - 1.0;
|
2024-03-23 16:46:31 +00:00
|
|
|
#if @reconstructNormalZ
|
2024-04-18 08:23:21 +00:00
|
|
|
normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
|
2024-03-23 16:46:31 +00:00
|
|
|
#endif
|
2024-04-18 08:23:21 +00:00
|
|
|
vec3 viewNormal = normalToView(normal);
|
2023-12-10 18:45:15 +00:00
|
|
|
#else
|
2023-12-29 23:43:38 +00:00
|
|
|
vec3 viewNormal = normalize(gl_NormalMatrix * passNormal);
|
2023-12-10 18:45:15 +00:00
|
|
|
#endif
|
2017-09-20 23:25:48 +00:00
|
|
|
|
2020-12-19 17:17:42 +00:00
|
|
|
float shadowing = unshadowedLightRatio(linearDepth);
|
2023-12-15 07:23:10 +00:00
|
|
|
vec3 lighting, specular;
|
2016-02-19 00:30:15 +00:00
|
|
|
#if !PER_PIXEL_LIGHTING
|
2020-12-19 17:17:42 +00:00
|
|
|
lighting = passLighting + shadowDiffuseLighting * shadowing;
|
2023-12-15 07:23:10 +00:00
|
|
|
specular = passSpecular + shadowSpecularLighting * shadowing;
|
2019-05-01 08:33:19 +00:00
|
|
|
#else
|
2016-02-20 18:54:47 +00:00
|
|
|
#if @specularMap
|
2020-05-08 13:55:22 +00:00
|
|
|
float shininess = 128.0; // TODO: make configurable
|
2023-12-15 07:23:10 +00:00
|
|
|
vec3 specularColor = vec3(diffuseTex.a);
|
2016-02-20 18:54:47 +00:00
|
|
|
#else
|
|
|
|
float shininess = gl_FrontMaterial.shininess;
|
2023-12-15 07:23:10 +00:00
|
|
|
vec3 specularColor = getSpecularColor().xyz;
|
|
|
|
#endif
|
|
|
|
vec3 diffuseLight, ambientLight, specularLight;
|
|
|
|
doLighting(passViewPos, viewNormal, shininess, shadowing, diffuseLight, ambientLight, specularLight);
|
|
|
|
lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + getEmissionColor().xyz;
|
|
|
|
specular = specularColor * specularLight;
|
2016-02-20 18:54:47 +00:00
|
|
|
#endif
|
|
|
|
|
2023-12-15 07:23:10 +00:00
|
|
|
clampLightingResult(lighting);
|
|
|
|
gl_FragData[0].xyz = gl_FragData[0].xyz * lighting + specular;
|
2016-02-20 18:54:47 +00:00
|
|
|
|
2023-02-25 19:03:39 +00:00
|
|
|
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth, far);
|
2018-06-28 16:24:36 +00:00
|
|
|
|
2022-05-14 01:58:00 +00:00
|
|
|
#if !@disableNormals && @writeNormals
|
2023-01-19 16:39:38 +00:00
|
|
|
gl_FragData[1].xyz = viewNormal * 0.5 + 0.5;
|
2022-05-14 01:58:00 +00:00
|
|
|
#endif
|
|
|
|
|
2018-06-28 16:24:36 +00:00
|
|
|
applyShadowDebugOverlay();
|
2016-02-19 00:30:15 +00:00
|
|
|
}
|