Volumes Of Fun
http://www.volumesoffun.com/phpBB3/

How many materials can a voxel have?
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=14&t=264
Page 1 of 2

Author:  DJDD [ Tue Sep 20, 2011 10:01 am ]
Post subject:  How many materials can a voxel have?

Hi,

I've been playing around with PolyVox quite a bit lately and I'm really loving it. I've got my game world in there and its successfully extracting surfaces for me.
I'm now thinking about how to make it look pretty and I've grown a bit worried:
1. How many materials can a voxel have?
2. I'm being told that if I generate a single mesh, like you do from SurfaceExtractor, then you're only limited to a fairly small number of textures or one big texture 'atlas'. Is this true?

I would like to have 100s of textures on my terrain. Will this not be possible?

I'd like my game to look like a more modern version of Dungeon Keeper 2:
http://images.google.com/search?tbm=isc ... 90l3-3l3l0

Author:  floAr [ Tue Sep 20, 2011 11:46 am ]
Post subject:  Re: How many materials can a voxel have?

As far as I know a Voxel can have one material.

What you can do beside of this limitation is increasing the size of a voxel 8if you reserver 7 bit for material you can have 128 different materials) and then use the extracted number in a shader or something like this to map different materials over the voxel.

Author:  David Williams [ Tue Sep 20, 2011 9:46 pm ]
Post subject:  Re: How many materials can a voxel have?

Each voxel has a single material chosen from a number of available materials. The total number of available materials depends on how many bits you use per voxel. For example, if you use Material8 for your voxel type then you will have 256 available materials, but if you use Material16 then you will have 65536.

Which surface extractor are you using? The cubic one? Your screenshot link doesn't seem to work by the way...

Author:  DJDD [ Wed Sep 21, 2011 4:59 am ]
Post subject:  Re: How many materials can a voxel have?

floAr wrote:
As far as I know a Voxel can have one material.

What you can do beside of this limitation is increasing the size of a voxel 8if you reserver 7 bit for material you can have 128 different materials) and then use the extracted number in a shader or something like this to map different materials over the voxel.

I've also been looking for such a shader but I've found no such shader that can paint textures in a half decent way with features such as blending based on normal maps or blend maps, etc. Any ideas?

David Williams wrote:
Each voxel has a single material chosen from a number of available materials. The total number of available materials depends on how many bits you use per voxel. For example, if you use Material8 for your voxel type then you will have 256 available materials, but if you use Material16 then you will have 65536.

Which surface extractor are you using? The cubic one? Your screenshot link doesn't seem to work by the way...

Ok great so if I use Material16 then I'm all good in terms of what the voxels can store. But how do I then paint the extracted volume? I have found so little in terms of decent shaders to do such a thing.

I've not been using the cubic extractor no, and I've fixed my link to just include a google images search.

Author:  ker [ Wed Sep 21, 2011 10:24 am ]
Post subject:  Re: How many materials can a voxel have?

DJDD wrote:
I've also been looking for such a shader but I've found no such shader that can paint textures in a half decent way with features such as blending based on normal maps or blend maps, etc. Any ideas?

DJDD wrote:
But how do I then paint the extracted volume? I have found so little in terms of decent shaders to do such a thing.


That's because everyone has very specific needs and there just isn't a single shader that's good for everyone.
If you don't know how to code a shader yet, it's probably easier if you take a tutorial, create a simple shader that just works (even if it looks horrible) and then ask for help improving it.

Author:  DJDD [ Wed Sep 21, 2011 11:32 am ]
Post subject:  Re: How many materials can a voxel have?

Understood. But surely there are common parts to it?
I mean, every GLSL shader will contain the same code to blend multiple textures with associated normal/bump/spec maps. The only real difference should be the blend type.
I don't even really have a starting point right now. :(

Author:  ker [ Wed Sep 21, 2011 12:47 pm ]
Post subject:  Re: How many materials can a voxel have?

