Last active
December 21, 2021 15:31
-
-
Save phi-lira/6fe995bcf01afd45869c to your computer and use it in GitHub Desktop.
Overdraw Debugger Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, ""); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there,
if is Blend One One, RenderType should be Transparent, no?