From 8e28b357a7e2f5015a46817a2e0218db886a979f Mon Sep 17 00:00:00 2001 From: LetsBlend Date: Fri, 13 Jan 2023 19:03:13 +0100 Subject: [PATCH] Depth Visualizer DepthVisualizer created and put on the main camera --- .vsconfig | 6 + Assets/Depth.shader | 54 ++++++++ Assets/Depth.shader.meta | 10 ++ Assets/DepthVisualizer.cs | 52 ++++++++ Assets/DepthVisualizer.cs.meta | 11 ++ Assets/Hidden_Depth.mat | 30 +++++ Assets/Hidden_Depth.mat.meta | 8 ++ Assets/Scenes/Model.unity | 17 ++- ProjectSettings/ProjectVersion.txt | 4 +- UserSettings/Layouts/default-2021.dwlt | 178 ++++++++++++------------- 10 files changed, 278 insertions(+), 92 deletions(-) create mode 100644 .vsconfig create mode 100644 Assets/Depth.shader create mode 100644 Assets/Depth.shader.meta create mode 100644 Assets/DepthVisualizer.cs create mode 100644 Assets/DepthVisualizer.cs.meta create mode 100644 Assets/Hidden_Depth.mat create mode 100644 Assets/Hidden_Depth.mat.meta diff --git a/.vsconfig b/.vsconfig new file mode 100644 index 0000000..d70cd98 --- /dev/null +++ b/.vsconfig @@ -0,0 +1,6 @@ +{ + "version": "1.0", + "components": [ + "Microsoft.VisualStudio.Workload.ManagedGame" + ] +} diff --git a/Assets/Depth.shader b/Assets/Depth.shader new file mode 100644 index 0000000..2be04e7 --- /dev/null +++ b/Assets/Depth.shader @@ -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 + } + } +} diff --git a/Assets/Depth.shader.meta b/Assets/Depth.shader.meta new file mode 100644 index 0000000..84a5806 --- /dev/null +++ b/Assets/Depth.shader.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 563dce4521b850c42aff8cb425f95211 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/DepthVisualizer.cs b/Assets/DepthVisualizer.cs new file mode 100644 index 0000000..58c617f --- /dev/null +++ b/Assets/DepthVisualizer.cs @@ -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(); + 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); + } +} diff --git a/Assets/DepthVisualizer.cs.meta b/Assets/DepthVisualizer.cs.meta new file mode 100644 index 0000000..11b4e2c --- /dev/null +++ b/Assets/DepthVisualizer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2adb703f0c7569a4f9cbfd04970951ac +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Hidden_Depth.mat b/Assets/Hidden_Depth.mat new file mode 100644 index 0000000..14d6c3b --- /dev/null +++ b/Assets/Hidden_Depth.mat @@ -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: [] diff --git a/Assets/Hidden_Depth.mat.meta b/Assets/Hidden_Depth.mat.meta new file mode 100644 index 0000000..7f67879 --- /dev/null +++ b/Assets/Hidden_Depth.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1c7c9687ca8d57242897a8d768f80b98 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Model.unity b/Assets/Scenes/Model.unity index 8ec1cbd..cda4117 100644 --- a/Assets/Scenes/Model.unity +++ b/Assets/Scenes/Model.unity @@ -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: @@ -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 @@ -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} diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 3acd168..3643b02 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -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) diff --git a/UserSettings/Layouts/default-2021.dwlt b/UserSettings/Layouts/default-2021.dwlt index fe36445..8a11efe 100644 --- a/UserSettings/Layouts/default-2021.dwlt +++ b/UserSettings/Layouts/default-2021.dwlt @@ -15,9 +15,9 @@ MonoBehaviour: m_PixelRect: serializedVersion: 2 x: 0 - y: 43 - width: 1920 - height: 997 + y: 42 + width: 1280 + height: 710 m_ShowMode: 4 m_Title: Game m_RootView: {fileID: 6} @@ -43,8 +43,8 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 30 - width: 1920 - height: 947 + width: 1280 + height: 660 m_MinSize: {x: 300, y: 200} m_MaxSize: {x: 24288, y: 16192} vertical: 0 @@ -64,12 +64,12 @@ MonoBehaviour: m_Children: [] m_Position: serializedVersion: 2 - x: 1531 + x: 1020.5 y: 0 - width: 389 - height: 947 - m_MinSize: {x: 276, y: 71} - m_MaxSize: {x: 4001, y: 4021} + width: 259.5 + height: 660 + m_MinSize: {x: 275, y: 50} + m_MaxSize: {x: 4000, y: 4000} m_ActualView: {fileID: 14} m_Panes: - {fileID: 14} @@ -92,10 +92,10 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 0 - width: 249 - height: 676 - m_MinSize: {x: 200, y: 200} - m_MaxSize: {x: 4000, y: 4000} + width: 166 + height: 471 + m_MinSize: {x: 201, y: 221} + m_MaxSize: {x: 4001, y: 4021} m_ActualView: {fileID: 15} m_Panes: - {fileID: 15} @@ -117,9 +117,9 @@ MonoBehaviour: m_Position: serializedVersion: 2 x: 0 - y: 676 - width: 1531 - height: 271 + y: 471 + width: 1020.5 + height: 189 m_MinSize: {x: 231, y: 271} m_MaxSize: {x: 10001, y: 10021} m_ActualView: {fileID: 13} @@ -148,8 +148,8 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 0 - width: 1920 - height: 997 + width: 1280 + height: 710 m_MinSize: {x: 875, y: 300} m_MaxSize: {x: 10000, y: 10000} m_UseTopView: 1 @@ -173,7 +173,7 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 0 - width: 1920 + width: 1280 height: 30 m_MinSize: {x: 0, y: 0} m_MaxSize: {x: 0, y: 0} @@ -194,8 +194,8 @@ MonoBehaviour: m_Position: serializedVersion: 2 x: 0 - y: 977 - width: 1920 + y: 690 + width: 1280 height: 20 m_MinSize: {x: 0, y: 0} m_MaxSize: {x: 0, y: 0} @@ -218,12 +218,12 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 0 - width: 1531 - height: 947 + width: 1020.5 + height: 660 m_MinSize: {x: 200, y: 200} m_MaxSize: {x: 16192, y: 16192} vertical: 1 - controlID: 89 + controlID: 84 --- !u!114 &10 MonoBehaviour: m_ObjectHideFlags: 52 @@ -243,12 +243,12 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 0 - width: 1531 - height: 676 + width: 1020.5 + height: 471 m_MinSize: {x: 200, y: 100} m_MaxSize: {x: 16192, y: 8096} vertical: 0 - controlID: 90 + controlID: 85 --- !u!114 &11 MonoBehaviour: m_ObjectHideFlags: 52 @@ -264,10 +264,10 @@ MonoBehaviour: m_Children: [] m_Position: serializedVersion: 2 - x: 249 + x: 166 y: 0 - width: 1282 - height: 676 + width: 854.5 + height: 471 m_MinSize: {x: 202, y: 221} m_MaxSize: {x: 4002, y: 4021} m_ActualView: {fileID: 16} @@ -293,7 +293,7 @@ MonoBehaviour: m_MaxSize: {x: 2048, y: 2048} m_TitleContent: m_Text: Asset Store - m_Image: {fileID: 357073275683767465, guid: 0000000000000000d000000000000000, type: 0} + m_Image: {fileID: -7444545952099596278, guid: 0000000000000000d000000000000000, type: 0} m_Tooltip: m_Pos: serializedVersion: 2 @@ -321,14 +321,14 @@ MonoBehaviour: m_MaxSize: {x: 10000, y: 10000} m_TitleContent: m_Text: Project - m_Image: {fileID: -7501376956915960154, guid: 0000000000000000d000000000000000, type: 0} + m_Image: {fileID: -5179483145760003458, guid: 0000000000000000d000000000000000, type: 0} m_Tooltip: m_Pos: serializedVersion: 2 x: 0 - y: 749 - width: 1530 - height: 250 + y: 543 + width: 1019.5 + height: 168 m_ViewDataDictionary: {fileID: 0} m_OverlayCanvas: m_LastAppliedPresetName: Default @@ -346,22 +346,22 @@ MonoBehaviour: m_SkipHidden: 0 m_SearchArea: 1 m_Folders: - - Assets/Scripts + - Assets m_Globs: [] m_OriginalText: m_ViewMode: 1 m_StartGridSize: 64 m_LastFolders: - - Assets/Scripts + - Assets m_LastFoldersGridSize: -1 - m_LastProjectPath: C:\Users\Fatal\Documents\Unity\Grass + m_LastProjectPath: C:\Users\david\Documents\GitHub\Grass m_LockTracker: m_IsLocked: 0 m_FolderTreeState: - scrollPos: {x: 0, y: 0} - m_SelectedIDs: 00580000 - m_LastClickedID: 22528 - m_ExpandedIDs: 00000000ec57000000ca9a3b + scrollPos: {x: 0, y: 12} + m_SelectedIDs: 107e0000 + m_LastClickedID: 32272 + m_ExpandedIDs: 00000000107e000000ca9a3bffffff7f m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -389,7 +389,7 @@ MonoBehaviour: scrollPos: {x: 0, y: 0} m_SelectedIDs: m_LastClickedID: 0 - m_ExpandedIDs: 00000000ec570000 + m_ExpandedIDs: m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -461,14 +461,14 @@ MonoBehaviour: m_MaxSize: {x: 4000, y: 4000} m_TitleContent: m_Text: Inspector - m_Image: {fileID: -6905738622615590433, guid: 0000000000000000d000000000000000, type: 0} + m_Image: {fileID: -440750813802333266, guid: 0000000000000000d000000000000000, type: 0} m_Tooltip: m_Pos: serializedVersion: 2 - x: 1531 - y: 73 - width: 388 - height: 926 + x: 1020.5 + y: 72 + width: 258.5 + height: 639 m_ViewDataDictionary: {fileID: 0} m_OverlayCanvas: m_LastAppliedPresetName: Default @@ -480,7 +480,7 @@ MonoBehaviour: m_ControlHash: -371814159 m_PrefName: Preview_InspectorPreview m_LastInspectedObjectInstanceID: -1 - m_LastVerticalScrollValue: 0 + m_LastVerticalScrollValue: 658 m_GlobalObjectId: m_InspectorMode: 0 m_LockTracker: @@ -502,14 +502,14 @@ MonoBehaviour: m_MaxSize: {x: 4000, y: 4000} m_TitleContent: m_Text: Hierarchy - m_Image: {fileID: -590624980919486359, guid: 0000000000000000d000000000000000, type: 0} + m_Image: {fileID: -3734745235275155857, guid: 0000000000000000d000000000000000, type: 0} m_Tooltip: m_Pos: serializedVersion: 2 x: 0 - y: 73 - width: 248 - height: 655 + y: 72 + width: 165 + height: 450 m_ViewDataDictionary: {fileID: 0} m_OverlayCanvas: m_LastAppliedPresetName: Default @@ -517,9 +517,9 @@ MonoBehaviour: m_SceneHierarchy: m_TreeViewState: scrollPos: {x: 0, y: 0} - m_SelectedIDs: 28580000 - m_LastClickedID: 22568 - m_ExpandedIDs: dcf9ffff3cfbffff + m_SelectedIDs: 5c7e0000 + m_LastClickedID: 32348 + m_ExpandedIDs: 60d3ffff72d4ffff m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -559,14 +559,14 @@ MonoBehaviour: m_MaxSize: {x: 4000, y: 4000} m_TitleContent: m_Text: Scene - m_Image: {fileID: 2318424515335265636, guid: 0000000000000000d000000000000000, type: 0} + m_Image: {fileID: 8634526014445323508, guid: 0000000000000000d000000000000000, type: 0} m_Tooltip: m_Pos: serializedVersion: 2 - x: 249 - y: 73 - width: 1280 - height: 655 + x: 166 + y: 72 + width: 852.5 + height: 450 m_ViewDataDictionary: {fileID: 0} m_OverlayCanvas: m_LastAppliedPresetName: Default @@ -577,7 +577,7 @@ MonoBehaviour: collapsed: 0 displayed: 1 snapOffset: {x: 0, y: 0} - snapOffsetDelta: {x: -101, y: -26} + snapOffsetDelta: {x: -98, y: -26} snapCorner: 3 id: Tool Settings index: 0 @@ -804,7 +804,7 @@ MonoBehaviour: m_Value: 1 m_Color: {r: 0.5, g: 0.5, b: 0.5, a: 0.4} m_Pivot: {x: 0, y: 0, z: 0} - m_Size: {x: 1, y: 1} + m_Size: {x: 0.03125, y: 0.03125} zGrid: m_Fade: m_Target: 0 @@ -819,11 +819,11 @@ MonoBehaviour: m_Rotation: m_Target: {x: 0.14085595, y: 0.00029737948, z: -0.000041638104, w: 0.9901413} speed: 2 - m_Value: {x: 0.14084044, y: 0.00029734673, z: -0.000041633517, w: 0.9900322} + m_Value: {x: -0.14085595, y: -0.0002973795, z: 0.000041638104, w: -0.9901413} m_Size: - m_Target: 13.323015 + m_Target: 18.130785 speed: 2 - m_Value: 13.323015 + m_Value: 18.130785 m_Ortho: m_Target: 0 speed: 2 @@ -864,14 +864,14 @@ MonoBehaviour: m_MaxSize: {x: 4000, y: 4000} m_TitleContent: m_Text: Game - m_Image: {fileID: -2087823869225018852, guid: 0000000000000000d000000000000000, type: 0} + m_Image: {fileID: 4621777727084837110, guid: 0000000000000000d000000000000000, type: 0} m_Tooltip: m_Pos: serializedVersion: 2 - x: 249 - y: 73 - width: 1280 - height: 655 + x: 166 + y: 72 + width: 852.5 + height: 450 m_ViewDataDictionary: {fileID: 0} m_OverlayCanvas: m_LastAppliedPresetName: Default @@ -882,7 +882,7 @@ MonoBehaviour: m_ShowGizmos: 0 m_TargetDisplay: 0 m_ClearColor: {r: 0, g: 0, b: 0, a: 0} - m_TargetSize: {x: 1280, y: 634} + m_TargetSize: {x: 852.5, y: 429} m_TextureFilterMode: 0 m_TextureHideFlags: 61 m_RenderIMGUI: 1 @@ -890,17 +890,17 @@ MonoBehaviour: m_UseMipMap: 0 m_VSyncEnabled: 0 m_Gizmos: 0 - m_Stats: 0 + m_Stats: 1 m_SelectedSizes: 00000000000000000000000000000000000000000000000000000000000000000000000000000000 m_ZoomArea: m_HRangeLocked: 0 m_VRangeLocked: 0 hZoomLockedByDefault: 0 vZoomLockedByDefault: 0 - m_HBaseRangeMin: -640 - m_HBaseRangeMax: 640 - m_VBaseRangeMin: -317 - m_VBaseRangeMax: 317 + m_HBaseRangeMin: -213.125 + m_HBaseRangeMax: 213.125 + m_VBaseRangeMin: -107.25 + m_VBaseRangeMax: 107.25 m_HAllowExceedBaseRangeMin: 1 m_HAllowExceedBaseRangeMax: 1 m_VAllowExceedBaseRangeMin: 1 @@ -918,23 +918,23 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 21 - width: 1280 - height: 634 - m_Scale: {x: 1, y: 1} - m_Translation: {x: 640, y: 317} + width: 852.5 + height: 429 + m_Scale: {x: 2, y: 2} + m_Translation: {x: 426.25, y: 214.5} m_MarginLeft: 0 m_MarginRight: 0 m_MarginTop: 0 m_MarginBottom: 0 m_LastShownAreaInsideMargins: serializedVersion: 2 - x: -640 - y: -317 - width: 1280 - height: 634 + x: -213.125 + y: -107.25 + width: 426.25 + height: 214.5 m_MinimalGUI: 1 - m_defaultScale: 1 - m_LastWindowPixelSize: {x: 1280, y: 655} + m_defaultScale: 2 + m_LastWindowPixelSize: {x: 1705, y: 900} m_ClearInEditMode: 1 m_NoCameraWarning: 1 m_LowResolutionForAspectRatios: 01000000000000000000 @@ -956,7 +956,7 @@ MonoBehaviour: m_MaxSize: {x: 4000, y: 4000} m_TitleContent: m_Text: Console - m_Image: {fileID: 111653112392082826, guid: 0000000000000000d000000000000000, type: 0} + m_Image: {fileID: -4950941429401207979, guid: 0000000000000000d000000000000000, type: 0} m_Tooltip: m_Pos: serializedVersion: 2