|
|
|
|
|
|
using UnityEditor.Graphing; |
|
|
|
using UnityEditor.ShaderGraph.Drawing.Controls; |
|
|
|
using System.Collections.Generic; |
|
|
|
using UnityEditor.Graphing; |
|
|
|
public class FogNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequirePosition |
|
|
|
public class FogNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction, IMayRequirePosition |
|
|
|
public FogNode() |
|
|
|
{ |
|
|
|
name = "Fog"; |
|
|
|
UpdateNodeAfterDeserialization(); |
|
|
|
} |
|
|
|
|
|
|
|
const int OutputSlotId = 0; |
|
|
|
const int OutputSlot1Id = 1; |
|
|
|
public const int OutputSlotId = 0; |
|
|
|
public const int OutputSlot1Id = 1; |
|
|
|
public override bool hasPreview |
|
|
|
{ |
|
|
|
get { return false; } |
|
|
|
} |
|
|
|
public FogNode() |
|
|
|
string GetFunctionName() |
|
|
|
name = "Fog"; |
|
|
|
UpdateNodeAfterDeserialization(); |
|
|
|
return string.Format("Unity_Fog_{0}", precision); |
|
|
|
} |
|
|
|
|
|
|
|
public sealed override void UpdateNodeAfterDeserialization() |
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
string uvValue = GetSlotValue(OutputSlotId, generationMode); |
|
|
|
string outputValue = GetSlotValue(OutputSlot1Id, 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 + ");"; |
|
|
|
} |
|
|
|
visitor.AddShaderChunk(string.Format("{0} {1} = unity_FogColor;", |
|
|
|
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType), |
|
|
|
GetVariableNameForSlot(OutputSlotId)), true); |
|
|
|
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|
|
|
{ |
|
|
|
visitor.AddShaderChunk(GetFunctionPrototype("ObjectSpacePosition", "Color", "Density"), false); |
|
|
|
visitor.AddShaderChunk("{", false); |
|
|
|
visitor.Indent(); |
|
|
|
visitor.AddShaderChunk(string.Format("{0} clipZ_01 = UNITY_Z_0_FAR_FROM_CLIPSPACE(UnityObjectToClipPos(IN.ObjectSpacePosition).z);", precision), true); |
|
|
|
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(string.Format("{0} {1} = fogFactor;", |
|
|
|
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlot1Id).concreteValueType), |
|
|
|
GetVariableNameForSlot(OutputSlot1Id)), true); |
|
|
|
visitor.AddShaderChunk("Density = fogFactor;", true); |
|
|
|
visitor.AddShaderChunk(string.Format("{0} {1} = {2}(saturate(exp2(-fogFactor)));", |
|
|
|
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlot1Id).concreteValueType), |
|
|
|
GetVariableNameForSlot(OutputSlot1Id), precision), true); |
|
|
|
visitor.AddShaderChunk("Density = {2}(saturate(exp2(-fogFactor)));", true); |
|
|
|
visitor.AddShaderChunk(string.Format("{0} {1} = {2}(saturate(exp2(-fogFactor*fogFactor)));", |
|
|
|
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlot1Id).concreteValueType), |
|
|
|
GetVariableNameForSlot(OutputSlot1Id), precision), true); |
|
|
|
visitor.AddShaderChunk("Density = {2}(saturate(exp2(-fogFactor*fogFactor)));", true); |
|
|
|
visitor.AddShaderChunk(string.Format("{0} {1} = 0.0h;", |
|
|
|
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlot1Id).concreteValueType), |
|
|
|
GetVariableNameForSlot(OutputSlot1Id)), true); |
|
|
|
visitor.AddShaderChunk("Density = 0.0h;", true); |
|
|
|
|
|
|
|
visitor.Deindent(); |
|
|
|
visitor.AddShaderChunk("}", false); |
|
|
|
} |
|
|
|
|
|
|
|
public NeededCoordinateSpace RequiresPosition() |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |