void UpdateCurrentStaticLightingSky()
        {
            // First, grab the sky settings of the right type in the profile.
            CoreUtils.Destroy(m_SkySettings);
            m_SkySettings      = null;
            m_LastComputedHash = 0;
            GetSkyFromIDAndVolume(m_StaticLightingSkyUniqueID, m_Profile, out m_SkySettingsFromProfile, out var skyType);

            if (m_SkySettingsFromProfile != null)
            {
                // The static lighting sky is a Volume Component that lives outside of the volume system (we just grab a component from a profile)
                // As such, it may contain values that are not actually overridden
                // For example, user overrides a value, change it, and disable overrides. In this case the volume still contains the old overridden value
                // In this case, we want to use values only if they are still overridden, so we create a volume component with default values and then copy the overridden values from the profile.

                // Create an instance with default values
                m_SkySettings = (SkySettings)ScriptableObject.CreateInstance(skyType);
                var newSkyParameters     = m_SkySettings.parameters;
                var profileSkyParameters = m_SkySettingsFromProfile.parameters;
                int parameterCount       = m_SkySettings.parameters.Count;

                // Seems to inexplicably happen sometimes on domain reload.
                if (profileSkyParameters == null)
                {
                    return;
                }

                // Copy overridden parameters.
                for (int i = 0; i < parameterCount; ++i)
                {
                    if (profileSkyParameters[i].overrideState == true)
                    {
                        newSkyParameters[i].SetValue(profileSkyParameters[i]);
                    }
                }

                m_LastComputedHash = m_SkySettingsFromProfile.GetHashCode();
            }
        }
示例#2
0
        public void Cleanup()
        {
            CoreUtils.Destroy(m_CombineLightingPass);
            CoreUtils.Destroy(m_SssVerticalFilterPass);
            CoreUtils.Destroy(m_SssHorizontalFilterAndCombinePass);
            CoreUtils.Destroy(m_CopyStencilForSplitLighting);

            for (int i = 0; i < k_MaxSSSBuffer; ++i)
            {
                if (!m_ReuseGBufferMemory [i])
                {
                    RTHandles.Release(m_ColorMRTs[i]);
                    if (m_MSAASupport)
                    {
                        RTHandles.Release(m_ColorMSAAMRTs[i]);
                    }
                }
            }

            RTHandles.Release(m_CameraFilteringBuffer);
            RTHandles.Release(m_HTile);
        }
        internal void Toggle(DebugUI.Value widget)
        {
            int index = m_Items.FindIndex(x => x.GetWidget() == widget);

            // Remove
            if (index > -1)
            {
                var item = m_Items[index];
                CoreUtils.Destroy(item.gameObject);
                m_Items.RemoveAt(index);
                return;
            }

            // Add
            var go = Instantiate(valuePrefab, panel, false).gameObject;

            go.name = widget.displayName;
            var uiHandler = go.GetComponent <DebugUIHandlerValue>();

            uiHandler.SetWidget(widget);
            m_Items.Add(uiHandler);
        }
