Exemple #1
0
    public override void Create()
    {
        UniversalRendererData data = null;

        if (UniversalRenderPipeline.asset.m_RendererDataList[0] != null)
        {
            data = UniversalRenderPipeline.asset.m_RendererDataList[0] as UniversalRendererData;
        }

        if (data == null)
        {
            return;
        }

        if (data.shaders == null)
        {
            return;
        }

        if (data.shaders.samplingPS == null)
        {
            return;
        }

        if (m_SamplingMaterial == null)
        {
            m_SamplingMaterial = CoreUtils.CreateEngineMaterial(data.shaders.samplingPS);
        }
    }
        public static void SwitchProjectToURP()
        {
#if URP_PACKAGE_IS_INSTALLED
            // Create default URP render pipeline asset (if it doesn't already exist).
            //
            // The #if/#else is needed here because Unity renamed `ForwardRendererData`
            // to `UniversalRendererData` in Unity 2021.2.

#if UNITY_2021_2_OR_NEWER
            UniversalRendererData rendererData = null;

            if (!AssetPathUtil.Exists(URP_RENDERER_ASSET_PATH))
            {
                rendererData = ScriptableObject.CreateInstance <UniversalRendererData>();
                AssetDatabase.CreateAsset(rendererData, URP_RENDERER_ASSET_PATH);
                // reload asset so that object reference is "backed" by asset file
                rendererData = AssetDatabase.LoadAssetAtPath <UniversalRendererData>(URP_RENDERER_ASSET_PATH);
            }
#else
            ForwardRendererData rendererData = null;

            if (!AssetPathUtil.Exists(URP_RENDERER_ASSET_PATH))
            {
                rendererData = ScriptableObject.CreateInstance <ForwardRendererData>();
                AssetDatabase.CreateAsset(rendererData, URP_RENDERER_ASSET_PATH);
                // reload asset so that object reference is "backed" by asset file
                rendererData = AssetDatabase.LoadAssetAtPath <ForwardRendererData>(URP_RENDERER_ASSET_PATH);
            }
#endif

            RenderPipelineAsset renderPipeline = null;

            if (!AssetPathUtil.Exists(URP_PIPELINE_ASSET_PATH))
            {
                renderPipeline = UniversalRenderPipelineAsset.Create(rendererData);
                AssetDatabase.CreateAsset(renderPipeline, URP_PIPELINE_ASSET_PATH);
            }

            // reload asset so that object reference is "backed" by asset file
            renderPipeline = AssetDatabase.LoadAssetAtPath <RenderPipelineAsset>(URP_PIPELINE_ASSET_PATH);
            GraphicsSettings.renderPipelineAsset = renderPipeline;

            // Set color space to linear to match Unity's
            // default setting for new URP projects.
            PlayerSettings.colorSpace = ColorSpace.Linear;
#endif
        }
    public void CreatePipelineAssetWithoutErrors()
    {
        // Test without any render pipeline assigned to GraphicsSettings.
        var renderPipelineAsset = GraphicsSettings.renderPipelineAsset;

        GraphicsSettings.renderPipelineAsset = null;

        try
        {
            UniversalRendererData        data  = ScriptableObject.CreateInstance <UniversalRendererData>();
            UniversalRenderPipelineAsset asset = UniversalRenderPipelineAsset.Create(data);
            LogAssert.NoUnexpectedReceived();
            ScriptableObject.DestroyImmediate(asset);
            ScriptableObject.DestroyImmediate(data);
        }
        // Makes sure the render pipeline is restored in case of a NullReference exception.
        finally
        {
            GraphicsSettings.renderPipelineAsset = renderPipelineAsset;
        }
    }
    public void ValidateNewAssetResources()
    {
        UniversalRendererData        data  = ScriptableObject.CreateInstance <UniversalRendererData>();
        UniversalRenderPipelineAsset asset = UniversalRenderPipelineAsset.Create(data);

        Assert.AreNotEqual(null, asset.defaultMaterial);
        Assert.AreNotEqual(null, asset.defaultParticleMaterial);
        Assert.AreNotEqual(null, asset.defaultLineMaterial);
        Assert.AreNotEqual(null, asset.defaultTerrainMaterial);
        Assert.AreNotEqual(null, asset.defaultShader);

        // URP doesn't override the following materials
        Assert.AreEqual(null, asset.defaultUIMaterial);
        Assert.AreEqual(null, asset.defaultUIOverdrawMaterial);
        Assert.AreEqual(null, asset.defaultUIETC1SupportedMaterial);
        Assert.AreEqual(null, asset.default2DMaterial);

        Assert.AreNotEqual(null, asset.m_EditorResourcesAsset, "Editor Resources should be initialized when creating a new pipeline.");
        Assert.AreNotEqual(null, asset.m_RendererDataList, "A default renderer data should be created when creating a new pipeline.");
        ScriptableObject.DestroyImmediate(asset);
        ScriptableObject.DestroyImmediate(data);
    }
    public void ValidateAssetSettings()
    {
        // Create a new asset and validate invalid settings
        UniversalRendererData        data  = ScriptableObject.CreateInstance <UniversalRendererData>();
        UniversalRenderPipelineAsset asset = UniversalRenderPipelineAsset.Create(data);

        if (asset != null)
        {
            asset.shadowDistance = -1.0f;
            Assert.GreaterOrEqual(asset.shadowDistance, 0.0f);

            asset.renderScale = -1.0f;
            Assert.GreaterOrEqual(asset.renderScale, UniversalRenderPipeline.minRenderScale);

            asset.renderScale = 32.0f;
            Assert.LessOrEqual(asset.renderScale, UniversalRenderPipeline.maxRenderScale);

            asset.shadowNormalBias = -1.0f;
            Assert.GreaterOrEqual(asset.shadowNormalBias, 0.0f);

            asset.shadowNormalBias = 32.0f;
            Assert.LessOrEqual(asset.shadowNormalBias, UniversalRenderPipeline.maxShadowBias);

            asset.shadowDepthBias = -1.0f;
            Assert.GreaterOrEqual(asset.shadowDepthBias, 0.0f);

            asset.shadowDepthBias = 32.0f;
            Assert.LessOrEqual(asset.shadowDepthBias, UniversalRenderPipeline.maxShadowBias);

            asset.maxAdditionalLightsCount = -1;
            Assert.GreaterOrEqual(asset.maxAdditionalLightsCount, 0);

            asset.maxAdditionalLightsCount = 32;
            Assert.LessOrEqual(asset.maxAdditionalLightsCount, UniversalRenderPipeline.maxPerObjectLights);
        }
        ScriptableObject.DestroyImmediate(asset);
        ScriptableObject.DestroyImmediate(data);
    }