Hello everyone.
I need help with my problem.
In my framebuffer (deffered shading) I have my light attachment, albeto, normal and also my shadow mapping.
In my "finalshader" I combine everything, but it seems that the shadow is overlapping and "erasing" the light:
this is my light attachment:
and my shadow (is still raw, with no filters or smoothing):
What do I need to do so that light overlaps the shadow, and not the shadow overlapping the light?
My final shader to combine:
//summed up uniforms
uniform sampler2D DiffuseBuffer;
uniform sampler2D LightBuffer;
uniform sampler2D DepthBufferShadow;
uniform mat4 View;
uniform mat4 Proj;
uniform mat4 World;
uniform vec3 lightPos;
uniform vec3 viewPos;
uniform mat4 lightSpaceMatrix;
//the shadow calcs
float ShadowCalculation(vec4 fragPosLightSpace)
{
vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
projCoords = projCoords * 0.5 + 0.5;
float closestDepth = texture(DepthBufferShadow, projCoords.xy).r;
float currentDepth = projCoords.z;
vec3 normal = normalize(texture2D(NormalBuffer, TexCoord).xyz);
vec3 FragPos = texture(PositionBuffer, TexCoord).xyz;
vec3 lightDir = normalize(lightPos - FragPos);
float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005);
float shadow = 0.0;
vec2 texelSize = 1.0 / textureSize(DepthBufferShadow, 0);
for(int x = -1; x <= 1; ++x)
{
for(int y = -1; y <= 1; ++y)
{
float pcfDepth = texture(DepthBufferShadow, projCoords.xy + vec2(x, y) * texelSize).r;
shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0;
}
}
shadow /= 9.0;
if(projCoords.z > 1.0)
shadow = 0.0;
return shadow;
}
///......................
//in main
vec3 FragPos = texture(PositionBuffer, TexCoord).xyz;
vec4 FragPosLightSpace = lightSpaceMatrix * vec4(FragPos, 1.0);
float shadow = ShadowCalculation(FragPosLightSpace);
FragColor = ((texture2D(DiffuseBuffer, TexCoord)*(vec4(vec3((1.0 - shadow)), 1.0)))) * texture2D(LightBuffer, TexCoord);
Can someone help me ?
thank