SlideShare a Scribd company logo
Version 1.0
October 2, 2015
Table of Contents
About....................................................................................................................................................3
Using the editor....................................................................................................................................4
Voxel Converter...............................................................................................................................4
Voxel Mesh......................................................................................................................................5
Voxel Particle System......................................................................................................................6
Using the programming interface.........................................................................................................7
namespace Voxels............................................................................................................................7
class Voxels.Converter.Settings.......................................................................................................7
class Voxels.Converter.....................................................................................................................9
abstract class Voxels.Converter.Processor.....................................................................................11
class Voxels.Converter.Engine.......................................................................................................12
class Voxels.Storage.......................................................................................................................14
class Voxels.HSVColor..................................................................................................................16
© 2015 Ronny Burkersroda 2
About
“Voxels for Unity” is a plug-in extension for the Unity engine and development environment
(www.Unity3D.com). It utilizes the graphics hardware to rasterize renderer objects into a three-
dimensional grid instead of a 2D planar surface, which is done to present them on a screen or to
compute effects most of all. As opposed to other existing solutions it is able to bake a lot of shading
and lighting conditions into the target color of every grid cell at the moment of the processing. Such
cells are called voxels, which is a composition of volume and pixels. You can use them to display
grid aligned (e.g. blocky) models or particles, which are generated from existing assets. Those
particles can be used to create visual effects in combination with the original objects or you transfer
the data to an existing voxel engine respectively a rendering framework.
The extension is executable in the editor and at runtime and therefore provides an inspector and a
programming interface, which can be accessed from other scripts. And the complete package
includes two sample processing classes, which are converting the gathered data to visible game
objects. One creates a hierarchy of meshes while the other passes the grid elements to a particle
system. You are able to adapt the existing examples or write your own processor scripts using the
derivation from a base class.
Unfortunately not all rendering features can be baked into the final voxel colors because the culling
system of Unity hides them in the scanning process. Known issues are dynamic shadow maps and
particles. The first one can still be applied to converted voxel objects but cannot be included in the
color of the object itself. We are still looking for workarounds or alternative rendering methods to
be provide the support in future releases.
© 2015 Ronny Burkersroda 3
Using the editor
Voxel Converter
After you have imported the package to your Unity project, you can attach the Voxel Converter
plug-in to any game object, even multiple times. In the hierarchy any object under the modified one
or the modified one itself should contain a visual component like a mesh renderer or a terrain.
Otherwise nothing could be rasterized to the volume grid.
You get an inspector for every converter instance. If you turn the switch off, it will not
automatically being executed at the start of the scene.
Boundaries: Minimum and Maximum are the limiting 3D vectors of the volume in the scene, which
is being scanned for voxels. By pressing on the
Adopt from object button both values are
measured by combining the current bounds of
all attached objects.
Voxel Size: This is the extent of one grid cell in
the space of the scene.
Voxel Counts: It describes the number of
columns, rows and slices the volume grid contains.
Voxel Size and Voxel Counts are affecting one another, where the counts are the outcome of the total
volume and the single cell size.
Baking Mode: The shaded colors of a source object can be interpreted in various ways. By using
Original Material the color is not baked at all. The source material, which is located at a cell, is
transferred directly to its voxel. On the contrary Averaged Color, Darkest Color and Brightest Color
burn the shaded result color to a material, which is used in association with renderer of the single
voxel. Most Frequent Color works similar but does not simply averages all detected cell colors or
builds the mini- or maximum of them but filters by the amount of their occurrences.
Opaque Template: This option only appears, if you have selected a color baking mode. You can
specify a default material, which is used, if the alpha value of the grid cell is 1. This means that the
voxel is originally not a transparent one. Without a selection a standard legacy material is created.
Transparent Template: Comparable to Opaque
Template it allows the choice of a material,
which is used for semi-transparent cells, which
means that the alpha value is between 0 and 1.
Main Color / Specular Color / Emissive Color:
Here you can select, which component of the
© 2015 Ronny Burkersroda 4
Voxel Converter inspector with all properties
Voxel Converter shows the current progress
applied material is modulate by the result color of the baking.
Saturation: This factor allows the manipulation of the result color by making it more or less
colorful.
Brightness: A material can be made darker or lighter by modifying it.
Process / Processing… / Waiting…: That button starts or stops the conversion of the selected
object from the editor. It also shows the current state: Processing… signals that the object is
currently being processed and shows the progress, whereas Waiting… represents that another object
is currently in conversion and indicates the position in the queue.
At runtime the button does not appear and will
be replaced by a progress bar during the
conversion.
Frame Time Target: This is a global setting,
which affects all converter instances and adjusts
the aimed frame rate. Because the processing
cannot be done in real-time it happens in
cooperation with the other work load of Unity
and your scene. The approximate value allows
you to specify to amount of time, which should
be used for total processing between two frames,
but it can be more in complex scenarios.
At last there is a box with some information
about the volume size, the grid resolution and
maximum count of resulting voxels, if all grid
cells would get filled. You can make use of the data to adapt setting for a target specification.
Voxel Mesh
One of the two sample processor scripts constructs a hierarchy of meshes from the data, which has
been collected by the converter instance. That instance transfers gathered voxels to active processor
components, which are attached at the same game object like the converter.
Enabled: The flag activates the processing of
incoming data.
Voxel Mesh: You have to select a template,
which is used to represent a voxel. Most often a
cube might be the general choice. Nevertheless you are able to choose any imported mesh asset like
a sphere. But beware of the vertex / polygon count: Thousands of voxels multiplied by thousands of
triangles turn into millions of polygons that need to be processed per frame.
© 2015 Ronny Burkersroda 5
Voxel Converter inspector at runtime while processing
Voxel Mesh inspector
Size Factor: That value increases or decreases the extent of one cell mesh, which is normalized to
fit the voxel size declared in the converter.
Static Containers: It is a flag, which is copied to new game object that will be created during the
processing. If you want to animated single voxels, you should turn it off.
Merge Meshes: Multiple voxels that share the same material will be merged into larger meshes. So
single cells cannot be moved by individual game object transform components any longer but
shaders can be used to do so.
Opaque Only: Whenever Merge Meshes is enabled that flag skips the combination of voxels, which
have got semi-transparent alpha values. This is important if you want to retain the correct blending
order from camera view with the standard Unity solution.
Target Name: The main container of the target object is named after the string, which is given here.
Voxel Particle System
The second sample class builds a system of particles using the incoming data. You are able to
combine it with other processors, so that the same data is processed into different objects.
Enabled: Equally to Voxel Mesh it activates or
deactivates the processing of the component.
Object Template: That needs to be game object
instance with a predefined particle system, which is instantiated as a new one for the target.
Size Factor: It is the factor, which is multiplied with the standard particle size of a voxel cell.
Target Name: The recently instantiated template gets the stated name.
© 2015 Ronny Burkersroda 6
Voxel Particle System inspector
Using the programming interface
namespace Voxels
All structures, enumerations and classes of the extension are collected in that main namespace.
struct
int
int
int
Vector
x
y
z
A vector with a coordinate (column, line, slice) in
voxel space
enum BakingOperation
Undefined
OriginalMaterial
AveragedColor
DarkestColor
BrightestColor
MostFrequentColor
Method to interpret sampled colors per volume cell
• Use material of the source object(s)
• Apply average, darkest, brightest or most
frequent sampled color of a cell to a derived
material
class Voxels.Converter.Settings
This class is used to deliver scanning and properties to the engine.
UnityEngine.Bounds bounds Center and size of volume to scan
UnityEngine.Vector3 voxelSize Size of a volume cell in scene space
Voxels.Vector volumeResolution Number of columns, rows and slices in
the scan volume
int samplingResolution [not supported yet]
Voxels.BakingOperation bakingOperationMode Type of method to use for casting
scanned material or color
UnityEngine.Material opaqueTemplate A material, which is used to apply non-
transparent cell colors to
UnityEngine.Material transparentTemplate A material, which is used to apply semi-
transparent cell colors to
bool mainColorModulation Flag to modulate main color of the
instantiated material by the cell content
bool specularColorModulation Flag to modulate specular color of the
instantiated material by the cell content
bool emissiveColorModulation Flag to modulate emissive color of the
instantiated material by the cell content
© 2015 Ronny Burkersroda 7
float saturationFactor Modifies chroma of the cell color
float brightnessFactor Modifies luminosity of the cell color
float budgetTime Frame time target for that specific
conversion (<0 for standard value)
There are no other methods beside the two constructors, which are quite similar. One is for setting
the size per voxel, the other to use a target resolution for the complete volume.
Settings(
UnityEngine.Bounds bounds,
UnityEngine.Vector3 voxelSize,
int samplingResolution,
Voxels.BakingOperation bakingOperationMode,
UnityEngine.Material opaqueTemplate,
UnityEngine.Material tranparentTemplate,
bool mainColorModulation,
bool specularColorModulation,
bool emissiveColorModulation,
float saturationFactor,
float brightnessFactor,
float budgetTime = -1
)
Initialize values including voxel size and set volume resolution to zero, which leads to an automatic
calculation.
Settings(
UnityEngine.Bounds bounds,
Voxels.Vector volumeResolution,
int samplingResolution,
Voxels.BakingOperation bakingOperationMode,
UnityEngine.Material opaqueTemplate,
UnityEngine.Material tranparentTemplate,
bool mainColorModulation,
bool specularColorModulation,
bool emissiveColorModulation,
float saturationFactor,
float brightnessFactor,
float budgetTime = -1
)
Initialize values including volume resolution and set voxel size to zero, which leads to an automatic
calculation.
Parameters:
See member variables
© 2015 Ronny Burkersroda 8
class Voxels.Converter
That is the instance for a game object to equip it with serializable conversion settings.
UnityEngine.Vector3 minimumBound Smaller edge of the volume to scan for
voxels
UnityEngine.Vector3 maximumBound Larger edge of the volume to scan for
voxels
UnityEngine.Vector3 voxelSize Extent of a voxel cell
int resolutionWidth Number of columns in the volume
int resolutionHeight Number of rows in the volume
int resolutionDepth Number of slices in the volume
Voxels.BakingOperation bakingOperationMode Method to process scanned materials /
colors
UnityEngine.Material opaqueTemplate Material to use for non-transparent cells
UnityEngine.Material transparentTemplate Material to use for cells with alpha
value smaller then one
bool mainColorModulation Flag to multiply main color of the
template / default material with scanned
cell one
bool specularColorModulation Flag to multiply specular color of the
template / default material with scanned
cell one
bool emissiveColorModulation Flag to multiply emissive color of the
template / default material with scanned
cell one
float saturationFactor Value makes cell colors more or less
colorful
float brightnessFactor Value makes cell colors brighter or
darker
float budgetTime Target time to limit total computation
per frame to
© 2015 Ronny Burkersroda 9
bool Process(
)
Transfer the game object for voxel conversion to crafting singleton using the applied settings and attached
processors.
Return Value:
true, if processing initialization could be successfully completed.
false, if a failure occurred.
bool Stop(
)
End the conversion of the game object.
Return Value:
true, if game object has been successfully removed from processing.
false, if object is not being processed.
float GetProgress(
)
Read current conversion progress.
Return Value:
> 1, if object is waiting to be processed.
0 … 1, if object is currently being processed.
-1, if object is not included in the processing queue.
void RecomputeBounds(
)
Adopt boundaries of the volume, which is scanned for voxels, from the renderers of the game object and
its children.
bool SetVoxelSize(
float width
float height,
float depth
)
Change the size of a voxel cell in scene space. Calling this function invalids volume resolution values.
Return Value:
true, if arguments are valid.
Parameters:
width Width of a voxel
height Height of a voxel
depth Depth of a voxel
© 2015 Ronny Burkersroda 10
bool SetVolumeResolution(
int width,
int height,
int depth
)
Change the numbers of cell columns, rows and slices of the whole volume. Calling this function invalids
voxel size values.
Return Value:
true, if arguments are valid.
Parameters:
width Cell columns
height Cell rows
depth Cell slices
bool IsVolumeResolutionDefined(
)
Check if volume resolution is set. Otherwise the voxel size is used for generating cells.
Return Value:
true, if volume resolution is used to define number of scanning cells.
false, if voxel size is used to calculate number of scanning cells.
abstract class Voxels.Converter.Processor
This class is used as a base interface to implement functions to handle the voxel data, which had
been collected by the engine right before. You have to derive your own classes from it like
VoxelMesh and VoxelParticleSystem are.
bool process This flag indicates, if the processor is
being executed by the engine.
float Build(
Voxels.Storage voxels,
UnityEngine.Bounds bounds
)
The method is repeatedly called to process incoming data until it signals the completion.
Return Value:
0 … <1 is the current progress. Processing has not been finished.
>=1 signals the end of processing.
Parameters:
voxels Instance containing collected voxel data
bounds Boundaries, which have been used to scan the source object(s) and therefore
define the volume of the data
© 2015 Ronny Burkersroda 11
class Voxels.Converter.Engine
For scanning and transferring the result data to processor classes a singleton of this type is created.
You cannot instantiate it from outside but that is not necessary because the public methods are static
and therefore no object is required to call them.
bool Processing Read-only property returns if the engine
is currently at work
UnityEngine.Bounds ObjectBounds Read-only property returns center and
size of source object, which is currently
being processed
bool Process(
Voxels.Converter converter,
Voxels.Converter.Settings settings,
Voxels.Converter.Processor[] processors
)
Append given voxel converter component altogether with settings and processor instance to waiting
queue and start conversion, if previous entries have been completed or aborted.
Return Value:
true, if converter could be successfully added to the list.
Parameters:
converter Component of the source object, which should be converted
settings Conversion settings
processors Array of processor class instances, which handle the result data
bool Process(
UnityEngine.GameObject source,
Voxels.Converter.Settings settings,
Voxels.Converter.Processor[] processors
)
Append given game object altogether with settings and processor instance to waiting queue and start
conversion, if previous entries have been completed or aborted. There is no converter instance used for
enhanced access.
Return Value:
true, if converter could be successfully added to the list.
Parameters:
source Source object, which should be converted
settings Conversion settings
processors Array of processor class instances, which handle the result data
© 2015 Ronny Burkersroda 12
bool Stop(
Voxels.Converter converter
)
Remove given voxel converter from processing queue.
Return Value:
true, if converter could be found in the waiting list or processing has been stopped.
Parameters:
converter Component of the source object, whose conversion has to be canceled
float GetProgress(
Voxels.Converter voxelConverter
)
Retrieve current conversion progress for given converter instance.
Return Value:
> 1, if object is waiting to be processed.
0 … 1, if object is currently being processed.
-1, if object is not included in the processing queue.
Parameters:
voxelConverter Component of the source object, whose state is requested
bool IsActive(
)
Method answers if the singleton is currently alive.
Return Value:
true, if engine instance exists.
UnityEngine.Bounds ComputeBounds(
UnityEngine.GameObject gameObject
)
Compute the bounding box of the given object and all its children.
Return Value:
Center and half size (Unity standard)
Parameters:
gameObject Top object to be measured
settings Conversion settings
processors Array of processor class instance, which handle the result data
© 2015 Ronny Burkersroda 13
class Voxels.Storage
The result data is filed and can queried using this class.
int Width Read-only property returns number of
cell columns
int Height Read-only property returns number of
cell rows
int Depth Read-only property returns number of
cell slices
int FacesCount Read-only property returns number of
faces per cell (fixed to 6)
int Count Read-only property returns total number
of stored cells
bool SetIndex(
int x,
int y,
int z,
UnityEngine.CubemapFace face,
int index,
int sx = 0,
int sy = 0,
int sz = 0
)
Store the given (material) index for the given direction to the given coordinate.
Return Value:
true, if cell content could be written.
Parameters:
x, y, z Coordinate of the cell in volume space
face Direction of the cell cube plane to store index for
index Value to write
sx, sy, sz Sub-sampling coordinate in cell space
© 2015 Ronny Burkersroda 14
bool SetColor(
int x,
int y,
int z,
UnityEngine.CubemapFace face,
UnityEngine.Color color,
int sx = 0,
int sy = 0,
int sz = 0
)
Store the given color value for the given direction to the given coordinate.
Return Value:
true, if cell content could be written.
Parameters:
x, y, z Coordinate of the cell in volume space
face Direction of the cell cube plane to store index for
color Value to write
sx, sy, sz Sub-sampling coordinate in cell space
bool AddColor(
int x,
int y,
int z,
UnityEngine.CubemapFace face,
UnityEngine.Color color,
int sx = 0,
int sy = 0,
int sz = 0,
Voxels.BakingOperation operationMode = Voxels.BakingOperation.Undefined
)
Include the given color value for the given direction to the given coordinate using the given or the
internally stored baking mode.
Return Value:
true, if cell content could be written.
Parameters:
x, y, z Coordinate of the cell in volume space
face Direction of the cell cube plane to store index for
color Value to account
sx, sy, sz Sub-sampling coordinate in cell space
operationMode Baking operation to use for applying input against existing color
© 2015 Ronny Burkersroda 15
UnityEngine.Material GetMaterial(
int x,
int y,
int z,
Voxels.BakingOperation operationMode = Voxels.BakingOperation.Undefined
int normalized = true
)
Return the source material of the cell or a newly instantiated one with the optionally modulated color of
the voxel.
Return Value:
An existing or a new material instance
Parameters:
x, y, z Coordinate of the cell in volume space
operationMode Baking operation to use for applying input against existing color
normalized Flag to remove pre-multiplication of alpha from red, green and blue
components
class Voxels.HSVColor
It is kind of a helper class to apply color modifications and stores color values as hue, saturation and
value components.
float h Hue component
float s Saturation component
float v Value component
float a Alpha value (inverted transparency)
HSVColor(
float h,
float s,
float v,
[float a]
)
Common constructor to initialize member variables
Parameters:
See member variables
HSVColor(
UnityEngine.Color col
)
Initialize member variables using a RGBA color value as input.
Parameters:
See member variables
© 2015 Ronny Burkersroda 16
UnityEngine.Color ToColor(
)
Build a RGBA color value from instance.
Return Value:
Converted color result
Voxels.HSVColor Lerp(
Voxels.HSVColor a,
Voxels.HSVColor b,
float t
)
Do a linear interpolation between two HSV color values.
Return Value:
Blending result value
Parameters:
a, b Source colors
t Interpolation factor; should be between 0 and 1
© 2015 Ronny Burkersroda 17

