Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .vsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Workload.ManagedGame"
]
}
54 changes: 54 additions & 0 deletions Assets/Depth.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Shader "Hidden/Depth"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Cull Off ZWrite Off ZTest Always

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"

struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};

struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};

v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}

sampler2D _MainTex;
sampler2D depthTex;

fixed4 frag (v2f i) : SV_Target
{
float depth = SAMPLE_DEPTH_TEXTURE(depthTex , i.uv);
depth = Linear01Depth(depth);
return depth;

fixed4 col = tex2D(_MainTex, i.uv);
return col;
}
ENDCG
}
}
}
10 changes: 10 additions & 0 deletions Assets/Depth.shader.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions Assets/DepthVisualizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DepthVisualizer : MonoBehaviour
{
public Shader visualizerShader;
public Material visualizerMaterial;

Camera cam;
RenderTexture rt;
RenderTexture rtDepth;

Vector2 lastres = Vector2.zero;

// Start is called before the first frame update
void Start()
{
cam = GetComponent<Camera>();
Vector2 currentRes = new Vector2(Screen.width, Screen.height);
Initialize(currentRes);
}

// Update is called once per frame
void Update()
{
Vector2 currentRes = new Vector2(Screen.width, Screen.height);
if(currentRes != lastres)
{
Initialize(currentRes);
}
}
void Initialize(Vector2 currentRes)
{
if (rt)
Destroy(rt);
if (rtDepth)
Destroy(rtDepth);

rt = new RenderTexture(Screen.width, Screen.height, 0, RenderTextureFormat.ARGBFloat);
rtDepth = new RenderTexture(Screen.width, Screen.height, 32, RenderTextureFormat.Depth);

cam.SetTargetBuffers(rt.colorBuffer, rtDepth.depthBuffer);
visualizerMaterial.SetTexture("depthTex", rtDepth);

lastres= currentRes;
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
Graphics.Blit(source, destination, visualizerMaterial);
}
}
11 changes: 11 additions & 0 deletions Assets/DepthVisualizer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions Assets/Hidden_Depth.mat
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Hidden_Depth
m_Shader: {fileID: 4800000, guid: 563dce4521b850c42aff8cb425f95211, type: 3}
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats: []
m_Colors: []
m_BuildTextureStacks: []
8 changes: 8 additions & 0 deletions Assets/Hidden_Depth.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion Assets/Scenes/Model.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 705507994}
m_IndirectSpecularColor: {r: 0.17757882, g: 0.2223225, b: 0.30451846, a: 1}
m_IndirectSpecularColor: {r: 0.17757854, g: 0.222322, b: 0.30451757, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -397,6 +397,7 @@ GameObject:
- component: {fileID: 963194229}
- component: {fileID: 963194230}
- component: {fileID: 963194231}
- component: {fileID: 963194232}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
Expand Down Expand Up @@ -543,6 +544,20 @@ MonoBehaviour:
brightness: 0
saturation: 1
gamma: 1
--- !u!114 &963194232
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2adb703f0c7569a4f9cbfd04970951ac, type: 3}
m_Name:
m_EditorClassIdentifier:
visualizerShader: {fileID: 4800000, guid: 563dce4521b850c42aff8cb425f95211, type: 3}
visualizerMaterial: {fileID: 2100000, guid: 1c7c9687ca8d57242897a8d768f80b98, type: 2}
--- !u!1 &1422709744 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 697d5844150f9a4429a34af057b64ffe, type: 3}
Expand Down
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2021.2.2f1
m_EditorVersionWithRevision: 2021.2.2f1 (5e2b1e92c7f8)
m_EditorVersion: 2021.3.16f1
m_EditorVersionWithRevision: 2021.3.16f1 (4016570cf34f)
Loading