浏览代码

Merge pull request #99 from Unity-Technologies/node-input-scene

Node Input Scene
/main
GitHub 7 年前
当前提交
1a3f590c
共有 18 个文件被更改,包括 682 次插入16 次删除
  1. 38
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/CameraNode.cs
  2. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/TransformNode.cs
  3. 35
      MaterialGraphProject/Assets/NewNodes/Editor/Sampler2DShaderProperty.cs
  4. 3
      MaterialGraphProject/Assets/NewNodes/Editor/Sampler2DShaderProperty.cs.meta
  5. 112
      MaterialGraphProject/Assets/NewNodes/Editor/SceneDepthNode.cs
  6. 8
      MaterialGraphProject/Assets/NewNodes/Editor/SceneDepthNode.cs.meta
  7. 114
      MaterialGraphProject/Assets/NewNodes/Editor/SceneNormalsNode.cs
  8. 8
      MaterialGraphProject/Assets/NewNodes/Editor/SceneNormalsNode.cs.meta
  9. 109
      MaterialGraphProject/Assets/NewNodes/Editor/SceneVelocityNode.cs
  10. 8
      MaterialGraphProject/Assets/NewNodes/Editor/SceneVelocityNode.cs.meta
  11. 49
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/AmbientNode.cs
  12. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/AmbientNode.cs.meta
  13. 98
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/FogNode.cs
  14. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/FogNode.cs.meta
  15. 41
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/ObjectNode.cs
  16. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/ObjectNode.cs.meta
  17. 39
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/ScreenNode.cs
  18. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/ScreenNode.cs.meta

38
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/CameraNode.cs


[Title("Input", "Scene", "Camera")]
public class CameraNode : AbstractMaterialNode
{
private const string kOutputSlotName = "Pos";
private const string kOutputSlot1Name = "Dir";
private const string kOutputSlot2Name = "Near";
private const string kOutputSlot3Name = "Far";
private const string kOutputSlot4Name = "Sign";
const string kOutputSlotName = "Position";
const string kOutputSlot1Name = "Direction";
const string kOutputSlot2Name = "Orthographic";
const string kOutputSlot3Name = "Near Plane";
const string kOutputSlot4Name = "Far Plane";
const string kOutputSlot5Name = "Sign";
const string kOutputSlot6Name = "Width";
const string kOutputSlot7Name = "Height";
public const int OutputSlotId = 0;
public const int OutputSlot1Id = 1;

public const int OutputSlot5Id = 5;
public const int OutputSlot6Id = 6;
public const int OutputSlot7Id = 7;
public CameraNode()
{

AddSlot(new Vector1MaterialSlot(OutputSlot2Id, kOutputSlot2Name, kOutputSlot2Name, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlot3Id, kOutputSlot3Name, kOutputSlot3Name, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlot4Id, kOutputSlot4Name, kOutputSlot4Name, SlotType.Output, 1));
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { OutputSlotId, OutputSlot1Id, OutputSlot2Id, OutputSlot3Id, OutputSlot4Id }; }
AddSlot(new Vector1MaterialSlot(OutputSlot5Id, kOutputSlot5Name, kOutputSlot5Name, SlotType.Output, 1));
AddSlot(new Vector1MaterialSlot(OutputSlot6Id, kOutputSlot6Name, kOutputSlot6Name, SlotType.Output, 1));
AddSlot(new Vector1MaterialSlot(OutputSlot7Id, kOutputSlot7Name, kOutputSlot7Name, SlotType.Output, 1));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, OutputSlot1Id, OutputSlot2Id, OutputSlot3Id, OutputSlot4Id, OutputSlot5Id, OutputSlot6Id, OutputSlot7Id });
}
public override string GetVariableNameForSlot(int slotId)

case OutputSlot1Id:
return "mul(unity_ObjectToWorld, UNITY_MATRIX_IT_MV [2].xyz)";
return "-1 * mul(unity_ObjectToWorld, UNITY_MATRIX_IT_MV [2].xyz)";
return "unity_OrthoParams.w";
case OutputSlot3Id:
case OutputSlot3Id:
case OutputSlot4Id:
case OutputSlot4Id:
case OutputSlot5Id:
case OutputSlot6Id:
return "unity_OrthoParams.x";
case OutputSlot7Id:
return "unity_OrthoParams.y";
default:
return "_WorldSpaceCameraPos";
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/TransformNode.cs


