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


All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Understanding Terrain Generation with PolyVox
PostPosted: Sun Oct 09, 2016 10:29 pm 

Joined: Sun Oct 09, 2016 9:37 pm
Posts: 4
Greetings,

Lately I am experimenting with procedural terrain generation using Accidental Noise Library (ANL) to generate Voxels and later on to construct a mesh of these voxels. I would like to have a nice smooth terrain and to archive this I am using the marchingCubeExtractor from PolyVox. But my mesh is not really smooth like in other examples I could find. Here is an example of the code I use:

Image

I believe something with my density values is not correct. Despite the research of a couple of days I could not find the right solution for this problem. Thats why I decided to ask directly here and I am hoping to understand all this a little bit better.

I am using Unreal Engine for the render process. I know that there is a plugin for Unreal Engine but at this point I would like to archive a proper rendering without any plugin, only with the core libraries if possible. The code is pretty much the same Brandon Garvin is using at his nice tutorial here: https://garvinized.com/posts/2016/voxel ... ing-setup/

First I am generating a noise...

Code:
    // Commonly used constants
    auto Zero           = NoiseKernel.constant(0);
    auto One            = NoiseKernel.constant(1);
    auto two55          = NoiseKernel.constant(255);
    auto zScale         = NoiseKernel.constant(1.1);
    auto VerticalHeight = NoiseKernel.constant(TerrainHeight);
    auto FallOff        = NoiseKernel.constant(2.0 / TerrainHeight);
   
    // Create a gradient on the vertical axis to form our ground plane.
    auto VerticalGradient = NoiseKernel.divide(NoiseKernel.clamp(NoiseKernel.subtract(VerticalHeight, NoiseKernel.z()), Zero, VerticalHeight), VerticalHeight);
   
    // Turn our gradient into two solids that represent the ground and air. This prevents floating terrain from forming later.
    auto VerticalSelect = NoiseKernel.select(Zero, two55, VerticalGradient, NoiseKernel.constant(0.5), Zero);
   
    // This is the actual noise generator we'll be using.
    // In this case I've gone with a simple fBm generator, which will create terrain that looks like smooth, rolling hills.
    auto TerrainFractal = NoiseKernel.simplefBm(BasisTypes::BASIS_SIMPLEX, InterpolationTypes::INTERP_LINEAR, NoiseOctaves, NoiseFrequency, Seed);
   
    // Scale and offset the generated noise value.
    // Scaling the noise makes the features bigger or smaller, and offsetting it will move the terrain up and down.
    auto TerrainScale = NoiseKernel.scaleOffset(TerrainFractal, NoiseScale, NoiseOffset);
   
    // Setting the Z scale of the fractal to 0 will effectively turn the fractal into a heightmap.
    auto TerrainZScale = NoiseKernel.scaleZ(TerrainScale, Zero);
   
    // Finally, apply the Z offset we just calculated from the fractal to our ground plane.
    auto PerturbGradient = NoiseKernel.translateZ(VerticalSelect, TerrainZScale);
   
    CNoiseExecutor TerrainExecutor(NoiseKernel);


then I am filling the voxels with that information like this:

Code:
    // Now that we have our noise setup, let's loop over our chunk and apply it.
    for (int x = region.getLowerX(); x <= region.getUpperX(); x++)
    {
        for (int y = region.getLowerY(); y <= region.getUpperY(); y++)
        {
            for (int z = region.getLowerZ(); z <= region.getUpperZ(); z++)
            {
                // Evaluate the noise
                auto EvaluatedNoise = TerrainExecutor.evaluateScalar(x, y, z, PerturbGradient);
                MaterialDensityPair44 Voxel;

                uint8_t densityVal = static_cast<uint8_t>(EvaluatedNoise);
                Voxel.setDensity(densityVal);
               
                bool bSolid = EvaluatedNoise > 127;
                Voxel.setMaterial(bSolid ? 1 : 0);
               
                // Voxel position within a chunk always start from zero. So if a chunk represents region (4, 8, 12) to (11, 19, 15)
                // then the valid chunk voxels are from (0, 0, 0) to (7, 11, 3). Hence we subtract the lower corner position of the
                // region from the volume space position in order to get the chunk space position.
                Chunk->setVoxel(x - region.getLowerX(), y - region.getLowerY(), z - region.getLowerZ(), Voxel);
            }
        }
    }


Finally I am extracting the mesh from PolyVox:

