简体   繁体   中英

Find out the texture portion needed for a mesh

I've got a very specific problem. I have an OpenGL application that is used to render video onto 3D meshes. As it turns out, I can make my video sources send me rectangular portions of the image, reducing memory usage. These portions are specified as a Rectangle2D(int x, int y, int width, int height) with 0 <= x <= w <= sourceVideoWidth and 0 <= y <= h <= sourceVideoHeight .

With that said, I want to find out, for each frame, and for each mesh the following:

  • Whether the mesh is visible
  • If so, what portion of image should I request

The benefit is reducint the texture upload to GPU, this operation is often the bottleneck in my application.

In order to simplify the problem let's make the assumption that all meshes are 3D rectangles arbitrarily positioned. A 3D rectangle is defined by four points:

class Rectangle3D
{
public:
    Vec3 topLeft;
    Vec3 topRight;
    Vec3 botLeft;
    Vec3 botRight;
}

Possible solutions:

A) Split the mesh into a point grid of points with known texture coordinates, and run frustum culling for each point, then, from the visible points find the top left and bottom right texture coordinates that we must request. This is rather inefficient, and the number of points to test multiplies when we add another mesh to the scene. Solutions that use just the four corners of the rectangle might be preferable.

B) Using the frustum defining planes (see frustum culling ). For further simplicity, using only the four planes that correspond to the screen sides. Finding out whether the mesh is visible is rather simple. Finding the visible texture coordinates would need several cases: - One or more frustum sides intersect with the mesh - No frustum sides intersect with the mesh - Either the mesh is fully visible - Or the mesh is surrounding the screen sides In any case I need several plane-plane and plane-line segment intersections. Which are not necessarily efficient.

C) Make a 2D projection of the Rectangle3D lines, resulting into a four side polygon, then using line segment intersection between the screen sides and the polygon sides. Also accounting for cases where we have no intersection and the mesh is still visible.

D) Using OpenGL occlusion query objects, this way a render pass could generate information about the visible mesh portion.

Is there any other solution that best solves this problem? If not which one would you use and why?

Just one more thought on to your solutions,

Why don't you incorporate one rendering pass for occlusion queries. Split your mesh into imaginary rectangles which tells you about the visible parts of the mesh. Like

在此处输入图片说明

Left part of the image is with imaginary sub-rectangles, right part of the image shows sub-rectangles visible within the screen area (red rectangle in this case). Based on this pass result, you will get the co-ordinates of mesh which are visible.

UPDATE: This is a sample view that explains my point. This can be done by using opengl query objects . r is result of GL_SAMPLES_PASSED

在此处输入图片说明

Since you will know which rectangles are visible through the result of the query objects , you will come to know which co-ordinates are visible.Google for opengl occlusion queries you will get detailed info. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM