Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17560

Create Polygonal View Frustum

$
0
0

I'm getting really close to being able to do real view frustum culling with triangle shaped or quad shaped polygons but need only one measly step to getting there.
Basically when I wanted to add frustum culling I did a number of techniques. First I tried testing the vertices of a poly to see if they are all in or out of the view frustum. Works great! Except one problem. When a polygon is big or you are close to it, all the vertices are out of the view frustum but the polygon remains to be seen. So I tried testing to see if the sides of the polygons were in the view frustum by using a line plane collision algorithm as a third and forth case, which is if the lines of the polygon collide into any of the 6 planes of the view frustum, it will be visible, else, cull the polygon. I was basically using this:

		for (int i = 0; i < 6; i++)
		{
			//Check if any of the 4 lines of the quad cross any of the 6 view frustum planes. If the values fall between 0 and 1, then the line has crossed
			//the plane and the polygon is visible.
			t[0] = -((frustum_plane[i].a * vertex[0].x + frustum_plane[i].b * vertex[0].y + frustum_plane[i].c * vertex[0].z) + frustum_plane[i].d) /
				     (frustum_plane[i].a * vector[0].x + frustum_plane[i].b * vector[0].y + frustum_plane[i].c * vector[0].z);
			t[1] = -((frustum_plane[i].a * vertex[1].x + frustum_plane[i].b * vertex[1].y + frustum_plane[i].c * vertex[1].z) + frustum_plane[i].d) /
				     (frustum_plane[i].a * vector[1].x + frustum_plane[i].b * vector[1].y + frustum_plane[i].c * vector[1].z);
			t[2] = -((frustum_plane[i].a * vertex[2].x + frustum_plane[i].b * vertex[2].y + frustum_plane[i].c * vertex[2].z) + frustum_plane[i].d) /
				     (frustum_plane[i].a * vector[2].x + frustum_plane[i].b * vector[2].y + frustum_plane[i].c * vector[2].z);
			t[3] = -((frustum_plane[i].a * vertex[0].x + frustum_plane[i].b * vertex[0].y + frustum_plane[i].c * vertex[0].z) + frustum_plane[i].d) /
				     (frustum_plane[i].a * vector[3].x + frustum_plane[i].b * vector[3].y + frustum_plane[i].c * vector[3].z);

			if ((t[0] < 0.0f || t[0] > 1.0f) &&
				(t[1] < 0.0f || t[1] > 1.0f) &&
				(t[2] < 0.0f || t[2] > 1.0f) &&
				(t[3] < 0.0f || t[3] > 1.0f))
			{
				pierced[i] = false;
			}
			else
			{
				pierced[i] = true;
			}
		}

Where the vector was literally all 4 sides of a quad. Works but ran into another problem. Even when the polygon is completely off screen, it still manages to collide into a frustum plane due to the fact it is literally 6 infinite planes. So I wanna test the frustum as six polygons rather than treat them as planes. How can I make the view frustum 6 polygonal quads? Thanks in advance.


Viewing all articles
Browse latest Browse all 17560

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>