Class InstancedRenderSystem

All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable, IObserver, IRenderSystem, Comparable<IRenderSystem>
Direct Known Subclasses:
BillboardProceduralCPURenderer, BillboardSetRenderer, ElementsSetRenderer, ParticleSetInstancedRenderer, StarSetInstancedRenderer, VariableSetInstancedRenderer

public abstract class InstancedRenderSystem extends ImmediateModeRenderSystem implements IObserver
  • Field Details

    • models

      protected com.badlogic.gdx.utils.Array<InstancedRenderSystem.InstancedModel> models
      Instanced model list, one per particle group.
    • utils

      protected final ParticleUtils utils
      Particle utils instance.
    • aux

      protected final com.badlogic.gdx.math.Matrix4 aux
      Auxiliary matrix.
    • refSysTransformF

      protected final com.badlogic.gdx.math.Matrix4 refSysTransformF
      Auxiliary reference system transform matrix.
  • Constructor Details

  • Method Details

    • initVertices

      protected void initVertices()
      Specified by:
      initVertices in class ImmediateModeRenderSystem
    • isWireframe

      public boolean isWireframe(int primitive)
    • setModel

      protected void setModel(int offset, InstancedRenderSystem.InstancedModel model)
    • getModel

      protected InstancedRenderSystem.InstancedModel getModel(ParticleSet set, int offset)
    • getModelQuad

      protected InstancedRenderSystem.InstancedModel getModelQuad(int primitive, int offset)
    • getModel

      protected InstancedRenderSystem.InstancedModel getModel(IntModel modelFile, String modelType, Map<String,Object> modelParams, int primitive, int offset)
    • addAttributesDivisor0

      protected void addAttributesDivisor0(com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.VertexAttribute> attributes, int posArraySize, boolean useNormals, boolean useTexCoords)
      Adds the required vertex attributes for this renderer to the given list. These attributes are added only once for all instances (divisor=0)
      Parameters:
      attributes - The list of attributes with divisor=0
      posArraySize - Size of the position array (2 or 3).
      useNormals - Add normal attributes as a vector-3.
      useTexCoords - Add texture coordinates attribute as a vector-2.
    • addAttributesDivisor1

      protected abstract void addAttributesDivisor1(com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.VertexAttribute> attributes, int primitive)
      Adds the required vertex attributes for this renderer to the given list. These attributes are added for every instance (divisor=1)
      Parameters:
      attributes - The list of attributes with divisor=1
      primitive - The rendering primitive.
    • buildAttributesDivisor0

      protected com.badlogic.gdx.graphics.VertexAttribute[] buildAttributesDivisor0(int posArraySize, boolean useNormals, boolean useTexCoords)
      Builds the vertex attributes with divisor=0 array and returns it. The content of divisor-0 attributes is updated in each iteration of the vertex shader.
      Parameters:
      posArraySize - Size of the position array (2 or 3).
      useNormals - Add normal attributes as a vector-3.
      useTexCoords - Add texture coordinates attribute as a vector-2.
      Returns:
      The vertex attributes array
    • buildAttributesDivisor1

      protected com.badlogic.gdx.graphics.VertexAttribute[] buildAttributesDivisor1(int primitive)
      Builds the vertex attributes with divisor=1 array and returns it The content of divisor-1 attributes is updated for each instance.
      Parameters:
      primitive - The rendering primitive.
      Returns:
      The vertex attributes array.
    • offsets0

      protected abstract void offsets0(ImmediateModeRenderSystem.MeshData curr, InstancedRenderSystem.InstancedModel model)
      Computes the offset for each vertex attribute. The offsets will be used later in the render stage.
      Parameters:
      curr - The current mesh data.
      model - The instanced model.
    • offsets1

      protected abstract void offsets1(ImmediateModeRenderSystem.MeshData curr, InstancedRenderSystem.InstancedModel model)
      Computes the offset for each vertex attribute in the instanced array. The offsets will be used later in the render stage.
      Parameters:
      curr - The current mesh data.
      model - The instanced model.
    • addMeshData

      protected int addMeshData(InstancedRenderSystem.InstancedModel model, int maxVerts, int maxInstances, int maxIndices, String modelType, int primitive)
      Adds a new mesh data to the meshes list and increases the mesh data index.
      Parameters:
      model - The instanced model instance.
      maxVerts - The max number of vertices the divisor 0 mesh data can hold.
      maxInstances - The max number of vertices the divisor 1 mesh data can hold.
      modelType - The model type string.
      primitive - The rendering primitive.
      Returns:
      The index of the new mesh data.
    • addMeshData

      protected int addMeshData(InstancedRenderSystem.InstancedModel model, int maxVerts, int maxInstances, int maxIndices, String modelFile, String modelType, int primitive)
      Adds a new mesh data to the meshes list and increases the mesh data index.
      Parameters:
      model - The instanced model instance.
      maxVerts - The max number of vertices the divisor 0 mesh data can hold.
      maxInstances - The max number of vertices the divisor 1 mesh data can hold.
      modelFile - The model file, if any.
      modelType - The model type string.
      primitive - The rendering primitive.
      Returns:
      The index of the new mesh data.
    • preRenderObjects

      protected void preRenderObjects(ExtShaderProgram shaderProgram, ICamera camera)
    • renderObject

      protected void renderObject(ExtShaderProgram shaderProgram, ICamera camera, IRenderable renderable)
    • postRenderObjects

      protected void postRenderObjects(ExtShaderProgram shaderProgram, ICamera camera)
    • renderStud

      public void renderStud(List<IRenderable> renderables, ICamera camera, double t)
      Specified by:
      renderStud in class AbstractRenderSystem
    • generateChannelNoise

      protected void generateChannelNoise(long seed, double noise, float[] result)
      Generates color noise per channel, given a seed and an (n).
      Parameters:
      seed - The seed for the RNG.
      noise - The noise value in [0,1].
      result - The result array.
    • preShadingType

      protected int preShadingType(Highlight hl, ParticleSet.ShadingType shadingType)
      Apply blending mode and depth mask depending on the highlight component and shading type.
      Parameters:
      hl - The highlight component.
      shadingType - The shading type.
      Returns:
      The ordinal shading type.
    • postShadingType

      protected void postShadingType()
      Restore regular blending and depth writes.
    • getProfileDecay

      protected float getProfileDecay(int shadingType, float profileDecay)
      Returns the profile decay for the given shading type.
      Parameters:
      shadingType - The shading type.
      profileDecay - The profile decay.
      Returns:
      The effective profile decay.
    • setShadingTypeUniforms

      protected void setShadingTypeUniforms(ExtShaderProgram shaderProgram, ICamera camera, int shadingType, float sphericalPower, float ambient, GraphNode graph)
      Sets uniforms pertaining to the shading type.
      Parameters:
      shaderProgram - The program.
      shadingType - The shading type ordinal.
      sphericalPower - The spherical power value.
    • setRefSysTransformAndDatasetPosUniforms

      protected void setRefSysTransformAndDatasetPosUniforms(ExtShaderProgram shaderProgram, GraphNode graph, ParticleSet set)
    • computeTextureIndex

      public static int computeTextureIndex(IParticleRecord pr, Random rand, com.badlogic.gdx.graphics.TextureArray textureArray, String textureAttribute)
      Computes the texture index for a given particle, for particle and orbital elements sets, given their texture array and texture attribute.
      Parameters:
      pr - The particle record
      rand - The RNG.
      textureArray - The texture array. May be null.
      textureAttribute - The texture attribute. May be null.
      Returns:
      The texture index for the given particle.