mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-31 13:36:44 +00:00
This more-or-less gets rid of the shadow system's only depencency on FFP stuff. All that remains is it using OSG cameras, which OSG provides a uniform-based implementation of, too, which we can trivially migrate to. This should mean we're not eating any of the ~8 FPP-friendly texture units, which is good as Morrowind models can use all of those on their (although they very rarely do), and instead use some of the ~160 shader-only texture image units. This just requires not calling glEnable(GL_TEXTURE_2D), accomplished by changing setTextureAttributeAndModes to setTextureAttribute. Also changes from using glTexGen and its eye plane matrices to pass the shadow space matrix for each light to explicit uniforms. Thankfully, the maths was a simple combination of the valid region matrix and eye plane matrix maths. As of this commit, I believe this kills shadows in one eye for stereo rendering.
49 lines
No EOL
1.9 KiB
GLSL
49 lines
No EOL
1.9 KiB
GLSL
#define SHADOWS @shadows_enabled
|
|
|
|
#if SHADOWS
|
|
@foreach shadow_texture_unit_index @shadow_texture_unit_list
|
|
uniform mat4 shadowSpaceMatrix@shadow_texture_unit_index;
|
|
uniform int shadowTextureUnit@shadow_texture_unit_index;
|
|
varying vec4 shadowSpaceCoords@shadow_texture_unit_index;
|
|
|
|
#if @perspectiveShadowMaps
|
|
uniform mat4 validRegionMatrix@shadow_texture_unit_index;
|
|
varying vec4 shadowRegionCoords@shadow_texture_unit_index;
|
|
#endif
|
|
@endforeach
|
|
|
|
// Enabling this may reduce peter panning. Probably unnecessary.
|
|
const bool onlyNormalOffsetUV = false;
|
|
#endif // SHADOWS
|
|
|
|
void setupShadowCoords(vec4 viewPos, vec3 viewNormal)
|
|
{
|
|
#if SHADOWS
|
|
// This matrix has the opposite handedness to the others used here, so multiplication must have the vector to the left. Alternatively it could be transposed after construction, but that's extra work for the GPU just to make the code look a tiny bit cleaner.
|
|
vec4 shadowOffset;
|
|
@foreach shadow_texture_unit_index @shadow_texture_unit_list
|
|
#if @perspectiveShadowMaps
|
|
shadowRegionCoords@shadow_texture_unit_index = validRegionMatrix@shadow_texture_unit_index * viewPos;
|
|
#endif
|
|
|
|
#if @disableNormalOffsetShadows
|
|
shadowSpaceCoords@shadow_texture_unit_index = shadowSpaceMatrix@shadow_texture_unit_index * viewPos;
|
|
#else
|
|
shadowOffset = vec4(viewNormal * @shadowNormalOffset, 0.0);
|
|
|
|
if (onlyNormalOffsetUV)
|
|
{
|
|
vec4 lightSpaceXY = viewPos + shadowOffset;
|
|
lightSpaceXY = shadowSpaceMatrix@shadow_texture_unit_index * lightSpaceXY;
|
|
|
|
shadowSpaceCoords@shadow_texture_unit_index.xy = lightSpaceXY.xy;
|
|
}
|
|
else
|
|
{
|
|
vec4 offsetViewPosition = viewPos + shadowOffset;
|
|
shadowSpaceCoords@shadow_texture_unit_index = shadowSpaceMatrix@shadow_texture_unit_index * offsetViewPosition;
|
|
}
|
|
#endif
|
|
@endforeach
|
|
#endif // SHADOWS
|
|
} |