Code:
    // Extract the voxel mesh from PolyVox
    PolyVox::Region ToExtract(Vector3DInt32(0, 0, 0), Vector3DInt32(TerrainSize.Component(0), TerrainSize.Component(1), TerrainHeight-1));
   
    //auto ExtractedMesh = extractCubicMesh(VoxelVolume.Get(), ToExtract);
    auto ExtractedMesh = extractMarchingCubesMesh(VoxelVolume.Get(), ToExtract);
    auto DecodedMesh   = decodeMesh(ExtractedMesh);


the last step is to fill the vertex information in my final mesh of Unreal Engine for rendering:

Code:
    // Loop over all of the triangle vertex indices
    for (uint32 i = 0; i < DecodedMesh.getNoOfIndices() - 2; i+=3)
    {
        // We need to add the vertices of each triangle in reverse or the mesh will be upside down
        auto Index = DecodedMesh.getIndex(i + 2);
        auto Vertex2 = DecodedMesh.getVertex(Index);
        Indices.Add(Vertices.Add(FPolyVoxVector(Vertex2.position) * 100.f));
       
        Index = DecodedMesh.getIndex(i + 1);
        auto Vertex1 = DecodedMesh.getVertex(Index);
        Indices.Add(Vertices.Add(FPolyVoxVector(Vertex1.position) * 100.f));
       
        Index = DecodedMesh.getIndex(i);
        auto Vertex0 = DecodedMesh.getVertex(Index);
        Indices.Add(Vertices.Add(FPolyVoxVector(Vertex0.position) * 100.f));
       
        // Calculate the tangents of our triangle
        const FVector Edge01 = FPolyVoxVector(Vertex1.position - Vertex0.position);
        const FVector Edge02 = FPolyVoxVector(Vertex2.position - Vertex0.position);
       
        const FVector TangentX = Edge01.GetSafeNormal();
        FVector TangentZ = (Edge01 ^ Edge02).GetSafeNormal();
       
        for (int32 j = 0; j < 3; j++)
        {
            Tangents.Add(FProcMeshTangent(TangentX, false));
            Normals.Add(TangentZ);
        }
    }


I believe I am missing something or I failed to understand a core concept of all this. I would appreciate if someone can help me with this forward. Thanks in advance!

Sincerely,
Sav


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Understanding Terrain Generation with PolyVox
PostPosted: Mon Oct 10, 2016 5:52 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
It looks like the problem is indeed the values you pass to setDensity(), and that you are only ever setting the maximum value or the minimum/zero. For smooth terrain the densities need to have a continuous range. But I don't see quite how the error is occurring:

Code:
// Evaluate the noise
auto EvaluatedNoise = TerrainExecutor.evaluateScalar(x, y, z, PerturbGradient);
MaterialDensityPair44 Voxel;

uint8_t densityVal = static_cast<uint8_t>(EvaluatedNoise);
Voxel.setDensity(densityVal);


What is the type and the range of values in 'EvaluatedNoise' (before casting)?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Understanding Terrain Generation with PolyVox
PostPosted: Tue Oct 11, 2016 4:42 pm 

Joined: Fri Sep 30, 2016 3:30 am
Posts: 14
you need to have a smooth transition between air and solid. Go look at your vertical select function. you have the Falloff parameter set to zero, which is going to give you an abrupt transition. It needs to be set to a small number, somewhere near falloff = 2 / (terrainHeight).

so you have something like this:

auto VerticalSelect = NoiseKernel.select(Zero, twoHundred55, VerticalGradient, NoiseKernel.constant(0.5), falloff);


If you still get stuck, let me know. I'm basically working on the same project. If you want to work together I would be happy to. I'm doing it for a hobby project.

Here's a video showing where I'm at right now:
https://youtu.be/hhwmsSBDI3Y


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Understanding Terrain Generation with PolyVox
PostPosted: Wed Oct 12, 2016 1:18 am 

Joined: Sun Oct 09, 2016 9:37 pm
Posts: 4
Hey!

Thank you both for the replies and help!

@David Williams
I checked the EvaluatedNoise values again and as you pointed out the only two values were 0 and 255. I continued with mgumleys suggestion at that point!

@mgumley
With the FallOff parameter the density values which I get from the EvaluatedNoise changes. It seems like a proper distribution by means of the values, but the rendered terrain looks quite interesting:

Image

