Jump to content

  • Log In with Google      Sign In   
  • Create Account

Determine light volume in screen space?


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
3 replies to this topic

#1 danromeo   Members   -  Reputation: 237

Like
0Likes
Like

Posted 14 June 2013 - 10:27 PM

Hello Gamedev.

 

I'm working on a deferred rendering engine and trying to figure out how to determine what area of the screen is affected by a light, so I can alter the rendering quad to only cover that area of the screen when creating the light map, instead of drawing the entire screen once per light.  Hope that makes sense.    

 

So I'm using Viewport.Project on the lights bounding frustum....but Project returns a Vector3.  Am I doing this right, and how do I get a 2d quad from the Vector3 returned by Project?  

 

This is the best forum on earth.  

 

THANKS 



Sponsor:

#2 phil_t   Crossbones+   -  Reputation: 4092

Like
0Likes
Like

Posted 14 June 2013 - 11:47 PM

What kind of light is it? Point light? Spotlight? Directional?

 

The simplest thing is probably just to render your light volume in worldspace, with the same View/Projection matrices you used for everything else.



#3 belfegor   Crossbones+   -  Reputation: 2716

Like
1Likes
Like

Posted 15 June 2013 - 12:18 AM


....but Project returns a Vector3...how do I get a 2d quad from the Vector3 returned by Project?

 x & y should be in viewport coords, eg. in range x = 0 - res.width & y = 0 - res.height, z is depth in 0 - 1 range (i think you don't need it for your light technique).

For points laying outside of view frustum you need to clamp them in these ranges (but before this you frustum cull these lights).

To get 2d quad/rectangle you need to find its  bounds:

Vector2 min = new Vector2(float.MaxValue, float.MaxValue);
            Vector2 max = new Vector2(float.MinValue, float.MinValue);
            float minDepth = float.MaxValue;
            foreach (Vector3 v in lightFrustumProjectedPoints)
            {
                if (v.X < min.X)
                {
                    min.X = v.X;
                }
                if (v.Y < min.Y)
                {
                    min.Y = v.Y;
                }
                if (v.X > max.X)
                {
                    max.X = v.X;
                }
                if (v.Y > max.Y)
                {
                    max.Y = v.Y;
                }

                if (v.Z < minDepth)
                {
                    minDepth = v.Z;
                }
            }


            //Clamp
            Clamp(min.X, 0f, viewport.width);
            Clamp(min.Y, 0f, viewport.height);
            Clamp(max.X, 0f, viewport.width);
            Clamp(max.Y, 0f, viewport.height);
            Clapm(minDepth, 0.0f, 1.0f);

although i have not used this technique for lights.

 

You can try with light volumes, spheres/box for point, pyramid/cone for spot lights and fullscreen quad for directional.

Thread with nice explanation.


Edited by belfegor, 15 June 2013 - 12:23 AM.


#4 danromeo   Members   -  Reputation: 237

Like
0Likes
Like

Posted 15 June 2013 - 10:01 AM

This is exactly what I needed. Nice post! THANKS!!!!




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.



PARTNERS