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

How does shadow mapping work?

6 posts in this topic

hi all,

 

I'm trying to implement the shadow mapping, but I can't understanding the exact theory behind it. My problem lies in the second pass where I need to compare the depth stored in the shadow map with the current pixel depth. 

 

Assume now in the second render pass I have the depth of one pixel, which value in shadow map should I compare to? how can I get that value?

I read some tutorial online, which says I need to calculate the distance between light source and the pixel in the second pass, but I don't know how.

 

Can someone elaborate the above part of the algorithm to me? Thanks in advance.

0

Share this post


Link to post
Share on other sites

Sure, I'll give it a shot. The idea is you need to be comparing depth values in the same space. When you generated your shadow map, you used a certain model, view, and projection matrix for a piece of geometry. When you render the scene from the camera's point of view, you have a model, view and projection matrix as well, but this results in a value that's in a different space. When you render from the point of view of the camera (the second pass), you must also transform by the lights model, view and projection matrix. This will give you a value that's in the range [-1, 1] for X, Y and Z. Texture coordinates are in the range [0, 1] though, so you must scale the value by .5 (note for OpenGL you must also negate the Y texture coordinate). After doing this you'll have texture coordinates to look into the shadow map and see what depth value the light "saw". You also have your pixel that you transformed into the same space, so you know what its depth value is. If the depth value you have for the pixel you are drawing is less than the depth value in the shadow map, that means the pixel you are drawing is closer to the light than what the light saw. In other words, it's not occluded and thus should not be in shadow.

thanks very much for your help here. but I still have some confusions. so far, my problem is in the second pass where I transform object vertices from both the view of the camera and the view of the light. But I don't know how to interpolate vertices of light view for every fragment(i'm using my own software graphics pipeline). 

0

Share this post


Link to post
Share on other sites
Apologies, I omitted a lot and made some pretty big errors in my first post (you aren't in the same space because your view matrix varies between your shadow map pass and your "normal" pass; you need to offset in addition to scale to generate shadow map texture coordinates). Although I don't know the specifics of your implementation, you can probably pass your world space coordinate to the fragment shader as a texture coordinate. I'm sure there are smarter ways of doing this (like you alluded to in your initial post) that only involve interpolating depth. smile.png
0

Share this post


Link to post
Share on other sites

Yeah, the most straightforward way to do this is to pass your world position (which of course you have access to in the vertex shader) to the pixel shader via a TEXCOORD semantic.

 

Then in your pixel shader, you can multiply that by the View * Projection matrix of your light (so your camera's V and P matrices are shader parameters used by your vertex shader as usual, and your light's V and P matrices are shader parameters used by your pixel shader). This should get you in the same space as what you used to generate your shadow map.

0

Share this post


Link to post
Share on other sites

Yeah, the most straightforward way to do this is to pass your world position (which of course you have access to in the vertex shader) to the pixel shader via a TEXCOORD semantic.

 

Then in your pixel shader, you can multiply that by the View * Projection matrix of your light (so your camera's V and P matrices are shader parameters used by your vertex shader as usual, and your light's V and P matrices are shader parameters used by your pixel shader). This should get you in the same space as what you used to generate your shadow map.

but the world position in vertex shader is vertex-based, how do I know what's the world position for every fragment(or pixel)?

and what space is the xy axes of shadow map in? I think it's in window space which are all integers. but view * Projection matrix only take us to clip space right?

Thanks.

Edited by sobeit
0

Share this post


Link to post
Share on other sites

but the world position in vertex shader is vertex-based, how do I know what's the world position for every fragment(or pixel)?

 

Just like I described: you pass it out of the vertex shader, and then you get the interpolated value in the pixel shader.

Edited by phil_t
0

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