Your project is looking quite nicely, mgumley! I would surely be glad to exchange some experience and I have no problem to help if I can help! At that point I just want to evaluate the suitability of procedural terrain generation with voxels for RTS projects.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Understanding Terrain Generation with PolyVox
PostPosted: Wed Oct 12, 2016 3:26 am 

Joined: Fri Sep 30, 2016 3:30 am
Posts: 14
it's hard to tell what's going on by looking at that image. I'd be happy to post my code once I get a few more bugs fixed. In the mean while, you should try building a smaller terrain at first, like 4x4x4, and look at the voxel values manually in the debugger.

You or anyone can message me on Skype if you want to talk about PolyVox projects. My contact is mgumley, my name's Max.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Understanding Terrain Generation with PolyVox
PostPosted: Thu Oct 13, 2016 7:28 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Savadiv wrote:
I checked the EvaluatedNoise values again and as you pointed out the only two values were 0 and 255.


Right, so that's the core of your problem. Unfortunately I'm not familiar with ANL, so you'll have to spend some time working out how to get continuous values out of it (or more likely it is giving you continuous values already, and the casting, etc it causing problems).

mgumley wrote:
...you should try building a smaller terrain at first, like 4x4x4, and look at the voxel values manually in the debugger...


Yes, this is what I would suggest. Better still, print out a single column of voxels so you can easily see the transition from low to high values.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Understanding Terrain Generation with PolyVox
PostPosted: Thu Oct 13, 2016 10:11 pm 

Joined: Sun Oct 09, 2016 9:37 pm
Posts: 4
Okay. Continuing to debug all this. I am using a RawVolume of the size 4x4x4 to simplify all the process. It's of course far easier to debug without any pager. My values seem to be increasing from 0 to 4 on the Z-Coordinate. But I can not say that it's very continuous and the visualisation is strange too. Here are the values:

