1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-01 03:21:41 +00:00
OpenMW/files/shaders/compatibility/groundcover.frag

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

97 lines
2.4 KiB
GLSL
Raw Normal View History

2020-01-12 07:42:47 +00:00
#version 120
#if @useUBO
#extension GL_ARB_uniform_buffer_object : require
#endif
#if @useGPUShader4
#extension GL_EXT_gpu_shader4: require
#endif
2020-01-12 07:42:47 +00:00
#define GROUNDCOVER
#if @diffuseMap
uniform sampler2D diffuseMap;
varying vec2 diffuseMapUV;
#endif
#if @normalMap
uniform sampler2D normalMap;
varying vec2 normalMapUV;
varying vec4 passTangent;
#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 20:40:38 +00:00
uniform vec2 screenRes;
2023-02-25 19:03:39 +00:00
uniform float far;
uniform float alphaRef;
2020-01-12 07:42:47 +00:00
#if PER_PIXEL_LIGHTING
varying vec3 passViewPos;
#else
centroid varying vec3 passLighting;
centroid varying vec3 shadowDiffuseLighting;
#endif
2022-05-14 01:58:00 +00:00
varying vec3 passNormal;
2020-01-12 07:42:47 +00:00
#include "shadows_fragment.glsl"
2023-02-25 19:03:39 +00:00
#include "lib/light/lighting.glsl"
#include "lib/material/alpha.glsl"
2022-06-06 20:40:38 +00:00
#include "fog.glsl"
2020-01-12 07:42:47 +00:00
void main()
{
2023-01-19 16:39:38 +00:00
vec3 normal = normalize(passNormal);
2022-05-14 01:58:00 +00:00
2020-01-12 07:42:47 +00:00
#if @normalMap
vec4 normalTex = texture2D(normalMap, normalMapUV);
2023-01-19 16:39:38 +00:00
vec3 normalizedNormal = normal;
2020-01-12 07:42:47 +00:00
vec3 normalizedTangent = normalize(passTangent.xyz);
vec3 binormal = cross(normalizedTangent, normalizedNormal) * passTangent.w;
mat3 tbnTranspose = mat3(normalizedTangent, binormal, normalizedNormal);
2023-01-19 16:39:38 +00:00
normal = normalize(tbnTranspose * (normalTex.xyz * 2.0 - 1.0));
2020-01-12 07:42:47 +00:00
#endif
2023-01-19 16:39:38 +00:00
vec3 viewNormal = normalize(gl_NormalMatrix * normal);
2020-01-12 07:42:47 +00:00
#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-25 19:03:39 +00:00
gl_FragData[0].a = alphaTest(gl_FragData[0].a);
2021-02-14 23:32:04 +00:00
float shadowing = unshadowedLightRatio(linearDepth);
2020-01-12 07:42:47 +00:00
vec3 lighting;
#if !PER_PIXEL_LIGHTING
lighting = passLighting + shadowDiffuseLighting * shadowing;
#else
vec3 diffuseLight, ambientLight;
2023-01-19 16:39:38 +00:00
doLighting(passViewPos, viewNormal, shadowing, diffuseLight, ambientLight);
2020-01-12 07:42:47 +00:00
lighting = diffuseLight + ambientLight;
#endif
clampLightingResult(lighting);
2020-01-12 07:42:47 +00:00
gl_FragData[0].xyz *= lighting;
2023-02-25 19:03:39 +00:00
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth, far);
2020-01-12 07:42:47 +00:00
2022-05-14 01:58:00 +00:00
#if !@disableNormals
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
2020-01-12 07:42:47 +00:00
applyShadowDebugOverlay();
}