Shader

View source

Represents a render-core shader asset value as a shader-stage and source pair.

Use this value to keep shader-language source associated with a ShaderStage for storage and rendering.

Examples

import { Shader, ShaderStage } from '@wimaengine/render-core'

const vertex = new Shader(
  ShaderStage.Vertex,
  'void main() { gl_Position = vec4(0.0); }'
)
const restored = Shader.deserialize(Shader.serialize(vertex))
console.log(restored.stage === ShaderStage.Vertex, restored.source)

Constructor


constructor(stage: number, source: string)

View source

Creates a shader asset value from a stage and source string.

This constructor stores both arguments without compiling or validating the source.

Parameters

NameDescriptionDefault
stage——
source——

Properties


source: string

View source

Shader-language source code for this stage.

The string is stored as supplied; Shader does not compile or transform it.

Methods


staticserialize(value: Shader): ShaderSerial

View source

Converts a shader to its serializable stage/source pair.

The returned object contains the current stage and source values without compiling or otherwise transforming the source.

Parameters

NameDescriptionDefault
value——

staticdeserialize(value: ShaderSerial, out?: Shader): Shader

View source

Populates a shader from serialized stage/source data.

When out is supplied, its two fields are replaced and the same object is returned. Otherwise the method creates an empty shader with Shader.default and populates it. This method copies values only; it does not compile or validate the source.

Parameters

NameDescriptionDefault
value——
out?—...

Returns

The populated shader.

staticvalidateSerial(value: unknown): value is ShaderSerial

View source

Checks the shape and primitive field types accepted for shader data.

The check requires a numeric stage and string source; it does not verify that the stage number is one of the values in ShaderStage.

Parameters

NameDescriptionDefault
value——