浏览代码

-Moved cube map node

-Tweaked colour guide texture
-Fixed time node
/main
Andre McGrail 8 年前
当前提交
c127b19f
共有 5 个文件被更改,包括 1090 次插入249 次删除
  1. 989
      MaterialGraphProject/Assets/TestAssets/ColorGuide.tif
  2. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TimeNode.cs
  3. 340
      MaterialGraphProject/Assets/Matt&Andre/CubemapNode.cs
  4. 0
      /MaterialGraphProject/Assets/Matt&Andre/CubemapNode.cs
  5. 0
      /MaterialGraphProject/Assets/Matt&Andre/CubemapNode.cs.meta

989
MaterialGraphProject/Assets/TestAssets/ColorGuide.tif
文件差异内容过多而无法显示
查看文件

10
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TimeNode.cs


public class TimeNode : AbstractMaterialNode, IRequiresTime
{
private const string kOutputSlotName = "Time";
private const string kOutputSlotNameX = "Time.x";
private const string kOutputSlotNameY = "Time.y";
private const string kOutputSlotNameZ = "Time.z";
private const string kOutputSlotNameW = "Time.w";
private const string kOutputSlotNameX = "Time/20";
private const string kOutputSlotNameY = "Time";
private const string kOutputSlotNameZ = "Time * 2";
private const string kOutputSlotNameW = "Time * 3";
public const int OutputSlotId = 0;
public const int OutputSlotIdX = 1;

protected int[] validSlots
{
get { return new[] {OutputSlotId, OutputSlotIdX, OutputSlotIdY, OutputSlotIdZ, OutputSlotId}; }
get { return new[] {OutputSlotId, OutputSlotIdX, OutputSlotIdY, OutputSlotIdZ, OutputSlotIdW}; }
}
public override string GetVariableNameForSlot(int slotId)

340
MaterialGraphProject/Assets/Matt&Andre/CubemapNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Input/Cubemap")]
public class CubemapNode : PropertyNode, IGeneratesBodyCode, IMayRequireMeshUV
{
protected const string kUVSlotName = "Refl";
protected const string kOutputSlotRGBAName = "RGBA";
protected const string kOutputSlotRName = "R";
protected const string kOutputSlotGName = "G";
protected const string kOutputSlotBName = "B";
protected const string kOutputSlotAName = "A";
[Title("Input/Cubemap")]
public class CubemapNode : PropertyNode, IGeneratesBodyCode, IMayRequireMeshUV
{
protected const string kUVSlotName = "Refl";
protected const string kOutputSlotRGBAName = "RGBA";
protected const string kOutputSlotRName = "R";
protected const string kOutputSlotGName = "G";
protected const string kOutputSlotBName = "B";
protected const string kOutputSlotAName = "A";
public const int UvSlotId = 0;
public const int OutputSlotRgbaId = 1;
public const int OutputSlotRId = 2;
public const int OutputSlotGId = 3;
public const int OutputSlotBId = 4;
public const int OutputSlotAId = 5;
public const int UvSlotId = 0;
public const int OutputSlotRgbaId = 1;
public const int OutputSlotRId = 2;
public const int OutputSlotGId = 3;
public const int OutputSlotBId = 4;
public const int OutputSlotAId = 5;
[SerializeField]
private string m_SerializedCube;
[SerializeField]
private string m_SerializedCube;
//private TextureType m_TextureType;
//private TextureType m_TextureType;
[Serializable]
private class CubemapHelper
{
[Serializable]
private class CubemapHelper
{
}
}
public override bool hasPreview { get { return true; } }
public override bool hasPreview { get { return true; } }
#if UNITY_EDITOR
#if UNITY_EDITOR
{
get
{
if (string.IsNullOrEmpty(m_SerializedCube))
return null;
{
get
{
if (string.IsNullOrEmpty(m_SerializedCube))
return null;
var tex = new CubemapHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedCube, tex);
return tex.cube;
}
set
{
if (defaultCube == value)
return;
var tex = new CubemapHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedCube, tex);
return tex.cube;
}
set
{
if (defaultCube == value)
return;
var tex = new CubemapHelper();
tex.cube = value;
m_SerializedCube = EditorJsonUtility.ToJson(tex, true);
var tex = new CubemapHelper();
tex.cube = value;
m_SerializedCube = EditorJsonUtility.ToJson(tex, true);
if (onModified != null)
{
onModified(this, ModificationScope.Node);
}
}
}
#else
if (onModified != null)
{
onModified(this, ModificationScope.Node);
}
}
}
#else
#endif
#endif
/*public TextureType textureType
{
get { return m_TextureType; }
set
{
if (m_TextureType == value)
return;
public CubemapNode()
{
name = "Cubemap";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotRgbaId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(UvSlotId, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector3, Vector3.zero, false));
RemoveSlotsNameNotMatching(validSlots);
}
m_TextureType = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}*/
public CubemapNode()
{
name = "Cubemap";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotRgbaId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(UvSlotId, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector3, Vector3.zero, false));
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] {OutputSlotRgbaId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, UvSlotId}; }
}
// Node generations
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
if (uvSlot == null)
return;
var uvName = string.Format("{0}.xyz", UVChannel.uv0.GetUVName());
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
if (edges.Count > 0)
{
var edge = edges[0];
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid);
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector3, true);
}
string body = "texCUBE (" + propertyName + ", " + uvName + ")";
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + " = " + body + ";", true);
}
public override PreviewMode previewMode {
get {
return PreviewMode.Preview3D;
}
}
public override string GetVariableNameForSlot(int slotId)
{
string slotOutput;
switch (slotId)
{
case OutputSlotRId:
slotOutput = ".r";
break;
case OutputSlotGId:
slotOutput = ".g";
break;
case OutputSlotBId:
slotOutput = ".b";
break;
case OutputSlotAId:
slotOutput = ".a";
break;
default:
slotOutput = "";
break;
}
return GetVariableNameForNode() + slotOutput;
}
protected int[] validSlots
{
get { return new[] {OutputSlotRgbaId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, UvSlotId}; }
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(GetPreviewProperty());
}
// Node generations
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
if (uvSlot == null)
return;
// Properties
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderProperty(
new CubemapPropertyChunk(
propertyName,
description,
defaultCube,
PropertyChunk.HideState.Visible,
exposedState == ExposedState.Exposed ?
CubemapPropertyChunk.ModifiableState.Modifiable
: CubemapPropertyChunk.ModifiableState.NonModifiable));
}
var uvName = string.Format("{0}.xyz", UVChannel.uv0.GetUVName());
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk("samplerCUBE " + propertyName + ";", true);
}
if (edges.Count > 0)
{
var edge = edges[0];
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid);
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector3, true);
}
/*
public override bool DrawSlotDefaultInput(Rect rect, Slot inputSlot)
{
var uvSlot = FindInputSlot(kUVSlotName);
if (uvSlot != inputSlot)
return base.DrawSlotDefaultInput(rect, inputSlot);
string body = "texCUBE (" + propertyName + ", " + uvName + ")";
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + " = " + body + ";", true);
}
public override string GetVariableNameForSlot(int slotId)
{
string slotOutput;
switch (slotId)
{
case OutputSlotRId:
slotOutput = ".r";
break;
case OutputSlotGId:
slotOutput = ".g";
break;
case OutputSlotBId:
slotOutput = ".b";
break;
case OutputSlotAId:
slotOutput = ".a";
break;
default:
slotOutput = "";
break;
}
return GetVariableNameForNode() + slotOutput;
}
var rectXmax = rect.xMax;
rect.x = rectXmax - 70;
rect.width = 70;
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(GetPreviewProperty());
}
EditorGUI.DrawRect(rect, new Color(0.0f, 0.0f, 0.0f, 0.7f));
GUI.Label(rect, "From Mesh");
// Properties
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderProperty(
new CubemapPropertyChunk(
propertyName,
description,
defaultCube,
PropertyChunk.HideState.Visible,
exposedState == ExposedState.Exposed ?
CubemapPropertyChunk.ModifiableState.Modifiable
: CubemapPropertyChunk.ModifiableState.NonModifiable));
}
return false;
}
*/
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk("samplerCUBE " + propertyName + ";", true);
}
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Cubemap,
m_Cubemap = defaultCube
};
}
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Cubemap,
m_Cubemap = defaultCube
};
}
public bool RequiresMeshUV(UVChannel channel)
{
if (channel != UVChannel.uv0)
{
return false;
}
public bool RequiresMeshUV(UVChannel channel)
{
if (channel != UVChannel.uv0)
{
return false;
}
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
if (uvSlot == null)
return true;
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
if (uvSlot == null)
return true;
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
return edges.Count == 0;
}
}
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
return edges.Count == 0;
}
}
}

/MaterialGraphProject/Assets/CubemapNode.cs → /MaterialGraphProject/Assets/Matt&Andre/CubemapNode.cs

/MaterialGraphProject/Assets/CubemapNode.cs.meta → /MaterialGraphProject/Assets/Matt&Andre/CubemapNode.cs.meta

正在加载...
取消
保存