protected int[] validSlots
{
get { return new[] {InputSlotId, OutputSlotId}; }
get { return new[] { InputSlotId, OutputSlotId }; }
}
protected virtual MaterialSlot GetInputSlot()

return conversion.from.ToNeededCoordinateSpace();
}
}
}
}

35
MaterialGraphProject/Assets/NewNodes/Editor/Sampler2DShaderProperty.cs


using System;
using System.Text;
using UnityEngine;
/*namespace UnityEditor.ShaderGraph
{
[Serializable]
public class Sampler2DShaderProperty : AbstractShaderProperty<object>
{
public override PropertyType propertyType
{
get { return PropertyType.SamplerState; }
}
public override Vector4 defaultValue
{
get { return new Vector4(); }
}
public override string GetPropertyBlockString()
{
return string.Empty;
}
public override string GetPropertyDeclarationString()
{
return "sampler2D " + referenceName + ";";
}
public override PreviewProperty GetPreviewMaterialProperty()
{
return default(PreviewProperty);
}
}
}*/

3
MaterialGraphProject/Assets/NewNodes/Editor/Sampler2DShaderProperty.cs.meta


fileFormatVersion: 2
guid: 165606e7f31c5df4ebb94765e37694c2
timeCreated: 1505346922

112
MaterialGraphProject/Assets/NewNodes/Editor/SceneDepthNode.cs


