It is currently Tue Feb 18, 2020 1:20 am


All times are UTC




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Improved CubicSurfaceExtractor
PostPosted: Thu Oct 21, 2010 10:11 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Hi all,

I know that at least a couple of people are using the CubicSurfaceExtractor for MineCraft style levels so I wanted to let you know that I've made some improvements to it. These will break your existing code so read carefully.

The biggest difference is that this surface extractor no longer generates normals for the vertices. This mean less data per vertex, and also it means vertices can be shared between different faces of a cube. So generally less data and faster uploads to the GPU.

The catch is that you will still want normals for your lighting, and to solve this I propose generating your normals in the pixel shader. I use the following shader code to do this in Thermite:

Code:
float3 worldNormal = cross(ddy(inWorldPosition.xyz), ddx(inWorldPosition.xyz));
worldNormal = normalize(worldNormal);


I can't use this same trick on the surfaces generated by the Marching Cubes algorithm, and so that one still generates normals. As a result there is now more than one type of vertex in PolyVox. The old 'SurfaceVertex' is gone and in its place are two classes called 'PositionMaterial' and 'PositionMaterialNormal'. The SurfaceMesh class has also been templatized so it can work with either of these types.

If for some reason you still want normals from the CubicSurfaceExtractor then the old version of the code is still available as a class called CubicSurfaceExtractorWithNormals.

It seems to all work OK though there are still some loose ends to tidy up. PolyVox does not have a stable API but hopefully these changes aren't too problematic.

I won't be doing any development for the next week or so but should be able to answer any questions.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Improved CubicSurfaceExtractor
PostPosted: Sat Oct 23, 2010 3:14 am 

Joined: Sat Sep 18, 2010 9:45 pm
Posts: 189
Upvote!

Yeah I mean cool. I will check it out ASAP. Thanks.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Improved CubicSurfaceExtractor
PostPosted: Tue Nov 02, 2010 5:03 pm 

Joined: Sun Oct 03, 2010 10:13 pm
Posts: 73
Just tried out the new CubicSurfaceExtractor. I noticed two things:
1) The outmost voxels are correctly drawn now :)
2) I had to include <Array.h> in order to compile my project using CubicSurfaceExtractor. I think the CSE class file should include this file itself.

And again a handful of warnings, I list them here in case you want to fix them (it took me only a couple of minutes):

Code:
__PolyVox_CubicSurfaceExtractor_H__
..\Tools\include\PolyVox\CubicSurfaceExtractor.h||In constructor 'PolyVox::CubicSurfaceExtractor<VoxelType>::CubicSurfaceExtractor(PolyVox::Volume<VoxelType>*, PolyVox::Region, PolyVox::SurfaceMesh<PolyVox::PositionMaterial>*) [with VoxelType = PolyVox::MaterialDensityPair<unsigned char, 7u, 1u>]':|
D:\Programmieren\Mine_ModDLL\main.cpp:244|152|instantiated from here|
..\Tools\include\PolyVox\CubicSurfaceExtractor.h|59|warning: 'PolyVox::CubicSurfaceExtractor<PolyVox::MaterialDensityPair<unsigned char, 7u, 1u> >::m_regSizeInVoxels' will be initialized after|
..\Tools\include\PolyVox\CubicSurfaceExtractor.h|56|warning:   'PolyVox::SurfaceMesh<PolyVox::PositionMaterial>* PolyVox::CubicSurfaceExtractor<PolyVox::MaterialDensityPair<unsigned char, 7u, 1u> >::m_meshCurrent'|
..\Tools\include\PolyVox\CubicSurfaceExtractor.inl|36|warning:   when initialized here|

__PolyVox_Array_H__
..\Tools\include\PolyVox\Array.h||In constructor 'PolyVox::Array<dimensions, ElementType>::Array() [with unsigned int noOfDims = 3u, ElementType = PolyVox::IndexAndMaterial]':|
..\Tools\include\PolyVox\CubicSurfaceExtractor.inl:40|24|instantiated from 'PolyVox::CubicSurfaceExtractor<VoxelType>::CubicSurfaceExtractor(PolyVox::Volume<VoxelType>*, PolyVox::Region, PolyVox::SurfaceMesh<PolyVox::PositionMaterial>*) [with VoxelType = PolyVox::MaterialDensityPair<unsigned char, 7u, 1u>]'|
D:\Programmieren\Mine_ModDLL\main.cpp:244|152|instantiated from here|
..\Tools\include\PolyVox\Array.h|111|warning: 'PolyVox::Array<3u, PolyVox::IndexAndMaterial>::m_pElements' will be initialized after|
..\Tools\include\PolyVox\Array.h|108|warning:   'uint32_t* PolyVox::Array<3u, PolyVox::IndexAndMaterial>::m_pDimensions'|
..\Tools\include\PolyVox\Array.inl|31|warning:   when initialized here|

