浏览代码

[mat graph]Really rough, but working! remap nodes.

/main
Tim Cooper 8 年前
当前提交
112ae744
共有 12 个文件被更改,包括 223 次插入6 次删除
  1. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialGraphDataSource.cs
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/subshader.template
  3. 25
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/MasterRemapGraph.cs
  4. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/RemapMasterNode.cs
  5. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/AbstractSurfaceMasterNode.cs
  6. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/SurfaceMaterialOptions.cs
  7. 18
      MaterialGraphProject/Assets/ShaderLOD.cs
  8. 12
      MaterialGraphProject/Assets/ShaderLOD.cs.meta
  9. 39
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/SurfaceMasterDrawData.cs
  10. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/SurfaceMasterDrawData.cs.meta
  11. 97
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/ProjectSpecificMasterNode.cs
  12. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/ProjectSpecificMasterNode.cs.meta

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialGraphDataSource.cs


AddTypeMapping(typeof(SubGraphNode), typeof(SubgraphNodeDrawData));
AddTypeMapping(typeof(RemapMasterNode), typeof(RemapMasterNodeDrawData));
AddTypeMapping(typeof(MasterRemapInputNode), typeof(RemapInputNodeDrawData));
AddTypeMapping(typeof(AbstractSurfaceMasterNode), typeof(SurfaceMasterDrawData));
AddTypeMapping(typeof(EdgeDrawData), typeof(Edge));
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/subshader.template


${ZTest}
${ZWrite}
LOD 200
LOD ${LOD}
CGPROGRAM
#pragma target 3.0

25
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/MasterRemapGraph.cs


base.AddNode(node);
}
struct DisposeMeh : IDisposable
{
private readonly MasterRemapInputNode m_Graph;
public DisposeMeh(MasterRemapInputNode graph, RemapMasterNode master)
{
m_Graph = graph;
graph.m_RemapTarget = master;
}
public void Dispose()
{
m_Graph.m_RemapTarget = null;
}
}
inputNode.m_RemapTarget = rmn;
foreach (var node in GetNodes<IMasterNode>())
subShaders.Add(node.GetSubShader(mode));
using (new DisposeMeh(inputNode, rmn))
{
foreach (var node in GetNodes<IMasterNode>())
subShaders.Add(node.GetSubShader(mode));
}
inputNode.m_RemapTarget = null;
return subShaders;
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/RemapMasterNode.cs


}
else
{
shaderBody.AddShaderChunk("float4 " + inputNode.GetVariableNameForSlot(mappedSlot.id) + " = 0;", true);
shaderBody.AddShaderChunk("float4 " + inputNode.GetVariableNameForSlot(mappedSlot.id) + " = " + inputNode.FindSlot<MaterialSlot>(mappedSlot.id).GetDefaultValue(GenerationMode.ForReals) + ";", true);
}
}
}

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


resultShader = resultShader.Replace("${Culling}", cullingVisitor.GetShaderString(2));
resultShader = resultShader.Replace("${ZTest}", zTestVisitor.GetShaderString(2));
resultShader = resultShader.Replace("${ZWrite}", zWriteVisitor.GetShaderString(2));
resultShader = resultShader.Replace("${LOD}", ""+m_MaterialOptions.lod);
resultShader = resultShader.Replace("${VertexShaderDecl}", "vertex:vert");
resultShader = resultShader.Replace("${VertexShaderBody}", vertexShaderBlock.GetShaderString(3));

continue;
shaderBody.AddShaderChunk("o." + slot.shaderOutputName + " = " + fromNode.GetVariableNameForSlot(outputRef.slotId) + ";", true);
if (slot.id == NormalSlotId)
shaderBody.AddShaderChunk("o." + slot.shaderOutputName + " += 1e-6;", true);
}
}
}

5
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/SurfaceMaterialOptions.cs


private bool m_HalfAsView;
[SerializeField]
private int m_LOD = 200;
[SerializeField]
private bool m_Expanded;
public void Init()

noForwardAdd = false;
approxView = false;
halfAsView = false;
lod = 200;
}
public void GetTags(ShaderGenerator visitor)

public bool noForwardAdd { get { return m_NoForwardAdd; } set { m_NoForwardAdd = value; } }
public bool approxView { get { return m_ApproxView; } set { m_ApproxView = value; } }
public bool halfAsView { get { return m_HalfAsView; } set { m_HalfAsView = value; } }
public int lod { get { return m_LOD; } set { m_LOD = value; } }
}
}

18
MaterialGraphProject/Assets/ShaderLOD.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShaderLOD : MonoBehaviour {
void OnGUI()
{
if (GUILayout.Button("200"))
{
Shader.globalMaximumLOD = 200;
}
if (GUILayout.Button("400"))
{
Shader.globalMaximumLOD = 400;
}
}
}

12
MaterialGraphProject/Assets/ShaderLOD.cs.meta


