/// <summary> /// Draw each individual point lights /// </summary> /// <param name="light"></param> /// <param name="cameraOrigin"></param> private void DrawPointLight(PointLight light, Vector3 cameraOrigin, int vertexOffset, int startIndex, int primitiveCount) { if (!light.IsEnabled) { return; } //first let's check if the light is even in bounds if (_boundingFrustum.Contains(light.BoundingSphere) == ContainmentType.Disjoint || !_boundingFrustum.Intersects(light.BoundingSphere)) { return; } //For our stats GameStats.LightsDrawn++; //Send the light parameters to the shader if (_viewProjectionHasChanged) { light.LightViewSpace = light.WorldMatrix * _view; light.LightWorldViewProj = light.WorldMatrix * _viewProjection; } Shaders.deferredPointLightParameter_WorldView.SetValue(light.LightViewSpace); Shaders.deferredPointLightParameter_WorldViewProjection.SetValue(light.LightWorldViewProj); Shaders.deferredPointLightParameter_LightPosition.SetValue(light.LightViewSpace.Translation); Shaders.deferredPointLightParameter_LightColor.SetValue(light.ColorV3); Shaders.deferredPointLightParameter_LightRadius.SetValue(light.Radius); Shaders.deferredPointLightParameter_LightIntensity.SetValue(light.Intensity); //Compute whether we are inside or outside and use float cameraToCenter = Vector3.Distance(cameraOrigin, light.Position); int inside = cameraToCenter < light.Radius * 1.2f ? 1 : -1; Shaders.deferredPointLightParameter_Inside.SetValue(inside); if (GameSettings.g_UseDepthStencilLightCulling == 2) { _graphicsDevice.DepthStencilState = _stencilCullPass1; //draw front faces _graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; Shaders.deferredPointLightWriteStencil.Passes[0].Apply(); _graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, vertexOffset, startIndex, primitiveCount); //////////// _graphicsDevice.DepthStencilState = _stencilCullPass2; //draw backfaces _graphicsDevice.RasterizerState = RasterizerState.CullClockwise; light.ApplyShader(_inverseView); _graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, vertexOffset, startIndex, primitiveCount); } else { //If we are inside compute the backfaces, otherwise frontfaces of the sphere _graphicsDevice.RasterizerState = inside > 0 ? RasterizerState.CullClockwise : RasterizerState.CullCounterClockwise; light.ApplyShader(_inverseView); _graphicsDevice.DepthStencilState = GameSettings.g_UseDepthStencilLightCulling > 0 && !light.IsVolumetric && inside < 0 ? DepthStencilState.DepthRead : DepthStencilState.None; _graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, vertexOffset, startIndex, primitiveCount); } //Draw the sphere }