Class VolumeLayout

java.lang.Object
gaiasky.render.gdx.graphics.VolumeLayout

public final class VolumeLayout extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Length in floats of one field in the packed array.
    static final int
    Number of fields summed into one slot.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    static boolean
    canReuse(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 boolean
    canReuse(VolumeTexture existing, VoxelGrid grid)
    Whether a texture can be refilled for the given grid instead of a new one being allocated.
    static float[]
    gridCell(double lateralHalf, double verticalHalf, VoxelGrid grid)
    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 boolean
    slotIsOcclusive(List<? extends GalaxyAttributes> fields, int count)
    Whether the slot stores density (occluding) rather than light.
    static int
    usableCount(List<? extends GalaxyAttributes> fields)
    Number of fields a slot can hold, with a warning when it declares more.
    static void
    warnOnPitch(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.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_FIELDS

      public static final int MAX_FIELDS
      Number of fields summed into one slot. Mirrors GX_MAX_FIELDS.
      See Also:
    • FIELD_STRIDE

      public static final int FIELD_STRIDE
      Length in floats of one field in the packed array. Mirrors GX_FIELD_STRIDE.
      See Also:
  • Method Details

    • packFields

      public static float[] packFields(List<? extends GalaxyAttributes> fields, int count)
      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 most MAX_FIELDS.
      Returns:
      An array of MAX_FIELDS * FIELD_STRIDE floats.
    • usableCount

      public static int usableCount(List<? extends GalaxyAttributes> fields)
      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

      public static boolean slotIsOcclusive(List<? extends GalaxyAttributes> fields, int count)
      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

      public static void warnOnPitch(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.
      Parameters:
      fields - The fields of the slot.
      count - How many of them to check.
    • gridOrigin

      public static float[] gridOrigin(double lateralHalf, double verticalHalf, VoxelGrid grid)
      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

      public static float[] gridCell(double lateralHalf, double verticalHalf, VoxelGrid grid)
      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

      public static boolean canReuse(VolumeTexture existing, VoxelGrid grid)
      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 existing can receive the new content.
    • canReuse

      public static boolean canReuse(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. Split out from canReuse(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.