Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

fluoro

Object culling and shadow casting

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my engine, when objects fall outside the view frustum and get culled then their shadows disappear as well. How do other people display shadows for objects that are outside the view frustum?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Form a convex hull by taking your view frustum and adding a point at the light source. If the object is not visible but within the convex hull then it can potentially cast a visible shadow so just draw that.

Here''s some old code to quickly do it for you:


const tQuickList<int>& visible_lights = visq.GetVisibleLights();
for (tQuickList<int>::const_iterator i = visible_lights.begin(); i != visible_lights.end(); ++i)
{
// Mark all visible lights

cPortalLight::Ptr light_ptr = Cast<cPortalLight>(m_GraphicsObjects[*i]);
light_ptr->GetPSObject()->SetEnabled(true);

// Ignore the light if its position is in the view frustum

cVector3 light_pos = light_ptr->GetWorldOrientation().GetTranslation();
if (frustum.ContainsPoint(light_pos))
continue;

// Generate the 8 extreme points of the view frustum

cVector3 vertices[8];
ASSERT(frustum.GetPointExtremes(vertices));

// Mark all frustum planes that are visible to the light

bool plane_visible[frustum.NB_PLANES];
for (int j = 0; j < frustum.NB_PLANES; j++)
plane_visible[j] = (frustum.planes[j].DistanceFrom(light_pos) < 1e-4f);

// Convex hull planes list

tVector<cPlane> planes;
planes.reserve(20);

// Add all non-visible planes to the convex hull

for (int j = 0; j < frustum.NB_PLANES; j++)
if (!plane_visible[j])
planes.push_back(frustum.planes[j]);

struct Face
{
int v[4];
int f[4];
};

Face faces[] =
{
{ // NEAR

{ 4, 5, 7, 6 },
{ cFrustum::TOP, cFrustum::RIGHT, cFrustum::BOTTOM, cFrustum::LEFT }
},
{ // FAR

{ 0, 2, 3, 1 },
{ cFrustum::LEFT, cFrustum::BOTTOM, cFrustum::RIGHT, cFrustum::TOP }
},
{ // LEFT

{ 0, 4, 6, 2 },
{ cFrustum::TOP, cFrustum::NEAR, cFrustum::BOTTOM, cFrustum::FAR }
},
{ // RIGHT

{ 5, 1, 3, 7 },
{ cFrustum::TOP, cFrustum::FAR, cFrustum::BOTTOM, cFrustum::NEAR }
},
{ // TOP

{ 0, 1, 5, 4 },
{ cFrustum::FAR, cFrustum::RIGHT, cFrustum::NEAR, cFrustum::LEFT }
},
{ // BOTTOM

{ 6, 7, 3, 2 },
{ cFrustum::NEAR, cFrustum::RIGHT, cFrustum::FAR, cFrustum::LEFT }
}
};

// Search for faces that belong to visible planes

for (int j = 0; j < frustum.NB_PLANES; j++)
{
if (plane_visible[j])
{
// Search for an adjacent face that is non-visible, representing a terminator edge

Face& face = faces[j];
for (int k = 0; k < 4; k++)
{
// Add a plane between the terminator edge and light position

int fi = face.f[k];
if (!plane_visible[fi])
planes.push_back(cPlane(light_pos, vertices[face.v[(k + 1) & 3]], vertices[face.v[k]]));
}
}
}

// Go through each object affected by this light

const tQuickList<int>& objects = light_ptr->GetObjects();
for (tQuickList<int>::const_iterator j = objects.begin(); j != objects.end(); ++j)
{
// Ignore objects that are visible

cPortalObject::Ptr object_ptr = Cast<cPortalObject>(m_GraphicsObjects[*j]);
if (object_ptr->GetFrame() == m_CurrentFrame + 1)
continue;

if (Intersections::TestOBBFrustum(object_ptr->GetOBB(), planes) && draw_contents)
m_RendererWorld->ShadowVisible(iInstance::Ptr(object_ptr->GetPSObject()), light_ptr->GetPSObject());
}
}


Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!