浏览代码

Added pipeline capabilities. Stripping shader meta pass and variants based on selected capabilities.

/main
Felipe Lira 7 年前
当前提交
c30fcd10
共有 6 个文件被更改,包括 94 次插入31 次删除
  1. 4
      ScriptableRenderPipeline/Core/CoreRP/Utilities/CoreUtils.cs
  2. 25
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderPreprocessor.cs
  3. 20
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  4. 58
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs
  5. 18
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightKeywords.cs
  6. 0
      /ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs.meta

4
ScriptableRenderPipeline/Core/CoreRP/Utilities/CoreUtils.cs


};
return mat;
}
public static bool HasFlag<T>(T mask, T flag) where T : IConvertible
{
return (mask.ToUInt32(null) & flag.ToUInt32(null)) != 0;
}
public static void SetKeyword(CommandBuffer cmd, string keyword, bool state)
{

25
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderPreprocessor.cs


using UnityEditor.Build;
using UnityEditor.Rendering;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
class ShaderPreprocessor : IPreprocessShaders
public class ShaderPreprocessor : IPreprocessShaders
{
int totalVariantsInputCount = 0;
int totalVariantsOutputCount = 0;

private bool StripUnusedVariant(ShaderSnippetData snippetData, ShaderCompilerData compilerData)
{
if (snippetData.passName == "Meta")
if (snippetData.passType == PassType.Meta)
return true;
PipelineCapabilities capabilities = UnityEngine.Experimental.Rendering.LightweightPipeline.LightweightPipeline.GetPipelineCapabilities();
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.AdditionalLights) &&
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.AdditionalLights))
return true;
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.VertexLights) &&
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.VertexLights))
return true;
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.DirectionalShadows) &&
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.DirectionalShadows))
return true;
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.LocalShadows) &&
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.LocalShadows))
return true;
return false;