示例#4
0
        public void Release()
        {
            m_TextureCache.Release();
            CoreUtils.Destroy(m_TempRenderTexture);

            if (m_ConvolutionTargetTextureArray != null)
            {
                for (int bsdfIdx = 0; bsdfIdx < m_IBLFilterBSDF.Length; ++bsdfIdx)
                {
                    if (m_ConvolutionTargetTextureArray[bsdfIdx] != null)
                    {
                        CoreUtils.Destroy(m_ConvolutionTargetTextureArray[bsdfIdx]);
                        m_ConvolutionTargetTextureArray[bsdfIdx] = null;
                    }
                }
            }

            m_ProbeBakingState = null;

            CoreUtils.Destroy(m_ConvertTextureMaterial);
            CoreUtils.Destroy(m_CubeToPano);
        }
        void Update()
        {
            int state = DebugManager.instance.GetState();

            if (m_DebugTreeState != state)
            {
                foreach (Transform t in transform)
                {
                    CoreUtils.Destroy(t.gameObject);
                }

                Rebuild();
            }

            HandleInput();

            // Update scroll position in the panel
            if (m_UIPanels != null && m_SelectedPanel < m_UIPanels.Count && m_UIPanels[m_SelectedPanel] != null)
            {
                m_UIPanels[m_SelectedPanel].ScrollTo(m_SelectedWidget);
            }
        }
        public void ReleaseResources()
        {
            if (m_LightVolumeGPUArray != null)
            {
                CoreUtils.SafeRelease(m_LightVolumeGPUArray);
                m_LightVolumeGPUArray = null;
            }

            if (m_LightCluster != null)
            {
                CoreUtils.SafeRelease(m_LightCluster);
                m_LightCluster = null;
            }

            if (m_LightCullResult != null)
            {
                CoreUtils.SafeRelease(m_LightCullResult);
                m_LightCullResult = null;
            }

            if (m_LightDataGPUArray != null)
            {
                CoreUtils.SafeRelease(m_LightDataGPUArray);
                m_LightDataGPUArray = null;
            }

            if (m_EnvLightDataGPUArray != null)
            {
                CoreUtils.SafeRelease(m_EnvLightDataGPUArray);
                m_EnvLightDataGPUArray = null;
            }

            if (m_DebugMaterial != null)
            {
                CoreUtils.Destroy(m_DebugMaterial);
                m_DebugMaterial = null;
            }
        }
示例#7
0
        public void Cleanup()
        {
            if (!m_ReuseGBufferMemory)
            {
                RTHandles.Release(m_NormalRT);
            }

            if (m_MotionVectorsSupport)
            {
                RTHandles.Release(m_MotionVectorsRT);
                if (m_MSAASupported)
                {
                    RTHandles.Release(m_MotionVectorsMSAART);
                }
            }

            RTHandles.Release(m_CameraDepthStencilBuffer);
            RTHandles.Release(m_CameraDepthBufferMipChain);
            RTHandles.Release(m_CameraHalfResDepthBuffer);
            DisposeCoarseStencilBuffer();

            if (m_MSAASupported)
            {
                RTHandles.Release(m_CameraDepthStencilMSAABuffer);
                RTHandles.Release(m_CameraDepthValuesBuffer);
                RTHandles.Release(m_StencilBufferResolved);

                RTHandles.Release(m_NormalMSAART);
                RTHandles.Release(m_DepthAsColorMSAART);

                // Do not forget to release the materials
                CoreUtils.Destroy(m_DepthResolveMaterial);
                CoreUtils.Destroy(m_ColorResolveMaterial);
                CoreUtils.Destroy(m_MotionVectorResolve);
            }
        }
        internal override void SetWidget(DebugUI.Widget widget)
        {
            base.SetWidget(widget);
            m_Field        = CastWidget <DebugUI.BitField>();
            m_Container    = GetComponent <DebugUIHandlerContainer>();
            nameLabel.text = m_Field.displayName;

            int toggleIndex = 0;

            foreach (var enumName in m_Field.enumNames)
            {
                if (toggleIndex >= toggles.Count)
                {
                    continue;
                }

                var toggle = toggles[toggleIndex];
                toggle.getter            = GetValue;
                toggle.setter            = SetValue;
                toggle.nextUIHandler     = toggleIndex < (m_Field.enumNames.Length - 1) ? toggles[toggleIndex + 1] : null;
                toggle.previousUIHandler = toggleIndex > 0 ? toggles[toggleIndex - 1] : null;
                toggle.parentUIHandler   = this;
                toggle.index             = toggleIndex;
                toggle.nameLabel.text    = enumName.text;
                toggle.Init();
                toggleIndex++;
            }
            ;

            // Destroy the remaining toggles outside of the range of the displayed enum.
            for (; toggleIndex < toggles.Count; ++toggleIndex)
            {
                CoreUtils.Destroy(toggles[toggleIndex].gameObject);
                toggles[toggleIndex] = null;
            }
        }
