• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1Demx  Members

Posted 28 October 2013 - 06:18 AM

hi,

I have managed to create a directional shadow map with decent results so i decided to go on and try implementing

From what I understand the basic principle is the same as directional lights but using a perspective projection

So i use glm::perspective to create the new projection matrix..

glm::vec3 slPos = glm::vec3( 1.0f, 3.0f, 0.0f );
glm::vec3 slDir = glm::vec3( glm::normalize( glm::vec3( 0.0f, 0.0f, 0.0f ) - slPos ) );

glm::mat4 depthProjectionMatrix = glm::perspective<float>( 45.0f, 1.0f, 2.0f, 50.0f );
glm::mat4 depthViewMatrix = glm::lookAt( slPos, glm::vec3( 0.0f, 0.0f, 0.0f ), glm::vec3( 0.0f, 1.0f, 0.0f ) );

And this is the glsl code I use to access the depth value in the sampler2DShadow texture.

if( texture( shadowMap, vec3( ShadowCoord.xyz ) / ShadowCoord.w ) < ( ShadowCoord.z / ShadowCoord.w ) )
{
}

Applying these changes i get this result  .. there is the correct shadow but also a long shadow that shouldn't be there and I really can't find

an obvious bug..

Edited by Demx, 28 October 2013 - 06:21 AM.

### #2N.I.B.  Members

Posted 28 October 2013 - 06:33 AM

Look here:

### #3Demx  Members

Posted 28 October 2013 - 07:44 AM

i tried with

void main()
{
vec4 MaterialDiffuseColor = texture( gSampler, texCoord );

//{
//}

vec4 LightColor = vec4( 0.0, 0.0, 0.0, 0.0 );

LightColor += getSpotLightColor( spotLights[0] );

float fDiffuseIntensity = max(0.0, dot( normalize(vNormal), -sunLight.vDirection));
LightColor += vec4(sunLight.vColor*(sunLight.fAmbientIntensity+fDiffuseIntensity), 1.0);

outputColor = MaterialDiffuseColor * LightColor * shade;
}

but same result

Edited by Demx, 28 October 2013 - 07:45 AM.

### #4kalle_h  Members

Posted 28 October 2013 - 02:42 PM

Clamp texture coordinates to 0-1 range.

Also it's good trick to leave 1 pixel borders at edge with depth value of 1 and use scissors when rendering shadow maps. This will prevent some artifacts when samping outside of shadow map. But with spotlight light fallof should do the trick.

Ps. shadow2DProj returns shadow value that can be used direclty but textureProj return just depth value!

Edited by kalle_h, 28 October 2013 - 02:44 PM.

### #5Demx  Members

Posted 29 October 2013 - 01:01 PM

Clamp texture coordinates to 0-1 range.

Also it's good trick to leave 1 pixel borders at edge with depth value of 1 and use scissors when rendering shadow maps. This will prevent some artifacts when samping outside of shadow map. But with spotlight light fallof should do the trick.

Ps. shadow2DProj returns shadow value that can be used direclty but textureProj return just depth value!

shadow2DProj doesn't work for me ..

should this work in theory?

if( ( ShadowCoord.x >= 0 && ShadowCoord.x <= 1 ) &&
{
{
}
}

outputColor = MaterialDiffuseColor * LightColor * shade;

Edited by Demx, 29 October 2013 - 01:06 PM.

### #6N.I.B.  Members

Posted 29 October 2013 - 01:09 PM

Assuming you initialize shade to 0, then yes.
Basically, this check tells you that the current pixel is out of the texture, and hence out of the light frustum.

### #7Demx  Members

Posted 29 October 2013 - 01:19 PM

Assuming you initialize shade to 0, then yes.
Basically, this check tells you that the current pixel is out of the texture, and hence out of the light frustum.

actually i had to divide the variables in the if by ShadowCoord.w .. apart from that it works well now

### #8kalle_h  Members

Posted 06 November 2013 - 05:09 AM

Assuming you initialize shade to 0, then yes.
Basically, this check tells you that the current pixel is out of the texture, and hence out of the light frustum.

actually i had to divide the variables in the if by ShadowCoord.w .. apart from that it works well now

Just set texture wrap mode to clamp and you can loose that branch compleatly.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.