VoxelGeneratorGraph
Graph-based voxel generator.
Graph-based voxel generator.
Generates voxel data from a graph of per-voxel operations. The graph must be created, compiled, and only then blocks can be generated. It can be used with SDF-based smooth terrain, and also blocky terrains. Warning: methods to modify the graph should only be called from the main thread.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
VoxelGeneratorGraphConstructor
public VoxelGeneratorGraph();Properties8
DebugBlockClippingProperty
public bool DebugBlockClipping { get; set; }When enabled, if the graph outputs SDF data, generated blocks that would otherwise be clipped will be inverted. This has the effect of them showing up as "walls artifacts", which is useful to visualize where the optimization occurs.
GraphDataProperty
public Reckfell.Collections.Dictionary GraphData { get; set; }SdfClipThresholdProperty
public float SdfClipThreshold { get; set; }When generating SDF blocks for a terrain, if the range analysis of a block is beyond this threshold, its SDF data will be considered either fully air, or fully matter (using high constants, positive or negative). This optimizes memory because chunks entirely underground or in the air will have the same value on every voxel. It also saves processing time because SDF calculations (noise etc) are skipped. To turn off this optimization, set it to a high value.
Downside: if you use operations to edit the terrain assuming coherent SDF, they might behave incorrectly at boundaries where the clipping starts to occur. This is notably the case of VoxelTool.GrowSphere.
SubdivisionSizeProperty
public int SubdivisionSize { get; set; }When generating SDF blocks for a terrain, and if block size is divisible by this value, range analysis will operate on such subdivision. This allows to optimize away more precise areas. However, it may not be set too small otherwise overhead will outweight the benefits.
TextureModeProperty
public VoxelGeneratorGraph.TextureModeEnum TextureMode { get; set; }Sets which voxel format will be produced by texture outputs, if present.
UseOptimizedExecutionMapProperty
public bool UseOptimizedExecutionMap { get; set; }If enabled, when generating blocks for a terrain, the generator will attempt to skip specific nodes if they are found to have no importance in specific areas.
UseSubdivisionProperty
public bool UseSubdivision { get; set; }If enabled, VoxelGeneratorGraph.SubdivisionSize will be used.
UseXzCachingProperty
public bool UseXzCaching { get; set; }If enabled, the generator will run only once branches of the graph that only depend on X and Z. This is effective when part of the graph generates a heightmap, as this part is not volumetric.
Methods24
BakeSphereBumpmapvoid
public void BakeSphereBumpmap(Image im, float refRadius, float sdfMin, float sdfMax);Bakes a spherical bumpmap (or heightmap) using SDF output produced by the generator, if any. The bumpmap uses a panorama projection.
ref_radius: radius of the sphere on which heights will be sampled.
strength: strength of produced normals, may default to 1.0.
| Name | Type | Default |
|---|---|---|
im | Image | — |
refRadius | float | — |
sdfMin | float | — |
sdfMax | float | — |
BakeSphereNormalmapvoid
public void BakeSphereNormalmap(Image im, float refRadius, float strength);Bakes a spherical normalmap using SDF output produced by the generator, if any. The normalmap uses a panorama projection. It is assumed the generator produces a spherical shape (like a planet). Such normalmap can be used to add more detail to distant views of a terrain using this generator.
ref_radius: radius of the sphere on which normals will be sampled.
strength: strength of produced normals, may default to 1.0.
Note: an alternative is to use distance normals feature with VoxelLodTerrain.
| Name | Type | Default |
|---|---|---|
im | Image | — |
refRadius | float | — |
strength | float | — |
Clearvoid
public void Clear();Erases all nodes and connections from the graph.
CompileReckfell.Collections.Dictionary
public Reckfell.Collections.Dictionary Compile();Compiles the graph so it can be used to generate blocks. If it succeeds, the returned result is a dictionary with the following layout:
{
"success": true
}If it fails, the returned result may contain a message and the ID of a graph node that could be the cause:
{
"success": false,
"node_id": int,
"message": String
}The node ID will be -1 if the error is not about a particular node.
Reckfell.Collections.DictionaryDebugAnalyzeRangeVector2
public Vector2 DebugAnalyzeRange(Vector3 minPos, Vector3 maxPos);| Name | Type | Default |
|---|---|---|
minPos | Vector3 | — |
maxPos | Vector3 | — |
Vector2DebugLoadWavesPresetvoid
public void DebugLoadWavesPreset();DebugMeasureMicrosecondsPerVoxelfloat
public float DebugMeasureMicrosecondsPerVoxel(bool useSingularQueries);| Name | Type | Default |
|---|---|---|
useSingularQueries | bool | — |
floatGenerateImageFromSdfvoid
public void GenerateImageFromSdf(Image im, Transform3D transform, Vector2 size);Genereates SDF data within a plane centered on the given transform spanning its X and Y axes, and stores results in pixels of the image. Samples are centered on pixels. The image should preferably have a 32-bit float format, and must not be compressed.
| Name | Type | Default |
|---|---|---|
im | Image | — |
transform | Transform3D | — |
size | Vector2 | — |
GetMainFunctionVoxelGraphFunction
public VoxelGraphFunction GetMainFunction();Gets the graph used for generation.
VoxelGraphFunctionGetSdfClipThresholdfloat
public float GetSdfClipThreshold();floatGetSubdivisionSizeint
public int GetSubdivisionSize();intGetTextureModeVoxelGeneratorGraph.TextureModeEnum
public VoxelGeneratorGraph.TextureModeEnum GetTextureMode();VoxelGeneratorGraph.TextureModeEnumIsDebugClippedBlocksbool
public bool IsDebugClippedBlocks();boolIsUsingOptimizedExecutionMapbool
public bool IsUsingOptimizedExecutionMap();boolIsUsingSubdivisionbool
public bool IsUsingSubdivision();boolIsUsingXzCachingbool
public bool IsUsingXzCaching();boolRaycastSdfApproxfloat
public float RaycastSdfApprox(Vector3 rayOrigin, Vector3 rayEnd, float stride);Generates values along a ray to find the first one where SDF < 0.0, and return distance along the ray. If no hit is found, returns -1.0. This is an approximation: the error margin of the returned value will be up to the given stride. The longer the distance, the more expensive it is. The lower the stride, the more expensive and accurate it is.
| Name | Type | Default |
|---|---|---|
rayOrigin | Vector3 | — |
rayEnd | Vector3 | — |
stride | float | — |
floatSetDebugClippedBlocksvoid
public void SetDebugClippedBlocks(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetSdfClipThresholdvoid
public void SetSdfClipThreshold(float threshold);| Name | Type | Default |
|---|---|---|
threshold | float | — |
SetSubdivisionSizevoid
public void SetSubdivisionSize(int size);| Name | Type | Default |
|---|---|---|
size | int | — |
SetTextureModevoid
public void SetTextureMode(VoxelGeneratorGraph.TextureModeEnum mode);| Name | Type | Default |
|---|---|---|
mode | VoxelGeneratorGraph.TextureModeEnum | — |
SetUseOptimizedExecutionMapvoid
public void SetUseOptimizedExecutionMap(bool use);| Name | Type | Default |
|---|---|---|
use | bool | — |
SetUseSubdivisionvoid
public void SetUseSubdivision(bool use);| Name | Type | Default |
|---|---|---|
use | bool | — |
SetUseXzCachingvoid
public void SetUseXzCaching(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
Signals and events1
NodeNameChangedEvent
public event VoxelGeneratorGraph.NodeNameChangedEventHandler NodeNameChanged;| Name | Type | Default |
|---|---|---|
nodeId | long | — |
VoxelGeneratorGraph.TextureModeEnum
| Value | Description |
|---|---|
Mixel4 = 0 | Writes texture data into |
Single = 1 | Writes texture data into |