Quote:
LogTemp:Warning: Density (0, 0, 0): 255.000000
LogTemp:Warning: Density (0, 0, 1): 228.603516
LogTemp:Warning: Density (0, 0, 2): 127.500000
LogTemp:Warning: Density (0, 0, 3): 26.396484
LogTemp:Warning: Density (0, 1, 0): 254.982368
LogTemp:Warning: Density (0, 1, 1): 223.167042
LogTemp:Warning: Density (0, 1, 2): 118.311549
LogTemp:Warning: Density (0, 1, 3): 21.490275
LogTemp:Warning: Density (0, 2, 0): 254.872811
LogTemp:Warning: Density (0, 2, 1): 217.524628
LogTemp:Warning: Density (0, 2, 2): 109.629525
LogTemp:Warning: Density (0, 2, 3): 17.328909
LogTemp:Warning: Density (0, 3, 0): 254.612730
LogTemp:Warning: Density (0, 3, 1): 211.757708
LogTemp:Warning: Density (0, 3, 2): 101.476830
LogTemp:Warning: Density (0, 3, 3): 13.833944
LogTemp:Warning: Density (0, 4, 0): 254.171348
LogTemp:Warning: Density (0, 4, 1): 205.939618
LogTemp:Warning: Density (0, 4, 2): 93.863613
LogTemp:Warning: Density (0, 4, 3): 10.927994
LogTemp:Warning: Density (1, 0, 0): 255.000000
LogTemp:Warning: Density (1, 0, 1): 236.145428
LogTemp:Warning: Density (1, 0, 2): 142.075412
LogTemp:Warning: Density (1, 0, 3): 35.274691
LogTemp:Warning: Density (1, 1, 0): 255.000000
LogTemp:Warning: Density (1, 1, 1): 231.660473
LogTemp:Warning: Density (1, 1, 2): 133.108977
LogTemp:Warning: Density (1, 1, 3): 29.650914
LogTemp:Warning: Density (1, 2, 0): 254.999349
LogTemp:Warning: Density (1, 2, 1): 226.862604
LogTemp:Warning: Density (1, 2, 2): 124.456884
LogTemp:Warning: Density (1, 2, 3): 24.713685
LogTemp:Warning: Density (1, 3, 0): 254.967871
LogTemp:Warning: Density (1, 3, 1): 221.877639
LogTemp:Warning: Density (1, 3, 2): 116.258058
LogTemp:Warning: Density (1, 3, 3): 20.464761
LogTemp:Warning: Density (1, 4, 0): 254.848273
LogTemp:Warning: Density (1, 4, 1): 216.776366
LogTemp:Warning: Density (1, 4, 2): 108.533645
LogTemp:Warning: Density (1, 4, 3): 16.835973
LogTemp:Warning: Density (2, 0, 0): 255.000000
LogTemp:Warning: Density (2, 0, 1): 242.221360
LogTemp:Warning: Density (2, 0, 2): 156.185245
LogTemp:Warning: Density (2, 0, 3): 45.227849
LogTemp:Warning: Density (2, 1, 0): 255.000000
LogTemp:Warning: Density (2, 1, 1): 238.704703
LogTemp:Warning: Density (2, 1, 2): 147.687232
LogTemp:Warning: Density (2, 1, 3): 39.066965
LogTemp:Warning: Density (2, 2, 0): 255.000000
LogTemp:Warning: Density (2, 2, 1): 234.802147
LogTemp:Warning: Density (2, 2, 2): 139.284994
LogTemp:Warning: Density (2, 2, 3): 33.467975
LogTemp:Warning: Density (2, 3, 0): 255.000000
LogTemp:Warning: Density (2, 3, 1): 230.625225
LogTemp:Warning: Density (2, 3, 2): 131.168917
LogTemp:Warning: Density (2, 3, 3): 28.502667
LogTemp:Warning: Density (2, 4, 0): 254.998477
LogTemp:Warning: Density (2, 4, 1): 226.277826
LogTemp:Warning: Density (2, 4, 2): 123.457051
LogTemp:Warning: Density (2, 4, 3): 24.173374
LogTemp:Warning: Density (3, 0, 0): 255.000000
LogTemp:Warning: Density (3, 0, 1): 246.912329
LogTemp:Warning: Density (3, 0, 2): 169.645837
LogTemp:Warning: Density (3, 0, 3): 56.092116
LogTemp:Warning: Density (3, 1, 0): 255.000000
LogTemp:Warning: Density (3, 1, 1): 244.311097
LogTemp:Warning: Density (3, 1, 2): 161.805959
LogTemp:Warning: Density (3, 1, 3): 49.592944
LogTemp:Warning: Density (3, 2, 0): 255.000000
LogTemp:Warning: Density (3, 2, 1): 241.267654
LogTemp:Warning: Density (3, 2, 2): 153.774901
LogTemp:Warning: Density (3, 2, 3): 43.427846
LogTemp:Warning: Density (3, 3, 0): 255.000000
LogTemp:Warning: Density (3, 3, 1): 237.943809
LogTemp:Warning: Density (3, 3, 2): 145.974791
LogTemp:Warning: Density (3, 3, 3): 37.886979
LogTemp:Warning: Density (3, 4, 0): 255.000000
LogTemp:Warning: Density (3, 4, 1): 234.364302
LogTemp:Warning: Density (3, 4, 2): 138.396057
LogTemp:Warning: Density (3, 4, 3): 32.903241
LogTemp:Warning: Density (4, 0, 0): 255.000000
LogTemp:Warning: Density (4, 0, 1): 250.338864
LogTemp:Warning: Density (4, 0, 2): 182.302241
LogTemp:Warning: Density (4, 0, 3): 67.689908
LogTemp:Warning: Density (4, 1, 0): 255.000000
LogTemp:Warning: Density (4, 1, 1): 248.555007
LogTemp:Warning: Density (4, 1, 2): 175.277017
LogTemp:Warning: Density (4, 1, 3): 61.074815
LogTemp:Warning: Density (4, 2, 0): 255.000000
LogTemp:Warning: Density (4, 2, 1): 246.303086
LogTemp:Warning: Density (4, 2, 2): 167.707133
LogTemp:Warning: Density (4, 2, 3): 54.438783
LogTemp:Warning: Density (4, 3, 0): 255.000000
LogTemp:Warning: Density (4, 3, 1): 243.778024
LogTemp:Warning: Density (4, 3, 2): 160.323126
LogTemp:Warning: Density (4, 3, 3): 48.418159
LogTemp:Warning: Density (4, 4, 0): 255.000000
LogTemp:Warning: Density (4, 4, 1): 241.000863
LogTemp:Warning: Density (4, 4, 2): 153.115848
LogTemp:Warning: Density (4, 4, 3): 42.943018


Image

EDIT:

Still trying all kinds of stuff. To simplify the problem I tried the sphere in volume example. Even here, with strictly calculated density values I am getting not a round sphere. Instead... some kind of art. Here you go:

