• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Tasaq

SpotLight shadow projection

12 posts in this topic

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 [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
But also I want to know why does it extrude projected texture towards light camera and how to reapir it [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
Thank You in advance [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Edited by Tasaq
0

Share this post


Link to post
Share on other sites
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?
1

Share this post


Link to post
Share on other sites
[quote name='Seabolt' timestamp='1344449486' post='4967466']
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?
[/quote]
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
0

Share this post


Link to post
Share on other sites
It's definitely interesting, and shadowing issues are notoriously difficult to debug [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]
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: ([url="http://mynameismjp.wordpress.com/samples-tutorials-tools/pix-with-xna-tutorial/"]http://mynameismjp.wordpress.com/samples-tutorials-tools/pix-with-xna-tutorial/[/url])
0

Share this post


Link to post
Share on other sites
[quote name='Seabolt' timestamp='1344450467' post='4967475']
Your light looks to be over the hood of the car, but it's shading areas behind the light
[/quote]
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).
[quote name='Seabolt' timestamp='1344450467' post='4967475']
As far as PIX goes, MJP has a really good tutorial for it: (http://mynameismjp.w...h-xna-tutorial/)
[/quote]
Thanks! I was thinking about asking for tutorial, but you were faster :) And I like MJP tutorials, they are very clear :)
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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 [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] ).
Ok to make up for that here's what happenes with clamps made like that:
[source lang="cpp"]
//hlsl sampler declaration

texture 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? Edited by Tasaq
0

Share this post


Link to post
Share on other sites
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!
0

Share this post


Link to post
Share on other sites
[quote name='Seabolt' timestamp='1344527146' post='4967819']
To the PIX!
[/quote]
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.
0

Share this post


Link to post
Share on other sites
Ah that's the problem, that's not what Clamp does.

[url="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.textureaddressmode.aspx"]http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.textureaddressmode.aspx[/url]

Essentially if you read at address 1.25, -.25, your address will be changed to 1.0f, 0.0f.
0

Share this post


Link to post
Share on other sites
[quote name='Seabolt' timestamp='1344535071' post='4967861']
Essentially if you read at address 1.25, -.25, your address will be changed to 1.0f, 0.0f.
[/quote]

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

Share this post


Link to post
Share on other sites
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.
1

Share this post


Link to post
Share on other sites
[quote name='Seabolt' timestamp='1344544149' post='4967903']
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.
[/quote]
Okay, thanks, you helped me a lot and I learned some new things :)
I already implemented pcf and everything looks fine :D
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0