コード例 #1
0
        bool StripUnused(ShaderFeatures features, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData)
        {
            if (StripUnusedFeatures(features, shader, snippetData, compilerData))
            {
                return(true);
            }

            if (StripInvalidVariants(compilerData))
            {
                return(true);
            }

            if (StripUnsupportedVariants(compilerData))
            {
                return(true);
            }

            if (StripUnusedPass(features, snippetData))
            {
                return(true);
            }

            // Strip terrain holes
            // TODO: checking for the string name here is expensive
            // maybe we can rename alpha clip keyword name to be specific to terrain?
            if (compilerData.shaderKeywordSet.IsEnabled(m_AlphaTestOn) &&
                !IsFeatureEnabled(features, ShaderFeatures.TerrainHoles) &&
                shader.name.Contains(kTerrainShaderName))
            {
                return(true);
            }

            return(false);
        }
コード例 #2
0
        bool StripUnusedFeatures(ShaderFeatures features, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData)
        {
            // strip main light shadows and cascade variants
            if (!IsFeatureEnabled(features, ShaderFeatures.MainLightShadows))
            {
                if (compilerData.shaderKeywordSet.IsEnabled(m_MainLightShadows))
                {
                    return(true);
                }

                if (compilerData.shaderKeywordSet.IsEnabled(m_CascadeShadows))
                {
                    return(true);
                }
            }

            if (!IsFeatureEnabled(features, ShaderFeatures.SoftShadows) &&
                compilerData.shaderKeywordSet.IsEnabled(m_SoftShadows))
            {
                return(true);
            }

            if (compilerData.shaderKeywordSet.IsEnabled(m_MixedLightingSubtractive) &&
                !IsFeatureEnabled(features, ShaderFeatures.MixedLighting))
            {
                return(true);
            }

            // No additional light shadows
            bool isAdditionalLightShadow = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightShadows);

            if (!IsFeatureEnabled(features, ShaderFeatures.AdditionalLightShadows) && isAdditionalLightShadow)
            {
                return(true);
            }


            // Additional light are shaded per-vertex or per-pixel.
            bool isFeaturePerPixelLightingEnabled  = IsFeatureEnabled(features, ShaderFeatures.AdditionalLights);
            bool isFeaturePerVertexLightingEnabled = IsFeatureEnabled(features, ShaderFeatures.VertexLighting);
            bool isAdditionalLightPerPixel         = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightsPixel);
            bool isAdditionalLightPerVertex        = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightsVertex);

            // Strip if Per-Pixel lighting is NOT used in the project and the
            // Per-Pixel (_ADDITIONAL_LIGHTS) or additional shadows (_ADDITIONAL_LIGHT_SHADOWS)
            // variants are enabled in the shader.
            if (!isFeaturePerPixelLightingEnabled && (isAdditionalLightPerPixel || isAdditionalLightShadow))
            {
                return(true);
            }

            // Strip if Per-Vertex lighting is NOT used in the project and the
            // Per-Vertex (_ADDITIONAL_LIGHTS_VERTEX) variant is enabled in the shader.
            if (!isFeaturePerVertexLightingEnabled && isAdditionalLightPerVertex)
            {
                return(true);
            }

            return(false);
        }
