1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

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

113 lines
2.9 KiB
GLSL
Raw Normal View History

2020-12-17 00:46:09 +03:00
#version 120
#pragma import_defines(FORCE_OPAQUE)
2020-12-17 00:46:09 +03:00
2021-03-31 22:05:47 -07:00
#if @useUBO
#extension GL_ARB_uniform_buffer_object : require
#endif
2020-12-17 00:46:09 +03:00
#if @useGPUShader4
#extension GL_EXT_gpu_shader4: require
#endif
2023-02-26 14:31:41 -08:00
#define PER_PIXEL_LIGHTING 1
2020-12-17 00:46:09 +03:00
#if @diffuseMap
uniform sampler2D diffuseMap;
varying vec2 diffuseMapUV;
#endif
#if @emissiveMap
uniform sampler2D emissiveMap;
varying vec2 emissiveMapUV;
#endif
#if @normalMap
uniform sampler2D normalMap;
varying vec2 normalMapUV;
varying vec4 passTangent;
#endif
varying float euclideanDepth;
varying float linearDepth;
varying vec3 passViewPos;
varying vec3 passNormal;
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;
2023-02-26 14:31:41 -08:00
uniform float emissiveMult;
uniform float specStrength;
uniform bool useTreeAnim;
2022-06-06 22:40:38 +02:00
2023-02-25 11:03:39 -08:00
#include "lib/light/lighting.glsl"
#include "lib/material/alpha.glsl"
2020-12-17 00:46:09 +03:00
2023-02-26 14:31:41 -08:00
#include "compatibility/vertexcolors.glsl"
#include "compatibility/shadows_fragment.glsl"
#include "compatibility/fog.glsl"
2020-12-17 00:46:09 +03:00
void main()
{
2023-01-19 08:39:38 -08:00
vec3 normal = normalize(passNormal);
2022-05-13 18:58:00 -07:00
2020-12-17 00:46:09 +03:00
#if @diffuseMap
gl_FragData[0] = texture2D(diffuseMap, diffuseMapUV);
2021-11-07 16:02:27 +03:00
gl_FragData[0].a *= coveragePreservingAlphaScale(diffuseMap, diffuseMapUV);
2020-12-17 00:46:09 +03:00
#else
gl_FragData[0] = vec4(1.0);
#endif
vec4 diffuseColor = getDiffuseColor();
if (!useTreeAnim)
gl_FragData[0].a *= diffuseColor.a;
2023-02-26 14:31:41 -08:00
gl_FragData[0].a = alphaTest(gl_FragData[0].a, alphaRef);
2020-12-17 00:46:09 +03:00
#if @normalMap
vec4 normalTex = texture2D(normalMap, normalMapUV);
2023-01-19 08:39:38 -08:00
vec3 normalizedNormal = normal;
2020-12-17 00:46:09 +03:00
vec3 normalizedTangent = normalize(passTangent.xyz);
vec3 binormal = cross(normalizedTangent, normalizedNormal) * passTangent.w;
mat3 tbnTranspose = mat3(normalizedTangent, binormal, normalizedNormal);
2023-01-19 08:39:38 -08:00
normal = normalize(tbnTranspose * (normalTex.xyz * 2.0 - 1.0));
2020-12-17 00:46:09 +03:00
#endif
2023-01-19 08:39:38 -08:00
vec3 viewNormal = normalize(gl_NormalMatrix * normal);
2020-12-17 00:46:09 +03:00
float shadowing = unshadowedLightRatio(linearDepth);
vec3 diffuseLight, ambientLight;
2023-01-19 08:39:38 -08:00
doLighting(passViewPos, viewNormal, shadowing, diffuseLight, ambientLight);
2020-12-17 00:46:09 +03:00
vec3 emission = getEmissionColor().xyz * emissiveMult;
#if @emissiveMap
emission *= texture2D(emissiveMap, emissiveMapUV).xyz;
#endif
vec3 lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + emission;
clampLightingResult(lighting);
2020-12-17 00:46:09 +03:00
gl_FragData[0].xyz *= lighting;
float shininess = gl_FrontMaterial.shininess;
2021-11-10 19:58:06 +03:00
vec3 matSpec = getSpecularColor().xyz * specStrength;
2020-12-17 00:46:09 +03:00
#if @normalMap
matSpec *= normalTex.a;
#endif
if (matSpec != vec3(0.0))
gl_FragData[0].xyz += matSpec * getSpecular(viewNormal, passViewPos, shininess, shadowing);
2022-06-06 22:40:38 +02:00
2023-02-25 11:03:39 -08:00
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth, far);
2020-12-17 00:46:09 +03:00
#if defined(FORCE_OPAQUE) && FORCE_OPAQUE
// having testing & blending isn't enough - we need to write an opaque pixel to be opaque
gl_FragData[0].a = 1.0;
2020-12-17 00:46:09 +03:00
#endif
2022-05-13 18:58:00 -07:00
#if !defined(FORCE_OPAQUE) && !@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-12-17 00:46:09 +03:00
applyShadowDebugOverlay();
}