Image

Maybe the problem is how the mesh is created?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Understanding Terrain Generation with PolyVox
PostPosted: Sun Oct 16, 2016 11:26 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Savadiv wrote:
To simplify the problem I tried the sphere in volume example.


Yes, this is smart. Let's go a step further and really validate your volume data and also the generated vertex positions. The code below generates a much smaller volume and sphere and prints out the data:

Code:
// Create an empty volume and then place a sphere in it
RawVolume<uint8_t> volData(PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(7, 7, 7)));
createSphereInVolume(volData, 2);

for (int x = 0; x <= 7; x++)
{
   std::cout << "Density = " << int(volData.getVoxel(x, 3, 3)) << std::endl;
}
std::cout << std::endl;

// Extract the surface for the specified region of the volume.
auto mesh = extractMarchingCubesMesh(&volData, volData.getEnclosingRegion());

// The surface extractor outputs the mesh in an efficient compressed format which is not directly suitable for rendering. The easiest approach is to
// decode this on the CPU as shown below, though more advanced applications can upload the compressed mesh to the GPU and decompress in shader code.
auto decodedMesh = decodeMesh(mesh);

std::cout << "Vertices" << std::endl;
std::cout << "========" << std::endl;
for (int v = 0; v < decodedMesh.getNoOfVertices(); v++)
{
   std::cout << "Vertex " << v << " = " << decodedMesh.getVertex(v).position << std::endl;
}
std::cout << std::endl;

std::cout << "Indices" << std::endl;
std::cout << "=======" << std::endl;
for (int i = 0; i < decodedMesh.getNoOfIndices(); i++)
{
   std::cout << "Index " << i << " = " << decodedMesh.getIndex(i) << std::endl;
}
std::cout << std::endl;


Note that I print out a single column of density values through the centre of the sphere, which I expect to start low, go high, and then go low again (as I leave the sphere). I get the following output:
Code:
Density = 0
Density = 0
Density = 70
Density = 161
Density = 202
Density = 161
Density = 70
Density = 0

Vertices
========
Vertex 0 = (4,4,2)
Vertex 1 = (4,4,2)
Vertex 2 = (4,4,2)
Vertex 3 = (4,4,2)
Vertex 4 = (4,4,2)
Vertex 5 = (2.625,3,3)
Vertex 6 = (3,2.625,3)
Vertex 7 = (3,3,2.625)
Vertex 8 = (4,2.28516,3)
Vertex 9 = (4,3,2.28516)
Vertex 10 = (5,2.625,3)
Vertex 11 = (5,3,2.625)
Vertex 12 = (5.37109,3,3)
Vertex 13 = (2.28516,4,3)
Vertex 14 = (3,4,2.28516)
Vertex 15 = (5,4,2.28516)
Vertex 16 = (5.71094,4,3)
Vertex 17 = (2.625,5,3)
Vertex 18 = (3,5,2.625)
Vertex 19 = (4,5,2.28516)
Vertex 20 = (5,5,2.625)
Vertex 21 = (5.37109,5,3)
Vertex 22 = (3,5.37109,3)
Vertex 23 = (4,5.71094,3)
Vertex 24 = (5,5.37109,3)
Vertex 25 = (4,2,4)
Vertex 26 = (4,2,4)
Vertex 27 = (4,2,4)
Vertex 28 = (4,2,4)
Vertex 29 = (2.28516,3,4)
Vertex 30 = (3,2.28516,4)
Vertex 31 = (5,2.28516,4)
Vertex 32 = (5.71094,3,4)
Vertex 33 = (2,4,4)
Vertex 34 = (2,4,4)
Vertex 35 = (2,4,4)
Vertex 36 = (6,4,4)
Vertex 37 = (6,4,4)
Vertex 38 = (6,4,4)
Vertex 39 = (2,4,4)
Vertex 40 = (2.28516,5,4)
Vertex 41 = (5.71094,5,4)
Vertex 42 = (6,4,4)
Vertex 43 = (3,5.71094,4)
Vertex 44 = (4,6,4)
Vertex 45 = (4,6,4)
Vertex 46 = (4,6,4)
Vertex 47 = (5,5.71094,4)
Vertex 48 = (4,6,4)
Vertex 49 = (4,2,4)
Vertex 50 = (2.625,3,5)
Vertex 51 = (3,2.625,5)
Vertex 52 = (4,2.28516,5)
Vertex 53 = (5,2.625,5)
Vertex 54 = (5.37109,3,5)
Vertex 55 = (2,4,4)
Vertex 56 = (2.28516,4,5)
Vertex 57 = (5.71094,4,5)
Vertex 58 = (6,4,4)
Vertex 59 = (2.625,5,5)
Vertex 60 = (5.37109,5,5)
Vertex 61 = (3,5.37109,5)
Vertex 62 = (4,5.71094,5)
Vertex 63 = (4,6,4)
Vertex 64 = (5,5.37109,5)
Vertex 65 = (3,3,5.37109)
Vertex 66 = (4,3,5.71094)
Vertex 67 = (5,3,5.37109)
Vertex 68 = (3,4,5.71094)
Vertex 69 = (4,4,6)
Vertex 70 = (4,4,6)
Vertex 71 = (4,4,6)
Vertex 72 = (5,4,5.71094)
Vertex 73 = (3,5,5.37109)
Vertex 74 = (4,4,6)
Vertex 75 = (4,5,5.71094)
Vertex 76 = (5,5,5.37109)
Vertex 77 = (4,4,6)

