View Full Version : Help Newbie, Visibility test for texture mapping
Nawar 02-08-2009, 09:25 PM Hi to all
I am a newbie to computer graphics so please excuse my ignorance. I have
a 3D mesh of a scanned object, and I have images taken from heaps of
known positions. I am currently doing a simple texture mapping procedure
which results in a simple vrml file. This is done offline using C++. The
output is a vrml file with a list of facets, where each facet is mapped
to a portion of an image
Currently the texture mapping process is simply: for each facet
- finds list of images (ie camera postions) where facet is facing camera (ie
backface culling)
- filters the list of images to keep the ones where the angle between
camera and facet's normal is less than a given threshold.
For now the winner image is simply the one that is most normal to the facet.
For most facets, the results are acceptable, but I need to develop this
further, since some facets are mapped to incorrect images due to
occlusion. Now I need to test for visibility (occlusion
culling). I have been doing some reasearch and seems like z-buffer is
the way to go (ie the most common) (please correct me if that's
wrong). But I am not sure I fully understand it. It seems like
for each image
for each pixel
find depth of closest 3D point (on a facet)
But I am sort of lost how does that help in texture mapping. In the end
of my visibility filter, I want for each facet, a list of images where
the whole facet is visible, I will then chose the winner based on some
other future defined criteris. I fail to see how using z -buffer will
tell me whether a facet is fully visible in an image. I might be
mistaken but is z-buffer used mainly to create an image from a new
viewpoint using existing images (I am not interested in that). I would
appreciate any help in clarifying how having a z buffer for each image
will help in deciding whether a facet is fully visible in that image.Is
ray tracing more suitable for my application
Thanks
Nawar
|
|
ThE_JacO
02-10-2009, 02:01 AM
If your final objective is finding what camera is best suited to map a facet, and you're walking facets in first place, why don't you work in that direction?
This is fairly brute force, but as a starting point:
Cast a ray from each vertex along the facet's normal and check it for intersections with the mesh itself.
If no intersections are found use the camera aligned the closest to that normal. If it's not safe to assume that camera will be right (distribution is very sparse on the hemisphere) then check for intersections from that camera to all vertices of the facet, if none intersects, you're good.
If intersections are found, find if they are partial (one or more rays didn't intersect).
If they are start another iteration of raycasting with the normal biased towards the vertex(ices) that didn't intersect.
If the intersections were complete then you'll have to start sampling quite heavily until you find a direction where you have no intersections, then integrate between that (or ideally those) and your normal until you obtain something close to optimal.
As I said this is fairly brute force, but the basic principle will get you there. Once you have that worked out you can start working on optimization.
Acceleration structures (most likely a simple OCtree will give you good benefits while still being trivial to implement if you're new to CG dev) would be the first step.
Other accelerations or methods might need some assumptions that I can't make for you without seeing the mesh and the distribution of the cameras.
IE: if the mesh is fairly dense and uniform checking for neighborhood results (after looking up normal discontinuity to make sure you don't bias towards irrelevant samples close to a sudden change in curvature) will help a lot with biasing and make the process exponentially faster while you complete more facets, but if distribution is very sparse or topology is not uniform this might not yield that much of a ROI.
Limiting the lenght of rays and the voxel look-up can also speed things tenfold, but if you're dealing with something like large flat terrains with occasional bumps (not so uncommon in similar operations for topography) then it often isn't so convenient.
A similar problem you can look into for further documentation is ambient occlusion.
Ambocc (with environment look-up) deals exactly with checking for intersections starting from samples on a piece of geometry, and looking up spherical coordinates for an environment.
The only difference will be that in your case the sampling point will be represented by facets rather than by what geometry was contained in a fragment, but the same principles and optimizations largely apply.
Nawar
02-11-2009, 06:44 PM
Thanks ThE_JacO for your help. I haven't heard of ambient occlusion before, I have just started looking into it after I read your post, it sound like it might do the job for me, I just need to read more to get it thru my head :-).
With regards to your first suggestion, could you please clarify some of my questions. Note you are right about your comment, my cameras' distribution is very sparse on the hemisphere.
You mentioned testing for intersections from camera to all the veritcies of the facet (I am using triangles so 3 vertices), if I get no intersections, how can that be good ie, I can't see how that would exclude partial ocllusions, couldn't the rays from the verticies to camera have no intersections, but rays from other points on the facet to camera might intersect the mesh??? How is this problem usually solved, should I sample the facet??
Again thanks for all your help, especially with the ambient occlusion, cause from the preliminary reading I have done now, it does seem like it might be my solution.
ThE_JacO
02-11-2009, 09:47 PM
Thanks ThE_JacO for your help. I haven't heard of ambient occlusion before, I have just started looking into it after I read your post, it sound like it might do the job for me, I just need to read more to get it thru my head :-).
Ambocc is common-place and thoroughly researched in CG, and it's been around for a while now. It's only natural though that if you're background is as an engineer and you're a competent programmer, but new to cg, it might come as a surprise :)
You're lucky that you're approaching a problem that has a well documented parallel.
You mentioned testing for intersections from camera to all the veritcies of the facet (I am using triangles so 3 vertices), if I get no intersections, how can that be good ie, I can't see how that would exclude partial ocllusions,
That greatly depends from your topological distribution and the shape of the meshes.
There is no guarantee, and like with all integration or minimization problems, you'll have at some point to make assumptions for the sake of performance.
If your distribution and the size of the triangles are irregular enough, and the shape has bits sticking out and odd nooks, then yes, you're right, you might have a partial occlusion that will simply not register at the vertices.
So, yes, you are correct. I was intentionally simplifying and making some assumptions, they don't necessarily apply to your data though.
couldn't the rays from the verticies to camera have no intersections, but rays from other points on the facet to camera might intersect the mesh??? How is this problem usually solved, should I sample the facet??
That's a way to do it, and it's how most amb-occ or similar processes are treated.
Yes, you can up the number of samples considerably. In amb-occ you normally sample from bits contained in fragments, in your case though you will have to work from the geometry I understand.
What you could do is use barycentric coordinates to create a grid of stalks (points to shoot rays from) for every facet, and cast a ray from each. Again, it's fundamentally integration, so there are no guarantees other than those provided by having a fierce enough sampling to defeat statistics.
Alternatively you could also test against intersection between volumes, building a pyramid from vertices to camera, or (easier to optimize but not as precise) using a cone.
This would be an accurate solution, but the computational order of the operations grows exponentially here, and it gets a little bit more complex (although from an implementation point of view it might be simplier than sampling from discrete elements of the barycentric space).
When you get to that point optimization starts becoming necessary if time is of any concern. Going about this brute force against the whole mesh every time is going to cost you aeons of computational time.
Again, I don't know the complexity and type of the terms, but I'd suggest you start looking into acceleration structures right away. It will come in terribly handy in first place, and imo the simplier ones make for very easy to visualise problems that are kinda fun to solve. Have a look into OCtrees for a first step.
Again thanks for all your help, especially with the ambient occlusion, cause from the preliminary reading I have done now, it does seem like it might be my solution.
You're welcome, it makes for an interesting thread anyway.
Now hope somebody with a stronger rendering background than me feels like pitching in :) There's a ton of interesting algorithmic solutions to deal with problems of this type, but I'm across different fields so I can't really recite all the techniques and formulas off the top of my head.
CGTalk Moderation
02-11-2009, 09:47 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.