SHARE
TWEET

DepthNormalsTextureNode.cs

a guest Jul 6th, 2019 276 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEditor.Graphing;
  4.  
  5. namespace UnityEditor.ShaderGraph
  6. {
  7.     [Title("Custom", "Input", "Texture", "_CameraDepthNormalsTexture")]
  8.     class DepthNormalsTextureNode : AbstractMaterialNode
  9.     {
  10.         public const int OutputSlotId = 0;
  11.         const string kOutputSlotName = "Out";
  12.  
  13.         private string inputTexture;
  14.        
  15.         public DepthNormalsTextureNode()
  16.         {
  17.             name = "_CameraDepthNormalsTexture";
  18.             inputTexture = "_CameraDepthNormalsTexture";
  19.             UpdateNodeAfterDeserialization();
  20.         }
  21.  
  22.         public sealed override void UpdateNodeAfterDeserialization()
  23.         {
  24.             AddSlot(new Texture2DMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
  25.             RemoveSlotsNameNotMatching(new[] {OutputSlotId});
  26.         }
  27.        
  28.         public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
  29.         {
  30.             properties.AddShaderProperty(new TextureShaderProperty
  31.             {
  32.                 displayName = "Main Texture",
  33.                 overrideReferenceName = GetVariableNameForSlot(OutputSlotId),
  34.                 generatePropertyBlock = false
  35.             });
  36.         }
  37.  
  38.         public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
  39.         {
  40.             properties.Add(new PreviewProperty(PropertyType.Texture2D)
  41.             {
  42.                 name = GetVariableNameForSlot(OutputSlotId),
  43.                 textureValue = Shader.GetGlobalTexture(inputTexture)
  44.             });
  45.         }
  46.        
  47.         public override string GetVariableNameForSlot(int slotId)
  48.         {
  49.             return slotId == OutputSlotId ? inputTexture : base.GetVariableNameForSlot(slotId);
  50.         }
  51.     }
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top