shader_materials.rst 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. .. _doc_shader_materials:
  2. Shader materials
  3. ================
  4. Introduction
  5. ------------
  6. For the most common cases, :ref:`doc_fixed_materials` are enough to create the
  7. desired textures or look and feel. Shader materials are a step beyond
  8. that, adding a huge amount of flexibility. With them, it is possible to:
  9. - Create procedural textures.
  10. - Create complex texture blendings.
  11. - Create animated materials, or materials that change with time.
  12. - Create refractive effects or other advanced effects.
  13. - Create special lighting shaders for more exotic materials.
  14. - Animate vertices, like tree leaves or grass.
  15. - And much more!
  16. Traditionally, most engines will ask you to learn GLSL, HLSL or CG,
  17. which are pretty complex for the skillset of most artists. Godot uses a
  18. simplified version of a shader language that will detect errors as you
  19. type, so you can see your edited shaders in real-time. Additionally, it
  20. is possible to edit shaders using a visual, node-based graph editor.
  21. Creating a ShaderMaterial
  22. -------------------------
  23. Create a new ShaderMaterial in some object of your choice. Go to the
  24. "Shader" property, then create a new "MaterialShader" (use
  25. "MaterialShaderGraph" for access to the visual graph editor):
  26. .. image:: /img/shader_material_create.png
  27. Edit the newly created shader, and the shader editor will open:
  28. .. image:: /img/shader_material_editor.png
  29. There are three code tabs open, the first is for the vertex shader, the
  30. second for the fragment and the third for the lighting. The shader
  31. language is documented in :ref:`doc_shading_language` so a small example will be
  32. presented next.
  33. Create a very simple fragment shader that writes a color:
  34. ::
  35. uniform color col;
  36. DIFFUSE = col.rgb;
  37. Code changes take place in real-time. If the code is modified, it will
  38. be instantly recompiled and the object will be updated. If a typo is
  39. made, the editor will notify of the compilation failure:
  40. .. image:: /img/shader_material_typo.png
  41. Finally, go back and edit the material, and the exported uniform will be
  42. instantly visible:
  43. .. image:: /img/shader_material_col.png
  44. This allows to very quickly create custom, complex materials for every
  45. type of object.