Class VolumeLayout
java.lang.Object
gaiasky.render.gdx.graphics.VolumeLayout
The parts of the volume generation that do not depend on which backend evaluates the field: the
packing of the fields into the flat array the shader and the CPU port both read, the geometry of
the sampling grid inside the volume's box, and the validation the two backends have to agree on.
Everything here is a mirror of a piece of assets/shader/compute/galgen.volume.comp.glsl or
of assets/shader/lib/galaxy.glsl, and is shared so that the GPU and the CPU voxeliser
cannot disagree about where a voxel is or which field parameter lives where.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intLength in floats of one field in the packed array.static final intNumber of fields summed into one slot. -
Method Summary
Modifier and TypeMethodDescriptionstatic float[]boxFor(double lateralHalf, double verticalHalf) The volume's box in object-size units:{-x,-y,-z, +x,+y,+z}, centred, with the lateral half-extent at exactly 0.5 so that the largest axis spans the object's size.static booleancanReuse(int width, int height, int depth, VolumeType type, VoxelGrid grid) Whether a texture of the given shape can receive a generation of the given grid.static booleancanReuse(VolumeTexture existing, VoxelGrid grid) Whether a texture can be refilled for the given grid instead of a new one being allocated.static float[]Galaxy-space size of one voxel on each axis.static float[]gridOrigin(double lateralHalf, double verticalHalf, VoxelGrid grid) Centre of voxel (0, 0, 0) in galaxy space.static float[]packFields(List<? extends GalaxyAttributes> fields, int count) Packs the slot's fields into the flat array the field evaluator reads.static booleanslotIsOcclusive(List<? extends GalaxyAttributes> fields, int count) Whether the slot stores density (occluding) rather than light.static intusableCount(List<? extends GalaxyAttributes> fields) Number of fields a slot can hold, with a warning when it declares more.static voidwarnOnPitch(List<? extends GalaxyAttributes> fields, int count) Warns about a spiral whose pitch is too small for its radial span: it comes out as a set of radial spokes rather than a spiral, and it looks like a cross.
-
Field Details
-
MAX_FIELDS
public static final int MAX_FIELDSNumber of fields summed into one slot. MirrorsGX_MAX_FIELDS.- See Also:
-
FIELD_STRIDE
public static final int FIELD_STRIDELength in floats of one field in the packed array. MirrorsGX_FIELD_STRIDE.- See Also:
-
-
Method Details
-
packFields
Packs the slot's fields into the flat array the field evaluator reads.- Parameters:
fields- The fields, in slot order.count- How many of them to pack, at mostMAX_FIELDS.- Returns:
- An array of
MAX_FIELDS * FIELD_STRIDEfloats.
-
usableCount
Number of fields a slot can hold, with a warning when it declares more.- Parameters:
fields- The fields of the slot.- Returns:
- The count to use, at most
MAX_FIELDS.
-
slotIsOcclusive
Whether the slot stores density (occluding) rather than light. One slot holds either, never both: the alpha channel has a single interpretation, so a mixed slot is a descriptor mistake and the first field decides.- Parameters:
fields- The fields of the slot.count- How many of them to look at.- Returns:
- True if the slot occludes.
-
warnOnPitch
Warns about a spiral whose pitch is too small for its radial span: it comes out as a set of radial spokes rather than a spiral, and it looks like a cross.- Parameters:
fields- The fields of the slot.count- How many of them to check.
-
gridOrigin
Centre of voxel (0, 0, 0) in galaxy space.The box is centred on the origin, so this is the near corner plus half a cell - the field is evaluated at
origin + voxel * cell, which is what keeps the field's symmetry (and the spiral's winding) aligned with the texture's.- Parameters:
lateralHalf- Half-extent along x and z, in galaxy space.verticalHalf- Half-extent along y.grid- The grid being filled.- Returns:
{x, y, z}of the centre of the first voxel.
-
gridCell
Galaxy-space size of one voxel on each axis. Not uniform: the grid is thinner than it is wide.- Parameters:
lateralHalf- Half-extent along x and z.verticalHalf- Half-extent along y.grid- The grid being filled.- Returns:
{x, y, z}voxel sizes.
-
boxFor
public static float[] boxFor(double lateralHalf, double verticalHalf) The volume's box in object-size units:{-x,-y,-z, +x,+y,+z}, centred, with the lateral half-extent at exactly 0.5 so that the largest axis spans the object's size. The vertical one follows the fields' aspect, so a flat galaxy gets a flat box.- Parameters:
lateralHalf- Half-extent along x and z, in galaxy space.verticalHalf- Half-extent along y, in galaxy space.- Returns:
- The six corners of the box.
-
canReuse
Whether a texture can be refilled for the given grid instead of a new one being allocated.The dimensions and the storage format have to match exactly: one texel is written per voxel of the grid, so a texture of another size would be written past its end.
- Parameters:
existing- The texture currently bound to the slot, or null.grid- The grid about to be generated.- Returns:
- True if
existingcan receive the new content.
-
canReuse
Whether a texture of the given shape can receive a generation of the given grid. Split out fromcanReuse(VolumeTexture, VoxelGrid)so that the decision can be tested without a texture, which needs a GL context.- Parameters:
width- The texture's extent on the first axis.height- The texture's extent on the second axis.depth- The texture's extent on the third axis.type- The texture's storage format.grid- The grid about to be generated.- Returns:
- True if the content fits.
-