public static void FetchHistogramValues()
    {
        // Fetch histograms from GPU
        var histograms = new HistStruct[SceneManager.Get.SceneHierarchy.Count];

        GPUBuffers.Get.Histograms.GetData(histograms);

        // Clear histograms
        ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(2, "_Histograms", GPUBuffers.Get.Histograms);
        ComputeShaderManager.Get.ComputeVisibilityCS.Dispatch(2, Mathf.CeilToInt(CPUBuffers.Get.HistogramData.Count / 64.0f), 1, 1);

        foreach (var histogram in histograms)
        {
            int addWhere = histogram.parent;
            while (addWhere >= 0)
            {
                histograms[addWhere].all     += histogram.all;
                histograms[addWhere].cutaway += histogram.cutaway;
                histograms[addWhere].visible += histogram.visible;
                addWhere = histograms[addWhere].parent;
            }
        }

        CPUBuffers.Get.HistogramData = histograms.ToList();
    }
Exemple #2
0
    void InitHistogramLookups()
    {
        // Init histogram GPU buffer
        CPUBuffers.Get.HistogramData.Clear();
        foreach (var path in SceneManager.Get.SceneHierarchy)
        {
            var hist = new HistStruct
            {
                parent    = -1,
                all       = 0,
                cutaway   = 0,
                occluding = 0,
                visible   = 0
            };

            if (MyUtility.IsPathRoot(path))
            {
                hist.parent = -1;
            }
            else
            {
                var parentPath = MyUtility.GetParentUrlPath(path);
                if (!SceneManager.Get.SceneHierarchy.Contains(parentPath))
                {
                    throw new Exception("Hierarchy corrupted");
                }
                hist.parent = SceneManager.Get.SceneHierarchy.IndexOf(parentPath);
            }

            CPUBuffers.Get.HistogramData.Add(hist);
        }

        //*******************************//

        CPUBuffers.Get.IngredientToNodeLookup.Clear();

        foreach (var ingredientName in SceneManager.Get.AllIngredientNames)
        {
            if (SceneManager.Get.SceneHierarchy.Contains(ingredientName))
            {
                CPUBuffers.Get.IngredientToNodeLookup.Add(SceneManager.Get.SceneHierarchy.IndexOf(ingredientName));
            }
        }

        //*******************************//

        CPUBuffers.Get.NodeToIngredientLookup.Clear();

        foreach (var path in SceneManager.Get.SceneHierarchy)
        {
            if (SceneManager.Get.AllIngredientNames.Contains(path))
            {
                CPUBuffers.Get.NodeToIngredientLookup.Add(SceneManager.Get.AllIngredientNames.IndexOf(path));
            }
            else
            {
                CPUBuffers.Get.NodeToIngredientLookup.Add(-1);
            }
        }
    }
    public static void FetchHistogramValues()
    {
        // Fetch histograms from GPU
        var histograms = new HistStruct[SceneManager.Get.SceneHierarchy.Count];
        GPUBuffers.Get.Histograms.GetData(histograms);

        // Clear histograms
        ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(2, "_Histograms", GPUBuffers.Get.Histograms);
        ComputeShaderManager.Get.ComputeVisibilityCS.Dispatch(2, Mathf.CeilToInt(CPUBuffers.Get.HistogramData.Count / 64.0f), 1, 1);

        foreach (var histogram in histograms)
        {
            int addWhere = histogram.parent;
            while (addWhere >= 0)
            {
                histograms[addWhere].all += histogram.all;
                histograms[addWhere].cutaway += histogram.cutaway;
                histograms[addWhere].visible += histogram.visible;
                addWhere = histograms[addWhere].parent;
            }
        }

        CPUBuffers.Get.HistogramData = histograms.ToList();
    }
    void InitHistogramLookups()
    {
        // Init histogram GPU buffer
        HistogramData.Clear();
        foreach (var path in SceneHierarchy)
        {
            var hist = new HistStruct
            {
                parent = -1,
                all = 0,
                cutaway = 0,
                occluding = 0,
                visible = 0
            };

            if (MyUtility.IsPathRoot(path))
            {
                hist.parent = -1;
            }
            else
            {
                var parentPath = MyUtility.GetParentUrlPath(path);
                if(!SceneHierarchy.Contains(parentPath)) throw new Exception("Hierarchy corrupted");
                hist.parent = SceneHierarchy.IndexOf(parentPath);
            }

            HistogramData.Add(hist);
        }

        //*******************************//

        IngredientToNodeLookup.Clear();

        foreach (var ingredientName in AllIngredientNames)
        {
            if (SceneHierarchy.Contains(ingredientName))
            {
                IngredientToNodeLookup.Add(SceneHierarchy.IndexOf(ingredientName));
            }
        }

        //*******************************//

        NodeToIngredientLookup.Clear();

        foreach (var path in SceneHierarchy)
        {
            if (AllIngredientNames.Contains(path))
            {
                NodeToIngredientLookup.Add(AllIngredientNames.IndexOf(path));
            }
            else
            {
                NodeToIngredientLookup.Add(-1);
            }
        }

        int a = 0;
    }
    void FetchHistogramValues()
    {
        // Fetch histograms from GPU
        var histograms = new HistStruct[SceneManager.Get.SceneHierarchy.Count];
        GPUBuffers.Instance.Histograms.GetData(histograms);

        //read back the cull flag buffer
        SceneManager.Get.cullflags = new int[SceneManager.Get.NumProteinInstances];
        GPUBuffers.Instance.ProteinInstanceCullFlags.GetData(SceneManager.Get.cullflags);

        SceneManager.Get.distance = new float[SceneManager.Get.NumProteinInstances];
        GPUBuffers.Instance.ProteinInstanceDistance.GetData(SceneManager.Get.distance);

        /*Debug.Log("~~~~~~~~~~~~~~~~~~~~");
        for (int i = 0; i < 30; i++)
        {
            Debug.Log(SceneManager.Get.distance[i]);
        }
        Debug.Log("====================");*/

        ComputeShaderManager.Instance.ObjectSpaceCutAwaysCS.SetBuffer(0, "_ProteinInstanceCullFlags", GPUBuffers.Instance.ProteinInstanceCullFlags);

        // Clear histograms
        ComputeShaderManager.Instance.ComputeVisibilityCS.SetBuffer(2, "_Histograms", GPUBuffers.Instance.Histograms);
        ComputeShaderManager.Instance.ComputeVisibilityCS.Dispatch(2, Mathf.CeilToInt(SceneManager.Get.HistogramData.Count / 64.0f), 1, 1);

        foreach (var histogram in histograms)
        {
            int addWhere = histogram.parent;
            while (addWhere >= 0)
            {
                histograms[addWhere].all += histogram.all;
                histograms[addWhere].cutaway += histogram.cutaway;
                histograms[addWhere].visible += histogram.visible;
                addWhere = histograms[addWhere].parent;
            }
        }

        SceneManager.Get.HistogramData = histograms.ToList();

        //int a = 0;
    }