Array.inl
..\Tools\include\PolyVox\Array.inl||In member function 'void PolyVox::Array<dimensions, ElementType>::resize(const uint32_t (&)[noOfDims]) [with unsigned int noOfDims = 3u, ElementType = PolyVox::IndexAndMaterial, uint32_t = unsigned int]':|
..\Tools\include\PolyVox\CubicSurfaceExtractor.inl:53|3|instantiated from 'void PolyVox::CubicSurfaceExtractor<VoxelType>::execute() [with VoxelType = PolyVox::MaterialDensityPair<unsigned char, 7u, 1u>]'|
D:\Programmieren\Mine_ModDLL\main.cpp:245|27|instantiated from here|
..\Tools\include\PolyVox\Array.inl|147|warning: comparison between signed and unsigned integer expressions|

CubicSurfaceExtractor.inl
..\Tools\include\PolyVox\CubicSurfaceExtractor.inl||In member function 'int32_t PolyVox::CubicSurfaceExtractor<VoxelType>::addVertex(float, float, float, uint8_t, PolyVox::Array<3u, PolyVox::IndexAndMaterial>&) [with VoxelType = PolyVox::MaterialDensityPair<unsigned char, 7u, 1u>, int32_t = int, uint8_t = unsigned char]':|
..\Tools\include\PolyVox\CubicSurfaceExtractor.inl:87|103|instantiated from 'void PolyVox::CubicSurfaceExtractor<VoxelType>::execute() [with VoxelType = PolyVox::MaterialDensityPair<unsigned char, 7u, 1u>]'|
D:\Programmieren\Mine_ModDLL\main.cpp:245|27|instantiated from here|

CubicSurfaceExtractor.inl
..\Tools\include\PolyVox\CubicSurfaceExtractor.inl|174|warning: comparison between signed and unsigned integer expressions|
..\Tools\include\PolyVox\CubicSurfaceExtractor.inl:87|103|instantiated from 'void PolyVox::CubicSurfaceExtractor<VoxelType>::execute() [with VoxelType = PolyVox::MaterialDensityPair<unsigned char, 7u, 1u>]'|
D:\Programmieren\Mine_ModDLL\main.cpp:245|27|instantiated from here|

CubicSurfaceExtractor.inl
..\Tools\include\PolyVox\CubicSurfaceExtractor.inl|172|warning: unused variable 'uZ'|

__PolyVox_SubArray_H__
..\Tools\include\PolyVox\PolyVoxImpl\SubArray.h||In constructor 'PolyVox::SubArray<noOfDims, ElementType>::SubArray(ElementType*, uint32_t*, uint32_t*) [with unsigned int noOfDims = 2u, ElementType = PolyVox::IndexAndMaterial, uint32_t = unsigned int]':|
..\Tools\include\PolyVox\Array.inl:79|33|instantiated from 'PolyVox::SubArray<(noOfDims - 1), ElementType> PolyVox::Array<dimensions, ElementType>::operator[](uint32_t) [with unsigned int noOfDims = 3u, ElementType = PolyVox::IndexAndMaterial, uint32_t = unsigned int]'|
..\Tools\include\PolyVox\CubicSurfaceExtractor.inl:176|58|instantiated from 'int32_t PolyVox::CubicSurfaceExtractor<VoxelType>::addVertex(float, float, float, uint8_t, PolyVox::Array<3u, PolyVox::IndexAndMaterial>&) [with VoxelType = PolyVox::MaterialDensityPair<unsigned char, 7u, 1u>, int32_t = int, uint8_t = unsigned char]'|
..\Tools\include\PolyVox\CubicSurfaceExtractor.inl:87|103|instantiated from 'void PolyVox::CubicSurfaceExtractor<VoxelType>::execute() [with VoxelType = PolyVox::MaterialDensityPair<unsigned char, 7u, 1u>]'|
D:\Programmieren\Mine_ModDLL\main.cpp:245|27|instantiated from here|
..\Tools\include\PolyVox\PolyVoxImpl\SubArray.h|56|warning: 'PolyVox::SubArray<2u, PolyVox::IndexAndMaterial>::m_pElements' will be initialized after|
..\Tools\include\PolyVox\PolyVoxImpl\SubArray.h|53|warning:   'uint32_t* PolyVox::SubArray<2u, PolyVox::IndexAndMaterial>::m_pDimensions'|
..\Tools\include\PolyVox\PolyVoxImpl\SubArray.inl|47|warning:   when initialized here|



