particle_shader.rst 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. .. _doc_particle_shader:
  2. Particle shaders
  3. ================
  4. Particle shaders are a special type of vertex shader that runs before the
  5. object is drawn. They are used for calculating material properties such as
  6. color, position, and rotation. They are drawn with any regular material for
  7. CanvasItem or Spatial, depending on whether they are 2D or 3D.
  8. Particle shaders are unique because they are not used to draw the object
  9. itself; they are used to calculate particle properties, which are then used
  10. by the CanvasItem of Spatial shader. They contain only a vertex processor
  11. function that outputs multiple properties (see built-ins below).
  12. Particle shaders use a transform feedback shader, which is a special type of
  13. vertex shader that runs on its own. It takes in data in a buffer like a regular
  14. vertex shader does, but it also outputs to data buffers instead of outputting
  15. to the fragment shader for pixel-processing. Because of this, transform feedback
  16. shaders can build on themselves each run, unlike other shaders that discard the
  17. data they have calculated once they draw to the frame buffer.
  18. .. note:: Particle shaders are only available in the GLES3 backend. If you need
  19. particles in GLES2, use :ref:`CPUParticles <class_CPUParticles>`.
  20. Render modes
  21. ^^^^^^^^^^^^
  22. +---------------------------------+----------------------------------------------------------------------+
  23. | Render mode | Description |
  24. +=================================+======================================================================+
  25. | **keep_data** | Do not clear previous data on restart. |
  26. +---------------------------------+----------------------------------------------------------------------+
  27. | **disable_force** | Disable attractor force. (Not currently implemented in 3.1) |
  28. +---------------------------------+----------------------------------------------------------------------+
  29. | **disable_velocity** | Ignore **VELOCITY** value. |
  30. +---------------------------------+----------------------------------------------------------------------+
  31. Built-ins
  32. ^^^^^^^^^
  33. Values marked as "in" are read-only. Values marked as "out" are for optional writing and will
  34. not necessarily contain sensible values. Values marked as "inout" provide a sensible default
  35. value, and can optionally be written to. Samplers are not subjects of writing and they are
  36. not marked.
  37. Global built-ins
  38. ^^^^^^^^^^^^^^^^
  39. Global built-ins are available everywhere, including custom functions.
  40. +-------------------+--------------------------+
  41. | Built-in | Description |
  42. +===================+==========================+
  43. | in float **TIME** | Global time, in seconds. |
  44. +-------------------+--------------------------+
  45. Vertex built-ins
  46. ^^^^^^^^^^^^^^^^
  47. In order to use the ``COLOR`` variable in a SpatialMaterial, set ``use_vertex_as_albedo``
  48. to ``true``. In a ShaderMaterial, access it with the ``COLOR`` variable.
  49. +---------------------------------+-------------------------------------------------------------------------------------+
  50. | Built-in | Description |
  51. +=================================+=====================================================================================+
  52. | inout vec4 **COLOR** | Particle color, can be written to and accessed in mesh's vertex function. |
  53. +---------------------------------+-------------------------------------------------------------------------------------+
  54. | inout vec3 **VELOCITY** | Particle velocity, can be modified. |
  55. +---------------------------------+-------------------------------------------------------------------------------------+
  56. | out float **MASS** | Particle mass, use for attractors (not implemented in 3.1). |
  57. +---------------------------------+-------------------------------------------------------------------------------------+
  58. | inout bool **ACTIVE** | ``true`` when Particle is active, can be set to ``false``. |
  59. +---------------------------------+-------------------------------------------------------------------------------------+
  60. | in bool **RESTART** | ``true`` when particle must restart (lifetime cycled). |
  61. +---------------------------------+-------------------------------------------------------------------------------------+
  62. | inout vec4 **CUSTOM** | Custom particle data. Accessible from shader of mesh as **INSTANCE_CUSTOM**. |
  63. +---------------------------------+-------------------------------------------------------------------------------------+
  64. | inout mat4 **TRANSFORM** | Particle transform. |
  65. +---------------------------------+-------------------------------------------------------------------------------------+
  66. | in float **LIFETIME** | Particle lifetime. |
  67. +---------------------------------+-------------------------------------------------------------------------------------+
  68. | in float **DELTA** | Delta process time. |
  69. +---------------------------------+-------------------------------------------------------------------------------------+
  70. | in uint **NUMBER** | Unique number since emission start. |
  71. +---------------------------------+-------------------------------------------------------------------------------------+
  72. | in int **INDEX** | Particle index (from total particles). |
  73. +---------------------------------+-------------------------------------------------------------------------------------+
  74. | in mat4 **EMISSION_TRANSFORM** | Emitter transform (used for non-local systems). |
  75. +---------------------------------+-------------------------------------------------------------------------------------+
  76. | in uint **RANDOM_SEED** | Random seed used as base for random. |
  77. +---------------------------------+-------------------------------------------------------------------------------------+