1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 11: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.

119 lines
3.2 KiB
GLSL
Raw Normal View History

2020-12-16 21:46:09 +00:00
#version 120
2023-11-10 16:02:53 +00:00
#pragma import_defines(FORCE_OPAQUE, DISTORTION)
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;
#endif
2023-11-10 16:02:53 +00:00
uniform sampler2D opaqueDepthTex;
2020-12-16 21:46:09 +00:00
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;
2023-11-10 16:02:53 +00:00
uniform float distortionStrength;
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"
2023-11-10 16:02:53 +00:00
#include "lib/util/distortion.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"
#include "compatibility/normals.glsl"
2020-12-16 21:46:09 +00:00
void main()
{
#if @diffuseMap
gl_FragData[0] = texture2D(diffuseMap, diffuseMapUV);
2023-11-10 16:02:53 +00:00
#if defined(DISTORTION) && DISTORTION
vec2 screenCoords = gl_FragCoord.xy / (screenRes * @distorionRTRatio);
gl_FragData[0].a *= getDiffuseColor().a;
2023-11-10 16:02:53 +00:00
gl_FragData[0] = applyDistortion(gl_FragData[0], distortionStrength, gl_FragCoord.z, texture2D(opaqueDepthTex, screenCoords).x);
return;
#endif
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
vec3 specularColor = getSpecularColor().xyz;
2020-12-16 21:46:09 +00:00
#if @normalMap
vec4 normalTex = texture2D(normalMap, normalMapUV);
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);
specularColor *= normalTex.a;
#else
vec3 viewNormal = normalize(gl_NormalMatrix * passNormal);
2020-12-16 21:46:09 +00:00
#endif
float shadowing = unshadowedLightRatio(linearDepth);
vec3 diffuseLight, ambientLight, specularLight;
doLighting(passViewPos, viewNormal, gl_FrontMaterial.shininess, shadowing, diffuseLight, ambientLight, specularLight);
vec3 diffuse = diffuseColor.xyz * diffuseLight;
vec3 ambient = getAmbientColor().xyz * ambientLight;
2020-12-16 21:46:09 +00:00
vec3 emission = getEmissionColor().xyz * emissiveMult;
#if @emissiveMap
emission *= texture2D(emissiveMap, emissiveMapUV).xyz;
#endif
vec3 lighting = diffuse + ambient + emission;
vec3 specular = specularColor * specularLight * specStrength;
2020-12-16 21:46:09 +00:00
clampLightingResult(lighting);
2020-12-16 21:46:09 +00:00
gl_FragData[0].xyz = gl_FragData[0].xyz * lighting + specular;
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();
}