Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[RELEASED] Voxels for Unity: Rasterizer - Extension to convert 3D objects

Discussion in 'Assets and Asset Store' started by LightrockerRon, Sep 20, 2015.

?

Do you need support for Unity 4 Pro?

Poll closed Nov 23, 2017.
  1. Yes

    0 vote(s)
    0.0%
  2. No

    100.0%
  1. LightrockerRon

    LightrockerRon

    Joined:
    Mar 17, 2015
    Posts:
    12
    I proudly present my spare time project of the last year:

    In the video of the following post you can see some free assets in a composition with conversions, which were generated using the extension "Voxels for Unity". It is a tool with an inherent programming interface, can be used in the editor or at run time and is currently waiting for approval to be published to the Asset Store.

    The primary function is the scanning of the 3D models and terrains from all six main directions through Unity's rendering methods, what is the key difference contrary to existing solutions. So it is possible to bake lighting and shading into the colors of the generated volume cells. But you are still able to combine them with dynamic properties at the end.
    The collected data can be converted to a list of uniformly ordered meshes (most likely cubes), copied to a particle system or you write your own processor class, e.g. to transfer it to existing voxel frameworks or render classes.

    If you want to know more, you can have a look at Voxels.Lightrock.biz. Or you follow me on Facebook and Twitter. I will publish the informative manual in the upcoming days after it will be completed.

    Thank you for your attention!
     
    Last edited: Feb 21, 2016
  2. LightrockerRon

    LightrockerRon

    Joined:
    Mar 17, 2015
    Posts:
    12
    After adding a subtitle, adjusting the description and working some time on the code my package had been approved within a day and is now available at the Asset Store: http://u3d.as/jpL. You can read more about the background on my blog or view the manual at SlideShare.


    This year I participated at the Global Game Jam and created a small exploration game called "Lookout" with Unity. Shortly afterwards I converted a level to a voxel version. Using my extension finding the right settings and processing took about an hour only. Another hour was used to get pixelated textures and to adopt the collision data of the terrain to prevent clipping issues. Here is the result:
    That endeavor led to an enhancement of the core. Because of small deviations while using the GPU the sampled terrain included some holes. I added an overscan factor so the generation of a voxel cell can also incorporate neighbor data now. That way holes are closed and objects can become thicker.

    You can see that my package is good for fast prototyping of voxelized worlds or the generation of bonus levels/modes, which are combining your original art design and volumetric representation, out of the box.


    The next is big step is to integrate processors that are able to import the collected data of my rasterizer into existing, popular voxel tools, frameworks or engines from the store. What would be your favorite? Please leave a note in the comments. Thanks for your help!
     
    Last edited: Feb 21, 2016
    Mikael-H likes this.
  3. Mikael-H

    Mikael-H

    Joined:
    Apr 26, 2013
    Posts:
    309
    Wow really cool project!

    I would vote for Cubiquity! As it is moving towards open source I hope it will be more widely used by the community.
     
  4. LightrockerRon

    LightrockerRon

    Joined:
    Mar 17, 2015
    Posts:
    12
    Voxels for Unity 1.1.png

    The second release (1.1) with following improvements is out at the Asset Store:
    • Adaption to Unity 5.6 and 2017
    • Better results using PBR (physical based rendering) and HDR (high dynamic range)
    • Two fully working file exporter examples added: PLY (common point cloud format) and VOX (MagicaVoxel editor format)
    • Rasterizer enhanced by supersampling and multithreading options
    • API enhancement: Callback parameter to inform the executing script about the creation of new game objects
    • API extension: New class to decrease number of resulting materials in a processor to given amount
    • Multi-textured terrain included into the example scene
    • Bug fixes for minor issues
     
  5. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    Will this work with terrains generated (with splat textures) in Terrain Composer 2 in Unity 2018.1 and for games with isometric or perspective view? How is its performance impact or is there a limitation on the size of the object to be converted?

    I tried your downloadable game Lookout demo and it seems it does not yet use Voxels for Unity as depicted in one of your videos above. Can that be activated within game?

     
    Last edited: May 30, 2018
  6. LightrockerRon

    LightrockerRon

    Joined:
    Mar 17, 2015
    Posts:
    12
    The plug-in still works in Unity 2018.1.

    TerrainComposer 2 generates standard Unity terrains, doesn't it? So it should be convertible by the rasterizer but the tool is not a voxel renderer. Its package include scripts, which can build standard meshes or particle systems from the collected data. Using them you are able to create blocky meshes, which are presentable in runtime, for example. But if you want the best performance you will need a specific framework for rendering voxels, which however can be fed by the data coming out of my tool.

    One limitation of the converter is the maximum of 2048x2048x2048 voxels. But it is possible to use multiple instances to rasterize one or a group of objects. You only have to set the boundaries next to each other.

    You surely have downloaded the Lookout project from the Global Gam Jam site, right? The voxel version of the first level is not part of it because I made it some days later. Unfortunately the old project is not compatible with the latest Unity 5.6 version, so I could not run it. But I reduced the assets to the level file only. You can download it here and so have a look into it.
     
  7. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    Yes, TC2 generates standard Unity terrains but I noticed all changes I made to it using the native Unity Terrain Tools gets reset after I reload my project. Maybe I will have to convert them to a Mesh first for it to work with Voxels for Unity... When you mean the effect is "presentable in runtime", do you mean they are not present in Scene View and only when playing the game? So this tool does not actually create a Blocky Voxel Mesh copy but actually works like a filter effect that disappears when you quit the game and go to Unity Scene View?

    Good to know about the tools limitation and how to possibly work around it. Yes, I have downloaded the Global Game Jam version. Ok, will try out the link. Thank you!

    Is Voxels for Unity still being developed? In my recent research, I have discovered an almost similar tool here that even supports animation but it's a bit unwieldy to use.

    The most important features for me to make Voxels for Unity a must buy would be:
    • Option to directly convert a Terrain to a blocky Mesh (if possible)
    • Can convert animations too
    • Optimization settings (i.e. being able to include visible top and side faces only in the conversion when possible, specify the number/size of blocks, etc.)
    Secondary features would be:
     
    Last edited: Jun 2, 2018
  8. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    Because there is really no live demo I can check, I just bought Voxels for Unity to see if it will fit my basic requirements. After install in Unity 2018.1, I immediately received the following errors:



    Also took a closer look at the included Example scene by attaching an Extended Fly Cam. It was so slow that the Stats window displayed 1 FPS. :eek:

    I tested by rasterizing an actual 500 x 600 x 500 terrain I made using Unity's native Terrain Tool by attaching the included Rasterizer and Mesh Scripts to the terrain and set some basic configuration. After waiting for a minute or so to process, it only managed to produce a blank gameobject. This means this tool is NOT compatible with a Terrain GameObject as advertised. :(

    Then I tried rasterizing a Terrain Mesh I got from Material Terrain Editor (Free version). The original Terrain GameObject was created using Terrain Composer 2 and the size is 2048 x 1500 x 2048. Processing was slow but I was able to get a voxelized mesh alright. The cube was large and the texture does not seem right as each cube seems to have the whole texture inside it. Also, some parts of the resulting terrain mesh had holes in the ground. Will see later if the holes will be fixed by increasing the Voxel Overscan.
     
    Last edited: Jun 9, 2018
  9. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    Further testing, I was able to convert a smaller Mesh part (with help from MTE & TC2) using the configuration in the attached image. But I still cannot get the splatmap/textures to be placed correctly. What am I doing wrong?

    Also, I'm planning to use a tool to merge the rasterized Meshes in the future. Do you think that is possible and would that help increase the frame rate?
     

    Attached Files:

    Last edited: Jun 5, 2018
  10. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    An error that kept appearing:
     
  11. LightrockerRon

    LightrockerRon

    Joined:
    Mar 17, 2015
    Posts:
    12
    The first two are only warnings, which I should adapt in a new version. But currently they do not harm.
    After some research it seems the shader error is kind of a bug in Unity 2018.1. It should disappear at further loads of the project.

    First I have the say that the example scene is not made for high performance rendering but to show possible settings and the outcome. Despite the speed of converting the terrain is much higher in Unity 5.6. The profiling showed me that Terrain.Trees.Render takes 75% of the frame time in Unity 2018, while in 5.6 it is zero, which is reasonable because no trees are set. That seems to be another issue in the current version and I hope it gets fixed.

    Empty objects can be the result of various cases: For example boundaries are not specified correctly or there is no enabled converter attached to the rasterizer.

    A result with the same texture on every voxel can occur, when Baking Mode is set to Original Material or a template material contains a texture, which is not replaced by the mesh converter using the Main Texture and Emission Texture flags.
    Did you try to copy the component(s) from my terrain sample to your object and see, if that works?
     
  12. LightrockerRon

    LightrockerRon

    Joined:
    Mar 17, 2015
    Posts:
    12
    You are using Original Material, which references the source materials with textures that are made for the original objects. Try to use Averaged Color and template materials like in my example scene.

    Did you see that the mesh converter has got a Merge Meshes option? For high-detailed source objects it is only useful if you do not use the Main Color, Specular Color or Emissive Color options in the rasterizer. Those lead to the creation of a new material for every unique color. If the color information is stored to a texture or as vertex data instead, up to 65,534 vertices can be combined into single meshes. Again, let's have a look at my example and the objects, which are being constructed there. You can see there, which options result in which output by parsing through the tree and watching the inspectors.
     
    RendCycle likes this.
  13. LightrockerRon

    LightrockerRon

    Joined:
    Mar 17, 2015
    Posts:
    12
    I attached a slightly adapted version of the script, so the warning should vanish.
     

    Attached Files:

  14. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    I have followed your instructions and made two tests. Please see the result in the illustrations below.

    1st Test: Using just the included example terrain.



    2nd Test: Using a newly created Unity Terrain without tress nor grass.



    Although terrain conversion worked, there were still some errors encountered as seen in the above image (Console Errors, Terrain Holes, & Material w/ Tangent Geometry Error). Thanks for guiding me with this! I appreciate it very much. Since I initially received installation errors, I didn't delve deeper in investigating how the script worked internally after briefly tinkering with some settings and checking out the example file. Because I have very limited time with this current project I have, I only try to use tools that work out-of-the-box. I've read the manual but was not able to figure out the correct settings. Not demanding this but only suggesting adding a simple Quick Start Guide with illustrations for new users or even an additional Youtube video if you have time.

    I have one more question when using converted terrains. Since you specified I can use several small converted terrains in a Scene, do you have a suggestion on the best way I can seamlessly interconnect these voxelized terrains so it won't be noticeable for the player that traverses the edges of each?

    I was thinking also of combining all the produced "Part" meshes into one large hollow mesh to maybe increase FPS or reduce draw calls. Is that possible within this tool already or I need a different tool for that like Super Combiner?

     
    Last edited: Jun 9, 2018
  15. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    This fix seem to have worked. Related error for this script is gone. Thank you! But other errors were encountered upon terrain conversion. Please refer to previous post.

    I also experienced the script hangs when more than 1 Million+ Voxels Count is reached (see Rasterizer info below). Is that normal and is this too much? I used a Voxel Size of 0.5 with Voxel Overscan of 1. What do I have to check to avoid this?

     
    Last edited: Jun 9, 2018
  16. LightrockerRon

    LightrockerRon

    Joined:
    Mar 17, 2015
    Posts:
    12
    Sorry for the very late reply!

    The Frame Time Target is set to 40ms, which means that the rasterizer tries to use only so much time, that game can be rendered or the editor can be updated at about 25 fps while it is processing. Lowering the target increases the frame rate but also slows down the conversion. And the 66.3 fps after the creation of the result are typical for refresh rate dependence.

    If you want to convert the full object the boundaries have to be set to include all source assets, which can be multiple in the child hierarchy. Usally it is set automatically if the rasterizer component is attached to an existing object. But if you modify it you can click "Adopt from object" to recalculate the bounding box. Sometimes it does not work as intended because Unity delivers inaccurate values. If you see that one axis has got a length of zero or the result has got missing patches, then you have to adapt it manually. Sometimes that happens for terrains. But you can use with intent, if you only want to voxelize a part of the source(s).

    You do not have to specify emissive properties for all components. It depends on what you want to achieve. If you want to have a result, which can be dynamically lighted, you should use "Main Color/Texture" and more standard material templates. But you can also combine various states if something fancy has to be the outcome. As "Voxel Mesh" you can also specify as sphere, for example. That would lead to round cells.

    I think the holes are generated because the minimum y-bound is a bit too high. Try to lower it to -25, for example.

    That tangent geometry warning is in the terrain component, which is a part of Unity. You could avoid it by using other settings. E.g. "Built In Standard" works, too.

    Did you had a look into the tutorial video with activated captions? If yes, what is the clip lacking?

    My package is not really a tool, which does simple things out of box. It is more part of a complex workflow to feed a voxel engine with data from typical 3D objects but the example converters can be used to create productive assets for smaller projects, which do not have such an engine. It is very flexible and that comes with the cost of complexity. Maybe I could create helpers to make it easier for cases like yours to simplify the setup for typical settings.

    You only have to set the boundaries for every rasterizer to match the neighbors. For that 0, 0 - 500, 500 terrain it could be 0, 0 - 250, 250 / 250, 0 - 500, 0 / 0, 250 - 250, 500 / 250, 250 - 500, 500.

    That game objects, which are named "Part", have already been combined to fit into the 64k limit of Unity. The only improvement I still can implement is to automatically remove hidden triangles. Even the generator component like the "Mesh" are not the core part of the package but examples, I could create a new one for optimized cubes.
     
  17. LightrockerRon

    LightrockerRon

    Joined:
    Mar 17, 2015
    Posts:
    12
    Does it really hang or is it very, very slow? That is a lot of data, the CPU has to process. Lowering the "Voxel Counts" property leads to fewer cells to process. Or do you need such a high resolution? Then you could try to split up the conversion into four or more rasterizer components as described in the previous reply.
     
  18. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    Thanks for the reply. But I've dropped this asset for now and went with an alternative solution.