Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

着色器材质

前言

For the most common cases, Godot provides ready to use materials for most types of shaders, such as StandardMaterial3D, CanvasItemMaterial and ParticleProcessMaterial. They are flexible implementations that cover most use cases.

着色器材质允许直接编写自定义着色器, 以获得最大的灵活性. 这方面的示例是:

  • 创建程序式纹理。

  • 创建复杂的纹理混合效果.

  • 创建动画材质, 或随时间变化的材质.

  • 创建折射效果或其他高级效果.

  • 为更具异国情调的材质创建特殊照明着色器.

  • 动画顶点, 如树叶或草.

  • 创建自定义粒子代码.

  • 以及更多!

Godot提供了内置的功能, 使频繁的操作更容易. 此外,Godot的着色器编辑器会在你输入时检测错误, 所以你可以实时看到编辑的着色器. 也可以使用可视化的, 基于节点的图形编辑器来编辑着色器.

创建 ShaderMaterial

在你选择的某个对象中创建一个新的 ShaderMaterial。转到 Material 属性并创建 ShaderMaterial。

../../_images/shader_material_create.png

接下来, 点击着色器材质, 查看其属性. 从这里你可以创建一个着色器或视觉着色器. 常规着色器使用代码来设置它们的属性, 而视觉着色器则使用基于节点的工作流程.

如果你需要, 你可以将视觉着色器转换为文本着色器. 但是你不能将文本着色器转换为视觉着色器.

选择其中一个, 你就可以开始编辑你的着色器.

../../_images/shader_create.png

编辑新创建的着色器, 着色器编辑器将打开.

../../_images/shader_material_editor.png

编辑新创建的着色器, 着色器编辑器将打开.

../../_images/visual_shader_editor.png

在视觉着色器编辑器中, 你可以点击一个按钮, 看看你的视觉着色器作为着色器代码的样子. 如果你想复制一个文本着色器作为节点, 这可能是有用的, 或者它可以作为将你的视觉着色器转换为文本着色器的预览.

../../_images/visual_shader_code.png

备注

要了解更多关于可视化着色器的信息, 请阅读 使用 VisualShader .

转换为 ShaderMaterial

It is possible to convert from StandardMaterial3D, CanvasItemMaterial and ParticleProcessMaterial to ShaderMaterial. To do so, go to the material properties and select the convert option.

../../_images/shader_material_convert.png

备注

Using the convert option will turn the StandardMaterial3D into a ShaderMaterial with a text shader, not a visual shader.