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

PolyVox and Unreal Engine 4
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=14&t=667
Page 1 of 1

Author:  DennyR [ Wed May 04, 2016 10:05 am ]
Post subject:  PolyVox and Unreal Engine 4

Hi,

first off, I love PolyVox, I've built it from the repo yesterday and got a voxel sphere going in Unreal in about an hour or so. The only thing i had to take care of was a SurfaceMeshWrapper to convert the Y-Up of PolyVox to Z-Up that Unreal uses.

I am getting a bit lost in coordinate spaces though, so here are a few questions:

Basic question about units
As far as I can tell, the voxel volume and the extractors operate on integers. So when I extract a mesh, this mesh will be extracted around the integer voxel data, right? So if I want a bigger mesh, I'd have to manually scale it up, or is there some kind of unit system in place to scale the voxel volume itself?

More units and conversion
Basically an extension of the last question. Lets assume I would like to live edit my voxels with a sphere of a certain radius. The sphere lives in the games world coordinate space. Is there any functionality to transform the sphere and return all voxels within the sphere? Or do I have to write the transformation myself?

chunks of a volume
I've already set everything up to work multithreaded with a pool of vertex buffers and extractor threads that would operate on regions of a RawVolume(possibly changing this to PagedVolume later). Is there any way to define a chunk size and then just operate mesh extractions on the chunks or blocks? For example having a 1024x1024x1024 volume that is subdivided into 32x32x32 blocks. I can't find any built in way of telling in what chunk a certain voxel lives in. My plan was to set it up in a way that every voxel knows in what chunk it lives and whenever a voxel gets editited it marks the chunk as dirty, so I can extract a new mesh using a worker thread.

Not a real question, but
I am planning on making a voxel planet using marching cubes, any tips or possible culprits a naive, first time voxler could run into?


Okay enough questions for now, thanks for making this awesome and clean framework. Having a blast working with it so far.

Author:  David Williams [ Wed May 04, 2016 10:35 pm ]
Post subject:  Re: PolyVox and Unreal Engine 4

Hi!

DennyR wrote:
Basic question about units
As far as I can tell, the voxel volume and the extractors operate on integers. So when I extract a mesh, this mesh will be extracted around the integer voxel data, right? So if I want a bigger mesh, I'd have to manually scale it up, or is there some kind of unit system in place to scale the voxel volume itself?


Indeed, there are no units. You simply decide how big you want each voxel to be in your world and scale the mesh by the appropriate amount.

DennyR wrote:
More units and conversion
Basically an extension of the last question. Lets assume I would like to live edit my voxels with a sphere of a certain radius. The sphere lives in the games world coordinate space. Is there any functionality to transform the sphere and return all voxels within the sphere? Or do I have to write the transformation myself?


This is not built in, you would need to do the transformation yourself.It is certainly possible though, as demonstrated by this video (Cubiquity builds on PolyVox): https://youtu.be/NLQozqoPMho?t=5m10s

DennyR wrote:
chunks of a volume
I've already set everything up to work multithreaded with a pool of vertex buffers and extractor threads that would operate on regions of a RawVolume(possibly changing this to PagedVolume later). Is there any way to define a chunk size and then just operate mesh extractions on the chunks or blocks? For example having a 1024x1024x1024 volume that is subdivided into 32x32x32 blocks. I can't find any built in way of telling in what chunk a certain voxel lives in. My plan was to set it up in a way that every voxel knows in what chunk it lives and whenever a voxel gets editited it marks the chunk as dirty, so I can extract a new mesh using a worker thread.


Be aware that 'chunks' is a bit of a vague term which can have a couple of different meanings. Firstly, it can apply to the storage of data. PagedVolume stores it's voxels as a set of 'chunks' typically between 16^3 and 64^3. Such chunking is an implementation detail and not really exposed through the API. RawVolume does not store data as chunks but instead as a single large array. Use RawVolume to start with.

Secondly, regardless of whether the volume uses chunks, you can choose to only extract part of it (which does not have to line up with any internal chunk boundaries, if they even exist).

You can use integer division and modulus operations to get voxel chunk positions and offsets. E.g. for pos 47 with chunk size 32 you have 47 / 32 = 1 (chunk 1) and 47% 32 = 15 = voxel offset 15 into the chunk. However, be aware that surface extraction also requires looking at *neighbouring* voxels.

Expect pain when it comes to threading, unfortunately this is an area of PolyVox which never really got developed properly. I will try and give that more thought for Cubiquity 2. http://www.volumesoffun.com/polyvox/doc ... ading.html

DennyR wrote:
Not a real question, but
I am planning on making a voxel planet using marching cubes, any tips or possible culprits a naive, first time voxler could run into?


Scale is the biggest issue as I never worked with very large volumes, but just see how far you can push it. Again that is something I want to improve in future work.

Author:  DennyR [ Thu May 05, 2016 8:09 am ]
Post subject:  Re: PolyVox and Unreal Engine 4

Hey,

thanks for your fast response. I got most of the unit and transformation stuff figured out and can now edit the voxels in real-time.

Regarding mutlithreading, I think I will start with RawVolume and the modulo division that you described to logically chop the data into small logical 'chunks' that I can process with a worker thread.
I guess I will implement a chunk-index table to not have two workers work the same 'chunk'.
That should give me a performant starting point, before I start digging into paging and loading/unloading data dynamically.

Author:  petersvp [ Tue May 10, 2016 9:48 am ]
Post subject:  Re: PolyVox and Unreal Engine 4

Please note however that negative space will not suffice with plain modulus and plain divisions, so you definitely want to use following two functions, especially the Negative Floating Modulus one, to convert from world to inner-chunk coordinates.

Code:
// http://stackoverflow.com/questions/1082917/mod-of-negative-number-is-melting-my-brain
float nfmod(float a, float b)
{
    return a - b * floor(a / b);
}

// In addition to that, this tries to preserve negative stats e.g. 0..3/4 = 0,  4..7/4 = 1,  but -1...-4 = -1, -5...-8 = -2 and so on
int nfdiv(float a, float b)
{
    return (a>0 ? a/b : (a-b+1)/b);
}

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