Example #1
0
 private void PerformPendingNormalBiasChange()
 {
     if (m_NormalBias != normalBiasFromProfile)
     {
         m_NormalBias = normalBiasFromProfile;
         m_Index.WriteConstants(ref m_Transform, m_Pool.GetPoolDimensions(), m_NormalBias);
     }
 }
        /// <summary>
        /// Initialize the reference volume.
        /// </summary>
        /// <param name ="allocationSize"> Size used for the chunk allocator that handles bricks.</param>
        /// <param name ="memoryBudget">Probe reference volume memory budget.</param>
        /// <param name ="indexDimensions">Dimensions of the index data structure.</param>
        public void InitProbeReferenceVolume(int allocationSize, ProbeVolumeTextureMemoryBudget memoryBudget, Vector3Int indexDimensions)
        {
            if (!m_ProbeReferenceVolumeInit)
            {
                Profiler.BeginSample("Initialize Reference Volume");
                m_Pool  = new ProbeBrickPool(allocationSize, memoryBudget);
                m_Index = new ProbeBrickIndex(indexDimensions);

                m_TmpBricks[0]          = new List <Brick>();
                m_TmpBricks[1]          = new List <Brick>();
                m_TmpBricks[0].Capacity = m_TmpBricks[1].Capacity = 1024;

                // initialize offsets
                m_PositionOffsets[0] = 0.0f;
                float probeDelta = 1.0f / ProbeBrickPool.kBrickCellCount;
                for (int i = 1; i < ProbeBrickPool.kBrickProbeCountPerDim - 1; i++)
                {
                    m_PositionOffsets[i] = i * probeDelta;
                }
                m_PositionOffsets[m_PositionOffsets.Length - 1] = 1.0f;
                Profiler.EndSample();

                m_ProbeReferenceVolumeInit = true;

                // Write constants on init to start with right data.
                m_Index.WriteConstants(ref m_Transform, m_Pool.GetPoolDimensions(), m_NormalBias);
                // Set the normalBiasFromProfile to avoid re-update of the constants up until the next change in profile editor
                normalBiasFromProfile = m_NormalBias;
            }
            m_NeedLoadAsset = true;
        }
        // Runtime API starts here
        internal RegId AddBricks(List <Brick> bricks, ProbeBrickPool.DataLocation dataloc)
        {
            Profiler.BeginSample("AddBricks");

            // calculate the number of chunks necessary
            int          ch_size = m_Pool.GetChunkSize();
            List <Chunk> ch_list = new List <Chunk>((bricks.Count + ch_size - 1) / ch_size);

            m_Pool.Allocate(ch_list.Capacity, ch_list);

            // copy chunks into pool
            m_TmpSrcChunks.Clear();
            m_TmpSrcChunks.Capacity = ch_list.Count;
            Chunk c;

            c.x = 0;
            c.y = 0;
            c.z = 0;

            // currently this code assumes that the texture width is a multiple of the allocation chunk size
            for (int i = 0; i < ch_list.Count; i++)
            {
                m_TmpSrcChunks.Add(c);
                c.x += ch_size * ProbeBrickPool.kBrickProbeCountPerDim;
                if (c.x >= dataloc.width)
                {
                    c.x  = 0;
                    c.y += ProbeBrickPool.kBrickProbeCountPerDim;
                    if (c.y >= dataloc.height)
                    {
                        c.y  = 0;
                        c.z += ProbeBrickPool.kBrickProbeCountPerDim;
                    }
                }
            }

            // Update the pool and index and ignore any potential frame latency related issues for now
            m_Pool.Update(dataloc, m_TmpSrcChunks, ch_list, ProbeVolumeSHBands.SphericalHarmonicsL2);

            m_BricksLoaded = true;

            // create a registry entry for this request
            RegId id;

            m_ID++;
            id.id = m_ID;
            m_Registry.Add(id, ch_list);

            // update the index
            m_Index.AddBricks(id, bricks, ch_list, m_Pool.GetChunkSize(), m_Pool.GetPoolWidth(), m_Pool.GetPoolHeight());
            m_Index.WriteConstants(ref m_Transform, m_Pool.GetPoolDimensions(), m_NormalBias);

            Profiler.EndSample();

            return(id);
        }