It is currently Sat Aug 22, 2020 3:36 am


All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Texturing and Voxel materials
PostPosted: Fri Dec 27, 2013 6:22 pm 

Joined: Sat Dec 21, 2013 3:41 pm
Posts: 10
Firstly, how did you intend on storing data in voxels?

What I wanted to do, is simply set voxel value to greater than zero and use it as ID for voxel type.
It would work with cubic worlds, but I have found that in order for marching cubes extractor to see voxel as full, value needs to be set as greater than half of size of selected datatype.

Why is it so? I suppose I could still use greater than half values as ID's, but then I think low pass filter would overwrite these values as I am guessing it is using them as a way of storing density/its data (?)

And how does it look with non-numeric datatypes? If I use my own class as template parameter for volume, how will surface extractor know wheres the half?

I think I'm missing something here... :lol:

Other thing, how would you go about texturing such terrain? I've implemented simple triplanar mapping shader, but am not sure how to go about actually using voxel data to texture it.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Texturing and Voxel materials
PostPosted: Sat Dec 28, 2013 9:18 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Neomex wrote:
Firstly, how did you intend on storing data in voxels?


The volume classes are templatized so you can use your own classes/structures as voxel types. At least, this is if you are working with C++. If you are using the bindings then you have to use one of the predefined voxel types (or modify the bindings to define your own).

Neomex wrote:
What I wanted to do, is simply set voxel value to greater than zero and use it as ID for voxel type.
It would work with cubic worlds, but I have found that in order for marching cubes extractor to see voxel as full, value needs to be set as greater than half of size of selected datatype.


Indeed, the marching cubes algorithm works on continuous density fields, not simply 'on' or 'off'. So the density field controls the shape of the mesh. You can also choose to store a separate material identifier with each voxel if you wish.

Neomex wrote:
Why is it so? I suppose I could still use greater than half values as ID's, but then I think low pass filter would overwrite these values as I am guessing it is using them as a way of storing density/its data (?)


Indeed, you should probably keep your density and material identifier separate within the voxel. See the MaterialDensityPair class as an example.

Neomex wrote:
And how does it look with non-numeric datatypes? If I use my own class as template parameter for volume, how will surface extractor know wheres the half?


Have a look at the DefaultMarchingCubesController class. I think the comments should help but ask if it's still not clear.

Neomex wrote:
Other thing, how would you go about texturing such terrain? I've implemented simple triplanar mapping shader, but am not sure how to go about actually using voxel data to texture it.


There's some useful information in the manual about this, though there's no single solution. It's a good starting point though: http://www.volumesoffun.com/polyvox/doc ... pping.html


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Texturing and Voxel materials
PostPosted: Mon Dec 30, 2013 12:18 am 

Joined: Sat Dec 21, 2013 3:41 pm
Posts: 10
Quote:
Both the CubicSurfaceExtractor and the MarchingCubesSurfacExtractor understand the concept of a material being associated with a voxel, and they will take this into account when generating a mesh. Specifically, they will both copy the material identifier into the vertex data of the output mesh, so you can pass it through to your shaders and use it to affect the way the surface is rendered.


I'm using MaterialDensityPair88 as voxel type and there I have 8bit integer value representing 'id' of material. Why does getMaterial() return float and how to interpret this?

And what should I pass to shader? Should I loop through vertices in mesh, get material and pass it? Wouldn't then I need some huge array in shader?

In manual's pseudocode you use single value for materialId, I can't grasp my head around how to set this variable for every vertex.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Texturing and Voxel materials
PostPosted: Mon Dec 30, 2013 9:20 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Neomex wrote:
I'm using MaterialDensityPair88 as voxel type and there I have 8bit integer value representing 'id' of material. Why does getMaterial() return float and how to interpret this?


Older graphics hardware only let you pass floats, and so the surface extractor automatically casts the integer identifier to a float value (always 0.0, 1.0, 2.0, etc). Actually this may not have been a good design but it works. The version of PolyVox used for Cubiquity has been modified so that the identifier type in the vertex data is always the same as the voxel type (i.e. the vertex class is templatised). This has not yet been merged back into the main PolyVox branch but you don't really need it.

Neomex wrote:
And what should I pass to shader? Should I loop through vertices in mesh, get material and pass it? Wouldn't then I need some huge array in shader?

In manual's pseudocode you use single value for materialId, I can't grasp my head around how to set this variable for every vertex.


You should upload all the vertices to the GPU in some kind of vertex buffer. For each vertex you should upload the position (xyz), normal (xyz), and material identifier (so a total of seven floats per vertex). You probably want to interpolate the identifier across the rendered triangles and you can then read the identifier from the fragment shader to decide what color/texture/etc to use.

Do start simple though, and get it working with just a single material first.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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