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


All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Cubic extractor with array indices instead of normals
PostPosted: Mon Apr 04, 2011 12:02 pm 

Joined: Mon Apr 04, 2011 10:06 am
Posts: 5
Have anyone tried using an 0-5 number for normals which could be used as an index for an array containing regular vectors in the vertex shader?
That could also be used as an index for a texture atlas if you want different textures on the sides. They could be passed to the shader as bytes instead of float vectors (92% bandwidth reduction) or byte vectors (66% bandwidth reduction). This could be useful for embedded devices since they usually have limited bandwidth and memory.

I may do some benchmarking regarding this...


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Cubic extractor with array indices instead of normals
PostPosted: Mon Apr 04, 2011 8:24 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
I haven't tried this but in principle it should work, and it shouldn't be difficult to implement. However, personally I'm using the CubicSurfaceExtractor (i.e. without normals) and then generating the normals in the pixel shader as shown here. This saves even more space, and also allows for improved vertex sharing between quads.

That said, I haven't measured the performance so I don't know how it compares. Any insights are welcome :-)


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Cubic extractor with array indices instead of normals
PostPosted: Mon Apr 04, 2011 11:36 pm 

Joined: Mon Apr 04, 2011 10:06 am
Posts: 5
I've added yet another cubic extractor which gives out indices instead.

I also noticed a couple of things that should be done with the cubic extractors. They should be passed a callback so you can choose what to do with the data without it going into the weird Mesh class. The range checks in getVoxelAt has to go and extracting the edge cases seem trivial. getVoxelAt also seem to be called multiple times with the same parameters.

I see that getVoxelAt in Block uses asserts, these are currently still there in release mode right?

Also do you know of a better algorithm for this? (with less than 6 branches per voxel)


Attachments:
CubicSurfaceExtractorWithIndices.patch [13.12 KiB]
Downloaded 293 times
Top
Offline Profile  
Reply with quote  
 Post subject: Re: Cubic extractor with array indices instead of normals
PostPosted: Tue Apr 05, 2011 7:00 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Zoxc wrote:
I've added yet another cubic extractor which gives out indices instead.


That's fine, but I don't think we want to add this to PolyVox. The CubicSurfaceExtractorWithNormals is really just a simple testing class to help people get started with PolyVox, and to make the examples easier (no need to use shaders). But for real work you should use the standard CubicSurfaceExtractor (i.e. without normals) and generate the normals in the fragment shader. You can then have a lot less data in your mesh because vertices can be shared between faces which face in different directions.

Zoxc wrote:
They should be passed a callback so you can choose what to do with the data without it going into the weird Mesh class.


Possibly, if there is demand. Though our plan is really to try and stablise PolyVox from now on, and what you suggest would be a pretty big change affecting existing code. Plus I'm not convinced callbacks are a better approach than the SurfaceMesh class.

But anyway, wthin a week we will have moved to Git and then it will be possible for people to try these things in ther own repositories.

Zoxc wrote:
The range checks in getVoxelAt has to go and extracting the edge cases seem trivial.

The CubicSurfaceExtractor should handle the edge cases properly. The CubicSurfaceExtractorWithNormals may not, but that's because it just for testing and to keep the code simple.

Zoxc wrote:
getVoxelAt also seem to be called multiple times with the same parameters.

Again, only for the CubicSurfaceExtractorWithNormals. This is because three different faces of a cube may all want to share a vertex but have differnt normals. Hence the vertex gets duplicated three times. The CubicSurfaceExtractor does not have this problem.

Zoxc wrote:
I see that getVoxelAt in Block uses asserts, these are currently still there in release mode right?


No, they should only be present in debug mode.

Zoxc wrote:
Also do you know of a better algorithm for this? (with less than 6 branches per voxel)

Well, I've thought about other algorithms but none that I've been convinced are better. The branches may or may not be a bottleneck - it's equally possible that memory access is the bottleneck. Only profiling would tell for sure. But it's pretty fast regardless so I haven't worried about it much. When I work again on this surface extractor I'll be more inclined to focus on the triangle count than the speed.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Cubic extractor with array indices instead of normals
PostPosted: Wed Apr 06, 2011 10:26 am 

