• 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.

12 replies to this topic

### #1Tasaq  Members

Posted 08 August 2012 - 07:22 AM

Hello,
I know, it's me again but I run into another strange problem and I am stuck in one place :\
I want to project a shadow map but renderTarget seems unable to be clamped (i set it from both xna and hlsl to pointClamp).
Even after manually clamping it in the shader It got extruded towards light position.
Picture will better explain the situation so I attach one (green line is where the projected texture should be cut off, and the ball in front of the car is lookAt point, and bellow normal buffer you see light view).
Here's HLSL code:
[source lang="cpp"]float3 DepthToPosition(float2 TexCoord){ float4 position; float d = tex2D(depth, TexCoord.xy); position.x = TexCoord.x * 2.0f - 1.0f; position.y = -(TexCoord.y * 2.0f - 1.0f); position.z = d; position.w = 1.0f; position = mul(position, InvertViewProjection); position /= position.w; return position;}float4 SpotShadow(VertexShaderOutput input) : COLOR0{ float3 Position = DepthToPosition(input.TexCoord); float4 texcoord = mul(float4(Position, 1.0), LightWorldViewProjection); if(texcoord.z < 0) return float4(1,0,0,1); texcoord.x = ((texcoord.x / texcoord.w) * 0.5 ) + 0.5; texcoord.y = ((texcoord.y / texcoord.w) * -0.5 ) + 0.5; if(texcoord.x < 0 || texcoord.x > 1 || texcoord.y < 0 || texcoord.x > 1) return float4(1,0,0,1); float LightDistance = (tex2D(shadow, texcoord.xy)); return LightDistance;}[/source]
I think I don't have to say i want to get rid of this if that is checking coords
But also I want to know why does it extrude projected texture towards light camera and how to reapir it

#### Attached Thumbnails

Edited by Tasaq, 08 August 2012 - 07:24 AM.

### #2Seabolt  Members

Posted 08 August 2012 - 12:11 PM

That definitely does look weird, something more sinister looks to be afoot. Have you tried taking it into PIX and seeing what is actually sampling at the extruded spots?
Perception is when one imagination clashes with another

### #3Tasaq  Members

Posted 08 August 2012 - 12:17 PM

That definitely does look weird, something more sinister looks to be afoot. Have you tried taking it into PIX and seeing what is actually sampling at the extruded spots?

To be onest I have never used PIX. I will try that in a few hours.
What You see I use with spotlight which projects light shape (black and white mask), which works fine. But I want to make a CSM and I am very concerned about this:)
It's first time I get this with spotlight o.O

Edited by Tasaq, 08 August 2012 - 12:17 PM.

### #4Seabolt  Members

Posted 08 August 2012 - 12:27 PM

It's definitely interesting, and shadowing issues are notoriously difficult to debug
It sort of looks like your shadow map test is giving false positives for sections that shouldn't be lit. Your light looks to be over the hood of the car, but it's shading areas behind the light, or at least out of the view of the light, so maybe something is going on there...

As far as PIX goes, MJP has a really good tutorial for it: (http://mynameismjp.wordpress.com/samples-tutorials-tools/pix-with-xna-tutorial/)
Perception is when one imagination clashes with another

### #5Tasaq  Members

Posted 08 August 2012 - 02:04 PM

Your light looks to be over the hood of the car, but it's shading areas behind the light

I worte that the ball in front of the car is lookAt point The light is at the top of that triangular shape (if you want I can reupload image with dot in light position).

As far as PIX goes, MJP has a really good tutorial for it: (http://mynameismjp.w...h-xna-tutorial/)

Thanks! I was thinking about asking for tutorial, but you were faster And I like MJP tutorials, they are very clear

### #6Seabolt  Members

Posted 08 August 2012 - 02:24 PM

Ah what I was more thinking about is that your depth map doesn't seem to include the area that is distorted. So maybe your depth testing isn't clipping unlit pixels, or your depth map doesn't properly generate the full field of view for the light.
Perception is when one imagination clashes with another

### #7Tasaq  Members

Posted 08 August 2012 - 04:52 PM

I feel ashamed to admit it but it was a typo...
In the last comparison in if statment there's x instead of y (at least i learnt basic stuff wiht PIX ).
Ok to make up for that here's what happenes with clamps made like that:
[source lang="cpp"]//hlsl sampler declarationtexture ShadowMap;sampler shadow = sampler_state{ Texture = (ShadowMap); AddressU = CLAMP; AddressV = CLAMP; MagFilter = POINT; MinFilter = POINT; Mipfilter = POINT;};//XNA side before draw call: device.SamplerStates[0] = SamplerState.PointClamp; device.SamplerStates[1] = SamplerState.PointClamp; device.SamplerStates[2] = SamplerState.PointClamp; device.SamplerStates[3] = SamplerState.PointClamp;[/source]
Left one is with if inside shader, right one is without. Why clamp doesn't work like that?

#### Attached Thumbnails

Edited by Tasaq, 08 August 2012 - 04:57 PM.

### #8Seabolt  Members

Posted 09 August 2012 - 09:45 AM

Clamp will take any texture fetches that are beyond 1.0f or lower than 0.0f and sample at 1.0f or 0.0f respectively. Now it looks like areas beyond the lit range are being shaded in the right image, and if you were to set clamp on the texture and every object in the scene sampled that texture, I could see that happening. Especially if the left hand image is the only shader that is supposed to read from that texture. But I'm not entirely certain what's happening in these images.

To the PIX!
Perception is when one imagination clashes with another

### #9Tasaq  Members

Posted 09 August 2012 - 10:56 AM

To the PIX!

PIX said it's clamped. Maybe I understand clamp the wrong way...
I will describe it how I understand clamping:
When texture's sampler state is set to uv clamp, tex2D returns transparent value when either u or v is out of [0,1] range.
When it's set to wrap, when u or v is, for instance, 1.1 tex2D reads it as 0.1 and thus we can make tiling.

### #10Seabolt  Members

Posted 09 August 2012 - 11:57 AM

Ah that's the problem, that's not what Clamp does.

Perception is when one imagination clashes with another

### #11Tasaq  Members

Posted 09 August 2012 - 12:25 PM

Ouch, so that's why.
So that if statement must remain there? Or is there another better solution?

Edited by Tasaq, 09 August 2012 - 12:26 PM.

### #12Seabolt  Members

Posted 09 August 2012 - 02:29 PM

Yes, that if statement looks to cull out the pixels that are outside the light's range. Sorry I didn't look over it very well that first time.
Perception is when one imagination clashes with another

### #13Tasaq  Members

Posted 09 August 2012 - 04:42 PM

Yes, that if statement looks to cull out the pixels that are outside the light's range. Sorry I didn't look over it very well that first time.

Okay, thanks, you helped me a lot and I learned some new things
I already implemented pcf and everything looks fine

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.