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

Randomized Shadow Lookup

7 posts in this topic

Hi guys,

 

Right now I offset my shadowmap lookups with an array of constant values. I'm not sure if that's such a good idea since every pixel has the same sampling pattern.

 

I think the way to go is to fill a texture with random offset values but I don't know how to access them that way, what should I use for the uv values ?

 

I'm doing this now:

 

static const float2 Offsets[8] =
{
  float2(0.560991f, 0.741455f),
  ...
};
 
for(int i=0;i<8;i++){
  occluder=tex2D(ShadowMap,input.proj.xy+Offsets[i]*0.001f).x;
  sum += (occluder < receiver) ? 0 : 1;
}
shadow=sum/8;

 

I'd like a better way that isn't terribly complicated. Thanks a lot.

 

 

0

Share this post


Link to post
Share on other sites

It is already the appropriate method to use static offsets.  Use a Poisson pattern for the offsets and if you want the pattern to look less obvious use more samples (more Poisson offsets).

 

 

L. Spiro

1

Share this post


Link to post
Share on other sites

If you have a 2D texture containing random values, then you'll want to index it based on the shadow UV coordinates you calculate for sampling the shadow map. This way the sample pattern remains stable as the camera moves. You'll want to scale the UV values by some multiplier and use WRAP sampling, this way the random pattern can tile across the entire area being affected by the shadow map. So for instance if you have a 64x64 random texture and a 512x512 shadow map, you could multiply the UV coordinates by 8.0 in order to tile it 8 times in the U and V directions.

 

Also you don't need to store the actual offsets in the texture. Instead you can store a random [0, 1] value and multiply it by 2?, and then use it as rotation value. This way you can share the same static offsets for all pixels, but have a random rotation to effectively change the sample pattern.

2

Share this post


Link to post
Share on other sites

Thanks a lot, I switched to a Poisson disk for now. I will try out MJP's method tonight and see what happens.

 

Is there a way I can do adaptive sampling ? For example, if the samples are along the shadow edge I can take many more samples. I tried taking four samples and testing them but it didn't really work:

 

sum=0.0f;
 
occluder=tex2D(Sampler0,input.proj.xy+float2(0,1)*0.002f).x;
sum+=(occluder < receiver) ? 0.0f : 1.0f;
 
occluder=tex2D(Sampler0,input.proj.xy+float2(1,0)*0.002f).x;
sum+=(occluder < receiver) ? 0.0f : 1.0f;
 
occluder=tex2D(Sampler0,input.proj.xy+float2(0,-1)*0.002f).x;
sum+=(occluder < receiver) ? 0.0f : 1.0f;
 
occluder=tex2D(Sampler0,input.proj.xy+float2(-1,0)*0.002f).x;
sum+=(occluder < receiver) ? 0.0f : 1.0f;
 
if(sum == 0.0f){
 // all in shadow
 shadow=0.0f;
}
else if(sum == 4.0f){
 // all out of shadow
 shadow=1.0f;
}
else{
 // on penumbra
 // take lots of samples
}

 

Thanks again.

0

Share this post


Link to post
Share on other sites

There typically is but you should give more details on what you are trying to do.

It looks like percentage closer soft shadowing, which includes a step to estimate the size of the penumbra.  At the risk of artifacts you can reduce the number of samples you take based on the size of the penumbra.

 

 

L. Spiro

0

Share this post


Link to post
Share on other sites

I'm trying to anti-alias the hard edges from my SSM setup, I don't really want soft shadows per se.

 

I average multiple samples offset by the Poisson values. I'm not sure if this is defined as PCF (I think it is),

 

I was thinking, if all the samples in the disk are in shadow there really isn't a need to samples so many, the average will be the same if I sample 2 or 200. So maybe I can do a test and take a large number of samples only where it's needed on the edges.

 

Thanks a lot for helping.

Edited by Endemoniada
0

Share this post


Link to post
Share on other sites

You can't really use the first few samples as an indicator of whether you need more samples. You don't know that you need more samples until you take more samples!

 

Instead you can try pre-computing information about the penumbra regions in the shadow map. One way to do this is build a low resolution texture that contains the min and max shadow map depth for an entire region of the shadow map (similar to a Hi-Z depth buffer). With this information you can know for sure that a pixel will be completely in shadow or completely out of shadow for an entire region by comparing the pixel depth to the min and mex depth values.

1

Share this post


Link to post
Share on other sites

MJP, that's interesting. I'm going to do some research on Hi-Z because I'm not really sure what you mean. Thanks for helping.

 

PS - I was just reading (I think your) Position From Depth 3, it's very useful.

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