A game about forced loneliness, made by TACStudios
at master 113 lines 3.3 kB view raw
1using System.Reflection; 2using UnityEngine; 3using UnityEditor.Graphing; 4using UnityEditor.ShaderGraph.Drawing.Controls; 5 6namespace UnityEditor.ShaderGraph 7{ 8 enum DepthSamplingMode 9 { 10 Linear01, 11 Raw, 12 Eye 13 }; 14 15 [Title("Input", "Scene", "Scene Depth")] 16 sealed class SceneDepthNode : CodeFunctionNode, IMayRequireDepthTexture 17 { 18 const string kScreenPositionSlotName = "UV"; 19 const string kOutputSlotName = "Out"; 20 21 public const int ScreenPositionSlotId = 0; 22 public const int OutputSlotId = 1; 23 24 [SerializeField] 25 private DepthSamplingMode m_DepthSamplingMode = DepthSamplingMode.Linear01; 26 27 [EnumControl("Sampling Mode")] 28 public DepthSamplingMode depthSamplingMode 29 { 30 get { return m_DepthSamplingMode; } 31 set 32 { 33 if (m_DepthSamplingMode == value) 34 return; 35 36 m_DepthSamplingMode = value; 37 Dirty(ModificationScope.Graph); 38 } 39 } 40 41 public SceneDepthNode() 42 { 43 name = "Scene Depth"; 44 synonyms = new string[] { "zbuffer", "zdepth" }; 45 UpdateNodeAfterDeserialization(); 46 } 47 48 public override bool hasPreview { get { return false; } } 49 50 51 protected override MethodInfo GetFunctionToConvert() 52 { 53 switch (m_DepthSamplingMode) 54 { 55 case DepthSamplingMode.Raw: 56 return GetType().GetMethod("Unity_SceneDepth_Raw", BindingFlags.Static | BindingFlags.NonPublic); 57 case DepthSamplingMode.Eye: 58 return GetType().GetMethod("Unity_SceneDepth_Eye", BindingFlags.Static | BindingFlags.NonPublic); 59 case DepthSamplingMode.Linear01: 60 default: 61 return GetType().GetMethod("Unity_SceneDepth_Linear01", BindingFlags.Static | BindingFlags.NonPublic); 62 } 63 } 64 65 static string Unity_SceneDepth_Linear01( 66 [Slot(0, Binding.ScreenPosition)] Vector4 UV, 67 [Slot(1, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out) 68 { 69 return 70@" 71{ 72 Out = Linear01Depth(SHADERGRAPH_SAMPLE_SCENE_DEPTH(UV.xy), _ZBufferParams); 73} 74"; 75 } 76 77 static string Unity_SceneDepth_Raw( 78 [Slot(0, Binding.ScreenPosition)] Vector4 UV, 79 [Slot(1, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out) 80 { 81 return 82@" 83{ 84 Out = SHADERGRAPH_SAMPLE_SCENE_DEPTH(UV.xy); 85} 86"; 87 } 88 89 static string Unity_SceneDepth_Eye( 90 [Slot(0, Binding.ScreenPosition)] Vector4 UV, 91 [Slot(1, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out) 92 { 93 return 94@" 95{ 96 if (unity_OrthoParams.w == 1.0) 97 { 98 Out = LinearEyeDepth(ComputeWorldSpacePosition(UV.xy, SHADERGRAPH_SAMPLE_SCENE_DEPTH(UV.xy), UNITY_MATRIX_I_VP), UNITY_MATRIX_V); 99 } 100 else 101 { 102 Out = LinearEyeDepth(SHADERGRAPH_SAMPLE_SCENE_DEPTH(UV.xy), _ZBufferParams); 103 } 104} 105"; 106 } 107 108 public bool RequiresDepthTexture(ShaderStageCapability stageCapability) 109 { 110 return true; 111 } 112 } 113}