# 6. Decals on Quest Tests and Pitfalls
Part of [[Decals and Environment Detail]]. Previous: [[5. Blood Splatter and Content Settings]].
> [!warning] Not profiled
> The guidance below comes from the URP 17.5.0 source (technique selection and its tooltips) and general tile-based GPU behaviour. **No Quest profiling was done.** Measure with the Meta and Unity profilers on device ([[Profiling and Optimization]]).
## 6.1 Pick the technique per platform
| Renderer asset | Technique | Why |
|---|---|---|
| PC / console | **DBuffer** (or Automatic) | Full surface blending (normal, MAOS). The prepass is affordable |
| Quest / Android | **Screen Space**, explicitly | DBuffer needs a **depth-normals prepass**, which the URP tooltip calls not viable on tile-based GPUs. Screen Space draws decals as meshes after opaques, with no prepass |
| WebGL / GLES | Screen Space | DBuffer isn't supported on OpenGL (URP logs an error and disables it) |
Set this on **each** renderer asset used by your quality tiers ([[Scalability and Quality Tiers]]), instead of trusting *Automatic*. That way the Editor (desktop API) and the device (mobile API) don't quietly use different techniques while you author.
### Screen Space settings for Quest
- **Normal Blend: Low** (1 depth sample) unless you can see the difference. Medium is 5 samples per decal pixel and High is 9.
- **Max Draw Distance** on the feature: 20–30 m. Players in VR rarely read a bullet hole farther away.
- **No Affect MAOS** materials. Screen Space can't blend them separately.
- Keep decal boxes **small and shallow**. Screen Space cost scales with the pixels the box covers. A 2 m blood decal seen up close in VR can fill a large part of the eye buffer.
## 6.2 Budgets
| Tier | Impact budget | Authored decals visible | Notes |
|---|---|---|---|
| PC | 128–256 | Hundreds | DBuffer, instanced atlas |
| Quest 3 | 32–64 | ≤ 50 | Screen Space, Low normal blend |
| Quest 2 | 16–32 | ≤ 30 | Consider the quad fallback for bullet holes |
These are **starting points to measure from, not measured numbers**. Change `budget` on the spawner per tier.
## 6.3 Quad fallback for the lowest tier
For bullet holes on flat walls, a tiny quad with an unlit transparent atlas material is cheaper than any projector. It's one small mesh draw, with no decal pass. It doesn't wrap around corners, so use it only for small decals on flat surfaces.
```csharp
// Assets/Scripts/Decals/QuadDecalFallback.cs
using UnityEngine;
/// <summary>
/// Cheapest possible "decal" for very low-end targets: a pooled quad laid on the surface with an
/// unlit transparent atlas material. Flat surfaces only (it doesn't wrap corners), but costs one
/// tiny mesh draw and no decal pass. Uses _BaseMap_ST (URP Unlit/Lit tiling) via a property block.
/// </summary>
public sealed class QuadDecalFallback : MonoBehaviour
{
static readonly int BaseMapST = Shader.PropertyToID("_BaseMap_ST");
[SerializeField] Material unlitAtlasMaterial;
[SerializeField, Min(1)] int atlasColumns = 4;
[SerializeField, Min(1)] int atlasRows = 4;
[SerializeField, Min(1)] int budget = 32;
[SerializeField] float surfaceOffset = 0.005f;
DecalAtlas _atlas;
DecalBudget _budget;
MeshRenderer[] _quads;
MaterialPropertyBlock _block;
void Awake()
{
_atlas = new DecalAtlas(atlasColumns, atlasRows);
_budget = new DecalBudget(budget);
_quads = new MeshRenderer[budget];
_block = new MaterialPropertyBlock();
for (var i = 0; i < budget; i++)
{
var go = GameObject.CreatePrimitive(PrimitiveType.Quad);
Destroy(go.GetComponent<Collider>());
go.name = "QuadDecal " + i;
go.transform.SetParent(transform, false);
var r = go.GetComponent<MeshRenderer>();
r.sharedMaterial = unlitAtlasMaterial;
r.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
r.receiveShadows = false;
go.SetActive(false);
_quads[i] = r;
}
}
public void Spawn(in RaycastHit hit, int cell, float size)
{
var slot = _budget.Acquire(Time.timeAsDouble, out _);
var r = _quads[slot];
var t = r.transform;
// Unity's Quad faces -Z, so look along -normal to face it out of the surface.
t.SetPositionAndRotation(hit.point + hit.normal * surfaceOffset,
Quaternion.LookRotation(-hit.normal) * Quaternion.Euler(0f, 0f, Random.Range(0f, 360f)));
t.localScale = new Vector3(size, size, 1f);
_atlas.Cell(cell, false, out var sx, out var sy, out var bx, out var by);
_block.SetVector(BaseMapST, new Vector4(sx, sy, bx, by));
r.SetPropertyBlock(_block);
r.gameObject.SetActive(true);
}
}
```
- Unity's built-in Quad faces **−Z**, so `LookRotation(-hit.normal)` turns its visible side out of the wall.
- `surfaceOffset` (5 mm) avoids z-fighting. In VR, check it at arm's length. If it shimmers, raise it slightly, or use a material with a depth offset.
- `_BaseMap_ST` is the tiling/offset vector URP's Lit and Unlit shaders read for `_BaseMap`. It's set through a `MaterialPropertyBlock` for the atlas cell. Note: property blocks opt that renderer out of the **SRP Batcher**. With 16–32 quads that's fine, but don't use this for thousands.
## 6.4 Tests
`DecalAtlas` and `DecalBudget` ran as a .NET 10 console program on 2026-12-01:
```text
PASS cell 0 is top-left: offset (0, 0.75)
PASS cell 5 = column 1, row 1 from top: offset (0.25, 0.5)
PASS cell 15 is bottom-right: offset (0.75, 0)
PASS flipX: negative tiling, offset moved to the cell's right edge
PASS flipped cell still samples u in [0.25, 0.5]
PASS 2x1 strip: second cell offset (0.5, 0)
PASS out-of-range cell throws
PASS fills 3 distinct slots
PASS full: recycles the oldest (spawned t=0)
PASS a freed slot is reused before stealing a live decal
PASS never more than capacity alive
PASS opacity 1 until fade, 0.5 halfway through fade, 0 at lifetime
PASS lifetime 0 = permanent
ALL PASS
```
As Unity Test Framework EditMode tests (type-checked only; see [[Unity Test Framework]]):
```csharp
// Assets/Tests/EditMode/DecalMathTests.cs
using NUnit.Framework;
public class DecalMathTests
{
[Test]
public void CellZeroIsTopLeft()
{
new DecalAtlas(4, 4).Cell(0, false, out var sx, out var sy, out var bx, out var by);
Assert.AreEqual(0.25f, sx, 1e-5f);
Assert.AreEqual(0.25f, sy, 1e-5f);
Assert.AreEqual(0f, bx, 1e-5f);
Assert.AreEqual(0.75f, by, 1e-5f);
}
[Test]
public void FlipStaysInsideTheCell()
{
new DecalAtlas(4, 4).Cell(5, true, out var sx, out _, out var bx, out _);
Assert.AreEqual(0.5f, bx, 1e-5f);
Assert.AreEqual(0.25f, bx + sx, 1e-5f);
}
[Test]
public void BudgetRecyclesOldestOnlyWhenFull()
{
var b = new DecalBudget(3);
var first = b.Acquire(0, out _);
var second = b.Acquire(1, out _);
b.Acquire(2, out _);
Assert.AreEqual(first, b.Acquire(3, out var recycled));
Assert.IsTrue(recycled);
b.Release(second);
Assert.AreEqual(second, b.Acquire(4, out recycled));
Assert.IsFalse(recycled);
}
[Test]
public void OpacityFadesOverTheLastSeconds()
{
Assert.AreEqual(1f, DecalBudget.Opacity(10, 30, 3), 1e-5f);
Assert.AreEqual(0.5f, DecalBudget.Opacity(28.5, 30, 3), 1e-5f);
Assert.AreEqual(0f, DecalBudget.Opacity(30, 30, 3), 1e-5f);
Assert.AreEqual(1f, DecalBudget.Opacity(1e6, 0, 0), 1e-5f);
}
}
```
## 6.5 Pitfalls
| Symptom | Cause | Fix |
|---|---|---|
| Decal invisible | No Decal renderer feature on the **active** renderer asset (often the Quest tier's) | Add the feature to every renderer asset used |
| Decal invisible on glass or water | Decals don't project onto transparent surfaces | Use a texture on that material instead |
| Decal on the player's boots | Projector box overlaps characters | Rendering layers (part 2) |
| Long smears down walls | Box clips perpendicular surfaces | Angle Fade start 60 / end 85, and a shallower box |
| Bullet hole shows on both sides of a door | Projection depth deeper than the door | Bullet depth ≈ 0.1 m |
| One draw call per decal | GPU instancing off, or a different material per decal | One instanced atlas material (part 3) |
| Atlas neighbours bleed in at distance | No padding between cells | 8 px+ transparent border per cell |
| Hole stays in the air when a door opens | Not parented to the moving object | The spawner parents to non-static hits (part 4) |
| PC looks right, Quest looks flat | DBuffer on PC, Screen Space on Quest (no MAOS) | Author for Screen Space, or set both to Screen Space while comparing |
| Compile error on `decalLayerMask` | API replaced in 6000.2 | `renderingLayerMask` (part 1) |
| Unlimited decals during a minigun burst | No budget | `DecalBudget` caps and recycles |