浏览代码

Depth Texture Node

- SamplerShaderProperty
/main
Matt Dean 7 年前
当前提交
874bec55
共有 4 个文件被更改,包括 163 次插入0 次删除
  1. 46
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SamplerShaderProperty.cs
  2. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SamplerShaderProperty.cs.meta
  3. 106
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/DepthTextureNode.cs
  4. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/DepthTextureNode.cs.meta

46
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SamplerShaderProperty.cs


using System;
using System.Text;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Serializable]
public class SamplerShaderProperty : AbstractShaderProperty<float>
{
public override PropertyType propertyType
{
get { return PropertyType.Float; }
}
public override Vector4 defaultValue
{
get { return new Vector4(value, value, value, value);}
}
public override string GetPropertyBlockString()
{
var result = new StringBuilder();
result.Append(referenceName);
result.Append("(\"");
result.Append(displayName);
result.Append("\", Float) = ");
result.Append(value);
return result.ToString();
}
public override string GetPropertyDeclarationString()
{
return "sampler2D " + referenceName + ";";
}
public override PreviewProperty GetPreviewMaterialProperty()
{
return new PreviewProperty()
{
m_Name = referenceName,
m_PropType = PropertyType.Float,
m_Float = value
};
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SamplerShaderProperty.cs.meta


fileFormatVersion: 2
guid: 165606e7f31c5df4ebb94765e37694c2
timeCreated: 1505346922

106
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/DepthTextureNode.cs


using UnityEditor.Graphing;
using UnityEngine;
using UnityEditor.ShaderGraph.Drawing.Controls;
using System.Collections.Generic;
namespace UnityEditor.ShaderGraph
{
public enum DepthTextureMode
{
Default,
Normalized
};
[Title("Input/Scene/Depth Texture")]
public class DepthTextureNode : AbstractMaterialNode, IGenerateProperties, IMayRequireScreenPosition
{
const string kUVSlotName = "UV";
const string kOutputSlotName = "Out";
public const int UVSlotId = 0;
public const int OutputSlotId = 1;
public DepthTextureNode()
{
name = "Depth Texture";
UpdateNodeAfterDeserialization();
}
public override bool hasPreview
{
get { return true; }
}
[SerializeField]
private DepthTextureMode m_DepthTextureMode = DepthTextureMode.Default;
[EnumControl("Mode")]
public DepthTextureMode depthTextureMode
{
get { return m_DepthTextureMode; }
set
{
if (m_DepthTextureMode == value)
return;
m_DepthTextureMode = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new ScreenPositionMaterialSlot(UVSlotId, kUVSlotName, kUVSlotName));
AddSlot(new Vector1MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0));
RemoveSlotsNameNotMatching(new[] { UVSlotId, OutputSlotId });
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty()
{
m_Name = "_CameraDepthTexture",
m_PropType = PropertyType.Float,
m_Vector4 = new Vector4(1, 1, 1, 1),
m_Float = 1,
m_Color = new Vector4(1, 1, 1, 1),
});
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
properties.AddShaderProperty(new SamplerShaderProperty
{
overrideReferenceName = "_CameraDepthTexture",
generatePropertyBlock = false
});
}
public override string GetVariableNameForSlot(int slotId)
{
switch (depthTextureMode)
{
case DepthTextureMode.Normalized:
return "Linear01Depth(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(" + GetSlotValue(UVSlotId, GenerationMode.Preview) + ")).r)";
default:
return "LinearEyeDepth(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(" + GetSlotValue(UVSlotId, GenerationMode.Preview) + ")).r)";
}
}
public bool RequiresScreenPosition()
{
var uvSlot = FindInputSlot<MaterialSlot>(UVSlotId) as ScreenPositionMaterialSlot;
if (uvSlot == null)
return false;
if (uvSlot.isConnected)
return false;
return uvSlot.RequiresScreenPosition();
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/DepthTextureNode.cs.meta


fileFormatVersion: 2
guid: 93d2a1d512bd9114a8d1a21ade3d6ea6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
正在加载...
取消
保存