コード例 #3
0
        bool StripUnusedShader(ShaderFeatures features, Shader shader, ShaderCompilerData compilerData)
        {
            if (shader.name.Contains("Debug"))
            {
                return(true);
            }

            if (shader.name.Contains("HDRenderPipeline"))
            {
                return(true);
            }

            if (!CoreUtils.HasFlag(features, ShaderFeatures.MainLightShadows) &&
                shader.name.Contains("ScreenSpaceShadows"))
            {
                return(true);
            }

            if (shader.name == "Hidden/Lightweight Render Pipeline/Blit")
            {
                bool preserveAlpha       = PlayerSettings.preserveFramebufferAlpha && compilerData.platformKeywordSet.IsEnabled(BuiltinShaderDefine.SHADER_API_MOBILE);
                bool shaderPreserveAlpha = !compilerData.shaderKeywordSet.IsEnabled(m_KillAlpha);

                if (preserveAlpha != shaderPreserveAlpha)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #4
0
        static void SetSupportedShaderFeatures(LightweightPipelineAsset pipelineAsset)
        {
            s_ShaderFeatures = 0U;

            // Strip variants based on selected pipeline features
            if (pipelineAsset.maxPixelLights > 1 || pipelineAsset.supportsVertexLight)
            {
                s_ShaderFeatures |= ShaderFeatures.AdditionalLights;
            }

            if (pipelineAsset.supportsVertexLight)
            {
                s_ShaderFeatures |= ShaderFeatures.VertexLights;
            }

            if (pipelineAsset.supportsDirectionalShadows)
            {
                s_ShaderFeatures |= ShaderFeatures.DirectionalShadows;
            }

            if (pipelineAsset.supportsLocalShadows)
            {
                s_ShaderFeatures |= ShaderFeatures.LocalShadows;
            }

            bool anyShadows = pipelineAsset.supportsDirectionalShadows || pipelineAsset.supportsLocalShadows;

            if (pipelineAsset.supportsSoftShadows && anyShadows)
            {
                s_ShaderFeatures |= ShaderFeatures.SoftShadows;
            }
        }
コード例 #5
0
        bool StripUnused(ShaderFeatures features, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData)
        {
            if (StripUnusedFeatures(features, shader, snippetData, compilerData))
                return true;

            if (StripInvalidVariants(compilerData))
                return true;

            if (StripUnsupportedVariants(compilerData))
                return true;

            if (StripUnusedPass(features, snippetData))
                return true;

            // Strip terrain holes
            // TODO: checking for the string name here is expensive
            // maybe we can rename alpha clip keyword name to be specific to terrain?
            if (compilerData.shaderKeywordSet.IsEnabled(m_AlphaTestOn) &&
                !IsFeatureEnabled(features, ShaderFeatures.TerrainHoles) &&
                shader.name.Contains(kTerrainShaderName))
                return true;

            // TODO: Test against lightMode tag instead.
            if (snippetData.passName == kPassNameGBuffer)
            {
                if (!IsFeatureEnabled(features, ShaderFeatures.DeferredShading))
                    return true;
                if (IsFeatureEnabled(features, ShaderFeatures.DeferredWithAccurateGbufferNormals) && !compilerData.shaderKeywordSet.IsEnabled(m_GbufferNormalsOct))
                    return true;
                if (IsFeatureEnabled(features, ShaderFeatures.DeferredWithoutAccurateGbufferNormals) && compilerData.shaderKeywordSet.IsEnabled(m_GbufferNormalsOct))
                    return true;
            }
            return false;
        }
コード例 #6
0
        bool StripUnusedVariant(ShaderFeatures features, ShaderCompilerData compilerData)
        {
            if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeyword.AdditionalLights) &&
                !CoreUtils.HasFlag(features, ShaderFeatures.AdditionalLights))
            {
                return(true);
            }

            if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeyword.VertexLights) &&
                !CoreUtils.HasFlag(features, ShaderFeatures.VertexLights))
            {
                return(true);
            }

            if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeyword.DirectionalShadows) &&
                !CoreUtils.HasFlag(features, ShaderFeatures.DirectionalShadows))
            {
                return(true);
            }

            if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeyword.LocalShadows) &&
                !CoreUtils.HasFlag(features, ShaderFeatures.LocalShadows))
            {
                return(true);
            }

            if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeyword.SoftShadows) &&
                !CoreUtils.HasFlag(features, ShaderFeatures.SoftShadows))
            {
                return(true);
            }

            return(false);
        }
コード例 #7
0
        public void OnProcessShader(Shader shader, ShaderSnippetData snippetData, IList <ShaderCompilerData> compilerDataList)
        {
            LightweightRP lw = RenderPipelineManager.currentPipeline as LightweightRP;

            if (lw == null)
            {
                return;
            }

            ShaderFeatures features         = LightweightRP.GetSupportedShaderFeatures();
            int            prevVariantCount = compilerDataList.Count;

            for (int i = 0; i < compilerDataList.Count; ++i)
            {
                if (StripUnused(features, shader, snippetData, compilerDataList[i]))
                {
                    compilerDataList.RemoveAt(i);
                    --i;
                }
            }

#if LOG_VARIANTS
            m_TotalVariantsInputCount  += prevVariantCount;
            m_TotalVariantsOutputCount += compilerDataList.Count;

            LogVariants(shader, snippetData, prevVariantCount, compilerDataList.Count);
#endif
        }
