For the most common cases, Godot provides ready to use materials for most types of shaders, such as SpatialMaterial, CanvasItemMaterial and ParticlesMaterial. They are flexible implementations that cover most use cases.
Shader materials allow writing a custom shader directly, for maximum flexibility. Examples of this are:
- Create procedural textures.
- Create complex texture blending effects.
- Create animated materials, or materials that change over time.
- Create refractive effects or other advanced effects.
- Create special lighting shaders for more exotic materials.
- Animate vertices, like tree leaves or grass.
- Create custom particle code.
- And much more!
Godot provides built in functionality to make frequent operations easier. Additionally, Godot’s shader editor will detect errors as you type, so you can see your edited shaders in real-time. It is also possible to edit shaders using a visual, node-based graph editor.
Creating a ShaderMaterial¶
Create a new ShaderMaterial in some object of your choice. Go to the «Material» property and create a ShaderMaterial.
Next, click on the shader material to see its properties. From here you can create a shader or visual shader. Regular shaders use code to set their properties while a visual shader uses a node based workflow.
There is no way to convert between the two, so if you decide you want to change to a visual shader or vice versa, you will have to start from scratch.
Choose one of them and you can start editing your shader.
If you create a regular shader click on it and the shader editor will open.
If you create a visual shader the visual shader editor will open automatically.
Converting to ShaderMaterial¶
It is possible to convert from SpatialMaterial, CanvasItemMaterial and ParticlesMaterial to ShaderMaterial. To do so, go to the material properties and select the convert option.
Using the convert option will turn the SpatialMaterial into a ShaderMaterial with a text shader, not a visual shader.