浏览代码

Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017

/main
bfogerty 8 年前
当前提交
82da97c0
共有 17 个文件被更改,包括 1057 次插入177 次删除
  1. 8
      MaterialGraphProject/Assets/Andre/Editor/ToggleNodePresenter.cs
  2. 5
      MaterialGraphProject/Assets/Andre/New Material.mat
  3. 2
      MaterialGraphProject/Assets/Andre/New Shader Graph.ShaderGraph
  4. 11
      MaterialGraphProject/Assets/Andre/ToggleNode.cs
  5. 140
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/CombineNode.cs
  6. 90
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SplitNode.cs
  7. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphNode.cs
  8. 50
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/AbstractSurfaceMasterNode.cs
  9. 48
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs
  10. 1
      MaterialGraphProject/Assets/Andre/FlowMap.ShaderGraph
  11. 9
      MaterialGraphProject/Assets/Andre/FlowMap.ShaderGraph.meta
  12. 643
      MaterialGraphProject/Assets/TestAssets/flowmap.png
  13. 84
      MaterialGraphProject/Assets/TestAssets/flowmap.png.meta
  14. 122
      MaterialGraphProject/Assets/NewNodes/WIP/ParallaxNode.cs
  15. 12
      MaterialGraphProject/Assets/NewNodes/WIP/ParallaxNode.cs.meta

8
MaterialGraphProject/Assets/Andre/Editor/ToggleNodePresenter.cs


using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing

{
base.OnGUIHandler();
var cNode = node as BlendModeNode;
var cNode = node as ToggleNode;
cNode.blendMode = (BlendModesEnum)EditorGUILayout.EnumPopup("", cNode.blendMode);
cNode.value = EditorGUILayout.Toggle(cNode.value);
cNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), cNode.exposedState);
}
/* public override float GetHeight()

*/
public override float GetHeight()
{
return 3 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
return 2 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}

5
MaterialGraphProject/Assets/Andre/New Material.mat


m_Texture: {fileID: 10305, guid: 0000000000000000f000000000000000, type: 0}
m_Scale: {x: 1, y: 2}
m_Offset: {x: 0, y: 0}
- Texture_7e044bc6_b639_4457_83f6_752bfaedcb11_Uniform:
m_Texture: {fileID: 2800000, guid: 330f42016073a97418a4aae5517e32c8, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}

m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- Toggle_bda28932_b1ab_4b0b_ba54_ca5db612047a_Uniform: 0
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1

2
MaterialGraphProject/Assets/Andre/New Shader Graph.ShaderGraph
文件差异内容过多而无法显示
查看文件

11
MaterialGraphProject/Assets/Andre/ToggleNode.cs


{
[SerializeField]
private float m_Float;
private bool m_ToggleState;
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Ouput";

get { return PropertyType.Float; }
}
public float value
public bool value
get { return m_Float; }
get { return m_ToggleState; }
if (m_Float == value)
if (m_ToggleState == value)
m_Float = value;
m_ToggleState = value;
if (onModified != null)
{
onModified(this, ModificationScope.Node);

{
m_Name = propertyName,
m_PropType = PropertyType.Float,
m_Float = value
m_Float = value ? 1f : 0f
};
}
}

140
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/CombineNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Channel/Combine")]
public class CombineNode : PropertyNode, IGeneratesBodyCode
public class CombineNode : AbstractMaterialNode, IGeneratesBodyCode
protected const string kOutputSlot0Id = "Input0";
protected const string kOutputSlot1Id = "Input1";
protected const string kOutputSlot2Id = "Input2";
protected const string kOutputSlot3Id = "Input3";
protected const string kInputSlot0Name = "Input1";
protected const string kInputSlot1Name = "Input2";
protected const string kInputSlot2Name = "Input3";
protected const string kInputSlot3Name = "Input4";
protected const string kOutputSlotRGBAName = "RGBA";
protected const string kOutputSlotRGBSlotName = "RGB";
protected const string kOutputSlotRGSlotName = "RG";
protected const string kOutputSlotName = "Output";
public const int InputSlot0Id = 0;
public const int InputSlot1Id = 1;

