It is currently Sat Aug 22, 2020 4:39 am


All times are UTC




Post new topic Reply to topic  [ 12 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: [Resolved]: Material woes
PostPosted: Tue Dec 06, 2011 10:37 pm 

Joined: Sat Dec 03, 2011 7:38 pm
Posts: 7
Is there any situation where the generated mesh from PolyVox would contain materials not found in the volume?

I'm populating a volume, and all my voxels only ever have material IDs 0, 1 or 2. Yet somehow some of the vertices generated by polyvox are coming out as material ID 3. It seems to be occuring in areas where there is a transition between 2 materials.

Here's a screenshot. Grass 1, Rock is 2, sand is 3. 0 is "error" material for things that shouldn't be drawn. I'm only populating my volume with grass and rock (1s and 2s), I have checked this and I know for 100% sure this is the case. Yet as you can see, Polyvox is producing ID 3. In the background you see some random patches of sand also, they should be rock. I've double checked everything, the 3s make it into the system as soon as I execute the surfaceextractor.

Image

Any thoughts?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Material woes
PostPosted: Wed Dec 07, 2011 9:26 am 
User avatar

Joined: Wed Jan 26, 2011 3:20 pm
Posts: 203
Location: Germany
how are you getting your indices from the SurfaceMesh? could there be any float casting issues?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Material woes
PostPosted: Wed Dec 07, 2011 9:37 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Actually I think this is indeed a bug in PolyVox. In the old days PolyVox only supported material volumes (no density), and zero was considered to be empty space while any other material id was solid. Therefore, when generating a surface between two voxels it was guarenteed that one of the voxels would be zero.

I needed to assign the material which was not zero to the vertices, and rather than using if-else statements I could just OR the value of the two voxels (knowing that one of them was zero). However, I don't think this logic makes sense anymore since we have the densities but it has been left in. A logical OR of '1' and '2' would give your value of '3'.

I'll move this to the bugs forum and get it fixed. Of course it could still be something else (like rounding errors... it's a bit ugly that PolyVox uses floats for the materials) but I'll start wth the logical OR.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Material woes
PostPosted: Wed Dec 07, 2011 11:47 am 
User avatar

Joined: Wed Jan 26, 2011 3:20 pm
Posts: 203
Location: Germany
David Williams wrote:
I'll move this to the bugs forum and get it fixed. Of course it could still be something else (like rounding errors... it's a bit ugly that PolyVox uses floats for the materials) but I'll start wth the logical OR.


I've always wondered, why are the material indices floats to begin with?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Material woes
PostPosted: Wed Dec 07, 2011 3:38 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
ker wrote:
I've always wondered, why are the material indices floats to begin with?


I'm not exactly sure which GPUs support integer types but I don't think it's all of them. I'm sure that DirectX10+ hardware will support them for indexing texture arrays, etc, but I don't know about older hardware. Whereas I do know that floats work everywhere.

However, PolyVox could (and probably should) still output integer materials and leave it up to the user to cast them to floats if necessary for their particular target hardware. The reason it doesn't do this at the moment is that it is currently possible to do a direct memcpy() of the index/vertex buffers which is theorectically faster than iterating over each vertex and copying/casting them one at a time.

In practice, many people are not doing a memcpy() anyway as they are using things like Ogre::ManualObject. Also, for some applications you want to split the mesh or duplicate triangles so in this case you are iteratng over the data anyway. I think in the future the data type will get changed to int rather than float.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Material woes
PostPosted: Wed Dec 07, 2011 4:03 pm 

Joined: Sat Dec 03, 2011 7:38 pm
Posts: 7
I iterate over my vertices (several times since I smooth the mesh and other stuff), so I don't use memcpy. I have a seperate VBO (using OpenGL) for positions and normals so I kinda have to.

Thanks for looking into it. I did notice some OR operations going on when I looked over the source code briefly but didn't really understand what was going on.

I know you're a busy man, and I don't mean to be rude, but I'm on a deadline - what kind of timeframe are we looking at?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Material woes
PostPosted: Thu Dec 08, 2011 8:31 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
I think you can fix this quite easily yourself. If you look in SurfaceExtractor.inl you need to replace the three lines similar to this:

Code:
const uint32_t uMaterial = v000.getMaterial() | v100.getMaterial();


with lines similar to this:

Code:
const uint32_t uMaterial = std::max(v000.getMaterial(), v100.getMaterial());


In Git master it's lines 445, 468, and 491, but the lines number might be different in the last snapshot. Looking at Git master should let you recognise the code though.

Note that the three instances are slightly different (v100 vs v010 vs v001) so don't just do a copy and paste. Let me know how that works out and I'll commit it if it's ok.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Material woes
PostPosted: Thu Dec 08, 2011 12:35 pm 

Joined: Sat Dec 03, 2011 7:38 pm
Posts: 7
Cheers, I'll have a go at that later and let you know how it turns out.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Material woes
PostPosted: Thu Dec 08, 2011 10:34 pm 

Joined: Sat Dec 03, 2011 7:38 pm
Posts: 7
Success! Your fix seems to have fixed the problem.

Image


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Material woes
PostPosted: Fri Dec 09, 2011 1:04 pm 

Joined: Wed Oct 26, 2011 2:09 pm
Posts: 9
What technique do you use for the texturing? Looks very nice : D


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net