public void TestPointLightAccumulation() { //TODO: add a way to show the specular in the alpha channel var game = new DX11Game(); game.InitDirectX(); var device = game.Device; var context = device.ImmediateContext; var filledGBuffer = new TestFilledGBuffer(game, 800, 600); var light = new PointLightRenderer(game, filledGBuffer.GBuffer); var toggle = false; game.GameLoopEvent += delegate { filledGBuffer.DrawUpdatedGBuffer(); game.SetBackbuffer(); if (game.Keyboard.IsKeyPressed(Key.C)) { toggle = !toggle; } if (toggle) { light.LightPosition = game.SpectaterCamera.CameraPosition; } if (game.Keyboard.IsKeyDown(Key.I)) { GBufferTest.DrawGBuffer(game, filledGBuffer.GBuffer); } else { light.Draw(); } }; game.Run(); light.Dispose(); filledGBuffer.Dispose(); }
public void Render() { angle += MathHelper.Pi * game.Elapsed; point.LightPosition = new Vector3((float)Math.Sin(angle), (float)Math.Cos(angle), -2); ctx.ClearState(); combineFinal.SetLightAccumulationStates(); combineFinal.ClearLightAccumulation(); point.Draw(); ctx.ClearState(); game.SetBackbuffer(); ctx.Rasterizer.SetViewports(new Viewport(400, 300, 400, 300)); combineFinal.DrawCombined(); game.SetBackbuffer(); GBufferTest.DrawGBuffer(game, buffer); }
public void drawMeshTest(IMesh mesh, Matrix worldMatrix) { var game = createGame(); var pool = createTexturePool(game); var worldMesh = new WorldMesh { Mesh = mesh, WorldMatrix = worldMatrix }; var meshes = new MeshesRenderer(new RendererResourcePool(new MeshRenderDataFactory(game, null, pool), pool, game), game); var ctx = game.Device.ImmediateContext; var gBuffer = createGBuffer(game); var scene = new RenderingTestsHelper.SimpleLightedScene(game, gBuffer); var list = new List <WorldMesh>(); list.Add(worldMesh); var buffer = gBuffer; ctx = game.Device.ImmediateContext; // Non-related init code var point = new PointLightRenderer(game, buffer); point.LightRadius = 3; point.LightIntensity = 1; point.ShadowsEnabled = false; var angle = 0f; var combineFinal = new CombineFinalRenderer(game, buffer); var raster = new RasterizerStateDescription() { CullMode = CullMode.Front, FillMode = FillMode.Solid }; var state = RasterizerState.FromDescription(game.Device, raster); point.LightRadius = 10; game.GameLoopEvent += delegate { ctx.ClearState(); ctx.Rasterizer.State = state; gBuffer.Clear(); gBuffer.SetTargetsToOutputMerger(); meshes.DrawMeshes(list, game.Camera); angle += MathHelper.Pi * game.Elapsed; var alpha = 0.99f * game.Elapsed * 20000; var cam = game.Camera.ViewInverse.GetTranslation(); var diff = cam - point.LightPosition; diff.Normalize(); point.LightPosition += diff * game.Elapsed * 2;// new Vector3((float)Math.Sin(angle), (float)Math.Cos(angle), -2); ctx.ClearState(); combineFinal.SetLightAccumulationStates(); combineFinal.ClearLightAccumulation(); point.Draw(); ctx.ClearState(); game.SetBackbuffer(); ctx.Rasterizer.SetViewports(new Viewport(400, 300, 400, 300)); combineFinal.DrawCombined(); game.SetBackbuffer(); GBufferTest.DrawGBuffer(game, buffer); }; game.Run(); }
public void TestPointLightRendererShadowing() { var game = new DX11Game(); game.InitDirectX(); var device = game.Device; var context = device.ImmediateContext; var filledGBuffer = new TestFilledGBuffer(game, 800, 600); var light = new PointLightRenderer(game, filledGBuffer.GBuffer); light.LightRadius *= 2; light.ShadowsEnabled = true; var toggle = false; game.GameLoopEvent += delegate { filledGBuffer.DrawUpdatedGBuffer(); light.UpdateShadowMap(delegate(CustomCamera lightCamera) { game.Camera = lightCamera; filledGBuffer.Draw(); game.Camera = game.SpectaterCamera; }); game.SetBackbuffer(); if (game.Keyboard.IsKeyPressed(Key.C)) { toggle = !toggle; } if (toggle) { light.LightPosition = game.SpectaterCamera.CameraPosition; } if (game.Keyboard.IsKeyDown(Key.I)) { GBufferTest.DrawGBuffer(game, filledGBuffer.GBuffer); } else { light.Draw(); //game.TextureRenderer.Draw(light.ShadowCubeMapRv, new Vector2(10, 10), new Vector2(300, 300)); for (int i = 0; i < 6; i++) { game.LineManager3D.AddViewFrustum(light.LightCameras[i].ViewProjection, new Color4(0, 1, 0)); } } }; game.Run(); }
public void TestMultipleLightAccumulation() { //TODO: add a way to show the specular in the alpha channel var game = new DX11Game(); game.InitDirectX(); var device = game.Device; var context = device.ImmediateContext; var filledGBuffer = new TestFilledGBuffer(game, 800, 600); var spot = new SpotLightRenderer(game, filledGBuffer.GBuffer); var point = new PointLightRenderer(game, filledGBuffer.GBuffer); var directional = new DirectionalLightRenderer(game, filledGBuffer.GBuffer); var state = 0; var bsDesc = new BlendStateDescription(); var b = new RenderTargetBlendDescription(); b.BlendEnable = true; b.BlendOperation = BlendOperation.Add; b.BlendOperationAlpha = BlendOperation.Add; b.DestinationBlend = BlendOption.One; b.DestinationBlendAlpha = BlendOption.One; b.SourceBlend = BlendOption.One; b.SourceBlendAlpha = BlendOption.One; b.RenderTargetWriteMask = ColorWriteMaskFlags.All; bsDesc.RenderTargets[0] = b; var blendState = BlendState.FromDescription(device, bsDesc); var depthState = DepthStencilState.FromDescription(device, new DepthStencilStateDescription { IsDepthEnabled = false, IsStencilEnabled = false, }); game.GameLoopEvent += delegate { filledGBuffer.DrawUpdatedGBuffer(); game.SetBackbuffer(); if (game.Keyboard.IsKeyPressed(Key.D1)) { state = 0; } if (game.Keyboard.IsKeyPressed(Key.D2)) { state = 1; } if (game.Keyboard.IsKeyPressed(Key.D3)) { state = 2; } if (game.Keyboard.IsKeyPressed(Key.D4)) { state = 3; } switch (state) { case 0: break; case 1: directional.LightDirection = game.SpectaterCamera.CameraDirection; break; case 2: point.LightPosition = game.SpectaterCamera.CameraPosition; break; case 3: spot.LightPosition = game.SpectaterCamera.CameraPosition; spot.SpotDirection = game.SpectaterCamera.CameraDirection; break; } if (game.Keyboard.IsKeyDown(Key.I)) { GBufferTest.DrawGBuffer(game, filledGBuffer.GBuffer); } else { context.OutputMerger.DepthStencilState = depthState; directional.Draw(); context.OutputMerger.BlendState = blendState; spot.Draw(); point.Draw(); context.OutputMerger.BlendState = null; context.OutputMerger.DepthStencilState = null; } }; game.Run(); }
public void DrawUpdatedDeferredRendering() { FilledGBuffer.DrawUpdatedGBuffer(); if (game.Keyboard.IsKeyPressed(Key.D1)) { state = 0; } if (game.Keyboard.IsKeyPressed(Key.D2)) { state = 1; } if (game.Keyboard.IsKeyPressed(Key.D3)) { state = 2; } if (game.Keyboard.IsKeyPressed(Key.D4)) { state = 3; } switch (state) { case 0: break; case 1: directional.LightDirection = game.SpectaterCamera.CameraDirection; break; case 2: point.LightPosition = game.SpectaterCamera.CameraPosition; break; case 3: spot.LightPosition = game.SpectaterCamera.CameraPosition; spot.SpotDirection = game.SpectaterCamera.CameraDirection; break; } if (game.Keyboard.IsKeyDown(Key.I)) { context.ClearState(); game.SetBackbuffer(); GBufferTest.DrawGBuffer(game, FilledGBuffer.GBuffer); } else { combineFinal.ClearLightAccumulation(); combineFinal.SetLightAccumulationStates(); directional.Draw(); spot.Draw(); point.Draw(); context.ClearState(); game.SetBackbuffer(); // This is to set viewport, not sure this is correct context.OutputMerger.SetTargets(hdrImageRTV); DrawCombined(); } if (game.Keyboard.IsKeyPressed(Key.O)) { Resource.SaveTextureToFile(game.Device.ImmediateContext, hdrImage, ImageFileFormat.Dds, TWDir.Test.CreateSubdirectory("Deferred") + "\\HdrImage.dds"); } }