浏览代码

Add VertexColorNode & Fix missing bitangent in AbstractSurfaceMasterNode.cs

/main
Paul Demeulenaere 8 年前
当前提交
2c0192a0
共有 5 个文件被更改,包括 94 次插入10 次删除
  1. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphNode.cs
  2. 22
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/AbstractSurfaceMasterNode.cs
  3. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs
  4. 45
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/VertexColorNode.cs
  5. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/VertexColorNode.cs.meta

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


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

return false;
return subGraph.activeNodes.OfType<IMayRequireBitangent>().Any(x => x.RequiresBitangent());
}
public bool RequiresVertexColor()
{
if (subGraph == null)
return false;
return subGraph.activeNodes.OfType<IMayRequireVertexColor>().Any(x => x.RequiresVertexColor());
}
}
}

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


shaderBody.AddShaderChunk("float4 " + ShaderGeneratorNames.ScreenPosition + " = IN.screenPos;", true);
}
if (activeNodeList.OfType<IMayRequireTangent>().Any(x => x.RequiresTangent()))
bool needBitangent = activeNodeList.OfType<IMayRequireBitangent>().Any(x => x.RequiresBitangent());
if (needBitangent || activeNodeList.OfType<IMayRequireTangent>().Any(x => x.RequiresTangent()))
shaderInputVisitor.AddShaderChunk("float3 worldTangent;", true);
vertexShaderBlock.AddShaderChunk("o.worldTangent = UnityObjectToWorldDir(v.tangent.xyz);", true);
shaderBody.AddShaderChunk("float3 " + ShaderGeneratorNames.WorldSpaceTangent + " = normalize(IN.worldTangent);", true);
shaderInputVisitor.AddShaderChunk("float4 worldTangent;", true);
vertexShaderBlock.AddShaderChunk("o.worldTangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w);", true);
shaderBody.AddShaderChunk("float3 " + ShaderGeneratorNames.WorldSpaceTangent + " = normalize(IN.worldTangent.xyz);", true);
if (activeNodeList.OfType<IMayRequireNormal>().Any(x => x.RequiresNormal()))
if (needBitangent || activeNodeList.OfType<IMayRequireNormal>().Any(x => x.RequiresNormal()))
{
// is the normal connected?
var normalSlot = FindInputSlot<MaterialSlot>(NormalSlotId);

shaderBody.AddShaderChunk("float3 " + ShaderGeneratorNames.WorldSpaceNormal + " = normalize(IN.worldNormal);", true);
}
if (needBitangent)
{
shaderBody.AddShaderChunk(string.Format("float3 {0} = cross({1}, {2}) * IN.worldTangent.w;", ShaderGeneratorNames.WorldSpaceBitangent, ShaderGeneratorNames.WorldSpaceNormal, ShaderGeneratorNames.WorldSpaceTangent), true);
}
if (activeNodeList.OfType<IMayRequireVertexColor>().Any(x => x.RequiresVertexColor()))
{
shaderBody.AddShaderChunk("float4 " + ShaderGeneratorNames.VertexColor + " = IN.color;", true);
}
GenerateNodeCode(shaderBody, mode);
}

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


public const string WorldSpacePosition = "worldPosition";
public const string WorldSpaceViewDirection = "worldSpaceViewDirection";
public const string ScreenPosition = "screenPosition";
public const string VertexColor = "vertexColor";
public const string UV0 = "uv0";
}

vertexShaderBlock.AddShaderChunk("float4 screenPos = ComputeScreenPos(UnityObjectToClipPos(v.vertex));", true);
vertexShaderBlock.AddShaderChunk("float3 worldNormal = UnityObjectToWorldNormal(v.normal);", true);
bool bRequireBitangent = activeNodeList.OfType<IMayRequireBitangent>().Any(x => x.RequiresBitangent());
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()))
{

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

shaderBodyVisitor.AddShaderChunk("half4 " + ShaderGeneratorNames.ScreenPosition + " = IN.screenPos;", true);
}
if (bRequireBitangent || activeNodeList.OfType<IMayRequireTangent>().Any(x => x.RequiresTangent()))
if (needBitangent || activeNodeList.OfType<IMayRequireTangent>().Any(x => x.RequiresTangent()))
{
shaderInputVisitor.AddShaderChunk("float4 worldTangent : TEXCOORD4;", true);
vertexShaderBlock.AddShaderChunk("o.worldTangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w);", true);

if (bRequireBitangent)
if (needBitangent)
}
if (activeNodeList.OfType<IMayRequireVertexColor>().Any(x => x.RequiresVertexColor()))
{
vertexShaderBlock.AddShaderChunk("o.color = v.color;", true);
shaderBodyVisitor.AddShaderChunk("float4 " + ShaderGeneratorNames.VertexColor + " = IN.color;", true);
}
var generationMode = GenerationMode.Preview;

45
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/VertexColorNode.cs


using System.ComponentModel;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
interface IMayRequireVertexColor
{
bool RequiresVertexColor();
}
[Title("Input/Vertex Color Node")]
public class VertexColorNode : AbstractMaterialNode, IMayRequireVertexColor
{
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "VertexColor";
public override bool hasPreview { get { return true; } }
public override PreviewMode previewMode
{
get { return PreviewMode.Preview3D; }
}
public VertexColorNode()
{
name = "Vertex Color";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.one));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override string GetVariableNameForSlot(int slotId)
{
return ShaderGeneratorNames.VertexColor;
}
public bool RequiresVertexColor()
{
return true;
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/VertexColorNode.cs.meta


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