public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var chunkSHAr = chunk.GetNativeArray(SHArType);
                var chunkSHAg = chunk.GetNativeArray(SHAgType);
                var chunkSHAb = chunk.GetNativeArray(SHAbType);
                var chunkSHBr = chunk.GetNativeArray(SHBrType);
                var chunkSHBg = chunk.GetNativeArray(SHBgType);
                var chunkSHBb = chunk.GetNativeArray(SHBbType);
                var chunkSHC  = chunk.GetNativeArray(SHCType);

                for (var i = 0; i < chunkSHAr.Length; i++)
                {
                    chunkSHAr[i] = new BuiltinMaterialPropertyUnity_SHAr {
                        Value = Properties.SHAr
                    };
                    chunkSHAg[i] = new BuiltinMaterialPropertyUnity_SHAg {
                        Value = Properties.SHAg
                    };
                    chunkSHAb[i] = new BuiltinMaterialPropertyUnity_SHAb {
                        Value = Properties.SHAb
                    };
                    chunkSHBr[i] = new BuiltinMaterialPropertyUnity_SHBr {
                        Value = Properties.SHBr
                    };
                    chunkSHBg[i] = new BuiltinMaterialPropertyUnity_SHBg {
                        Value = Properties.SHBg
                    };
                    chunkSHBb[i] = new BuiltinMaterialPropertyUnity_SHBb {
                        Value = Properties.SHBb
                    };
                    chunkSHC[i] = new BuiltinMaterialPropertyUnity_SHC {
                        Value = Properties.SHC
                    };
                }
            }
Esempio n. 2
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var chunkSHAr         = chunk.GetNativeArray(SHArType);
                var chunkSHAg         = chunk.GetNativeArray(SHAgType);
                var chunkSHAb         = chunk.GetNativeArray(SHAbType);
                var chunkSHBr         = chunk.GetNativeArray(SHBrType);
                var chunkSHBg         = chunk.GetNativeArray(SHBgType);
                var chunkSHBb         = chunk.GetNativeArray(SHBbType);
                var chunkSHC          = chunk.GetNativeArray(SHCType);
                var chunkLocalToWorld = chunk.GetNativeArray(LocalToWorldType);

                var tetrahedronIndexGuesses = new NativeArray <int>(chunkSHAr.Length, Allocator.Temp);

                for (var i = 0; i < chunkSHAr.Length; i++)
                {
                    tetrahedronIndexGuesses[i] = -1;
                }

                for (var i = 0; i < chunkSHAr.Length; i++)
                {
                    var position             = chunkLocalToWorld[i].Position;
                    int tetrahedronIndex     = tetrahedronIndexGuesses[i];
                    int prevTetrahedronIndex = tetrahedronIndex;
                    lightProbesQuery.CalculateInterpolatedLightAndOcclusionProbe(position, tetrahedronIndex, out var lightProbe, out var occlusionProbe);
                    if (tetrahedronIndex != prevTetrahedronIndex)
                    {
                        tetrahedronIndexGuesses[i] = tetrahedronIndex;
                    }

                    var properties = new SHProperties(lightProbe);
                    chunkSHAr[i] = new BuiltinMaterialPropertyUnity_SHAr {
                        Value = properties.SHAr
                    };
                    chunkSHAg[i] = new BuiltinMaterialPropertyUnity_SHAg {
                        Value = properties.SHAg
                    };
                    chunkSHAb[i] = new BuiltinMaterialPropertyUnity_SHAb {
                        Value = properties.SHAb
                    };
                    chunkSHBr[i] = new BuiltinMaterialPropertyUnity_SHBr {
                        Value = properties.SHBr
                    };
                    chunkSHBg[i] = new BuiltinMaterialPropertyUnity_SHBg {
                        Value = properties.SHBg
                    };
                    chunkSHBb[i] = new BuiltinMaterialPropertyUnity_SHBb {
                        Value = properties.SHBb
                    };
                    chunkSHC[i] = new BuiltinMaterialPropertyUnity_SHC {
                        Value = properties.SHC
                    };
                }
            }
        private void UpdateEntitiesFromGrid()
        {
            Profiler.BeginSample("UpdateEntitiesFromGrid");

            var SHArType         = GetComponentTypeHandle <BuiltinMaterialPropertyUnity_SHAr>();
            var SHAgType         = GetComponentTypeHandle <BuiltinMaterialPropertyUnity_SHAg>();
            var SHAbType         = GetComponentTypeHandle <BuiltinMaterialPropertyUnity_SHAb>();
            var SHBrType         = GetComponentTypeHandle <BuiltinMaterialPropertyUnity_SHBr>();
            var SHBgType         = GetComponentTypeHandle <BuiltinMaterialPropertyUnity_SHBg>();
            var SHBbType         = GetComponentTypeHandle <BuiltinMaterialPropertyUnity_SHBb>();
            var SHCType          = GetComponentTypeHandle <BuiltinMaterialPropertyUnity_SHC>();
            var localToWorldType = GetComponentTypeHandle <LocalToWorld>();

            var chunks = m_ProbeGridQuery.CreateArchetypeChunkArray(Allocator.Temp);

            if (chunks.Length == 0)
            {
                Profiler.EndSample();
                return;
            }

            //TODO: Bring this off the main thread when we have new c++ API
            Dependency.Complete();

            foreach (var chunk in chunks)
            {
                var chunkSHAr         = chunk.GetNativeArray(SHArType);
                var chunkSHAg         = chunk.GetNativeArray(SHAgType);
                var chunkSHAb         = chunk.GetNativeArray(SHAbType);
                var chunkSHBr         = chunk.GetNativeArray(SHBrType);
                var chunkSHBg         = chunk.GetNativeArray(SHBgType);
                var chunkSHBb         = chunk.GetNativeArray(SHBbType);
                var chunkSHC          = chunk.GetNativeArray(SHCType);
                var chunkLocalToWorld = chunk.GetNativeArray(localToWorldType);

                m_Positions.Clear();
                m_LightProbes.Clear();
                m_OcclusionProbes.Clear();

                for (int i = 0; i != chunkLocalToWorld.Length; i++)
                {
                    m_Positions.Add(chunkLocalToWorld[i].Position);
                }

                LightProbes.CalculateInterpolatedLightAndOcclusionProbes(m_Positions, m_LightProbes, m_OcclusionProbes);

                for (int i = 0; i < m_Positions.Count; ++i)
                {
                    var properties = new SHProperties(m_LightProbes[i]);
                    chunkSHAr[i] = new BuiltinMaterialPropertyUnity_SHAr {
                        Value = properties.SHAr
                    };
                    chunkSHAg[i] = new BuiltinMaterialPropertyUnity_SHAg {
                        Value = properties.SHAg
                    };
                    chunkSHAb[i] = new BuiltinMaterialPropertyUnity_SHAb {
                        Value = properties.SHAb
                    };
                    chunkSHBr[i] = new BuiltinMaterialPropertyUnity_SHBr {
                        Value = properties.SHBr
                    };
                    chunkSHBg[i] = new BuiltinMaterialPropertyUnity_SHBg {
                        Value = properties.SHBg
                    };
                    chunkSHBb[i] = new BuiltinMaterialPropertyUnity_SHBb {
                        Value = properties.SHBb
                    };
                    chunkSHC[i] = new BuiltinMaterialPropertyUnity_SHC {
                        Value = properties.SHC
                    };
                }
            }
            Profiler.EndSample();
        }