public const int OutputSlotRGBAId = 4;
public const int OutputSlotRGBId = 5;
public const int OutputSlotRGId = 6;
public const int OutputSlotId = 4;
public CombineNode()
{

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(InputSlot0Id, kOutputSlot0Id, kOutputSlot0Id, SlotType.Input, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot(InputSlot1Id, kOutputSlot1Id, kOutputSlot1Id, SlotType.Input, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot(InputSlot2Id, kOutputSlot2Id, kOutputSlot2Id, SlotType.Input, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot(InputSlot3Id, kOutputSlot3Id, kOutputSlot3Id, SlotType.Input, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotRGBAId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotRGBId, kOutputSlotRGBSlotName, kOutputSlotRGBSlotName, SlotType.Output, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotRGId, kOutputSlotRGSlotName, kOutputSlotRGSlotName, SlotType.Output, SlotValueType.Vector2, Vector4.zero));
AddSlot(new MaterialSlot(InputSlot0Id, kInputSlot0Name, kInputSlot0Name, SlotType.Input, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot(InputSlot1Id, kInputSlot1Name, kInputSlot1Name, SlotType.Input, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot(InputSlot2Id, kInputSlot2Name, kInputSlot2Name, SlotType.Input, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot(InputSlot3Id, kInputSlot3Name, kInputSlot3Name, SlotType.Input, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
get { return new[] { InputSlot0Id, InputSlot1Id, InputSlot2Id, InputSlot3Id, OutputSlotRGBAId, OutputSlotRGBId, OutputSlotRGId }; }
get { return new[] { InputSlot0Id, InputSlot1Id, InputSlot2Id, InputSlot3Id, OutputSlotId}; }
[SerializeField]
private Vector4 m_Value;
public Vector4 value
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
get { return m_Value; }
set
{
if (m_Value == value)
return;
m_Value = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlot0Id, InputSlot1Id, InputSlot2Id, InputSlot3Id }, new[] { OutputSlotId });
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForSlot(OutputSlotId) + " = " + GetNodeBody(generationMode) + ";", true);
public override PropertyType propertyType { get { return PropertyType.Vector4; } }
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
private int GetChannelCountForInput(int inputSlotId)
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
}
var inputSlot = FindInputSlot<MaterialSlot>(inputSlotId);
if (inputSlot == null)
return 0;
int numInputChannels = (int)inputSlot.concreteValueType;
if (owner.GetEdges(inputSlot.slotReference).ToList().Count() == 0)
numInputChannels = 0;
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
visitor.AddShaderChunk(precision + "4 " + propertyName + ";", true);
return numInputChannels;
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
private void AddChannelsFromInputSlot(GenerationMode generationMode, int inputSlot, ref string outputString, ref int freeChannel)
//if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
// return;
var inputValue = GetSlotValue(InputSlot0Id, generationMode);
visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + inputValue + ";", false);
//visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + precision + "4 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ", " + m_Value.w + ");", true);
}
string[] channelNames = { "r", "g", "b", "a" };
protected virtual MaterialSlot GetInputSlot()
{
return new MaterialSlot(InputSlot0Id, GetInputSlotName(), kOutputSlot0Id, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
int numChannel = GetChannelCountForInput(inputSlot);
numChannel = Math.Min(freeChannel, numChannel);
if (numChannel <= 0)
return;
protected virtual string GetInputSlotName() { return "Input"; }
string channelInputName = GetSlotValue(inputSlot, generationMode);
outputString += channelInputName;
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Vector4,
m_Vector4 = m_Value
};
freeChannel -= numChannel;
if (freeChannel != 0)
outputString += ",";
/*public override string GetVariableNameForSlot(int slotId)
protected string GetNodeBody(GenerationMode generationMode)
string slotOutput;
switch (slotId)
string outputString = precision + "4(";
int freeChannels = 4;
AddChannelsFromInputSlot(generationMode, InputSlot0Id, ref outputString, ref freeChannels);
AddChannelsFromInputSlot(generationMode, InputSlot1Id, ref outputString, ref freeChannels);
AddChannelsFromInputSlot(generationMode, InputSlot2Id, ref outputString, ref freeChannels);
AddChannelsFromInputSlot(generationMode, InputSlot3Id, ref outputString, ref freeChannels);
for (int i = freeChannels; i > 0; --i)
case OutputSlotRId:
slotOutput = ".r";
break;
case OutputSlotGId:
slotOutput = ".g";
break;
case OutputSlotBId:
slotOutput = ".b";
break;
case OutputSlotAId:
slotOutput = ".a";
break;
default:
slotOutput = "";
break;
outputString += "0.0";
if (i > 1)
outputString += ", ";
return propertyName + slotOutput;
//return GetVariableNameForNode() + slotOutput;
}*/
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(GetPreviewProperty());
outputString += ")";
return outputString;
}
}
}

90
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SplitNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class SplitNode : PropertyNode, IGeneratesBodyCode
public class SplitNode : AbstractMaterialNode, IGeneratesBodyCode
{
protected const string kInputSlotName = "Input";
protected const string kOutputSlotRName = "R";

get { return new[] { InputSlotId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, OutputSlotRGBId, OutputSlotRGId }; }
}
[SerializeField]
private Vector4 m_Value;
public Vector4 value
{
get { return m_Value; }
set
{
if (m_Value == value)
return;
m_Value = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
}
public override PropertyType propertyType { get { return PropertyType.Vector4; } }
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
visitor.AddShaderChunk(precision + "4 " + propertyName + ";", true);
}
//if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
// return;
var inputValue = GetSlotValue(InputSlotId, generationMode);
visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + inputValue + ";", false);
//visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + precision + "4 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ", " + m_Value.w + ");", true);
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlotId }, new[] { OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotRGBId, OutputSlotRGId });
string inputValue = GetSlotValue(InputSlotId, generationMode);
visitor.AddShaderChunk(precision +"4 "+ GetVariableNameForNode() + " = " + GetNodeBody(inputValue) + ";", true);
protected virtual MaterialSlot GetInputSlot()
protected string GetNodeBody(string inputValue)
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
string[] channelNames = { "r", "g", "b", "a" };
var inputSlot = FindInputSlot<MaterialSlot>(InputSlotId);
if (inputSlot == null)
return "1.0";
protected virtual string GetInputSlotName() { return "Input"; }
int numInputChannels = (int)inputSlot.concreteValueType;
if (owner.GetEdges(inputSlot.slotReference).ToList().Count() == 0)
numInputChannels = 0;
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
string outputString = precision + "4(";
if (numInputChannels == 0)
{
outputString += "1.0, 1.0, 1.0, 1.0)";
}
else
m_Name = propertyName,
m_PropType = PropertyType.Vector4,
m_Vector4 = m_Value
};
//float4(arg1, 1.0, 1.0)
outputString += inputValue;
for (int i = numInputChannels; i < 4; i++)
{
outputString += ", 1.0";
}
outputString += ")";
}
return outputString;
{
{
string slotOutput;
switch (slotId)
{

slotOutput = "";
break;
}
return propertyName + slotOutput;
//return GetVariableNameForNode() + slotOutput;
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(GetPreviewProperty());
return GetVariableNameForNode() + slotOutput;
}
}
}

