Skip to main content

Materials

Materials are a fundamental part of 3D graphics. They define the appearance of 3D objects and are used to create realistic lighting effects. Materials can be applied to Render components to change the appearance of 3D objects. They accept a wide range of properties to control the appearance of the material.

The useMaterial hook returns a StandardMaterial instance. This is useful if you need to create materials and apply them to Render components.

import { useMaterial } from '@playcanvas/react/hooks'

const RedBox = () => {
const material = useMaterial({ diffuse: 'red' });
return (
<Entity>
<Render type="box" material={material} />
</Entity>
)
}

In the example below, we're using the useMaterial hook to create a material and applying it to a Render component. We also add a onClick event to the Entity to change the material properties when the cube is clicked.

Materials have a wide range of properties that can be used to control the appearance of the material. You can find the full list of properties here.