Joined: Mon Apr 04, 2011 10:06 am
Posts: 5
David Williams wrote:
That's fine, but I don't think we want to add this to PolyVox. The CubicSurfaceExtractorWithNormals is really just a simple testing class to help people get started with PolyVox, and to make the examples easier (no need to use shaders). But for real work you should use the standard CubicSurfaceExtractor (i.e. without normals) and generate the normals in the fragment shader. You can then have a lot less data in your mesh because vertices can be shared between faces which face in different directions.

I guess this will require some benchmarks!

Since I'm pretty new to this, what's the most efficient methods without and with normals or indices:
- for a single texture on all sides?
- for different textures on all sides?
- for a single texture on all sides with per-pixel lighting?
- for different textures on all sides with per-pixel lighting?
This is probably quite useful to have for reference too.

David Williams wrote:
Possibly, if there is demand. Though our plan is really to try and stablise PolyVox from now on, and what you suggest would be a pretty big change affecting existing code. Plus I'm not convinced callbacks are a better approach than the SurfaceMesh class.

This callback doesn't have to be explicit, it could just be another template parameter which defaults to the SurfaceMesh class so it wouldn't break anything. Another thing to add is a filter since it's likely you don't want all the voxels (say transparent or non-cubic objects). This filter might also control if normals should be added or not. That may get a bit complex (especially if you add mesh decimation into the mix) if the cubic surface extractors are more meant as examples or simple utilities.

David Williams wrote:
But anyway, wthin a week we will have moved to Git and then it will be possible for people to try these things in ther own repositories.

Excellent :)

David Williams wrote:
Zoxc wrote:
The range checks in getVoxelAt has to go and extracting the edge cases seem trivial.

The CubicSurfaceExtractor should handle the edge cases properly. The CubicSurfaceExtractorWithNormals may not, but that's because it just for testing and to keep the code simple.

What I mean was for the code to use a version of Volume::getVoxelAt which doesn't do range checks, the majority of the voxels will always be valid. Some basic profiling showed that around half of the time was spent in getVoxelAt, with profiled guided optimization this overhead seemed to disappear.

David Williams wrote:
Zoxc wrote:
getVoxelAt also seem to be called multiple times with the same parameters.

Again, only for the CubicSurfaceExtractorWithNormals. This is because three different faces of a cube may all want to share a vertex but have differnt normals. Hence the vertex gets duplicated three times. The CubicSurfaceExtractor does not have this problem.

What I was getting at was that the result should be stored in a variable and reused, for readability and performance's sake.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Cubic extractor with array indices instead of normals
PostPosted: Wed Apr 06, 2011 9:30 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Zoxc wrote:
I guess this will require some benchmarks!

Since I'm pretty new to this, what's the most efficient methods without and with normals or indices:
- for a single texture on all sides?
- for different textures on all sides?
- for a single texture on all sides with per-pixel lighting?
- for different textures on all sides with per-pixel lighting?
This is probably quite useful to have for reference too.


I don't really have any figures to hand about this. My current project isn't actually using textures anyway (just coloured cubes). So you'll just have to experiment ;-)

Zoxc wrote:
This callback doesn't have to be explicit, it could just be another template parameter which defaults to the SurfaceMesh class so it wouldn't break anything. Another thing to add is a filter since it's likely you don't want all the voxels (say transparent or non-cubic objects). This filter might also control if normals should be added or not. That may get a bit complex (especially if you add mesh decimation into the mix) if the cubic surface extractors are more meant as examples or simple utilities.


I have thought a bit about transparency but havn't really worked it through yet as I haven't needed it myself. I think I would make it another property of the VoxelType like material and density. Also need to think how it would work with the Marching Cubes surface extractor though.

Zoxc wrote:
What I mean was for the code to use a version of Volume::getVoxelAt which doesn't do range checks, the majority of the voxels will always be valid. Some basic profiling showed that around half of the time was spent in getVoxelAt, with profiled guided optimization this overhead seemed to disappear.


The CubicSurfaceExtractor should really be implemented using the VolumeSampler which would then avoid all the calls to GetVoxelAt. I haven't done this yet, but it shouldn't be difficult.

Zoxc wrote:
What I was getting at was that the result should be stored in a variable and reused, for readability and performance's sake.


This is already done, search the CubicSurfaceExtractor for 'm_previousSliceVertices' and 'm_currentSliceVertices'.


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


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