constructor(stage: number, source: string)
View sourceCreates a shader asset value from a stage and source string.
This constructor stores both arguments without compiling or validating the source.
Class
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.
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(stage: number, source: string)Creates a shader asset value from a stage and source string.
This constructor stores both arguments without compiling or validating the source.
Shader stage represented by this asset.
Use a value from ShaderStage, such as
ShaderStage.Vertex or ShaderStage.Fragment. The
constructor stores the supplied value.
Shader-language source code for this stage.
The string is stored as supplied; Shader does not compile or
transform it.
default(): ShaderCreates an empty fragment-stage shader.
serialize(value: Shader): ShaderSerialConverts 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.
deserialize(value: ShaderSerial, out?: Shader): ShaderPopulates 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.
validateSerial(value: unknown): value is ShaderSerialChecks 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.