着色器材质
简介
对于最常见的情况,Godot为大多数类型的着色器提供了随时可用的材质,例如 SpatialMaterial , CanvasItemMaterial 和 ParticlesMaterial 。 它们是涵盖了大多数用例的灵活实现。
着色器材质允许直接编写自定义着色器,以获得最大的灵活性。 这方面的示例是:
- 创建程序纹理。
- Create complex texture blending effects.
- Create animated materials, or materials that change over time.
- 创建折射效果或其他高级效果。
- 为更具异国情调的材质创建特殊照明着色器。
- 动画顶点,如树叶或草。
- Create custom particle code.
- 以及更多!
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.
创建ShaderMaterial
在您选择的某个对象中创建一个新的ShaderMaterial。 转到``材质``属性并创建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.
If you need to you can convert a visual shader to a text shader. However you can’t convert a text shader to a visual shader.
Choose one of them and you can start editing your shader.
编辑新创建的着色器,着色器编辑器将打开。
编辑新创建的着色器,着色器编辑器将打开。
In the visual shader editor you can click a button and see what your visual shader looks like as shader code. This can be useful if you’re trying to replicate a text shader as nodes, or it can be used as a preview for converting your visual shader to a text shader.
注解
To learn more about visual shaders, read VisualShaders.
转换为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.