Interface MaterialExtension

Material extension interface This is used to extend a three.js material satisfying the IMaterial interface, with extra uniforms, defines, shader code, etc.

interface MaterialExtension {
    __setDirty?: () => void;
    computeCacheKey?: string | (material: IMaterial) => string;
    extraDefines?: Record<
        string,
        ValOrFunc<undefined | string | number | boolean>,
    >;
    extraUniforms?: { [uniform: string]: ValOrFunc<IUniform> };
    getUiConfig?: (
        material: IMaterial,
        refreshUi?: (
            deep?: boolean,
            mode?: TUiRefreshModes | "immediate",
            delay?: number,
        ) => void,
    ) => undefined | UiObjectConfig;
    isCompatible: (material: IMaterial) => boolean;
    onAfterRender?: (
        object: Object3D,
        material: IMaterial,
        renderer: IWebGLRenderer,
    ) => void;
    onObjectRender?: (
        object: Object3D,
        material: IMaterial,
        renderer: IWebGLRenderer,
    ) => void;
    parsFragmentSnippet?:
        | string
        | (renderer?: WebGLRenderer, material?: IMaterial) => string;
    parsVertexSnippet?:
        | string
        | (renderer?: WebGLRenderer, material?: IMaterial) => string;
    priority?: number;
    setDirty?: () => void;
    shaderExtender?: (
        shader: Shader & { defines: any; extensionDerivatives?: boolean },
        material: IMaterial,
        renderer: WebGLRenderer,
    ) => void;
    updaters?: IShaderPropertiesUpdater[] | () => IShaderPropertiesUpdater[];
    updateVersion?: number;
    uuid?: string;
}

Implemented by

Properties

__setDirty?: () => void
computeCacheKey?: string | (material: IMaterial) => string

Custom cache key to use for this material extension. A different cache key will cause the shader to be recompiled. Check three.js docs for more info. Value can be a string or a function that returns a string This will only be checked if material.needsUpdate is true, not on every render. Note: extension might never be registered if an empty string is returned.

extraDefines?: Record<string, ValOrFunc<undefined | string | number | boolean>>

Extra defines to copy to material Note: boolean are converted to 0 and 1

extraUniforms?: { [uniform: string]: ValOrFunc<IUniform> }

Extra uniforms to copy to material

getUiConfig?: (
    material: IMaterial,
    refreshUi?: (
        deep?: boolean,
        mode?: TUiRefreshModes | "immediate",
        delay?: number,
    ) => void,
) => undefined | UiObjectConfig

Function to return the UI config for this material extension. This is called once when the material extension is registered.

isCompatible: (material: IMaterial) => boolean

Function to check if this material extension is compatible with the given material. If not compatible, the material extension will not be applied. This is only checked when the extension is registered.

onAfterRender?: (
    object: Object3D,
    material: IMaterial,
    renderer: IWebGLRenderer,
) => void

Custom callback to run code after the material is rendered Executes from material.onAfterRender for each material for each object it's rendered on.

onObjectRender?: (
    object: Object3D,
    material: IMaterial,
    renderer: IWebGLRenderer,
) => void

Custom callback to run code before the material is rendered Executes from material.onBeforeRender for each material for each object it's rendered on.

parsFragmentSnippet?:
    | string
    | (renderer?: WebGLRenderer, material?: IMaterial) => string

Extra code to add to the top of the fragment shader Value can be a string or a function that returns a string

parsVertexSnippet?:
    | string
    | (renderer?: WebGLRenderer, material?: IMaterial) => string

Extra code to add to the top of the vertex shader Value can be a string or a function that returns a string

priority?: number

Higher priority extensions are applied first.

setDirty?: () => void
shaderExtender?: (
    shader: Shader & { defines: any; extensionDerivatives?: boolean },
    material: IMaterial,
    renderer: WebGLRenderer,
) => void

Custom callback to extend/modify/replace shader code and other shader properties

List of shader properties updaters to run on the material.

updateVersion?: number
uuid?: string