Class Material

The Material provides direct access to the appearance of rendered objects. RSX's standard Material can be used with a powerful physically-based rendering (PBR) model or with a custom Shader where users have full control over the rendering process.

The standard Material supports the following features:

  • Dielectric and metallic workflow for physically-based rendering (PBR).
  • Tangent and Object-Space Normal mapping for detailed surface textures.
  • Effects such as Anisotropy, Clear Coat, Subsurface Scattering, and Sheen.
  • Foliage rendering mode for vegetation and plants.
  • Emissive materials that can glow and illuminate surrounding objects when used in conjuction with GI.
  • Assignment of Texture and SpriteImage resources to material parameters.
  • Support for packed textures with channel control for optimized performance.
  • Shader
  • CarbonMaterial

Hierarchy (view full)

Constructors

  • Creates a new empty material.

    Returns Material

    Make sure you call Material::setShader or Material::setModel before using it.

  • Creates a new material with the specified shader.

    Parameters

    Returns Material

  • Creates a new material with the specified model.

    Parameters

    Returns Material

Accessors

  • get isDestroyed(): boolean
  • Determines if the resource is destroyed.

    Returns boolean

    This can happen when the Resource was forcefully unloaded or reverted. For this reason, it is safer to hold on to a instead of directly referencing a resource pointer, as the current Resource can always be retrieved via .value.

  • get isValid(): boolean
  • Returns boolean

  • get model(): MaterialModel
  • Sets a material model and applies all model parameters to the material.

    Returns MaterialModel

  • set model(value): void
  • Parameters

    Returns void

  • get name(): string
  • Name of the resource. Use primarily for easier identification and not important to the engine itself.

    Returns string

  • get shader(): Shader
  • Sets a shader that will be used by the material. Material will be initialized using all compatible techniques from the shader. Shader must be set before doing any other operations with the material.

    Returns Shader

  • set shader(value): void
  • Sets a shader that will be used by the material. Material will be initialized using all compatible techniques from the shader. Shader must be set before doing any other operations with the material.

    Parameters

    Returns void

  • get shaderHandle(): ResourceHandle<Shader>
  • Sets a shader that will be used by the material. Material will be initialized using all compatible techniques from the shader. Shader must be set before doing any other operations with the material.

    Returns ResourceHandle<Shader>

  • set shaderHandle(value): void
  • Parameters

    Returns void

  • get techniqueCount(): number
  • Returns the total number of techniques supported by this material.

    Returns number

  • get uuid(): UUID
  • Returns a universally unique identifier of this resource.

    Returns UUID

  • get variation(): ShaderVariation
  • Set of parameters that determine which subset of techniques in the assigned shader should be used. Only the techniques that have the provided parameters with the provided values will match. This will control which technique is considered the default technique and which subset of techniques are searched during a call to findTechnique().

    Returns ShaderVariation

  • set variation(value): void
  • Parameters

    Returns void