fileFormatVersion: 2
guid: 4dae8f09bae183044ade8415d66232d2
timeCreated: 1481294521
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

39
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/SurfaceMasterDrawData.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class SurfaceMasterContolDrawData : ControlDrawData
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as AbstractSurfaceMasterNode;
if (cNode == null)
return;
cNode.options.lod = EditorGUILayout.IntField("LOD", cNode.options.lod);
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class SurfaceMasterDrawData : MaterialNodeDrawData
{
protected override IEnumerable<GraphElementData> GetControlData()
{
var instance = CreateInstance<SurfaceMasterContolDrawData>();
instance.Initialize(node);
return new List<GraphElementData> { instance };
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/SurfaceMasterDrawData.cs.meta


fileFormatVersion: 2
guid: 8a96d6b5dce22a748b50fa5a7629231e
timeCreated: 1481294173
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

97
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/ProjectSpecificMasterNode.cs


/*using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Serializable]
public abstract class ProjectSpecificMasterNode : AbstractMasterNode
{
public override string GetSubShader(GenerationMode mode)
{
}
public override string GetFullShader(
GenerationMode mode,
out List<PropertyGenerator.TextureInfo> configuredTextures)
{
var shaderTemplateLocation = ShaderGenerator.GetTemplatePath("shader.template");
if (!File.Exists(shaderTemplateLocation))
{
configuredTextures = new List<PropertyGenerator.TextureInfo>();
return string.Empty;
}
var templateText = File.ReadAllText(shaderTemplateLocation);
var shaderBodyVisitor = new ShaderGenerator();
var shaderFunctionVisitor = new ShaderGenerator();
var shaderPropertiesVisitor = new PropertyGenerator();
var shaderPropertyUsagesVisitor = new ShaderGenerator();
var shaderInputVisitor = new ShaderGenerator();
var vertexShaderBlock = new ShaderGenerator();
GenerateSurfaceShaderInternal(
shaderBodyVisitor,
shaderFunctionVisitor,
shaderInputVisitor,
vertexShaderBlock,
shaderPropertiesVisitor,
shaderPropertyUsagesVisitor,
mode);
var tagsVisitor = new ShaderGenerator();
var blendingVisitor = new ShaderGenerator();
var cullingVisitor = new ShaderGenerator();
var zTestVisitor = new ShaderGenerator();
var zWriteVisitor = new ShaderGenerator();
m_MaterialOptions.GetTags(tagsVisitor);
m_MaterialOptions.GetBlend(blendingVisitor);
m_MaterialOptions.GetCull(cullingVisitor);
m_MaterialOptions.GetDepthTest(zTestVisitor);
m_MaterialOptions.GetDepthWrite(zWriteVisitor);
var resultShader = templateText.Replace("${ShaderName}", GetType() + guid.ToString());
resultShader = resultShader.Replace("${ShaderPropertiesHeader}", shaderPropertiesVisitor.GetShaderString(2));
resultShader = resultShader.Replace("${ShaderPropertyUsages}", shaderPropertyUsagesVisitor.GetShaderString(2));
resultShader = resultShader.Replace("${LightingFunctionName}", GetLightFunction());
resultShader = resultShader.Replace("${SurfaceOutputStructureName}", GetSurfaceOutputName());
resultShader = resultShader.Replace("${ShaderFunctions}", shaderFunctionVisitor.GetShaderString(2));
resultShader = resultShader.Replace("${ShaderInputs}", shaderInputVisitor.GetShaderString(3));
resultShader = resultShader.Replace("${PixelShaderBody}", shaderBodyVisitor.GetShaderString(3));
resultShader = resultShader.Replace("${Tags}", tagsVisitor.GetShaderString(2));
resultShader = resultShader.Replace("${Blending}", blendingVisitor.GetShaderString(2));
resultShader = resultShader.Replace("${Culling}", cullingVisitor.GetShaderString(2));
resultShader = resultShader.Replace("${ZTest}", zTestVisitor.GetShaderString(2));
resultShader = resultShader.Replace("${ZWrite}", zWriteVisitor.GetShaderString(2));
resultShader = resultShader.Replace("${VertexShaderDecl}", "vertex:vert");
resultShader = resultShader.Replace("${VertexShaderBody}", vertexShaderBlock.GetShaderString(3));
configuredTextures = shaderPropertiesVisitor.GetConfiguredTexutres();
return Regex.Replace(resultShader, @"\r\n|\n\r|\n|\r", Environment.NewLine);
}
private void GenerateSurfaceShaderInternal(
ShaderGenerator propertyUsages,
GenerationMode mode)
{
var activeNodeList = new List<INode>();
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, this);
foreach (var node in activeNodeList.OfType<AbstractMaterialNode>())
{
node.GeneratePropertyUsages(propertyUsages, mode);
}
}
}
}*/

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/ProjectSpecificMasterNode.cs.meta


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