浏览代码

Unlit and lit nodes now working properly in and outside a subgraph :)

/main
Tim Cooper 7 年前
当前提交
c1f2dd69
共有 8 个文件被更改,包括 29 次插入65 次删除
  1. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightSubshaderUnlit.template
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Add-Sub-Graph.ShaderSubGraph.meta
  3. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/AbstractLightweightMasterNode.cs
  4. 34
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/AbstractLightweightPBRMasterNode.cs
  5. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/LightweightUnlitMasterNode.cs
  6. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MasterNode.cs
  7. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/IMasterNode.cs
  8. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/IMasterNode.cs.meta

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightSubshaderUnlit.template


SurfaceDescription surf = PopulateSurfaceData(surfaceInput);
float3 Color = 0;
float3 Alpha = 0;
${SurfaceOutputRemap}
#ifdef _ALPHABLEND_ON

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Add-Sub-Graph.ShaderSubGraph.meta


fileFormatVersion: 2
guid: e8dfdb83d3043c7499b6cd1edd7b8f8d
timeCreated: 1503169600
licenseType: Pro
ScriptedImporter:
userData:
assetBundleName:

11
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/AbstractLightweightMasterNode.cs


{
foreach (var slot in GetInputSlots<MaterialSlot>())
{
var edge = owner.GetEdges(slot.slotReference).FirstOrDefault();
if (edge == null)
continue;
surfaceOutputRemap.AddShaderChunk(slot.shaderOutputName
+ " = surf."
+ slot.shaderOutputName + ";", true);

foreach (var activeNode in nodes.OfType<AbstractMaterialNode>())
{
if (activeNode is IGeneratesBodyCode)
(activeNode as IGeneratesBodyCode).GenerateNodeCode(surfaceOutputRemap, GenerationMode.ForReals);
(activeNode as IGeneratesBodyCode).GenerateNodeCode(surfaceOutputRemap,
GenerationMode.ForReals);
}
foreach (var input in GetInputSlots<MaterialSlot>())

if (fromNode == null)
continue;
surfaceOutputRemap.AddShaderChunk(string.Format("{0} = {1};", input.shaderOutputName, fromNode.GetVariableNameForSlot(outputRef.slotId)), true);
surfaceOutputRemap.AddShaderChunk(
string.Format("{0} = {1};", input.shaderOutputName,
fromNode.GetVariableNameForSlot(outputRef.slotId)), true);
}
}

34
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/AbstractLightweightPBRMasterNode.cs


using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{

var nm = FindSlot<MaterialSlot>(NormalSlotId);
return owner.GetEdges(nm.slotReference).Any();
}
/* public void GenerateNodeCode(ShaderGenerator shaderBody, ShaderGenerator propertyUsages, GenerationMode generationMode)
{
foreach (var slot in GetInputSlots<MaterialSlot>())
{
if (surfaceInputs.Contains(slot.id))
{
foreach (var edge in owner.GetEdges(slot.slotReference))
{
var outputRef = edge.outputSlot;
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid);
if (fromNode == null)
continue;
var remapper = fromNode as INodeGroupRemapper;
if (remapper != null && !remapper.IsValidSlotConnection(outputRef.slotId))
continue;
shaderBody.AddShaderChunk("o." + slot.shaderOutputName + " = " + fromNode.GetVariableNameForSlot(outputRef.slotId) + ";", true);
if (slot.id == NormalSlotId)
shaderBody.AddShaderChunk("o." + slot.shaderOutputName + " += 1e-6;", true);
if (slot.id == AlphaSlotId)
propertyUsages.AddShaderChunk("#define _ALPHAPREMULTIPLY_ON", true);
}
}
}
}*/
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/LightweightUnlitMasterNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text.RegularExpressions;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

{
public const string ColorSlotName = "Color";
public const string AlphaSlotName = "Alpha";
public const string VertexOffsetName = "VertexPosition";
public const int VertexOffsetId = 2;
public LightweightUnlitMasterNode()
{

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(VertexOffsetId, VertexOffsetName, VertexOffsetName, SlotType.Input, SlotValueType.Vector3, Vector4.zero, ShaderStage.Vertex));
AddSlot(new MaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero, ShaderStage.Fragment));
AddSlot(new MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero, ShaderStage.Fragment));

new[]
{
ColorSlotId,
AlphaSlotId,
VertexOffsetId
AlphaSlotId
});
}

{
get
{
return new[]
return new int[]
VertexOffsetId
};
}
}

13
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MasterNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Graphing;
public interface IMasterNode
{
SurfaceMaterialOptions options { get; }
IEnumerable<string> GetSubshader(ShaderGraphRequirements graphRequirements, MasterRemapGraph remapper);
}
[Serializable]
public abstract class MasterNode : AbstractMaterialNode, IMasterNode
{

{
name = "MasterNode";
UpdateNodeAfterDeserialization();
}
public override IEnumerable<ISlot> GetInputsWithNoConnection()
{
return new List<ISlot>();
}
public override bool hasPreview

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


using System.Collections.Generic;
namespace UnityEngine.MaterialGraph
{
public interface IMasterNode
{
SurfaceMaterialOptions options { get; }
IEnumerable<string> GetSubshader(ShaderGraphRequirements graphRequirements, MasterRemapGraph remapper);
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/IMasterNode.cs.meta


fileFormatVersion: 2
guid: 570cf3dfbfc001e46a74d5f1342a3cfc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存