سؤال

I'm trying to implement tiled deferred rendering method and now I'm stuck. I'm computing min/max depth for each tile (32x32) and storing it in texture. Then I want to compute screen space bounding box (bounding square) represented by left down and top right coords of rectangle for every pointlight (sphere) in my scene (see pic from my app). This together with min/max depth will be used to check if light affects actual tile.

Problem is I have no idea how to do this. Any idea, source code or exact math?

bounding box of light, rendered light volume

Update Your idea I guess

My attempt

هل كانت مفيدة؟

المحلول

Screen-space is basically a 2D entity, so instead of a bounding box think of a bounding rectangle.

Here is a simple way to compute it:

  1. Project 8 corner points of your world-space bounding box onto the screen using your ModelViewProjection matrix
  2. Find a bounding rectangle of these points (which is just min/max X and Y coordinates of the points)

A more sophisticated way can be used to compute a screen-space bounding rect for a point light source. We calculate four planes that pass through the camera position and are tangent to the light’s sphere of illumination (the light radius). Intersections of each tangent plane with the image plane gives us 4 lines on the image plane. This lines define the resulting bounding rectangle.

Refer to this article for math details: http://www.altdevblogaday.com/2012/03/01/getting-the-projected-extent-of-a-sphere-to-the-near-plane/

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top