示例#9
0
            void InitializeCustomPostProcessesLists()
            {
                var hdrpAsset = HDRenderPipeline.defaultAsset;

                if (hdrpAsset == null)
                {
                    return;
                }

                var ppVolumeTypes = TypeCache.GetTypesDerivedFrom <CustomPostProcessVolumeComponent>();
                var ppVolumeTypeInjectionPoints = new Dictionary <Type, CustomPostProcessInjectionPoint>();

                foreach (var ppVolumeType in ppVolumeTypes)
                {
                    if (ppVolumeType.IsAbstract)
                    {
                        continue;
                    }

                    var comp = ScriptableObject.CreateInstance(ppVolumeType) as CustomPostProcessVolumeComponent;
                    ppVolumeTypeInjectionPoints[ppVolumeType] = comp.injectionPoint;
                    CoreUtils.Destroy(comp);
                }

                InitList(ref m_BeforeTransparentCustomPostProcesses, hdrpAsset.beforeTransparentCustomPostProcesses, "After Opaque And Sky", CustomPostProcessInjectionPoint.AfterOpaqueAndSky);
                InitList(ref m_BeforePostProcessCustomPostProcesses, hdrpAsset.beforePostProcessCustomPostProcesses, "Before Post Process", CustomPostProcessInjectionPoint.BeforePostProcess);
                InitList(ref m_AfterPostProcessCustomPostProcesses, hdrpAsset.afterPostProcessCustomPostProcesses, "After Post Process", CustomPostProcessInjectionPoint.AfterPostProcess);

                void InitList(ref ReorderableList reorderableList, List <string> customPostProcessTypes, string headerName, CustomPostProcessInjectionPoint injectionPoint)
                {
                    // Sanitize the list:
                    customPostProcessTypes.RemoveAll(s => Type.GetType(s) == null);

                    reorderableList = new ReorderableList(customPostProcessTypes, typeof(string));
                    reorderableList.drawHeaderCallback = (rect) =>
                                                         EditorGUI.LabelField(rect, headerName, EditorStyles.boldLabel);
                    reorderableList.drawElementCallback = (rect, index, isActive, isFocused) =>
                    {
                        rect.height = EditorGUIUtility.singleLineHeight;
                        var elemType = Type.GetType(customPostProcessTypes[index]);
                        EditorGUI.LabelField(rect, elemType.ToString(), EditorStyles.boldLabel);
                    };
                    reorderableList.onAddCallback = (list) =>
                    {
                        var menu = new GenericMenu();

                        foreach (var kp in ppVolumeTypeInjectionPoints)
                        {
                            if (kp.Value == injectionPoint && !customPostProcessTypes.Contains(kp.Key.AssemblyQualifiedName))
                            {
                                menu.AddItem(new GUIContent(kp.Key.ToString()), false, () => {
                                    Undo.RegisterCompleteObjectUndo(hdrpAsset, $"Added {kp.Key.ToString()} Custom Post Process");
                                    customPostProcessTypes.Add(kp.Key.AssemblyQualifiedName);
                                });
                            }
                        }

                        if (menu.GetItemCount() == 0)
                        {
                            menu.AddDisabledItem(new GUIContent("No Custom Post Process Availble"));
                        }

                        menu.ShowAsContext();
                        EditorUtility.SetDirty(hdrpAsset);
                    };
                    reorderableList.onRemoveCallback = (list) =>
                    {
                        Undo.RegisterCompleteObjectUndo(hdrpAsset, $"Removed {list.list[list.index].ToString()} Custom Post Process");
                        customPostProcessTypes.RemoveAt(list.index);
                        EditorUtility.SetDirty(hdrpAsset);
                    };
                    reorderableList.elementHeightCallback = _ => EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                    reorderableList.onReorderCallback     = (list) => EditorUtility.SetDirty(hdrpAsset);
                }
            }