{
int initDataCount = data.Count;
int initDataCount = data.Count;
for (int i = 0; i < data.Count; ++i)
{

20
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


public static int opaque;
}
public class LightweightPipeline : RenderPipeline
public partial class LightweightPipeline : RenderPipeline
{
private readonly LightweightPipelineAsset m_Asset;

m_Asset = asset;
SetRenderingFeatures();
SetPipelineCapabilities(asset);
PerFrameBuffer._GlossyEnvironmentColor = Shader.PropertyToID("_GlossyEnvironmentColor");
PerFrameBuffer._SubtractiveShadowColor = Shader.PropertyToID("_SubtractiveShadowColor");

{
List<VisibleLight> visibleLights = lightData.visibleLights;
int mainLightIndex = lightData.mainLightIndex;
bool shadowsEnabled = m_ShadowPass.HasDirectionalShadowmap || m_ShadowPass.HasLocalLightsShadowmap;
CoreUtils.SetKeyword(cmd, "_SHADOWS_ENABLED", shadowsEnabled);
CoreUtils.SetKeyword(cmd, "_LOCAL_SHADOWS_ENABLED", m_ShadowPass.HasLocalLightsShadowmap);
CoreUtils.SetKeyword(cmd, LightweightKeywords.AdditionalLightsText, lightData.totalAdditionalLightsCount > 0);
CoreUtils.SetKeyword(cmd, LightweightKeywords.MixedLightingSubtractiveText, m_MixedLightingSetup == MixedLightingSetup.Subtractive);
CoreUtils.SetKeyword(cmd, LightweightKeywords.VertexLightsText, vertexLightsCount > 0);
CoreUtils.SetKeyword(cmd, "_MAIN_LIGHT_COOKIE", mainLightIndex != -1 && LightweightUtils.IsSupportedCookieType(visibleLights[mainLightIndex].lightType) && visibleLights[mainLightIndex].light.cookie != null);
CoreUtils.SetKeyword(cmd, LightweightKeywords.MainLightCookieText, mainLightIndex != -1 && LightweightUtils.IsSupportedCookieType(visibleLights[mainLightIndex].lightType) && visibleLights[mainLightIndex].light.cookie != null);
CoreUtils.SetKeyword(cmd, "_ADDITIONAL_LIGHTS", lightData.totalAdditionalLightsCount > 0);
CoreUtils.SetKeyword(cmd, "_MIXED_LIGHTING_SUBTRACTIVE", m_MixedLightingSetup == MixedLightingSetup.Subtractive);
CoreUtils.SetKeyword(cmd, "_VERTEX_LIGHTS", vertexLightsCount > 0);
CoreUtils.SetKeyword(cmd, LightweightKeywords.DirectionalShadowsText, m_ShadowPass.HasDirectionalShadowmap);
CoreUtils.SetKeyword(cmd, LightweightKeywords.LocalShadowsText, m_ShadowPass.HasLocalLightsShadowmap);
// TODO: Remove this. legacy particles support will be removed from Unity in 2018.3. This should be a shader_feature instead with prop exposed in the Standard particles shader.
CoreUtils.SetKeyword(cmd, "SOFTPARTICLES_ON", m_RequireDepthTexture && m_Asset.RequireSoftParticles);
}

58
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs


using System;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
[Flags]
public enum PipelineCapabilities
{
AdditionalLights = (1 << 0),
VertexLights = (1 << 1),
DirectionalShadows = (1 << 2),
LocalShadows = (1 << 3),
}
public class LightweightKeywords
{
public static readonly string AdditionalLightsText = "_ADDITIONAL_LIGHTS";
public static readonly string VertexLightsText = "_VERTEX_LIGHTS";
public static readonly string MixedLightingSubtractiveText = "_MIXED_LIGHTING_SUBTRACTIVE";
public static readonly string MainLightCookieText = "_MAIN_LIGHT_COOKIE";
public static readonly string DirectionalShadowsText = "_SHADOWS_ENABLED";
public static readonly string LocalShadowsText = "_LOCAL_SHADOWS_ENABLED";
public static readonly ShaderKeyword AdditionalLights = new ShaderKeyword(AdditionalLightsText);
public static readonly ShaderKeyword VertexLights = new ShaderKeyword(VertexLightsText);
public static readonly ShaderKeyword MixedLightingSubtractive = new ShaderKeyword(MixedLightingSubtractiveText);
public static readonly ShaderKeyword MainLightCookie = new ShaderKeyword(MainLightCookieText);
public static readonly ShaderKeyword DirectionalShadows = new ShaderKeyword(DirectionalShadowsText);
public static readonly ShaderKeyword LocalShadows = new ShaderKeyword(LocalShadowsText);
}
public partial class LightweightPipeline
{
static PipelineCapabilities pipelineCapabilities;
public static PipelineCapabilities GetPipelineCapabilities()
{
return pipelineCapabilities;
}
static void SetPipelineCapabilities(LightweightPipelineAsset pipelineAsset)
{
pipelineCapabilities = 0U;
if (pipelineAsset.MaxPixelLights < 1 && !pipelineAsset.SupportsVertexLight)
pipelineCapabilities |= PipelineCapabilities.AdditionalLights;
if (pipelineAsset.SupportsVertexLight)
pipelineCapabilities |= PipelineCapabilities.VertexLights;
if (pipelineAsset.ShadowSetting != ShadowType.NO_SHADOW)
pipelineCapabilities |= PipelineCapabilities.DirectionalShadows;
pipelineCapabilities |= PipelineCapabilities.LocalShadows;
}
}
}

18
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightKeywords.cs


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class LightweightKeywords : MonoBehaviour
{
// Pipeline specific keywords
public static readonly ShaderKeyword AdditionalLights = new ShaderKeyword("_ADDITIONAL_LIGHTS");
public static readonly ShaderKeyword VertexLights = new ShaderKeyword("_VERTEX_LIGHTS");
public static readonly ShaderKeyword SubtractiveLight = new ShaderKeyword("_MIXED_LIGHTING_SUBTRACTIVE");
public static readonly ShaderKeyword DirectionalShadows = new ShaderKeyword("_SHADOWS_ENABLED");
public static readonly ShaderKeyword LocalShadows = new ShaderKeyword("_LOCAL_SHADOWS_ENABLED");
public static readonly ShaderKeyword Lightmap = new ShaderKeyword("DIRLIGHTMAP_COMBINED");
public static readonly ShaderKeyword DirectionalLightmap = new ShaderKeyword("LIGHTMAP_ON");
}
}

/ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightKeywords.cs.meta → /ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs.meta

正在加载...
取消
保存