public void RegisterFilter(HDRayTracingFilter targetFilter) { if (!m_Filters.Contains(targetFilter)) { // Add this graph m_Filters.Add(targetFilter); // Try to get the sub-scene HDRayTracingSubScene currentSubScene = null; if (!m_SubScenes.TryGetValue(targetFilter.layermask.value, out currentSubScene)) { // Create the ray-tracing sub-scene currentSubScene = new HDRayTracingSubScene(); currentSubScene.mask = targetFilter.layermask.value; // If this is a new graph, we need to build its data BuildSubSceneStructure(ref currentSubScene); // register this sub-scene and this layer mask m_SubScenes.Add(targetFilter.layermask.value, currentSubScene); m_LayerMasks.Add(targetFilter.layermask.value); } // Add this graph to the reference graphs currentSubScene.referenceFilters.Add(targetFilter); } }
public void UnregisterFilter(HDRayTracingFilter targetFilter) { if (m_Filters.Contains(targetFilter)) { // Add this graph m_Filters.Remove(targetFilter); // Match the sub-matching sub-scene HDRayTracingSubScene currentSubScene = null; if (m_SubScenes.TryGetValue(targetFilter.layermask.value, out currentSubScene)) { // Remove the reference to this graph currentSubScene.referenceFilters.Remove(targetFilter); // Is there is no one referencing this sub-scene and it is not persistent, then we need to delete its if (currentSubScene.referenceFilters.Count == 0 && !currentSubScene.persistent) { // If this is a new graph, we need to build its data DestroySubSceneStructure(ref currentSubScene); // Remove it from the list of the sub-scenes m_SubScenes.Remove(targetFilter.layermask.value); m_LayerMasks.Remove(targetFilter.layermask.value); } } } }
public HDRayTracingSubScene RequestSubScene(HDCamera hdCamera) { bool editorCamera = hdCamera.camera.cameraType == CameraType.SceneView || hdCamera.camera.cameraType == CameraType.Preview; if (editorCamera) { // For the scene view, we want to use the default acceleration structure return(RequestSubScene(m_Settings.editorRaytracingFilterLayerMask)); } else { HDRayTracingFilter raytracingFilter = hdCamera.camera.gameObject.GetComponent <HDRayTracingFilter>(); return(raytracingFilter ? RequestSubScene(raytracingFilter.layermask) : null); } }
public void SetDirty() { int numFilters = m_Filters.Count; for (int filterIdx = 0; filterIdx < numFilters; ++filterIdx) { // Grab the target graph component HDRayTracingFilter filterComponent = m_Filters[filterIdx]; // If this camera had a graph component had an obsolete flag if (filterComponent != null) { filterComponent.SetDirty(); } } }
public void InitAccelerationStructures() { // Create the sub-scene structure m_SubScenes = new Dictionary <int, HDRayTracingSubScene>(); // Grab all the ray tracing graphs in the scene HDRayTracingFilter[] tracingGraphs = UnityEngine.Object.FindObjectsOfType <HDRayTracingFilter>(); m_LayerMasks = new List <int>(); // Build an array with all the layer combinations that are requested for (var filterIndex = 0; filterIndex < tracingGraphs.Length; filterIndex++) { // Grab the current graph HDRayTracingFilter currentFilter = tracingGraphs[filterIndex]; // Fetch or create the sub-scene HDRayTracingSubScene currentSubScene = null; if (!m_SubScenes.TryGetValue(currentFilter.layermask.value, out currentSubScene)) { currentSubScene = new HDRayTracingSubScene(); currentSubScene.mask = currentFilter.layermask.value; m_SubScenes.Add(currentFilter.layermask.value, currentSubScene); m_LayerMasks.Add(currentFilter.layermask.value); } // Mark the current graph for a reference currentSubScene.referenceFilters.Add(currentFilter); } // Create all the ray tracing for (var subSceneIndex = 0; subSceneIndex < m_LayerMasks.Count; subSceneIndex++) { HDRayTracingSubScene currentSubScene = m_SubScenes[m_LayerMasks[subSceneIndex]]; BuildSubSceneStructure(ref currentSubScene); } }
public void CheckSubScenes() { // Here there is two options, either the full things needs to be rebuilded or we should only rebuild the ones that have been flagged obsolete if (m_DirtyEnvironment) { // First of let's reset all the obsolescence flags int numFilters = m_Filters.Count; for (int filterIdx = 0; filterIdx < numFilters; ++filterIdx) { // Grab the target graph component HDRayTracingFilter filterComponent = m_Filters[filterIdx]; // If this camera had a graph component had an obsolete flag if (filterComponent != null) { filterComponent.ResetDirty(); } } // Also let's mark all the sub-scenes as obsolete for (var subSceneIndex = 0; subSceneIndex < m_LayerMasks.Count; subSceneIndex++) { HDRayTracingSubScene currentSubScene = m_SubScenes[m_LayerMasks[subSceneIndex]]; currentSubScene.obsolete = true; } m_DirtyEnvironment = false; } else { // First of all propagate the obsolete flags to the sub scenes int numGraphs = m_Filters.Count; for (int filterIdx = 0; filterIdx < numGraphs; ++filterIdx) { // Grab the target graph component HDRayTracingFilter filterComponent = m_Filters[filterIdx]; // If this camera had a graph component had an obsolete flag if (filterComponent != null && filterComponent.IsDirty()) { // Get the sub-scene that matches HDRayTracingSubScene currentSubScene = null; if (m_SubScenes.TryGetValue(filterComponent.layermask, out currentSubScene)) { currentSubScene.obsolete = true; } filterComponent.ResetDirty(); } } } // Rebuild all the obsolete scenes for (var subSceneIndex = 0; subSceneIndex < m_LayerMasks.Count; subSceneIndex++) { // Grab the current sub-scene HDRayTracingSubScene subScene = m_SubScenes[m_LayerMasks[subSceneIndex]]; // Does this scene need rebuilding? if (subScene.obsolete) { DestroySubSceneStructure(ref subScene); BuildSubSceneStructure(ref subScene); subScene.obsolete = false; } } }