Skip to content

Instantly share code, notes, and snippets.

@phi-lira
Last active December 21, 2021 15:31
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save phi-lira/6fe995bcf01afd45869c to your computer and use it in GitHub Desktop.
Save phi-lira/6fe995bcf01afd45869c to your computer and use it in GitHub Desktop.
Overdraw Debugger Unity
using UnityEngine;
using System.Collections;
public class OverdrawDebugReplacement : MonoBehaviour
{
public Shader _OverdrawShader;
private Camera _Camera;
private bool _SceneFogSettings = false;
void OnLevelWasLoaded()
{
// Every time a scene is loaded we have to disable fog. We save it for restorting it later in OnDisable
_SceneFogSettings = RenderSettings.fog;
RenderSettings.fog = false;
}
void OnEnable()
{
// not set in the editor inspector
if (_OverdrawShader == null)
{
// It must be added on Project Settings -> Graphics -> Always Include Shader if you want to see it on the build.
_OverdrawShader = Shader.Find("Custom/OverdrawDebugReplacement");
}
_Camera = GetComponent<Camera>();
if (_OverdrawShader != null && _Camera != null)
{
RenderSettings.fog = false;
Camera camera = GetComponent<Camera>();
camera.SetReplacementShader(_OverdrawShader, "");
}
else
{
Debug.LogWarning("Can't use OverdrawDebugReplace. Check if script is attached to a camera object.");
}
}
void OnDisable()
{
if (_Camera != null)
{
RenderSettings.fog = _SceneFogSettings;
camera.SetReplacementShader(null, "");
}
}
}
Shader "Custom/OverdrawDebugReplacement"
{
SubShader
{
Tags {"RenderType" = "Opaque"}
LOD 100
Pass
{
Blend One One
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
half4 vert(half4 vertex : POSITION) : SV_POSITION
{
return mul(UNITY_MATRIX_MVP, vertex);
}
fixed4 frag(half4 vertex : SV_POSITION) : COLOR
{
return fixed4(0.1, 0.1, 0.1, 1.0);
}
ENDCG
}
}
}
@resetme
Copy link

resetme commented Sep 16, 2020

Hi there,

if is Blend One One, RenderType should be Transparent, no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment