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

Need some info about SimpleVolume
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=14&t=516
Page 1 of 1

Author:  Grade [ Mon May 20, 2013 1:54 pm ]
Post subject:  Need some info about SimpleVolume

Hi everyone !
It's me again, I was able to build the PolyVox lib and now I'm trying to have some fun with it.
I followed this tutorial (http://www.volumesoffun.com/polyvox/doc ... rial1.html) but modified the Render part (I use Ogre).

That's it, it creates a huge sphere !
So now, I'm thinking, why not create a gigantic cube instead, so I modified the part with the setVoxelAt function :
Code:
    for (int z = 0; z < volData.getDepth(); z++)
    {
        for (int y = 0; y < volData.getHeight(); y++)
        {
            for (int x = 0; x < volData.getWidth(); x++) {
               volData.setVoxelAt(x, y, z, 255);
            }
        }
    }

I was thinking that it was going to create a cube, but no, I can't see a thing.

So what I think is that I misunderstood this part of the code.
My final goal is to make a Minecraft-like terrain (another one :lol:). Is there a particular technique for that ?

Thanks ! :)

Author:  milliams [ Mon May 20, 2013 2:15 pm ]
Post subject:  Re: Need some info about SimpleVolume

Don't worry, you're on the right track. Firstly, make sure you're read through the documentation for the cubic surface extractor.

Basically, the reason you're not seeing anything rendered is that you're setting every single voxel to be 255. However, PolyVox only generates polygons between voxels when one voxel is above a given threshold and the other is below it. In your case, the voxels inside your volume are above the threshold but there's nothing outside to compare it to and so no polygons are generated. If you change your code to:
Code:
for (int z = 1; z < volData.getDepth()-1; z++)
{
    for (int y = 1; y < volData.getHeight()-1; y++)
    {
        for (int x = 1; x < volData.getWidth()-1; x++) {
           volData.setVoxelAt(x, y, z, 255);
        }
    }
}
then you'll see the cube appear. For a volume which is 64×64×64 you'll get a rendered cube which is 62×62×62.

Hopefully this helps. If not then let us know and we'll try to help further.

Author:  Grade [ Mon May 20, 2013 4:43 pm ]
Post subject:  Re: Need some info about SimpleVolume

Thank you, it's working indeed !
But I have another problem. I'm trying to add some texture (Ogre material) to the cube. For that I created a simple material file :
Code:
material Cube/dirt
 {
    technique
    {
       pass
        {
          texture_unit
          {
            texture dirt.png
          }
       }   
    }
 }

This texture is a simple image that represents dirt (made for one small cube). I applied this material to my ManualObject instance, but (as I kind of expected) the big cube is all brown (the texture is kind of brown), but it's unicolor.
I think that I need to use TexCoord for my ManualObject but I don't know how to use them in order to apply the texture on every single little cube.

If you need more information about my problem just ask.
Thanks !

Author:  David Williams [ Mon May 20, 2013 7:12 pm ]
Post subject:  Re: Need some info about SimpleVolume

This is correct, PolyVox does not provide texture coordinates for the meshes. Have a read of the user manual for some ideas about how to address this: http://www.volumesoffun.com/polyvox/doc ... pping.html

Author:  Grade [ Wed May 22, 2013 11:56 am ]
Post subject:  Re: Need some info about SimpleVolume

Hi and thank you for the link, I understood the principle with the normals.
I might get off the subject a little bit, but I have a question (that concerns mostly Ogre).

I was able to print texture on my cube, but only one different texture (because my whole ManualObject has only one material).
So I had many ideas including putting all these textures in the same file and then choose the coordinates I want. But the result of this wasn't great because there were horrible white lines on the borders of each cube.

