Shader Material
Updated
Draws its mesh with a shader: a preset, or code written with pragmas and hooks.
- Type
comp-shader-material- Script class
ShaderMaterialComponent- Per entity
- One
- Version
- 1.0.0
Read about it in Materials: what it does, how to use it from a script, and examples.
Properties
Section titled “Properties”The props the runtime declares for this component, with their defaults and accepted ranges.
| Prop | Default | Range |
|---|---|---|
color |
"#ffffff" |
|
opacity |
1 |
0 ≤ x ≤ 1 |
preset |
"custom" |
|
shader |
"#pragma material(shading=unlit)\n#pragma lifecycle(fragment)\n#pragma uniform(r |
|
side |
"front" |
|
uniforms |
{} |
|
wireframe |
false |
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
Live example
A hover glow using the pointer inputA custom shader reads the pointer and time inputs by itself: the button pulses while the pointer is over it and flashes when pressed, with no script work per frame.
Move the pointer over the button to make it pulse, and press on it to flash it. Drag elsewhere to orbit the camera, scroll to zoom.
From a script
Section titled “From a script”#pragma lifecycle(startup)
function startup() { const component = self.parent.getComponent(ShaderMaterialComponent); if (component) log(component.props);}