Indices
=======
Index 0 = 2
Index 1 = 1
Index 2 = 0
Index 3 = 1
Index 4 = 2
Index 5 = 3
Index 6 = 2
Index 7 = 0
Index 8 = 4
Index 9 = 3
Index 10 = 2
Index 11 = 4
Index 12 = 7
Index 13 = 6
Index 14 = 5
Index 15 = 7
Index 16 = 9
Index 17 = 8
Index 18 = 6
Index 19 = 7
Index 20 = 8
Index 21 = 9
Index 22 = 11
Index 23 = 10
Index 24 = 8
Index 25 = 9
Index 26 = 10
Index 27 = 10
Index 28 = 11
Index 29 = 12
Index 30 = 14
Index 31 = 7
Index 32 = 5
Index 33 = 13
Index 34 = 14
Index 35 = 5
Index 36 = 1
Index 37 = 14
Index 38 = 0
Index 39 = 1
Index 40 = 9
Index 41 = 14
Index 42 = 9
Index 43 = 7
Index 44 = 14
Index 45 = 3
Index 46 = 9
Index 47 = 1
Index 48 = 3
Index 49 = 15
Index 50 = 9
Index 51 = 15
Index 52 = 11
Index 53 = 9
Index 54 = 16
Index 55 = 12
Index 56 = 11
Index 57 = 15
Index 58 = 16
Index 59 = 11
Index 60 = 18
Index 61 = 14
Index 62 = 13
Index 63 = 17
Index 64 = 18
Index 65 = 13
Index 66 = 0
Index 67 = 19
Index 68 = 4
Index 69 = 0
Index 70 = 14
Index 71 = 19
Index 72 = 14
Index 73 = 18
Index 74 = 19
Index 75 = 4
Index 76 = 15
Index 77 = 3
Index 78 = 4
Index 79 = 19
Index 80 = 15
Index 81 = 19
Index 82 = 20
Index 83 = 15
Index 84 = 21
Index 85 = 16
Index 86 = 15
Index 87 = 20
Index 88 = 21
Index 89 = 15
Index 90 = 18
Index 91 = 17
Index 92 = 22
Index 93 = 19
Index 94 = 18
Index 95 = 22
Index 96 = 23
Index 97 = 19
Index 98 = 22
Index 99 = 20
Index 100 = 19
Index 101 = 23
Index 102 = 24
Index 103 = 20
Index 104 = 23
Index 105 = 21
Index 106 = 20
Index 107 = 24
Index 108 = 27
Index 109 = 26
Index 110 = 25
Index 111 = 26
Index 112 = 27
Index 113 = 28
Index 114 = 6
Index 115 = 30
Index 116 = 29
Index 117 = 5
Index 118 = 6
Index 119 = 29
Index 120 = 25
Index 121 = 8
Index 122 = 27
Index 123 = 25
Index 124 = 30
Index 125 = 8
Index 126 = 30
Index 127 = 6
Index 128 = 8
Index 129 = 27
Index 130 = 31
Index 131 = 28
Index 132 = 27
Index 133 = 8
Index 134 = 31
Index 135 = 8
Index 136 = 10
Index 137 = 31
Index 138 = 31
Index 139 = 10
Index 140 = 12
Index 141 = 32
Index 142 = 31
Index 143 = 12
Index 144 = 35
Index 145 = 34
Index 146 = 33
Index 147 = 35
Index 148 = 29
Index 149 = 34
Index 150 = 35
Index 151 = 13
Index 152 = 29
Index 153 = 13
Index 154 = 5
Index 155 = 29
Index 156 = 36
Index 157 = 16
Index 158 = 37
Index 159 = 36
Index 160 = 32
Index 161 = 16
Index 162 = 32
Index 163 = 12
Index 164 = 16
Index 165 = 36
Index 166 = 37
Index 167 = 38
Index 168 = 35
Index 169 = 33
Index 170 = 39
Index 171 = 39
Index 172 = 13
Index 173 = 35
Index 174 = 39
Index 175 = 40
Index 176 = 13
Index 177 = 40
Index 178 = 17
Index 179 = 13
Index 180 = 37
Index 181 = 41
Index 182 = 42
Index 183 = 37
Index 184 = 16
Index 185 = 41
Index 186 = 16
Index 187 = 21
Index 188 = 41
Index 189 = 38
Index 190 = 37
Index 191 = 42
Index 192 = 17
Index 193 = 40
Index 194 = 43
Index 195 = 22
Index 196 = 17
Index 197 = 43
Index 198 = 45
Index 199 = 43
Index 200 = 44
Index 201 = 45
Index 202 = 23
Index 203 = 43
Index 204 = 23
Index 205 = 22
Index 206 = 43
Index 207 = 46
Index 208 = 23
Index 209 = 45
Index 210 = 46
Index 211 = 47
Index 212 = 23
Index 213 = 47
Index 214 = 24
Index 215 = 23
Index 216 = 41
Index 217 = 21
Index 218 = 24
Index 219 = 47
Index 220 = 41
Index 221 = 24
Index 222 = 45
Index 223 = 44
Index 224 = 48
Index 225 = 46
Index 226 = 45
Index 227 = 48
Index 228 = 26
Index 229 = 49
Index 230 = 25
Index 231 = 26
Index 232 = 28
Index 233 = 49
Index 234 = 30
Index 235 = 51
Index 236 = 50
Index 237 = 29
Index 238 = 30
Index 239 = 50
Index 240 = 49
Index 241 = 30
Index 242 = 25
Index 243 = 49
Index 244 = 52
Index 245 = 30
Index 246 = 52
Index 247 = 51
Index 248 = 30
Index 249 = 28
Index 250 = 52
Index 251 = 49
Index 252 = 28
Index 253 = 31
Index 254 = 52
Index 255 = 31
Index 256 = 53
Index 257 = 52
Index 258 = 53
Index 259 = 31
Index 260 = 32
Index 261 = 54
Index 262 = 53
Index 263 = 32
Index 264 = 34
Index 265 = 55
Index 266 = 33
Index 267 = 34
Index 268 = 56
Index 269 = 55
Index 270 = 34
Index 271 = 29
Index 272 = 56
Index 273 = 29
Index 274 = 50
Index 275 = 56
Index 276 = 58
Index 277 = 32
Index 278 = 36
Index 279 = 58
Index 280 = 57
Index 281 = 32
Index 282 = 57
Index 283 = 54
Index 284 = 32
Index 285 = 36
Index 286 = 38
Index 287 = 58
Index 288 = 33
Index 289 = 55
Index 290 = 39
Index 291 = 55
Index 292 = 40
Index 293 = 39
Index 294 = 55
Index 295 = 56
Index 296 = 40
Index 297 = 56
Index 298 = 59
Index 299 = 40
Index 300 = 42
Index 301 = 57
Index 302 = 58
Index 303 = 42
Index 304 = 41
Index 305 = 57
Index 306 = 41
Index 307 = 60
Index 308 = 57
Index 309 = 38
Index 310 = 42
Index 311 = 58
Index 312 = 40
Index 313 = 59
Index 314 = 61
Index 315 = 43
Index 316 = 40
Index 317 = 61
Index 318 = 44
Index 319 = 62
Index 320 = 63
Index 321 = 44
Index 322 = 43
Index 323 = 62
Index 324 = 43
Index 325 = 61
Index 326 = 62
Index 327 = 63
Index 328 = 47
Index 329 = 46
Index 330 = 63
Index 331 = 62
Index 332 = 47
Index 333 = 62
Index 334 = 64
Index 335 = 47
Index 336 = 60
Index 337 = 41
Index 338 = 47
Index 339 = 64
Index 340 = 60
Index 341 = 47
Index 342 = 44
Index 343 = 63
Index 344 = 48
Index 345 = 46
Index 346 = 48
Index 347 = 63
Index 348 = 51
Index 349 = 65
Index 350 = 50
Index 351 = 51
Index 352 = 52
Index 353 = 66
Index 354 = 65
Index 355 = 51
Index 356 = 66
Index 357 = 52
Index 358 = 53
Index 359 = 67
Index 360 = 66
Index 361 = 52
Index 362 = 67
Index 363 = 53
Index 364 = 54
Index 365 = 67
Index 366 = 65
Index 367 = 68
Index 368 = 56
Index 369 = 50
Index 370 = 65
Index 371 = 56
Index 372 = 69
Index 373 = 66
Index 374 = 70
Index 375 = 69
Index 376 = 68
Index 377 = 66
Index 378 = 68
Index 379 = 65
Index 380 = 66
Index 381 = 70
Index 382 = 72
Index 383 = 71
Index 384 = 70
Index 385 = 66
Index 386 = 72
Index 387 = 66
Index 388 = 67
Index 389 = 72
Index 390 = 54
Index 391 = 57
Index 392 = 72
Index 393 = 67
Index 394 = 54
Index 395 = 72
Index 396 = 68
Index 397 = 73
Index 398 = 59
Index 399 = 56
Index 400 = 68
Index 401 = 59
Index 402 = 74
Index 403 = 68
Index 404 = 69
Index 405 = 74
Index 406 = 75
Index 407 = 68
Index 408 = 75
Index 409 = 73
Index 410 = 68
Index 411 = 71
Index 412 = 75
Index 413 = 74
Index 414 = 71
Index 415 = 72
Index 416 = 75
Index 417 = 72
Index 418 = 76
Index 419 = 75
Index 420 = 57
Index 421 = 60
Index 422 = 76
Index 423 = 72
Index 424 = 57
Index 425 = 76
Index 426 = 59
Index 427 = 73
Index 428 = 61
Index 429 = 62
Index 430 = 61
Index 431 = 73
Index 432 = 75
Index 433 = 62
Index 434 = 73
Index 435 = 64
Index 436 = 62
Index 437 = 75
Index 438 = 76
Index 439 = 64
Index 440 = 75
Index 441 = 60
Index 442 = 64
Index 443 = 76
Index 444 = 70
Index 445 = 77
Index 446 = 69
Index 447 = 70
Index 448 = 71
Index 449 = 77
Index 450 = 69
Index 451 = 77
Index 452 = 74
Index 453 = 71
Index 454 = 74
Index 455 = 77