So I searched the Internet about this, and saw threads talking about Texture Atlas.
What exactly is Texture Atlas ? Is this the solution for the best rendering ? And (maybe I don't quite understand but), I saw that it requires a Shader file. So how can I decide which texture I use on X bloc if it's not in the source code ? (Sorry I'm probably not clear enough :?)

Thanks !

EDIT: I searched again and... well I'm not sure Texture Atlas is the solution. I've haven't seen much documentation about it and... Well I saw somewhere that you guys aren't using it so... :P.
Will I still be able to do a Minecraft-like terrain without Texture Atlas ? Thanks :)

Author:  David Williams [ Thu May 23, 2013 8:02 am ]
Post subject:  Re: Need some info about SimpleVolume

In order to use multiple materials you can make use of the material identifier property which is attached to each vertex. The value of this material identifier is copied from the voxel data, so for example if a particular voxel has a material identifier of '17' then this value will also be attached to the vertices corresponding to that voxel. So you need to:

  • Set the desired voxel values
  • Generate your mesh
  • Copy it to the GPU, including the material identifiers. You may want to pass these using one of the texture coordinate streams.
  • Attach a single Ogre material to the mesh, but set up multiple texture units.
  • In your shader code, retrieve the value of the material identifier and use it to decide which texture to sample.


This is the basic approach which uses multiple texture units, but this limits the number of textures you can have. As you have noted, another approach is to build a texture atlas. This is more complex and also causes problems with seams between textures (unless you use point filtering, which is what Minecraft does), but it does let you have many more textures. The 'best' approach is textures arrays but these are only available from DirectX 10 or OpenGL 3 and up. There is more detail here: http://www.volumesoffun.com/polyvox/doc ... f-textures

Note that you are going to need good shader programming skills to get any of these approaches working.

Personally, we're not using any of these approaches with cubic terain (because the cubes are a single colour) and we're using the multiple texture unit approach on smooth terrain because it's easiest.

Author:  Grade [ Thu May 23, 2013 7:18 pm ]
Post subject:  Re: Need some info about SimpleVolume

Thank you so much for your reply !
I read all the possibilities, and finally I decided to disable the Texture Filtering and it works !
And good news : I've been trying to disable this ugly smooth in the past but the only solution I had was to make the texture bigger directly in the texture file (not great).

So it's very good news and it solves all my problem, thanks !
This community is very welcoming, I'll definitively stay (to help people... and to ask for help :lol:)
Well, I think that my futur problems will be Ogre related so I'll probably post in Ogre forums.

Thanks again !

Author:  Grade [ Sat May 25, 2013 2:54 pm ]
Post subject:  Re: Need some info about SimpleVolume

Okay it's me again (I spoke too fast :lol:)
I still have one question, it's not directly about the library (or maybe it is), but I was wondering if you could help me.

Here's what I want to do :
I would like to have a three-dimensional array that contains the terrain. By that, I mean it would contain numbers that represent cubes (0=nothing, 1=dirt, 2=sand etc...)
But that's not my problem, my real problem is how to use it when I must define textures.

Here's the code that draws the ManualObject mesh :
Code:
    for(int index = beginIndex; index < endIndex; ++index) {
            const PolyVox::PositionMaterialNormal& vertex = vecVertices[vecIndices[index]];
            const PolyVox::Vector3DFloat& v3dVertexPos = vertex.getPosition();
            const PolyVox::Vector3DFloat& v3dVertexNormal = vertex.getNormal();
            const PolyVox::Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<PolyVox::Vector3DFloat>(mesh.m_Region.getLowerCorner());
            ogreMesh->position(v3dFinalVertexPos.getX(), v3dFinalVertexPos.getY(), v3dFinalVertexPos.getZ());
            ogreMesh->normal(v3dVertexNormal.getX(), v3dVertexNormal.getY(), v3dVertexNormal.getZ());
    }

Now, this for is listing every Vertex I have to draw but I would like to know, for each vertex, from what cube they belong (Like if I'm drawing the cube in (0,0,0) or in (4,3,5)), so I could know what texture I have to print on them.

I don't know if you understand what I want to do (my sentences are a bit messy), but I'd be really grateful.

Thanks :)

Author:  David Williams [ Sat May 25, 2013 10:59 pm ]
Post subject:  Re: Need some info about SimpleVolume

Actually you can get this information quite easily but calling getMaterial() on each of your vertices. This returns a float (should be fixed - watch out for rounding issues) corresponding to the material identifier you set on the voxel.

You need to pass this information to your shader, and in your shader you can use it to select the appropriate texture to apply. It's up to you how you pass this to the GPU but a simple approach is to attach it as a texture coordinate of the vertices you are uploading (of course it's not a texture coordinate, but it's quite common to use texture coordinate streams for general purpose data such as this).

So something like:

Code:
ogreMesh->texCoord(vertex.getMaterial(), 0.0f);


Would place the material identifier in the 'u' coordinate. Let me know it that's not clear. Oh, and look at this part of the manual for more information: http://www.volumesoffun.com/polyvox/doc ... identifier

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