More Related Content

PDF
From Experimentation to Production: The Future of WebGL
PDF
Scale free network Visualiuzation
PDF
Voxels for Unity: Rasterizer manual (1.1)
PDF
Voxels for Unity: Rasterizer manual (1.05)
PDF
Voxels: Rasterizer manual (1.2)
PDF
Introduction to Game Programming: Using C# and Unity 3D - Chapter 3 (Preview)
PPT
Gpu presentation
PPTX
03 unity 3_d_part_2
From Experimentation to Production: The Future of WebGL
Scale free network Visualiuzation
Voxels for Unity: Rasterizer manual (1.1)
Voxels for Unity: Rasterizer manual (1.05)
Voxels: Rasterizer manual (1.2)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 3 (Preview)
Gpu presentation
03 unity 3_d_part_2

Similar to Voxels for Unity: Manual (1.0) (20)

PDF
Introduction to Unity by Purdue university
PDF
Markus Tessmann, InnoGames
PPTX
4K Checkerboard in Battlefield 1 and Mass Effect Andromeda
PPTX
Making VR games and experiences in Unreal Engine
PPTX
Making VR Games and Experiences in UE4
PPTX
Making High Quality Interactive VR with Unreal Engine Luis Cataldi
PPTX
Making High Quality Interactive VR with Unreal Engine Luis Cataldi
PPTX
Unity - Internals: memory and performance
PPTX
Grapics debugging with RenderDoc
PDF
Introduction to Game Programming: Using C# and Unity 3D - Chapter 2 (Preview)
PPTX
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
PDF
Shaders - Claudia Doppioslash - Unity With the Best
PPT
Far cry 3
PPTX
Making VR with Unreal Engine Luis Cataldi
PPT
D3 D10 Unleashed New Features And Effects
PPTX
Cross platform physics games - NDC 2014
PDF
Unity Internals: Memory and Performance
PPTX
PDF
[UniteKorea2013] The Unity Rendering Pipeline
PPTX
Extending unity3D Editor
Introduction to Unity by Purdue university
Markus Tessmann, InnoGames
4K Checkerboard in Battlefield 1 and Mass Effect Andromeda
Making VR games and experiences in Unreal Engine
Making VR Games and Experiences in UE4
Making High Quality Interactive VR with Unreal Engine Luis Cataldi
Making High Quality Interactive VR with Unreal Engine Luis Cataldi
Unity - Internals: memory and performance
Grapics debugging with RenderDoc
Introduction to Game Programming: Using C# and Unity 3D - Chapter 2 (Preview)
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Shaders - Claudia Doppioslash - Unity With the Best
Far cry 3
Making VR with Unreal Engine Luis Cataldi
D3 D10 Unleashed New Features And Effects
Cross platform physics games - NDC 2014
Unity Internals: Memory and Performance
[UniteKorea2013] The Unity Rendering Pipeline
Extending unity3D Editor
Ad