Top
Offline Profile  
Reply with quote  
 Post subject: Re: Improved CubicSurfaceExtractor
PostPosted: Wed Nov 03, 2010 10:15 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Great, I'm glad it works for you. I was worried the lack of normals was going to cause problems for people but apparently it is ok.

Regarding the warning... I know have a lot to fix :-) If you can create a patch (if you are using TortoiseSVN then you just right click on the folder and choose 'create patch') then I can apply this to my code, otherwise I will just try to fix them when I get a chance.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Improved CubicSurfaceExtractor
PostPosted: Thu Nov 04, 2010 6:43 pm 

Joined: Sun Oct 03, 2010 10:13 pm
Posts: 73
Actually there were only about 7 warnings, I just copied the whole error-log here. The patch file is attached. Just see if it works, I have never used this before :)


Attachments:
warnings.zip [2.88 KiB]
Downloaded 241 times
Top
Offline Profile  
Reply with quote  
 Post subject: Re: Improved CubicSurfaceExtractor
PostPosted: Thu Nov 04, 2010 11:27 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Don't worry, you did great. I've applied the patch with a couple of changes (e.g. uint32_t rather than unsigned int). If you update you might get conflicts (as we've edited the same parts of the code) so just revert your local changes if there is a problem.

Also, I've added new classes 'Density8' and 'Maaterial8'. You should be able to use the Material8 class to get the full 8 bits of material that you wanted. It's not well tested yet though :-)


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Improved CubicSurfaceExtractor
PostPosted: Mon Nov 08, 2010 9:32 am 

Joined: Sun Oct 03, 2010 10:13 pm
Posts: 73
That sounds good! Thanks for the Material8 class, too. Funnily enough I found out that I probably won't be using more than 20 or so materials in my game, as I intend to handle some things differently than Minecraft does. Thanks anyway :)


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Improved CubicSurfaceExtractor
PostPosted: Mon Nov 08, 2010 11:26 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
AndiNo wrote:
...I found out that I probably won't be using more than 20 or so materials in my game, as I intend to handle some things differently than Minecraft does. Thanks anyway :)


Ok, then keep in mind that in the future you could implement your own voxel class (as long as it matches the interface of Material8/Density8/etc) which only uses a smaller number of bits for the material. You could then use the spare bits for any other propertes you might want ('voxel health/strength', for example).


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Improved CubicSurfaceExtractor
PostPosted: Sun Jan 23, 2011 1:16 am 

Joined: Sun Oct 03, 2010 10:13 pm
Posts: 73
Time for bumping ;)
David Williams wrote:
You could then use the spare bits for any other propertes you might want

First: I actually do this now :)

The main reason for bumping is a bit offtopic but relates to the newly calculated normals. I still use the ColouredCubicVoxel shader for my voxels. Everything is working fine, but now I'm trying to implement lighting, too (I guess everyone here already knows that ;) ). I just wanted to ask if anybody knows if I can use the calculated normals for per-pixel lighting. I followed this tutorial: http://www.ogre3d.org/tikiwiki/White+Phong+part+1+-+JaJDoo+Shader+Guide+-+Basics&structure=Cookbook The tutorial uses the normals passed in to the vertex shader, my calculation is obviously done in the fragment shader.
It seems to work with directional light, but testing with a point light was a bit strange. Will investigate further tomorrow.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Improved CubicSurfaceExtractor
PostPosted: Sun Jan 23, 2011 5:49 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
You should be able to use the normals just fine. I did play with point lights in Thermite3D at one time, but I don't have the support in there at the moment so there's no code I can give. If you want to verify/debug your normals, a good trick is to make sure it is normalised and write the x/y/z values into the r/g/b components of the output colour. If you want to see negative components you'll have to do some adjustment.


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 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