With all this talk about producing shadows, I figured I’d share this…

Yes, it’s old, but I’m messing with shadow rendering and lighting for my game right now and I found kind of interesting. It’s probably not like the current approach at all but it seems interesting.



http://www.slideshare.net/stefan_b/shadow-volumes-on-programmable-graphics-hardware



@t0neg0d your post on shadows from about a month and a half ago was what started me reading into it. I’m researching shadow techniques in my spare time.



@nehon you’ve posted about shadows several times in the last weeks, I’ve noticed. Thought this might be of some interest to you as well.



I’d love to actually take a crack at it but my GLSL knowledge is very limited (I’ve only just begun learning. I made a grayscale shader though! xD). I’m just messing with and reading into lighting and GLSL to see what I can learn from it. Hopefully this helps someone!

I you wish to implement this, you’ll be very welcome.

Thought, note that shadow volume are known to be dependent to the geometries complexity, wich means the more you have geometries and the more they are detailed the more your shadow rendering will be slow.

Last time i checked it was not a very popular technique in the game industry.

But we need alternatives.



I think someone already posted something like this though, I’ll try to find the post.

He even posted a patch for the engine to support stencil operations that have been integrated.



EDIT ok i found the post and actually it was pretty advanced.

I have to check it , because back then i said we’d had it to the core, but it has never been done. I don’t remeber why though. Most likely I forgot…

http://hub.jmonkeyengine.org/groups/user-code-projects/forum/topic/shadow-volume-sceneprocessor/?topic_page=2&num=15

Try to find what Ulf Assarson has written (or check out the book http://www.realtimeshadows.com/). He is all about shadow volumes :slight_smile:

Actually you can supply a simple mesh for the shadow volu7me sif done right, kinda like with collision model vs view model.



Eg a person would not need single fingers , ect.



The main problem with volumes if transparency, eg if you have a shadow casting ladder texture, it will be renderd as a black block.

Also the one you point to has a problem with mirroring shadow volumes outside the farfrustrum.

Sorry for the delayed reply, but it seems the site was down for a day? I couldn’t access it for all of yesterday :frowning:



Anyway, I was reading up on shadow mapping (the current technique used for PSSM) and I was thinking of ways to make it work for point lights as well. Here’s my idea:


  1. Generate distance from a light to the fragment, in the form of a float. (side note, we could define a max distance for the light and if the distance is > maxRange then fade it out based on it’s range and distance)
  2. Color it and create a spherical depth map based on distances from the point light (or we could do a cube map, rendering 6 depth maps for all cardinal directions)
  3. Get the lighting values from the camera’s perspective, compare and remove, as is done with PSSM right now, and apply.



    I realize in practice it’s much more complex, and seeing as my knowledge of GLSL is very little I wouldn’t be the one to try it. I’d be willing to give it a go, but it’d take me a while to get the required knowledge.



    Pseudocode (Just for a light, not a fully shaded point light. I’m trying to leave room for that bit to be added to this):



    [java]



    uniform vec3 m_LightPos;

    uniform float m_MaxRange;

    uniform float m_Intensity;



    float distanceToFrag;



    void main(){

    float fadeDist = m_MaxRange*0.75;

    float darkenValue=m_Intensity;

    distanceToFrag=distance(m_LightPos, [However you get a fragment’s position, or a texture coordinate, however it would work]);

    if(distanceToFrag>m_MaxRange){

    gl_FragColor=vec4([however one would pass through the current, unmodified color]);

    return;

    } else if(distanceToFrag>fadeDist){

    darkenValue-=distanceToFrag-fadeDist;

    if(darkenValue<0){

    darkenValue=0;

    }

    }

    darkenValue = clamp(darkenValue, 0.0, 1.0);

    gl_FragColor = vec4(darkenValue, darkenValue, darkenValue, 1.0);

    }

    [/java]



    That would get us the darker values as they get further from the light, to be rendered to a sphere/cube map and placed accordingly. My best attempt as of right now.



    EDIT: As for the adding the shadows part, we could do it like the following:


  4. Add a box (instead of a plane) around the camera, the box’s texture is the rendered shadow map as a cube map. (we could optimize by finding if a face isn’t shaded and just removing it). Don’t rotate box with camera, keep it just in the same pos as camera
  5. Get the same image from the viewport’s perspective, as is done with PSSM.
  6. Compare and remove.
  7. Get final map, apply to viewport.



    Once again, my best jab at point light shadows is all spelled out. I wish I could do it myself, but I’m just not experienced enough with GLSL and full scene shaders. If anyone wants to take this method and give it a shot, go for it, I’d love to see if it’s possible! I’m just throwing ideas out from a slightly educated point of view for anyone interested. :slight_smile:



    Edit again: http://http.developer.nvidia.com/GPUGems/gpugems_ch12.html

    Basically exactly what I’m talking about, except that it’s in HLSL. Wouldn’t be difficult to port it though, I might give it a shot…