示例#10
0
 public void Cleanup()
 {
     CoreUtils.Destroy(m_GgxConvolveMaterial);
     CoreUtils.Destroy(m_GgxIblSampleData);
 }
示例#11
0
        /// <summary>
        /// The HDRP implementation for the callback that the look dev raises to process any necessary cleanup.
        /// </summary>
        /// <param name="SRI">Access element of the LookDev's scene</param>
        void IDataProvider.Cleanup(StageRuntimeInterface SRI)
        {
            LookDevDataForHDRP data = (LookDevDataForHDRP)SRI.SRPData;

            CoreUtils.Destroy(data.volume.sharedProfile);
        }
示例#12
0
 void CleanupPrepass()
 {
     CoreUtils.Destroy(m_DepthResolveMaterial);
 }
示例#13
0
        /// <summary>Perform a rendering into <paramref name="target"/>.</summary>
        /// <example>
        /// How to perform standard rendering:
        /// <code>
        /// class StandardRenderingExample
        /// {
        ///     public void Render()
        ///     {
        ///         // Copy default settings
        ///         var settings = CameraRenderSettings.Default;
        ///         // Adapt default settings to our custom usage
        ///         settings.position.position = new Vector3(0, 1, 0);
        ///         settings.camera.frustum.fieldOfView = 60.0f;
        ///         // Get our render target
        ///         var rt = new RenderTexture(128, 128, 1, GraphicsFormat.B8G8R8A8_SNorm);
        ///         HDRenderUtilities.Render(settings, rt);
        ///         // Do something with rt
        ///         rt.Release();
        ///     }
        /// }
        /// </code>
        ///
        /// How to perform a cubemap rendering:
        /// <code>
        /// class CubemapRenderExample
        /// {
        ///     public void Render()
        ///     {
        ///         // Copy default settings
        ///         var settings = CameraRenderSettings.Default;
        ///         // Adapt default settings to our custom usage
        ///         settings.position.position = new Vector3(0, 1, 0);
        ///         settings.camera.physical.iso = 800.0f;
        ///         // Frustum settings are ignored and driven by the cubemap rendering
        ///         // Get our render target
        ///         var rt = new RenderTexture(128, 128, 1, GraphicsFormat.B8G8R8A8_SNorm)
        ///         {
        ///             dimension = TextureDimension.Cube
        ///         };
        ///         // The TextureDimension is detected and the renderer will perform a cubemap rendering.
        ///         HDRenderUtilities.Render(settings, rt);
        ///         // Do something with rt
        ///         rt.Release();
        ///     }
        /// }
        /// </code>
        /// </example>
        /// <param name="settings">Settings for the camera.</param>
        /// <param name="position">Position for the camera.</param>
        /// <param name="target">Target to render to.</param>
        /// <param name="staticFlags">Only used in the Editor fo cubemaps.
        /// This is bitmask of <see cref="UnityEditor.StaticEditorFlags"/> only objects with these flags will be rendered
        /// </param>
        public static void Render(
            CameraSettings settings,
            CameraPositionSettings position,
            Texture target,
            uint staticFlags = 0
            )
        {
            // Argument checking
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            var rtTarget   = target as RenderTexture;
            var cubeTarget = target as Cubemap;

            switch (target.dimension)
            {
            case TextureDimension.Tex2D:
                if (rtTarget == null)
                {
                    throw new ArgumentException("'target' must be a RenderTexture when rendering into a 2D texture");
                }
                break;

            case TextureDimension.Cube:
                break;

            default:
                throw new ArgumentException("Rendering into a target of dimension "
                                            + $"{target.dimension} is not supported");
            }

            var camera = NewRenderingCamera();

            try
            {
                camera.ApplySettings(settings);
                camera.ApplySettings(position);

                switch (target.dimension)
                {
                case TextureDimension.Tex2D:
                {
#if DEBUG
                    Debug.LogWarning(
                        "A static flags bitmask was provided but this is ignored when rendering into a Tex2D"
                        );
#endif
                    Assert.IsNotNull(rtTarget);
                    camera.targetTexture = rtTarget;
                    camera.Render();
                    camera.targetTexture = null;
                    target.IncrementUpdateCount();
                    break;
                }

                case TextureDimension.Cube:
                {
                    Assert.IsTrue(rtTarget != null || cubeTarget != null);

                    var canHandleStaticFlags = false;
#if UNITY_EDITOR
                    canHandleStaticFlags = true;
#endif
                    // ReSharper disable ConditionIsAlwaysTrueOrFalse
                    if (canHandleStaticFlags && staticFlags != 0)
                    // ReSharper restore ConditionIsAlwaysTrueOrFalse
                    {
#if UNITY_EDITOR
                        UnityEditor.Rendering.EditorCameraUtils.RenderToCubemap(
                            camera,
                            rtTarget,
                            -1,
                            (UnityEditor.StaticEditorFlags)staticFlags
                            );
#endif
                    }
                    else
                    {
                        // ReSharper disable ConditionIsAlwaysTrueOrFalse
                        if (!canHandleStaticFlags && staticFlags != 0)
                        // ReSharper restore ConditionIsAlwaysTrueOrFalse
                        {
                            Debug.LogWarning(
                                "A static flags bitmask was provided but this is ignored in player builds"
                                );
                        }

                        if (rtTarget != null)
                        {
                            camera.RenderToCubemap(rtTarget);
                        }
                        if (cubeTarget != null)
                        {
                            camera.RenderToCubemap(cubeTarget);
                        }
                    }

                    target.IncrementUpdateCount();
                    break;
                }
                }
            }
            finally
            {
                CoreUtils.Destroy(camera.gameObject);
            }
        }
 void CleanupSubsurfaceScattering()
 {
     CoreUtils.Destroy(m_CombineLightingPass);
     CoreUtils.Destroy(m_SSSCopyStencilForSplitLighting);
     DestroySSSBuffers();
 }
