浏览代码
Merge pull request #1481 from Unity-Technologies/refactor-shader-variant-per-material
Merge pull request #1481 from Unity-Technologies/refactor-shader-variant-per-material
Refactor shader variant to allow stripping per material/main
GitHub
7 年前
当前提交
1ea2f496
共有 21 个文件被更改,包括 309 次插入 和 108 次删除
-
1com.unity.render-pipelines.high-definition/CHANGELOG.md
-
103com.unity.render-pipelines.high-definition/HDRP/Editor/BuildProcessors/HDRPreprocessShaders.cs
-
14com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/HDEditorUtils.cs
-
22com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/RenderPipelineSettingsUI.cs
-
3com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedRenderPipelineSettings.cs
-
2com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLit.shader
-
2com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLitTessellation.shader
-
2com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.shader
-
2com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitTessellation.shader
-
23com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.shader
-
4com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLitProperties.hlsl
-
2com.unity.render-pipelines.high-definition/HDRP/Material/Unlit/Unlit.shader
-
1com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/Settings/RenderPipelineSettings.cs
-
77com.unity.render-pipelines.high-definition/HDRP/Editor/Material/BaseShaderPreprocessor.cs
-
11com.unity.render-pipelines.high-definition/HDRP/Editor/Material/BaseShaderPreprocessor.cs.meta
-
69com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/LitShaderPreprocessor.cs
-
11com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/LitShaderPreprocessor.cs.meta
-
23com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/StackLitShaderPreprocessor.cs
-
11com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/StackLitShaderPreprocessor.cs.meta
-
23com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Unlit/UnlitShaderPreprocessor.cs
-
11com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Unlit/UnlitShaderPreprocessor.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEditor.Build; |
|||
using UnityEditor.Rendering; |
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
// returns true if the variant should be stripped.
|
|||
public delegate bool VariantStrippingFunc(HDRenderPipelineAsset hdrpAsset, Shader shader, ShaderSnippetData snippet, ShaderCompilerData inputData); |
|||
|
|||
public class BaseShaderPreprocessor |
|||
{ |
|||
protected ShaderKeyword m_ShadowMask; |
|||
protected ShaderKeyword m_Transparent; |
|||
protected ShaderKeyword m_DebugDisplay; |
|||
protected ShaderKeyword m_TileLighting; |
|||
protected ShaderKeyword m_ClusterLighting; |
|||
|
|||
public BaseShaderPreprocessor() |
|||
{ |
|||
m_Transparent = new ShaderKeyword("_SURFACE_TYPE_TRANSPARENT"); |
|||
m_DebugDisplay = new ShaderKeyword("DEBUG_DISPLAY"); |
|||
m_TileLighting = new ShaderKeyword("USE_FPTL_LIGHTLIST"); |
|||
m_ClusterLighting = new ShaderKeyword("USE_CLUSTERED_LIGHTLIST"); |
|||
} |
|||
|
|||
public virtual void AddStripperFuncs(Dictionary<string, VariantStrippingFunc> stripperFuncs) {} |
|||
|
|||
// NOTE: All these keyword should be automatically stripped so there's no need to handle them ourselves.
|
|||
// LIGHTMAP_ON, DIRLIGHTMAP_COMBINED, DYNAMICLIGHTMAP_ON, LIGHTMAP_SHADOW_MIXING, SHADOWS_SHADOWMASK
|
|||
// FOG_LINEAR, FOG_EXP, FOG_EXP2
|
|||
// STEREO_INSTANCING_ON, STEREO_MULTIVIEW_ON, STEREO_CUBEMAP_RENDER_ON, UNITY_SINGLE_PASS_STEREO
|
|||
// INSTANCING_ON
|
|||
|
|||
// Several pass are common to all shader, let's share code here
|
|||
// This remove variant (return true) for:
|
|||
// - Scene Selection
|
|||
// - Motion vectors
|
|||
// - Tile pass for Transparent (not compatible)
|
|||
// -
|
|||
protected bool CommonShaderStripper(HDRenderPipelineAsset hdrpAsset, Shader shader, ShaderSnippetData snippet, ShaderCompilerData inputData) |
|||
{ |
|||
bool isSceneSelectionPass = snippet.passName == "SceneSelectionPass"; |
|||
if (isSceneSelectionPass) |
|||
return true; |
|||
|
|||
bool isMotionPass = snippet.passName == "Motion Vectors"; |
|||
if (!hdrpAsset.renderPipelineSettings.supportMotionVectors && isMotionPass) |
|||
return true; |
|||
|
|||
//bool isForwardPass = (snippet.passName == "Forward") || (snippet.passName == "ForwardOnly");
|
|||
|
|||
if (inputData.shaderKeywordSet.IsEnabled(m_Transparent)) |
|||
{ |
|||
// If we are transparent we use cluster lighting and not tile lighting
|
|||
if (inputData.shaderKeywordSet.IsEnabled(m_TileLighting)) |
|||
return true; |
|||
} |
|||
else // Opaque
|
|||
{ |
|||
// Note: we can't assume anything regarding tile/cluster for opaque as multiple view could used different settings and it depends on MSAA
|
|||
} |
|||
|
|||
// TODO: If static lighting we can remove meta pass, but how to know that?
|
|||
|
|||
// If we are in a release build, don't compile debug display variant
|
|||
// Also don't compile it if not requested by the render pipeline settings
|
|||
if ((/*!Debug.isDebugBuild || */ !hdrpAsset.renderPipelineSettings.supportRuntimeDebugDisplay) && inputData.shaderKeywordSet.IsEnabled(m_DebugDisplay)) |
|||
return true; |
|||
|
|||
return false; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c23f3fe1f63fff240a5cf70cf0a62c93 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEditor.Build; |
|||
using UnityEditor.Rendering; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class LitShaderPreprocessor : BaseShaderPreprocessor |
|||
{ |
|||
bool LitShaderStripper(HDRenderPipelineAsset hdrpAsset, Shader shader, ShaderSnippetData snippet, ShaderCompilerData inputData) |
|||
{ |
|||
if (CommonShaderStripper(hdrpAsset, shader, snippet, inputData)) |
|||
return true; |
|||
|
|||
bool isGBufferPass = snippet.passName == "GBuffer"; |
|||
bool isForwardPass = snippet.passName == "Forward"; |
|||
bool isTransparentForwardPass = snippet.passName == "TransparentDepthPostpass" || snippet.passName == "TransparentBackface" || snippet.passName == "TransparentDepthPrepass"; |
|||
|
|||
// When using forward only, we never need GBuffer pass (only Forward)
|
|||
if (hdrpAsset.renderPipelineSettings.supportOnlyForward && isGBufferPass) |
|||
return true; |
|||
|
|||
if (inputData.shaderKeywordSet.IsEnabled(m_Transparent)) |
|||
{ |
|||
// If transparent, we never need GBuffer pass.
|
|||
if (isGBufferPass) |
|||
return true; |
|||
} |
|||
else // Opaque
|
|||
{ |
|||
// If opaque, we never need transparent specific passes (even in forward only mode)
|
|||
if (isTransparentForwardPass) |
|||
return true; |
|||
|
|||
// When we are in deferred (i.e !hdrpAsset.renderPipelineSettings.supportOnlyForward), we only support tile lighting
|
|||
if (!hdrpAsset.renderPipelineSettings.supportOnlyForward && inputData.shaderKeywordSet.IsEnabled(m_ClusterLighting)) |
|||
return true; |
|||
|
|||
if (!hdrpAsset.renderPipelineSettings.supportOnlyForward) |
|||
{ |
|||
// If opaque and not forward only, then we only need the forward debug pass.
|
|||
if (isForwardPass && !inputData.shaderKeywordSet.IsEnabled(m_DebugDisplay)) |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
// TODO: Tests for later
|
|||
// We need to find a way to strip useless shader features for passes/shader stages that don't need them (example, vertex shaders won't ever need SSS Feature flag)
|
|||
// This causes several problems:
|
|||
// - Runtime code that "finds" shader variants based on feature flags might not find them anymore... thus fall backing to the "let's give a score to variant" code path that may find the wrong variant.
|
|||
// - Another issue is that if a feature is declared without a "_" fall-back, if we strip the other variants, none may be left to use! This needs to be changed on our side.
|
|||
//if (snippet.shaderType == ShaderType.Vertex && inputData.shaderKeywordSet.IsEnabled(m_FeatureSSS))
|
|||
// return true;
|
|||
|
|||
return false; |
|||
} |
|||
|
|||
public override void AddStripperFuncs(Dictionary<string, VariantStrippingFunc> stripperFuncs) |
|||
{ |
|||
// Add name of the shader and corresponding delegate to call to strip variant
|
|||
stripperFuncs.Add("HDRenderPipeline/Lit", LitShaderStripper); |
|||
stripperFuncs.Add("HDRenderPipeline/LitTessellation", LitShaderStripper); |
|||
stripperFuncs.Add("HDRenderPipeline/LayeredLit", LitShaderStripper); |
|||
stripperFuncs.Add("HDRenderPipeline/LayeredLitTessellation", LitShaderStripper); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 203e4ecfbd605d54d89374ef35e914c0 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEditor.Build; |
|||
using UnityEditor.Rendering; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class StackLitShaderPreprocessor : BaseShaderPreprocessor |
|||
{ |
|||
bool StackLitShaderStripper(HDRenderPipelineAsset hdrpAsset, Shader shader, ShaderSnippetData snippet, ShaderCompilerData inputData) |
|||
{ |
|||
return CommonShaderStripper(hdrpAsset, shader, snippet, inputData); |
|||
} |
|||
|
|||
public override void AddStripperFuncs(Dictionary<string, VariantStrippingFunc> stripperFuncs) |
|||
{ |
|||
// Add name of the shader and corresponding delegate to call to strip variant
|
|||
stripperFuncs.Add("HDRenderPipeline/StackLit", StackLitShaderStripper); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 238a7258cd3744f4c9d619f4355c3019 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEditor.Build; |
|||
using UnityEditor.Rendering; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class UnlitShaderPreprocessor : BaseShaderPreprocessor |
|||
{ |
|||
bool UnlitShaderStripper(HDRenderPipelineAsset hdrpAsset, Shader shader, ShaderSnippetData snippet, ShaderCompilerData inputData) |
|||
{ |
|||
return CommonShaderStripper(hdrpAsset, shader, snippet, inputData); |
|||
} |
|||
|
|||
public override void AddStripperFuncs(Dictionary<string, VariantStrippingFunc> stripperFuncs) |
|||
{ |
|||
// Add name of the shader and corresponding delegate to call to strip variant
|
|||
stripperFuncs.Add("HDRenderPipeline/Unlit", UnlitShaderStripper); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b9d6d9aeb9ea7a5449eb51aa059a75b8 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue