浏览代码

Add an index to RequiresMeshUV, allows require UV1 to UV3

/main
Paul Demeulenaere 8 年前
当前提交
8592d7d0
共有 5 个文件被更改,包括 28 次插入17 次删除
  1. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs
  2. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UVNode.cs
  3. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphNode.cs
  4. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/AbstractSurfaceMasterNode.cs
  5. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs

9
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs


if (uvSlot == null)
return;
var uvName = string.Format("{0}.xy", ShaderGeneratorNames.UV0);
var uvName = string.Format("{0}.xy", ShaderGeneratorNames.UV[0]);
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
if (edges.Count > 0)

public override PropertyType propertyType { get { return PropertyType.Texture2D; } }
public bool RequiresMeshUV()
public bool RequiresMeshUV(int index)
if (index != 0)
{
return false;
}
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
if (uvSlot == null)
return true;

8
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UVNode.cs


{
interface IMayRequireMeshUV
{
bool RequiresMeshUV();
bool RequiresMeshUV(int index);
}
[Title("Input/UV Node")]

public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForSlot(OutputSlotId) + " = " + ShaderGeneratorNames.UV0 + ";", true);
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForSlot(OutputSlotId) + " = " + ShaderGeneratorNames.UV[0] + ";", true);
public bool RequiresMeshUV()
public bool RequiresMeshUV(int index)
return true;
return index == 0;
}
}
}

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


return subGraph.activeNodes.OfType<IMayRequireNormal>().Any(x => x.RequiresNormal());
}
public bool RequiresMeshUV()
public bool RequiresMeshUV(int index)
return subGraph.activeNodes.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV());
return subGraph.activeNodes.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV(index));
}
public bool RequiresScreenPosition()

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


// always add color because why not.
shaderInputVisitor.AddShaderChunk("float4 color : COLOR;", true);
if (activeNodeList.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV()))
for (int uvIndex = 0; uvIndex < ShaderGeneratorNames.UV.Length; ++uvIndex)
shaderInputVisitor.AddShaderChunk("half4 meshUV0;", true);
vertexShaderBlock.AddShaderChunk("o.meshUV0 = v.texcoord;", true);
shaderBody.AddShaderChunk("half4 " + ShaderGeneratorNames.UV0 + " = IN.meshUV0;", true);
if (activeNodeList.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV(uvIndex)))
{
shaderInputVisitor.AddShaderChunk(string.Format("half4 meshUV{0};", uvIndex), true);
vertexShaderBlock.AddShaderChunk(string.Format("o.meshUV{0} = v.texcoord{1};", uvIndex, uvIndex == 0 ? "" : uvIndex.ToString()), true);
shaderBody.AddShaderChunk(string.Format("half4 {0} = IN.meshUV{1};", ShaderGeneratorNames.UV[uvIndex], uvIndex), true);
}
}
if (activeNodeList.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection()))

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


public const string WorldSpaceViewDirection = "worldSpaceViewDirection";
public const string ScreenPosition = "screenPosition";
public const string VertexColor = "vertexColor";
public const string UV0 = "uv0";
public static string[] UV = { "uv0", "uv1", "uv2", "uv3" };
}
public class ShaderGenerator

shaderBodyVisitor.AddShaderChunk("float3 " + ShaderGeneratorNames.WorldSpaceNormal + " = normalize(IN.worldNormal);", true);
}
if (activeNodeList.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV()))
for (int uvIndex = 0; uvIndex < ShaderGeneratorNames.UV.Length; ++uvIndex)
shaderInputVisitor.AddShaderChunk("half4 meshUV0 : TEXCOORD2;", true);
vertexShaderBlock.AddShaderChunk("o.meshUV0 = v.texcoord;", true);
shaderBodyVisitor.AddShaderChunk("half4 " + ShaderGeneratorNames.UV0 + " = IN.meshUV0;", true);
if (activeNodeList.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV(uvIndex)))
{
shaderInputVisitor.AddShaderChunk(string.Format("half4 meshUV{0} : TEXCOORD{1};", uvIndex, (uvIndex + 5)), true);
vertexShaderBlock.AddShaderChunk(string.Format("o.meshUV{0} = v.texcoord{1};", uvIndex, uvIndex == 0 ? "" : uvIndex.ToString()), true);
shaderBodyVisitor.AddShaderChunk(string.Format("half4 {0} = IN.meshUV{1};", ShaderGeneratorNames.UV[uvIndex], uvIndex), true);
}
}
if (activeNodeList.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection()))

正在加载...
取消
保存