示例#15
0
 protected override void Cleanup()
 {
     CoreUtils.Destroy(fullscreenMaterial);
     edgeDetectionBuffer.Release();
 }
示例#16
0
 internal void Cleanup()
 {
     CoreUtils.Destroy(occlusionMeshMaterial);
     CoreUtils.Destroy(mirrorViewMaterial);
 }
 internal void Release()
 {
     CoreUtils.Destroy(profileRT);
     CoreUtils.Destroy(transmittanceRT);
 }
示例#18
0
 protected override void Disable()
 {
     base.Disable();
     CoreUtils.Destroy(outputVolume);
     CoreUtils.Destroy(rayMapBuffer);
 }
示例#19
0
 protected override void Dispose(bool disposing)
 {
     CoreUtils.Destroy(m_ColorToMrtMaterial);
     CoreUtils.Destroy(m_CopyToViewportMaterial);
     CoreUtils.Destroy(m_BlitMaterial);
 }
示例#20
0
 protected override void Cleanup()
 {
     trueDepthBuffer.Release();
     CoreUtils.Destroy(depthClearMaterial);
     // CoreUtils.Destroy(foregroundCamera);
 }
示例#21
0
文件: Outline.cs 项目: LABSIM/APOLLON
 protected override void Cleanup()
 {
     CoreUtils.Destroy(fullscreenOutline);
     outlineBuffer.Release();
 }
示例#22
0
 public override void Cleanup()
 {
     CoreUtils.Destroy(m_ProceduralSkyMaterial);
 }
示例#23
0
 void ReleaseScreenSpaceShadows()
 {
     CoreUtils.Destroy(s_ScreenSpaceShadowsMat);
 }
示例#24
0
 protected override void Dispose(bool disposing)
 {
     CoreUtils.Destroy(m_BlitMaterial);
 }
