/// <summary> /// Initializes the RenderManager /// </summary> public void init(GraphicsDevice graphicsDevice) { this.GraphicsDevice = graphicsDevice; if (graphicsDevice != null) { bloomComponent = new BloomComponent(graphicsDevice, GameManager.Instance.Content); bloomComponent.loadContent(); bloomLightComponent = new BloomComponent(graphicsDevice, GameManager.Instance.Content); bloomLightComponent.loadContent(); this.spriteBatch = new SpriteBatch(this.GraphicsDevice); lightEffect = GameManager.Resources.Content.Load <Effect>("light.mgfx"); } }
public void renderAll(List <GameObject> gobs, List <InstanceDescriptor> insts) { //get width and height of window int bbWidth = GraphicsDevice.PresentationParameters.BackBufferWidth; int bbHeight = GraphicsDevice.PresentationParameters.BackBufferHeight; //initialize bloom component if (bloomComponent == null) { bloomComponent = new BloomComponent(GraphicsDevice, WhiskeyControl.Content); bloomComponent.loadContent(); bloomComponent.Settings = BloomSettings.PresetSettings[0]; } if (lightBloomComponent == null) { lightBloomComponent = new BloomComponent(GraphicsDevice, WhiskeyControl.Content); lightBloomComponent.loadContent(); lightBloomComponent.Settings = BloomSettings.PresetSettings[5]; } //load bloom settings if (Level.BloomSettings != null) { bloomComponent.Settings = Level.BloomSettings; } if (Level.LightBloomSettings != null) { lightBloomComponent.Settings = Level.LightBloomSettings; } //ensure render targets are correctly sized hudTarget = checkRenderTarget(hudTarget, bbWidth, bbHeight); lightMapTarget = checkRenderTarget(lightMapTarget, bbWidth, bbHeight); sceneTarget = checkRenderTarget(sceneTarget, bbWidth, bbHeight); hudObjectsTarget = checkRenderTarget(hudObjectsTarget, 1280, 720); layerScreenShader = checkRenderTarget(layerScreenShader, bbWidth, bbHeight); currentLayerTarget = checkRenderTarget(currentLayerTarget, bbWidth, bbHeight); //get game objects, and ui gameobjects List <GameObject> uiGameObjects = new List <GameObject>(); List <GameObject> gobsToRender = new List <GameObject>(); gobs.ForEach(g => uiGameObjects.Add(g)); insts.Where(g => !g.HudObject).ToList().ForEach(g => gobsToRender.Add(g)); //DRAW HUD renderHud(); //draw light radius gobsToRender.ForEach(g => { if (g.Light.Visible) { Convex convex = new Convex(g.Position, 0, VectorSet.Dodecahedren * (g.Light.Radius / 2)); convex.render(GraphicsDevice, CameraTransform, new RenderHints().setColor(Level.BackgroundColor.Inverted)); } }); //DRAW GAME OBJECTS // bloomComponent.BeginDraw(); render(gobsToRender); bloomComponent.BeginDraw(); GraphicsDevice.Clear(Level.BackgroundColor); spriteBatch.Begin(); spriteBatch.Draw(layerScreenShader, Vector.Zero, XnaColor.White); spriteBatch.End(); bloomComponent.draw(); //DRAW LIGHTMAP renderLightMap(gobs, insts.Where(g => !g.HudObject).ToList()); //DRAW SCENE WITH LIGHTMAP GraphicsDevice.SetRenderTarget(null); GraphicsDevice.Textures[1] = lightMapTarget; Vector4 ambience = ((XnaColor)Level.AmbientLight).ToVector4(); lightEffect.Parameters["ambience"].SetValue(ambience); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.LinearWrap, DepthStencilState.Default, RasterizerState.CullNone, Level.PreviewLighting ? lightEffect : null); spriteBatch.Draw(bloomComponent.OutputTarget, Vector.Zero, XnaColor.White); spriteBatch.End(); //DRAW HUD spriteBatch.Begin(); spriteBatch.Draw(hudTarget, Vector.Zero, XnaColor.White); spriteBatch.End(); }