浏览代码

Allow sub-shaders to tell whether they are compatible with a given render pipeline, and hook it up with the UI support for that such that an error is shown in the event that it's _not_ compatible.

This also adds a check in Update() such that the UI is reloaded when the render pipeline changes.
/main
Peter Bay Bastian 6 年前
当前提交
549996da
共有 9 个文件被更改,包括 55 次插入11 次删除
  1. 9
      com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDPBRSubShader.cs
  2. 9
      com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDUnlitSubShader.cs
  3. 7
      com.unity.render-pipelines.lightweight/LWRP/Editor/ShaderGraph/LightWeightPBRSubShader.cs
  4. 6
      com.unity.render-pipelines.lightweight/LWRP/Editor/ShaderGraph/LightWeightUnlitSubShader.cs
  5. 2
      com.unity.shadergraph/Editor/Data/MasterNodes/ISubShader.cs
  6. 2
      com.unity.shadergraph/Editor/Data/Nodes/IMasterNode.cs
  7. 15
      com.unity.shadergraph/Editor/Data/Nodes/MasterNode.cs
  8. 11
      com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs
  9. 5
      com.unity.shadergraph/Editor/Drawing/Views/MaterialNodeView.cs

9
com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDPBRSubShader.cs


using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{

subShader.AddShaderChunk("}", true);
return subShader.GetShaderString(0);
}
public bool IsPipelineCompatible(RenderPipelineAsset renderPipelineAsset)
{
return renderPipelineAsset is HDRenderPipelineAsset;
}
}
}

9
com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDUnlitSubShader.cs


using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{

subShader.AddShaderChunk("}", true);
return subShader.GetShaderString(0);
}
public bool IsPipelineCompatible(RenderPipelineAsset renderPipelineAsset)
{
return renderPipelineAsset is HDRenderPipelineAsset;
}
}
}

7
com.unity.render-pipelines.lightweight/LWRP/Editor/ShaderGraph/LightWeightPBRSubShader.cs


using System.Linq;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.LightweightPipeline;
namespace UnityEditor.Experimental.Rendering.LightweightPipeline
{

}
return subShader.ToString();
}
public bool IsPipelineCompatible(RenderPipelineAsset renderPipelineAsset)
{
return renderPipelineAsset is LightweightPipelineAsset;
}
static string GetTemplatePath(string templateName)

6
com.unity.render-pipelines.lightweight/LWRP/Editor/ShaderGraph/LightWeightUnlitSubShader.cs


using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.Experimental.Rendering.LightweightPipeline;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph;

}
return subShader.ToString();
}
public bool IsPipelineCompatible(RenderPipelineAsset renderPipelineAsset)
{
return renderPipelineAsset is LightweightPipelineAsset;
}
static string GetTemplatePath(string templateName)

2
com.unity.shadergraph/Editor/Data/MasterNodes/ISubShader.cs


using System;
using System.Collections.Generic;
using UnityEngine.Experimental.Rendering;
namespace UnityEditor.ShaderGraph
{

bool IsPipelineCompatible(RenderPipelineAsset renderPipelineAsset);
}
}

2
com.unity.shadergraph/Editor/Data/Nodes/IMasterNode.cs


public interface IMasterNode : INode
{
string GetShader(GenerationMode mode, string name, out List<PropertyCollector.TextureInfo> configuredTextures, List<string> sourceAssetDependencyPaths = null);
bool IsPipelineCompatible(IRenderPipeline renderPipeline);
bool IsPipelineCompatible(RenderPipelineAsset renderPipelineAsset);
}
}

15
com.unity.shadergraph/Editor/Data/Nodes/MasterNode.cs


using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Rendering;
namespace UnityEditor.ShaderGraph
{

}
foreach (var subShader in m_SubShaders)
finalShader.AppendLines(subShader.GetSubshader(this, mode, sourceAssetDependencyPaths));
{
if (mode != GenerationMode.Preview || subShader.IsPipelineCompatible(GraphicsSettings.renderPipelineAsset))
finalShader.AppendLines(subShader.GetSubshader(this, mode, sourceAssetDependencyPaths));
}
finalShader.AppendLine(@"FallBack ""Hidden/InternalErrorShader""");
}

public bool IsPipelineCompatible(IRenderPipeline renderPipeline)
public bool IsPipelineCompatible(RenderPipelineAsset renderPipelineAsset)
return true;
foreach (var subShader in m_SubShaders)
{
if (subShader.IsPipelineCompatible(GraphicsSettings.renderPipelineAsset))
return true;
}
return false;
}
public override void OnBeforeSerialize()

11
com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs


using Object = UnityEngine.Object;
using Edge = UnityEditor.Experimental.UIElements.GraphView.Edge;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
namespace UnityEditor.ShaderGraph.Drawing
{

public bool forceRedrawPreviews = false;
ColorSpace m_ColorSpace;
RenderPipelineAsset m_RenderPipelineAsset;
GraphEditorView m_GraphEditorView;

m_ColorSpace = PlayerSettings.colorSpace;
}
if (GraphicsSettings.renderPipelineAsset != m_RenderPipelineAsset)
{
graphEditorView = null;
m_RenderPipelineAsset = GraphicsSettings.renderPipelineAsset;
}
try
{
if (graphObject == null && selectedGuid != null)

var asset = AssetDatabase.LoadAssetAtPath<Object>(AssetDatabase.GUIDToAssetPath(selectedGuid));
graphEditorView = new GraphEditorView(this, materialGraph, asset.name) { persistenceKey = selectedGuid };
m_ColorSpace = PlayerSettings.colorSpace;
m_RenderPipelineAsset = GraphicsSettings.renderPipelineAsset;
}
if (forceRedrawPreviews)

try
{
m_ColorSpace = PlayerSettings.colorSpace;
m_RenderPipelineAsset = GraphicsSettings.renderPipelineAsset;
var asset = AssetDatabase.LoadAssetAtPath<Object>(AssetDatabase.GUIDToAssetPath(assetGuid));
if (asset == null)

5
com.unity.shadergraph/Editor/Drawing/Views/MaterialNodeView.cs


using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.UIElements.StyleEnums;
using UnityEngine.Experimental.UIElements.StyleSheets;
using UnityEngine.Rendering;
using Node = UnityEditor.Experimental.UIElements.GraphView.Node;
namespace UnityEditor.ShaderGraph.Drawing

var masterNode = node as IMasterNode;
if (masterNode != null)
{
if (!masterNode.IsPipelineCompatible(RenderPipelineManager.currentPipeline))
if (!masterNode.IsPipelineCompatible(GraphicsSettings.renderPipelineAsset))
IconBadge wrongPipeline = IconBadge.CreateError("The current render pipeline is not compatible with this node preview.");
IconBadge wrongPipeline = IconBadge.CreateError("The current render pipeline is not compatible with this master node.");
Add(wrongPipeline);
VisualElement title = this.Q("title");
wrongPipeline.AttachTo(title, SpriteAlignment.LeftCenter);

正在加载...
取消
保存