public GlobalIlluminationRenderer(Device device, Vector3 sceneBoundsMin, Vector3 sceneBoundsMax) { m_CubeObject = TextureObject.CreateCubeTexture(device, 128, 128, 1, Format.R16G16B16A16_Float, false, true); m_CubeObjectDepth = TextureObject.CreateCubeTexture(device, 128, 128, 1, Format.R32_Typeless, true, true); if (System.IO.File.Exists("textures\\givolumer.dds")) { m_GIVolumeR = TextureObject.CreateTexture3DFromFile(device, VolumeSizeX, VolumeSizeY, VolumeSizeZ, Format.R16G16B16A16_Float, "textures\\givolumer.dds"); m_GIVolumeG = TextureObject.CreateTexture3DFromFile(device, VolumeSizeX, VolumeSizeY, VolumeSizeZ, Format.R16G16B16A16_Float, "textures\\givolumeg.dds"); m_GIVolumeB = TextureObject.CreateTexture3DFromFile(device, VolumeSizeX, VolumeSizeY, VolumeSizeZ, Format.R16G16B16A16_Float, "textures\\givolumeb.dds"); } else { m_GIVolumeR = TextureObject.CreateTexture3D(device, VolumeSizeX, VolumeSizeY, VolumeSizeZ, Format.R16G16B16A16_Float); m_GIVolumeG = TextureObject.CreateTexture3D(device, VolumeSizeX, VolumeSizeY, VolumeSizeZ, Format.R16G16B16A16_Float); m_GIVolumeB = TextureObject.CreateTexture3D(device, VolumeSizeX, VolumeSizeY, VolumeSizeZ, Format.R16G16B16A16_Float); } m_InitialSHSet = RenderTargetSet.CreateRenderTargetSet(device, 128, 128, Format.R16G16B16A16_Float, 3, false); m_Downsampled16x16SHSetR = RenderTargetSet.CreateRenderTargetSet(device, 32, 32, Format.R16G16B16A16_Float, 1, false); m_Downsampled16x16SHSetG = RenderTargetSet.CreateRenderTargetSet(device, 32, 32, Format.R16G16B16A16_Float, 1, false); m_Downsampled16x16SHSetB = RenderTargetSet.CreateRenderTargetSet(device, 32, 32, Format.R16G16B16A16_Float, 1, false); m_Downsampled4x4SHSetR = RenderTargetSet.CreateRenderTargetSet(device, 8, 8, Format.R16G16B16A16_Float, 1, false); m_Downsampled4x4SHSetG = RenderTargetSet.CreateRenderTargetSet(device, 8, 8, Format.R16G16B16A16_Float, 1, false); m_Downsampled4x4SHSetB = RenderTargetSet.CreateRenderTargetSet(device, 8, 8, Format.R16G16B16A16_Float, 1, false); m_GIConstantBuffer = ShaderManager.CreateConstantBufferInstance("GIConstantBuffer", device); m_SceneBoundsMin = sceneBoundsMin; m_SceneBoundsMax = sceneBoundsMax; }
public SSAOEffectPass(SlimDX.Direct3D11.Device device, int resolutionX, int resolutionY) { m_RTDescriptor = new RenderTargetSet.RenderTargetDescriptor() { m_Format = Format.R8G8B8A8_UNorm, m_HasDepth = false, m_NumSurfaces = 1, m_Height = resolutionY, m_Width = resolutionX }; TemporalSurfaceManager.InitializeRenderTarget("SSAO", m_RTDescriptor); m_SSAOBuffer = ShaderManager.CreateConstantBufferInstance("SSAOBuffer", device); }
public static void Initialize(Device device) { m_CurrentViewportBuffer = ShaderManager.CreateConstantBufferInstance("CurrentViewport", device); }
public void Initialize(Device device, Form form, Panel panel, int resolutionX, int resolutionY) { m_ResolutionX = resolutionX; m_ResolutionY = resolutionY; m_FullResDescriptor = new RenderTargetSet.RenderTargetDescriptor() { m_Format = Format.R16G16B16A16_Float, m_HasDepth = false, m_NumSurfaces = 1, m_Height = resolutionY, m_Width = resolutionX }; m_FullResAndDepthDescriptor = new RenderTargetSet.RenderTargetDescriptor() { m_Format = Format.R16G16B16A16_Float, m_HasDepth = true, m_NumSurfaces = 1, m_Height = resolutionY, m_Width = resolutionX }; m_ResolvedColorDescriptor = new RenderTargetSet.RenderTargetDescriptor() { m_Format = Format.R8G8B8A8_UNorm, m_HasDepth = false, m_NumSurfaces = 1, m_Height = resolutionY, m_Width = resolutionX }; m_LinearDepthDescriptor = new RenderTargetSet.RenderTargetDescriptor() { m_Format = Format.R32_Float, m_HasDepth = false, m_NumSurfaces = 1, m_Height = resolutionY, m_Width = resolutionX }; m_SSAODescriptor = new RenderTargetSet.RenderTargetDescriptor() { m_Format = Format.R8_UNorm, m_HasDepth = false, m_NumSurfaces = 1, m_Height = resolutionY, m_Width = resolutionX }; m_SimpleSceneWrapper.Initialize(device, "sponza"); TemporalSurfaceManager.InitializeRenderTarget("ResolvedColor", m_ResolvedColorDescriptor); TemporalSurfaceManager.InitializeRenderTarget("MotionVectors", new RenderTargetSet.RenderTargetDescriptor() { m_Format = Format.R16G16_Float, m_HasDepth = false, m_NumSurfaces = 1, m_Height = resolutionY, m_Width = resolutionX }); m_PostEffectsConstantBuffer = ShaderManager.CreateConstantBufferInstance("PostEffects", device); m_ForwardPassBuffer = ShaderManager.CreateConstantBufferInstance("ForwardPassBuffer", device); m_ViewportConstantBuffer = ShaderManager.CreateConstantBufferInstance("GlobalViewportBuffer", device); m_CurrentViewportBuffer = ShaderManager.CreateConstantBufferInstance("CurrentViewport", device); Vector3 min, max; m_SimpleSceneWrapper.GetSceneBounds(out min, out max); m_GIRenderer = new GlobalIlluminationRenderer(device, min, max); // Init passes m_ScatterDOFPass = new ScatterDOFPass(); m_ScatterDOFPass.Initialize(device, resolutionX, resolutionY); m_ResolveHDRPass = new ResolveHDRPass(); m_ResolveMotionVectorsPass = new ResolveMotionVectorsPass(); m_ResolveTemporalPass = new ResolveTemporalMotionBasedPass(); m_FxaaPass = new FxaaPass(); m_SSAOPass = new SSAOEffectPass(device, resolutionX, resolutionY); m_LuminanceCalculations = new LuminanceCalculations(device, resolutionX, resolutionY); m_ShadowEVSMGenerator = new ShadowEVSMGenerator(); m_VolumetricFog = new VolumetricFog(); m_VolumetricFog.Initialize(device); m_StartTime = DateTime.Now; m_ViewportCamera.BindToInput(form, panel); POISSON_SAMPLES = new float[POISSON_SAMPLE_NUM * 2] { 0.655897408497f, 0.95575996511f, 0.944576716895f, 0.455478901428f, 0.203683172197f, 0.0177149729234f, 0.383628747896f, 0.379284571357f, 0.945473563065f, 0.779431977074f, 0.570420562284f, 0.576156483093f, 0.674354533289f, 0.286346887653f, 0.347776132801f, 0.734938485879f, }; }
static void Main() { m_FrameNumber = 0; m_Time = 0.0f; Device device; SwapChain swapChain; //var form = new RenderForm("CSharpRenderer"); var form = new CSharpRendererMainForm(); var panel = form.GetRenderingPanel(); form.ClientSize = new System.Drawing.Size(ResolutionX, ResolutionY); var description = new SwapChainDescription() { BufferCount = 2, Usage = Usage.RenderTargetOutput, OutputHandle = panel.Handle, IsWindowed = true, ModeDescription = new ModeDescription(ResolutionX, ResolutionY, new Rational(60, 1), Format.R8G8B8A8_UNorm), SampleDescription = new SampleDescription(1, 0), Flags = SwapChainFlags.AllowModeSwitch, SwapEffect = SwapEffect.Discard }; Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, description, out device, out swapChain); var swapChainResource = Resource.FromSwapChain <Texture2D>(swapChain, 0); SamplerStates.Initialize(device); ShaderManager.Initialize(device); GPUProfiler.Initialize(device); ContextHelper.Initialize(device); RenderTargetManager.Initialize(device); PostEffectHelper.Initialize(device, ResolutionX, ResolutionY); CubemapRenderHelper.Initialize(device); PerlinNoiseRenderHelper.Initialize(device, device.ImmediateContext); LightingLUTHelper.Initialize(device, device.ImmediateContext); DebugManager.Initialize(device, ResolutionX, ResolutionY); InitializeControls(form); Scene scene = new Scene(); scene.Initialize(device, form, panel, ResolutionX, ResolutionY); var resolvedRenderTarget = RenderTargetSet.CreateRenderTargetSet(device, ResolutionX, ResolutionY, Format.R8G8B8A8_UNorm, 1, false); RenderTargetSet.BindNull(device.ImmediateContext); // setting a viewport is required if you want to actually see anything var context = device.ImmediateContext; // prevent DXGI handling of alt+enter, which doesn't work properly with Winforms using (var factory = swapChain.GetParent <Factory>()) factory.SetWindowAssociation(panel.Handle, WindowAssociationFlags.IgnoreAltEnter); int counter = 0; Dictionary <string, double> profilers; profilers = new Dictionary <String, double>(); DateTime now = DateTime.Now; CustomConstantBufferInstance globalFrameConstantBuffer = ShaderManager.CreateConstantBufferInstance("GlobalFrameBuffer", device); MessagePump.Run(form, () => { TemporalSurfaceManager.UpdateTemporalSurfaces(); if (ShaderManager.UpdateShaderManager(device)) { InitializeControls(form); } GPUProfiler.BeginFrameProfiling(context); double timeDelta = (DateTime.Now - now).TotalMilliseconds; if (!form.GetFreezeTime()) { m_Time += timeDelta / 1000.0; m_FrameNumber++; } UpdateGlobalConstantBuffer(context, globalFrameConstantBuffer, form); scene.RenderFrame(context, timeDelta, resolvedRenderTarget); now = DateTime.Now; DebugManager.PresentDebug(context, resolvedRenderTarget); context.CopyResource(resolvedRenderTarget.m_RenderTargets[0].m_TextureObject2D, swapChainResource); GPUProfiler.EndFrameProfiling(context); swapChain.Present(0, PresentFlags.None); context.PixelShader.SetShaderResource(null, 0); if (GPUProfiler.m_CurrentFrameProfilerTree != null) { Action <GPUProfiler.ProfilerTreeMember, String> processLevel = null; processLevel = (GPUProfiler.ProfilerTreeMember treeMember, String level) => { string finalName = level + treeMember.m_Name; if (profilers.ContainsKey(finalName)) { profilers[finalName] += treeMember.m_Time; } else { profilers.Add(finalName, treeMember.m_Time); } foreach (var v in treeMember.m_ChildMembers) { processLevel(v, level + "_"); } }; processLevel(GPUProfiler.m_CurrentFrameProfilerTree, ""); } CheckAndUpdateDebugUI(context, form); if (++counter == 10) { UpdateControls(); DataGridView dataGridView = form.GetDataGridView(); dataGridView.Rows.Clear(); foreach (var profilerEntry in profilers) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(dataGridView); row.Cells[0].Value = profilerEntry.Key; row.Cells[1].Value = String.Format("{0}", Math.Round(profilerEntry.Value * 100.0 / 10.0) / 100.0); dataGridView.Rows.Add(row); } profilers.Clear(); counter = 0; } else { // avoid 2ms frame times... System.Threading.Thread.Sleep(10); } }); }
public void Initialize(Device device, Form form, Panel panel, int resolutionX, int resolutionY) { m_ResolutionX = resolutionX; m_ResolutionY = resolutionY; m_FullResDescriptor = new RenderTargetSet.RenderTargetDescriptor() { m_Format = Format.R16G16B16A16_Float, m_HasDepth = false, m_NumSurfaces = 1, m_Height = resolutionY, m_Width = resolutionX }; m_FullResAndDepthDescriptor = new RenderTargetSet.RenderTargetDescriptor() { m_Format = Format.R16G16B16A16_Float, m_HasDepth = true, m_NumSurfaces = 1, m_Height = resolutionY, m_Width = resolutionX }; m_ResolvedColorDescriptor = new RenderTargetSet.RenderTargetDescriptor() { m_Format = Format.R8G8B8A8_UNorm, m_HasDepth = false, m_NumSurfaces = 1, m_Height = resolutionY, m_Width = resolutionX }; m_LinearDepthDescriptor = new RenderTargetSet.RenderTargetDescriptor() { m_Format = Format.R32_Float, m_HasDepth = false, m_NumSurfaces = 1, m_Height = resolutionY, m_Width = resolutionX }; m_SSAODescriptor = new RenderTargetSet.RenderTargetDescriptor() { m_Format = Format.R8_UNorm, m_HasDepth = false, m_NumSurfaces = 1, m_Height = resolutionY, m_Width = resolutionX }; m_SimpleSceneWrapper.Initialize(device, "sponza"); TemporalSurfaceManager.InitializeRenderTarget("ResolvedColor", m_ResolvedColorDescriptor); TemporalSurfaceManager.InitializeRenderTarget("MotionVectors", new RenderTargetSet.RenderTargetDescriptor() { m_Format = Format.R16G16_Float, m_HasDepth = false, m_NumSurfaces = 1, m_Height = resolutionY, m_Width = resolutionX }); m_PostEffectsConstantBuffer = ShaderManager.CreateConstantBufferInstance("PostEffects", device); m_ForwardPassBuffer = ShaderManager.CreateConstantBufferInstance("ForwardPassBuffer", device); m_ViewportConstantBuffer = ShaderManager.CreateConstantBufferInstance("GlobalViewportBuffer", device); m_CurrentViewportBuffer = ShaderManager.CreateConstantBufferInstance("CurrentViewport", device); Vector3 min, max; m_SimpleSceneWrapper.GetSceneBounds(out min, out max); m_GIRenderer = new GlobalIlluminationRenderer(device, min, max); // Init passes m_ScatterDOFPass = new ScatterDOFPass(); m_ScatterDOFPass.Initialize(device, resolutionX, resolutionY); m_ResolveHDRPass = new ResolveHDRPass(); m_ResolveMotionVectorsPass = new ResolveMotionVectorsPass(); m_ResolveTemporalPass = new ResolveTemporalMotionBasedPass(); m_FxaaPass = new FxaaPass(); m_SSAOPass = new SSAOEffectPass(device, resolutionX, resolutionY); m_LuminanceCalculations = new LuminanceCalculations(device, resolutionX, resolutionY); m_ShadowEVSMGenerator = new ShadowEVSMGenerator(); m_ViewportCamera.BindToInput(form, panel); }