Difference between revisions of "Decalery manual"

From Bakery GPU Lightmapper: Wiki
Jump to navigation Jump to search
Line 29: Line 29:
 
* Update: (re)builds the decal geometry once.
 
* Update: (re)builds the decal geometry once.
 
* Remove: removes previously generated decal geometry.
 
* Remove: removes previously generated decal geometry.
 +
 +
== Runtime API ==
 +
Decals can be created at runtime. While it is possible to directly use the DecalGroup component, it is not recommended for performance reasons. Decalery has a special fast mode of generating and rendering simple quad-like and trail-like decals at runtime. The architecture is as follows:
 +
 +
[[File:Decalarch.jpg]]
 +
 +
<hr>
 +
 +
'''DecalSpawner''' class is the main building block that manages pools of decals using identical settings and materials. For example, in a shooter, a single DecalSpawner for bullet holes can be used by all guns of all characters.
 +
 +
Properties:
 +
 +
* '''{{code|<nowiki>InitData initData</nowiki>}}'''Main spawner settings. InitData class contains following members:<br><br>
 +
** '''{{code|<nowiki>Material material</nowiki>}}'''Base material used by all spawned decals. Use shaders made specifically for decals (offsetting position to camera to prevent Z-fighting).<br><br>
 +
** '''{{code|<nowiki>bool isTrail</nowiki>}}'''Is this decal a trail (e.g. a tire track)? Trails connect edge-to-edge instead of being separated quads. Trails also have a unique continuous UV generation style.<br><br>
 +
** '''{{code|<nowiki>float trailInterval</nowiki>}}'''If ''isTrail'' is enabled, controls interval between trail edges (smaller interval = rounder trails).<br><br>
 +
** '''{{code|<nowiki>float trailVScale</nowiki>}}'''If ''isTrail'' is enabled, controls vertical texture coordinate tiling. <br><br>
 +
** '''{{code|<nowiki>bool tangents</nowiki>}}'''Should decals have tangents (do they need normal mapping)?<br><br>
 +
** '''{{code|<nowiki>bool inheritMaterialPropertyBlocks</nowiki>}}'''Should these decals inherit MaterialPropertyBlocks from receivers?<br><br>
 +
** '''{{code|<nowiki>bool useShaderReplacement</nowiki>}}'''Use shader replacement feature? (see next)<br><br>
 +
** '''{{code|<nowiki>ShaderReplacement[] shaderReplacement</nowiki>}}'''Allows optionally overriding decal shader based on the receiver's shader. Can be used when applying decals to e.g. special surfaces with vertex deformation. ShaderReplacement structure contains following members<br>
 +
*** '''{{code|<nowiki>Shader src</nowiki>}}
 +
*** '''{{code|<nowiki>Shader dest</nowiki>}}'''If receiver has shader ''src'', decal will use shader ''dest''.
 +
 +
'''{{code|<nowiki>Init(int maxTrisTotal, int maxTrisInDecal, DecalUtils.Mode preferredMode, bool preferDrawIndirect, int preferredShaderPass)</nowiki>}}'''
 +
Initializes
 +
 +
 +
 +
'''DecalManager''' manages the creation and reuse of ''DecalSpawners''.

Revision as of 18:25, 27 November 2023

(Draft)

Components

Decal Group

Represents a decal projector, defined by the MeshFilter/MeshRenderer on the same object. Decal shape can be anything from a simple quad, to a complex shape, such as e.g. a corner, a ring around another object, etc. MeshRenderer should be normally disabled after the decal is projected.

Settings:

  • Receiver selection mode: defines how the decal-receiving objects are selected. Possible options:
    • Manual: receivers are selected by hand. This is the most precise and predictable method. Objects can be chosen via both the standard Unity selector or by pressing the "Pick in Scene" button and directly clicking receivers in the scene. To the side of every added object there are X and M buttons:
      • Pressing X will remove the receiver from the list.
      • Pressing M will show a material field which will be used instead of the decal's own material only for the selected receiver. This is useful when, for example, the same decal is applied to a dry and a wet surface, where different shaders might be desirable.
    • Box Intersection: receivers are chosen by overlapping a box with nearby colliders.
      • Box scale: scales the selection box. Final box size is affected both by decal mesh bounds, Forward/Backward distance and Box scale.
    • Raycast from vertices: receivers are chosen by performing a physics raycast from every vertex of the decal's mesh, in the inverse normal direction. As with the previous option, it only picks up objects having colliders.
  • Forward distance: decal projection distance (inside).
  • Backward distance: decal projection distance (outside).
  • Angle clip: maximum allowed angle between each decal triangle and projector triangle. The value is from -1 (-180) to 1 (180). This is to prevent texture stretching on surfaces parallel to the projection.
  • Angle fade: fades vertex color/alpha to 0 as the projection approaches Angle clip value.
  • Layer mask: a simple layer mask to filter out receiving objects.
  • Generate tangents: does decal geometry need per-vertex tangents generated? Tangents are required for normal-mapping, parallax and other effects.
  • Link to parent: if enabled, decal meshes will be parented to their receivers.
  • Optimize: performs vertex welding and vertex order optimization.

Buttons:

  • Live Preview: when enabled, decal will be rebuilt interactively, as it is transformed, or its settings are tweaked.
  • Update: (re)builds the decal geometry once.
  • Remove: removes previously generated decal geometry.

Runtime API

Decals can be created at runtime. While it is possible to directly use the DecalGroup component, it is not recommended for performance reasons. Decalery has a special fast mode of generating and rendering simple quad-like and trail-like decals at runtime. The architecture is as follows:

Decalarch.jpg


DecalSpawner class is the main building block that manages pools of decals using identical settings and materials. For example, in a shooter, a single DecalSpawner for bullet holes can be used by all guns of all characters.

Properties:

  • InitData initData
    Main spawner settings. InitData class contains following members:

    • Material material
      Base material used by all spawned decals. Use shaders made specifically for decals (offsetting position to camera to prevent Z-fighting).

    • bool isTrail
      Is this decal a trail (e.g. a tire track)? Trails connect edge-to-edge instead of being separated quads. Trails also have a unique continuous UV generation style.

    • float trailInterval
      If isTrail is enabled, controls interval between trail edges (smaller interval = rounder trails).

    • float trailVScale
      If isTrail is enabled, controls vertical texture coordinate tiling.

    • bool tangents
      Should decals have tangents (do they need normal mapping)?

    • bool inheritMaterialPropertyBlocks
      Should these decals inherit MaterialPropertyBlocks from receivers?

    • bool useShaderReplacement
      Use shader replacement feature? (see next)

    • ShaderReplacement[] shaderReplacement
      Allows optionally overriding decal shader based on the receiver's shader. Can be used when applying decals to e.g. special surfaces with vertex deformation. ShaderReplacement structure contains following members
      • Shader src
      • Shader dest
        If receiver has shader src, decal will use shader dest.
Init(int maxTrisTotal, int maxTrisInDecal, DecalUtils.Mode preferredMode, bool preferDrawIndirect, int preferredShaderPass)

Initializes


DecalManager manages the creation and reuse of DecalSpawners.