9
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphNode.cs


, IMayRequireViewDirection
, IMayRequireWorldPosition
, IMayRequireVertexColor
, IMayRequireViewDirectionTangentSpace
{
[SerializeField]
private string m_SerializedSubGraph = string.Empty;

return false;
return subGraph.activeNodes.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection());
}
public bool RequiresViewDirectionTangentSpace()
{
if (subGraph == null)
return false;
return subGraph.activeNodes.OfType<IMayRequireViewDirectionTangentSpace>().Any(x => x.RequiresViewDirectionTangentSpace());
}
public bool RequiresWorldPosition()

50
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/AbstractSurfaceMasterNode.cs


// always add color because why not.
shaderInputVisitor.AddShaderChunk("float4 color : COLOR;", true);
bool requiresBitangent = activeNodeList.OfType<IMayRequireBitangent>().Any(x => x.RequiresBitangent());
bool requiresTangent = activeNodeList.OfType<IMayRequireTangent>().Any(x => x.RequiresTangent());
bool requiresViewDirTangentSpace = activeNodeList.OfType<IMayRequireViewDirectionTangentSpace>().Any(x => x.RequiresViewDirectionTangentSpace());
bool requiresViewDir = activeNodeList.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection());
bool requiresWorldPos = activeNodeList.OfType<IMayRequireWorldPosition>().Any(x => x.RequiresWorldPosition());
bool requiresNormal = activeNodeList.OfType<IMayRequireNormal>().Any(x => x.RequiresNormal());
bool requiresScreenPosition = activeNodeList.OfType<IMayRequireScreenPosition>().Any(x => x.RequiresScreenPosition());
bool requiresVertexColor = activeNodeList.OfType<IMayRequireVertexColor>().Any(x => x.RequiresVertexColor());
for (int uvIndex = 0; uvIndex < ShaderGeneratorNames.UVCount; ++uvIndex)
{
var channel = (UVChannel)uvIndex;

}
}
if (activeNodeList.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection()))
if (requiresViewDir || requiresViewDirTangentSpace)
if (activeNodeList.OfType<IMayRequireWorldPosition>().Any(x => x.RequiresWorldPosition()))
if (requiresWorldPos)
if (activeNodeList.OfType<IMayRequireScreenPosition>().Any(x => x.RequiresScreenPosition()))
if (requiresScreenPosition)
bool needBitangent = activeNodeList.OfType<IMayRequireBitangent>().Any(x => x.RequiresBitangent());
if (needBitangent || activeNodeList.OfType<IMayRequireTangent>().Any(x => x.RequiresTangent()))
if (requiresBitangent || requiresTangent || requiresViewDirTangentSpace)
{
shaderInputVisitor.AddShaderChunk("float4 worldTangent;", true);
vertexShaderBlock.AddShaderChunk("o.worldTangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w);", true);

if (needBitangent || activeNodeList.OfType<IMayRequireNormal>().Any(x => x.RequiresNormal()))
if (requiresBitangent || requiresNormal || requiresViewDirTangentSpace)
{
// is the normal connected?
var normalSlot = FindInputSlot<MaterialSlot>(NormalSlotId);

shaderBody.AddShaderChunk("float3 " + ShaderGeneratorNames.WorldSpaceNormal + " = normalize(IN.worldNormal);", true);
}
if (needBitangent)
if (requiresBitangent || requiresViewDirTangentSpace)
if (activeNodeList.OfType<IMayRequireVertexColor>().Any(x => x.RequiresVertexColor()))
if (requiresViewDirTangentSpace)
{
// shaderInputVisitor.AddShaderChunk("float3 tangentViewDir;", true);
// shaderBody.AddShaderChunk("float3 " + ShaderGeneratorNames.TangentSpaceViewDirection + " = IN.tangentViewDir;", true);
shaderBody.AddShaderChunk(
"float3 " + ShaderGeneratorNames.TangentSpaceViewDirection + ";", true);
shaderBody.AddShaderChunk(
ShaderGeneratorNames.TangentSpaceViewDirection + ".x = dot(" +
ShaderGeneratorNames.WorldSpaceViewDirection + "," +
ShaderGeneratorNames.WorldSpaceTangent + ");", true);
shaderBody.AddShaderChunk(
ShaderGeneratorNames.TangentSpaceViewDirection + ".y = dot(" +
ShaderGeneratorNames.WorldSpaceViewDirection + "," +
ShaderGeneratorNames.WorldSpaceBitangent + ");", true);
shaderBody.AddShaderChunk(
ShaderGeneratorNames.TangentSpaceViewDirection + ".z = dot(" +
ShaderGeneratorNames.WorldSpaceViewDirection + "," +
ShaderGeneratorNames.WorldSpaceNormal + ");", true);
}
if (requiresVertexColor)
{
shaderBody.AddShaderChunk("float4 " + ShaderGeneratorNames.VertexColor + " = IN.color;", true);
}

48
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs


public const string WorldSpaceTangent = "worldSpaceTangent";
public const string WorldSpacePosition = "worldPosition";
public const string WorldSpaceViewDirection = "worldSpaceViewDirection";
public const string TangentSpaceViewDirection = "tangentSpaceViewDirection";
public const string ScreenPosition = "screenPosition";
public const string VertexColor = "vertexColor";

vertexShaderBlock.AddShaderChunk("float4 screenPos = ComputeScreenPos(UnityObjectToClipPos(v.vertex));", true);
vertexShaderBlock.AddShaderChunk("float3 worldNormal = UnityObjectToWorldNormal(v.normal);", true);
bool needBitangent = activeNodeList.OfType<IMayRequireBitangent>().Any(x => x.RequiresBitangent());
bool needsWorldPos = activeNodeList.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection());
if (needsWorldPos || activeNodeList.OfType<IMayRequireWorldPosition>().Any(x => x.RequiresWorldPosition()))
bool requiresBitangent = activeNodeList.OfType<IMayRequireBitangent>().Any(x => x.RequiresBitangent());
bool requiresTangent = activeNodeList.OfType<IMayRequireTangent>().Any(x => x.RequiresTangent());
bool requiresViewDirTangentSpace = activeNodeList.OfType<IMayRequireViewDirectionTangentSpace>().Any(x => x.RequiresViewDirectionTangentSpace());
bool requiresViewDir = activeNodeList.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection());
bool requiresWorldPos = activeNodeList.OfType<IMayRequireWorldPosition>().Any(x => x.RequiresWorldPosition());
bool requiresNormal = activeNodeList.OfType<IMayRequireNormal>().Any(x => x.RequiresNormal());
bool requiresScreenPosition = activeNodeList.OfType<IMayRequireScreenPosition>().Any(x => x.RequiresScreenPosition());
bool requiresVertexColor = activeNodeList.OfType<IMayRequireVertexColor>().Any(x => x.RequiresVertexColor());
// view directions calculated from world position
if (requiresWorldPos || requiresViewDir || requiresViewDirTangentSpace)
{
shaderInputVisitor.AddShaderChunk("float3 worldPos : TEXCOORD0;", true);
vertexShaderBlock.AddShaderChunk("o.worldPos = worldPos;", true);

if (needBitangent || activeNodeList.OfType<IMayRequireNormal>().Any(x => x.RequiresNormal()))
if (requiresBitangent || requiresNormal || requiresViewDirTangentSpace)
{
shaderInputVisitor.AddShaderChunk("float3 worldNormal : TEXCOORD1;", true);
vertexShaderBlock.AddShaderChunk("o.worldNormal = worldNormal;", true);

}
}
if (activeNodeList.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection()))
if (requiresViewDir || requiresViewDirTangentSpace)
{
shaderBodyVisitor.AddShaderChunk(
"float3 "

+ "));", true);
}
if (activeNodeList.OfType<IMayRequireScreenPosition>().Any(x => x.RequiresScreenPosition()))
if (requiresScreenPosition)
{
shaderInputVisitor.AddShaderChunk("float4 screenPos : TEXCOORD3;", true);
vertexShaderBlock.AddShaderChunk("o.screenPos = screenPos;", true);

if (needBitangent || activeNodeList.OfType<IMayRequireTangent>().Any(x => x.RequiresTangent()))
if (requiresBitangent || requiresViewDirTangentSpace || requiresTangent)
{
shaderInputVisitor.AddShaderChunk("float4 worldTangent : TEXCOORD4;", true);
vertexShaderBlock.AddShaderChunk("o.worldTangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w);", true);

if (needBitangent)
if (requiresBitangent || requiresViewDirTangentSpace)
if (activeNodeList.OfType<IMayRequireVertexColor>().Any(x => x.RequiresVertexColor()))
if (requiresViewDirTangentSpace)
{
shaderBodyVisitor.AddShaderChunk(
"float3 " + ShaderGeneratorNames.TangentSpaceViewDirection + ";", true);
shaderBodyVisitor.AddShaderChunk(
ShaderGeneratorNames.TangentSpaceViewDirection + ".x = dot(" +
ShaderGeneratorNames.WorldSpaceViewDirection + "," +
ShaderGeneratorNames.WorldSpaceTangent + ");", true);
shaderBodyVisitor.AddShaderChunk(
ShaderGeneratorNames.TangentSpaceViewDirection + ".y = dot(" +
ShaderGeneratorNames.WorldSpaceViewDirection + "," +
ShaderGeneratorNames.WorldSpaceBitangent + ");", true);
shaderBodyVisitor.AddShaderChunk(
ShaderGeneratorNames.TangentSpaceViewDirection + ".z = dot(" +
ShaderGeneratorNames.WorldSpaceViewDirection + "," +
ShaderGeneratorNames.WorldSpaceNormal + ");", true);
}
if (requiresVertexColor)
{
vertexShaderBlock.AddShaderChunk("o.color = v.color;", true);
shaderBodyVisitor.AddShaderChunk("float4 " + ShaderGeneratorNames.VertexColor + " = IN.color;", true);

1
MaterialGraphProject/Assets/Andre/FlowMap.ShaderGraph
文件差异内容过多而无法显示
查看文件

9
MaterialGraphProject/Assets/Andre/FlowMap.ShaderGraph.meta


fileFormatVersion: 2
guid: 78cd4aa6317ee45c1a7e853fbab1e808
timeCreated: 1495548280
licenseType: Pro
ScriptedImporter:
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

643
MaterialGraphProject/Assets/TestAssets/flowmap.png

之前 之后
宽度: 1024  |  高度: 1024  |  大小: 169 KiB

84
MaterialGraphProject/Assets/TestAssets/flowmap.png.meta


fileFormatVersion: 2
guid: 8a17a00c2a071472cb92f6911bb7be11
timeCreated: 1495551094
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 0
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -1
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

122
MaterialGraphProject/Assets/NewNodes/WIP/ParallaxNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
interface IMayRequireViewDirectionTangentSpace
{
bool RequiresViewDirectionTangentSpace();
}
[Title("UV/Parallax")]
public class ParallaxNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction, IMayRequireMeshUV, IMayRequireViewDirectionTangentSpace
{
protected const string kInputSlot1ShaderName = "Depth";
protected const string kOutputSlotShaderName = "UV";
public const int InputSlot1Id = 0;
public const int OutputSlotId = 1;
public override bool hasPreview
{
get { return true; }
}
public override PreviewMode previewMode
{
get
{
return PreviewMode.Preview3D;
}
}
public ParallaxNode()
{
name = "Parallax";
UpdateNodeAfterDeserialization();
}
public string GetFunctionName()
{
return "unity_parallax_" + precision;
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(GetInputSlot1());
AddSlot(GetOutputSlot());
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { InputSlot1Id, OutputSlotId }; }
}
protected virtual MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Vector1, Vector4.zero);
}
protected virtual MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector2, Vector4.zero);
}
protected virtual string GetInputSlot1Name()
{
return kInputSlot1ShaderName;
}
protected virtual string GetOutputSlotName()
{
return kOutputSlotShaderName;
}
protected virtual string GetFunctionPrototype(string arg1Name, string arg2Name, string arg3Name)
{
return "inline " + precision + "2 " + GetFunctionName() + " (" +
precision + " " + arg1Name + ", " +
precision + "2 " + arg2Name + ", " +
precision + "3 " + arg3Name + ")";
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlot1Id }, new[] { OutputSlotId });
string input1Value = GetSlotValue(InputSlot1Id, generationMode);
visitor.AddShaderChunk(precision + "2 " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(input1Value) + ";", true);
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("depth", "UVs", "viewTangentSpace"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return UVs + depth * viewTangentSpace.xy / viewTangentSpace.z;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
protected virtual string GetFunctionCallBody(string inputValue1)
{
var channel = UVChannel.uv0;
return GetFunctionName() + " (" +
inputValue1 + ", " +
channel.GetUVName() + ", " +
ShaderGeneratorNames.TangentSpaceViewDirection + ")";
}
public bool RequiresMeshUV(UVChannel channel)
{
return channel == UVChannel.uv0;
}
public bool RequiresViewDirectionTangentSpace()
{
return true;
}
}
}

12
MaterialGraphProject/Assets/NewNodes/WIP/ParallaxNode.cs.meta


fileFormatVersion: 2
guid: 5f290ce984a59bb46a1c34491b3b8b98
timeCreated: 1495488490
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存