/// <summary> /// Update the 6-sides of the cube map using a single pass via Geometry shader instancing with the provided context /// </summary> /// <param name="context">The context to render within</param> /// <param name="renderScene">The method that will render the scene</param> public void UpdateSinglePass(DeviceContext context, Action<DeviceContext, Matrix, Matrix, RenderTargetView, DepthStencilView, DynamicCubeMap> renderScene) { // Don't render the reflector itself if (Reflector != null) { Reflector.Show = false; } // Prepare pipeline context.OutputMerger.SetRenderTargets(EnvMapDSV, EnvMapRTV); context.Rasterizer.SetViewport(Viewport); // Prepare the view projections Matrix[] viewProjections = new Matrix[6]; for (var i = 0; i < 6; i++) viewProjections[i] = Matrix.Transpose(Cameras[i].View * Cameras[i].Projection); // Update per env map buffer with the ViewProjections context.UpdateSubresource(viewProjections, PerEnvMapBuffer); // Assign the per environment map buffer to the GS stage at slot 4 context.GeometryShader.SetConstantBuffer(4, PerEnvMapBuffer); // Render the scene using the view, projection, RTV and DSV renderScene(context, Cameras[0].View, Cameras[0].Projection, EnvMapRTV, EnvMapDSV, this); // Unbind the RTV and DSV context.OutputMerger.ResetTargets(); // Prepare the SRV mip levels context.GenerateMips(EnvMapSRV); // Re-enable the Reflector renderer if (Reflector != null) { Reflector.Show = true; } }
private void UpdateCubeFace(DeviceContext context, int index, Action<DeviceContext, Matrix, Matrix, RenderTargetView, DepthStencilView, DynamicCubeMap> renderScene) { // Prepare pipeline context.ClearState(); context.OutputMerger.SetRenderTargets(EnvMapDSVs[index], EnvMapRTVs[index]); context.Rasterizer.SetViewport(Viewport); // Render the scene using the view, projection, RTV and DSV of this cube face renderScene(context, Cameras[index].View, Cameras[index].Projection, EnvMapRTVs[index], EnvMapDSVs[index], this); // Unbind the RTV and DSV context.OutputMerger.ResetTargets(); // Prepare the SRV mip levels context.GenerateMips(EnvMapSRV); }
/// <summary> /// Update the 6-sides of the cube map using a single pass via Geometry shader instancing with the provided context /// </summary> /// <param name="context">The context to render within</param> /// <param name="renderScene">The method that will render the scene</param> public void UpdateSinglePass(DeviceContext context, Action<DeviceContext, Matrix, Matrix, RenderTargetView, DepthStencilView, DualParaboloidMap> renderScene) { // Don't render the reflector itself if (Reflector != null) { Reflector.Show = false; } // Prepare pipeline context.OutputMerger.SetRenderTargets(EnvMapDSV, EnvMapRTV); context.Rasterizer.SetViewport(Viewport); // Update perCubeMap with the ViewProjections PerEnvMap pem = this.DualMapView; pem.View.Transpose(); // Must transpose the matrix for HLSL context.UpdateSubresource(ref pem, PerEnvMapBuffer); // Assign the per dual map buffer to the VS and PS stages at slot 4 context.VertexShader.SetConstantBuffer(4, PerEnvMapBuffer); context.PixelShader.SetConstantBuffer(4, PerEnvMapBuffer); // Render the scene using the view, projection, RTV and DSV // Note that we use an identity matrix for the projection! renderScene(context, this.DualMapView.View, Matrix.Identity, EnvMapRTV, EnvMapDSV, this); // Unbind the RTV and DSV context.OutputMerger.ResetTargets(); // Prepare the SRV mip levels context.GenerateMips(EnvMapSRV); // Re-enable the Reflector renderer if (Reflector != null) { Reflector.Show = true; } }