Ok, here is the solution I came up with.
Not claiming is the best solution, since its the first time I ever use shaders and I have been extremelly confused in the last couple of hours:
First of all I created a mask (the colored lines) that pretty much locates of all the candidates for shadow to be removed: Walls that are just above an empty cell.
The purple line indicates how tall the wall is, you can put this like higher or lower depending of the type of cell, so it won't mess up different walls depending on their height.
When I draw the walls I use the following shader:
uniform sampler2D texture; //Texture to draw
uniform sampler2D filterTexture; //Texture of the masks
uniform vec2 textureSize; //Size of the texture
uniform float cellSize; //Size of a cell in pixels
uniform sampler2D shadowTexture; //Texture were the shadows are drawn
void main()
{
vec2 position;
vec4 filterPixel;
vec4 shadowPixel;
bool aboveRed=false;
bool belowPurple=false;
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy );
for( float i=0 ; i<=cellSize*2 ; i++)
{
position = gl_TexCoord[0].xy;
position.y = position.y - (i/textureSize.y);
filterPixel = texture2D( filterTexture, position );
position.y = position.y + (1/textureSize.y);
shadowPixel = texture2D( shadowTexture, position );
if (shadowPixel == 0){
if( filterPixel.r == 1.0 && filterPixel.b == 0.0 )
{
aboveRed=true;
}
}
position = gl_TexCoord[0].xy;
position.y = position.y + (i/textureSize.y);
filterPixel = texture2D( filterTexture, position );
if(filterPixel.r == 1.0 && filterPixel.b == 1.0)
{
belowPurple = true;
}
if(belowPurple && aboveRed){
pixel.a = 0;
break;
}
}
gl_FragColor = pixel;
}
This shader pretty much looks for a red pixel (in the mask) bellow the current pixel within a cellSize*2 range. If it finds the red line, it check the shadow in the pixel just below it.
It also looks for a purple pixel above the current pixel within the same range.
If the current pixel meets this two conditions, the current pixel is drawn on the screen.
I don't know if this is a really dirty way to solve the problem, since, as I said, I never used shaders and i'm still pretty ignorant of it's usage.
If someone more knowledgeable on SLGL can comment on the shader, and also point me in the right direction for a good tutorial which could be useful for SFML users, that would be awesome!