public ImperativeRenderer ForRenderTarget(RenderTarget2D renderTarget, Action <DeviceManager, object> before = null, Action <DeviceManager, object> after = null, object userData = null) { var result = this; var group = BatchGroup.ForRenderTarget(Container, Layer, renderTarget, before, after, userData); group.Dispose(); result.Container = group; result.Layer = 0; Layer += 1; return(result); }
public override void Draw(GameTime gameTime, Frame frame) { using (var rtb = BatchGroup.ForRenderTarget(frame, -1, Rt)) { var ir = new ImperativeRenderer(rtb, Materials); ir.Clear(color: Color.Transparent); ir.SetViewport(new Rectangle(128, 128, 256, 256), true); ir.FillRectangle(new Rectangle(0, 0, 512, 512), Color.Black, customMaterial: Vpos); } { var ir = new ImperativeRenderer(frame, Materials) { AutoIncrementLayer = true }; ir.SetViewport(null, true); ir.Clear(color: Color.SteelBlue); const float scale = 0.65f; var pos = new Vector2(Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight) / 2f; ir.Draw( Texture, pos, origin: Vector2.One * 0.5f, scale: Vector2.One * scale, blendState: BlendState.Opaque, samplerState: SamplerState.LinearClamp ); ir.DrawString( Font, "Hello, World!", Vector2.Zero, blendState: BlendState.AlphaBlend, material: Materials.ScreenSpaceShadowedBitmap ); var sg = ir.MakeSubgroup(); sg.AutoIncrementLayer = true; sg.SetViewport(new Rectangle(128, 128, 512, 512), true); sg.FillRectangle(new Rectangle(0, 0, 1024, 1024), Color.Black, customMaterial: Vpos); sg.SetViewport(null, true); ir.Draw( Rt, new Vector2(1920 - 512, 0) ); } }
public override void Draw(Squared.Render.Frame frame) { const float LightmapScale = 1f; LightmapMaterials.ViewportScale = new Vector2(1f / LightmapScale); LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter( 0, Width, Height, 0, 0, 1 ); CreateRenderTargets(); var args = new float[] { MagnitudeScale, MiddleGray, AppliedAverageLuminance, MaximumLuminance }; using (var bg = BatchGroup.ForRenderTarget( frame, -1, Lightmap, (dm, _) => Renderer.IlluminantMaterials.SetGammaCompressionParameters(args[0], args[1], args[2], args[3]) )) { ClearBatch.AddNew(bg, 0, LightmapMaterials.Clear, clearColor: Color.Black, clearZ: 0, clearStencil: 0); Renderer.RenderLighting(frame, bg, 1, intensityScale: 1 / MagnitudeScale); }; ClearBatch.AddNew(frame, 0, Game.ScreenMaterials.Clear, clearColor: Color.Black); using (var bb = BitmapBatch.New( frame, 1, Game.ScreenMaterials.Get(Renderer.IlluminantMaterials.ScreenSpaceGammaCompressedBitmap, blendState: BlendState.Opaque) )) bb.Add(new BitmapDrawCall(Lightmap, Vector2.Zero)); if (ShowOutlines) { Renderer.RenderOutlines(frame, 2, true); } }
public override void Draw(Squared.Render.Frame frame) { CreateRenderTargets(); LightmapMaterials.ViewportScale = new Vector2(1f / LightmapScale); LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter( 0, BackgroundLightmap.Width, BackgroundLightmap.Height, 0, 0, 1 ); using (var backgroundGroup = BatchGroup.ForRenderTarget(frame, 0, Background)) { ClearBatch.AddNew(backgroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent); using (var bb = BitmapBatch.New(backgroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) { for (var i = 0; i < 1; i++) { var layer = Layers[i]; var dc = new BitmapDrawCall(layer, Vector2.Zero); dc.SortKey = i; bb.Add(dc); } } } using (var foregroundGroup = BatchGroup.ForRenderTarget(frame, 1, Foreground)) { ClearBatch.AddNew(foregroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent); using (var bb = BitmapBatch.New(foregroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) { for (var i = 1; i < Layers.Length; i++) { var layer = Layers[i]; var dc = new BitmapDrawCall(layer, Vector2.Zero); dc.SortKey = i; bb.Add(dc); } } } using (var backgroundLightGroup = BatchGroup.ForRenderTarget(frame, 4, BackgroundLightmap)) { ClearBatch.AddNew(backgroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(32, 32, 32, 255), clearZ: 0, clearStencil: 0); BackgroundRenderer.RenderLighting(frame, backgroundLightGroup, 2); } using (var foregroundLightGroup = BatchGroup.ForRenderTarget(frame, 5, ForegroundLightmap)) { ClearBatch.AddNew(foregroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(96, 96, 96, 255), clearZ: 0, clearStencil: 0); ForegroundRenderer.RenderLighting(frame, foregroundLightGroup, 2); } SetRenderTargetBatch.AddNew(frame, 49, null); ClearBatch.AddNew(frame, 50, Game.ScreenMaterials.Clear, clearColor: Color.Black, clearZ: 0, clearStencil: 0); if (ShowLightmap) { using (var bb = BitmapBatch.New(frame, 55, Game.ScreenMaterials.WorldSpaceBitmap)) { var dc = new BitmapDrawCall(BackgroundLightmap, Vector2.Zero, LightmapScale); bb.Add(dc); } ParticleRenderer.Draw(frame, 56); } else { var dc = new BitmapDrawCall(Background, Vector2.Zero); var material = LightmapMaterials.Get(LightmapMaterials.WorldSpaceLightmappedBitmap, blendState: BlendState.AlphaBlend); using (var bb = BitmapBatch.New(frame, 55, material)) { dc.Textures = new TextureSet(Background, BackgroundLightmap); dc.SortKey = 0; bb.Add(dc); } ParticleRenderer.Draw(frame, 56); using (var bb = BitmapBatch.New(frame, 57, material)) { dc.Textures = new TextureSet(Foreground, ForegroundLightmap); dc.SortKey = 1; bb.Add(dc); } } if (ShowOutlines || (Dragging != null)) { BackgroundRenderer.RenderOutlines(frame, 59, true); } }
public override void Draw(Squared.Render.Frame frame) { CreateRenderTargets(); LightmapMaterials.ViewportScale = new Vector2(1f / LightmapScale); LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter( 0, BackgroundLightmap.Width, BackgroundLightmap.Height, 0, 0, 1 ); using (var backgroundGroup = BatchGroup.ForRenderTarget(frame, 0, Background)) { ClearBatch.AddNew(backgroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent); using (var bb = BitmapBatch.New(backgroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) { for (var i = 0; i < 1; i++) { var layer = Layers[i]; var dc = new BitmapDrawCall(layer, Vector2.Zero); dc.SortKey = i; bb.Add(dc); } } } using (var foregroundGroup = BatchGroup.ForRenderTarget(frame, 1, Foreground)) { ClearBatch.AddNew(foregroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent); using (var bb = BitmapBatch.New(foregroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) { for (var i = 1; i < Layers.Length; i++) { var layer = Layers[i]; var dc = new BitmapDrawCall(layer, Vector2.Zero); dc.SortKey = i; bb.Add(dc); } } } if (ShowBrickSpecular) { using (var bricksLightGroup = BatchGroup.ForRenderTarget(frame, 2, ForegroundLightmap)) { ClearBatch.AddNew(bricksLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(0, 0, 0, 255), clearZ: 0, clearStencil: 0); ForegroundRenderer.RenderLighting(frame, bricksLightGroup, 2); } } if (ShowAOShadow) { using (var aoShadowFirstPassGroup = BatchGroup.ForRenderTarget(frame, 3, AOShadowScratch)) { ClearBatch.AddNew(aoShadowFirstPassGroup, 1, LightmapMaterials.Clear, clearColor: Color.Transparent); using (var bb = BitmapBatch.New(aoShadowFirstPassGroup, 2, Game.ScreenMaterials.ScreenSpaceHorizontalGaussianBlur5Tap)) { bb.Add(new BitmapDrawCall(Foreground, Vector2.Zero, 1f / LightmapScale)); } } } using (var backgroundLightGroup = BatchGroup.ForRenderTarget(frame, 4, BackgroundLightmap)) { ClearBatch.AddNew(backgroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(40, 40, 40, 255), clearZ: 0, clearStencil: 0); BackgroundRenderer.RenderLighting(frame, backgroundLightGroup, 2); if (ShowBrickSpecular) { using (var foregroundLightBatch = BitmapBatch.New(backgroundLightGroup, 3, MaskedForegroundMaterial)) { var dc = new BitmapDrawCall( ForegroundLightmap, Vector2.Zero ); dc.Textures = new TextureSet(dc.Textures.Texture1, BricksLightMask); foregroundLightBatch.Add(dc); } } else { ForegroundRenderer.RenderLighting(frame, backgroundLightGroup, 3); } if (ShowAOShadow) { using (var aoShadowBatch = BitmapBatch.New(backgroundLightGroup, 4, AOShadowMaterial)) { var dc = new BitmapDrawCall( AOShadowScratch, new Vector2(0, 4) ); dc.MultiplyColor = Color.Black; dc.AddColor = Color.White; aoShadowBatch.Add(dc); } } } using (var foregroundLightGroup = BatchGroup.ForRenderTarget(frame, 5, ForegroundLightmap)) { ClearBatch.AddNew(foregroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(127, 127, 127, 255), clearZ: 0, clearStencil: 0); ForegroundRenderer.RenderLighting(frame, foregroundLightGroup, 2); } SetRenderTargetBatch.AddNew(frame, 49, null); ClearBatch.AddNew(frame, 50, Game.ScreenMaterials.Clear, clearColor: Color.Black, clearZ: 0, clearStencil: 0); if (ShowLightmap) { using (var bb = BitmapBatch.New(frame, 55, Game.ScreenMaterials.WorldSpaceBitmap)) { var dc = new BitmapDrawCall(BackgroundLightmap, Vector2.Zero, LightmapScale); bb.Add(dc); } } else { var dc = new BitmapDrawCall(Background, Vector2.Zero); var material = LightmapMaterials.Get(LightmapMaterials.WorldSpaceLightmappedBitmap, blendState: BlendState.AlphaBlend); using (var bb = BitmapBatch.New(frame, 55, material)) { dc.Textures = new TextureSet(Background, BackgroundLightmap); dc.SortKey = 0; bb.Add(dc); } ParticleRenderer.Draw(frame, 56); using (var bb = BitmapBatch.New(frame, 57, material)) { dc.Textures = new TextureSet(Foreground, ForegroundLightmap); dc.SortKey = 1; bb.Add(dc); } } if (ShowOutlines || (Dragging != null)) { BackgroundRenderer.RenderOutlines(frame, 59, true); } }