Followers 0

# Determine light volume in screen space?

## 3 posts in this topic

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

0

##### Share on other sites

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.

0

##### Share on other sites

....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.

Edited by belfegor
1

##### Share on other sites
This is exactly what I needed. Nice post! THANKS!!!!
0

## Create an account

Register a new account