materials.rst 4.2 KB

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