예제 #1
0
        public static void SetupEffect<T>()
        {
#if URP
            ScriptableRendererData[] rendererDataList = (ScriptableRendererData[])typeof(UniversalRenderPipelineAsset).GetField("m_RendererDataList", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(UniversalRenderPipeline.asset);
            ScriptableRendererData forwardRenderer = rendererDataList[0];

            ScriptableRendererFeature feature = (ScriptableRendererFeature)ScriptableRendererFeature.CreateInstance(typeof(T).ToString());
            feature.name = "[SCPE] " + typeof(T).ToString().Replace("SCPE.", string.Empty);

            //Add component https://github.com/Unity-Technologies/Graphics/blob/d0473769091ff202422ad13b7b764c7b6a7ef0be/com.unity.render-pipelines.universal/Editor/ScriptableRendererDataEditor.cs#L180
            AssetDatabase.AddObjectToAsset(feature, forwardRenderer);
            AssetDatabase.TryGetGUIDAndLocalFileIdentifier(feature, out var guid, out long localId);

            //Get feature list
            FieldInfo renderFeaturesInfo = typeof(ScriptableRendererData).GetField("m_RendererFeatures", BindingFlags.Instance | BindingFlags.NonPublic);
            List<ScriptableRendererFeature> m_RendererFeatures = (List<ScriptableRendererFeature>)renderFeaturesInfo.GetValue(forwardRenderer);

            //Modify and set list
            m_RendererFeatures.Add(feature);
            renderFeaturesInfo.SetValue(forwardRenderer, m_RendererFeatures);

            //Onvalidate will call ValidateRendererFeatures and update m_RendererPassMap
            MethodInfo validateInfo = typeof(ScriptableRendererData).GetMethod("OnValidate", BindingFlags.Instance | BindingFlags.NonPublic);
            validateInfo.Invoke(forwardRenderer, null);

#if UNITY_EDITOR
            EditorUtility.SetDirty(forwardRenderer);
            AssetDatabase.SaveAssets();
#endif
            Debug.Log("<b>" + feature.name + "</b> was added to the " + forwardRenderer.name + " renderer");
#endif
        }
예제 #2
0
        private void RemoveComponent(int id)
        {
            SerializedProperty property  = m_RendererFeatures.GetArrayElementAtIndex(id);
            Object             component = property.objectReferenceValue;

            property.objectReferenceValue = null;

            Undo.SetCurrentGroupName(component == null ? "Remove Renderer Feature" : $"Remove {component.name}");

            // remove the array index itself from the list
            m_RendererFeatures.DeleteArrayElementAtIndex(id);
            m_RendererFeaturesMap.DeleteArrayElementAtIndex(id);
            UpdateEditorList();
            serializedObject.ApplyModifiedProperties();

            // Destroy the setting object after ApplyModifiedProperties(). If we do it before, redo
            // actions will be in the wrong order and the reference to the setting object in the
            // list will be lost.
            if (component != null)
            {
                Undo.DestroyObjectImmediate(component);

                ScriptableRendererFeature feature = component as ScriptableRendererFeature;
                feature?.Dispose();
            }

            // Force save / refresh
            ForceSave();
        }
예제 #3
0
        public static void SetSSAOActive(bool active)
        {
            var urpAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;

            ScriptableRenderer forwardRenderer = urpAsset.GetRenderer(0);
            FieldInfo          featuresField   = typeof(ScriptableRenderer).GetField("m_RendererFeatures", BindingFlags.NonPublic | BindingFlags.Instance);

            IList features = featuresField.GetValue(forwardRenderer) as IList;
            ScriptableRendererFeature ssaoFeature = features[0] as ScriptableRendererFeature;

            if (!active)
            {
                ssaoFeature.SetActive(false);
                return;
            }

            FieldInfo settingsField = ssaoFeature.GetType().GetField("m_Settings", BindingFlags.NonPublic | BindingFlags.Instance);
            object    settings      = settingsField.GetValue(ssaoFeature);

            FieldInfo sourceField     = settings.GetType().GetField("Source", BindingFlags.NonPublic | BindingFlags.Instance);
            FieldInfo downsampleField = settings.GetType().GetField("Downsample", BindingFlags.NonPublic | BindingFlags.Instance);

            ssaoFeature.SetActive(true);
            sourceField.SetValue(settings, 1);
            downsampleField.SetValue(settings, false);
        }
예제 #4
0
 internal TAAFeature()
 {
     // Set data
     s_Instance          = this;
     m_cameraSettingPass = new CameraSettingPass();
     m_TAAPass           = new TAAPass();
     m_TAADatas          = new Dictionary <Camera, TAAData>();
 }
예제 #5
0
 public override void Create()
 {
     s_Instance          = this;
     name                = "TAA";
     m_cameraSettingPass = new CameraSettingPass();
     m_TAAPass           = new TAAPass();
     m_TAADatas          = new Dictionary <Camera, TAAData>();
 }
예제 #6
0
        public void RemoveRendererFeatureIfPresent(ScriptableRendererFeature feature)
        {
            var rendererFeatures = GetScriptableRendererFeatures();

            if (rendererFeatures != null && rendererFeatures.Exists(element => element.Equals(feature)))
            {
                rendererFeatures.Remove(feature);
            }
        }
예제 #7
0
        public void AddRendererFeatureIfNotPresent(ScriptableRendererFeature feature)
        {
            var rendererFeatures = GetScriptableRendererFeatures();

            if (rendererFeatures != null && !rendererFeatures.Exists(element => element.GetType() == feature.GetType()))
            {
                rendererFeatures.Add(feature);
            }
        }
예제 #8
0
 public override void Create()
 {
     name = "TAA";
     // Set data
     s_Instance          = this;
     m_cameraSettingPass = new CameraSettingPass();
     m_cameraSettingPass.renderPassEvent = RenderPassEvent.BeforeRenderingOpaques;
     m_TAAPass  = new TAAPass();
     m_TAADatas = new Dictionary <Camera, TAAData>();
 }
예제 #9
0
        public override void Initialize()
        {
            base.Initialize();

            urpAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;

            ScriptableRenderer forwardRenderer = urpAsset.GetRenderer(0) as ScriptableRenderer;
            var featuresField = typeof(ScriptableRenderer).GetField("m_RendererFeatures", BindingFlags.NonPublic | BindingFlags.Instance);

            IList features = featuresField.GetValue(forwardRenderer) as IList;

            ssaoFeature = features[0] as ScriptableRendererFeature;

            FieldInfo settingsField = ssaoFeature.GetType().GetField("m_Settings", BindingFlags.NonPublic | BindingFlags.Instance);

            settings = settingsField.GetValue(ssaoFeature);

            sourceField     = settings.GetType().GetField("Source", BindingFlags.NonPublic | BindingFlags.Instance);
            downsampleField = settings.GetType().GetField("Downsample", BindingFlags.NonPublic | BindingFlags.Instance);
        }
예제 #10
0
        private static ShaderFeatures GetSupportedShaderFeatures(UniversalRenderPipelineAsset pipelineAsset)
        {
            ShaderFeatures shaderFeatures;

            shaderFeatures = ShaderFeatures.MainLight;

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

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

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

            bool anyShadows = pipelineAsset.supportsMainLightShadows ||
                              (shaderFeatures & ShaderFeatures.AdditionalLightShadows) != 0;

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

            if (pipelineAsset.supportsMixedLighting)
            {
                shaderFeatures |= ShaderFeatures.MixedLighting;
            }

            if (pipelineAsset.supportsTerrainHoles)
            {
                shaderFeatures |= ShaderFeatures.TerrainHoles;
            }

            if (pipelineAsset.useFastSRGBLinearConversion)
            {
                shaderFeatures |= ShaderFeatures.UseFastSRGBLinearConversion;
            }

            if (pipelineAsset.supportsLightLayers)
            {
                shaderFeatures |= ShaderFeatures.LightLayers;
            }

            bool hasScreenSpaceShadows         = false;
            bool hasScreenSpaceOcclusion       = false;
            bool hasDeferredRenderer           = false;
            bool withAccurateGbufferNormals    = false;
            bool withoutAccurateGbufferNormals = false;

            int rendererCount = pipelineAsset.m_RendererDataList.Length;

            for (int rendererIndex = 0; rendererIndex < rendererCount; ++rendererIndex)
            {
                ScriptableRenderer renderer = pipelineAsset.GetRenderer(rendererIndex);
                if (renderer is UniversalRenderer)
                {
                    UniversalRenderer universalRenderer = (UniversalRenderer)renderer;
                    if (universalRenderer.renderingMode == RenderingMode.Deferred)
                    {
                        hasDeferredRenderer           |= true;
                        withAccurateGbufferNormals    |= universalRenderer.accurateGbufferNormals;
                        withoutAccurateGbufferNormals |= !universalRenderer.accurateGbufferNormals;
                    }
                }

                // Check for Screen Space Ambient Occlusion Renderer Feature
                ScriptableRendererData rendererData = pipelineAsset.m_RendererDataList[rendererIndex];
                if (rendererData != null)
                {
                    for (int rendererFeatureIndex = 0; rendererFeatureIndex < rendererData.rendererFeatures.Count; rendererFeatureIndex++)
                    {
                        ScriptableRendererFeature rendererFeature = rendererData.rendererFeatures[rendererFeatureIndex];

                        ScreenSpaceShadows ssshadows = rendererFeature as ScreenSpaceShadows;
                        hasScreenSpaceShadows |= ssshadows != null;

                        ScreenSpaceAmbientOcclusion ssao = rendererFeature as ScreenSpaceAmbientOcclusion;
                        hasScreenSpaceOcclusion |= ssao != null;
                    }
                }
            }

            if (hasDeferredRenderer)
            {
                shaderFeatures |= ShaderFeatures.DeferredShading;
            }

            // We can only strip accurateGbufferNormals related variants if all DeferredRenderers use the same option.
            if (withAccurateGbufferNormals)
            {
                shaderFeatures |= ShaderFeatures.DeferredWithAccurateGbufferNormals;
            }

            if (withoutAccurateGbufferNormals)
            {
                shaderFeatures |= ShaderFeatures.DeferredWithoutAccurateGbufferNormals;
            }

            if (hasScreenSpaceShadows)
            {
                shaderFeatures |= ShaderFeatures.ScreenSpaceShadows;
            }

            if (hasScreenSpaceOcclusion)
            {
                shaderFeatures |= ShaderFeatures.ScreenSpaceOcclusion;
            }

            return(shaderFeatures);
        }
예제 #11
0
        private static ShaderFeatures GetSupportedShaderFeatures(UniversalRenderPipelineAsset pipelineAsset)
        {
            ShaderFeatures shaderFeatures;

            shaderFeatures = ShaderFeatures.MainLight;

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

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

            bool anyShadows = pipelineAsset.supportsMainLightShadows ||
                              (shaderFeatures & ShaderFeatures.AdditionalLightShadows) != 0;

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

            if (pipelineAsset.supportsMixedLighting)
            {
                shaderFeatures |= ShaderFeatures.MixedLighting;
            }

            if (pipelineAsset.supportsTerrainHoles)
            {
                shaderFeatures |= ShaderFeatures.TerrainHoles;
            }

            if (pipelineAsset.useFastSRGBLinearConversion)
            {
                shaderFeatures |= ShaderFeatures.UseFastSRGBLinearConversion;
            }

            if (pipelineAsset.supportsLightLayers)
            {
                shaderFeatures |= ShaderFeatures.LightLayers;
            }

            bool hasScreenSpaceShadows         = false;
            bool hasScreenSpaceOcclusion       = false;
            bool hasDeferredRenderer           = false;
            bool withAccurateGbufferNormals    = false;
            bool withoutAccurateGbufferNormals = false;
            bool clusteredRendering            = false;
            bool onlyClusteredRendering        = false;
            bool usesRenderPass = false;

            int rendererCount = pipelineAsset.m_RendererDataList.Length;

            for (int rendererIndex = 0; rendererIndex < rendererCount; ++rendererIndex)
            {
                ScriptableRenderer renderer = pipelineAsset.GetRenderer(rendererIndex);
                if (renderer is UniversalRenderer)
                {
                    UniversalRenderer universalRenderer = (UniversalRenderer)renderer;
                    if (universalRenderer.renderingMode == RenderingMode.Deferred)
                    {
                        hasDeferredRenderer           |= true;
                        withAccurateGbufferNormals    |= universalRenderer.accurateGbufferNormals;
                        withoutAccurateGbufferNormals |= !universalRenderer.accurateGbufferNormals;
                        usesRenderPass |= universalRenderer.useRenderPassEnabled;
                    }
                }

                var rendererClustered = false;

                ScriptableRendererData rendererData = pipelineAsset.m_RendererDataList[rendererIndex];
                if (rendererData != null)
                {
                    for (int rendererFeatureIndex = 0; rendererFeatureIndex < rendererData.rendererFeatures.Count; rendererFeatureIndex++)
                    {
                        ScriptableRendererFeature rendererFeature = rendererData.rendererFeatures[rendererFeatureIndex];

                        ScreenSpaceShadows ssshadows = rendererFeature as ScreenSpaceShadows;
                        hasScreenSpaceShadows |= ssshadows != null;

                        // Check for Screen Space Ambient Occlusion Renderer Feature
                        ScreenSpaceAmbientOcclusion ssao = rendererFeature as ScreenSpaceAmbientOcclusion;
                        hasScreenSpaceOcclusion |= ssao != null;

                        // Check for Decal Renderer Feature
                        DecalRendererFeature decal = rendererFeature as DecalRendererFeature;
                        if (decal != null)
                        {
                            var technique = decal.GetTechnique(renderer);
                            switch (technique)
                            {
                            case DecalTechnique.DBuffer:
                                shaderFeatures |= GetFromDecalSurfaceData(decal.GetDBufferSettings().surfaceData);
                                break;

                            case DecalTechnique.ScreenSpace:
                                shaderFeatures |= GetFromNormalBlend(decal.GetScreenSpaceSettings().normalBlend);
                                shaderFeatures |= ShaderFeatures.DecalScreenSpace;
                                break;

                            case DecalTechnique.GBuffer:
                                shaderFeatures |= GetFromNormalBlend(decal.GetScreenSpaceSettings().normalBlend);
                                shaderFeatures |= ShaderFeatures.DecalGBuffer;
                                break;
                            }
                        }
                    }

                    if (rendererData is UniversalRendererData universalRendererData)
                    {
                        rendererClustered = universalRendererData.renderingMode == RenderingMode.Forward &&
                                            universalRendererData.clusteredRendering;
                    }
                }

                clusteredRendering     |= rendererClustered;
                onlyClusteredRendering &= rendererClustered;
            }

            if (hasDeferredRenderer)
            {
                shaderFeatures |= ShaderFeatures.DeferredShading;
            }

            // We can only strip accurateGbufferNormals related variants if all DeferredRenderers use the same option.
            if (withAccurateGbufferNormals)
            {
                shaderFeatures |= ShaderFeatures.DeferredWithAccurateGbufferNormals;
            }

            if (withoutAccurateGbufferNormals)
            {
                shaderFeatures |= ShaderFeatures.DeferredWithoutAccurateGbufferNormals;
            }

            if (hasScreenSpaceShadows)
            {
                shaderFeatures |= ShaderFeatures.ScreenSpaceShadows;
            }

            if (hasScreenSpaceOcclusion)
            {
                shaderFeatures |= ShaderFeatures.ScreenSpaceOcclusion;
            }

            if (usesRenderPass)
            {
                shaderFeatures |= ShaderFeatures.RenderPassEnabled;
            }

            if (pipelineAsset.reflectionProbeBlending)
            {
                shaderFeatures |= ShaderFeatures.ReflectionProbeBlending;
            }

            if (pipelineAsset.reflectionProbeBoxProjection)
            {
                shaderFeatures |= ShaderFeatures.ReflectionProbeBoxProjection;
            }

            if (clusteredRendering)
            {
                shaderFeatures |= ShaderFeatures.ClusteredRendering;
            }

            if (onlyClusteredRendering)
            {
                shaderFeatures &= ~(ShaderFeatures.AdditionalLights | ShaderFeatures.VertexLighting);
            }

            if (pipelineAsset.additionalLightsRenderingMode == LightRenderingMode.PerPixel || clusteredRendering)
            {
                if (pipelineAsset.supportsAdditionalLightShadows)
                {
                    shaderFeatures |= ShaderFeatures.AdditionalLightShadows;
                }
            }

            return(shaderFeatures);
        }
 private bool TryGetFeature(out ScriptableRendererFeature feature)
 {
     feature = rendererData.rendererFeatures.Where((f) => f.name == featureName).FirstOrDefault();
     return(feature != null);
 }
 /// <summary>
 /// Removes a renderer feature from the renderer
 /// </summary>
 /// <param name="rendererFeature">The renderer feature to remove from the renderer</param>
 private void RemoveFeatureFromRenderer(ScriptableRendererFeature rendererFeature)
 {
     GetFeaturesFromRenderer();
     _activeFeaturesList.Remove(rendererFeature);
     SetFeaturesToRenderer();
 }
 /// <summary>
 /// Adds a renderer feature to the renderer
 /// </summary>
 /// <param name="rendererFeature">The renderer feature to add to the renderer</param>
 private void AddFeatureToRenderer(ScriptableRendererFeature rendererFeature)
 {
     GetFeaturesFromRenderer();
     _activeFeaturesList.Add(rendererFeature);
     SetFeaturesToRenderer();
 }