Methods

  • Compiles the specified variation asynchronously, if the variation is already compiled, the operation will complete immediately.

    Parameters

    • variation: ShaderVariation

      The variation to compile, if unspecified, compiles the material default variation.

    Returns AsyncOp<boolean, void>

  • Dispatch a compute shader using this material asynchronously.

    Parameters

    • groupCountX: number

      The number of thread groups to dispatch in the X dimension.

    • groupCountY: number

      The number of thread groups to dispatch in the Y dimension.

    • groupCountZ: number

      The number of thread groups to dispatch in the Z dimension.

    Returns UncertainAsyncOp<boolean, string>

    A handle to the async operation, which is marked as completed once the dispatch was queued on core.

    This method only queues the dispatch on the core thread, it does not wait for the dispatch to complete. The material must have a compute shader technique for this to work. Otherwise an error will be returned.

  • Duplicates the resource and creates a unique UUID for the duplicated resource.

    Returns Resource

    The duplicated resource or null, if the duplication failed.

  • Returns a boolean value assigned with the parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string

      Parameter name.

    • OptionalarrayIndex: number

      Position index as an array.

    Returns boolean

  • Returns a buffer assigned with the parameter with the specified name.

    Parameters

    • name: string

    Returns GPUBuffer

  • Returns a color assigned with the parameter with the specified name. If a color gradient is assigned to this parameter, returns the gradient color evaluated at time 0.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string
    • OptionalarrayIndex: number

    Returns LinearColor

  • Returns a color gradient assigned with the parameter with the specified name. If the parameter has a constant value bound instead of a gradient then this method returns an empty gradient.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string
    • OptionalarrayIndex: number

    Returns ColorGradientHDR

  • Returns a float value assigned with the parameter with the specified name. If a curve is assigned to this parameter, returns the curve value evaluated at time 0.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string
    • OptionalarrayIndex: number

    Returns number

  • Returns a curve value assigned to the parameter with the specified name. If the parameter has a constant value bound instead of a curve then this method returns an empty curve.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string
    • OptionalarrayIndex: number

    Returns AnimationCurve

  • Returns an integer value assigned with the parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string

      Parameter name.

    • OptionalarrayIndex: number

      Position index as an array.

    Returns number

  • Returns a 3x3 matrix assigned with the parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string
    • OptionalarrayIndex: number

    Returns Matrix3

  • Returns a 4x4 matrix assigned with the parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string
    • OptionalarrayIndex: number

    Returns Matrix4

  • Returns a sampler state assigned with the parameter with the specified name.

    Parameters

    • name: string

    Returns SamplerState

  • Returns a SpriteImage assigned to the material parameter.

    Parameters

    • name: string

      Name of the texture parameter.

    Returns SpriteImage

    SpriteImage assigned to the specified material or null if not found.

  • Parameters

    • name: string

    Returns SpriteImage

  • Returns a texture assigned to the material. If the material has a sprite texture assigned, this will return the parent texture of the sprite.

    Parameters

    • name: string

      Name of the texture parameter.

    Returns Texture

    Texture assigned to the specified material

  • Returns an unsigned integer value assigned with the parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string

      Parameter name.

    • OptionalarrayIndex: number

      Position index as an array.

    Returns number

  • Returns a 2D vector assigned with the parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string
    • OptionalarrayIndex: number

    Returns Vector2

  • Returns a 2D vector assigned with the parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string
    • OptionalarrayIndex: number

    Returns Vector2

  • Returns a 2D vector assigned with the parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string
    • OptionalarrayIndex: number

    Returns Vector2

  • Returns a 3D vector assigned with the parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string
    • OptionalarrayIndex: number

    Returns Vector3

  • Returns a 3D vector assigned with the parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string
    • OptionalarrayIndex: number

    Returns Vector3

  • Returns a 3D vector assigned with the parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string
    • OptionalarrayIndex: number

    Returns Vector3

  • Returns a 4D vector assigned with the parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string
    • OptionalarrayIndex: number

    Returns Vector4

  • Returns a 4D vector assigned with the parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string
    • OptionalarrayIndex: number

    Returns Vector4

  • Returns a 4D vector assigned with the parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index you which to retrieve.

    Parameters

    • name: string
    • OptionalarrayIndex: number

    Returns Vector4

  • Checks does the data parameter with the specified name currently contains animated data. This could be an animation curve or a color gradient.

    Parameters

    • name: string
    • OptionalarrayIndex: number

    Returns boolean

  • Virtual

    Method called by RSX to perform actions required after the creation of the resource.

    Returns void

  • Virtual

    Method called by RSX to perform any operations needed after deserialization.

    Returns void

    Use this API to restore your serializable data into live objects.

  • Virtual

    Method called by RSX to disable the resource.

    Returns void

    Use this API to deactivate the resource before it is serialized.

  • Virtual

    Method called by RSX to enable the resource.

    Returns void

    Use this API to activate the resource after it has been disabled by serialization.

  • Virtual

    Method called by RSX to perform initialization of the resource.

    Returns void

    Use this API to initialize data and default construct all fields.

  • Virtual

    Method called by RSX to perform any operations before serialization.

    Returns void

    Use this API to bake your live data into serializable data.

  • Reverts the resource to the on-disk representation.

    Returns boolean

    This is a potentially expensive call, as it needs to deserialize and replace all existing in-memory resource handles.

  • Assigns a boolean value to the shader parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    • name: string
    • value: boolean
    • OptionalarrayIndex: number

    Returns void

  • Assigns a buffer to the shader parameter with the specified name.

    Parameters

    Returns void

  • Assigns a color to the shader parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    Returns void

  • Assigns a color gradient to the shader parameter with the specified name. The system will automatically evaluate the gradient with the passage of time and apply the evaluated value to the parameter.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    Returns void

  • Assigns a float value to the shader parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    • name: string
    • value: number
    • OptionalarrayIndex: number

    Returns void

  • Parameters

    Returns void

  • Assigns an integer value to the shader parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    • name: string
    • value: number
    • OptionalarrayIndex: number

    Returns void

  • Assigns a 3x3 matrix to the shader parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    Returns void

  • Assigns a 4x4 matrix to the shader parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    Returns void

  • Assigns a sampler state to the shader parameter with the specified name.

    Parameters

    Returns void

  • Assigns a SpriteImage to the specified material parameter. The sprite image is allowed to be animated, or just used for referencing a subset of a texture atlas.

    Parameters

    Returns void

  • Assigns a texture to the specified material parameter.

    Parameters

    Returns void

  • Assigns a texture to the specified material parameter. Allows you to specify a surface parameter that allows you to bind only a sub-set of the texture.

    Parameters

    Returns void

  • Assigns an unsigned integer value to the shader parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    • name: string
    • value: number
    • OptionalarrayIndex: number

    Returns void

  • Assigns a 2D vector to the shader parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    Returns void

  • Assigns a 2D vector to the shader parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    Returns void

  • Assigns a 2D vector to the shader parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    Returns void

  • Assigns a 3D vector to the shader parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    Returns void

  • Assigns a 3D vector to the shader parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    Returns void

  • Assigns a 3D vector to the shader parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    Returns void

  • Assigns a 4D vector to the shader parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    Returns void

  • Assigns a 4D vector to the shader parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    Returns void

  • Assigns a 4D vector to the shader parameter with the specified name.

    Optionally if the parameter is an array you may provide an array index to assign the value to.

    Parameters

    Returns void