コード例 #8
0
 static ShaderVariables GetShader(IVertexType vertextype, ShaderFeatures caps)
 {
     if (vertextype is Utf.Dfm.DfmVertex)
     {
         return(Basic_Skinned.Get(caps));
     }
     if (vertextype is VertexPositionNormalTexture ||
         vertextype is VertexPositionNormal)
     {
         return(Basic_PositionNormalTexture.Get(caps));
     }
     if (vertextype is VertexPositionNormalTextureTwo)
     {
         return(Basic_PositionNormalTextureTwo.Get(caps));
     }
     if (vertextype is VertexPositionNormalDiffuseTexture)
     {
         return(Basic_PositionNormalColorTexture.Get(caps));
     }
     if (vertextype is VertexPositionTexture)
     {
         return(Basic_PositionTexture.Get(caps));
     }
     if (vertextype is VertexPosition)
     {
         return(Basic_PositionTexture.Get(caps));
     }
     if (vertextype is VertexPositionColor)
     {
         return(Basic_PositionColor.Get(caps));
     }
     throw new NotImplementedException(vertextype.GetType().Name);
 }
        public void OnProcessShader(Shader shader, ShaderSnippetData snippetData, IList <ShaderCompilerData> compilerDataList)
        {
            UniversalRenderPipelineAsset urpAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;

            if (urpAsset == null || compilerDataList == null || compilerDataList.Count == 0)
            {
                return;
            }

            ShaderFeatures features = GetSupportedShaderFeatures(urpAsset);

            int prevVariantCount = compilerDataList.Count;

            for (int i = 0; i < compilerDataList.Count; ++i)
            {
                if (StripUnused(features, shader, snippetData, compilerDataList[i]))
                {
                    compilerDataList.RemoveAt(i);
                    --i;
                }
            }

            if (urpAsset.shaderVariantLogLevel != ShaderVariantLogLevel.Disabled)
            {
                m_TotalVariantsInputCount  += prevVariantCount;
                m_TotalVariantsOutputCount += compilerDataList.Count;
                LogShaderVariants(shader, snippetData, urpAsset.shaderVariantLogLevel, prevVariantCount, compilerDataList.Count);
            }
        }
コード例 #10
0
        bool StripUnused(ShaderFeatures features, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData)
        {
            if (StripUnusedShader(features, shader, compilerData))
            {
                return(true);
            }

            if (StripUnusedPass(features, snippetData))
            {
                return(true);
            }

            if (StripUnusedFeatures(features, shader, compilerData))
            {
                return(true);
            }

            if (StripUnsupportedVariants(compilerData))
            {
                return(true);
            }

            if (StripInvalidVariants(compilerData))
            {
                return(true);
            }

            if (StripDeprecated(compilerData))
            {
                return(true);
            }

            return(false);
        }