using UnityEditor.Graphing;
using UnityEngine;
using UnityEditor.ShaderGraph.Drawing.Controls;
using System.Collections.Generic;
/*namespace UnityEditor.ShaderGraph
{
public enum SceneDepthMode
{
Default,
Normalized
};
[Title("Input", "Scene", "Scene Depth")]
public sealed class SceneDepthNode : AbstractMaterialNode, IGenerateProperties, IGeneratesBodyCode, IMayRequireScreenPosition
{
const string kUVSlotName = "UV";
const string kOutputSlotName = "Out";
public const int UVSlotId = 0;
public const int OutputSlotId = 1;
public SceneDepthNode()
{
name = "Scene Depth";
UpdateNodeAfterDeserialization();
}
public override bool hasPreview
{
get { return true; }
}
[SerializeField]
private SceneDepthMode m_SceneDepthMode = SceneDepthMode.Default;
[EnumControl("Mode")]
public SceneDepthMode sceneDepthMode
{
get { return m_SceneDepthMode; }
set
{
if (m_SceneDepthMode == value)
return;
m_SceneDepthMode = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public 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()
{
name = "_CameraDepthTexture",
propType = PropertyType.Float,
vector4Value = new Vector4(1, 1, 1, 1),
floatValue = 1,
colorValue = new Vector4(1, 1, 1, 1),
});
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
properties.AddShaderProperty(new Sampler2DShaderProperty
{
overrideReferenceName = "_CameraDepthTexture",
generatePropertyBlock = false
});
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
string uvValue = GetSlotValue(UVSlotId, generationMode);
string outputValue = GetSlotValue(OutputSlotId, generationMode);
string methodName = "";
switch (sceneDepthMode)
{
case SceneDepthMode.Normalized:
methodName = "Linear01Depth";
break;
default:
methodName = "LinearEyeDepth";
break;
}
visitor.AddShaderChunk(string.Format("{0} _DepthTexture = {1}(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD({2})).r);", precision, methodName, uvValue), true);
visitor.AddShaderChunk(string.Format("{0} {1} = _DepthTexture;", ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType), GetVariableNameForSlot(OutputSlotId)), true);
}
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/NewNodes/Editor/SceneDepthNode.cs.meta


fileFormatVersion: 2
guid: 93d2a1d512bd9114a8d1a21ade3d6ea6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

114
MaterialGraphProject/Assets/NewNodes/Editor/SceneNormalsNode.cs


using UnityEditor.Graphing;
using UnityEngine;
using UnityEditor.ShaderGraph.Drawing.Controls;
using System.Collections.Generic;
/*namespace UnityEditor.ShaderGraph
{
[Title("Input", "Scene", "Scene Normals")]
public class SceneNormalsNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction, IGenerateProperties, IMayRequireScreenPosition
{
const string kUVSlotName = "UV";
const string kOutputSlotName = "Out";
public const int UVSlotId = 0;
public const int OutputSlotId = 1;
public SceneNormalsNode()
{
name = "Scene Normals";
UpdateNodeAfterDeserialization();
}
public override bool hasPreview
{
get { return true; }
}
string GetFunctionName()
{
return "Unity_DecodeViewNormalStereo";
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new ScreenPositionMaterialSlot(UVSlotId, kUVSlotName, kUVSlotName));
AddSlot(new Vector3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector3.zero));
RemoveSlotsNameNotMatching(new[] { UVSlotId, OutputSlotId });
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty()
{
name = "_CameraDepthNormalsTexture",
propType = PropertyType.Float,
vector4Value = new Vector4(1, 1, 1, 1),
floatValue = 1,
colorValue = new Vector4(1, 1, 1, 1),
});
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
properties.AddShaderProperty(new Sampler2DShaderProperty
{
overrideReferenceName = "_CameraDepthNormalsTexture",
generatePropertyBlock = false
});
}
string GetFunctionPrototype(string argIn, string argOut)
{
return string.Format("void {0} ({1}4 {2}, out {3} {4})", GetFunctionName(),
precision, argIn,
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType), argOut);
}
string GetFunctionCallBody(string inputValue, string outputValue)
{
return GetFunctionName() + " (" + inputValue + ", " + outputValue + ");";
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("Tex", "Out"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk(string.Format("{0}3 nn = Tex.xyz * {0}3(2.0 * 1.7777, 2.0 * 1.7777, 0) + {0}3(-1.7777, -1.7777, 1);", precision), true);
outputString.AddShaderChunk(string.Format("{0} g = 2.0 / dot(nn.xyz, nn.xyz);", precision), true);
outputString.AddShaderChunk(string.Format("{0}3 n;", precision), true);
outputString.AddShaderChunk("n.xy = g * nn.xy;", true);
outputString.AddShaderChunk("n.z = g - 1.0;", true);
outputString.AddShaderChunk(string.Format("Out = n;", precision), true);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
string uvValue = GetSlotValue(UVSlotId, generationMode);
string outputValue = GetSlotValue(OutputSlotId, generationMode);
visitor.AddShaderChunk(string.Format("{0}4 _DepthNormalsTexture = tex2D(_CameraDepthNormalsTexture, {1});", precision, uvValue), true);
visitor.AddShaderChunk(string.Format("{0} {1};", ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType), GetVariableNameForSlot(OutputSlotId)), true);
visitor.AddShaderChunk(GetFunctionCallBody("_DepthNormalsTexture", outputValue), true);
visitor.AddShaderChunk(string.Format("{1} = {1} * {0}3(1.0, 1.0, -1.0);", precision, GetVariableNameForSlot(OutputSlotId)), true);
}
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/NewNodes/Editor/SceneNormalsNode.cs.meta


fileFormatVersion: 2
guid: e54cf83dd14c5ea4cbecc38ad40a3a4b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

109
MaterialGraphProject/Assets/NewNodes/Editor/SceneVelocityNode.cs


using UnityEditor.Graphing;
using UnityEngine;
using UnityEditor.ShaderGraph.Drawing.Controls;
using System.Collections.Generic;
/*namespace UnityEditor.ShaderGraph
{
public enum SceneVelocityMode
{
Default,
Hue
};
[Title("Input", "Scene", "Scene Velocity")]
public class SceneVelocityNode : AbstractMaterialNode, IGenerateProperties, IGeneratesBodyCode, IMayRequireScreenPosition
{
const string kUVSlotName = "UV";
const string kOutputSlotName = "Out";
public const int UVSlotId = 0;
public const int OutputSlotId = 1;
public SceneVelocityNode()
{
name = "Scene Velocity";
UpdateNodeAfterDeserialization();
}
public override bool hasPreview
{
get { return true; }
}
[SerializeField]
private SceneVelocityMode m_SceneVelocityMode = SceneVelocityMode.Default;
[EnumControl("Mode")]
public SceneVelocityMode sceneVelocityMode
{
get { return m_SceneVelocityMode; }
set
{
if (m_SceneVelocityMode == value)
return;
m_SceneVelocityMode = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new ScreenPositionMaterialSlot(UVSlotId, kUVSlotName, kUVSlotName));
AddSlot(new Vector3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector3.zero));
RemoveSlotsNameNotMatching(new[] { UVSlotId, OutputSlotId });
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty()
{
name = "_CameraMotionVectorTexture",
propType = PropertyType.Float,
vector4Value = new Vector4(1, 1, 1, 1),
floatValue = 1,
colorValue = new Vector4(1, 1, 1, 1),
});
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
properties.AddShaderProperty(new Sampler2DShaderProperty
{
overrideReferenceName = "_CameraMotionVectorTexture",
generatePropertyBlock = false
});
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
string uvValue = GetSlotValue(UVSlotId, generationMode);
string outputValue = GetSlotValue(OutputSlotId, generationMode);
visitor.AddShaderChunk(string.Format("{0}3 _MotionVectorTexture = {0}3(tex2D(_CameraMotionVectorTexture, {1}).rg, 0);", precision, uvValue), true);
if (sceneVelocityMode == SceneVelocityMode.Hue)
{
visitor.AddShaderChunk(string.Format("{0} hue = (atan2(_MotionVectorTexture.x, _MotionVectorTexture.y) / 3.14159265359 + 1.0) * 0.5;", precision), true);
visitor.AddShaderChunk(string.Format("_MotionVectorTexture = saturate({0}3(abs(hue * 6.0 - 3.0) - 1.0, 2.0 - abs(hue * 6.0 - 2.0), 2.0 - abs(hue * 6.0 - 4.0)));", precision), true);
}
visitor.AddShaderChunk(string.Format("{0} {1} = _MotionVectorTexture;", ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType), GetVariableNameForSlot(OutputSlotId)), true);
}
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/NewNodes/Editor/SceneVelocityNode.cs.meta


fileFormatVersion: 2
guid: 8e751ddf46d42b349a993a7438152f82
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

49
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/AmbientNode.cs


using UnityEditor.Graphing;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Scene", "Ambient")]
public class AmbientNode : AbstractMaterialNode
{
const string kOutputSlotName = "Color";
const string kOutputSlot1Name = "Sky";
const string kOutputSlot2Name = "Equator";
const string kOutputSlot3Name = "Ground";
public const int OutputSlotId = 0;
public const int OutputSlot1Id = 1;
public const int OutputSlot2Id = 2;
public const int OutputSlot3Id = 3;
public AmbientNode()
{
name = "Ambient";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
AddSlot(new Vector4MaterialSlot(OutputSlot1Id, kOutputSlot1Name, kOutputSlot1Name, SlotType.Output, Vector4.zero));
AddSlot(new Vector4MaterialSlot(OutputSlot2Id, kOutputSlot2Name, kOutputSlot2Name, SlotType.Output, Vector4.zero));
AddSlot(new Vector4MaterialSlot(OutputSlot3Id, kOutputSlot3Name, kOutputSlot3Name, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, OutputSlot1Id, OutputSlot2Id, OutputSlot3Id });
}
public override string GetVariableNameForSlot(int slotId)
{
switch (slotId)
{
case OutputSlot1Id:
return "unity_AmbientSky";
case OutputSlot2Id:
return "unity_AmbientEquator";
case OutputSlot3Id:
return "unity_AmbientGround";
default:
return "UNITY_LIGHTMODEL_AMBIENT";
}
}
}
}

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


fileFormatVersion: 2
guid: 0f9e9a126b4ecf24d81258763ac4a64d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

98
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/FogNode.cs


using UnityEngine;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Scene", "Fog")]
public class FogNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction, IMayRequirePosition
{
public FogNode()
{
name = "Fog";
UpdateNodeAfterDeserialization();
}
const int OutputSlotId = 0;
const int OutputSlot1Id = 1;
const string kOutputSlotName = "Color";
const string kOutputSlot1Name = "Density";
public override bool hasPreview
{
get { return false; }
}
string GetFunctionName()
{
return string.Format("Unity_Fog_{0}", precision);
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
AddSlot(new Vector1MaterialSlot(OutputSlot1Id, kOutputSlot1Name, kOutputSlot1Name, SlotType.Output, 0));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, OutputSlot1Id });
}
string GetFunctionPrototype(string argIn, string argOut, string argOut2)
{
return string.Format("void {0} ({1}3 {2}, out {3} {4}, out {5} {6})", GetFunctionName(), precision, argIn,
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType), argOut,
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlot1Id).concreteValueType), argOut2);
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
string colorValue = GetSlotValue(OutputSlotId, generationMode);
string densityValue = GetSlotValue(OutputSlot1Id, generationMode);
visitor.AddShaderChunk(string.Format("{0} {1};", ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType), GetVariableNameForSlot(OutputSlotId)), true);
visitor.AddShaderChunk(string.Format("{0} {1};", ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlot1Id).concreteValueType), GetVariableNameForSlot(OutputSlot1Id)), true);
string objectSpacePosition = string.Format("IN.{0}", CoordinateSpace.Object.ToVariableName(InterpolatorType.Position));
visitor.AddShaderChunk(GetFunctionCallBody(objectSpacePosition, colorValue, densityValue), true);
}
string GetFunctionCallBody(string objectSpaceValue, string outputValue, string output1Value)
{
return GetFunctionName() + " (" + objectSpaceValue + ", " + outputValue + ", " + output1Value + ");";
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk(GetFunctionPrototype("ObjectSpacePosition", "Color", "Density"), false);
visitor.AddShaderChunk("{", false);
visitor.Indent();
visitor.AddShaderChunk("Color = unity_FogColor;", true);
visitor.AddShaderChunk(string.Format("{0} clipZ_01 = UNITY_Z_0_FAR_FROM_CLIPSPACE(UnityObjectToClipPos(ObjectSpacePosition).z);", precision), true);
visitor.AddShaderChunk("#if defined(FOG_LINEAR)", true);
visitor.Indent();
visitor.AddShaderChunk(string.Format("{0} fogFactor = saturate(clipZ_01 * unity_FogParams.z + unity_FogParams.w);", precision), true);
visitor.AddShaderChunk("Density = fogFactor;", true);
visitor.Deindent();
visitor.AddShaderChunk("#elif defined(FOG_EXP)", true);
visitor.Indent();
visitor.AddShaderChunk(string.Format("{0} fogFactor = unity_FogParams.y * clipZ_01;", precision), true);
visitor.AddShaderChunk("Density = {2}(saturate(exp2(-fogFactor)));", true);
visitor.Deindent();
visitor.AddShaderChunk("#elif defined(FOG_EXP2)", true);
visitor.Indent();
visitor.AddShaderChunk(string.Format("{0} fogFactor = unity_FogParams.x * clipZ_01;", precision), true);
visitor.AddShaderChunk("Density = {2}(saturate(exp2(-fogFactor*fogFactor)));", true);
visitor.Deindent();
visitor.AddShaderChunk("#else", true);
visitor.Indent();
visitor.AddShaderChunk("Density = 0.0h;", true);
visitor.Deindent();
visitor.AddShaderChunk("#endif", true);
visitor.Deindent();
visitor.AddShaderChunk("}", false);
}
public NeededCoordinateSpace RequiresPosition()
{
return CoordinateSpace.Object.ToNeededCoordinateSpace();
}
}
}

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


fileFormatVersion: 2
guid: f934acb3f675022448ac439d87d84a80
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

41
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/ObjectNode.cs


using UnityEditor.Graphing;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Scene", "Object")]
public sealed class ObjectNode : AbstractMaterialNode
{
const string kOutputSlotName = "Position";
const string kOutputSlot1Name = "Scale";
public const int OutputSlotId = 0;
public const int OutputSlot1Id = 1;
public ObjectNode()
{
name = "Object";
UpdateNodeAfterDeserialization();
}
public override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector3.zero));
AddSlot(new Vector3MaterialSlot(OutputSlot1Id, kOutputSlot1Name, kOutputSlot1Name, SlotType.Output, Vector3.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, OutputSlot1Id });
}
public override string GetVariableNameForSlot(int slotId)
{
switch (slotId)
{
case OutputSlot1Id:
return @"float3(length(float3(unity_ObjectToWorld[0].x, unity_ObjectToWorld[1].x, unity_ObjectToWorld[2].x)),
length(float3(unity_ObjectToWorld[0].y, unity_ObjectToWorld[1].y, unity_ObjectToWorld[2].y)),
length(float3(unity_ObjectToWorld[0].z, unity_ObjectToWorld[1].z, unity_ObjectToWorld[2].z)))";
default:
return "unity_ObjectToWorld._m03_m13_m23";
}
}
}
}

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


fileFormatVersion: 2
guid: 081b8aed5e33ba1418a6a80f7693b9b4
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

39
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/ScreenNode.cs


using UnityEditor.Graphing;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Scene", "Screen")]
public sealed class ScreenNode : AbstractMaterialNode
{
const string kOutputSlotName = "Width";
const string kOutputSlot1Name = "Height";
public const int OutputSlotId = 0;
public const int OutputSlot1Id = 1;
public ScreenNode()
{
name = "Screen";
UpdateNodeAfterDeserialization();
}
public override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlot1Id, kOutputSlot1Name, kOutputSlot1Name, SlotType.Output, 0));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, OutputSlot1Id });
}
public override string GetVariableNameForSlot(int slotId)
{
switch (slotId)
{
case OutputSlot1Id:
return "_ScreenParams.y";
default:
return "_ScreenParams.x";
}
}
}
}

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


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