WebglMaterialPlugin

View source

ExtendsPlugin

Configures one Material asset type with a supplied 3D vertex and fragment shader pair for WebGL rendering.

The material type must satisfy UniformBind so its instances can provide the values used for WebGL uniforms through UniformBind#asUniformBind.

Examples

import { App } from '@wimaengine/app'
import { DefaultPlugin } from '@wimaengine/misc'
import { WebglMaterialPlugin, WebglRendererPlugin } from '@wimaengine/render-webgl'
import { CustomMaterial } from './custom-material'

const app = new App()
app
  .registerPlugin(new DefaultPlugin())
  .registerPlugin(new WebglRendererPlugin())
  .registerPlugin(new WebglMaterialPlugin({
    material: CustomMaterial, // extends Material and implements asUniformBind()
    vertex3d: vertexSource,
    fragment3d: fragmentSource
  }))
  .run()

Constructor


constructor<T extends Material & UniformBind>(options: WebglMaterialPluginOptions<T>)

View source

Creates a WebGL material configuration from a material constructor and its matching 3D shader sources.

material identifies the asset type; vertex3d and fragment3d provide the shader stages used to render it. The material type must satisfy Material and UniformBind.

Type Parameters

T extends Material & UniformBind

Parameters

NameDescriptionDefault
options

Material constructor and 3D shader source strings.

—

Properties


readonlymaterial: Constructor<T>

View source

Material asset constructor configured for WebGL rendering.

The material type must satisfy both Material and UniformBind. Its UniformBind#asUniformBind method supplies the values bound to the material’s WebGL uniforms.

readonlyvertex3d: string

View source

Vertex-stage shader source for the material’s 3D WebGL pipeline.

Provide a source compatible with the material and its matching fragment3d shader.

readonlyfragment3d: string

View source

Fragment-stage shader source for the material’s 3D WebGL pipeline.

Provide a source compatible with the material and its matching vertex3d shader.

Methods


register(app: App): void

View source

Configures an App to render the material’s 3D opaque pass with the supplied shader pair.

Matching material assets use the material’s UniformBind#asUniformBind values for WebGL uniforms.

Parameters

NameDescriptionDefault
app

App receiving the material and shader configuration.

—

name(): TypeId

View source

Returns the generic plugin ID for this material constructor.

The material constructor distinguishes this plugin’s configuration from configurations for other material types.

Returns

Generic plugin TypeId.