mirror of https://github.com/OpenMW/openmw.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.9 KiB
Plaintext
49 lines
1.9 KiB
Plaintext
7 years ago
|
#define SHADOWS @shadows_enabled
|
||
|
|
||
|
#if SHADOWS
|
||
|
@foreach shadow_texture_unit_index @shadow_texture_unit_list
|
||
2 years ago
|
uniform mat4 shadowSpaceMatrix@shadow_texture_unit_index;
|
||
7 years ago
|
uniform int shadowTextureUnit@shadow_texture_unit_index;
|
||
|
varying vec4 shadowSpaceCoords@shadow_texture_unit_index;
|
||
6 years ago
|
|
||
|
#if @perspectiveShadowMaps
|
||
|
uniform mat4 validRegionMatrix@shadow_texture_unit_index;
|
||
|
varying vec4 shadowRegionCoords@shadow_texture_unit_index;
|
||
|
#endif
|
||
7 years ago
|
@endforeach
|
||
6 years ago
|
|
||
|
// Enabling this may reduce peter panning. Probably unnecessary.
|
||
|
const bool onlyNormalOffsetUV = false;
|
||
7 years ago
|
#endif // SHADOWS
|
||
|
|
||
6 years ago
|
void setupShadowCoords(vec4 viewPos, vec3 viewNormal)
|
||
7 years ago
|
{
|
||
|
#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.
|
||
6 years ago
|
vec4 shadowOffset;
|
||
7 years ago
|
@foreach shadow_texture_unit_index @shadow_texture_unit_list
|
||
6 years ago
|
#if @perspectiveShadowMaps
|
||
|
shadowRegionCoords@shadow_texture_unit_index = validRegionMatrix@shadow_texture_unit_index * viewPos;
|
||
|
#endif
|
||
2 years ago
|
|
||
6 years ago
|
#if @disableNormalOffsetShadows
|
||
2 years ago
|
shadowSpaceCoords@shadow_texture_unit_index = shadowSpaceMatrix@shadow_texture_unit_index * viewPos;
|
||
6 years ago
|
#else
|
||
|
shadowOffset = vec4(viewNormal * @shadowNormalOffset, 0.0);
|
||
|
|
||
|
if (onlyNormalOffsetUV)
|
||
|
{
|
||
|
vec4 lightSpaceXY = viewPos + shadowOffset;
|
||
2 years ago
|
lightSpaceXY = shadowSpaceMatrix@shadow_texture_unit_index * lightSpaceXY;
|
||
6 years ago
|
|
||
|
shadowSpaceCoords@shadow_texture_unit_index.xy = lightSpaceXY.xy;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
vec4 offsetViewPosition = viewPos + shadowOffset;
|
||
2 years ago
|
shadowSpaceCoords@shadow_texture_unit_index = shadowSpaceMatrix@shadow_texture_unit_index * offsetViewPosition;
|
||
6 years ago
|
}
|
||
|
#endif
|
||
7 years ago
|
@endforeach
|
||
|
#endif // SHADOWS
|
||
|
}
|