godot-docs/tutorials/3d/shader_materials.rst

68 lines
2.1 KiB
ReStructuredText
Raw Normal View History

2016-02-08 23:45:57 +01:00
.. _doc_shader_materials:
2016-02-06 01:54:33 +01:00
Shader Materials
================
Introduction
------------
2016-02-08 23:45:57 +01:00
For the most common cases, :ref:`doc_fixed_materials` are enough to create the
2016-02-06 01:54:33 +01:00
desired textures or look and feel. Shader materials are a step beyond
that adds a huge amount of flexibility. With them, it is possible to:
- Create procedural texures.
- Create complex texture blendings.
- Create animated materials, or materials that change with time.
- Create refractive effects or other advanced effects.
- Create special lighting shaders for more exotic materials.
- Animate vertices, like tree leaves or grass.
- And much more!
Traditionally, most engines will ask you to learn GLSL, HLSL or CG,
which are pretty complex for the skillset of most artists. Godot uses a
simplified version of a shader language that will detect errors as you
type, so you can see your edited shaders in real-time. Additionally, it
is possible to edit shaders using a visual graph editor (NOTE: Currently
disabled! work in progress!).
Creating a ShaderMaterial
-------------------------
Create a new ShaderMaterial in some object of your choice. Go to the
2016-02-07 23:47:10 +01:00
"Shader" property, then create a new "Shader":
2016-02-06 01:54:33 +01:00
.. image:: /img/shader_material_create.png
Edit the newly created shader, and the shader editor will open:
.. image:: /img/shader_material_editor.png
There are three code tabs open, the first is for the vertex shader, the
second for the fragment and the third for the lighting. The shader
2016-02-08 23:45:57 +01:00
language is documented in it's :ref:`doc_shading_language` so a small example will be
2016-02-06 01:54:33 +01:00
presented next.
Create a very simple fragment shader that writes a color:
::
uniform color col;
DIFFUSE = col.rgb;
Code changes take place in real-time. If the code is modified, it will
be instantly recompiled and the object will be updated. If a typo is
made, the editor will notify of the compilation failure:
.. image:: /img/shader_material_typo.png
Finally, go back and edit the material, and the exported uniform will be
instantly visible:
.. image:: /img/shader_material_col.png
This allows to very quickly create custom, complex materials for every
type of object.