# Sphere projection

This topic is 4679 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello there, I'm coding a deferred shading algorythm, for thoses of you not familliar with the subject its simply a way to lighten a scene in image space. Now my problem is not directly related to deferred shading but rater to finding the dimensions of screen aligned quad that would perfectly fit the projection of a sphere in 3D. The sphere is centered on a light position in 3D and its radius is equal to the range of the attenuation of the light. What I tried is to transform the position of the light in view space then, in the same space, create a screen aligned quad using the apropriate radius. But after projection, the quad is not large enough (this works only in ortho projection). It would be easier to understand with a picture, but I dont know how to add one here...

##### Share on other sites
I found a solution...

That was what I did first :

ocvec3 & viewPosition = ovec3 ().transformCoord (lightPosition, matView);
ovec3 corners[4];
corners[0].transformCoord (viewPosition + ocvec3 (lightFalloff, lightFalloff, 0), matProjection);
corners[1].transformCoord (viewPosition + ocvec3 (-lightFalloff, lightFalloff, 0), matProjection);
corners[2].transformCoord (viewPosition + ocvec3 (lightFalloff, -lightFalloff, 0), matProjection);
corners[3].transformCoord (viewPosition + ocvec3 (-lightFalloff, -lightFalloff, 0), matProjection);
for (odword i = 0; i < 4; ++i)
{
if (corners.x < tlCorner.x) tlCorner.x = corners.x;
if (corners.x > brCorner.x) brCorner.x = corners.x;
if (corners.y > tlCorner.y) tlCorner.y = corners.y;
if (corners.y < brCorner.y) brCorner.y = corners.y;
}

This is what I do now :

ocvec3 & viewPosition = ovec3 ().transformCoord (lightPosition, matView);
ovec3 corners[8];
corners[0].transformCoord (viewPosition + ocvec3 (lightFalloff, lightFalloff, lightFalloff), matProjection);
corners[1].transformCoord (viewPosition + ocvec3 (-lightFalloff, lightFalloff, lightFalloff), matProjection);
corners[2].transformCoord (viewPosition + ocvec3 (lightFalloff, -lightFalloff, lightFalloff), matProjection);
corners[3].transformCoord (viewPosition + ocvec3 (-lightFalloff, -lightFalloff, lightFalloff), matProjection);
corners[4].transformCoord (viewPosition + ocvec3 (lightFalloff, lightFalloff, -lightFalloff), matProjection);
corners[5].transformCoord (viewPosition + ocvec3 (-lightFalloff, lightFalloff, -lightFalloff), matProjection);
corners[6].transformCoord (viewPosition + ocvec3 (lightFalloff, -lightFalloff, -lightFalloff), matProjection);
corners[7].transformCoord (viewPosition + ocvec3 (-lightFalloff, -lightFalloff, -lightFalloff), matProjection);
for (odword i = 0; i < 4; ++i)
{
ocvec2 & center = (corners + corners[i + 4]) * 0.5f;
if (center.x < tlCorner.x) tlCorner.x = center.x;
if (center.x > brCorner.x) brCorner.x = center.x;
if (center.y > tlCorner.y) tlCorner.y = center.y;
if (center.y < brCorner.y) brCorner.y = center.y;
}

A make a full box around the sphere in view space, project it, and find the "center" between the "near" and "far" plane of that box in projected space... It seems to work.. but is there a better way to do that ?

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 9
• 24
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633383
• Total Posts
3011591
• ### Who's Online (See full list)

There are no registered users currently online

×