Skip to content

Transparency Workarounds

Dale Eidd edited this page May 12, 2021 · 2 revisions

Rendering Transparent Object Behind Surface

@Cotanius on Discord shared a solution (source) for solving their transparency issue by rendering the transparent object before the transparent pass.

s Fixed and broken respectively.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;

public class DamageRenderer : MonoBehaviour
{
    CommandBuffer mCacheCommandBuffer;
    public MeshRenderer testRenderer;
    void OnEnable()
    {
        mCacheCommandBuffer = new CommandBuffer();
        mCacheCommandBuffer.name = "DamageRenderCommandBuffer";
        mCacheCommandBuffer.DrawRenderer(testRenderer, testRenderer.material, 0, -1);
        Camera.main.AddCommandBuffer(CameraEvent.AfterSkybox, mCacheCommandBuffer);
    }

    void OnDisable()
    {
        Camera.main.RemoveCommandBuffer(CameraEvent.AfterSkybox, mCacheCommandBuffer);
        mCacheCommandBuffer.Dispose();
    }
}