mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-09 21:42:13 +00:00
c48eee4eee
Fixes a regression in which pass lighting was clamped after being passed to fragment shader. For correct FFP emulation, we need to clamp the result in vertex shader. When clamping after interpolation, negative lights in particular have a much more drastic effect.
60 lines
1.4 KiB
GLSL
60 lines
1.4 KiB
GLSL
#version 120
|
|
|
|
#if @useUBO
|
|
#extension GL_ARB_uniform_buffer_object : require
|
|
#endif
|
|
|
|
#if @useGPUShader4
|
|
#extension GL_EXT_gpu_shader4: require
|
|
#endif
|
|
|
|
varying vec2 uv;
|
|
varying float euclideanDepth;
|
|
varying float linearDepth;
|
|
|
|
#define PER_PIXEL_LIGHTING (@normalMap || @forcePPL)
|
|
|
|
#if !PER_PIXEL_LIGHTING
|
|
centroid varying vec3 passLighting;
|
|
centroid varying vec3 shadowDiffuseLighting;
|
|
#endif
|
|
varying vec3 passViewPos;
|
|
varying vec3 passNormal;
|
|
|
|
#include "vertexcolors.glsl"
|
|
#include "shadows_vertex.glsl"
|
|
|
|
#include "lighting.glsl"
|
|
|
|
void main(void)
|
|
{
|
|
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
|
|
|
vec4 viewPos = (gl_ModelViewMatrix * gl_Vertex);
|
|
gl_ClipVertex = viewPos;
|
|
euclideanDepth = length(viewPos.xyz);
|
|
linearDepth = gl_Position.z;
|
|
|
|
#if (!PER_PIXEL_LIGHTING || @shadows_enabled)
|
|
vec3 viewNormal = normalize((gl_NormalMatrix * gl_Normal).xyz);
|
|
#endif
|
|
|
|
passColor = gl_Color;
|
|
passNormal = gl_Normal.xyz;
|
|
passViewPos = viewPos.xyz;
|
|
|
|
#if !PER_PIXEL_LIGHTING
|
|
vec3 diffuseLight, ambientLight;
|
|
doLighting(viewPos.xyz, viewNormal, diffuseLight, ambientLight, shadowDiffuseLighting);
|
|
passLighting = getDiffuseColor().xyz * diffuseLight + getAmbientColor().xyz * ambientLight + getEmissionColor().xyz;
|
|
clampLightingResult(passLighting);
|
|
shadowDiffuseLighting *= getDiffuseColor().xyz;
|
|
#endif
|
|
|
|
uv = gl_MultiTexCoord0.xy;
|
|
|
|
#if (@shadows_enabled)
|
|
setupShadowCoords(viewPos, viewNormal);
|
|
#endif
|
|
}
|