Esempio n. 1
0
        private void PrepareSpotlights()
        {
            int index       = 0;
            int casterIndex = 0;
            var worldMatrix = MatrixD.CreateTranslation(MyRender11.Environment.Matrices.CameraPosition);

            foreach (var id in MyLightsRendering.VisibleSpotlights)
            {
                if (id.CastsShadows && casterIndex < MAX_SPOTLIGHT_SHADOWCASTERS)
                {
                    if (ShadowmapsPool.Count <= casterIndex)
                    {
                        ShadowmapsPool.Add(MyManagers.RwTextures.CreateDepth("ShadowmapsPool.Item", SpotlightShadowmapSize, SpotlightShadowmapSize, Format.R32_Typeless, Format.R32_Float, Format.D32_Float));
                    }

                    MyLights.SetCastsShadowsThisFrame(id, true);

                    MatrixD viewProjection = MyLights.GetSpotlightViewProjection(id);
                    var     query          = new MyShadowmapQuery
                    {
                        DepthBuffer    = ShadowmapsPool[casterIndex],
                        Viewport       = new MyViewport(SpotlightShadowmapSize, SpotlightShadowmapSize),
                        QueryType      = MyFrustumEnum.ShadowProjection,
                        Index          = casterIndex,
                        ProjectionInfo = new MyProjectionInfo
                        {
                            WorldCameraOffsetPosition = MyRender11.Environment.Matrices.CameraPosition,
                            WorldToProjection         = viewProjection,
                            LocalToProjection         = worldMatrix * viewProjection
                        },
                        IgnoredEntities = MyLights.GetEntitiesIgnoringShadow(id)
                    };
                    m_shadowmapQueries.Add(query);
                    ++casterIndex;
                }
                else
                {
                    MyLights.SetCastsShadowsThisFrame(id, false);
                }

                index++;
            }
        }