示例#25
0
 public void Release()
 {
     CoreUtils.Destroy(m_Cache);
 }
示例#26
0
 protected override void DoCleanup()
 {
     CoreUtils.Destroy(material);
 }
 public override void Cleanup()
 {
     CoreUtils.Destroy(m_Material);
 }
示例#28
0
 public void Release()
 {
     ClearTextures();
     CoreUtils.Destroy(m_Atlas);
     CoreUtils.Destroy(m_MipMapGenerationTemp);
 }
示例#29
0
 public void Dispose()
 {
     CoreUtils.Destroy(material);
     CoreUtils.Destroy(missingTexture);
 }
示例#30
0
        private Texture GetCompatibleTexture(Texture tex)
        {
            if (tex == null)
            {
                return(tex);
            }

            var texPath      = AssetDatabase.GetAssetPath(tex);
            var incompatible = IncompatibleExtensions.Any(extension => texPath.EndsWith(extension, StringComparison.InvariantCultureIgnoreCase));

            // No need to convert texture if it uses glTF compatible format.
            // Note that the unsupported extensions are based on WISE implementation, not format standard.
            if (!incompatible)
            {
                return(tex);
            }

            var origImporter = (TextureImporter)AssetImporter.GetAtPath(texPath);

            // Standard blit won't work for normal textures due to Unity's way of storing data.
            // GltfBlit shader will convert Unity's imported normal format to proper pre-import RGB values.
            var mat = new Material(Shader.Find("Hidden/GltfBlit"));

            mat.SetKeyword("BLIT_NORMAL", origImporter.textureType == TextureImporterType.NormalMap);

            // Original texture might not be readable - use blit instead of copy or read/write pixels.
            var readWriteFormat = origImporter.sRGBTexture ? RenderTextureReadWrite.sRGB : RenderTextureReadWrite.Linear;
            var tmp             = RenderTexture.GetTemporary(tex.width, tex.height, 0, RenderTextureFormat.Default, readWriteFormat);

            Graphics.Blit(tex, tmp, mat);
            var prevTarget = RenderTexture.active;
            var newTex     = new Texture2D(tex.width, tex.height);

            newTex.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0);
            newTex.Apply();
            RenderTexture.active = prevTarget;

            var bytes       = newTex.EncodeToPNG();
            var fullPngPath = Path.Combine(tmpObjectPath, $"tmp_tex_{temporaryFiles.Count}.png");

            // Write PNG file to disk - FBX exporter scans materials for their original texture files.
            File.WriteAllBytes(fullPngPath, bytes);
            temporaryFiles.Add(fullPngPath);

            RenderTexture.ReleaseTemporary(tmp);

            AssetDatabase.Refresh();
            AssetDatabase.SaveAssets();

            // Copy settings from original importer to importer of new PNG file.
            var newImporter = (TextureImporter)AssetImporter.GetAtPath(fullPngPath);

            newImporter.textureType         = origImporter.textureType;
            newImporter.sRGBTexture         = origImporter.sRGBTexture;
            newImporter.alphaSource         = origImporter.alphaSource;
            newImporter.alphaIsTransparency = origImporter.alphaIsTransparency;
            newImporter.ignorePngGamma      = origImporter.ignorePngGamma;
            newImporter.isReadable          = origImporter.isReadable;
            newImporter.streamingMipmaps    = origImporter.streamingMipmaps;
            newImporter.mipmapEnabled       = origImporter.mipmapEnabled;
            newImporter.wrapMode            = origImporter.wrapMode;
            newImporter.filterMode          = origImporter.filterMode;
            newImporter.SaveAndReimport();

            AssetDatabase.Refresh();
            AssetDatabase.SaveAssets();

            CoreUtils.Destroy(mat);

            // Return newly created texture asset already processed by Unity's import pipeline.
            var newAsset = AssetDatabase.LoadAssetAtPath <Texture>(fullPngPath);

            return(newAsset);
        }