Skip to main content
GameDev.net gamedev.net
🔒 Locked

Visibility checking

Started by wolfman8k Jan 5, 2001 at 12:14 PM 5 replies 850+ views
Original Post
wolfman8k
wolfman8k
I have a scene with lots of triangles in it. I need to make a funtion that will tell me if a triangle is visible if I give it the camera position. The function should return true if at least 1 pixel of the triangle is visible and only false if the triangle is totaly blocked. Note, I want to only pass it the camera position, not the orientation. I''m using OpenGL, but I don''t think that it matters. Oh, and it doesn''t have to be real time (Even better, if I pass the function a box, it would tell me if there is anyway I can see the triangle from anywhere in the box) Thanks, wolfman8k
acw83
acw83
Yeah I want one too. That''s why I have been doing RESEARCH and am going to WRITE MY OWN algorithm... Seriously, people don''t just dish out their code. Plus, it''s a complicated topic.
Galileo430
Galileo430
3 Letters BSP. Check out the tutorial at www.grandus.com

If you want a solid tree. Check out the D3D tutorial at www.mrgamemaker.com

------------------------------------------------------------
I wrote the best video game ever, then I woke up...

Grandus.Com
------------------------------------------------------------I wrote the best video game ever, then I woke up...
CGI Joe
CGI Joe

BSP? That''s a little overkill if it''s not meant to be realtime.

What you need to do is calculate a vector from the camera position to any vertex on the polygon. Then calculate the Dot Product of this vector with the surface normal of the polygon. The polygon is facing the viewer if the result is negative.
"You say I''m a bitch like it''s a *bad* thing..."[email=alanetcetc@hotmail.com]Mail[/email] Site
zedzeek
zedzeek
for one triangle?

as above for the backfaced culling also

prolly the quickest way (it''ll give u all the triangles but might give some that arent actually in the view frustum)
take the point (A) in the center of the triangle. find the distance(B) to its most distant vertice.
measure the distance from the A to each of the viewfrustum planes if the distance is less than B then draw the triangle.

its also possible to do an accurate check tri with plane but it requires quite a bit more maths and will be quite a bit slower. though u could do this test for any tris that are borderline on the above test.

http://members.xoom.com/myBollux
wolfman8k
wolfman8k
Thanks for the help. But I need to make sure that the triangle also isn''t blocked by other triangles. Also, I don''t really have a view frustrum because I want to know if the triangle is visible from any camera orientation.

I think what I''ll do is render 6 shots from the camera, each shot orthagonal to each other. The triangle I want to check will be blue, and all the other triangles will be red. Then I''ll just scan for a blue pixel in all of the shots. If I find one, then
the triangle is visible, if I don''t then it''s not.

The only problem is I need to know if the triangle is visible from anywhere in a box. I guess I could just try 20 different positions inside the box.

I need this so I can make the scene render quicker. Like if I''m at a certain point, I KNOW exactly which triangles are visible and which aren''t so I don''t even have to pass them to the renderer.
Alan Kemp
Alan Kemp
It sounds like you are trying to compute PVS (potentialy visible set). A web search will turn up lots of information on PVS, or check the BSP/PVS tutorial on www.mr-gamemaker.com as it does exactly what I think you are after.

Alan
"There will come a time when you believe everything is finished. That will be the beginning." -Louis L'Amour

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.