コード例 #11
0
        bool StripUnusedPass(ShaderFeatures features, ShaderSnippetData snippetData)
        {
            // Strip all SRP shader variants
            if (IsSRPPass(snippetData))
            {
                return(true);
            }

            // Meta pass is needed in the player for Enlighten Precomputed Realtime GI albedo and emission.
            if (snippetData.passType == PassType.Meta)
            {
                if (SupportedRenderingFeatures.active.enlighten == false ||
                    ((int)SupportedRenderingFeatures.active.lightmapBakeTypes | (int)LightmapBakeType.Realtime) == 0)
                {
                    return(true);
                }
            }

            if (snippetData.passType == PassType.ShadowCaster)
            {
                if (!IsFeatureEnabled(features, ShaderFeatures.MainLightShadows) && !IsFeatureEnabled(features, ShaderFeatures.AdditionalLightShadows))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #12
0
        bool StripUnusedShader(ShaderFeatures features, Shader shader, ShaderCompilerData compilerData)
        {
            if (!CoreUtils.HasFlag(features, ShaderFeatures.MainLightShadows) &&
                shader.name.Contains("ScreenSpaceShadows"))
            {
                return(true);
            }

            return(false);
        }
コード例 #13
0
        private static int GetIndex(ShaderFeatures features)
        {
            ShaderFeatures masked = (features & ((ShaderFeatures)(16)));

            if ((masked == ((ShaderFeatures)(16))))
            {
                return(1);
            }
            return(0);
        }
コード例 #14
0
        bool StripUnusedFeatures(ShaderFeatures features, ShaderCompilerData compilerData)
        {
            // strip main light shadows and cascade variants
            if (!CoreUtils.HasFlag(features, ShaderFeatures.MainLightShadows))
            {
                if (compilerData.shaderKeywordSet.IsEnabled(m_MainLightShadows))
                {
                    return(true);
                }

                if (compilerData.shaderKeywordSet.IsEnabled(m_CascadeShadows))
                {
                    return(true);
                }
            }

            bool isAdditionalLightPerVertex = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightsVertex);
            bool isAdditionalLightPerPixel  = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightsPixel);
            bool isAdditionalLightShadow    = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightShadows);

            // Additional light are shaded per-vertex. Strip additional lights per-pixel and shadow variants
            if (CoreUtils.HasFlag(features, ShaderFeatures.VertexLighting) &&
                (isAdditionalLightPerPixel || isAdditionalLightShadow))
            {
                return(true);
            }

            // No additional lights
            if (!CoreUtils.HasFlag(features, ShaderFeatures.AdditionalLights) &&
                (isAdditionalLightPerPixel || isAdditionalLightPerVertex || isAdditionalLightShadow))
            {
                return(true);
            }

            // No additional light shadows
            if (!CoreUtils.HasFlag(features, ShaderFeatures.AdditionalLightShadows) && isAdditionalLightShadow)
            {
                return(true);
            }

            if (!CoreUtils.HasFlag(features, ShaderFeatures.SoftShadows) &&
                compilerData.shaderKeywordSet.IsEnabled(m_SoftShadows))
            {
                return(true);
            }

            if (compilerData.shaderKeywordSet.IsEnabled(m_MixedLightingSubtractive) &&
                !CoreUtils.HasFlag(features, ShaderFeatures.MixedLighting))
            {
                return(true);
            }

            return(false);
        }
コード例 #15
0
        bool StripUnusedPass(ShaderFeatures features, ShaderSnippetData snippetData)
        {
            if (snippetData.passType == PassType.Meta)
                return true;

            if (snippetData.passType == PassType.ShadowCaster)
                if (!IsFeatureEnabled(features, ShaderFeatures.MainLightShadows) && !IsFeatureEnabled(features, ShaderFeatures.AdditionalLightShadows))
                    return true;

            return false;
        }
