🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Voxels saved to MagicaVoxel .vox format

Started by
18 comments, last by taby 1 year, 7 months ago

I found an excellent C++ code to save voxel data to MagicaVoxel format. I use MagicaVoxel to convert the voxel data to OBJ format, for use in my upcoming game.

https://github.com/aiekick/MagicaVoxel_File_Writer

Now, @joej do you have any input on how to procedurally generate a landscape? ?

Advertisement

There is a problem. MagicaVoxel supports only one material. This makes it difficult to use the exported OBJ files – the geometry is not the same, between the two materials. So, I'm going to make my own OBJ exporter. I will remove faces that are between neighbouring “on” values, but I will not collapse the faces when it comes to the material. So there will be a bit more triangles. I tweeted the author of MagicaVoxel, about supporting multiple materials, but no response quite yet.

taby said:
There is a problem. MagicaVoxel supports only one material.

From your screenshots we see it does not merge faces with different colors. So you should be able to represent your materials with different colors to preserve them. And after the conversation use the color to map back to your material.

taby said:
do you have any input on how to procedurally generate a landscape?

Lots of stuff here, iirc: https://www.redblobgames.com/

Personally i also would try a terrain tool like Gaea and convert the heightmap to voxels. Gaea is free to use for 1024^2 terrain afaik. But there are also other similar tools.

JoeJ said:
But there are also other similar tools.

I personally have some experience with Worldmachine and in the (distant) past with Terragen. I kind of like control Worldmachine gives you over generation. It is available from https://www.world-machine.com/​​ There was some sort of free license, but it was only for personal and non-commercial use (plus I do remember there was some kind of limit - maybe on size of exported maps, and unable to build tiled maps (you still could do it by hand though)).

There is always an option to write a small tool to build height maps you want (you practically start with some sort of noise, and erosion). The basics are not that hard (requires a bit of math background), the moment you need multiple types of complex erosion and material generation - that's the moment this becomes extremely complex. Again, it depends on what exactly you need.

Few notes:

  • Heightmap is representation of voxels
  • Most tools (both Gaea and Worldmachine at least to my knowledge) allow to export splat maps - in case you want multi-material support

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

The author of MagicaVoxel got back to me – there is an option to disable merging of faces of similar colour! Now we're talking business!!! It's in config.txt

And then you can just use color to define material.

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

Yes, the plan is to use the 2nd texture as a specularity map… some parts shiny, some parts not.

taby said:
specularity map… some parts shiny, some parts not.

Flat shaded polygons likely won't appear very shiny, aside rare reflections of a light source. This would work well only with smooth shaded models, i guess.
If so, maybe you could use reflections of an environment map from the sky. But this causes the classical PBS problem of missing occlusions e.g. in case a nearby mountain or a roof should occlude the sky reflection, but doesn't.
That's something you can hardly identify using a single model. The issue becomes only a real problem once the scene is complex.
To my eyes, it is the most disturbing visual artifact of the PS4 era, because PBS requires reflection probes everywhere. Other people probably have no problem at all with it.
Often that's a good reason to avoid realistic shading models, which usually goes hand in hand with choosing voxel artstyle.

But try it out ans see if you like what you get.

Maybe a promising direction to improve voxel gfx is to ddress its quantization artifacts.
Think of a Minecraft landsacpe. Surfaces are flat shaded, and point always in one of only 6 directions.
The problem is such shading fails to express smooth slopes of the landscape. We might like the blocky appearance, but we might not like the resulting quantization of lighting, as it hurts important depth cues.
For a top down game, depth cues are not important, but visualizing smooth slopes would still help to make the landscape more recognizable.

So what you could do is to make the vertex normals smooth, while keeping positions blocky.
And then you could still average 4 normals per face to have flat shading.
I sort of do this when visualizing my isosurface:

Pay attention to the polygons. It's all quads, and cube alike structures form at some spots.
This is because my iso algorithm, unlike marching cubes, starts with a voxelization. So the first step looks exactly like a Minecraft mesh, but unfortunately i can't visualize this step.
After that, for each vertex i calculate the density gradient and project it along the gradient to the surface to get a smooth mesh, hiding the voxels.

My proposal now is that you do the same, but only for the normals. E.g. to calculate the normal of a voxel face, you calculate the density gradient at the center of the face and use this instead (or blend with) just 6 quantized directions.
Result might be an artstyle very different from typical low res voxel games, being blocky, but still appearing smooth. Could be interesting i think.

However, ofc. you can only do this if your terrain is made from gradual density (Or you use a trick like with your fractal refinement to apply smoothing to a quantized signal).
But a real downside is that mesh reduction on coplanar faces is no longer possible. So instead you could calculate a preshaded static color from the smooth normal and use that.

IIrc Magica voxel even supports path tracing? So you could use that to bake lighting maybe.

JoeJ said:
IIrc Magica voxel even supports path tracing?

Yes, it does:

If you can use this to bake lighting, no trickery and hacks like i have propose would be needed at all.

That's just beautiful and i would use that. Dynamic lights can just add to this.
But for dynamic objects you might need to make irradiance probes, e.g. SH2 or Ambient Cube. You could do this by ray tracing the baked static scene.
Maybe Magica has some API support for this as well.

@joej I promise that the results will be good. It already makes a difference on the knight character… the axe and helmet are shiny, as well as the pupils, and the rest is not shiny. Wait until I get a terrain in place… it will look deadly awesome, I hope.

This topic is closed to new replies.

Advertisement