Recently uploaded (20)

PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPT
Introduction Database Management System for Course Database
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
Odoo POS Development Services by CandidRoot Solutions
Which alternative to Crystal Reports is best for small or large businesses.pdf
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Design an Analysis of Algorithms II-SECS-1021-03
ManageIQ - Sprint 268 Review - Slide Deck
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Operating system designcfffgfgggggggvggggggggg
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Introduction Database Management System for Course Database
Internet Downloader Manager (IDM) Crack 6.42 Build 41
ISO 45001 Occupational Health and Safety Management System
Wondershare Filmora 15 Crack With Activation Key [2025
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Design an Analysis of Algorithms I-SECS-1021-03
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Understanding Forklifts - TECH EHS Solution
Softaken Excel to vCard Converter Software.pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Ad

Voxels for Unity: Manual (1.0)

  • 2. Table of Contents About....................................................................................................................................................3 Using the editor....................................................................................................................................4 Voxel Converter...............................................................................................................................4 Voxel Mesh......................................................................................................................................5 Voxel Particle System......................................................................................................................6 Using the programming interface.........................................................................................................7 namespace Voxels............................................................................................................................7 class Voxels.Converter.Settings.......................................................................................................7 class Voxels.Converter.....................................................................................................................9 abstract class Voxels.Converter.Processor.....................................................................................11 class Voxels.Converter.Engine.......................................................................................................12 class Voxels.Storage.......................................................................................................................14 class Voxels.HSVColor..................................................................................................................16 © 2015 Ronny Burkersroda 2
  • 3. About “Voxels for Unity” is a plug-in extension for the Unity engine and development environment (www.Unity3D.com). It utilizes the graphics hardware to rasterize renderer objects into a three- dimensional grid instead of a 2D planar surface, which is done to present them on a screen or to compute effects most of all. As opposed to other existing solutions it is able to bake a lot of shading and lighting conditions into the target color of every grid cell at the moment of the processing. Such cells are called voxels, which is a composition of volume and pixels. You can use them to display grid aligned (e.g. blocky) models or particles, which are generated from existing assets. Those particles can be used to create visual effects in combination with the original objects or you transfer the data to an existing voxel engine respectively a rendering framework. The extension is executable in the editor and at runtime and therefore provides an inspector and a programming interface, which can be accessed from other scripts. And the complete package includes two sample processing classes, which are converting the gathered data to visible game objects. One creates a hierarchy of meshes while the other passes the grid elements to a particle system. You are able to adapt the existing examples or write your own processor scripts using the derivation from a base class. Unfortunately not all rendering features can be baked into the final voxel colors because the culling system of Unity hides them in the scanning process. Known issues are dynamic shadow maps and particles. The first one can still be applied to converted voxel objects but cannot be included in the color of the object itself. We are still looking for workarounds or alternative rendering methods to be provide the support in future releases. © 2015 Ronny Burkersroda 3
  • 4. Using the editor Voxel Converter After you have imported the package to your Unity project, you can attach the Voxel Converter plug-in to any game object, even multiple times. In the hierarchy any object under the modified one or the modified one itself should contain a visual component like a mesh renderer or a terrain. Otherwise nothing could be rasterized to the volume grid. You get an inspector for every converter instance. If you turn the switch off, it will not automatically being executed at the start of the scene. Boundaries: Minimum and Maximum are the limiting 3D vectors of the volume in the scene, which is being scanned for voxels. By pressing on the Adopt from object button both values are measured by combining the current bounds of all attached objects. Voxel Size: This is the extent of one grid cell in the space of the scene. Voxel Counts: It describes the number of columns, rows and slices the volume grid contains. Voxel Size and Voxel Counts are affecting one another, where the counts are the outcome of the total volume and the single cell size. Baking Mode: The shaded colors of a source object can be interpreted in various ways. By using Original Material the color is not baked at all. The source material, which is located at a cell, is transferred directly to its voxel. On the contrary Averaged Color, Darkest Color and Brightest Color burn the shaded result color to a material, which is used in association with renderer of the single voxel. Most Frequent Color works similar but does not simply averages all detected cell colors or builds the mini- or maximum of them but filters by the amount of their occurrences. Opaque Template: This option only appears, if you have selected a color baking mode. You can specify a default material, which is used, if the alpha value of the grid cell is 1. This means that the voxel is originally not a transparent one. Without a selection a standard legacy material is created. Transparent Template: Comparable to Opaque Template it allows the choice of a material, which is used for semi-transparent cells, which means that the alpha value is between 0 and 1. Main Color / Specular Color / Emissive Color: Here you can select, which component of the © 2015 Ronny Burkersroda 4 Voxel Converter inspector with all properties Voxel Converter shows the current progress
  • 5. applied material is modulate by the result color of the baking. Saturation: This factor allows the manipulation of the result color by making it more or less colorful. Brightness: A material can be made darker or lighter by modifying it. Process / Processing… / Waiting…: That button starts or stops the conversion of the selected object from the editor. It also shows the current state: Processing… signals that the object is currently being processed and shows the progress, whereas Waiting… represents that another object is currently in conversion and indicates the position in the queue. At runtime the button does not appear and will be replaced by a progress bar during the conversion. Frame Time Target: This is a global setting, which affects all converter instances and adjusts the aimed frame rate. Because the processing cannot be done in real-time it happens in cooperation with the other work load of Unity and your scene. The approximate value allows you to specify to amount of time, which should be used for total processing between two frames, but it can be more in complex scenarios. At last there is a box with some information about the volume size, the grid resolution and maximum count of resulting voxels, if all grid cells would get filled. You can make use of the data to adapt setting for a target specification. Voxel Mesh One of the two sample processor scripts constructs a hierarchy of meshes from the data, which has been collected by the converter instance. That instance transfers gathered voxels to active processor components, which are attached at the same game object like the converter. Enabled: The flag activates the processing of incoming data. Voxel Mesh: You have to select a template, which is used to represent a voxel. Most often a cube might be the general choice. Nevertheless you are able to choose any imported mesh asset like a sphere. But beware of the vertex / polygon count: Thousands of voxels multiplied by thousands of triangles turn into millions of polygons that need to be processed per frame. © 2015 Ronny Burkersroda 5 Voxel Converter inspector at runtime while processing Voxel Mesh inspector
  • 6. Size Factor: That value increases or decreases the extent of one cell mesh, which is normalized to fit the voxel size declared in the converter. Static Containers: It is a flag, which is copied to new game object that will be created during the processing. If you want to animated single voxels, you should turn it off. Merge Meshes: Multiple voxels that share the same material will be merged into larger meshes. So single cells cannot be moved by individual game object transform components any longer but shaders can be used to do so. Opaque Only: Whenever Merge Meshes is enabled that flag skips the combination of voxels, which have got semi-transparent alpha values. This is important if you want to retain the correct blending order from camera view with the standard Unity solution. Target Name: The main container of the target object is named after the string, which is given here. Voxel Particle System The second sample class builds a system of particles using the incoming data. You are able to combine it with other processors, so that the same data is processed into different objects. Enabled: Equally to Voxel Mesh it activates or deactivates the processing of the component. Object Template: That needs to be game object instance with a predefined particle system, which is instantiated as a new one for the target. Size Factor: It is the factor, which is multiplied with the standard particle size of a voxel cell. Target Name: The recently instantiated template gets the stated name. © 2015 Ronny Burkersroda 6 Voxel Particle System inspector
  • 7. Using the programming interface namespace Voxels All structures, enumerations and classes of the extension are collected in that main namespace. struct int int int Vector x y z A vector with a coordinate (column, line, slice) in voxel space enum BakingOperation Undefined OriginalMaterial AveragedColor DarkestColor BrightestColor MostFrequentColor Method to interpret sampled colors per volume cell • Use material of the source object(s) • Apply average, darkest, brightest or most frequent sampled color of a cell to a derived material class Voxels.Converter.Settings This class is used to deliver scanning and properties to the engine. UnityEngine.Bounds bounds Center and size of volume to scan UnityEngine.Vector3 voxelSize Size of a volume cell in scene space Voxels.Vector volumeResolution Number of columns, rows and slices in the scan volume int samplingResolution [not supported yet] Voxels.BakingOperation bakingOperationMode Type of method to use for casting scanned material or color UnityEngine.Material opaqueTemplate A material, which is used to apply non- transparent cell colors to UnityEngine.Material transparentTemplate A material, which is used to apply semi- transparent cell colors to bool mainColorModulation Flag to modulate main color of the instantiated material by the cell content bool specularColorModulation Flag to modulate specular color of the instantiated material by the cell content bool emissiveColorModulation Flag to modulate emissive color of the instantiated material by the cell content © 2015 Ronny Burkersroda 7
  • 8. float saturationFactor Modifies chroma of the cell color float brightnessFactor Modifies luminosity of the cell color float budgetTime Frame time target for that specific conversion (<0 for standard value) There are no other methods beside the two constructors, which are quite similar. One is for setting the size per voxel, the other to use a target resolution for the complete volume. Settings( UnityEngine.Bounds bounds, UnityEngine.Vector3 voxelSize, int samplingResolution, Voxels.BakingOperation bakingOperationMode, UnityEngine.Material opaqueTemplate, UnityEngine.Material tranparentTemplate, bool mainColorModulation, bool specularColorModulation, bool emissiveColorModulation, float saturationFactor, float brightnessFactor, float budgetTime = -1 ) Initialize values including voxel size and set volume resolution to zero, which leads to an automatic calculation. Settings( UnityEngine.Bounds bounds, Voxels.Vector volumeResolution, int samplingResolution, Voxels.BakingOperation bakingOperationMode, UnityEngine.Material opaqueTemplate, UnityEngine.Material tranparentTemplate, bool mainColorModulation, bool specularColorModulation, bool emissiveColorModulation, float saturationFactor, float brightnessFactor, float budgetTime = -1 ) Initialize values including volume resolution and set voxel size to zero, which leads to an automatic calculation. Parameters: See member variables © 2015 Ronny Burkersroda 8
  • 9. class Voxels.Converter That is the instance for a game object to equip it with serializable conversion settings. UnityEngine.Vector3 minimumBound Smaller edge of the volume to scan for voxels UnityEngine.Vector3 maximumBound Larger edge of the volume to scan for voxels UnityEngine.Vector3 voxelSize Extent of a voxel cell int resolutionWidth Number of columns in the volume int resolutionHeight Number of rows in the volume int resolutionDepth Number of slices in the volume Voxels.BakingOperation bakingOperationMode Method to process scanned materials / colors UnityEngine.Material opaqueTemplate Material to use for non-transparent cells UnityEngine.Material transparentTemplate Material to use for cells with alpha value smaller then one bool mainColorModulation Flag to multiply main color of the template / default material with scanned cell one bool specularColorModulation Flag to multiply specular color of the template / default material with scanned cell one bool emissiveColorModulation Flag to multiply emissive color of the template / default material with scanned cell one float saturationFactor Value makes cell colors more or less colorful float brightnessFactor Value makes cell colors brighter or darker float budgetTime Target time to limit total computation per frame to © 2015 Ronny Burkersroda 9
  • 10. bool Process( ) Transfer the game object for voxel conversion to crafting singleton using the applied settings and attached processors. Return Value: true, if processing initialization could be successfully completed. false, if a failure occurred. bool Stop( ) End the conversion of the game object. Return Value: true, if game object has been successfully removed from processing. false, if object is not being processed. float GetProgress( ) Read current conversion progress. Return Value: > 1, if object is waiting to be processed. 0 … 1, if object is currently being processed. -1, if object is not included in the processing queue. void RecomputeBounds( ) Adopt boundaries of the volume, which is scanned for voxels, from the renderers of the game object and its children. bool SetVoxelSize( float width float height, float depth ) Change the size of a voxel cell in scene space. Calling this function invalids volume resolution values. Return Value: true, if arguments are valid. Parameters: width Width of a voxel height Height of a voxel depth Depth of a voxel © 2015 Ronny Burkersroda 10
  • 11. bool SetVolumeResolution( int width, int height, int depth ) Change the numbers of cell columns, rows and slices of the whole volume. Calling this function invalids voxel size values. Return Value: true, if arguments are valid. Parameters: width Cell columns height Cell rows depth Cell slices bool IsVolumeResolutionDefined( ) Check if volume resolution is set. Otherwise the voxel size is used for generating cells. Return Value: true, if volume resolution is used to define number of scanning cells. false, if voxel size is used to calculate number of scanning cells. abstract class Voxels.Converter.Processor This class is used as a base interface to implement functions to handle the voxel data, which had been collected by the engine right before. You have to derive your own classes from it like VoxelMesh and VoxelParticleSystem are. bool process This flag indicates, if the processor is being executed by the engine. float Build( Voxels.Storage voxels, UnityEngine.Bounds bounds ) The method is repeatedly called to process incoming data until it signals the completion. Return Value: 0 … <1 is the current progress. Processing has not been finished. >=1 signals the end of processing. Parameters: voxels Instance containing collected voxel data bounds Boundaries, which have been used to scan the source object(s) and therefore define the volume of the data © 2015 Ronny Burkersroda 11
  • 12. class Voxels.Converter.Engine For scanning and transferring the result data to processor classes a singleton of this type is created. You cannot instantiate it from outside but that is not necessary because the public methods are static and therefore no object is required to call them. bool Processing Read-only property returns if the engine is currently at work UnityEngine.Bounds ObjectBounds Read-only property returns center and size of source object, which is currently being processed bool Process( Voxels.Converter converter, Voxels.Converter.Settings settings, Voxels.Converter.Processor[] processors ) Append given voxel converter component altogether with settings and processor instance to waiting queue and start conversion, if previous entries have been completed or aborted. Return Value: true, if converter could be successfully added to the list. Parameters: converter Component of the source object, which should be converted settings Conversion settings processors Array of processor class instances, which handle the result data bool Process( UnityEngine.GameObject source, Voxels.Converter.Settings settings, Voxels.Converter.Processor[] processors ) Append given game object altogether with settings and processor instance to waiting queue and start conversion, if previous entries have been completed or aborted. There is no converter instance used for enhanced access. Return Value: true, if converter could be successfully added to the list. Parameters: source Source object, which should be converted settings Conversion settings processors Array of processor class instances, which handle the result data © 2015 Ronny Burkersroda 12
  • 13. bool Stop( Voxels.Converter converter ) Remove given voxel converter from processing queue. Return Value: true, if converter could be found in the waiting list or processing has been stopped. Parameters: converter Component of the source object, whose conversion has to be canceled float GetProgress( Voxels.Converter voxelConverter ) Retrieve current conversion progress for given converter instance. Return Value: > 1, if object is waiting to be processed. 0 … 1, if object is currently being processed. -1, if object is not included in the processing queue. Parameters: voxelConverter Component of the source object, whose state is requested bool IsActive( ) Method answers if the singleton is currently alive. Return Value: true, if engine instance exists. UnityEngine.Bounds ComputeBounds( UnityEngine.GameObject gameObject ) Compute the bounding box of the given object and all its children. Return Value: Center and half size (Unity standard) Parameters: gameObject Top object to be measured settings Conversion settings processors Array of processor class instance, which handle the result data © 2015 Ronny Burkersroda 13
  • 14. class Voxels.Storage The result data is filed and can queried using this class. int Width Read-only property returns number of cell columns int Height Read-only property returns number of cell rows int Depth Read-only property returns number of cell slices int FacesCount Read-only property returns number of faces per cell (fixed to 6) int Count Read-only property returns total number of stored cells bool SetIndex( int x, int y, int z, UnityEngine.CubemapFace face, int index, int sx = 0, int sy = 0, int sz = 0 ) Store the given (material) index for the given direction to the given coordinate. Return Value: true, if cell content could be written. Parameters: x, y, z Coordinate of the cell in volume space face Direction of the cell cube plane to store index for index Value to write sx, sy, sz Sub-sampling coordinate in cell space © 2015 Ronny Burkersroda 14
  • 15. bool SetColor( int x, int y, int z, UnityEngine.CubemapFace face, UnityEngine.Color color, int sx = 0, int sy = 0, int sz = 0 ) Store the given color value for the given direction to the given coordinate. Return Value: true, if cell content could be written. Parameters: x, y, z Coordinate of the cell in volume space face Direction of the cell cube plane to store index for color Value to write sx, sy, sz Sub-sampling coordinate in cell space bool AddColor( int x, int y, int z, UnityEngine.CubemapFace face, UnityEngine.Color color, int sx = 0, int sy = 0, int sz = 0, Voxels.BakingOperation operationMode = Voxels.BakingOperation.Undefined ) Include the given color value for the given direction to the given coordinate using the given or the internally stored baking mode. Return Value: true, if cell content could be written. Parameters: x, y, z Coordinate of the cell in volume space face Direction of the cell cube plane to store index for color Value to account sx, sy, sz Sub-sampling coordinate in cell space operationMode Baking operation to use for applying input against existing color © 2015 Ronny Burkersroda 15
  • 16. UnityEngine.Material GetMaterial( int x, int y, int z, Voxels.BakingOperation operationMode = Voxels.BakingOperation.Undefined int normalized = true ) Return the source material of the cell or a newly instantiated one with the optionally modulated color of the voxel. Return Value: An existing or a new material instance Parameters: x, y, z Coordinate of the cell in volume space operationMode Baking operation to use for applying input against existing color normalized Flag to remove pre-multiplication of alpha from red, green and blue components class Voxels.HSVColor It is kind of a helper class to apply color modifications and stores color values as hue, saturation and value components. float h Hue component float s Saturation component float v Value component float a Alpha value (inverted transparency) HSVColor( float h, float s, float v, [float a] ) Common constructor to initialize member variables Parameters: See member variables HSVColor( UnityEngine.Color col ) Initialize member variables using a RGBA color value as input. Parameters: See member variables © 2015 Ronny Burkersroda 16
  • 17. UnityEngine.Color ToColor( ) Build a RGBA color value from instance. Return Value: Converted color result Voxels.HSVColor Lerp( Voxels.HSVColor a, Voxels.HSVColor b, float t ) Do a linear interpolation between two HSV color values. Return Value: Blending result value Parameters: a, b Source colors t Interpolation factor; should be between 0 and 1 © 2015 Ronny Burkersroda 17