depends... all triplanar shaders are similar. all that use texatlas are similar. but there are many ways to render the surface.
I got texture arrays and some kind of *-planar shader.

well a simple starting point is this:

vertex shader, needs a position and a normal
Code:
void main() {
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    gl_TexCoord[0] = vec4(normalize( gl_Normal), 0.0);
    gl_TexCoord[1] = vec4(gl_Vertex);
}


fragment shader, can only use one texture, and there's no texatlas, and the texture is streched along the y axis
Code:
uniform sampler2D tex0;

void main() {
   vec4 col;
    vec4 light;
    float ambient = 0.400000;
   vec4 lightDirection;
   float ldn;
   vec3 coord = gl_TexCoord[1].xyz/16;
   vec2 tex;
   tex.x = coord.x;
   tex.y = coord.z;

   col = texture2D( tex0, tex);

   lightDirection.x = 1.0;
   lightDirection.y = -0.7;
   lightDirection.z = 1.0;
   lightDirection.w = 0.0;
    light = -normalize( lightDirection );
    ldn = max( 0.000000, dot( light, gl_TexCoord[0]));
    gl_FragData[0] = vec4( col * (ambient + ldn*(1-ambient)) );
}


yes the stretching is ugly, but now you can choose what you want to do :)

look in the general discussions forums for triplanar shaders (they're hlsl thou)

what graphics engine are you using?

Author:  David Williams [ Wed Sep 21, 2011 9:03 pm ]
Post subject:  Re: How many materials can a voxel have?

DJDD wrote:
Understood. But surely there are common parts to it?
I mean, every GLSL shader will contain the same code to blend multiple textures with associated normal/bump/spec maps. The only real difference should be the blend type.
I don't even really have a starting point right now. :(


It is actually suprising complicated, HLSL vs GLSL vs CG, forward vs deferred rendering, the vertex format used as input... these things all make a difference. Plus people might not even want triplanar texturing - for example in my picture of the earth the surface is done by sampling a cube map, the rock is triplarar textuing, and the lava is procedural noise.

I can see it would be nice to provide some more shader examples, but really PolyVox works well because it has a well defined scope. If it tries to do too much then some flexibility can be lost.

That said, there are shader examples around. There is this one on the Ogre forums, and some useful snippets in GPU Gems 3. But really start simple, and I'm sure people here can help you work up to something more complex.

Author:  DJDD [ Thu Sep 22, 2011 12:19 pm ]
Post subject:  Re: How many materials can a voxel have?

I'll be honest, I am oh so very confused. And I think you're correct to tell me to take a step back and get the basics going, so let me try to break it all down for myself:

1. I generate a voxel volume using Material16 and assign my various material types to the volume.
2. I ask for a region of the volume and perform a cubic extraction on it to get the polygons and normals needed for tri-planar texturing.
Knowledge Gap 1: I've got this output of verts and indicies and normal values, and from that I can generate a single mesh in my renderer (Leadwerks). Whats next? Do I need to run another pass over the created mesh with the custom shader to look at each 'vertex color' to do a texture blend? I'm not 100% sure at what point the shader comes in, and whether it has to render the entire mesh in one go. Because I'm reading that shaders do have a limit of how many textures it can work with, but is that at a vert level or a 'mesh' level?

I'm actively reading up on this now, so please bear with me. :P

Author:  ker [ Thu Sep 22, 2011 5:26 pm ]
Post subject:  Re: How many materials can a voxel have?

these vertices and indices make up one mesh. You have a limit of Textures for this mesh.
Each vertex contains a material.
You pass these vertices and indices to your rendering system. (you need to figure out how to do this with leadwerks).
You will also have to bind a vertex and a pixel shader to this mesh (also a leadwerks thing you need to find out).

when you got this set up, the graphics card will automatically call the vertex and pixel shaders, which will then position and color your mesh.

the limit to the textures is only in your graphics card. But there are many ways around that limit like texture arrays or texture atlanten

Page 1 of 2 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/