private void PrepareSpotlights() { MyLights.Update(); MyLights.SpotlightsBvh.OverlapAllFrustum(ref MyRender11.Environment.ViewFrustumClippedD, MyLightRendering.VisibleSpotlights); if (MyLightRendering.VisibleSpotlights.Count == 0) { OtherShadowsTriangleCounter = 0; } MyLightRendering.VisibleSpotlights.Sort(m_spotlightCastersComparer); int index = 0; int casterIndex = 0; var worldMatrix = MatrixD.CreateTranslation(MyRender11.Environment.CameraPosition); foreach (var id in MyLightRendering.VisibleSpotlights) { if (id.CastsShadows && casterIndex < MAX_SPOTLIGHT_SHADOWCASTERS) { if (ShadowmapsPool.Count <= casterIndex) { ShadowmapsPool.Add(MyRwTextures.CreateShadowmap(SpotlightShadowmapSize, SpotlightShadowmapSize)); } MyLights.Lights.Data[id.Index].CastsShadowsThisFrame = true; MatrixD viewProjection = MyLights.GetSpotlightViewProjection(id); var query = new MyShadowmapQuery { DepthBuffer = ShadowmapsPool[casterIndex].Dsv, Viewport = new MyViewport(SpotlightShadowmapSize, SpotlightShadowmapSize), QueryType = MyFrustumEnum.ShadowProjection, ProjectionInfo = new MyProjectionInfo { WorldCameraOffsetPosition = MyRender11.Environment.CameraPosition, WorldToProjection = viewProjection, LocalToProjection = worldMatrix * viewProjection }, IgnoredEntities = MyLights.IgnoredEntitites.ContainsKey(id) ? MyLights.IgnoredEntitites[id] : null, }; m_shadowmapQueries.Add(query); ++casterIndex; } else { MyLights.Lights.Data[id.Index].CastsShadowsThisFrame = false; } index++; } }
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++; } }