public void TestDirectionalLightAccumulation() { //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 DirectionalLightRenderer(game, filledGBuffer.GBuffer); game.GameLoopEvent += delegate { filledGBuffer.DrawUpdatedGBuffer(); game.SetBackbuffer(); if (game.Keyboard.IsKeyDown(Key.C)) { game.SpectaterCamera.Enabled = false; var mat = Matrix.RotationY(game.Mouse.RelativeX * game.Elapsed * 5) * Matrix.RotationX(game.Mouse.RelativeY * game.Elapsed * 5); light.LightDirection = Vector3.TransformNormal(light.LightDirection, mat); } else { game.SpectaterCamera.Enabled = true; } if (game.Keyboard.IsKeyDown(Key.I)) { GBufferTest.DrawGBuffer(game, filledGBuffer.GBuffer); } else { light.Draw(); } }; game.Run(); }
public TestCombineFinalClass(DX11Game game) { this.game = game; var device = game.Device; context = device.ImmediateContext; FilledGBuffer = new TestFilledGBuffer(game, 800, 600); spot = new SpotLightRenderer(game, FilledGBuffer.GBuffer); point = new PointLightRenderer(game, FilledGBuffer.GBuffer); directional = new DirectionalLightRenderer(game, FilledGBuffer.GBuffer); state = 0; combineFinal = new CombineFinalRenderer(game, FilledGBuffer.GBuffer); var desc = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.R16G16B16A16_Float, Width = FilledGBuffer.GBuffer.Width, Height = FilledGBuffer.GBuffer.Height, ArraySize = 1, SampleDescription = new SampleDescription(1, 0), MipLevels = 1 }; hdrImage = new Texture2D(device, desc); hdrImageRTV = new RenderTargetView(device, hdrImage); hdrImageRV = new ShaderResourceView(device, hdrImage); }
private void updateDirectionalShadows(DirectionalLightRenderer r, FrustumCullerView[] views) { var mainCamera = game.Camera; if (DEBUG_SeperateCullCamera != null) { mainCamera = DEBUG_SeperateCullCamera; } int num = 0; r.UpdateShadowmap(delegate(OrthographicCamera lightCamera) { var view = views[0]; num++; var oldCam = game.Camera; game.Camera = lightCamera; //TODO: fix culling+removing of elements //view.UpdateVisibility(lightCamera.ViewProjection); //setMeshRendererVisibles(view); meshesRenderer.DrawShadowCastersDepth(); game.Camera = oldCam; }, mainCamera); }
private void setDirectionalLightToRenderer(DirectionalLightRenderer r, DirectionalLight l) { r.LightDirection = l.LightDirection; r.Color = l.Color; r.ShadowsEnabled = l.ShadowsEnabled; }
public DeferredRenderer(DX11Game game) { this.game = game; var device = game.Device; context = device.ImmediateContext; screenWidth = game.Form.Form.ClientSize.Width; screenHeight = game.Form.Form.ClientSize.Height; int width = screenWidth; int height = screenHeight; gBuffer = new GBuffer(game.Device, width, height); texturePool = new TexturePool(game); meshesRenderer = new DeferredMeshesRenderer(game, gBuffer, TexturePool); directionalLightRenderer = new DirectionalLightRenderer(game, GBuffer); spotLightRenderer = new SpotLightRenderer(game, GBuffer); pointLightRenderer = new PointLightRenderer(game, GBuffer); combineFinalRenderer = new CombineFinalRenderer(game, GBuffer); var desc = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.R16G16B16A16_Float, Width = screenWidth, Height = screenHeight, ArraySize = 1, SampleDescription = new SampleDescription(1, 0), MipLevels = 1 }; hdrImage = new Texture2D(device, desc); hdrImageRtv = new RenderTargetView(device, hdrImage); hdrImageRV = new ShaderResourceView(device, hdrImage); calculater = new AverageLuminanceCalculater(game, hdrImageRV); toneMap = new ToneMapRenderer(game); var tempDesc = new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Read, Format = Format.R32_Float, Height = 1, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Staging, Width = 1 }; tempTex = new Texture2D(device, tempDesc); ssao = new HorizonSSAORenderer(game, screenWidth, screenHeight); Vector3 radius = new Vector3(500, 1000, 500); frustumCuller = new FrustumCuller(new BoundingBox(-radius, radius), 1); gbufferView = frustumCuller.CreateView(); meshesRenderer.Culler = frustumCuller; Texture2D skyColorTexture;// = Texture2D.FromFile(game.Device, TWDir.GameData.CreateSubdirectory("Core") + "\\skyColor.bmp"); var strm = new DataStream(16 * 4, true, true); var multiplier = 2; strm.Write(new Half4(new Half(135f / 255f * multiplier), new Half(206f / 255f * multiplier), new Half(235 / 255f * multiplier), new Half(1))); strm.Position = 0; var dataRectangle = new DataRectangle(16 * 4, strm); skyColorTexture = new Texture2D(game.Device, new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = Format.R16G16B16A16_Float, Height = 1, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, Width = 1 }, dataRectangle); skyColorRV = new ShaderResourceView(game.Device, skyColorTexture); postProcessRT1 = CreateBackbufferLikeRT(); postProcessRT2 = CreateBackbufferLikeRT(); fogRenderer = new FogEffect(game); backgroundDepthStencilState = DepthStencilState.FromDescription(game.Device, new DepthStencilStateDescription() { IsDepthEnabled = true, DepthComparison = Comparison.LessEqual, DepthWriteMask = DepthWriteMask.Zero, }); lineManager = new LineManager3D(game.Device); updateRasterizerState(); }
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 TestDirectionalLightShadowing() { var game = new DX11Game(); game.InitDirectX(); var device = game.Device; var context = device.ImmediateContext; var filledGBuffer = new TestFilledGBuffer(game, 800, 600); var light = new DirectionalLightRenderer(game, filledGBuffer.GBuffer); light.ShadowsEnabled = true; var toggle = false; game.GameLoopEvent += delegate { filledGBuffer.DrawUpdatedGBuffer(); light.UpdateShadowmap(delegate(OrthographicCamera lightCamera) { game.Camera = lightCamera; filledGBuffer.Draw(); game.Camera = game.SpectaterCamera; }, game.SpectaterCamera); game.SetBackbuffer(); if (game.Keyboard.IsKeyPressed(Key.C)) { toggle = !toggle; } if (toggle) { light.LightDirection = game.SpectaterCamera.CameraDirection; } if (game.Keyboard.IsKeyDown(Key.I)) { GBufferTest.DrawGBuffer(game, filledGBuffer.GBuffer); } else { light.Draw(); game.TextureRenderer.Draw(light.CSMRenderer.ShadowMapRV, new Vector2(10, 10), new Vector2(590, 200)); for (int i = 0; i < 6; i++) { //game.LineManager3D.AddViewFrustum(light.LightCameras[i].ViewProjection, //new Color4(0, 1, 0)); } } }; game.Run(); }