public DirectionalLightRenderer(DX11Game game, GBuffer gBuffer) { this.game = game; this.gBuffer = gBuffer; var device = game.Device; context = device.ImmediateContext; shadowsShader = BasicShader.LoadAutoreload(game, new System.IO.FileInfo( CompiledShaderCache.Current.RootShaderPath + "Deferred\\DirectionalLight.fx")); shadowsShader.SetTechnique("Technique0"); noShadowsShader = BasicShader.LoadAutoreload(game, new System.IO.FileInfo( CompiledShaderCache.Current.RootShaderPath + "Deferred\\DirectionalLight.fx"), null, new[] { new ShaderMacro("DISABLE_SHADOWS") }); noShadowsShader.SetTechnique("Technique0"); quad = new FullScreenQuad(device); layout = FullScreenQuad.CreateInputLayout(device, shadowsShader.GetCurrentPass(0)); LightDirection = Vector3.Normalize(new Vector3(1, 2, 1)); Color = new Vector3(1, 1, 0.9f); CSMRenderer = new CSM.CSMRenderer(game); }
public CombineFinalRenderer(DX11Game game, GBuffer gBuffer) { this.game = game; this.gBuffer = gBuffer; var device = game.Device; context = device.ImmediateContext; shader = BasicShader.LoadAutoreload(game, new System.IO.FileInfo( CompiledShaderCache.Current.RootShaderPath + "Deferred\\CombineFinal.fx")); shader.SetTechnique("Technique0"); quad = new FullScreenQuad(device); layout = FullScreenQuad.CreateInputLayout(device, shader.GetCurrentPass(0)); var desc = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.R16G16B16A16_Float, Width = gBuffer.Width, Height = gBuffer.Height, ArraySize = 1, SampleDescription = new SampleDescription(1, 0), MipLevels = 1 }; lightAccumulationMap = new Texture2D(device, desc); lightAccumulationRTV = new RenderTargetView(device, lightAccumulationMap); LightAccumulationRV = new ShaderResourceView(device, lightAccumulationMap); 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; blendState = BlendState.FromDescription(device, bsDesc); }
public void PostProcessFog(ShaderResourceView input, GBuffer gBuffer, RenderTargetView target) { global::SlimDX.Performance.BeginEvent(new Color4(), "Fog!"); context.OutputMerger.SetTargets(target); shader.Effect.GetVariableByName("inputMap").AsResource().SetResource(input); shader.Effect.GetVariableByName("InvertProjection").AsMatrix().SetMatrix( Matrix.Invert(game.Camera.Projection)); gBuffer.SetToShader(shader); shader.Apply(); quad.Draw(layout); shader.Effect.GetVariableByName("inputMap").AsResource().SetResource(null); shader.Apply(); global::SlimDX.Performance.EndEvent(); }
public PointLightRenderer(DX11Game game, GBuffer gBuffer) { this.game = game; this.gBuffer = gBuffer; var device = game.Device; context = device.ImmediateContext; reloadShader(game); quad = new FullScreenQuad(device); layout = FullScreenQuad.CreateInputLayout(device, noShadowsShader.GetCurrentPass(0)); LightPosition = new Vector3(0, 6, 0); LightRadius = 6; LightIntensity = 1; Color = new Vector3(1, 1, 0.9f); //var rasterizerInside = RasterizerState.FromDescription(device, new RasterizerStateDescription // { // CullMode = CullMode.Front // }); //var rasterizerOutside = RasterizerState.FromDescription(device, new RasterizerStateDescription //{ // CullMode = CullMode.Back //}); var shadowCubeMap = new Texture2D(device, new Texture2DDescription { ArraySize = 6, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = global::SlimDX.DXGI.Format.R32_Typeless, Height = shadowMapSize, Width = shadowMapSize, MipLevels = 1, OptionFlags = ResourceOptionFlags.TextureCube, SampleDescription = new global::SlimDX.DXGI.SampleDescription(1, 0), Usage = ResourceUsage.Default }); depthStencilViewFaces = new DepthStencilView[6]; shadowCubeMapRVs = new ShaderResourceView[6]; LightCameras = new CustomCamera[6]; for (int i = 0; i < 6; i++) { depthStencilViewFaces[i] = new DepthStencilView(device, shadowCubeMap, new DepthStencilViewDescription { Dimension = DepthStencilViewDimension .Texture2DArray, ArraySize = 1, FirstArraySlice = i, Flags = DepthStencilViewFlags .None, Format = global::SlimDX.DXGI.Format. D32_Float, MipSlice = 0 }); //ShadowCubeMapRVs[i] = new ShaderResourceView(device, shadowCubeMap, new ShaderResourceViewDescription //{ // Dimension = ShaderResourceViewDimension.Texture2D, // ArraySize = 1, // FirstArraySlice = i, // Format = SlimDX.DXGI.Format.R32_Float, // MipLevels = 1, // MostDetailedMip = 0 //}); LightCameras[i] = new CustomCamera(); } ShadowCubeMapRv = new ShaderResourceView(device, shadowCubeMap, new ShaderResourceViewDescription { Dimension = ShaderResourceViewDimension.TextureCube, MostDetailedMip = 0, MipLevels = 1, Format = global::SlimDX.DXGI.Format.R32_Float }); }
public SpotLightRenderer(DX11Game game, GBuffer gBuffer) { this.game = game; this.gBuffer = gBuffer; var device = game.Device; context = device.ImmediateContext; reloadShader(game); quad = new FullScreenQuad(device); layout = FullScreenQuad.CreateInputLayout(device, noShadowsShader.GetCurrentPass(0)); LightPosition = new Vector3(0, 6, 0); LightRadius = 6; LightIntensity = 1; SpotDirection = MathHelper.Down; SpotLightAngle = MathHelper.ToRadians(30); SpotDecayExponent = 1; Color = new Vector3(1, 1, 0.9f); shadowMap = new Texture2D(device, new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = global::SlimDX.DXGI.Format.R32_Typeless, Width = shadowMapSize, Height = shadowMapSize, MipLevels = 1, Usage = ResourceUsage.Default, SampleDescription = new global::SlimDX.DXGI.SampleDescription(1, 0) }); shadowMapRV = new ShaderResourceView(device, shadowMap, new ShaderResourceViewDescription { Dimension = ShaderResourceViewDimension.Texture2D, Format = global::SlimDX.DXGI.Format.R32_Float, MipLevels = 1, MostDetailedMip = 0 }); shadowMapDSV = new DepthStencilView(device, shadowMap, new DepthStencilViewDescription { Dimension = DepthStencilViewDimension.Texture2D, Format = global::SlimDX.DXGI.Format.D32_Float }); LightCamera = new CustomCamera(); //var rasterizerInside = RasterizerState.FromDescription(device, new RasterizerStateDescription // { // CullMode = CullMode.Front // }); //var rasterizerOutside = RasterizerState.FromDescription(device, new RasterizerStateDescription //{ // CullMode = CullMode.Back //}); }