materials.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. .. _doc_materials:
  2. Materials
  3. =========
  4. Introduction
  5. ------------
  6. Materials can be applied to most visible 3D objects, they basically
  7. are a description to how light reacts to that object. There are many
  8. types of materials, but the main ones are the
  9. :ref:`FixedMaterial <class_FixedMaterial>` and
  10. :ref:`ShaderMaterial <class_ShaderMaterial>`.
  11. Tutorials for each of them exist :ref:`doc_fixed_materials` and :ref:`doc_shader_materials`.
  12. This tutorial is about the basic properties shared between them.
  13. .. image:: /img/material_flags.png
  14. Flags
  15. -----
  16. Materials, no matter which type they are, have a set of flags
  17. associated. Each has a different use and will be explained as follows.
  18. Visible
  19. ~~~~~~~
  20. Toggles whether the material is visible. If unchecked, the object will
  21. not be shown.
  22. Double sided & invert faces
  23. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. Godot by default only shows geometry faces (triangles) when facing the
  25. camera. To do this it needs them to be in view in clockwise order.
  26. This saves a lot of GPU power by ensuring that not visible triangles
  27. are not drawn.
  28. Some flat objects might need to be drawn all the times though, for
  29. this the "double sided" flag will make sure that no matter the facing,
  30. the triangle will always be drawn. It is also possible to invert this
  31. check and draw counter-clockwise looking faces too, though it's not
  32. very useful except for a few cases (like drawing outlines).
  33. Unshaded
  34. ~~~~~~~~
  35. Objects are always black unless light affects them, and their shading
  36. changes according to the type and direction of lights. When this flag is
  37. turned on, the diffuse color is displayed right the same as it appears
  38. in the texture or parameter:
  39. .. image:: /img/material_unshaded.png
  40. On top
  41. ~~~~~~
  42. When this flag is turned on, the object will be drawn after everything
  43. else has been drawn and without a depth test. This is generally only
  44. useful for HUD effects or gizmos.
  45. Ligthmap on UV2
  46. ~~~~~~~~~~~~~~~
  47. When using lightmapping (see the :ref:`doc_light_baking` tutorial), this option
  48. determines that the lightmap should be accessed on the UV2 array instead
  49. of regular UV.
  50. Parameters
  51. ----------
  52. Some parameters also exist for controlling drawing and blending:
  53. Blend mode
  54. ~~~~~~~~~~
  55. Objects are usually blended in Mix mode. Other blend modes (Add and Sub)
  56. exist for special cases (usually particle effects, light rays, etc.) but
  57. materials can be set to them:
  58. .. image:: /img/fixed_material_blend.png
  59. Line width
  60. ~~~~~~~~~~
  61. When drawing lines, the size of them can be adjusted here per material.
  62. Depth draw mode
  63. ~~~~~~~~~~~~~~~
  64. This is a tricky but very useful setting. By default, opaque objects are
  65. drawn using the depth buffer and translucent objects are not (but are
  66. sorted by depth). This behavior can be changed here. The options are:
  67. - **Always**: Draw objects with depth always, even those with alpha.
  68. This often results in glitches like the one in the first image (which
  69. is why it's not the default).
  70. - **Opaque Only**: Draw objects with depth only when they are opaque,
  71. and do not set depth for alpha. This is the default because it's fast,
  72. but it's not the most correct setting. Objects with transparency that
  73. self-intersect will always look wrong, especially those that mix
  74. opaque and transparent areas, like grass, tree leaves, etc. Objects
  75. with transparency also can't cast shadows, this is evident in the
  76. second image.
  77. - **Alpha Pre-Pass**: The same as above, but a depth pass is performed
  78. for the opaque areas of objects with transparency. This makes objects
  79. with transparency look much more correct. In the third image it is
  80. evident how the leaves cast shadows between them and into the floor.
  81. This setting is turned off by default because, while on PC this is
  82. not very costly, mobile devices suffer a lot when this setting is
  83. turned on, so use it with care.
  84. - **Never**: Never use the depth buffer for this material. This is
  85. mostly useful in combination with the "On Top" flag explained above.
  86. .. image:: /img/material_depth_draw.png