shader_materials.rst 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. Shader Materials
  2. ================
  3. Introduction
  4. ------------
  5. For the most common cases, [[Fixed Material]] are enough to create the
  6. desired textures or look and feel. Shader materials are a step beyond
  7. that adds a huge amount of flexibility. With them, it is possible to:
  8. - Create procedural texures.
  9. - Create complex texture blendings.
  10. - Create animated materials, or materials that change with time.
  11. - Create refractive effects or other advanced effects.
  12. - Create special lighting shaders for more exotic materials.
  13. - Animate vertices, like tree leaves or grass.
  14. - And much more!
  15. Traditionally, most engines will ask you to learn GLSL, HLSL or CG,
  16. which are pretty complex for the skillset of most artists. Godot uses a
  17. simplified version of a shader language that will detect errors as you
  18. type, so you can see your edited shaders in real-time. Additionally, it
  19. is possible to edit shaders using a visual graph editor (NOTE: Currently
  20. disabled! work in progress!).
  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 `Shader <>`__
  25. .. image:: /img/shader_material_create.png
  26. Edit the newly created shader, and the shader editor will open:
  27. .. image:: /img/shader_material_editor.png
  28. There are three code tabs open, the first is for the vertex shader, the
  29. second for the fragment and the third for the lighting. The shader
  30. language is documented in it's [[Shader]] so a small example will be
  31. presented next.
  32. Create a very simple fragment shader that writes a color:
  33. ::
  34. uniform color col;
  35. DIFFUSE = col.rgb;
  36. Code changes take place in real-time. If the code is modified, it will
  37. be instantly recompiled and the object will be updated. If a typo is
  38. made, the editor will notify of the compilation failure:
  39. .. image:: /img/shader_material_typo.png
  40. Finally, go back and edit the material, and the exported uniform will be
  41. instantly visible:
  42. .. image:: /img/shader_material_col.png
  43. This allows to very quickly create custom, complex materials for every
  44. type of object.
  45. *Juan Linietsky, Ariel Manzur, Distributed under the terms of the `CC
  46. By <https://creativecommons.org/licenses/by/3.0/legalcode>`__ license.*