1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 06:35:30 +00:00

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

115 lines
3.1 KiB
GLSL
Raw Normal View History

2020-12-17 00:46:09 +03:00
#version 120
2023-11-10 08:02:53 -08:00
#pragma import_defines(FORCE_OPAQUE, DISTORTION)
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;
#endif
2023-11-10 08:02:53 -08:00
uniform sampler2D opaqueDepthTex;
2020-12-17 00:46:09 +03:00
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;
2023-11-10 08:02:53 -08:00
uniform float distortionStrength;
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"
2023-11-10 08:02:53 -08:00
#include "lib/util/distortion.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"
#include "compatibility/normals.glsl"
2020-12-17 00:46:09 +03:00
void main()
{
#if @diffuseMap
gl_FragData[0] = texture2D(diffuseMap, diffuseMapUV);
2023-11-10 08:02:53 -08:00
#if defined(DISTORTION) && DISTORTION
vec2 screenCoords = gl_FragCoord.xy / (screenRes * @distorionRTRatio);
gl_FragData[0].a = getDiffuseColor().a;
gl_FragData[0] = applyDistortion(gl_FragData[0], distortionStrength, gl_FragCoord.z, texture2D(opaqueDepthTex, screenCoords).x);
return;
#endif
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
vec3 specularColor = getSpecularColor().xyz;
2020-12-17 00:46:09 +03:00
#if @normalMap
vec4 normalTex = texture2D(normalMap, normalMapUV);
vec3 viewNormal = normalToView(normalTex.xyz * 2.0 - 1.0);
specularColor *= normalTex.a;
#else
vec3 viewNormal = normalize(gl_NormalMatrix * passNormal);
2020-12-17 00:46:09 +03: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-17 00:46:09 +03: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-17 00:46:09 +03:00
clampLightingResult(lighting);
2020-12-17 00:46:09 +03:00
gl_FragData[0].xyz = gl_FragData[0].xyz * lighting + specular;
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();
}