1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-19 22:53:53 +00:00
openmw/files/shaders/compatibility/bs/default.frag

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

113 lines
3 KiB
GLSL
Raw Normal View History

2020-12-16 21:46:09 +00:00
#version 120
#pragma import_defines(FORCE_OPAQUE)
2020-12-16 21:46:09 +00:00
2021-04-01 05:05:47 +00:00
#if @useUBO
#extension GL_ARB_uniform_buffer_object : require
#endif
2020-12-16 21:46:09 +00:00
#if @useGPUShader4
#extension GL_EXT_gpu_shader4: require
#endif
2023-02-26 22:31:41 +00:00
#define PER_PIXEL_LIGHTING 1
2020-12-16 21:46:09 +00: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 20:40:38 +00:00
uniform vec2 screenRes;
2023-02-25 19:03:39 +00:00
uniform float far;
uniform float alphaRef;
2023-02-26 22:31:41 +00:00
uniform float emissiveMult;
uniform float specStrength;
uniform bool useTreeAnim;
2022-06-06 20:40:38 +00:00
2023-02-25 19:03:39 +00:00
#include "lib/light/lighting.glsl"
#include "lib/material/alpha.glsl"
2020-12-16 21:46:09 +00:00
2023-02-26 22:31:41 +00:00
#include "compatibility/vertexcolors.glsl"
#include "compatibility/shadows_fragment.glsl"
#include "compatibility/fog.glsl"
2020-12-16 21:46:09 +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-12-16 21:46:09 +00:00
#if @diffuseMap
gl_FragData[0] = texture2D(diffuseMap, diffuseMapUV);
2021-11-07 13:02:27 +00:00
gl_FragData[0].a *= coveragePreservingAlphaScale(diffuseMap, diffuseMapUV);
2020-12-16 21:46:09 +00:00
#else
gl_FragData[0] = vec4(1.0);
#endif
vec4 diffuseColor = getDiffuseColor();
if (!useTreeAnim)
gl_FragData[0].a *= diffuseColor.a;
2023-02-26 22:31:41 +00:00
gl_FragData[0].a = alphaTest(gl_FragData[0].a, alphaRef);
2020-12-16 21:46:09 +00:00
#if @normalMap
vec4 normalTex = texture2D(normalMap, normalMapUV);
2023-01-19 16:39:38 +00:00
vec3 normalizedNormal = normal;
2020-12-16 21:46:09 +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-12-16 21:46:09 +00:00
#endif
2023-01-19 16:39:38 +00:00
vec3 viewNormal = normalize(gl_NormalMatrix * normal);
2020-12-16 21:46:09 +00:00
float shadowing = unshadowedLightRatio(linearDepth);
vec3 diffuseLight, ambientLight;
2023-01-19 16:39:38 +00:00
doLighting(passViewPos, viewNormal, shadowing, diffuseLight, ambientLight);
2020-12-16 21:46:09 +00: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-16 21:46:09 +00:00
gl_FragData[0].xyz *= lighting;
float shininess = gl_FrontMaterial.shininess;
2021-11-10 16:58:06 +00:00
vec3 matSpec = getSpecularColor().xyz * specStrength;
2020-12-16 21:46:09 +00:00
#if @normalMap
matSpec *= normalTex.a;
#endif
if (matSpec != vec3(0.0))
2023-01-19 16:39:38 +00:00
gl_FragData[0].xyz += getSpecular(viewNormal, normalize(passViewPos.xyz), shininess, matSpec) * shadowing;
2022-06-06 20:40:38 +00:00
2023-02-25 19:03:39 +00:00
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth, far);
2020-12-16 21:46:09 +00: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-16 21:46:09 +00:00
#endif
2022-05-14 01:58:00 +00:00
#if !defined(FORCE_OPAQUE) && !@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-12-16 21:46:09 +00:00
applyShadowDebugOverlay();
}