Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!

Light passing through multiple objects

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.

  • You cannot reply to this topic
7 replies to this topic

#1 Shawn619   Members   -  Reputation: 342


Posted 02 June 2013 - 09:47 AM

I've have decided to hold off on making shadows for a while, but until then, I have a question:


Can I do a depth test to check whether a pixel has been hit by a particular ray and stop it before hitting more surfaces beyond the one it just hit? And can I do this without fully implementing shadows with the stencil buffer?


I'm also starting to think this is a problem that can solved in shader if a depth test exists in the shader?


The problem appears in my game when a ray of light doesn't stop when it hits an object, like a house:




#2 Brother Bob   Moderators   -  Reputation: 9249


Posted 02 June 2013 - 10:01 AM

As far as I understand your question, no, this cannot be done without implementing shadows, because this is exactly what shadows are; objects blocking light on other surfaces. There are plenty of methods that does not involve the stencil buffer if that's the part stopping you, but in any case, you need to implement a shadow algorithm to get a shadow effect.

#3 Shawn619   Members   -  Reputation: 342


Posted 02 June 2013 - 10:51 AM

Ah ok, thanks Brother Bob.


From what I've googled, stencil buffering seemed like the easiest way to produce shadows, while shadow mapping was the most difficult.

#4 BGB   Crossbones+   -  Reputation: 1554


Posted 02 June 2013 - 02:55 PM


I am currently using both stencil shadows and shadow-mapping.


shadow mapping isn't "that" hard, but may be slightly tricky to get it working right, mostly due to the levels of fussiness involved with getting depth-textures to work, and some of the math involved in the shaders.



stencil shadows have different issues:

the actually good and well-behaved strategy (depth fail) is patented;

the "not so good" strategy (depth pass) isn't very well behaved in-general, but can be hacked on to make it more usable.


another downside of stencil shadows is that its performance is a lot more dependent on the amount of scene geometry which may cast shadows for a given light (the more shadow geometry, the more rendering cost). this is bad for large outdoor scenes, as large amounts of shadows being cast by the sun may quickly become rather expensive.



in contrast, shadow-mapping scales a little better with scene complexity, handling large outdoor scenes with less overall performance impact, but leaves the cost of having and updating the shadow maps, making the light-sources more expensive.


another downside of shadow maps may be due to resolution. for example, it requires using high-resolution textures to avoid pixelated shadows, but high-resolution textures are expensive (eat a lot of VRAM, ...).


a trick here is potentially to have another texture which generates more detail for a space following the camera (so that shadows near the camera are more detailed), though I have not done this in my case.


another general downside of shadow maps is that of potentially having lagging pixelated character shadows (if the update rate is slow and the shadow-map resolution is a little weak).



in my case, I am currently using a compromise:

static light-sources and static world geometry use shadow-maps;

static light-sources and moving objects use stencil shadows;

dynamic light-sources use stencil shadows.


thus far, this seems to be working out ok.

granted, there may still be better ways to handle all of this, and the specifics may change in the future.




granted, for simply blocking light going through walls, it could be possible to implement shadow maps which are rarely updated, and ignore any moving objects.

#5 shocobenn   Members   -  Reputation: 273


Posted 04 June 2013 - 05:57 AM

Hello ! For the house in the background if you are classicaly doing the illumination, you can't do it, because you calculate it with normals. You have to dissolve this light with the shadow. You should use shadow map with preference, because this is a little bit like "tracing a ray" but more easy : you do an depth from the light vue.


Else if you don't want to use shadows, you could just have to don't apply the light if the pixel is behind and not apply dark color on the pixel.


If you really want to "trace ray of light", you should use ray tracting, this is beautifull but require a lot of ressources and is more used in cinema etc...


But i'm wondering why you don't want shadow ? Is it for the inside of the houses?


If this is the case, you should model the insides separated of the outsides and draw the insides after the outsides , with and other shader where you won't apply the shadow. And more, if this is where you can control character, you'll be able to only draw the current inside you're visiting, and so OPTIMIZATION  \o/. If you separate the insides elements like tables, you can ever do random houses (Imagine a sims binding of Isaac)



#6 Shawn619   Members   -  Reputation: 342


Posted 04 June 2013 - 03:58 PM

I have found a working version of shadow mapping for opengl at http://www.paulsprojects.net/tutorials/smt/smt.html. This technique, shadow mapping, appears to be more versatile than stencil buffers, which I do not like. And I would much rather use the most modern form of making shadows, too. I'm also glad that this tutorial is not deprecated like so many I have seen(NeHe). The only real disadvantage of this shadow mapping is having render my scene 3 times per display with the "city-type" world I plan to create with many objects may pose a problem, but I think I have a few ideas on how to optimize this: backface culling, occlusion culling, fog, low-res shadow maps.


So far, the tutorial's code is implementing nicely with a model I imported into the tutorial: 




The code for shadow mapping looks quite daunting, but I'm glad the website provides documentation on how they did it. Plus, this website is an invaluable resource with very smart people if I ever get really stumped.

Edited by Shawn619, 04 June 2013 - 03:59 PM.

#7 shocobenn   Members   -  Reputation: 273


Posted 05 June 2013 - 01:58 AM

I would suggest you to don't draw shadows of objects who are too far away or if you do an american style city, you can do an easy quadtree to know which one to draw.


But if this is only for performance like if you do a HUGE CITY and your computer is ramming. Else i don't think that will matter. 


Personnaly I used this tutorial, which I find more sexy http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/

#8 Shawn619   Members   -  Reputation: 342


Posted 05 June 2013 - 04:42 PM

I haven't implemented the this shadow mapping technique in my large city, yet, but thanks for making me think of solutions once that problem arises. I haven't completely understood the shadow code, yet, but when I do i'm sure I can restrict drawing shadows that are past a certain distance.


Thanks for the link, it answered some of the question I had been having about shadow mapping.

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.