protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { m_device.Init(panelOutput.Handle, false, true); m_CB_Main = new ConstantBuffer <CB_Main>(m_device, 0); m_CB_Camera = new ConstantBuffer <CB_Camera>(m_device, 1); #if USE_SUBDIVIDED_CUBE m_Prim_Cube = BuildSubdividedCube(); m_Shader_renderScene = new Shader(m_device, new System.IO.FileInfo("./Shaders/RenderScene_Subdiv.hlsl"), VERTEX_FORMAT.P3N3G3B3T2, "VS", null, "PS"); #else m_Prim_Cube = BuildCube(); m_Shader_renderScene = new Shader(m_device, new System.IO.FileInfo("./Shaders/RenderScene.hlsl"), VERTEX_FORMAT.P3N3G3B3T2, "VS", null, "PS"); #endif m_Prim_Torus = BuildTorus(); m_Shader_renderSceneFinal = new Shader(m_device, new System.IO.FileInfo("./Shaders/RenderScene_Final.hlsl"), VERTEX_FORMAT.P3N3G3B3T2, "VS", null, "PS"); } catch (Exception _e) { MessageBox.Show(this, "Exception: " + _e.Message, "Curvature Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } m_startTime = DateTime.Now; // Initialize camera m_camera.CreatePerspectiveCamera(60.0f * (float)Math.PI / 180.0f, (float)panelOutput.Width / panelOutput.Height, 0.01f, 10.0f); m_manipulator.Attach(panelOutput, m_camera); m_manipulator.InitializeCamera(new float3(0, 0, 4.0f), float3.Zero, float3.UnitY); m_camera.CameraTransformChanged += m_camera_CameraTransformChanged; m_camera_CameraTransformChanged(null, EventArgs.Empty); Application.Idle += Application_Idle; }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { m_device.Init(outputPanel.Handle, false, true); m_shader_RenderDistanceField = new Shader(m_device, new System.IO.FileInfo("./Shaders/RenderDistanceField.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); m_CB_Main = new ConstantBuffer <CB_Main>(m_device, 0); m_CB_camera = new ConstantBuffer <CB_Camera>(m_device, 1); // Initialize camera m_camera.CreatePerspectiveCamera(CAMERA_FOV, (float)outputPanel.Width / outputPanel.Height, 0.1f, 100.0f); m_camera.CameraTransformChanged += m_camera_CameraTransformChanged; m_cameraManipulator.Attach(outputPanel, m_camera); // m_cameraManipulator.InitializeCamera( new float3( 0, 1.5f, 4.0f ), new float3( 0, 1.5f, 0.0f ), float3.UnitY ); m_cameraManipulator.InitializeCamera(new float3(0.0f, 2.73f, -8.0f), new float3(0.0f, 2.73f, 0.0f), float3.UnitY); // Build static voxel m_octree = new OctreeBuilder(m_device, 5.6f * new float3(-0.5f, 0.0f, -0.5f), 5.6f, 8); m_startTime = DateTime.Now; Application.Idle += Application_Idle; } catch (Exception _e) { MessageBox.Show(this, "An error occurred while initializing objects:\r\n\r\n" + _e.Message); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { m_Device.Init(panelOutput.Handle, false, true); } catch (Exception _e) { m_Device = null; MessageBox.Show("Failed to initialize DX device!\n\n" + _e.Message, "Project 4D Test", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } m_CS_Simulator = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("./Shaders/Simulator.hlsl")), "CS", null); m_CS_Project4D = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("./Shaders/Project4D.hlsl")), "CS", null); m_PS_Display = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("./Shaders/Display.hlsl")), VERTEX_FORMAT.T2, "VS", null, "PS", null); m_CB_Camera = new ConstantBuffer <CB_Camera>(m_Device, 1); m_CB_Camera4D = new ConstantBuffer <CB_Camera4D>(m_Device, 2); m_CB_Simulation = new ConstantBuffer <CB_Simulation>(m_Device, 3); { VertexT2[] Vertices = new VertexT2[4] { new VertexT2() { UV = new float2(-1.0f, 1.0f) }, new VertexT2() { UV = new float2(-1.0f, -1.0f) }, new VertexT2() { UV = new float2(1.0f, 1.0f) }, new VertexT2() { UV = new float2(1.0f, -1.0f) }, }; m_PrimQuad = new Primitive(m_Device, 4, VertexT2.FromArray(Vertices), null, Primitive.TOPOLOGY.TRIANGLE_STRIP, VERTEX_FORMAT.T2); } ///////////////////////////////////////////////////////////////////////////////////// // Create and fill the structured buffers with initial points lying on the surface of a hypersphere m_SB_Velocities4D = new StructuredBuffer <float4>(m_Device, POINTS_COUNT, true); m_SB_Points4D[0] = new StructuredBuffer <float4>(m_Device, POINTS_COUNT, true); m_SB_Points4D[1] = new StructuredBuffer <float4>(m_Device, POINTS_COUNT, true); m_SB_Points2D = new StructuredBuffer <float4>(m_Device, POINTS_COUNT, false); buttonInit_Click(buttonInit, EventArgs.Empty); ///////////////////////////////////////////////////////////////////////////////////// // Setup camera m_Camera.CreatePerspectiveCamera((float)(60.0 * Math.PI / 180.0), (float)panelOutput.Width / panelOutput.Height, 0.01f, 10.0f); m_Manipulator.Attach(panelOutput, m_Camera); m_Manipulator.InitializeCamera(new float3(0, 0, 2), new float3(0, 0, 0), float3.UnitY); }
public Form1() { InitializeComponent(); m_Device = new Device(); m_Device.Init(panel1.Handle, false, false); m_Shader_RenderCellPlanes = new Shader(m_Device, new System.IO.FileInfo("Shaders/RenderCellPlanes.hlsl"), VERTEX_FORMAT.T2, "VS", null, "PS", null); m_Shader_RenderCellMesh = new Shader(m_Device, new System.IO.FileInfo("Shaders/RenderCellMesh.hlsl"), VERTEX_FORMAT.P3N3, "VS", null, "PS", null); m_Shader_RenderCellMesh_Opaque = new Shader(m_Device, new System.IO.FileInfo("Shaders/RenderCellMesh_Opaque.hlsl"), VERTEX_FORMAT.P3N3, "VS", null, "PS", null); m_Shader_PostProcess = new Shader(m_Device, new System.IO.FileInfo("Shaders/PostProcess.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); m_Shader_PostProcess2 = new Shader(m_Device, new System.IO.FileInfo("Shaders/PostProcess.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); VertexT2[] Vertices = new VertexT2[4] { new VertexT2() { UV = new float2(0, 0) }, new VertexT2() { UV = new float2(0, 1) }, new VertexT2() { UV = new float2(1, 0) }, new VertexT2() { UV = new float2(1, 1) }, }; m_Prim_Quad = new Primitive(m_Device, 4, VertexT2.FromArray(Vertices), null, Primitive.TOPOLOGY.TRIANGLE_STRIP, VERTEX_FORMAT.T2); m_RT_WorldPositions[0] = new Texture2D(m_Device, (uint)panel1.Width, (uint)panel1.Height, 1, 1, PIXEL_FORMAT.RGBA32F, COMPONENT_FORMAT.AUTO, false, false, null); m_RT_WorldPositions[1] = new Texture2D(m_Device, (uint)panel1.Width, (uint)panel1.Height, 1, 1, PIXEL_FORMAT.RGBA32F, COMPONENT_FORMAT.AUTO, false, false, null); m_Device.Clear(m_RT_WorldPositions[0], float4.Zero); m_Device.Clear(m_RT_WorldPositions[1], float4.Zero); // Setup camera m_CB_Camera = new ConstantBuffer <CB_Camera>(m_Device, 0); m_CB_Mesh = new ConstantBuffer <CB_Mesh>(m_Device, 1); m_Camera.CreatePerspectiveCamera(120.0f * (float)Math.PI / 180.0f, (float)panel1.Width / panel1.Height, 0.01f, 100.0f); m_Camera.CameraTransformChanged += new EventHandler(Camera_CameraTransformChanged); m_CameraManipulator.Attach(panel1, m_Camera); m_CameraManipulator.InitializeCamera(-0.1f * float3.UnitZ, float3.Zero, float3.UnitY); // Initalize random neighbors integerTrackbarControlNeighborsCount_ValueChanged(integerTrackbarControlNeighborsCount, 0); Application.Idle += new EventHandler(Application_Idle); }
public ViewerForm(GeneratorForm _Owner) { InitializeComponent(); m_Owner = _Owner; // Setup camera m_Camera.CreatePerspectiveCamera((float)(60.0 * Math.PI / 180.0), (float)Width / Height, 0.01f, 100.0f); m_Manipulator.Attach(this, m_Camera); m_Manipulator.InitializeCamera(new float3(0, 1, 1), new float3(0, 0, 0), float3.UnitY); m_Camera.CameraTransformChanged += new EventHandler(Camera_CameraTransformChanged); m_Manipulator.EnableMouseAction += new CameraManipulator.EnableMouseActionEventHandler(m_Manipulator_EnableMouseAction); // Camera_CameraTransformChanged( m_Manipulator, EventArgs.Empty ); Application.Idle += new EventHandler(Application_Idle); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { m_device.Init(panelOutput.Handle, false, true); } catch (Exception _e) { m_device = null; MessageBox.Show("Failed to initialize DX device!\n\n" + _e.Message, "MSBRDF Test", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { // m_shader_Render = new Shader( m_device, new System.IO.FileInfo( "Shaders/Render.hlsl" ), VERTEX_FORMAT.Pt4, "VS", null, "PS", null ); m_shader_Render = new Shader(m_device, new System.IO.FileInfo("Shaders/RenderComplete.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); } catch (Exception _e) { MessageBox.Show("Shader failed to compile!\n\n" + _e.Message, "MSBRDF Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } uint W = (uint)panelOutput.Width; uint H = (uint)panelOutput.Height; m_CB_Global = new ConstantBuffer <CB_Global>(m_device, 0); m_CB_Camera = new ConstantBuffer <CB_Camera>(m_device, 1); m_CB_Render = new ConstantBuffer <CB_Render>(m_device, 2); BuildNoiseTextures(); BuildMSBRDF(new DirectoryInfo(@".\Tables\")); // Load cube map using (ImageUtility.ImagesMatrix I = new ImageUtility.ImagesMatrix()) { I.DDSLoadFile(new FileInfo("garage4_hd.dds")); m_tex_CubeMap = new Texture2D(m_device, I, ImageUtility.COMPONENT_FORMAT.AUTO); } // Setup camera m_camera.CreatePerspectiveCamera((float)(60.0 * Math.PI / 180.0), (float)panelOutput.Width / panelOutput.Height, 0.01f, 100.0f); m_manipulator.Attach(panelOutput, m_camera); m_manipulator.InitializeCamera(new float3(0, 1.5f, 2.0f), new float3(-0.4f, 0, 0.4f), float3.UnitY); // Start game time m_Ticks2Seconds = 1.0 / System.Diagnostics.Stopwatch.Frequency; m_StopWatch.Start(); m_StartGameTime = GetGameTime(); }
public Form1() { InitializeComponent(); // BuildKernelWeights(); try { m_device.Init(panelOutput.Handle, false, true); m_shader_renderGBuffer = new Shader(m_device, new System.IO.FileInfo("./Shaders/RenderGBuffer.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS"); m_shader_renderScene = new Shader(m_device, new System.IO.FileInfo("./Shaders/RenderScene.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS"); m_shader_filter = new Shader(m_device, new System.IO.FileInfo("./Shaders/ATrousFilter.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS"); m_shader_postProcess = new Shader(m_device, new System.IO.FileInfo("./Shaders/PostProcess.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS"); m_tex_GBuffer = new Texture2D(m_device, (uint)panelOutput.Width, (uint)panelOutput.Height, 3, 1, PIXEL_FORMAT.RGBA32F, COMPONENT_FORMAT.UNORM, false, false, null); m_tex_sceneRadiance = new Texture2D(m_device, (uint)panelOutput.Width, (uint)panelOutput.Height, 1 + (int)FILTER_ITERATIONS_COUNT, 1, PIXEL_FORMAT.RGBA32F, COMPONENT_FORMAT.UNORM, false, false, null); using (ImageFile blueNoise = new ImageFile(new System.IO.FileInfo("BlueNoise64x64.png"))) { m_Tex_BlueNoise = new Texture2D(m_device, new ImagesMatrix(new ImageFile[, ] { { blueNoise } }), COMPONENT_FORMAT.UNORM); } m_CB_global = new ConstantBuffer <CB_Global>(m_device, 0); m_CB_camera = new ConstantBuffer <CB_Camera>(m_device, 1); m_CB_renderScene = new ConstantBuffer <CB_RenderScene>(m_device, 10); m_CB_filtering = new ConstantBuffer <CB_Filtering>(m_device, 10); m_CB_postProcess = new ConstantBuffer <CB_PostProcess>(m_device, 10); } catch (Exception _e) { MessageBox.Show(this, "Error", "An exception occurred while creating DX structures:\r\n" + _e.Message); } // Initialize camera m_camera.CreatePerspectiveCamera(CAMERA_FOV, (float)panelOutput.Width / panelOutput.Height, 0.1f, 100.0f); m_camera.CameraTransformChanged += m_camera_CameraTransformChanged; m_cameraManipulator.Attach(panelOutput, m_camera); // m_cameraManipulator.InitializeCamera( new float3( 0, 1.5f, 4.0f ), new float3( 0, 1.5f, 0.0f ), float3.UnitY ); m_cameraManipulator.InitializeCamera(new float3(0.0f, 2.73f, -6.0f), new float3(0.0f, 2.73f, 0.0f), float3.UnitY); m_startTime = DateTime.Now; Application.Idle += Application_Idle; }
public void Init() { #if DEBUG m_PS_Display = new Shader(Device, new ShaderFile(new System.IO.FileInfo("./Shaders/Display.hlsl")), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); #else m_PS_Display = Shader.CreateFromBinaryBlob(Device, new System.IO.FileInfo("./Shaders/Display.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS"); #endif m_CB_Display = new ConstantBuffer <CBDisplay>(Device, 0); m_CB_Display.m._Width = (uint)Width; m_CB_Display.m._Height = (uint)Height; // Setup camera m_Camera.CreatePerspectiveCamera((float)(60.0 * Math.PI / 180.0), (float)Width / Height, 0.01f, 100.0f); m_Manipulator.Attach(this, m_Camera); m_Manipulator.InitializeCamera(new float3(0, -0.1f, 0.1f), new float3(0, 0, 0), float3.UnitY); m_Manipulator.ManipulationPanSpeed = 0.1f; m_Camera.CameraTransformChanged += new EventHandler(Camera_CameraTransformChanged); m_Manipulator.EnableMouseAction += new CameraManipulator.EnableMouseActionEventHandler(m_Manipulator_EnableMouseAction); Camera_CameraTransformChanged(m_Manipulator, EventArgs.Empty); Application.Idle += new EventHandler(Application_Idle); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { m_Device.Init(panelOutput.Handle, false, false); } catch (Exception _e) { m_Device = null; MessageBox.Show("Failed to initialize DX device!\n\n" + _e.Message, "Voronoi Debugger", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } BuildQuad(); try { m_Shader_Plane = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/RenderPlane.hlsl")), VERTEX_FORMAT.P3N3G3T2, "VS", null, "PS", null); m_Shader_Line = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/RenderLine.hlsl")), VERTEX_FORMAT.P3N3G3T2, "VS", null, "PS", null); } catch (Exception _e) { MessageBox.Show("Shader failed to compile!\n\n" + _e.Message, "Voronoi Debugger", MessageBoxButtons.OK, MessageBoxIcon.Error); m_Shader_Plane = null; } m_CB_Main = new ConstantBuffer <CB_Main>(m_Device, 0); m_CB_Camera = new ConstantBuffer <CB_Camera>(m_Device, 1); m_CB_Plane = new ConstantBuffer <CB_Plane>(m_Device, 2); m_CB_Line = new ConstantBuffer <CB_Line>(m_Device, 2); // Setup camera m_Camera.CreatePerspectiveCamera((float)(60.0 * Math.PI / 180.0), (float)panelOutput.Width / panelOutput.Height, 0.01f, 1000.0f); m_Manipulator.Attach(panelOutput, m_Camera); m_Manipulator.InitializeCamera(new float3(0, 1, -2.5f), new float3(0, 1, 0), float3.UnitY); Application.Idle += new EventHandler(Application_Idle); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { m_device.Init(panelOutput3D.Handle, false, true); m_Shader_renderWall = new Shader(m_device, new System.IO.FileInfo("./Shaders/RenderWall.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); m_Shader_renderGBuffer = new Shader(m_device, new System.IO.FileInfo("./Shaders/RenderGBuffer.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); m_Shader_renderScene = new Shader(m_device, new System.IO.FileInfo("./Shaders/RenderScene.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); m_CB_Main = new ConstantBuffer <CB_Main>(m_device, 0); m_CB_Camera = new ConstantBuffer <CB_Camera>(m_device, 1); using (ImageFile blueNoise = new ImageFile(new System.IO.FileInfo("BlueNoise64x64.png"))) { m_Tex_BlueNoise = new Texture2D(m_device, new ImagesMatrix(new ImageFile[, ] { { blueNoise } }), COMPONENT_FORMAT.UNORM); } m_Tex_Wall = new Texture2D(m_device, 64, 64, 1, 1, PIXEL_FORMAT.RGBA8, COMPONENT_FORMAT.AUTO, false, false, null); m_Tex_GBuffer = new Texture2D(m_device, m_device.DefaultTarget.Width, m_device.DefaultTarget.Height, 2, 1, PIXEL_FORMAT.RGBA16F, COMPONENT_FORMAT.AUTO, false, false, null); } catch (Exception _e) { MessageBox.Show(this, "Exception: " + _e.Message, "Path Tracing Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } m_startTime = DateTime.Now; // Initialize camera m_camera.CreatePerspectiveCamera(60.0f * (float)Math.PI / 180.0f, (float)panelOutput3D.Width / panelOutput3D.Height, 0.01f, 10.0f); m_manipulator.Attach(panelOutput3D, m_camera); m_manipulator.InitializeCamera(new float3(0, 0, -0.5f), float3.Zero, float3.UnitY); m_camera.CameraTransformChanged += m_camera_CameraTransformChanged; m_camera_CameraTransformChanged(null, EventArgs.Empty); Application.Idle += Application_Idle; }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { m_Device.Init(panelOutput.Handle, false, true); } catch (Exception _e) { m_Device = null; MessageBox("Failed to initialize DX device!\n\n" + _e.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } m_CB_Main = new ConstantBuffer <CB_Main>(m_Device, 0); m_CB_Camera = new ConstantBuffer <CB_Camera>(m_Device, 1); m_CB_AutoExposure = new ConstantBuffer <CB_AutoExposure>(m_Device, 10); m_CB_ToneMapping = new ConstantBuffer <CB_ToneMapping>(m_Device, 10); try { #if DEBUG m_Shader_RenderHDR = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/RenderCubeMap.hlsl")), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); m_Shader_ComputeTallHistogram = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/AutoExposure/ComputeTallHistogram.hlsl")), "CS", null); m_Shader_FinalizeHistogram = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/AutoExposure/FinalizeHistogram.hlsl")), "CS", null); m_Shader_ComputeAutoExposure = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/AutoExposure/ComputeAutoExposure.hlsl")), "CS", null); m_Shader_ToneMapping = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/ToneMapping.hlsl")), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); #else m_Shader_RenderHDR = Shader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("Shaders/RenderCubeMap.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS"); m_Shader_ComputeTallHistogram = ComputeShader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("Shaders/AutoExposure/ComputeTallHistogram.hlsl"), "CS"); m_Shader_FinalizeHistogram = ComputeShader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("Shaders/AutoExposure/FinalizeHistogram.hlsl"), "CS"); m_Shader_ComputeAutoExposure = ComputeShader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("Shaders/AutoExposure/ComputeAutoExposure.hlsl"), "CS"); m_Shader_ToneMapping = Shader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("Shaders/ToneMapping.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS"); #endif } catch (Exception _e) { MessageBox("Shader failed to compile!\n\n" + _e.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); m_Shader_RenderHDR = null; m_Shader_ComputeTallHistogram = null; m_Shader_FinalizeHistogram = null; m_Shader_ComputeAutoExposure = null; m_Shader_ToneMapping = null; } // Create the HDR buffer m_Tex_HDR = new Texture2D(m_Device, panelOutput.Width, panelOutput.Height, 1, 1, PIXEL_FORMAT.RGBA32_FLOAT, false, false, null); // Create the histogram & auto-exposure buffers int tallHistogramHeight = (panelOutput.Height + 3) >> 2; m_Tex_TallHistogram = new Texture2D(m_Device, 128, tallHistogramHeight, 1, 1, PIXEL_FORMAT.R32_UINT, false, true, null); m_Tex_Histogram = new Texture2D(m_Device, 128, 1, 1, 1, PIXEL_FORMAT.R32_UINT, false, true, null); m_Buffer_AutoExposureSource = new StructuredBuffer <autoExposure_t>(m_Device, 1, true); m_Buffer_AutoExposureSource.m[0].EngineLuminanceFactor = 1.0f; m_Buffer_AutoExposureSource.m[0].TargetLuminance = 1.0f; m_Buffer_AutoExposureSource.m[0].MinLuminanceLDR = 0.0f; m_Buffer_AutoExposureSource.m[0].MaxLuminanceLDR = 1.0f; m_Buffer_AutoExposureSource.m[0].MiddleGreyLuminanceLDR = 1.0f; m_Buffer_AutoExposureSource.m[0].EV = 0.0f; m_Buffer_AutoExposureSource.m[0].Fstop = 0.0f; m_Buffer_AutoExposureSource.m[0].PeakHistogramValue = 0; m_Buffer_AutoExposureSource.Write(); m_Buffer_AutoExposureTarget = new StructuredBuffer <autoExposure_t>(m_Device, 1, true); // Load cube map try { m_Tex_CubeMap = LoadCubeMap(new System.IO.FileInfo("garage4_hd.dds")); // m_Tex_CubeMap = LoadCubeMap( new System.IO.FileInfo( @"..\..\..\Arkane\CubeMaps\hdrcube6.dds" ) ); // m_Tex_CubeMap = LoadCubeMap( new System.IO.FileInfo( @"..\..\..\Arkane\CubeMaps\dust_return\pr_obe_28_cube_BC6H_UF16.bimage" ) ); // Tunnel // m_Tex_CubeMap = LoadCubeMap( new System.IO.FileInfo( @"..\..\..\Arkane\CubeMaps\dust_return\pr_obe_89_cube_BC6H_UF16.bimage" ) ); // Large sky // m_Tex_CubeMap = LoadCubeMap( new System.IO.FileInfo( @"..\..\..\Arkane\CubeMaps\dust_return\pr_obe_115_cube_BC6H_UF16.bimage" ) ); // Indoor // m_Tex_CubeMap = LoadCubeMap( new System.IO.FileInfo( @"..\..\..\Arkane\CubeMaps\dust_return\pr_obe_123_cube_BC6H_UF16.bimage" ) ); // Under the arch // m_Tex_CubeMap = LoadCubeMap( new System.IO.FileInfo( @"..\..\..\Arkane\CubeMaps\dust_return\pr_obe_189_cube_BC6H_UF16.bimage" ) ); // Indoor viewing out (vista) // m_Tex_CubeMap = LoadCubeMap( new System.IO.FileInfo( @"..\..\..\Arkane\CubeMaps\dust_return\pr_obe_246_cube_BC6H_UF16.bimage" ) ); // Nice! Statue's feet // m_Tex_CubeMap = LoadCubeMap( new System.IO.FileInfo( @"..\..\..\Arkane\CubeMaps\dust_return\pr_obe_248_cube_BC6H_UF16.bimage" ) ); // Nice! In a corner with lot of sky } catch (Exception) { } // Setup camera m_Camera.CreatePerspectiveCamera((float)(90.0 * Math.PI / 180.0), (float)panelOutput.Width / panelOutput.Height, 0.01f, 100.0f); m_Manipulator.Attach(panelOutput, m_Camera); m_Manipulator.InitializeCamera(new float3(0, 0, 1), new float3(0, 0, 0), float3.UnitY); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { // Initialize the device m_device = new Device(); m_device.Init(graphPanel.Handle, false, true); // Create the render shaders try { Shader.WarningAsError = false; m_shader_RenderSphere = new Shader(m_device, new System.IO.FileInfo(@"./Shaders/RenderSphere.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS"); m_shader_RenderScene = new Shader(m_device, new System.IO.FileInfo(@"./Shaders/RenderScene.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS"); m_shader_RenderLDR = new Shader(m_device, new System.IO.FileInfo(@"./Shaders/RenderLDR.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS"); } catch (Exception _e) { throw new Exception("Failed to compile shader! " + _e.Message); } // Create CB m_CB_Render = new ConstantBuffer <CB_Main>(m_device, 0); // Create textures LoadHDRImage(); m_Tex_HDRBuffer = new Texture2D(m_device, (uint)graphPanel.Width, (uint)graphPanel.Height, 2, 1, ImageUtility.PIXEL_FORMAT.RGBA32F, ImageUtility.COMPONENT_FORMAT.AUTO, false, false, null); { // Build noise texture SimpleRNG.SetSeed(1U); PixelsBuffer content = new PixelsBuffer(256 * 256 * 16); using (System.IO.BinaryWriter W = content.OpenStreamWrite()) for (int i = 0; i < 256 * 256; i++) { W.Write((float)SimpleRNG.GetUniform()); W.Write((float)SimpleRNG.GetUniform()); W.Write((float)SimpleRNG.GetUniform()); W.Write((float)SimpleRNG.GetUniform()); } m_Tex_Noise = new Texture2D(m_device, 256, 256, 1, 1, ImageUtility.PIXEL_FORMAT.RGBA32F, ImageUtility.COMPONENT_FORMAT.AUTO, false, false, new PixelsBuffer[] { content }); } // Build SH coeffs const int ORDERS = 20; { const int TABLE_SIZE = 64; // Load A coeffs into a texture array float[,,] A = new float[TABLE_SIZE, TABLE_SIZE, ORDERS]; // using ( System.IO.FileStream S = new System.IO.FileInfo( @"ConeTable_cosAO_order20.float" ).OpenRead() ) using (System.IO.FileStream S = new System.IO.FileInfo(@"ConeTable_cosTheta_order20.float").OpenRead()) using (System.IO.BinaryReader R = new System.IO.BinaryReader(S)) { for (int thetaIndex = 0; thetaIndex < TABLE_SIZE; thetaIndex++) { for (int AOIndex = 0; AOIndex < TABLE_SIZE; AOIndex++) { for (int order = 0; order < ORDERS; order++) { A[thetaIndex, AOIndex, order] = R.ReadSingle(); } } } } PixelsBuffer[] coeffSlices = new PixelsBuffer[5]; // 5 slices of 4 coeffs each to get our 20 orders for (int sliceIndex = 0; sliceIndex < coeffSlices.Length; sliceIndex++) { PixelsBuffer coeffSlice = new PixelsBuffer(TABLE_SIZE * TABLE_SIZE * 16); coeffSlices[sliceIndex] = coeffSlice; using (System.IO.BinaryWriter W = coeffSlice.OpenStreamWrite()) { for (int thetaIndex = 0; thetaIndex < TABLE_SIZE; thetaIndex++) { for (int AOIndex = 0; AOIndex < TABLE_SIZE; AOIndex++) { W.Write(A[thetaIndex, AOIndex, 4 * sliceIndex + 0]); W.Write(A[thetaIndex, AOIndex, 4 * sliceIndex + 1]); W.Write(A[thetaIndex, AOIndex, 4 * sliceIndex + 2]); W.Write(A[thetaIndex, AOIndex, 4 * sliceIndex + 3]); } } } } m_Tex_ACoeffs = new Texture2D(m_device, 64, 64, coeffSlices.Length, 1, ImageUtility.PIXEL_FORMAT.RGBA32F, ImageUtility.COMPONENT_FORMAT.AUTO, false, false, coeffSlices); } { // Load environment coeffs into a constant buffer float3[] coeffs = new float3[ORDERS * ORDERS]; using (System.IO.FileStream S = new System.IO.FileInfo(@"Ennis_order20.float3").OpenRead()) using (System.IO.BinaryReader R = new System.IO.BinaryReader(S)) for (int coeffIndex = 0; coeffIndex < ORDERS * ORDERS; coeffIndex++) { coeffs[coeffIndex].Set(R.ReadSingle(), R.ReadSingle(), R.ReadSingle()); } // Write into a raw byte[] byte[] rawContent = new byte[400 * 4 * 4]; using (System.IO.MemoryStream MS = new System.IO.MemoryStream(rawContent)) using (System.IO.BinaryWriter W = new System.IO.BinaryWriter(MS)) { for (int coeffIndex = 0; coeffIndex < ORDERS * ORDERS; coeffIndex++) { W.Write(coeffs[coeffIndex].x); W.Write(coeffs[coeffIndex].y); W.Write(coeffs[coeffIndex].z); W.Write(0.0f); } } m_CB_Coeffs = new RawConstantBuffer(m_device, 1, rawContent.Length); m_CB_Coeffs.UpdateData(rawContent); } // Create camera + manipulator m_camera.CreatePerspectiveCamera(0.5f * (float)Math.PI, (float)graphPanel.Width / graphPanel.Height, 0.01f, 100.0f); m_camera.CameraTransformChanged += m_camera_CameraTransformChanged; m_cameraManipulator.Attach(graphPanel, m_camera); m_cameraManipulator.InitializeCamera(-2.0f * float3.UnitZ, float3.Zero, float3.UnitY); m_camera_CameraTransformChanged(null, EventArgs.Empty); // Start rendering Application.Idle += Application_Idle; } catch (Exception _e) { MessageBox.Show("Failed to initialize D3D renderer!\r\nReason: " + _e.Message); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { m_Device.Init(panelOutput.Handle, false, true); } catch (Exception _e) { m_Device = null; MessageBox.Show("Failed to initialize DX device!\n\n" + _e.Message, "Distance Field Test", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { m_Shader_RenderScene = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/RenderScene.hlsl")), VERTEX_FORMAT.P3N3G3B3T2, "VS", null, "PS", null); } catch (Exception _e) { MessageBox.Show("Shader \"RenderScene\" failed to compile!\n\n" + _e.Message, "Distance Field Test", MessageBoxButtons.OK, MessageBoxIcon.Error); m_Shader_RenderScene = null; } try { m_Shader_PostProcess = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/PostProcess.hlsl")), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); } catch (Exception _e) { MessageBox.Show("Shader \"PostProcess\" failed to compile!\n\n" + _e.Message, "Distance Field Test", MessageBoxButtons.OK, MessageBoxIcon.Error); m_Shader_PostProcess = null; } #if DEBUG && !BISOU try { m_Shader_ClearAccumulator = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/SplatDepthStencil_Accumulate.hlsl")), "CS_Clear", null); m_Shader_SplatDepthStencil = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/SplatDepthStencil_Accumulate.hlsl")), "CS_Accumulate", null); m_Shader_Reproject = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/SplatDepthStencil_Reproject.hlsl")), "CS", null); m_Shader_FinalizeSplat = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/SplatDepthStencil_Finalize.hlsl")), "CS", null); } catch (Exception _e) { MessageBox.Show("Shader \"SplatDepthStencil\" failed to compile!\n\n" + _e.Message, "Distance Field Test", MessageBoxButtons.OK, MessageBoxIcon.Error); m_Shader_ClearAccumulator = null; m_Shader_SplatDepthStencil = null; m_Shader_FinalizeSplat = null; } try { m_Shader_BuildDistanceField[0] = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/BuildDistanceField_X.hlsl")), "CS", null); m_Shader_BuildDistanceField[1] = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/BuildDistanceField_Y.hlsl")), "CS", null); m_Shader_BuildDistanceField[2] = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/BuildDistanceField_Z.hlsl")), "CS", null); } catch (Exception _e) { MessageBox.Show("Shader \"BuildDistanceField\" failed to compile!\n\n" + _e.Message, "Distance Field Test", MessageBoxButtons.OK, MessageBoxIcon.Error); m_Shader_BuildDistanceField[0] = null; m_Shader_BuildDistanceField[1] = null; m_Shader_BuildDistanceField[2] = null; } #else try { m_Shader_ClearAccumulator = ComputeShader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("Shaders/SplatDepthStencil_Accumulate.hlsl"), "CS_Clear"); m_Shader_SplatDepthStencil = ComputeShader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("Shaders/SplatDepthStencil_Accumulate.hlsl"), "CS_Accumulate"); m_Shader_Reproject = ComputeShader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("Shaders/SplatDepthStencil_Reproject.hlsl"), "CS"); m_Shader_FinalizeSplat = ComputeShader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("Shaders/SplatDepthStencil_Finalize.hlsl"), "CS"); } catch (Exception _e) { MessageBox.Show("Shader \"SplatDepthStencil\" failed to compile!\n\n" + _e.Message, "Distance Field Test", MessageBoxButtons.OK, MessageBoxIcon.Error); m_Shader_ClearAccumulator = null; m_Shader_SplatDepthStencil = null; m_Shader_Reproject = null; m_Shader_FinalizeSplat = null; } try { m_Shader_BuildDistanceField[0] = ComputeShader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("./Shaders/Binary/BuildDistanceField_X.fxbin"), "CS"); m_Shader_BuildDistanceField[1] = ComputeShader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("./Shaders/Binary/BuildDistanceField_Y.fxbin"), "CS"); m_Shader_BuildDistanceField[2] = ComputeShader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("./Shaders/Binary/BuildDistanceField_Z.fxbin"), "CS"); } catch (Exception _e) { MessageBox.Show("Shader \"BuildDistanceField\" failed to compile!\n\n" + _e.Message, "Distance Field Test", MessageBoxButtons.OK, MessageBoxIcon.Error); m_Shader_BuildDistanceField[0] = null; m_Shader_BuildDistanceField[1] = null; m_Shader_BuildDistanceField[2] = null; } #endif m_CB_Main = new ConstantBuffer <CB_Main>(m_Device, 0); m_CB_Camera = new ConstantBuffer <CB_Camera>(m_Device, 1); m_CB_Object = new ConstantBuffer <CB_Object>(m_Device, 2); BuildPrimitives(); // Allocate texture // m_Tex_TempTarget = new Texture2D( m_Device, panelOutput.Width, panelOutput.Height, 2, 1, PIXEL_FORMAT.RGBA8_UNORM_sRGB, false, false, null ); m_Tex_TempTarget = new Texture2D(m_Device, panelOutput.Width, panelOutput.Height, 2, 1, PIXEL_FORMAT.RGBA16_FLOAT, false, false, null); // Allocate several 3D textures for depth-stencil reduction m_Tex_TempDepthAccumulatorRG = new Texture3D(m_Device, VOXELS_COUNT, VOXELS_COUNT, VOXELS_COUNT, 1, PIXEL_FORMAT.R32_UINT, false, true, null); m_Tex_TempDepthAccumulatorBA = new Texture3D(m_Device, VOXELS_COUNT, VOXELS_COUNT, VOXELS_COUNT, 1, PIXEL_FORMAT.R32_UINT, false, true, null); m_Tex_SplatDepthStencil[0] = new Texture3D(m_Device, VOXELS_COUNT, VOXELS_COUNT, VOXELS_COUNT, 1, PIXEL_FORMAT.RGBA8_UNORM, false, true, null); m_Tex_SplatDepthStencil[1] = new Texture3D(m_Device, VOXELS_COUNT, VOXELS_COUNT, VOXELS_COUNT, 1, PIXEL_FORMAT.RGBA8_UNORM, false, true, null); m_Tex_DistanceField[0] = new Texture3D(m_Device, VOXELS_COUNT, VOXELS_COUNT, VOXELS_COUNT, 6, PIXEL_FORMAT.R16_FLOAT, false, true, null); m_Tex_DistanceField[1] = new Texture3D(m_Device, VOXELS_COUNT, VOXELS_COUNT, VOXELS_COUNT, 6, PIXEL_FORMAT.R16_FLOAT, false, true, null); m_Device.Clear(m_Tex_SplatDepthStencil[0], float4.Zero); m_Device.Clear(m_Tex_SplatDepthStencil[1], float4.Zero); // Setup camera m_Camera.CreatePerspectiveCamera((float)(60.0 * Math.PI / 180.0), (float)panelOutput.Width / panelOutput.Height, 0.01f, 100.0f); m_Manipulator.Attach(panelOutput, m_Camera); m_Manipulator.InitializeCamera(new float3(0, 1, 4), new float3(0, 1, 0), float3.UnitY); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { m_device.Init(panelOutput.Handle, false, true); } catch (Exception _e) { m_device = null; MessageBox.Show("Failed to initialize DX device!\n\n" + _e.Message, "MSBRDF Test", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { // m_shader_Render = new Shader( m_device, new System.IO.FileInfo( "Shaders/Render.hlsl" ), VERTEX_FORMAT.Pt4, "VS", null, "PS", null ); // OBSOLETE MSBRDF CODE! For historical purpose only... m_shader_Finalize = new Shader(m_device, new System.IO.FileInfo("Shaders/RenderComplete.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS_Finalize", null); #if TEST_SH_ENVIRONMENT m_shader_Accumulate = new Shader(m_device, new System.IO.FileInfo("Shaders/RenderCompareSH.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); // Use this to show a rendering with SH environment checkBoxUseRealTimeApprox.Visible = true; checkBoxUseRealTimeApprox.Checked = true; floatTrackbarControlRoughnessSphere.Value = 1; // Show full roughness floatTrackbarControlReflectanceSphere2.Value = 0; // Disturbing if diffuse is showing! groupBoxPlane.Visible = false; // No plane is available in this configuration #elif TEST_LTC_AREA_LIGHT m_shader_Accumulate = new Shader(m_device, new System.IO.FileInfo("Shaders/RenderCompareLTC.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); // Use this to show a rendering with LTC area light checkBoxUseRealTimeApprox.Visible = true; // checkBoxUseRealTimeApprox.Checked = true; checkBoxUseRealTimeApprox.Checked = false; // floatTrackbarControlRoughnessSphere.Value = 1; // Show full roughness // floatTrackbarControlReflectanceSphere2.Value = 0; // Disturbing if diffuse is showing! checkBoxUseLTC.Visible = true; floatTrackbarControlRoughnessSphere.Value = 0.25f; floatTrackbarControlReflectanceSphere.Value = 0.04f; floatTrackbarControlRoughnessSphere2.Value = 0.80f; floatTrackbarControlReflectanceSphere2.Value = 0.5f; floatTrackbarControlRoughnessGround.Value = 0.85f; floatTrackbarControlReflectanceGround.Value = 0.35f; floatTrackbarControlLightElevation.Value = 0.5f; #else m_shader_Accumulate = new Shader(m_device, new System.IO.FileInfo("Shaders/RenderComplete.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); // Use this for a full render #endif } catch (Exception _e) { MessageBox.Show("Shader failed to compile!\n\n" + _e.Message, "MSBRDF Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } uint W = (uint)panelOutput.Width; uint H = (uint)panelOutput.Height; m_CB_Global = new ConstantBuffer <CB_Global>(m_device, 0); m_CB_Camera = new ConstantBuffer <CB_Camera>(m_device, 1); m_CB_Render = new ConstantBuffer <CB_Render>(m_device, 2); m_CB_SH = new ConstantBuffer <CB_SH>(m_device, 3); BuildNoiseTextures(); // Shuffle group indices for (uint groupIndex = 0; groupIndex < GROUPS_COUNT; groupIndex++) { m_groupShuffle[groupIndex] = groupIndex; } for (uint shuffleIndex = 100 * GROUPS_COUNT; shuffleIndex > 0; shuffleIndex--) { for (uint groupIndex = 0; groupIndex < GROUPS_COUNT; groupIndex++) { uint i0 = SimpleRNG.GetUint() % GROUPS_COUNT; uint i1 = SimpleRNG.GetUint() % GROUPS_COUNT; uint temp = m_groupShuffle[i0]; m_groupShuffle[i0] = m_groupShuffle[i1]; m_groupShuffle[i1] = temp; } } // Tables are "built" with Mathematica now // BuildMSBRDF( new DirectoryInfo( @".\Tables\" ) ); LoadMSBRDF(128, new FileInfo("./Tables/MSBRDF_GGX_G2_E128x128.float"), new FileInfo("./Tables/MSBRDF_GGX_G2_Eavg128.float"), out m_tex_MSBRDF_GGX_E, out m_tex_MSBRDF_GGX_Eavg); LoadMSBRDF(32, new FileInfo("./Tables/MSBRDF_OrenNayar_E32x32.float"), new FileInfo("./Tables/MSBRDF_OrenNayar_Eavg32.float"), out m_tex_MSBRDF_OrenNayar_E, out m_tex_MSBRDF_OrenNayar_Eavg); #if TEST_LTC_AREA_LIGHT // Area light m_tex_LTC = LoadLTC(new FileInfo(@".\Tables\LTC.dds")); m_tex_LTC_Unity = LoadUnityLTC(); #endif // Load cube map using (ImageUtility.ImagesMatrix I = new ImageUtility.ImagesMatrix()) { // I.DDSLoadFile( new FileInfo( "garage4_hd.dds" ) ); I.DDSLoadFile(new FileInfo("beach.dds")); EncodeCubeMapIntoSH(I); m_tex_CubeMap = new Texture2D(m_device, I, ImageUtility.COMPONENT_FORMAT.AUTO); } m_tex_Accumulator = new Texture2D(m_device, m_device.DefaultTarget.Width, m_device.DefaultTarget.Height, 1, 1, ImageUtility.PIXEL_FORMAT.RGBA32F, ImageUtility.COMPONENT_FORMAT.AUTO, false, true, null); // Setup camera m_camera.CreatePerspectiveCamera((float)(60.0 * Math.PI / 180.0), (float)panelOutput.Width / panelOutput.Height, 0.01f, 100.0f); m_manipulator.Attach(panelOutput, m_camera); // m_manipulator.InitializeCamera( new float3( 0, 1.5f, 2.0f ), new float3( -0.4f, 0, 0.4f ), float3.UnitY ); // Garage probe m_manipulator.InitializeCamera(new float3(1.46070266f, 1.10467184f, 1.36212754f), new float3(0, 1, 0), float3.UnitY); // Beach probe m_camera.CameraTransformChanged += Camera_CameraTransformChanged; Camera_CameraTransformChanged(null, EventArgs.Empty); // Start game time m_Ticks2Seconds = 1.0 / System.Diagnostics.Stopwatch.Frequency; m_StopWatch.Start(); m_StartGameTime = GetGameTime(); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { m_Device.Init(panelOutput.Handle, false, true); } catch (Exception _e) { m_Device = null; MessageBox.Show("Failed to initialize DX device!\n\n" + _e.Message, "Distance Field Test", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { m_Shader_RenderScene = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/RenderScene.hlsl")), VERTEX_FORMAT.P3N3G3B3T2, "VS", null, "PS", null); } catch (Exception _e) { MessageBox.Show("Shader \"RenderScene\" failed to compile!\n\n" + _e.Message, "Distance Field Test", MessageBoxButtons.OK, MessageBoxIcon.Error); m_Shader_RenderScene = null; } try { m_Shader_PostProcess = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/PostProcess.hlsl")), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); } catch (Exception _e) { MessageBox.Show("Shader \"PostProcess\" failed to compile!\n\n" + _e.Message, "Distance Field Test", MessageBoxButtons.OK, MessageBoxIcon.Error); m_Shader_PostProcess = null; } try { // m_Shader_BuildDistanceField[0] = new ComputeShader( m_Device, new ShaderFile( new System.IO.FileInfo( "Shaders/BuildDistanceField.hlsl" ) ), "CS_X", null ); } catch (Exception _e) { MessageBox.Show("Shader \"BuildDistanceField\" failed to compile!\n\n" + _e.Message, "Distance Field Test", MessageBoxButtons.OK, MessageBoxIcon.Error); m_Shader_PostProcess = null; } #if DEBUG && !BISOU try { m_Shader_SplatDepthStencil[0] = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/SplatDepthStencil.hlsl")), "CS0", null); m_Shader_SplatDepthStencil[1] = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/SplatDepthStencil.hlsl")), "CS1", null); m_Shader_SplatDepthStencil[2] = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/SplatDepthStencil.hlsl")), "CS2", null); } catch (Exception _e) { MessageBox.Show("Shader \"SplatDepthStencil\" failed to compile!\n\n" + _e.Message, "Distance Field Test", MessageBoxButtons.OK, MessageBoxIcon.Error); m_Shader_SplatDepthStencil[0] = null; m_Shader_SplatDepthStencil[1] = null; m_Shader_SplatDepthStencil[2] = null; } #else try { m_Shader_SplatDepthStencil[0] = ComputeShader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("./Shaders/Binary/SplatDepthStencil.fxbin"), "CS0"); m_Shader_SplatDepthStencil[1] = ComputeShader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("./Shaders/Binary/SplatDepthStencil.fxbin"), "CS1"); m_Shader_SplatDepthStencil[2] = ComputeShader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("./Shaders/Binary/SplatDepthStencil.fxbin"), "CS2"); } catch (Exception _e) { MessageBox.Show("Shader \"SplatDepthStencil\" failed to compile!\n\n" + _e.Message, "Distance Field Test", MessageBoxButtons.OK, MessageBoxIcon.Error); m_Shader_SplatDepthStencil[0] = null; m_Shader_SplatDepthStencil[1] = null; m_Shader_SplatDepthStencil[2] = null; } #endif m_CB_Main = new ConstantBuffer <CB_Main>(m_Device, 0); m_CB_Camera = new ConstantBuffer <CB_Camera>(m_Device, 1); m_CB_Object = new ConstantBuffer <CB_Object>(m_Device, 2); m_CB_DistanceField = new ConstantBuffer <CB_Distance>(m_Device, 2); BuildPrimitives(); // Allocate texture m_Tex_TempTarget = new Texture2D(m_Device, panelOutput.Width, panelOutput.Height, 1, 1, PIXEL_FORMAT.RGBA8_UNORM_sRGB, false, false, null); // Allocate several 3D textures for depth-stencil reduction int W = (panelOutput.Width + 7) & ~7; int H = (panelOutput.Height + 7) & ~7; int D = 1; for (int depthLevel = 0; depthLevel < 3; depthLevel++) { // On every level, resolution is reduced by 2 and depth gets multiplied by 4 W >>= 1; H >>= 1; D <<= 2; m_Tex_TempDepth3D[depthLevel] = new Texture3D(m_Device, W, H, D, 1, PIXEL_FORMAT.RGBA32_FLOAT, false, true, null); } m_Tex_TempDepth3D[3] = new Texture3D(m_Device, W, H, D, 1, PIXEL_FORMAT.RGBA32_FLOAT, false, true, null); // int cellsCountX = (panelOutput.Width + 7) >> 3; // int cellsCountY = (panelOutput.Height + 7) >> 3; // int cellsCountZ = 64; // m_Tex_DistanceField = new Texture3D( m_Device, cellsCountX, cellsCountY, cellsCountZ, 1, PIXEL_FORMAT.RGBA32_FLOAT, false, true, null ); // TODO: Use mips to smooth stuff up? // m_Tex_DistanceField = new Texture3D( m_Device, W, H, D, 1, PIXEL_FORMAT.RGBA32_FLOAT, false, true, null ); // TODO: Use mips to smooth stuff up? // Setup camera m_Camera.CreatePerspectiveCamera((float)(60.0 * Math.PI / 180.0), (float)panelOutput.Width / panelOutput.Height, 0.01f, 100.0f); m_Manipulator.Attach(panelOutput, m_Camera); m_Manipulator.InitializeCamera(new float3(0, 1, 4), new float3(0, 1, 0), float3.UnitY); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { m_Device.Init(panelOutput.Handle, false, true); } catch (Exception _e) { m_Device = null; MessageBox.Show("Failed to initialize DX device!\n\n" + _e.Message, "ShaderToy", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { m_Shader_UpdateHeightMap = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/UpdateHeightMap.hlsl")), "CS", null); m_shader_GenerateDensity = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/GenerateDensity.hlsl")), "CS", null); m_Shader_ClearAccumulator = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/TracePhotons.hlsl")), "CS_ClearAccumulator", null); m_Shader_InitPhotons = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/TracePhotons.hlsl")), "CS_InitPhotons", null); m_Shader_TracePhotons = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/TracePhotons.hlsl")), "CS_TracePhotons", null); m_Shader_RenderRoom = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/RenderRoom.hlsl")), VERTEX_FORMAT.P3N3G3T2, "VS", null, "PS", null); m_Shader_RenderSphere = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/RenderSphere.hlsl")), VERTEX_FORMAT.P3N3G3T2, "VS", null, "PS", null); m_Shader_RayMarcher = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/RayMarch.hlsl")), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); m_Shader_PostProcess = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/PostProcess.hlsl")), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); // m_ShaderDownsample = new Shader( m_Device, new ShaderFile( new System.IO.FileInfo( "Shaders/Downsample.hlsl" ) ), VERTEX_FORMAT.Pt4, "VS", null, "PS", null ); } catch (Exception _e) { MessageBox.Show("Shader failed to compile!\n\n" + _e.Message, "ShaderToy", MessageBoxButtons.OK, MessageBoxIcon.Error); } int W = panelOutput.Width; int H = panelOutput.Height; m_CB_Global = new ConstantBuffer <CB_Global>(m_Device, 0); m_CB_Camera = new ConstantBuffer <CB_Camera>(m_Device, 1); m_CB_GenerateDensity = new ConstantBuffer <CB_GenerateDensity>(m_Device, 2); m_CB_TracePhotons = new ConstantBuffer <CB_TracePhotons>(m_Device, 2); m_CB_RenderRoom = new ConstantBuffer <CB_RenderRoom>(m_Device, 2); m_CB_RenderSphere = new ConstantBuffer <CB_RenderSphere>(m_Device, 2); m_CB_PostProcess = new ConstantBuffer <CB_PostProcess>(m_Device, 2); m_CB_RayMarch = new ConstantBuffer <CB_RayMarch>(m_Device, 2); m_Tex_TempBackBuffer = new Texture2D(m_Device, W, H, 1, 1, PIXEL_FORMAT.RGBA16_FLOAT, false, false, null); m_Tex_HeightMap = new Texture2D(m_Device, HEIGHTMAP_SIZE, HEIGHTMAP_SIZE, 1, 1, PIXEL_FORMAT.RG16_FLOAT, false, true, null); m_Tex_Scattering = new Texture2D(m_Device, panelOutput.Width, panelOutput.Height, 2, 1, PIXEL_FORMAT.RGBA16_FLOAT, false, false, null); m_Tex_VolumeDensity = new Texture3D(m_Device, VOLUME_SIZE, VOLUME_SIZE, VOLUME_SIZE, 1, PIXEL_FORMAT.R8_UNORM, false, true, null);; m_Tex_AccumPhotonCube = new Texture2D(m_Device, 256, 256, -6, 1, PIXEL_FORMAT.RGBA16_FLOAT, false, true, null);; m_Tex_AccumPhoton3D = new Texture3D(m_Device, VOLUME_SIZE, VOLUME_SIZE, VOLUME_SIZE, 1, PIXEL_FORMAT.R32_UINT, false, true, null);; BuildNoiseTextures(); // Structured buffer m_SB_PhotonInfos = new StructuredBuffer <SB_PhotonInfo_t>(m_Device, PHOTONS_COUNT, false); m_SB_Photons[0] = new StructuredBuffer <SB_Photon_t>(m_Device, PHOTONS_COUNT, false); m_SB_Photons[1] = new StructuredBuffer <SB_Photon_t>(m_Device, PHOTONS_COUNT, false); BuildPrimitives(); // Setup camera m_Camera.CreatePerspectiveCamera((float)(60.0 * Math.PI / 180.0), (float)panelOutput.Width / panelOutput.Height, 0.01f, 100.0f); m_Manipulator.Attach(panelOutput, m_Camera); m_Manipulator.InitializeCamera(new float3(0, 1, -2.5f), new float3(0, 1, 0), float3.UnitY); // Start game time m_Ticks2Seconds = 1.0 / System.Diagnostics.Stopwatch.Frequency; m_StopWatch.Start(); m_StartGameTime = GetGameTime(); }
public TestForm() { InitializeComponent(); ComputeConeDirections(); try { m_device.Init(panelOutput.Handle, false, true); m_shader_voxelizeScene = new ComputeShader(m_device, new System.IO.FileInfo("./Shaders/VoxelizeScene.hlsl"), "CS", null); m_shader_buildVoxelMips = new ComputeShader(m_device, new System.IO.FileInfo("./Shaders/VoxelizeScene.hlsl"), "CS_Mip", null); m_shader_buildSingleVoxelMips = new ComputeShader(m_device, new System.IO.FileInfo("./Shaders/VoxelizeScene.hlsl"), "CS_SingleMip", null); m_shader_accumulateVoxelLighting = new ComputeShader(m_device, new System.IO.FileInfo("./Shaders/VoxelizeScene.hlsl"), "CS_Accumulate", null); m_shader_computeIndirectLighting = new ComputeShader(m_device, new System.IO.FileInfo("./Shaders/ComputeIndirectLighting.hlsl"), "CS", null); m_shader_renderGBuffer = new Shader(m_device, new System.IO.FileInfo("./Shaders/RenderGBuffer.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); m_shader_renderScene = new Shader(m_device, new System.IO.FileInfo("./Shaders/RenderScene.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); m_shader_renderVoxels = new Shader(m_device, new System.IO.FileInfo("./Shaders/RenderVoxels.hlsl"), VERTEX_FORMAT.P3, "VS", null, "PS", null); m_shader_postProcess = new Shader(m_device, new System.IO.FileInfo("./Shaders/PostProcess.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); m_tex_GBuffer = new Texture2D(m_device, (uint)panelOutput.Width, (uint)panelOutput.Height, 4, 1, PIXEL_FORMAT.RGBA32F, COMPONENT_FORMAT.UNORM, false, false, null); m_tex_sceneRadiance = new Texture2D(m_device, (uint)panelOutput.Width, (uint)panelOutput.Height, 1, 1, PIXEL_FORMAT.RGBA32F, COMPONENT_FORMAT.UNORM, false, false, null); using (ImageFile blueNoise = new ImageFile(new System.IO.FileInfo("BlueNoise64x64.png"))) { m_Tex_BlueNoise = new Texture2D(m_device, new ImagesMatrix(new ImageFile[, ] { { blueNoise } }), COMPONENT_FORMAT.UNORM); } m_CB_computeIndirect = new ConstantBuffer <CB_ComputeIndirectLighting>(m_device, 10); m_CB_global = new ConstantBuffer <CB_Global>(m_device, 0); m_CB_camera = new ConstantBuffer <CB_Camera>(m_device, 1); m_CB_renderScene = new ConstantBuffer <CB_RenderScene>(m_device, 10); m_CB_renderVoxels = new ConstantBuffer <CB_RenderVoxels>(m_device, 10); m_CB_filtering = new ConstantBuffer <CB_Filtering>(m_device, 10); m_CB_postProcess = new ConstantBuffer <CB_PostProcess>(m_device, 10); // Build the cube primitive used to render voxels { VertexP3[] vertices = new VertexP3[] { new VertexP3() { P = new float3(-1, -1, -1) }, new VertexP3() { P = new float3(1, -1, -1) }, new VertexP3() { P = new float3(1, 1, -1) }, new VertexP3() { P = new float3(-1, 1, -1) }, new VertexP3() { P = new float3(-1, -1, +1) }, new VertexP3() { P = new float3(1, -1, +1) }, new VertexP3() { P = new float3(1, 1, +1) }, new VertexP3() { P = new float3(-1, 1, +1) }, }; uint[] indices = new uint[] { 3, 0, 4, 3, 4, 7, 6, 5, 1, 6, 1, 2, 3, 7, 6, 3, 6, 2, 4, 0, 1, 4, 1, 5, 2, 1, 0, 2, 0, 3, 7, 4, 5, 7, 5, 6, }; m_prim_Cube = new Primitive(m_device, (uint)vertices.Length, VertexP3.FromArray(vertices), indices, Primitive.TOPOLOGY.TRIANGLE_LIST, VERTEX_FORMAT.P3); } // Voxelize the scene & compute indirect lighting Voxelize(); ComputeIndirectLighting((uint)integerTrackbarControlBouncesCount.Value); } catch (Exception _e) { MessageBox.Show(this, "An exception occurred while creating DX structures:\r\n" + _e.Message, "Error"); } // Initialize camera m_camera.CreatePerspectiveCamera(CAMERA_FOV, (float)panelOutput.Width / panelOutput.Height, 0.1f, 100.0f); m_camera.CameraTransformChanged += m_camera_CameraTransformChanged; m_cameraManipulator.Attach(panelOutput, m_camera); // m_cameraManipulator.InitializeCamera( new float3( 0, 1.5f, 4.0f ), new float3( 0, 1.5f, 0.0f ), float3.UnitY ); m_cameraManipulator.InitializeCamera(new float3(0.0f, 2.73f, -6.0f), new float3(0.0f, 2.73f, 0.0f), float3.UnitY); m_startTime = DateTime.Now; Application.Idle += Application_Idle; }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { m_Device.Init(panelOutput.Handle, false, false); } catch (Exception _e) { m_Device = null; MessageBox.Show("Failed to initialize DX device!\n\n" + _e.Message, "ShaderToy", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } BuildQuad(); try { // m_ShaderDownsample = new Shader( m_Device, new ShaderFile( new System.IO.FileInfo( "Shaders/Downsample.hlsl" ) ), VERTEX_FORMAT.Pt4, "VS", null, "PS", null ); m_ShaderLinearizeDepthCS = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/LinearizeCS.hlsl")), "CS", null); m_ShaderDownsampleCS = new ComputeShader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/DownsampleCS2.hlsl")), "CS", null); m_ShaderPostProcess = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/PostProcess.hlsl")), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); // m_Shader = new Shader( m_Device, new ShaderFile( new System.IO.FileInfo( "Shaders/Airlight.hlsl" ) ), VERTEX_FORMAT.Pt4, "VS", null, "PS", null ); // m_Shader = new Shader( m_Device, new ShaderFile( new System.IO.FileInfo( "Shaders/VoronoiInterpolation.hlsl" ) ), VERTEX_FORMAT.Pt4, "VS", null, "PS", null ); // m_Shader = new Shader( m_Device, new ShaderFile( new System.IO.FileInfo( "Shaders/Room.hlsl" ) ), VERTEX_FORMAT.Pt4, "VS", null, "PS", null ); #if true m_Shader = Shader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("Shaders/Binary/TestMSBRDF2.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS"); m_Shader_Glass = Shader.CreateFromBinaryBlob(m_Device, new System.IO.FileInfo("Shaders/TestMSBRDF_Glass.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS"); #else m_Shader = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/TestMSBRDF2.hlsl")), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); m_Shader_Glass = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("Shaders/TestMSBRDF_Glass.hlsl")), VERTEX_FORMAT.Pt4, "VS", null, "PS", null); #endif } catch (Exception _e) { MessageBox.Show("Shader failed to compile!\n\n" + _e.Message, "ShaderToy", MessageBoxButtons.OK, MessageBoxIcon.Error); m_Shader = null; } m_CB_Main = new ConstantBuffer <CB_Main>(m_Device, 0); m_CB_Camera = new ConstantBuffer <CB_Camera>(m_Device, 1); m_CB_Downsample = new ConstantBuffer <CB_Downsample>(m_Device, 2); m_CB_PostProcess = new ConstantBuffer <CB_PostProcess>(m_Device, 2); m_Tex_TempBuffer = new Texture2D(m_Device, panelOutput.Width, panelOutput.Height, 2, 1, PIXEL_FORMAT.RGBA32_FLOAT, false, false, null); m_Tex_TempBuffer2 = new Texture2D(m_Device, panelOutput.Width, panelOutput.Height, 2, 1, PIXEL_FORMAT.RGBA32_FLOAT, false, false, null); // Build linear and downsampled depth buffers m_Tex_LinearDepth = new Texture2D(m_Device, panelOutput.Width, panelOutput.Height, 1, 1, PIXEL_FORMAT.R32_FLOAT, false, true, null); int safeWidth = ((panelOutput.Width + 15) & ~15) >> 1; int safeHeight = ((panelOutput.Height + 15) & ~15) >> 1; m_Tex_DownsampledDepth = new Texture2D(m_Device, safeWidth, safeHeight, 1, 4, PIXEL_FORMAT.RGBA16_FLOAT, false, true, null); // Initialize Voronoï neighbor positions m_CB_Main.m._MainPosition = new float2(0.0f, 0.0f); m_CB_Main.m._NeighborPosition0 = new float2(-0.4f, -0.6f); m_CB_Main.m._NeighborPosition1 = new float2(0.6f, -0.4f); m_CB_Main.m._NeighborPosition2 = new float2(-0.2f, 0.8f); m_CB_Main.m._NeighborPosition3 = new float2(-0.6f, 0.14f); m_CB_Main.m._MousePosition.Set(0.5f, 0.5f); // Setup camera m_Camera.CreatePerspectiveCamera((float)(60.0 * Math.PI / 180.0), (float)panelOutput.Width / panelOutput.Height, 0.01f, 100.0f); m_Manipulator.Attach(panelOutput, m_Camera); // m_Manipulator.InitializeCamera( new float3( 0, 0.5f, 2.5f ), new float3( 0, 0.5f, 0 ), float3.UnitY ); m_Manipulator.InitializeCamera(new float3(0.91f, 0.11f, 3.3f), new float3(0.91f, 0.11f, 3.3f), float3.UnitY); // Start game time m_Ticks2Seconds = 1.0 / System.Diagnostics.Stopwatch.Frequency; m_StopWatch.Start(); m_StartGameTime = GetGameTime(); }
public Form1() { InitializeComponent(); m_Device = new Device(); m_Device.Init(panelOutput1.Handle, false, false); m_Shader_RenderMesh = new Shader(m_Device, new ShaderFile(new System.IO.FileInfo("./Shaders/RenderMesh.hlsl")), VERTEX_FORMAT.P3, "VS", null, "PS", null); { List <VertexP3> Vertices = new List <VertexP3>(); List <uint> Indices = new List <uint>(); const int SUBDIVS_THETA = 80; const int SUBDIVS_PHI = 160; for (int Y = 0; Y <= SUBDIVS_THETA; Y++) { double Theta = Y * Math.PI / SUBDIVS_THETA; float CosTheta = (float)Math.Cos(Theta); float SinTheta = (float)Math.Sin(Theta); for (int X = 0; X <= SUBDIVS_PHI; X++) { double Phi = X * 2.0 * Math.PI / SUBDIVS_PHI; float CosPhi = (float)Math.Cos(Phi); float SinPhi = (float)Math.Sin(Phi); float3 N = new float3(SinTheta * SinPhi, CosTheta, SinTheta * CosPhi); Vertices.Add(new VertexP3() { P = N }); } } for (int Y = 0; Y < SUBDIVS_THETA; Y++) { int CurrentLineOffset = Y * (SUBDIVS_PHI + 1); int NextLineOffset = (Y + 1) * (SUBDIVS_PHI + 1); for (int X = 0; X <= SUBDIVS_PHI; X++) { Indices.Add((uint)(CurrentLineOffset + X)); Indices.Add((uint)(NextLineOffset + X)); } if (Y < SUBDIVS_THETA - 1) { Indices.Add((uint)(NextLineOffset - 1)); // Degenerate triangle to end the line Indices.Add((uint)NextLineOffset); // Degenerate triangle to start the next line } } m_Prim_Sphere = new Primitive(m_Device, Vertices.Count, VertexP3.FromArray(Vertices.ToArray()), Indices.ToArray(), Primitive.TOPOLOGY.TRIANGLE_STRIP, VERTEX_FORMAT.P3); } // Setup camera m_CB_Camera = new ConstantBuffer <CB_Camera>(m_Device, 0); m_CB_Mesh = new ConstantBuffer <CB_Mesh>(m_Device, 1); m_Camera.CreatePerspectiveCamera(60.0f * (float)Math.PI / 180.0f, (float)panelOutput1.Width / panelOutput1.Height, 0.01f, 40.0f); m_Camera.CameraTransformChanged += new EventHandler(Camera_CameraTransformChanged); m_CameraManipulator.Attach(panelOutput1, m_Camera); m_CameraManipulator.InitializeCamera(4.0f * float3.UnitZ, float3.Zero, float3.UnitY); // Build SH { const int SUBDIVS_THETA = 80; const int SUBDIVS_PHI = 160; const double f0 = 0.28209479177387814347403972578039; // 0.5 / sqrt(PI); const double f1 = 0.48860251190291992158638462283835; // 0.5 * sqrt(3/PI); const double f2 = 1.09254843059207907054338570580270; // 0.5 * sqrt(15/PI); const double f3 = 0.31539156525252000603089369029571; // 0.25 * sqrt(5.PI); double[] SH = new double[9]; double[] DirectionSH = new double[9]; double[] PreciseDirectionSH = new double[9]; double[] SumDirectionSH = new double[9]; double[] SumPreciseDirectionSH = new double[9]; for (int Y = 0; Y < SUBDIVS_THETA; Y++) { for (int X = 0; X < SUBDIVS_PHI; X++) { double Theta = 2.0 * Math.Acos(Math.Sqrt(1.0 - (Y + WMath.SimpleRNG.GetUniform()) / SUBDIVS_THETA)); double Phi = 2.0 * Math.PI * (X + WMath.SimpleRNG.GetUniform()) / SUBDIVS_PHI; float CosTheta = (float)Math.Cos(Theta); float SinTheta = (float)Math.Sin(Theta); float CosPhi = (float)Math.Cos(Phi); float SinPhi = (float)Math.Sin(Phi); float3 Direction = new float3(SinTheta * CosPhi, SinTheta * SinPhi, CosTheta); // Z up DirectionSH[0] = f0; // l=0 m=0 DirectionSH[1] = f1 * Direction.y; // l=1 m=-1 DirectionSH[2] = f1 * Direction.z; // l=1 m=0 DirectionSH[3] = f1 * Direction.x; // l=1 m=1 DirectionSH[4] = f2 * Direction.x * Direction.y; // l=2 m=-2 DirectionSH[5] = f2 * Direction.y * Direction.z; // l=2 m=-1 DirectionSH[6] = f3 * (3.0 * Direction.z * Direction.z - 1.0); // l=2 m=0 DirectionSH[7] = f2 * Direction.x * Direction.z; // l=2 m=1 DirectionSH[8] = f2 * 0.5 * (Direction.x * Direction.x - Direction.y * Direction.y); // l=2 m=2 for (int i = 0; i < 9; i++) { int l = (int)Math.Floor(Math.Sqrt(i)); int m = i - l * (l + 1); PreciseDirectionSH[i] = SphericalHarmonics.SHFunctions.ComputeSH(l, m, Theta, Phi); SumDirectionSH[i] += DirectionSH[i]; SumPreciseDirectionSH[i] += PreciseDirectionSH[i]; // bool rha = false; // if ( Math.Abs( DirectionSH[i] - PreciseDirectionSH[i] ) > 1e-3 ) { // //throw new Exception( "BRA!" ); // rha = true; // } } // Encode function // double Function = 0.1 + 0.45 * (1.0 - Math.Cos( 2.0 * Theta ) * Math.Cos( 1.0 * Phi )); double Function = 0.5 * (1.0 + Direction.x); for (int i = 0; i < 9; i++) { SH[i] += Function * DirectionSH[i]; } } } // Normalize and store double Normalizer = 4.0 * Math.PI / (SUBDIVS_THETA * SUBDIVS_PHI); for (int i = 0; i < 9; i++) { SH[i] *= Normalizer; SumDirectionSH[i] *= Normalizer; SumPreciseDirectionSH[i] *= Normalizer; } // SphericalHarmonics.SHFunctions.EncodeIntoSH( SH, SUBDIVS_THETA, SUBDIVS_PHI, 1, 3, ( double _Theta, double _Phi ) => { // // double Function = 0.1 + 0.45 * (1.0 - Math.Cos( 2.0 * _Theta ) * Math.Cos( 1.0 * _Phi )); // double Function = Math.Cos( _Phi ); // return Function; // } ); m_CB_Mesh.m.m_SH0.x = (float)SH[0]; m_CB_Mesh.m.m_SH0.y = (float)SH[1]; m_CB_Mesh.m.m_SH0.z = (float)SH[2]; m_CB_Mesh.m.m_SH0.w = (float)SH[3]; m_CB_Mesh.m.m_SH1.x = (float)SH[4]; m_CB_Mesh.m.m_SH1.y = (float)SH[5]; m_CB_Mesh.m.m_SH1.z = (float)SH[6]; m_CB_Mesh.m.m_SH1.w = (float)SH[7]; m_CB_Mesh.m.m_SH2 = (float)SH[8]; } Application.Idle += new EventHandler(Application_Idle); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { m_device.Init(panelOutput.Handle, false, true); } catch (Exception _e) { m_device = null; MessageBox.Show("Failed to initialize DX device!\n\n" + _e.Message, "Area Light Test", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } m_CB_Main = new ConstantBuffer <CB_Main>(m_device, 0); m_CB_Camera = new ConstantBuffer <CB_Camera>(m_device, 1); m_CB_Light = new ConstantBuffer <CB_Light>(m_device, 2); m_CB_TestQuad = new ConstantBuffer <CB_TestQuad>(m_device, 3); try { m_shader_RenderLight = new Shader(m_device, new System.IO.FileInfo("Shaders/RenderLight.hlsl"), VERTEX_FORMAT.P3N3, "VS", null, "PS"); m_shader_RenderScene = new Shader(m_device, new System.IO.FileInfo("Shaders/RenderScene.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS"); m_shader_RenderScene_Reference = new Shader(m_device, new System.IO.FileInfo("Shaders/RenderScene_Reference.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS"); m_shader_RenderDiff = new Shader(m_device, new System.IO.FileInfo("Shaders/RenderDiff.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS"); m_shader_RenderTestQuad = new Shader(m_device, new System.IO.FileInfo("Shaders/RenderTestQuad.hlsl"), VERTEX_FORMAT.Pt4, "VS", null, "PS"); } catch (Exception _e) { MessageBox.Show("Shader failed to compile!\n\n" + _e.Message, "Area Light Test", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } BuildPrimitives(); // Allocate temp targets & false colors spectrum m_RT_temp0 = new Texture2D(m_device, m_device.DefaultTarget.Width, m_device.DefaultTarget.Height, 1, 1, ImageUtility.PIXEL_FORMAT.RGBA32F, ImageUtility.COMPONENT_FORMAT.AUTO, false, false, null); m_RT_temp1 = new Texture2D(m_device, m_device.DefaultTarget.Width, m_device.DefaultTarget.Height, 1, 1, ImageUtility.PIXEL_FORMAT.RGBA32F, ImageUtility.COMPONENT_FORMAT.AUTO, false, false, null); m_tex_FalseColors = Image2Texture(new System.IO.FileInfo("FalseColorsSpectrum.png"), ImageUtility.COMPONENT_FORMAT.UNORM_sRGB); // Setup camera m_camera.CreatePerspectiveCamera((float)(FOV_DEGREES * Math.PI / 180.0), (float)panelOutput.Width / panelOutput.Height, 0.01f, 100.0f); m_manipulator.Attach(panelOutput, m_camera); m_manipulator.InitializeCamera(new float3(0, 1, 4), new float3(0, 1, 0), float3.UnitY); m_manipulator.EnableMouseAction += m_manipulator_EnableMouseAction; // Pre-integrated BRDF tables LoadMSBRDF(new uint[] { 128, 32 }, new System.IO.FileInfo[] { new System.IO.FileInfo("./Tables/MSBRDF_GGX_G2_E128x128.float"), new System.IO.FileInfo("./Tables/MSBRDF_OrenNayar_E32x32.float"), }, new System.IO.FileInfo[] { new System.IO.FileInfo("./Tables/MSBRDF_GGX_G2_Eavg128.float"), new System.IO.FileInfo("./Tables/MSBRDF_OrenNayar_Eavg32.float"), }, out m_tex_MSBRDF_E, out m_tex_MSBRDF_Eavg ); // LTC Tables m_tex_LTC = LoadLTC(new System.IO.FileInfo(@".\Tables\LTC.dds")); m_tex_MS_LTC = LoadMSLTC(new System.IO.FileInfo(@".\Tables\MS_LTC.dds")); // Start game time m_ticks2Seconds = 1.0 / System.Diagnostics.Stopwatch.Frequency; m_stopWatch.Start(); m_startTime = GetGameTime(); m_camera.CameraTransformChanged += new EventHandler(Camera_CameraTransformChanged); Camera_CameraTransformChanged(m_camera, EventArgs.Empty); Application.Idle += new EventHandler(Application_Idle); }