PDA

View Full Version : shadows? Best way and advise on "pauls projects"?



Andy Gilbert
04-14-2010, 01:10 PM
Hi, firstly im wanting to give shadows a go. And after lots of "googling" im now a little confused.

What is the current best way or most common used way of shadows? "real-time" if i dare? :) I would have thought using shaders? But cant find much on that soim not sure?

another good question would also be (from a beginners POV) what would be the best way to have a go at first?

I thought about this one (im sure you have seen it before) its hte "pauls projects" one. http://www.paulsprojects.net/tutorials/smt/smt.html
Is that a real-time one? As in if there is a rotating object the shadows are also updated? Its just at the start it seems he has some rotating objects?

Bascially, im still classing myself as a beginner, and im wanting to have a go at shadows.

Thanks
Andy

FrimaMichael
04-14-2010, 01:17 PM
I'm also a beginner and know nothing about shadows right now but I'm reading the red book and its doing a good job teaching me OpenGl, so I recommend this section of the book that deals with Shadows.

Again I did not read it myself and so do not know if it's the best way to start. Anyway, I believe shadow is a fairly "hard" topic to start with so good luck :)

http://www.glprogramming.com/red/chapter14.html#name15

strattonbrazil
04-14-2010, 04:59 PM
The tricky thing about shadows is when rendering an object, you have to have information of other objects in your scene similar to ray tracing to see if it's blocking the light. The two most popular ways of providing shadows are shadow maps and shadow volumes.

Shadow maps are depth textures rendered from the light's point of view and with a reprojection a surface you're shading can see if something is between in and the light. There are a lot of different methodologies on filtering these so they don't look blocky. They're the de facto way to do shadows interactively.

Shadow volumes involve calculating silhouettes around the objects at edges where one face is in shadow and the other is in light. This requires calculating them, which can be tricky for complex geometry and scenes. They do give nice clean shadows though.

Dark Photon
04-14-2010, 06:51 PM
Hi, firstly im wanting to give shadows a go.
You ought to. It's great fun. If you understand basic vector and matrix math, and understand what MODELING, VIEWING, and PROJECTION transforms are, then you shouldn't have any trouble. Just a little learning and piecing things together -- should be a fun project.


And after lots of "googling" im now a little confused.
Post your questions, and we'll help you out. Might outline what you think you understand and then ask what's got you confused.


What is the current best way or most common used way of shadows? "real-time" if i dare? :)

Define "best" :cool: That's a flame war waiting to happen. Best quality? Best performance? Best hard shadows? Best soft shadows? Best for explicit geometry? Alpha geometry? Dynamic geometry? Point light sources? Directional light sources? Area light sources? etc. ...you see what I mean. :D

However, in terms of "most common" "real-time" shadowing techniques, arguably "shadow maps" have that title right now.

There are bunches of tweaks, variations, and add-ons (cascaded, variance, exponential, etc.), but just try your hand at some basic shadow mapping first to lock in the basic concepts. Then branch off to the variations as desired.


I would have thought using shaders? But cant find much on that soim not sure?
Yeah, it's a heck of a lot more flexible doing shadow mapping using shaders, versus legacy techniques using the fixed-function pipeline, but you can use legacy fixed-function pipeline functionality to do very basic shadow mapping if you want.


another good question would also be (from a beginners POV) what would be the best way to have a go at first?
Just start with a simple scene casting a shadow of a cube or sphere onto a plane. Easy to cook up such a scene using GLUT or similar (sphere above plane -- check!) or just borrow it from an on-line tutorial somewhere. Then add the shadow casting logic.


I thought about this one (im sure you have seen it before) its hte "pauls projects" one. http://www.paulsprojects.net/tutorials/smt/smt.html
Is that a real-time one?
Yeah, that's a pretty good tutorial. Pretty good description of the concepts. Though its implementation uses the legacy fixed-function pipeline TEXGEN functionality to do the projective lookup into the shadow map. Works, but as a Phase 2 you might want to convert to using shaders as its much more flexible and more easily extended.


As in if there is a rotating object the shadows are also updated?
Exactly.

Dark Photon
04-14-2010, 07:05 PM
By the way, just so you don't get confused by all the verbage in some tutorials, the basic algorithm is:

1. Render a depth map of the scene from the light's perspective
2. Render the scene from the camera's perspective, using the depth map to determine what's "in shadow"

Step 1 is of course new. And Step 2 is what you've always been doing, but with the tweak of using that new "depth map" (aka "shadow map").

Dark Photon
04-14-2010, 07:24 PM
Also, here's another brief shadow mapping tutorial, but unlike Paul's Shadow Mapping Tutorial Project (http://www.paulsprojects.net/tutorials/smt/smt.html), features shadow mapping with GLSL:

* ShadowMapping with GLSL (Fabien Sanglard) (http://fabiensanglard.net/shadowmapping/index.php)

It's not perfect, but it gives you some idea how you might do this with shaders.

Note that while his fragment shader references the depth texture (i.e. shadow map) using a sampler2D and does an depth comparison using explicit shader logic, he could just has well have used a sampler2DShadow and configured the GPU to do hardware-accelerated depth comparisons, either with or without PCF, even with the shader path. That can be even more efficient on some GPUs. But pay no attention to that until you understand what shadow depth comparisons and PCF are.

Also, on the subject of real-time shadowing algorithms, here is a very good (and recent) anthology of these techniques:

* Casting Shadows in Real-time - SIGGRAPH Asia Course Notes (2009) (http://www.mpi-inf.mpg.de/resources/ShadowCourse)

Andy Gilbert
04-15-2010, 01:45 AM
Wow, cheers for that! Very much appriciated and ready to give it a go. I like the idea of using a shader. Seems somewhat cleaner.

Anyways, ill have a read and a go and report my results!

Thanks
Andy