Shader

self:remove_from_material

Client

Removes a shader assignment previously made with `self:apply_to_material`

Syntax

local count = self:remove_from_material(
    model,
    component,
    material
)

Surfaces fall back to the next best shader.

  • What is removed — this shader's own assignments on the given target that are covered by component and material. "*" covers everything, so self:remove_from_material(model, "*", "*") removes all of them.
  • Fallback — each affected surface is handed to the next best assignment (highest priority, then most recently applied) and returns to its original material only when no other shader covers it.
  • Target — a model instance removes assignments made for that model. "*" / nil removes assignments made with "*". The two do not affect each other.

Parameters

TypeNameDescription
model | string | nilmodelModel instance to remove from
Use "*" / nil to remove the persistent assignment made for every model
stringcomponentMesh component name or wildcard pattern to match
stringmaterialSurface material name or wildcard pattern to match

Returns

TypeNameDescription
intcountNumber of surfaces that were handed to another shader or restored

Examples

Remove a shader from one model
core.model.load("character", "models/character.glb")

local model = core.model.create("character")
local entity = core.shader.create("assets/shaders/dissolve.glsl", core.shader.shader_mode.SPATIAL)

entity:apply_to_material(model, "*", "*")
entity:remove_from_material(model, "*", "*")
Remove a persistent shader assignment from all models
local entity = core.shader.create("assets/shaders/dissolve.glsl", core.shader.shader_mode.SPATIAL)

entity:remove_from_material("*", "*", "*")
Fall back to the previous shader
core.model.load("character", "models/character.glb")

local model = core.model.create("character")
local a = core.shader.create("assets/shaders/toon.glsl", core.shader.shader_mode.SPATIAL)
local b = core.shader.create("assets/shaders/dissolve.glsl", core.shader.shader_mode.SPATIAL)

a:apply_to_material(model, "*", "*")
b:apply_to_material(model, "*", "*") -- b is shown
b:remove_from_material(model, "*", "*") -- a is shown again

On this page