コード例 #16
0
        bool StripUnused(ShaderFeatures features, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData)
        {
            if (StripUnusedFeatures(features, shader, snippetData, compilerData))
            {
                return(true);
            }

            if (StripInvalidVariants(compilerData))
            {
                return(true);
            }

            if (StripUnsupportedVariants(compilerData))
            {
                return(true);
            }

            if (StripUnusedPass(features, snippetData))
            {
                return(true);
            }

            // Strip terrain holes
            // TODO: checking for the string name here is expensive
            // maybe we can rename alpha clip keyword name to be specific to terrain?
            if (compilerData.shaderKeywordSet.IsEnabled(m_AlphaTestOn) &&
                !IsFeatureEnabled(features, ShaderFeatures.TerrainHoles) &&
                shader.name.Contains(kTerrainShaderName))
            {
                return(true);
            }

            // TODO: Test against lightMode tag instead.
            if (snippetData.passName == kPassNameGBuffer)
            {
                if (!IsFeatureEnabled(features, ShaderFeatures.DeferredShading))
                {
                    return(true);
                }

                // Do not strip accurateGbufferNormals on Mobile Vulkan as some GPUs do not support R8G8B8A8_SNorm, which then force us to use accurateGbufferNormals
                if (!IsFeatureEnabled(features, ShaderFeatures.DeferredWithAccurateGbufferNormals) && compilerData.shaderKeywordSet.IsEnabled(m_GbufferNormalsOct) && compilerData.shaderCompilerPlatform != ShaderCompilerPlatform.Vulkan)
                {
                    return(true);
                }
                if (!IsFeatureEnabled(features, ShaderFeatures.DeferredWithoutAccurateGbufferNormals) && !compilerData.shaderKeywordSet.IsEnabled(m_GbufferNormalsOct))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #17
0
        bool StripUnusedPass(ShaderFeatures features, ShaderSnippetData snippetData)
        {
            // Meta pass is needed in the player for Enlighten Precomputed Realtime GI albedo and emission.
            if (snippetData.passType == PassType.Meta)
            {
                if (SupportedRenderingFeatures.active.enlighten == false ||
                    ((int)SupportedRenderingFeatures.active.lightmapBakeTypes | (int)LightmapBakeType.Realtime) == 0)
                {
                    return(true);
                }
            }

            if (snippetData.passType == PassType.ShadowCaster)
            {
                if (!IsFeatureEnabled(features, ShaderFeatures.MainLightShadows) && !IsFeatureEnabled(features, ShaderFeatures.AdditionalLightShadows))
                {
                    return(true);
                }
            }

            // DBuffer
            if (snippetData.passName == DecalShaderPassNames.DBufferMesh || snippetData.passName == DecalShaderPassNames.DBufferProjector ||
                snippetData.passName == DecalShaderPassNames.DecalMeshForwardEmissive || snippetData.passName == DecalShaderPassNames.DecalProjectorForwardEmissive)
            {
                if (!IsFeatureEnabled(features, ShaderFeatures.DBufferMRT1) && !IsFeatureEnabled(features, ShaderFeatures.DBufferMRT2) && !IsFeatureEnabled(features, ShaderFeatures.DBufferMRT3))
                {
                    return(true);
                }
            }

            // Decal Screen Space
            if (snippetData.passName == DecalShaderPassNames.DecalScreenSpaceMesh || snippetData.passName == DecalShaderPassNames.DecalScreenSpaceProjector)
            {
                if (!IsFeatureEnabled(features, ShaderFeatures.DecalScreenSpace))
                {
                    return(true);
                }
            }

            // Decal GBuffer
            if (snippetData.passName == DecalShaderPassNames.DecalGBufferMesh || snippetData.passName == DecalShaderPassNames.DecalGBufferProjector)
            {
                if (!IsFeatureEnabled(features, ShaderFeatures.DecalGBuffer))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #18
0
        private static void FetchAllSupportedFeatures()
        {
            List <UniversalRenderPipelineAsset> urps = new List <UniversalRenderPipelineAsset>();

            urps.Add(GraphicsSettings.defaultRenderPipeline as UniversalRenderPipelineAsset);
            for (int i = 0; i < QualitySettings.names.Length; i++)
            {
                urps.Add(QualitySettings.GetRenderPipelineAssetAt(i) as UniversalRenderPipelineAsset);
            }
            foreach (UniversalRenderPipelineAsset urp in urps)
            {
                if (urp != null)
                {
                    _supportedFeatures |= GetSupportedShaderFeatures(urp);
                }
            }
        }
コード例 #19
0
        bool StripUnusedPass(ShaderFeatures features, ShaderSnippetData snippetData)
        {
            if (snippetData.passType == PassType.Meta)
            {
                return(true);
            }

            if (snippetData.passType == PassType.ShadowCaster)
            {
                if (!CoreUtils.HasFlag(features, ShaderFeatures.MainLightShadows) && !CoreUtils.HasFlag(features, ShaderFeatures.AdditionalLightShadows))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #20
0
        bool StripUnusedShader(ShaderFeatures features, Shader shader)
        {
            if (shader.name.Contains("Debug"))
            {
                return(true);
            }

            if (shader.name.Contains("HDRP"))
            {
                return(true);
            }

            if (!CoreUtils.HasFlag(features, ShaderFeatures.MainLightShadows) &&
                shader.name.Contains("ScreenSpaceShadows"))
            {
                return(true);
            }

            return(false);
        }
コード例 #21
0
        bool StripUnusedShader(ShaderFeatures features, Shader shader)
        {
            if (shader.name.Contains("Debug"))
            {
                return(true);
            }

            if (shader.name.Contains("HDRenderPipeline"))
            {
                return(true);
            }

            if (!CoreUtils.HasFlag(features, ShaderFeatures.DirectionalShadows) &&
                shader.name.Contains("ScreenSpaceShadows"))
            {
                return(true);
            }

            return(false);
        }
コード例 #22
0
        private static ShaderFeatures GetFromDecalSurfaceData(DecalSurfaceData surfaceData)
        {
            ShaderFeatures shaderFeatures = ShaderFeatures.None;

            switch (surfaceData)
            {
            case DecalSurfaceData.Albedo:
                shaderFeatures |= ShaderFeatures.DBufferMRT1;
                break;

            case DecalSurfaceData.AlbedoNormal:
                shaderFeatures |= ShaderFeatures.DBufferMRT2;
                break;

            case DecalSurfaceData.AlbedoNormalMAOS:
                shaderFeatures |= ShaderFeatures.DBufferMRT3;
                break;
            }
            return(shaderFeatures);
        }
コード例 #23
0
        private static ShaderFeatures GetFromNormalBlend(DecalNormalBlend normalBlend)
        {
            ShaderFeatures shaderFeatures = ShaderFeatures.None;

            switch (normalBlend)
            {
            case DecalNormalBlend.Low:
                shaderFeatures |= ShaderFeatures.DecalNormalBlendLow;
                break;

            case DecalNormalBlend.Medium:
                shaderFeatures |= ShaderFeatures.DecalNormalBlendMedium;
                break;

            case DecalNormalBlend.High:
                shaderFeatures |= ShaderFeatures.DecalNormalBlendHigh;
                break;
            }
            return(shaderFeatures);
        }
        bool StripUnusedPass(ShaderFeatures features, ShaderSnippetData snippetData)
        {
            if (snippetData.passType == PassType.Meta)
            {
                return(true);
            }

            if (snippetData.passType == PassType.ShadowCaster)
            {
                if (!CoreUtils.HasFlag(features, ShaderFeatures.MainLightShadows) && !CoreUtils.HasFlag(features, ShaderFeatures.AdditionalLightShadows))
                {
                    return(true);
                }
            }

            // TODO: Test against lightMode tag instead.
            if (!CoreUtils.HasFlag(features, ShaderFeatures.DeferredShading) && snippetData.passName == kPassNameGBuffer)
            {
                return(true);
            }

            return(false);
        }
コード例 #25
0
        public static void SetSupportedShaderFeatures(LightweightRenderPipelineAsset pipelineAsset)
        {
            s_ShaderFeatures = ShaderFeatures.MainLight;

            if (pipelineAsset.supportsMainLightShadows)
            {
                s_ShaderFeatures |= ShaderFeatures.MainLightShadows;
            }

            if (pipelineAsset.additionalLightsRenderingMode == LightRenderingMode.PerVertex)
            {
                s_ShaderFeatures |= ShaderFeatures.AdditionalLights;
                s_ShaderFeatures |= ShaderFeatures.VertexLighting;
            }
            else if (pipelineAsset.additionalLightsRenderingMode == LightRenderingMode.PerPixel)
            {
                s_ShaderFeatures |= ShaderFeatures.AdditionalLights;

                if (pipelineAsset.supportsAdditionalLightShadows)
                {
                    s_ShaderFeatures |= ShaderFeatures.AdditionalLightShadows;
                }
            }

            bool anyShadows = pipelineAsset.supportsMainLightShadows ||
                              CoreUtils.HasFlag(s_ShaderFeatures, ShaderFeatures.AdditionalLightShadows);

            if (pipelineAsset.supportsSoftShadows && anyShadows)
            {
                s_ShaderFeatures |= ShaderFeatures.SoftShadows;
            }

            if (pipelineAsset.supportsMixedLighting)
            {
                s_ShaderFeatures |= ShaderFeatures.MixedLighting;
            }
        }
コード例 #26
0
 public static ShaderVariables Get(ShaderFeatures features)
 {
     return(variants[GetIndex(features)]);
 }
コード例 #27
0
        private static int GetIndex(ShaderFeatures features)
        {
            ShaderFeatures masked = (features & ((ShaderFeatures)(23)));

            if ((masked == ((ShaderFeatures)(1))))
            {
                return(1);
            }
            if ((masked == ((ShaderFeatures)(16))))
            {
                return(2);
            }
            if ((masked == ((ShaderFeatures)(17))))
            {
                return(3);
            }
            if ((masked == ((ShaderFeatures)(2))))
            {
                return(4);
            }
            if ((masked == ((ShaderFeatures)(3))))
            {
                return(5);
            }
            if ((masked == ((ShaderFeatures)(18))))
            {
                return(6);
            }
            if ((masked == ((ShaderFeatures)(19))))
            {
                return(7);
            }
            if ((masked == ((ShaderFeatures)(4))))
            {
                return(8);
            }
            if ((masked == ((ShaderFeatures)(5))))
            {
                return(9);
            }
            if ((masked == ((ShaderFeatures)(20))))
            {
                return(10);
            }
            if ((masked == ((ShaderFeatures)(21))))
            {
                return(11);
            }
            if ((masked == ((ShaderFeatures)(6))))
            {
                return(12);
            }
            if ((masked == ((ShaderFeatures)(7))))
            {
                return(13);
            }
            if ((masked == ((ShaderFeatures)(22))))
            {
                return(14);
            }
            if ((masked == ((ShaderFeatures)(23))))
            {
                return(15);
            }
            return(0);
        }
コード例 #28
0
        private static int GetIndex(ShaderFeatures features)
        {
            ShaderFeatures masked = (features & ((ShaderFeatures)(0)));

            return(0);
        }
コード例 #29
0
        bool StripUnusedFeatures(ShaderFeatures features, Shader shader, ShaderCompilerData compilerData)
        {
            // strip main light shadows and cascade variants
            if (!CoreUtils.HasFlag(features, ShaderFeatures.MainLightShadows))
            {
                if (compilerData.shaderKeywordSet.IsEnabled(m_MainLightShadows))
                {
                    return(true);
                }

                if (compilerData.shaderKeywordSet.IsEnabled(m_CascadeShadows))
                {
                    return(true);
                }
            }

            bool isAdditionalLightPerVertex = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightsVertex);
            bool isAdditionalLightPerPixel  = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightsPixel);
            bool isAdditionalLightShadow    = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightShadows);

            // Additional light are shaded per-vertex. Strip additional lights per-pixel and shadow variants
            if (CoreUtils.HasFlag(features, ShaderFeatures.VertexLighting) &&
                (isAdditionalLightPerPixel || isAdditionalLightShadow))
            {
                return(true);
            }

            // No additional lights
            if (!CoreUtils.HasFlag(features, ShaderFeatures.AdditionalLights) &&
                (isAdditionalLightPerPixel || isAdditionalLightPerVertex || isAdditionalLightShadow))
            {
                return(true);
            }

            // No additional light shadows
            if (!CoreUtils.HasFlag(features, ShaderFeatures.AdditionalLightShadows) && isAdditionalLightShadow)
            {
                return(true);
            }

            if (!CoreUtils.HasFlag(features, ShaderFeatures.SoftShadows) &&
                compilerData.shaderKeywordSet.IsEnabled(m_SoftShadows))
            {
                return(true);
            }

            if (compilerData.shaderKeywordSet.IsEnabled(m_MixedLightingSubtractive) &&
                !CoreUtils.HasFlag(features, ShaderFeatures.MixedLighting))
            {
                return(true);
            }

            bool isBuiltInTerrainLit = shader.name.Contains("Universal Render Pipeline/Terrain/Lit");

            if (isBuiltInTerrainLit && compilerData.shaderKeywordSet.IsEnabled(m_AlphaTestOn) &&
                !CoreUtils.HasFlag(features, ShaderFeatures.TerrainHoles))
            {
                return(true);
            }

            return(false);
        }
コード例 #30
0
 bool IsFeatureEnabled(ShaderFeatures featureMask, ShaderFeatures feature)
 {
     return((featureMask & feature) != 0);
 }