It looks as follows:

Image

I suggest you run the same test and verify that the densities are the same and that the generated mesh is the same. If it is, then the problem is most likely in your conversion to an Unreal mesh.

I don't much about Unreal but your comment makes me suspicious:

Code:
// We need to add the vertices of each triangle in reverse or the mesh will be upside down


If the mesh is really upside down then you need to change the coordinate system or fake it by negating the z (or y?) component of each vertex. If you mean that each triangle points in the wrong direction then you approach may be valid but I worry you have made a mistake. You may be better off disabling back-face culling in Unreal (I don't know how to do that...) until we fix the apparent corruption


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Understanding Terrain Generation with PolyVox
PostPosted: Sun Oct 16, 2016 3:24 pm 

Joined: Sun Oct 09, 2016 9:37 pm
Posts: 4
Ha! After this kind of debugging, I realised that the density value as input is different than the output. I was using MaterialDensityPair44, without realising that it has only 4 bits for saving material and density values. And because I was working with values between 0-255, I was getting arbitrary values. So I switched to MaterialDensityPair88 and I could get a similar sphere and a much more logical terrain:

Image

It's still a little bit cornered but at least it's somewhat shows the desired terrain!

EDIT:

But it is probably some issue with the density values which are calculated for the terrain, because the sphere is beautiful!

Image


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Understanding Terrain Generation with PolyVox
PostPosted: Tue Oct 18, 2016 8:58 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Great, I'm glad you are making some progress! You don't actually need to use the MaterialDensityPairXX classes at all - while getting the shape right you might find it easier to just use (u)ints or floats.


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

All times are UTC


Who is online

Users browsing this forum: Majestic-12 [Bot] 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