Shadows working, and looking totaly not shit.
Improved location of the shadowmap to always be infront of the camera.
This commit is contained in:
@@ -5,6 +5,8 @@ layout (binding=1) uniform sampler2D ShadowTexture;
|
||||
layout (binding=2) uniform sampler2D NormalMapTexture;
|
||||
layout (binding=3) uniform sampler2D SpecularMapTexture;
|
||||
|
||||
uniform vec3 SunDirection_cameraspace;
|
||||
uniform mat4 V;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
@@ -23,10 +25,20 @@ out vec4 frag_Specular;
|
||||
|
||||
float Shadow(vec4 ShadowCoord)
|
||||
{
|
||||
//float cosTheta = clamp(dot(Input.Normal, 1.0), 0.0, 1.0);
|
||||
float bias = 0.0005; // cosTheta is dot( n,l ), clamped between 0 and 1
|
||||
bias = clamp(bias, 0.0, 0.01);
|
||||
if( texture(ShadowTexture, Input.ShadowCoord.xy).z < ShadowCoord.z - bias)
|
||||
if (Input.ShadowCoord.x < 0.0 || Input.ShadowCoord.x > 1.0 || Input.ShadowCoord.y < 0.0 || Input.ShadowCoord.y > 1.0)
|
||||
return 0.9;
|
||||
|
||||
//Fixed bias
|
||||
//float bias = 0.00005;
|
||||
|
||||
//Variable bias
|
||||
vec3 n = normalize(Input.Normal);
|
||||
vec3 l = normalize(SunDirection_cameraspace);
|
||||
float cosTheta = clamp(dot(n, l), 0.0, 1.0);
|
||||
float bias = tan(acos(cosTheta));
|
||||
bias = clamp(bias, 0.0, 0.00005);
|
||||
|
||||
if( texture(ShadowTexture, Input.ShadowCoord.xy).z < ShadowCoord.z + bias)
|
||||
{
|
||||
return 0.6;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user