Shadows working, and looking totaly not shit.

Improved location of the shadowmap to always be infront of the camera.
This commit is contained in:
Tleety
2014-05-23 22:42:11 +02:00
parent dbad1ee7f5
commit a9f2911e41
7 changed files with 158 additions and 34 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ void main()
vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord);
vec4 ShadowTexel = texture(ShadowTexture, Input.TextureCoord);
//FragmentColor = LightingTexel;
//FragmentColor = DiffuseTexel;
FragmentColor = DiffuseTexel * (vec4(La, 0.0) + vec4(LightingTexel.rgb, 0.0)) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0);
//FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
+16 -4
View File
@@ -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;
}