├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── design-change.md │ ├── feature_request.md │ └── re-factor-request.md └── PULL_REQUEST_TEMPLATE │ └── pull_request_template.md ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── Jenkinsfile ├── LICENSE ├── README.md ├── imgui.ini ├── installer.exe ├── resources ├── alien_lights.json ├── shaders │ ├── deferred_composition_pass.hlsl │ ├── deferred_geometry_pass.hlsl │ ├── denoising_SVGF.hlsl │ ├── denoising_reflections.hlsl │ ├── denoising_spatial_reconstruction.hlsl │ ├── dxr_ambient_occlusion.hlsl │ ├── dxr_functions.hlsl │ ├── dxr_global.hlsl │ ├── dxr_pathtracer_accumulation.hlsl │ ├── dxr_pathtracer_entries.hlsl │ ├── dxr_pathtracer_functions.hlsl │ ├── dxr_pathtracer_main.hlsl │ ├── dxr_raytracing.hlsl │ ├── dxr_reflection_entries.hlsl │ ├── dxr_reflection_functions.hlsl │ ├── dxr_reflection_main.hlsl │ ├── dxr_shadow_entries.hlsl │ ├── dxr_shadow_functions.hlsl │ ├── dxr_shadow_main.hlsl │ ├── dxr_structs.hlsl │ ├── dxr_texture_lod.hlsl │ ├── fullscreen_quad.hlsl │ ├── generate_mips_cs.hlsl │ ├── lighting.hlsl │ ├── material_util.hlsl │ ├── math.hlsl │ ├── pbr_brdf_lut.hlsl │ ├── pbr_cubemap_conversion.hlsl │ ├── pbr_cubemap_convolution.hlsl │ ├── pbr_prefilter_env_map.hlsl │ ├── pbr_util.hlsl │ ├── pp_bloom_blur.hlsl │ ├── pp_bloom_blur_horizontal.hlsl │ ├── pp_bloom_blur_vertical.hlsl │ ├── pp_bloom_composition.hlsl │ ├── pp_bloom_extract_bright.hlsl │ ├── pp_bloom_util.hlsl │ ├── pp_dof_bokeh.hlsl │ ├── pp_dof_bokeh_post_filter.hlsl │ ├── pp_dof_coc.hlsl │ ├── pp_dof_composition.hlsl │ ├── pp_dof_compute_near_mask.hlsl │ ├── pp_dof_dilate.hlsl │ ├── pp_dof_downscale.hlsl │ ├── pp_dof_properties.hlsl │ ├── pp_dof_util.hlsl │ ├── pp_fxaa.hlsl │ ├── pp_hdr_util.hlsl │ ├── pp_tonemapping.hlsl │ ├── pp_util.hlsl │ └── rand_util.hlsl ├── sponza_lights.json └── viknell_lights.json ├── scripts └── JenkinsWebhook.bat ├── src ├── constant_buffer_pool.cpp ├── constant_buffer_pool.hpp ├── d3d12 │ ├── d3d12_acceleration_structure..cpp │ ├── d3d12_command_list.cpp │ ├── d3d12_command_queue.cpp │ ├── d3d12_constant_buffer_pool.cpp │ ├── d3d12_constant_buffer_pool.hpp │ ├── d3d12_defines.hpp │ ├── d3d12_descriptor_heap.cpp │ ├── d3d12_descriptors_allocations.cpp │ ├── d3d12_descriptors_allocations.hpp │ ├── d3d12_device.cpp │ ├── d3d12_dynamic_descriptor_heap.cpp │ ├── d3d12_dynamic_descriptor_heap.hpp │ ├── d3d12_enums.hpp │ ├── d3d12_fence.cpp │ ├── d3d12_functions.hpp │ ├── d3d12_heap.cpp │ ├── d3d12_indirect_command_buffer.cpp │ ├── d3d12_material_pool.cpp │ ├── d3d12_material_pool.hpp │ ├── d3d12_model_pool.cpp │ ├── d3d12_model_pool.hpp │ ├── d3d12_pipeline_state.cpp │ ├── d3d12_readback_buffer.cpp │ ├── d3d12_render_target.cpp │ ├── d3d12_render_window.cpp │ ├── d3d12_renderer.cpp │ ├── d3d12_renderer.hpp │ ├── d3d12_resource_pool_texture.cpp │ ├── d3d12_resource_pool_texture.hpp │ ├── d3d12_root_signature.cpp │ ├── d3d12_rt_descriptor_heap.cpp │ ├── d3d12_rt_descriptor_heap.hpp │ ├── d3d12_settings.hpp │ ├── d3d12_shader.cpp │ ├── d3d12_shader_table.cpp │ ├── d3d12_staging_buffer.cpp │ ├── d3d12_state_object.cpp │ ├── d3d12_structs.hpp │ ├── d3d12_structured_buffer.cpp │ ├── d3d12_structured_buffer_pool.cpp │ ├── d3d12_structured_buffer_pool.hpp │ ├── d3d12_texture_resources.hpp │ ├── d3d12_textures.cpp │ ├── d3d12_viewport.cpp │ └── d3dx12.hpp ├── engine_registry.cpp ├── engine_registry.hpp ├── entry.hpp ├── frame_graph │ └── frame_graph.hpp ├── id_factory.cpp ├── id_factory.hpp ├── imgui │ ├── ImGuizmo.cpp │ ├── ImGuizmo.h │ ├── imconfig.hpp │ ├── imgui.cpp │ ├── imgui.hpp │ ├── imgui_draw.cpp │ ├── imgui_impl_dx12.cpp │ ├── imgui_impl_dx12.hpp │ ├── imgui_impl_win32.cpp │ ├── imgui_impl_win32.hpp │ ├── imgui_internal.hpp │ ├── imgui_widgets.cpp │ ├── imstb_rectpack.hpp │ ├── imstb_textedit.hpp │ └── imstb_truetype.hpp ├── imgui_graphics_settings.hpp ├── imgui_tools.cpp ├── imgui_tools.hpp ├── material_pool.cpp ├── material_pool.hpp ├── model_loader.cpp ├── model_loader.hpp ├── model_loader_assimp.cpp ├── model_loader_assimp.hpp ├── model_loader_tinygltf.cpp ├── model_loader_tinygltf.hpp ├── model_pool.cpp ├── model_pool.hpp ├── pipeline_registry.cpp ├── pipeline_registry.hpp ├── platform_independend_structs.hpp ├── registry.hpp ├── render_tasks │ ├── d3d12_accumulation.hpp │ ├── d3d12_ansel.hpp │ ├── d3d12_bloom_composition.hpp │ ├── d3d12_bloom_extract_bright.hpp │ ├── d3d12_bloom_horizontal_blur.hpp │ ├── d3d12_bloom_vertical_blur.hpp │ ├── d3d12_brdf_lut_precalculation.hpp │ ├── d3d12_build_acceleration_structures.hpp │ ├── d3d12_cubemap_convolution.hpp │ ├── d3d12_deferred_composition.cpp │ ├── d3d12_deferred_composition.hpp │ ├── d3d12_deferred_main.hpp │ ├── d3d12_deferred_render_target_copy.hpp │ ├── d3d12_dof_bokeh.hpp │ ├── d3d12_dof_bokeh_postfilter.hpp │ ├── d3d12_dof_coc.hpp │ ├── d3d12_dof_composition.hpp │ ├── d3d12_dof_compute_near_mask.hpp │ ├── d3d12_dof_dilate_flatten.hpp │ ├── d3d12_dof_dilate_flatten_second_pass.hpp │ ├── d3d12_dof_dilate_near.hpp │ ├── d3d12_down_scale.hpp │ ├── d3d12_equirect_to_cubemap.hpp │ ├── d3d12_hbao.hpp │ ├── d3d12_imgui_render_task.hpp │ ├── d3d12_path_tracer.hpp │ ├── d3d12_post_processing.hpp │ ├── d3d12_raytracing_task.hpp │ ├── d3d12_reflection_denoiser.hpp │ ├── d3d12_rt_hybrid_helpers.hpp │ ├── d3d12_rt_reflection_task.hpp │ ├── d3d12_rt_shadow_task.hpp │ ├── d3d12_rtao_task.hpp │ ├── d3d12_shadow_denoiser_task.hpp │ └── d3d12_spatial_reconstruction.hpp ├── renderer.cpp ├── renderer.hpp ├── resource_pool_texture.cpp ├── resource_pool_texture.hpp ├── root_signature_registry.cpp ├── root_signature_registry.hpp ├── rt_pipeline_registry.cpp ├── rt_pipeline_registry.hpp ├── scene_graph │ ├── camera_node.cpp │ ├── camera_node.hpp │ ├── light_node.cpp │ ├── light_node.hpp │ ├── mesh_node.cpp │ ├── mesh_node.hpp │ ├── node.cpp │ ├── node.hpp │ ├── scene_graph.cpp │ ├── scene_graph.hpp │ ├── skybox_node.cpp │ └── skybox_node.hpp ├── settings.hpp ├── shader_registry.cpp ├── shader_registry.hpp ├── structs.hpp ├── structured_buffer_pool.cpp ├── structured_buffer_pool.hpp ├── util │ ├── aabb.cpp │ ├── aabb.hpp │ ├── bitmap_allocator.hpp │ ├── defines.hpp │ ├── delegate.hpp │ ├── file_watcher.cpp │ ├── file_watcher.hpp │ ├── log.cpp │ ├── log.hpp │ ├── logfile_handler.cpp │ ├── logfile_handler.hpp │ ├── named_type.hpp │ ├── pair_hash.hpp │ ├── strings.hpp │ ├── thread_pool.hpp │ └── user_literals.hpp ├── version.hpp ├── vertex.hpp ├── window.cpp ├── window.hpp ├── wisp.hpp └── wisprenderer_export.hpp ├── tests ├── CMakeLists.txt ├── common │ ├── scene.cpp │ └── scene.hpp ├── demo │ ├── debug_camera.hpp │ ├── demo.cpp │ ├── demo_frame_graphs.hpp │ ├── engine_interface.hpp │ ├── physics_engine.cpp │ ├── physics_engine.hpp │ ├── physics_node.cpp │ ├── physics_node.hpp │ ├── scene_alien.cpp │ ├── scene_alien.hpp │ ├── scene_emibl.cpp │ ├── scene_emibl.hpp │ ├── scene_sponza.cpp │ ├── scene_sponza.hpp │ ├── scene_viknell.cpp │ ├── scene_viknell.hpp │ ├── spline_library │ │ ├── LICENSE │ │ ├── spline.h │ │ ├── splines │ │ │ ├── cubic_hermite_spline.h │ │ │ ├── generic_b_spline.h │ │ │ ├── natural_spline.h │ │ │ ├── quintic_hermite_spline.h │ │ │ ├── uniform_cr_spline.h │ │ │ └── uniform_cubic_bspline.h │ │ ├── utils │ │ │ ├── arclength.h │ │ │ ├── calculus.h │ │ │ ├── linearalgebra.h │ │ │ ├── nanoflann.hpp │ │ │ ├── spline_common.h │ │ │ ├── splineinverter.h │ │ │ └── splinesample_adaptor.h │ │ └── vector.h │ ├── spline_node.cpp │ └── spline_node.hpp └── graphics_benchmark │ ├── frame_graphs.cpp │ ├── frame_graphs.hpp │ ├── graphics_benchmark.cpp │ ├── spheres_scene.cpp │ └── spheres_scene.hpp └── wisp.version /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behaviour: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behaviour** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Version [e.g. 22] 29 | - Hardware [e.g. CPU:6700k, GPU:RTX 2080ti, RAM:1GB] 30 | 31 | **Additional context** 32 | Add any other context about the problem here. 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/design-change.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Design change 3 | about: Suggest a design change for the project 4 | title: '' 5 | labels: design change 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your design request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or designs you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/re-factor-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Re-factor request 3 | about: Suggest a re-factor of code for the project 4 | title: '' 5 | labels: code change 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the request here. 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/pull_request_template.md: -------------------------------------------------------------------------------- 1 | **Description** 2 | Give a clear description of the changes 3 | 4 | **Issues** 5 | reference related issues if any 6 | 7 | **Possible conflicts** 8 | list any possible conflicts 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /build_vs2017_arm/ 3 | /build_vs2017_win64/ 4 | /build_vs2019_win64/ 5 | /build_vs2019_win32/ 6 | /build_vs2017_win32/ 7 | *.swp 8 | *.swo 9 | /cmake-build-debug/ 10 | /.idea/ 11 | perf_framerate.txt 12 | *.dll 13 | *.lib 14 | /resources/models 15 | /resources/materials 16 | /deps/ansel/ 17 | /deps/hbao+/ 18 | /benchmark_images/ 19 | /CrashPadDB/ 20 | /logs/ 21 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "deps/fmt"] 2 | path = deps/fmt 3 | url = https://github.com/fmtlib/fmt.git 4 | [submodule "deps/DirectXTex"] 5 | path = deps/DirectXTex 6 | url = https://github.com/TeamWisp/DirectXTex.git 7 | branch = master 8 | [submodule "deps/assimp"] 9 | path = deps/assimp 10 | url = https://github.com/assimp/assimp 11 | [submodule "deps/fallback"] 12 | path = deps/fallback 13 | url = https://github.com/TeamWisp/DXR-Fallback-Layer.git 14 | [submodule "deps/Wisp-LFS"] 15 | path = deps/Wisp-LFS 16 | url = https://github.com/TeamWisp/Wisp-LFS.git 17 | [submodule "deps/crashpad"] 18 | path = deps/crashpad 19 | url = https://github.com/TeamWisp/Crashpad.git 20 | [submodule "deps/tinygltf"] 21 | path = deps/tinygltf 22 | url = https://github.com/syoyo/tinygltf 23 | [submodule "deps/bullet3"] 24 | path = deps/bullet3 25 | url = https://github.com/TeamWisp/bullet3 26 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at viktorzoutman@vzout.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent any 3 | stages { 4 | stage('Install'){ 5 | steps{ 6 | echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL}" 7 | bat '''cd "%WORKSPACE%\\Scripts" 8 | call JenkinsWebhook.bat ":bulb: Building: %JOB_NAME%. Jenkins build nr: %BUILD_NUMBER%" 9 | cd "%WORKSPACE% 10 | install -remote "%WORKSPACE%" 11 | if errorlevel 1 ( 12 | cd "%WORKSPACE%\\Scripts" 13 | JenkinsWebhook ":x: %JOB_NAME% Build Failed!! Jenskins build nr: %BUILD_NUMBER% - install failed" 14 | EXIT 1 15 | )''' 16 | } 17 | } 18 | stage('Build') { 19 | steps { 20 | /*bat ''' 21 | cd "%WORKSPACE%" 22 | cmake --build ./build_vs2017_win32 23 | if errorlevel 1 ( 24 | cd "%WORKSPACE%\\Scripts" 25 | JenkinsWebhook ":x: %JOB_NAME% Build Failed!! Jenskins build nr: %BUILD_NUMBER% - 32bit build failed" 26 | EXIT 1 27 | ) 28 | '''*/ 29 | 30 | bat''' 31 | cd "%WORKSPACE%" 32 | cmake --build ./build_vs2017_win64 33 | if errorlevel 1 ( 34 | cd "%WORKSPACE%\\Scripts" 35 | JenkinsWebhook ":x: %JOB_NAME% Build Failed!! Jenskins build nr: %BUILD_NUMBER% - 64bit-debug build failed" 36 | EXIT 1 37 | ) 38 | ''' 39 | 40 | bat''' 41 | cd "%WORKSPACE%" 42 | cmake --build ./build_vs2017_win64 --config Release 43 | if errorlevel 1 ( 44 | cd "%WORKSPACE%\\Scripts" 45 | JenkinsWebhook ":x: %JOB_NAME% Build Failed!! Jenskins build nr: %BUILD_NUMBER% - 64bit-release build failed" 46 | EXIT 1 47 | ) 48 | ''' 49 | } 50 | } 51 | stage('test'){ 52 | steps{ 53 | script{ 54 | def has_failed = false 55 | try{ 56 | bat''' 57 | cd "%WORKSPACE%" 58 | cd build_vs2017_win64/bin/debug 59 | WispTest.exe 60 | if errorlevel 1 ( 61 | EXIT 1 62 | ) 63 | ''' 64 | } 65 | catch( exc ){ 66 | has_failed = true 67 | bat''' 68 | cd "%WORKSPACE%\\Scripts" 69 | JenkinsWebhook ":x: %JOB_NAME% Build Failed!! Jenskins build nr: %BUILD_NUMBER% - 64bit-debug Tests failed" 70 | ''' 71 | } 72 | try{ 73 | bat''' 74 | cd "%WORKSPACE%" 75 | cd build_vs2017_win64/bin/release 76 | WispTest.exe 77 | if errorlevel 1 ( 78 | EXIT 1 79 | ) 80 | ''' 81 | } 82 | catch( exc ){ 83 | has_failed = true 84 | bat''' 85 | cd "%WORKSPACE%\\Scripts" 86 | JenkinsWebhook ":x: %JOB_NAME% Build Failed!! Jenskins build nr: %BUILD_NUMBER% - 64bit-release Tests failed" 87 | ''' 88 | } 89 | if(has_failed){ 90 | EXIT 1 91 | } 92 | } 93 | } 94 | } 95 | stage('finalize'){ 96 | steps{ 97 | bat ''' 98 | rem mkdir builds 99 | rem move ./RayTracingLib/Debug "./builds/build_%BUILD_NUMBER%" 100 | cd "%WORKSPACE%\\scripts 101 | call "JenkinsWebhook.bat" ":white_check_mark: %JOB_NAME% Build Succesfull!! Jenkins build nr: %BUILD_NUMBER%" 102 | ''' 103 | } 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /installer.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeamWisp/WispRenderer/1f1493f9c9038dcd226c44fe154078a00168c3d9/installer.exe -------------------------------------------------------------------------------- /resources/alien_lights.json: -------------------------------------------------------------------------------- 1 | { 2 | "lights": [ 3 | { 4 | "angle": 69.0, 5 | "color": [ 6 | 0.0, 7 | 7.843137264251709, 8 | 11.764705657958984 9 | ], 10 | "pos": [ 11 | 0.5994455218315125, 12 | 1.0072081089019775, 13 | 0.7158395648002625, 14 | 0.0 15 | ], 16 | "radius": 200.0, 17 | "rot": [ 18 | -0.1899939924478531, 19 | 0.02998405694961548, 20 | 0.0, 21 | 0.0 22 | ], 23 | "size": 0.0872664600610733, 24 | "type": 0 25 | }, 26 | { 27 | "angle": 0.6981316804885864, 28 | "color": [ 29 | 1.0, 30 | 0.9999899864196777, 31 | 0.9999899864196777 32 | ], 33 | "pos": [ 34 | 0.8884486556053162, 35 | 1.0663642883300781, 36 | 0.0, 37 | 0.0 38 | ], 39 | "radius": 0.0, 40 | "rot": [ 41 | 0.0, 42 | 0.0, 43 | 0.0, 44 | 0.0 45 | ], 46 | "size": 0.0, 47 | "type": 0 48 | } 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /resources/shaders/dxr_functions.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __DXR_FUNCTIONS_HLSL__ 17 | #define __DXR_FUNCTIONS_HLSL__ 18 | 19 | float3 HitAttribute(float3 a, float3 b, float3 c, BuiltInTriangleIntersectionAttributes attr) 20 | { 21 | float3 vertexAttribute[3]; 22 | vertexAttribute[0] = a; 23 | vertexAttribute[1] = b; 24 | vertexAttribute[2] = c; 25 | 26 | return vertexAttribute[0] + 27 | attr.barycentrics.x * (vertexAttribute[1] - vertexAttribute[0]) + 28 | attr.barycentrics.y * (vertexAttribute[2] - vertexAttribute[0]); 29 | } 30 | 31 | uint3 Load3x32BitIndices(ByteAddressBuffer buffer, uint offsetBytes) 32 | { 33 | // Load first 2 indices 34 | return buffer.Load3(offsetBytes); 35 | } 36 | 37 | // Retrieve hit world position. 38 | float3 HitWorldPosition() 39 | { 40 | return WorldRayOrigin() + RayTCurrent() * WorldRayDirection(); 41 | } 42 | 43 | float3 unpack_position(float2 uv, float depth, float4x4 inv_vp) 44 | { 45 | // Get world space position 46 | const float4 ndc = float4(uv * 2.0 - 1.0, depth, 1.0); 47 | float4 wpos = mul(inv_vp, ndc); 48 | return (wpos.xyz / wpos.w).xyz; 49 | } 50 | 51 | float3 CalcPeturbedNormal(float3 normal, float3 normal_map, float3 tangent, float3 bitangent, float3 V, out float3 world_normal) 52 | { 53 | float3x4 object_to_world = ObjectToWorld3x4(); 54 | float3 N = normalize(mul(object_to_world, float4(normal, 0))); 55 | float3 T = normalize(mul(object_to_world, float4(tangent, 0))); 56 | #ifndef CALC_BITANGENT 57 | const float3 B = normalize(mul(object_to_world, float4(bitangent, 0))); 58 | #else 59 | T = normalize(T - dot(T, N) * N); 60 | float3 B = cross(N, T); 61 | #endif 62 | const float3x3 TBN = float3x3(T, B, N); 63 | 64 | float3 fN = normalize(mul(normal_map, TBN)); 65 | 66 | world_normal = N; 67 | 68 | return fN; 69 | } 70 | 71 | float3 CalcPeturbedNormal(float3 normal, float3 normal_map, float3 tangent, float3 bitangent, float3 V) 72 | { 73 | float3 temp = 0; 74 | return CalcPeturbedNormal(normal, normal_map, tangent, bitangent, V, temp); 75 | } 76 | 77 | 78 | #endif //__DXR_FUNCTIONS_HLSL__ 79 | -------------------------------------------------------------------------------- /resources/shaders/dxr_global.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __DXR_GLOBAL_HLSL__ 17 | #define __DXR_GLOBAL_HLSL__ 18 | 19 | #define MAX_RECURSION 2 20 | //#define FOUR_X_A 21 | //#define PATH_TRACING 22 | //#define DEPTH_OF_FIELD 23 | #define EPSILON 0.1 24 | #define SOFT_SHADOWS 25 | #define MAX_SHADOW_SAMPLES 1 26 | 27 | //#define PERFECT_MIRROR_REFLECTIONS 28 | #define GROUND_TRUTH_REFLECTIONS 29 | #define MAX_GT_REFLECTION_SAMPLES 4 30 | //#define DISABLE_SPATIAL_RECONSTRUCTION 31 | 32 | #define RUSSIAN_ROULETTE 33 | #define NO_PATH_TRACED_NORMALS 34 | #define CALC_BITANGENT // calculate bitangent in the shader instead of using the bitangent uploaded 35 | 36 | #ifdef FALLBACK 37 | #undef MAX_RECURSION 38 | #define MAX_RECURSION 1 39 | 40 | #undef GROUND_TRUTH_REFLECTIONS 41 | #undef MAX_GT_REFLECTION_SAMPLES 42 | #define MAX_GT_REFLECTION_SAMPLES 2 43 | 44 | //#define NO_SHADOWS 45 | #endif 46 | 47 | RaytracingAccelerationStructure Scene : register(t0, space0); 48 | 49 | #endif //__DXR_GLOBAL_HLSL__ 50 | -------------------------------------------------------------------------------- /resources/shaders/dxr_pathtracer_accumulation.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __DXR_PATHTRACER_ACCUMULATION_HLSL__ 17 | #define __DXR_PATHTRACER_ACCUMULATION_HLSL__ 18 | 19 | #include "pp_util.hlsl" 20 | #include "pp_hdr_util.hlsl" 21 | 22 | Texture2D input : register(t0); 23 | RWTexture2D output : register(u0); 24 | SamplerState s0 : register(s0); 25 | 26 | cbuffer Properties : register(b0) 27 | { 28 | float frame_idx; 29 | }; 30 | 31 | 32 | [numthreads(16, 16, 1)] 33 | void main(uint3 DTid : SV_DispatchThreadID) 34 | { 35 | float4 current = input[DTid.xy]; // Last path tracer result 36 | float4 prev = output[DTid.xy]; // Previous path tracer output 37 | 38 | float accum_count = frame_idx; // 0 to x, the number of times the accumulation has ran. 39 | 40 | float4 color = (accum_count * prev + current) / (accum_count + 1); // accumulate 41 | 42 | output[DTid.xy] = color; // update the output with the accumulated result. 43 | } 44 | 45 | #endif //__DXR_PATHTRACER_ACCUMULATION_HLSL__ -------------------------------------------------------------------------------- /resources/shaders/dxr_shadow_entries.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __DXR_SHADOW_ENTRIES_HLSL__ 17 | #define __DXR_SHADOW_ENTRIES_HLSL__ 18 | 19 | #include "pbr_util.hlsl" 20 | #include "material_util.hlsl" 21 | 22 | // Definitions for: 23 | // - Vertex, Material, Offset 24 | // - Ray, RayCone, ReflectionHitInfo 25 | #include "dxr_structs.hlsl" 26 | 27 | [shader("closesthit")] 28 | void ShadowClosestHitEntry(inout ShadowHitInfo hit, Attributes bary) 29 | { 30 | hit.is_hit = true; 31 | } 32 | 33 | [shader("miss")] 34 | void ShadowMissEntry(inout ShadowHitInfo hit : SV_RayPayload) 35 | { 36 | hit.is_hit = false; 37 | } 38 | 39 | #endif //__DXR_SHADOW_ENTRIES_HLSL__ -------------------------------------------------------------------------------- /resources/shaders/dxr_shadow_functions.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __DXR_SHADOWS_FUNCTIONS__ 17 | #define __DXR_SHADOWS_FUNCTIONS__ 18 | 19 | #include "dxr_global.hlsl" 20 | #include "dxr_structs.hlsl" 21 | 22 | bool TraceShadowRay(float3 origin, float3 direction, float far, uint calling_pass, unsigned int depth) 23 | { 24 | if (depth >= MAX_RECURSION) 25 | { 26 | return false; 27 | } 28 | 29 | // Define a ray, consisting of origin, direction, and the min-max distance values 30 | RayDesc ray; 31 | ray.Origin = origin; 32 | ray.Direction = direction; 33 | ray.TMin = 0; 34 | ray.TMax = far; 35 | 36 | ShadowHitInfo payload = { false, 0 }; 37 | 38 | uint ray_contr_idx = 1; 39 | uint miss_idx = 1; 40 | 41 | if (calling_pass == CALLINGPASS_SHADOWS) 42 | { 43 | ray_contr_idx = 0; 44 | miss_idx = 0; 45 | } 46 | 47 | // Trace the ray 48 | TraceRay( 49 | Scene, 50 | RAY_FLAG_NONE, 51 | ~0, // InstanceInclusionMask 52 | ray_contr_idx, // RayContributionToHitGroupIndex 53 | 0, // MultiplierForGeometryContributionToHitGroupIndex 54 | miss_idx, // miss shader index is set to idx but can probably be anything. 55 | ray, 56 | payload); 57 | 58 | return payload.is_hit; 59 | } 60 | 61 | // Get shadow factor 62 | float GetShadowFactor(float3 wpos, float3 light_dir, float light_size, float t_max, uint sample_count, uint depth, uint calling_pass, inout uint rand_seed) 63 | { 64 | float shadow_factor = 0.0f; 65 | 66 | #ifdef SOFT_SHADOWS 67 | for (uint i = 0; i < sample_count; ++i) 68 | { 69 | //float3 offset = normalize(float3(nextRand(rand_seed), nextRand(rand_seed), nextRand(rand_seed))) - 0.5; 70 | float3 dir = perturbDirectionVector(rand_seed, light_dir, light_size); 71 | float3 ray_direction = normalize(dir); 72 | 73 | bool shadow = TraceShadowRay(wpos, ray_direction, t_max, calling_pass, depth); 74 | 75 | shadow_factor += lerp(1.0, 0.0, shadow); 76 | } 77 | 78 | shadow_factor /= float(sample_count); 79 | 80 | #else //SOFT_SHADOWS 81 | 82 | bool shadow = TraceShadowRay(wpos, light_dir, t_max, calling_pass, depth); 83 | 84 | shadow_factor = !shadow; 85 | 86 | #endif //SOFT_SHADOWS 87 | 88 | return shadow_factor; 89 | } 90 | 91 | #endif //__DXR_SHADOWS_FUNCTIONS__ -------------------------------------------------------------------------------- /resources/shaders/dxr_structs.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __DXR_STRUCTS_HLSL__ 17 | #define __DXR_STRUCTS_HLSL__ 18 | 19 | struct Vertex 20 | { 21 | float3 pos; 22 | float2 uv; 23 | float3 normal; 24 | float3 tangent; 25 | float3 bitangent; 26 | }; 27 | 28 | struct MaterialData 29 | { 30 | float3 color; 31 | float metallic; 32 | 33 | float roughness; 34 | float emissive_multiplier; 35 | float is_double_sided; 36 | float use_alpha_masking; 37 | 38 | float albedo_uv_scale; 39 | float normal_uv_scale; 40 | float roughness_uv_scale; 41 | float metallic_uv_scale; 42 | 43 | float emissive_uv_scale; 44 | float ao_uv_scale; 45 | float padding; 46 | uint flags; 47 | }; 48 | 49 | struct Material 50 | { 51 | uint albedo_id; 52 | uint normal_id; 53 | uint roughness_id; 54 | uint metalicness_id; 55 | uint emissive_id; 56 | uint ao_id; 57 | float2 padding; 58 | 59 | MaterialData data; 60 | }; 61 | 62 | struct Offset 63 | { 64 | uint material_idx; 65 | uint idx_offset; 66 | uint vertex_offset; 67 | }; 68 | 69 | struct Ray 70 | { 71 | float3 origin; 72 | float3 direction; 73 | }; 74 | 75 | struct RayCone 76 | { 77 | float width; 78 | float spread_angle; 79 | }; 80 | 81 | struct ReflectionHitInfo 82 | { 83 | float3 origin; 84 | float3 color; 85 | unsigned int seed; 86 | unsigned int depth; 87 | float hit_t; 88 | RayCone cone; 89 | }; 90 | 91 | struct ShadowHitInfo 92 | { 93 | float is_hit; 94 | float thisvariablesomehowmakeshybridrenderingwork_killme; 95 | }; 96 | 97 | struct PathTracingHitInfo 98 | { 99 | float3 color; 100 | unsigned int seed; 101 | float3 origin; 102 | unsigned int depth; 103 | }; 104 | 105 | struct PathTracingHitInfoCone 106 | { 107 | float3 color; 108 | unsigned int seed; 109 | float3 origin; 110 | unsigned int depth; 111 | RayCone cone; 112 | }; 113 | 114 | struct FullRTHitInfo 115 | { 116 | float3 color; 117 | unsigned int seed; 118 | float3 origin; 119 | unsigned int depth; 120 | }; 121 | 122 | struct SurfaceHit 123 | { 124 | float3 pos; 125 | float3 normal; 126 | float surface_spread_angle; 127 | float dist; 128 | }; 129 | 130 | 131 | #endif //__DXR_STRUCTS_HLSL__ 132 | -------------------------------------------------------------------------------- /resources/shaders/fullscreen_quad.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __FULLSCREEN_QUAD_HLSL__ 17 | #define __FULLSCREEN_QUAD_HLSL__ 18 | 19 | struct VS_OUTPUT 20 | { 21 | float4 pos : SV_POSITION; 22 | float2 uv : TEXCOORD; 23 | }; 24 | 25 | VS_OUTPUT main_vs(float2 pos : POSITION) 26 | { 27 | VS_OUTPUT output; 28 | output.pos = float4(pos.x, pos.y, 0.0f, 1.0f); 29 | output.uv = 0.5 * (pos.xy + float2(1.0, 1.0)); 30 | return output; 31 | } 32 | 33 | #endif //__FULLSCREEN_QUAD_HLSL__ -------------------------------------------------------------------------------- /resources/shaders/math.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MATH_HLSL__ 17 | #define __MATH_HLSL__ 18 | 19 | #define M_PI 3.14159265358979 20 | 21 | float linterp(float t) { 22 | return saturate(1.0 - abs(2.0 * t - 1.0)); 23 | } 24 | 25 | float remap(float t, float a, float b) 26 | { 27 | return saturate((t - a) / (b - a)); 28 | } 29 | 30 | float4 spectrum_offset(float t) 31 | { 32 | float4 ret; 33 | float lo = step(t, 0.5); 34 | float hi = 1.0 - lo; 35 | float w = linterp(remap(t, 1.0 / 6.0, 5.0 / 6.0)); 36 | ret = float4(lo, 1.0, hi, 1.) * float4(1.0 - w, w, 1.0 - w, 1.); 37 | 38 | return pow(ret, float4(1.0 / 2.2, 1.0 / 2.2, 1.0 / 2.2, 1.0 / 2.2)); 39 | } 40 | 41 | #endif //__MATH_HLSL__ -------------------------------------------------------------------------------- /resources/shaders/pbr_brdf_lut.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "rand_util.hlsl" 17 | #include "pbr_util.hlsl" 18 | 19 | RWTexture2D output : register(u0); 20 | 21 | float2 IntegrateBRDF(float NdotV, float roughness) 22 | { 23 | float3 V; 24 | V.x = sqrt(1.0f - NdotV * NdotV); 25 | V.y = 0.0f; 26 | V.z = NdotV; 27 | 28 | float A = 0.0f; 29 | float B = 0.0f; 30 | 31 | float3 N = float3(0.0f, 0.0f, 1.0f); 32 | 33 | const uint SAMPLE_COUNT = 1024u; 34 | 35 | for (uint i = 0; i < SAMPLE_COUNT; ++i) 36 | { 37 | float2 Xi = hammersley2d(i, SAMPLE_COUNT); 38 | float3 H = importanceSample_GGX(Xi, roughness, N); 39 | float3 L = normalize(2.0f * dot(V, H) * H - V); 40 | 41 | float NdotL = max(L.z, 0.0f); 42 | float NdotH = max(H.z, 0.0f); 43 | float VdotH = max(dot(V, H), 0.0f); 44 | float NdotV = max(dot(N, V), 0.0f); 45 | 46 | if (NdotL > 0.0f) 47 | { 48 | float G = GeometrySmith_IBL(NdotV, NdotL, roughness); 49 | float G_Vis = (G * VdotH) / (NdotH * NdotV); 50 | float Fc = pow(1.0f - VdotH, 5.0f); 51 | 52 | A += (1.0f - Fc) * G_Vis; 53 | B += Fc * G_Vis; 54 | } 55 | } 56 | 57 | A /= float(SAMPLE_COUNT); 58 | B /= float(SAMPLE_COUNT); 59 | 60 | return float2(A, B); 61 | } 62 | 63 | [numthreads(16, 16, 1)] 64 | void main_cs(uint3 dt_id : SV_DispatchThreadID) 65 | { 66 | float2 screen_size = float2(0.f, 0.f); 67 | output.GetDimensions(screen_size.x, screen_size.y); 68 | 69 | float2 screen_coord = int2(dt_id.x, dt_id.y) + 0.5f; 70 | float2 uv = screen_coord / screen_size; 71 | 72 | output[dt_id.xy] = IntegrateBRDF(uv.x, uv.y); 73 | } 74 | -------------------------------------------------------------------------------- /resources/shaders/pbr_cubemap_conversion.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | struct VS_INPUT 17 | { 18 | float3 pos : POSITION; 19 | //float2 uv : TEXCOORD; 20 | //float3 normal : NORMAL; 21 | //float3 tangent : TANGENT; 22 | //float3 bitangent : BITANGENT; 23 | }; 24 | 25 | struct VS_OUTPUT 26 | { 27 | float4 pos : SV_POSITION; 28 | float3 local_pos : LOCPOS; 29 | }; 30 | 31 | cbuffer PassIndex : register (b0) 32 | { 33 | int idx; 34 | } 35 | 36 | cbuffer CameraProperties : register(b1) 37 | { 38 | float4x4 projection; 39 | float4x4 view[6]; 40 | }; 41 | 42 | VS_OUTPUT main_vs(VS_INPUT input) 43 | { 44 | VS_OUTPUT output; 45 | 46 | output.local_pos = input.pos.xyz; 47 | 48 | float4x4 vp = mul(projection, view[idx]); 49 | output.pos = mul(vp, float4(output.local_pos, 1.0f)); 50 | 51 | return output; 52 | } 53 | 54 | struct PS_OUTPUT 55 | { 56 | float4 color; 57 | }; 58 | 59 | Texture2D equirectangular_texture : register(t0); 60 | SamplerState s0 : register(s0); 61 | 62 | float2 SampleSphericalMap(float3 v) 63 | { 64 | float2 inv_atan = float2(0.1591f, 0.3183f); 65 | 66 | float2 uv = float2(atan2(v.z, v.x), asin(v.y)); 67 | uv *= inv_atan; 68 | uv += 0.5f; 69 | 70 | return uv; 71 | } 72 | 73 | PS_OUTPUT main_ps(VS_OUTPUT input) : SV_TARGET 74 | { 75 | PS_OUTPUT output; 76 | 77 | float2 uv = SampleSphericalMap(normalize(input.local_pos)); 78 | 79 | float3 color = equirectangular_texture.Sample(s0, uv).rgb; 80 | 81 | output.color = float4(color, 1.0f); 82 | 83 | return output; 84 | } 85 | -------------------------------------------------------------------------------- /resources/shaders/pbr_cubemap_convolution.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | struct VS_INPUT 17 | { 18 | float3 pos : POSITION; 19 | float2 uv : TEXCOORD; 20 | float3 normal : NORMAL; 21 | float3 tangent : TANGENT; 22 | float3 bitangent : BITANGENT; 23 | }; 24 | 25 | struct VS_OUTPUT 26 | { 27 | float4 pos : SV_POSITION; 28 | float3 local_pos : LOCPOS; 29 | }; 30 | 31 | cbuffer PassIndex : register (b0) 32 | { 33 | int idx; 34 | } 35 | 36 | cbuffer CameraProperties : register(b1) 37 | { 38 | float4x4 projection; 39 | float4x4 view[6]; 40 | }; 41 | 42 | VS_OUTPUT main_vs(VS_INPUT input) 43 | { 44 | VS_OUTPUT output; 45 | 46 | output.local_pos = input.pos.xyz; 47 | 48 | float4x4 vp = mul(projection, view[idx]); 49 | output.pos = mul(vp, float4(output.local_pos, 1.0f)); 50 | 51 | return output; 52 | } 53 | 54 | struct PS_OUTPUT 55 | { 56 | float4 color; 57 | }; 58 | 59 | TextureCube environment_cubemap : register(t0); 60 | SamplerState s0 : register(s0); 61 | 62 | PS_OUTPUT main_ps(VS_OUTPUT input) : SV_TARGET 63 | { 64 | PS_OUTPUT output; 65 | 66 | const float PI = 3.14159265359f; 67 | 68 | float3 normal = normalize(input.local_pos); 69 | float3 irradiance = float3(0.0f, 0.0f, 0.0f); 70 | 71 | float3 up = float3(0.0f, 1.0f, 0.0f); 72 | float3 right = cross(up, normal); 73 | up = cross(normal, right); 74 | 75 | float sample_delta = 0.025f; 76 | float nr_samples = 0.0f; 77 | 78 | for (float phi = 0.0f; phi < 2.0f * PI; phi += sample_delta) 79 | { 80 | for (float theta = 0.0f; theta < 0.5f * PI; theta += sample_delta) 81 | { 82 | float cos_theta = cos(theta); 83 | float sin_theta = sin(theta); 84 | 85 | float3 tangent_sample = float3(sin_theta * cos(phi), sin_theta * sin(phi), cos_theta); 86 | float3 sample_vec = tangent_sample.x * right + tangent_sample.y * up + tangent_sample.z * normal; 87 | 88 | irradiance += environment_cubemap.Sample(s0, sample_vec).rgb * cos_theta * sin_theta; 89 | 90 | nr_samples++; 91 | } 92 | } 93 | 94 | irradiance = PI * irradiance * (1.0f / float(nr_samples)); 95 | 96 | output.color = float4(irradiance.rgb, 1.0f); 97 | 98 | return output; 99 | } 100 | -------------------------------------------------------------------------------- /resources/shaders/pbr_prefilter_env_map.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "rand_util.hlsl" 17 | #include "pbr_util.hlsl" 18 | 19 | TextureCube src_texture : register(t0); 20 | RWTexture2D dst_texture : register(u0); 21 | SamplerState s0 : register(s0); 22 | 23 | cbuffer CB : register(b0) 24 | { 25 | float2 texture_size; 26 | float2 skybox_res; 27 | float roughness; 28 | uint cubemap_face; 29 | } 30 | 31 | [numthreads(8, 8, 1)] 32 | void main_cs(uint3 dt_id : SV_DispatchThreadID) 33 | { 34 | float2 position = float2(dt_id.xy + 0.5f) / texture_size; 35 | position.y = 1.0f - position.y; 36 | position = (position - 0.5f) * 2.0f; 37 | 38 | float3 direction = float3(0.0f, 0.0f, 0.0f); 39 | float3 up = float3(0.0f, 0.0f, 0.0f); 40 | 41 | switch (cubemap_face) 42 | { 43 | case 0: direction = float3(1.0f, position.y, -position.x); up = float3(0.0f, 1.0f, 0.0f); break; // +X 44 | case 1: direction = float3(-1.0f, position.y, position.x); up = float3(0.0f, 1.0f, 0.0f); break; // -X 45 | case 2: direction = float3(position.x, 1.0f, -position.y); up = float3(0.0f, 0.0f, -1.0f); break; // +Y 46 | case 3: direction = float3(position.x, -1.0f, position.y); up = float3(0.0f, 0.0f, 1.0f); break; // -Y 47 | case 4: direction = float3(position.x, position.y, 1.0f); up = float3(0.0f, 1.0f, 0.0f); break; // +Z 48 | case 5: direction = float3(-position.x, position.y, -1.0f); up = float3(0.0f, 1.0f, 0.0f); break; // -Z 49 | } 50 | 51 | float3 N = normalize(direction); 52 | float3 right = normalize(cross(up, N)); 53 | up = cross(N, right); 54 | 55 | float3 R = N; 56 | float3 V = R; 57 | 58 | const uint SAMPLE_COUNT = 1024u; 59 | float total_weight = 0.0f; 60 | float3 prefiltered_color = float3(0.0f, 0.0f, 0.0f); 61 | 62 | for (uint i = 0u; i < SAMPLE_COUNT; i++) 63 | { 64 | float2 Xi = hammersley2d(i, SAMPLE_COUNT); 65 | float3 H = importanceSample_GGX(Xi, roughness, N); 66 | float3 L = normalize(2.0f * dot(V, H) * H - V); 67 | 68 | float NdotL = max(dot(N, L), 0.0f); 69 | if (NdotL > 0.0f) 70 | { 71 | float NdotH = max(dot(N, H), 0.0f); 72 | float HdotV = max(dot(H, V), 0.0f); 73 | 74 | float D = D_GGX(NdotH, roughness); 75 | 76 | float pdf = D * NdotH / (4.0f * HdotV) + 0.0001f; 77 | 78 | float sa_texel = 4.0f * M_PI / (6.0f * skybox_res.x * skybox_res.y); 79 | float sa_sample = 1.0f / (float(SAMPLE_COUNT) * pdf + 0.0001f); 80 | 81 | float mip_level = roughness == 0.0f ? 0.0f : 0.5f * log2(sa_sample / sa_texel); 82 | 83 | prefiltered_color += src_texture.SampleLevel(s0, L, mip_level).rgb * NdotL; 84 | total_weight += NdotL; 85 | } 86 | } 87 | 88 | prefiltered_color = prefiltered_color / total_weight; 89 | 90 | //Write the final color into the destination texture. 91 | dst_texture[dt_id.xy] = float4(prefiltered_color, 1.0f); 92 | } 93 | -------------------------------------------------------------------------------- /resources/shaders/pp_bloom_blur.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __PP_BLOOM_BLUR_HLSL__ 17 | #define __PP_BLOOM_BLUR_HLSL__ 18 | 19 | #include "pp_dof_util.hlsl" 20 | #include "pp_bloom_util.hlsl" 21 | 22 | Texture2D source : register(t0); 23 | RWTexture2D output : register(u0); 24 | SamplerState s0 : register(s0); 25 | 26 | cbuffer BloomDirection : register(b0) 27 | { 28 | int blur_direction; 29 | float sigma_amt; 30 | }; 31 | 32 | [numthreads(16, 16, 1)] 33 | void main_cs(int3 dispatch_thread_id : SV_DispatchThreadID) 34 | { 35 | float2 screen_size = float2(0.f, 0.f); 36 | output.GetDimensions(screen_size.x, screen_size.y); 37 | 38 | float2 screen_coord = int2(dispatch_thread_id.x, dispatch_thread_id.y) + 0.5f; 39 | float2 texel_size = 1.0f / screen_size; 40 | 41 | float2 uv = (screen_coord) / screen_size; 42 | 43 | float sigma = sigma_amt - 1.0f; 44 | 45 | float2 blur_dir = float2(0.0f, 1.0f); 46 | 47 | if (blur_direction == 1) 48 | { 49 | blur_dir = float2(1.0f, 0.0f); 50 | } 51 | 52 | float4 color = 0; 53 | float weightSum = 0.0f; 54 | for (int i = -7; i < 7; i++) 55 | { 56 | float weight = CalcGaussianWeight(i, sigma); 57 | weightSum += weight; 58 | float2 o_uv = saturate((screen_coord + (blur_dir * i)) / screen_size); 59 | float4 s = source.SampleLevel(s0, o_uv, 0); 60 | color += s * weight; 61 | } 62 | 63 | output[int2(dispatch_thread_id.xy)] = color; 64 | } 65 | 66 | #endif //__PP_BLOOM_BLUR_HLSL__ -------------------------------------------------------------------------------- /resources/shaders/pp_bloom_blur_horizontal.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __PP_BLOOM_BLUR_HORIZONTAL_HLSL__ 17 | #define __PP_BLOOM_BLUR_HORIZONTAL_HLSL__ 18 | 19 | #include "pp_dof_util.hlsl" 20 | #include "pp_bloom_util.hlsl" 21 | 22 | Texture2D source : register(t0); 23 | RWTexture2D output : register(u0); 24 | RWTexture2D output_qes : register(u1); 25 | SamplerState s0 : register(s0); 26 | 27 | cbuffer BloomDirection : register(b0) 28 | { 29 | float2 blur_direction; 30 | float _pad; 31 | float sigma; 32 | }; 33 | 34 | float4 GetBlurFactor(float2 screen_coord, float res_scale) 35 | { 36 | float2 screen_size = float2(0.f, 0.f); 37 | output.GetDimensions(screen_size.x, screen_size.y); 38 | 39 | float2 blur_dir = float2(1.0f, 0.0f); 40 | float r_sigma = 3.0f; 41 | float4 color = 0; 42 | float weightSum = 0.0f; 43 | for (int i = -7; i < 7; i++) 44 | { 45 | float weight = CalcGaussianWeight(i, r_sigma); 46 | weightSum += weight; 47 | float2 o_uv = saturate((screen_coord + (blur_dir * i)) / (screen_size / res_scale)); 48 | float4 s = source.SampleLevel(s0, o_uv, 0); 49 | color += s * weight; 50 | } 51 | 52 | return color; 53 | } 54 | 55 | [numthreads(16, 16, 1)] 56 | void main_cs(int3 dispatch_thread_id : SV_DispatchThreadID) 57 | { 58 | float2 screen_size = float2(0.f, 0.f); 59 | output.GetDimensions(screen_size.x, screen_size.y); 60 | 61 | float2 screen_coord = int2(dispatch_thread_id.x, dispatch_thread_id.y) + 0.5f; 62 | 63 | float4 color = 0; 64 | 65 | if (screen_coord.x > screen_size.x) 66 | { 67 | if (screen_coord.x > (screen_size.x * 1.875f)) 68 | { 69 | color = GetBlurFactor(screen_coord - screen_size * 1.875f, 16.0f); 70 | } 71 | if (screen_coord.x > (screen_size.x * 1.75)) 72 | { 73 | color = GetBlurFactor(screen_coord - screen_size * 1.75f, 8.0f); 74 | } 75 | else if (screen_coord.x > (screen_size.x * 1.5)) 76 | { 77 | color = GetBlurFactor(screen_coord - screen_size * 1.5f, 4.0f); 78 | } 79 | else 80 | { 81 | color = GetBlurFactor(screen_coord - screen_size, 2.0f); 82 | } 83 | 84 | output_qes[screen_coord - int2(screen_size)] = color; 85 | } 86 | else 87 | { 88 | color = GetBlurFactor(screen_coord, 1.0f); 89 | output[screen_coord] = color; 90 | } 91 | } 92 | 93 | 94 | #endif //__PP_BLOOM_BLUR_HORIZONTAL_HLSL__ -------------------------------------------------------------------------------- /resources/shaders/pp_bloom_blur_vertical.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __PP_BLOOM_BLUR_VERTICAL_HLSL__ 17 | #define __PP_BLOOM_BLUR_VERTICAL_HLSL__ 18 | 19 | #include "pp_dof_util.hlsl" 20 | #include "pp_bloom_util.hlsl" 21 | 22 | Texture2D source : register(t0); 23 | Texture2D source_qes : register(t1); 24 | RWTexture2D output : register(u0); 25 | RWTexture2D output_qes : register(u1); 26 | SamplerState s0 : register(s0); 27 | 28 | cbuffer BloomDirection : register(b0) 29 | { 30 | float2 blur_direction; 31 | float _pad; 32 | float sigma; 33 | }; 34 | 35 | 36 | float4 GetBlurFactor(float2 screen_coord, float res_scale) 37 | { 38 | float2 screen_size = float2(0.f, 0.f); 39 | output.GetDimensions(screen_size.x, screen_size.y); 40 | 41 | float2 blur_dir = float2(0.0f, 1.0f); 42 | float r_sigma = 3.0f; 43 | float4 color = 0; 44 | float weightSum = 0.0f; 45 | for (int i = -7; i < 7; i++) 46 | { 47 | float weight = CalcGaussianWeight(i, r_sigma); 48 | weightSum += weight; 49 | float2 o_uv = saturate((screen_coord + (blur_dir * i)) / (screen_size / res_scale)); 50 | float4 s = source.SampleLevel(s0, o_uv, 0); 51 | color += s * weight; 52 | } 53 | 54 | return color; 55 | } 56 | 57 | float4 GetBlurFactorQES(float2 screen_coord) 58 | { 59 | float2 screen_size = float2(0.f, 0.f); 60 | output.GetDimensions(screen_size.x, screen_size.y); 61 | 62 | float2 blur_dir = float2(0.0f, 1.0f); 63 | float r_sigma = 3.0f; 64 | float4 color = 0; 65 | float weightSum = 0.0f; 66 | for (int i = -7; i < 7; i++) 67 | { 68 | float weight = CalcGaussianWeight(i, r_sigma); 69 | weightSum += weight; 70 | float4 s = source_qes[screen_coord + blur_dir * i].rgba; 71 | color += s * weight; 72 | } 73 | 74 | return color; 75 | } 76 | 77 | [numthreads(16, 16, 1)] 78 | void main_cs(int3 dispatch_thread_id : SV_DispatchThreadID) 79 | { 80 | float2 screen_size = float2(0.f, 0.f); 81 | output.GetDimensions(screen_size.x, screen_size.y); 82 | 83 | float2 screen_coord = int2(dispatch_thread_id.x, dispatch_thread_id.y) + 0.5f; 84 | 85 | float4 color = 0; 86 | 87 | if (screen_coord.x > screen_size.x) 88 | { 89 | 90 | color = GetBlurFactorQES(screen_coord - screen_size); 91 | output_qes[screen_coord - int2(screen_size)] = color; 92 | } 93 | else 94 | { 95 | color = GetBlurFactor(screen_coord, 1.0f); 96 | output[screen_coord] = color; 97 | } 98 | } 99 | 100 | #endif //__PP_BLOOM_BLUR_VERTICAL_HLSL__ -------------------------------------------------------------------------------- /resources/shaders/pp_bloom_composition.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __PP_BLOOM_COMPOSITION_HLSL__ 17 | #define __PP_BLOOM_COMPOSITION_HLSL__ 18 | 19 | #include "pp_hdr_util.hlsl" 20 | 21 | Texture2D source_main : register(t0); 22 | Texture2D source_bloom_half : register(t1); 23 | Texture2D source_bloom_qes : register(t2); 24 | RWTexture2D output : register(u0); 25 | SamplerState linear_sampler : register(s0); 26 | SamplerState point_sampler : register(s1); 27 | 28 | cbuffer Bloomproperties : register(b0) 29 | { 30 | int enable_bloom; 31 | }; 32 | 33 | [numthreads(16, 16, 1)] 34 | void main_cs(int3 dispatch_thread_id : SV_DispatchThreadID) 35 | { 36 | float2 screen_size = float2(0.f, 0.f); 37 | output.GetDimensions(screen_size.x, screen_size.y); 38 | 39 | float2 screen_coord = int2(dispatch_thread_id.x, dispatch_thread_id.y) + 0.5f; 40 | float2 texel_size = 1.0f / screen_size; 41 | 42 | float2 uv = screen_coord / screen_size; 43 | float2 uv_half = (screen_coord / 2 ) / screen_size; 44 | float2 uv_quarter = (screen_coord / 4) / screen_size + 0.5f; 45 | float2 uv_eighth = (screen_coord / 8) / screen_size + 0.75f; 46 | 47 | float3 finalcolor = float3(0, 0, 0); 48 | float bloom_intensity = 1.f; 49 | 50 | if (enable_bloom > 0) 51 | { 52 | finalcolor += source_bloom_half.SampleLevel(linear_sampler, uv, 0).rgb; 53 | finalcolor += source_bloom_qes.SampleLevel(linear_sampler, uv_half, 0).rgb; 54 | finalcolor += source_bloom_qes.SampleLevel(linear_sampler, uv_quarter, 0).rgb; 55 | finalcolor += source_bloom_qes.SampleLevel(linear_sampler, uv_eighth, 0).rgb; 56 | 57 | finalcolor *= 0.25f; 58 | } 59 | 60 | finalcolor += source_main.SampleLevel(point_sampler, uv, 0).rgb; 61 | 62 | output[int2(dispatch_thread_id.xy)] = float4(finalcolor, 1.0f); 63 | } 64 | 65 | #endif //__PP_BLOOM_COMPOSITION_HLSL__ -------------------------------------------------------------------------------- /resources/shaders/pp_bloom_extract_bright.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __PP_BLOOM_EXTRACT_BRIGHT_HLSL__ 17 | #define __PP_BLOOM_EXTRACT_BRIGHT_HLSL__ 18 | 19 | #include "pp_dof_util.hlsl" 20 | 21 | Texture2D source : register(t0); 22 | Texture2D g_emissive : register(t1); 23 | Texture2D g_depth : register(t2); 24 | 25 | RWTexture2D output_bright : register(u0); 26 | SamplerState s0 : register(s0); 27 | SamplerState s1 : register(s1); 28 | 29 | 30 | [numthreads(16, 16, 1)] 31 | void main_cs(int3 dispatch_thread_id : SV_DispatchThreadID) 32 | { 33 | float2 screen_size = float2(0.f, 0.f); 34 | output_bright.GetDimensions(screen_size.x, screen_size.y); 35 | 36 | float2 screen_coord = int2(dispatch_thread_id.x, dispatch_thread_id.y) + 0.5f; 37 | float2 uv = screen_coord / screen_size; 38 | 39 | float4 out_bright = float4(0.0f, 0.0f, 0.0f, 1.0f); 40 | float3 final_color = source.SampleLevel(s1, uv, 0).rgb; 41 | 42 | float brightness = dot(final_color, float3(0.2126f, 0.7152f, 0.0722f)); 43 | 44 | for (int i = -1; i < 2; ++i) 45 | { 46 | uv = float2(screen_coord.x + i, screen_coord.y + i) / screen_size; 47 | 48 | if (brightness > 1.0f && g_depth.SampleLevel(s1, uv, 0).r < 1) 49 | { 50 | out_bright = saturate(float4(final_color, 1.0f)); 51 | } 52 | 53 | out_bright += float4(g_emissive.SampleLevel(s0, uv, 0).rgb, 1.0f); 54 | } 55 | 56 | out_bright /= 3; 57 | 58 | output_bright[int2(dispatch_thread_id.xy)] = out_bright; 59 | } 60 | 61 | #endif //__PP_BLOOM_EXTRACT_BRIGHT_HLSL__ -------------------------------------------------------------------------------- /resources/shaders/pp_bloom_util.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __PP_BLOOM_UTIL_HLSL__ 17 | #define __PP_BLOOM_UTIL_HLSL__ 18 | 19 | static const float gaussian_weights[15] = { 0.023089f, 0.034587f, 0.048689f, 0.064408f, 0.080066f, 0.093531f, 0.102673f, 0.105915f, 0.102673f, 0.093531f, 0.080066f, 0.064408f, 0.048689f, 0.034587f, 0.023089f }; 20 | 21 | #endif //__PP_BLOOM_UTIL_HLSL__ -------------------------------------------------------------------------------- /resources/shaders/pp_dof_bokeh_post_filter.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __PP_DOF_BOKEH_POST_FILTER_HLSL__ 17 | #define __PP_DOF_BOKEH_POST_FILTER_HLSL__ 18 | 19 | Texture2D source_near : register(t0); 20 | Texture2D source_far : register(t1); 21 | RWTexture2D output_near : register(u0); 22 | RWTexture2D output_far : register(u1); 23 | SamplerState s0 : register(s0); 24 | SamplerState s1 : register(s1); 25 | 26 | [numthreads(16, 16, 1)] 27 | void main_cs(int3 dispatch_thread_id : SV_DispatchThreadID) 28 | { 29 | float2 screen_size = float2(0.f, 0.f); 30 | output_near.GetDimensions(screen_size.x, screen_size.y); 31 | screen_size -= 1.0f; 32 | 33 | float2 screen_coord = int2(dispatch_thread_id.x, dispatch_thread_id.y); 34 | 35 | 36 | float2 uv = screen_coord / screen_size; 37 | 38 | float nearcoc = source_near.SampleLevel(s1, uv, 0).a; 39 | float farcoc = source_far.SampleLevel(s1, uv, 0).a; 40 | 41 | static const int SampleRadius = 2; 42 | static const int SampleDiameter = SampleRadius * 2 + 1; 43 | 44 | float3 near_color = 0; 45 | float3 far_color = 0; 46 | 47 | [unroll] 48 | for (int y = -SampleRadius; y <= SampleRadius; ++y) 49 | { 50 | [unroll] 51 | for (int x = -SampleRadius; x <= SampleRadius; ++x) 52 | { 53 | near_color += source_near.SampleLevel(s0, (screen_coord + float2(x, y)) / screen_size, 0).rgb; 54 | far_color += source_far.SampleLevel(s0, (screen_coord + float2(x, y)) / screen_size, 0).rgb; 55 | } 56 | } 57 | 58 | near_color /= float(SampleDiameter * SampleDiameter); 59 | far_color /= float(SampleDiameter * SampleDiameter); 60 | 61 | output_near[int2(dispatch_thread_id.xy)] = float4(near_color, nearcoc); 62 | output_far[int2(dispatch_thread_id.xy)] = float4(far_color, farcoc); 63 | } 64 | 65 | #endif //__PP_DOF_BOKEH_POST_FILTER_HLSL__ -------------------------------------------------------------------------------- /resources/shaders/pp_dof_composition.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __PP_DOF_COMPOSITION_HLSL__ 17 | #define __PP_DOF_COMPOSITION_HLSL__ 18 | 19 | #include "pp_dof_properties.hlsl" 20 | 21 | Texture2D source : register(t0); 22 | RWTexture2D output : register(u0); 23 | Texture2D bokeh_near : register(t1); 24 | Texture2D bokeh_far : register(t2); 25 | Texture2D coc_buffer : register(t3); 26 | SamplerState s0 : register(s0); 27 | SamplerState s1 : register(s1); 28 | 29 | float GetDownSampledCoC(float2 uv , float2 texel_size) 30 | { 31 | float4 offset = texel_size.xyxy * float2(-0.5f, 0.5f).xxyy; 32 | float coc0 = coc_buffer.SampleLevel(s1, uv + offset.xy, 0); 33 | float coc1 = coc_buffer.SampleLevel(s1, uv + offset.zy, 0); 34 | float coc2 = coc_buffer.SampleLevel(s1, uv + offset.xw, 0); 35 | float coc3 = coc_buffer.SampleLevel(s1, uv + offset.zw, 0); 36 | 37 | float coc_min = min(min(min(coc0, coc1), coc2), coc3); 38 | float coc_max = max(max(max(coc0, coc1), coc2), coc3); 39 | 40 | float coc = coc_max >= -coc_min ? coc_max : coc_min; 41 | return coc; 42 | } 43 | 44 | [numthreads(16, 16, 1)] 45 | void main_cs(int3 dispatch_thread_id : SV_DispatchThreadID) 46 | { 47 | float2 screen_size = float2(0.f, 0.f); 48 | output.GetDimensions(screen_size.x, screen_size.y); 49 | screen_size -= 1.0f; 50 | 51 | float2 screen_coord = int2(dispatch_thread_id.x, dispatch_thread_id.y); 52 | 53 | 54 | float2 texel_size = 1.0 / screen_size; 55 | float2 uv = (screen_coord) / (screen_size); 56 | 57 | float coc = coc_buffer.SampleLevel(s0, uv, 0); 58 | 59 | float3 original_sample = source.SampleLevel(s0, uv, 0).rgb; 60 | float4 near_sample = bokeh_near.SampleLevel(s1, uv, 0); 61 | float4 far_sample = bokeh_far.SampleLevel(s1, uv, 0); 62 | 63 | float near_w = bokeh_near.SampleLevel(s0, uv, 0).a; 64 | 65 | float3 near = near_sample.rgb; 66 | float3 far = original_sample.rgb; 67 | 68 | if (far_sample.w > 0.0f) 69 | { 70 | far = far_sample.rgb / far_sample.w; 71 | } 72 | 73 | float far_blend = saturate(saturate(coc) * MAXCOCSIZE - 0.5f); 74 | 75 | float3 result = lerp(original_sample, far.rgb, far_blend); 76 | 77 | float near_blend = saturate(near_sample.w * 2.0f); 78 | 79 | result = lerp(result, near.rgb, smoothstep(0.0f, 1.0f, near_blend)); 80 | 81 | output[int2(dispatch_thread_id.xy)] = float4(result, coc); 82 | } 83 | 84 | #endif //__PP_DOF_COMPOSITION_HLSL__ -------------------------------------------------------------------------------- /resources/shaders/pp_dof_compute_near_mask.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | //================================================================================================= 18 | // 19 | // Baking Lab 20 | // by MJP and David Neubelt 21 | // http://mynameismjp.wordpress.com/ 22 | // 23 | // All code licensed under the MIT license 24 | // 25 | //================================================================================================= 26 | 27 | #ifndef __PP_DOF_COMPUTE_NEAR_MASK_HLSL__ 28 | #define __PP_DOF_COMPUTE_NEAR_MASK_HLSL__ 29 | 30 | #include "pp_dof_properties.hlsl" 31 | #include "pp_dof_util.hlsl" 32 | 33 | Texture2D input : register(t0); 34 | RWTexture2D output : register(u0); 35 | SamplerState s0 : register(s0); 36 | 37 | 38 | //================================================================================================= 39 | // Constants 40 | //================================================================================================= 41 | static const uint NumThreads = 16 * 16; 42 | 43 | 44 | 45 | // -- shared memory 46 | groupshared float Samples[NumThreads]; 47 | 48 | //================================================================================================= 49 | // Computes a downscaled mask for the near field 50 | //================================================================================================= 51 | [numthreads(32, 32, 1)] 52 | void main_cs(in uint3 GroupID : SV_GroupID, in uint3 GroupThreadID : SV_GroupThreadID, 53 | in uint ThreadIndex : SV_GroupIndex) 54 | { 55 | uint2 textureSize; 56 | input.GetDimensions(textureSize.x, textureSize.y); 57 | 58 | uint2 samplePos = GroupID.xy * 16 + GroupThreadID.xy; 59 | samplePos = min(samplePos, textureSize - 1); 60 | 61 | float cocSample = input[samplePos].w; 62 | 63 | // -- store in shared memory 64 | Samples[ThreadIndex] = cocSample; 65 | GroupMemoryBarrierWithGroupSync(); 66 | 67 | // -- reduce 68 | [unroll] 69 | for (uint s = NumThreads / 2; s > 0; s >>= 1) 70 | { 71 | if (ThreadIndex < s) 72 | Samples[ThreadIndex] = max(Samples[ThreadIndex], Samples[ThreadIndex + s]); 73 | 74 | GroupMemoryBarrierWithGroupSync(); 75 | } 76 | 77 | if (ThreadIndex == 0) 78 | output[GroupID.xy] = Samples[0]; 79 | } 80 | 81 | #endif //__PP_DOF_COC_HLSL__ -------------------------------------------------------------------------------- /resources/shaders/pp_dof_dilate.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __PP_DOF_DILATE_HLSL__ 17 | #define __PP_DOF_DILATE_HLSL__ 18 | 19 | #include "pp_dof_properties.hlsl" 20 | #include "pp_dof_util.hlsl" 21 | 22 | Texture2D source_near : register(t0); 23 | RWTexture2D output_near : register(u0); 24 | SamplerState s0 : register(s0); 25 | 26 | [numthreads(16, 16, 1)] 27 | void main_cs(int3 dispatch_thread_id : SV_DispatchThreadID) 28 | { 29 | float2 screen_size = float2(0.f, 0.f); 30 | output_near.GetDimensions(screen_size.x, screen_size.y); 31 | screen_size -= 1.0f; 32 | 33 | float2 screen_coord = int2(dispatch_thread_id.x, dispatch_thread_id.y); 34 | 35 | 36 | float2 uv = (screen_coord) / screen_size; 37 | 38 | static const int sample_radius = 3; 39 | 40 | float output = source_near.SampleLevel(s0, uv , 0).r; 41 | 42 | [unroll] 43 | for (int y = -sample_radius; y <= sample_radius; ++y) 44 | { 45 | [unroll] 46 | for (int x = -sample_radius; x <= sample_radius; ++x) 47 | { 48 | output = max(output, source_near.SampleLevel(s0, saturate((screen_coord + float2(x, y)) / screen_size), 0).r); 49 | } 50 | } 51 | 52 | output_near[int2(dispatch_thread_id.xy)] = output; 53 | } 54 | 55 | #endif //__PP_DOF_DILATE_HLSL__ -------------------------------------------------------------------------------- /resources/shaders/pp_dof_downscale.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __PP_DOF_DOWNSCALE_HLSL__ 17 | #define __PP_DOF_DOWNSCALE_HLSL__ 18 | 19 | #include "pp_dof_util.hlsl" 20 | 21 | Texture2D source : register(t0); 22 | RWTexture2D output_near : register(u0); 23 | RWTexture2D output_far : register(u1); 24 | Texture2D cocbuffer : register(t1); 25 | SamplerState s0 : register(s0); 26 | SamplerState s1 : register(s1); 27 | 28 | float GetDownSampledCoC(float2 uv, float2 texelSize) 29 | { 30 | float4 offset = texelSize.xyxy * float2(-0.5f, 0.5f).xxyy; 31 | 32 | float coc0 = cocbuffer.SampleLevel(s1, uv + offset.xy, 0).r; 33 | float coc1 = cocbuffer.SampleLevel(s1, uv + offset.zy, 0).r; 34 | float coc2 = cocbuffer.SampleLevel(s1, uv + offset.xw, 0).r; 35 | float coc3 = cocbuffer.SampleLevel(s1, uv + offset.zw, 0).r; 36 | float coc4 = cocbuffer.SampleLevel(s1, uv, 0).r; 37 | 38 | float cocMin = min(min(min(coc0, coc1), coc2), coc3); 39 | float cocMax = max(max(max(coc0, coc1), coc2), coc3); 40 | 41 | float coc = cocMax >= -cocMin ? cocMax : cocMin; 42 | return coc; 43 | } 44 | 45 | [numthreads(16, 16, 1)] 46 | void main_cs(int3 dispatch_thread_id : SV_DispatchThreadID) 47 | { 48 | float2 screen_size = float2(0.f, 0.f); 49 | output_far.GetDimensions(screen_size.x, screen_size.y); 50 | screen_size -= 1.0f; 51 | 52 | float2 screen_coord = int2(dispatch_thread_id.x, dispatch_thread_id.y); 53 | 54 | 55 | float2 texel_size = 1.0f / screen_size; 56 | float4 offset = texel_size.xyxy * float2(-0.5f, 0.5f).xxyy; 57 | 58 | float2 uv = screen_coord / (screen_size); 59 | 60 | float3 source11 = source.SampleLevel(s0, uv, 0).rgb; 61 | float3 source0 = source.SampleLevel(s0, uv + offset.xy, 0).rgb; 62 | float3 source1 = source.SampleLevel(s0, uv + offset.zy, 0).rgb; 63 | float3 source2 = source.SampleLevel(s0, uv + offset.xw, 0).rgb; 64 | float3 source3 = source.SampleLevel(s0, uv + offset.zw, 0).rgb; 65 | 66 | float3 finalcolor = (source11 + source0 + source1 + source2 + source3) * 0.2f; 67 | finalcolor = source.SampleLevel(s0, uv, 0).rgb; 68 | 69 | float coc = GetDownSampledCoC(uv, texel_size); 70 | 71 | float4 out_near = max(0,float4(finalcolor, 1.0f) * max(-coc, 0.0f)); 72 | out_near.rgb = finalcolor; 73 | 74 | coc = cocbuffer.SampleLevel(s1, uv, 0).r; 75 | float4 out_far = max(0,float4(finalcolor, 1.0f) * max(coc, 0.0f)); 76 | 77 | output_near[int2(dispatch_thread_id.xy)] = out_near; 78 | output_far[int2(dispatch_thread_id.xy)] = out_far; 79 | } 80 | 81 | #endif //__PP_DOF_DOWNSCALE_HLSL__ 82 | -------------------------------------------------------------------------------- /resources/shaders/pp_dof_properties.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __PP_DOF_PROPERTIES_HLSL__ 17 | #define __PP_DOF_PROPERTIES_HLSL__ 18 | 19 | static const float MAXBOKEHSIZE = 21.f; 20 | static const float MAXCOCSIZE = 4.0f; 21 | static const uint NUMDOFSAMPLES = 9; 22 | #endif //__PP_DOF_PROPERTIES_HLSL__ -------------------------------------------------------------------------------- /resources/shaders/pp_dof_util.hlsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeamWisp/WispRenderer/1f1493f9c9038dcd226c44fe154078a00168c3d9/resources/shaders/pp_dof_util.hlsl -------------------------------------------------------------------------------- /resources/shaders/pp_tonemapping.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __PP_TONEMAPPING_HLSL__ 17 | #define __PP_TONEMAPPING_HLSL__ 18 | 19 | #include "pp_util.hlsl" 20 | #include "pp_hdr_util.hlsl" 21 | 22 | Texture2D input : register(t0); 23 | RWTexture2D output : register(u0); 24 | SamplerState s0 : register(s0); 25 | 26 | cbuffer CameraProperties : register(b0) 27 | { 28 | float hdr; 29 | }; 30 | 31 | [numthreads(16, 16, 1)] 32 | void main(uint3 DTid : SV_DispatchThreadID) 33 | { 34 | float2 resolution; 35 | input.GetDimensions(resolution.x, resolution.y); 36 | 37 | float2 uv = (float2(DTid.xy + 0.5f) / resolution); 38 | 39 | float gamma = 2.2; 40 | float exposure = 1; 41 | 42 | float3 color = input.SampleLevel(s0, uv, 0).rgb; 43 | //color = SampleFXAA(input, s0, DTid.xy + 0.5f, resolution); 44 | //uv = ZoomUV(uv, 0.75); 45 | //float3 color = input.SampleLevel(s0, BarrelDistortUV(uv, 2), 0); 46 | //float3 color = ChromaticAberrationV2(input, s0, uv, 0.2, 0.96f).rgb; 47 | 48 | if (hdr == 0) 49 | { 50 | //color = linearToneMapping(color, exposure, gamma); 51 | //color = simpleReinhardToneMapping(color, exposure, gamma); 52 | //color = lumaBasedReinhardToneMapping(color, gamma); 53 | //color = whitePreservingLumaBasedReinhardToneMapping(color, gamma); 54 | //color = RomBinDaHouseToneMapping(color, gamma); 55 | //color = filmicToneMapping(color); 56 | //color = Uncharted2ToneMapping(color, gamma, exposure); 57 | //color = GrayscaleToneMapping(color); 58 | color = ACESToneMapping(color, exposure, gamma); 59 | //color = AllTonemappingAlgorithms(color.rgb, uv.x + uv.y, exposure, gamma); 60 | //color = Vignette(color, uv, 1.5, 0.5, 0.5); 61 | } 62 | 63 | output[DTid.xy] = float4(color, 1); 64 | } 65 | 66 | #endif //__PP_TONEMAPPING_HLSL__ 67 | -------------------------------------------------------------------------------- /resources/shaders/pp_util.hlsl: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __PP_UTIL_HLSL__ 17 | #define __PP_UTIL_HLSL__ 18 | 19 | #include "pp_fxaa.hlsl" 20 | #include "math.hlsl" 21 | 22 | float3 Vignette(float3 input, float2 pos, float radius, float softness, float strength) 23 | { 24 | float len = length(pos * 2 - 1); 25 | float vignette = smoothstep(radius, radius - softness, len); 26 | return lerp(input, input * vignette, strength); 27 | } 28 | 29 | 30 | // Old lens_effects.hlsl file 31 | float2 barrelDistortion(float2 coord, float amt) { 32 | float2 cc = coord - 0.5; 33 | float dist = dot(cc, cc); 34 | return coord + cc * dist * amt; 35 | } 36 | 37 | static const int num_iter = 11; 38 | static const float reci_num_iter_f = 1.0 / float(num_iter); 39 | 40 | // Old naive chromatic aberration. 41 | float4 ChromaticAberration(Texture2D tex, SamplerState s, float2 uv, float strength) { 42 | float2 r_offset = float2(strength, 0); 43 | float2 g_offset = float2(-strength, 0); 44 | float2 b_offset = float2(0, 0); 45 | 46 | float4 r = float4(1, 1, 1, 1); 47 | r.x = tex.SampleLevel(s, uv + r_offset, 0).x; 48 | r.y = tex.SampleLevel(s, uv + g_offset, 0).y; 49 | r.z = tex.SampleLevel(s, uv + b_offset, 0).z; 50 | r.a = tex.SampleLevel(s, uv, 0).a; 51 | 52 | return r; 53 | } 54 | 55 | // Zoom into a image. 56 | float2 ZoomUV(float2 uv, float zoom) 57 | { 58 | return (uv * zoom) + ((1 - (zoom)) / 2); 59 | } 60 | 61 | float4 ChromaticAberrationV2(Texture2D tex, SamplerState s, float2 uv, float strength, float zoom) { 62 | uv = ZoomUV(uv, zoom); 63 | float4 sumcol = 0.0; 64 | float4 sumw = 0.0; 65 | 66 | float2 resolution; 67 | tex.GetDimensions(resolution.x, resolution.y); 68 | 69 | for (int i = 0; i < num_iter; ++i) 70 | { 71 | float t = float(i) * reci_num_iter_f; 72 | float4 w = spectrum_offset(t); 73 | sumw += w; 74 | //sumcol += w * tex.SampleLevel(s, barrelDistortion(uv, 0.6 * strength*t ), 0); 75 | sumcol += w * SampleFXAA(tex, s, barrelDistortion(uv, 0.6 * strength * t) * resolution, resolution); 76 | } 77 | 78 | return sumcol / sumw; 79 | } 80 | 81 | float2 BarrelDistortUV(float2 uv, float kcube) 82 | { 83 | float k = -0.15; 84 | 85 | float r2 = (uv.x - 0.5) * (uv.x - 0.5) + (uv.y - 0.5) * (uv.y - 0.5); 86 | float f = 0; 87 | 88 | //only compute the cubic distortion if necessary 89 | if (kcube == 0.0) 90 | { 91 | f = 1 + r2 * k; 92 | } 93 | else 94 | { 95 | f = 1 + r2 * (k + kcube * sqrt(r2)); 96 | }; 97 | 98 | // get the right pixel for the current position 99 | float x = f * (uv.x - 0.5) + 0.5; 100 | float y = f * (uv.y - 0.5) + 0.5; 101 | 102 | return float2(x, y); 103 | } 104 | 105 | #endif //__PP_UTIL_HLSL__ -------------------------------------------------------------------------------- /resources/sponza_lights.json: -------------------------------------------------------------------------------- 1 | { 2 | "lights": [ 3 | { 4 | "angle": 69.0, 5 | "color": [ 6 | 0.9999899864196777, 7 | 0.9999899864196777, 8 | 1.0 9 | ], 10 | "pos": [ 11 | 0.0, 12 | 3.562610149383545, 13 | 0.0, 14 | 0.0 15 | ], 16 | "radius": 200.0, 17 | "rot": [ 18 | 0.0, 19 | 0.0, 20 | 0.0, 21 | 0.0 22 | ], 23 | "size": 0.0, 24 | "type": 0 25 | }, 26 | { 27 | "angle": 0.0, 28 | "color": [ 29 | 1.0, 30 | 0.0, 31 | 0.0 32 | ], 33 | "pos": [ 34 | -4.0, 35 | 1.0, 36 | -7.193277359008789, 37 | 0.0 38 | ], 39 | "radius": 5.0, 40 | "rot": [ 41 | -1.0399991273880005, 42 | 7.299992084503174, 43 | 0.0, 44 | 0.0 45 | ], 46 | "size": 0.0, 47 | "type": 0 48 | }, 49 | { 50 | "angle": 0.0, 51 | "color": [ 52 | 0.0, 53 | 1.0, 54 | 0.0 55 | ], 56 | "pos": [ 57 | 4.0, 58 | 1.0, 59 | -7.192999839782715, 60 | 0.0 61 | ], 62 | "radius": 5.0, 63 | "rot": [ 64 | 0.0, 65 | 0.0, 66 | 0.0, 67 | 0.0 68 | ], 69 | "size": 0.0, 70 | "type": 0 71 | } 72 | ] 73 | } 74 | -------------------------------------------------------------------------------- /resources/viknell_lights.json: -------------------------------------------------------------------------------- 1 | { 2 | "lights": [ 3 | { 4 | "angle": 69.0, 5 | "color": [ 6 | 0.0, 7 | 0.0, 8 | 1.0 9 | ], 10 | "pos": [ 11 | 0.75, 12 | 0.0, 13 | 0.75, 14 | 0.0 15 | ], 16 | "radius": 6.0, 17 | "rot": [ 18 | 0.0, 19 | 0.0, 20 | 0.0, 21 | 0.0 22 | ], 23 | "size": 0.0, 24 | "type": 0 25 | }, 26 | { 27 | "angle": 0.0, 28 | "color": [ 29 | 1.0, 30 | 0.0, 31 | 0.0 32 | ], 33 | "pos": [ 34 | -0.75, 35 | 0.0, 36 | 0.75, 37 | 0.0 38 | ], 39 | "radius": 5.0, 40 | "rot": [ 41 | 0.0, 42 | 0.0, 43 | 0.0, 44 | 0.0 45 | ], 46 | "size": 0.0, 47 | "type": 0 48 | } 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /scripts/JenkinsWebhook.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set "str=%~1" 3 | "C:\Program Files\cURL\bin\curl.exe" -X POST --data "{ \"content\": \"%str%\", \"username\": \"Jenkins\" }" -H "Content-Type: application/json" https://discordapp.com/api/webhooks/488672255321309185/GdU9rve6wW5rcbk6xcDx4TX8AKez5Yfej8kfKco17qRvHTlTuB6bdziQIDDYBHW8HuES 4 | @echo on -------------------------------------------------------------------------------- /src/constant_buffer_pool.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "constant_buffer_pool.hpp" 17 | 18 | namespace wr 19 | { 20 | ConstantBufferPool::ConstantBufferPool(std::size_t size_in_bytes) : m_size_in_bytes(size_in_bytes) 21 | { 22 | } 23 | 24 | ConstantBufferHandle* ConstantBufferPool::Create(std::size_t buffer_size) 25 | { 26 | std::lock_guard lock(m_mutex); 27 | 28 | return AllocateConstantBuffer(buffer_size); 29 | } 30 | 31 | void ConstantBufferPool::Update(ConstantBufferHandle* handle, size_t size, size_t offset, std::uint8_t * data) 32 | { 33 | std::lock_guard lock(m_mutex); 34 | 35 | WriteConstantBufferData(handle, size, offset, data); 36 | } 37 | 38 | void ConstantBufferPool::Destroy(ConstantBufferHandle* handle) 39 | { 40 | std::lock_guard lock(m_mutex); 41 | 42 | DeallocateConstantBuffer(handle); 43 | } 44 | void ConstantBufferPool::Update(ConstantBufferHandle * handle, size_t size, size_t offset, size_t frame_idx, std::uint8_t * data) 45 | { 46 | std::lock_guard lock(m_mutex); 47 | 48 | WriteConstantBufferData(handle, size, offset, frame_idx, data); 49 | } 50 | } /* wr */ -------------------------------------------------------------------------------- /src/constant_buffer_pool.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "util/defines.hpp" 25 | 26 | namespace wr 27 | { 28 | 29 | class ConstantBufferPool; 30 | 31 | struct ConstantBufferHandle 32 | { 33 | ConstantBufferPool* m_pool; 34 | }; 35 | 36 | class ConstantBufferPool 37 | { 38 | public: 39 | explicit ConstantBufferPool(std::size_t size_in_bytes); 40 | virtual ~ConstantBufferPool() = default; 41 | 42 | ConstantBufferPool(ConstantBufferPool const &) = delete; 43 | ConstantBufferPool& operator=(ConstantBufferPool const &) = delete; 44 | ConstantBufferPool(ConstantBufferPool&&) = delete; 45 | ConstantBufferPool& operator=(ConstantBufferPool&&) = delete; 46 | 47 | [[nodiscard]] ConstantBufferHandle* Create(std::size_t buffer_size); 48 | 49 | void Update(ConstantBufferHandle* handle, size_t size, size_t offset, std::uint8_t* data); 50 | void Update(ConstantBufferHandle* handle, size_t size, size_t offset, size_t frame_idx, std::uint8_t* data); 51 | 52 | void Destroy(ConstantBufferHandle* handle); 53 | 54 | virtual void Evict() = 0; 55 | virtual void MakeResident() = 0; 56 | 57 | protected: 58 | virtual ConstantBufferHandle* AllocateConstantBuffer(std::size_t buffer_size) = 0; 59 | virtual void WriteConstantBufferData(ConstantBufferHandle* handle, size_t size, size_t offset, std::uint8_t* data) = 0; 60 | virtual void WriteConstantBufferData(ConstantBufferHandle* handle, size_t size, size_t offset, size_t frame_idx, std::uint8_t* data) = 0; 61 | virtual void DeallocateConstantBuffer(ConstantBufferHandle* handle) = 0; 62 | 63 | std::size_t m_size_in_bytes; 64 | std::mutex m_mutex; 65 | }; 66 | 67 | } /* wr */ 68 | -------------------------------------------------------------------------------- /src/d3d12/d3d12_command_queue.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "d3d12_functions.hpp" 17 | 18 | #include "../util/log.hpp" 19 | #include "d3d12_defines.hpp" 20 | 21 | namespace wr::d3d12 22 | { 23 | 24 | CommandQueue* CreateCommandQueue(Device* device, CmdListType type) 25 | { 26 | auto cmd_queue = new CommandQueue(); 27 | const auto n_device = device->m_native; 28 | 29 | D3D12_COMMAND_QUEUE_DESC cmd_queue_desc = {}; 30 | cmd_queue_desc.Flags = settings::enable_gpu_timeout ? D3D12_COMMAND_QUEUE_FLAG_NONE : D3D12_COMMAND_QUEUE_FLAG_DISABLE_GPU_TIMEOUT; 31 | cmd_queue_desc.Type = static_cast(type); 32 | 33 | TRY_M(n_device->CreateCommandQueue(&cmd_queue_desc, IID_PPV_ARGS(&cmd_queue->m_native)), 34 | "Failed to create DX12 command queue."); 35 | NAME_D3D12RESOURCE(cmd_queue->m_native); 36 | 37 | return cmd_queue; 38 | } 39 | 40 | void Execute(CommandQueue* cmd_queue, std::vector const & cmd_lists, Fence* fence) 41 | { 42 | std::vector native_lists; 43 | native_lists.resize(cmd_lists.size()); 44 | for (auto i = 0; i < native_lists.size(); i++) 45 | { 46 | native_lists[i] = cmd_lists[i]->m_native; 47 | } 48 | 49 | cmd_queue->m_native->ExecuteCommandLists(static_cast(native_lists.size()), native_lists.data()); 50 | 51 | fence->m_fence_value++; 52 | Signal(fence, cmd_queue); 53 | 54 | } 55 | 56 | void Destroy(CommandQueue* cmd_queue) 57 | { 58 | SAFE_RELEASE(cmd_queue->m_native); 59 | delete cmd_queue; 60 | } 61 | void SetName(CommandQueue * cmd_queue, std::wstring name) 62 | { 63 | cmd_queue->m_native->SetName(name.c_str()); 64 | } 65 | 66 | 67 | } /* wr::d3d12 */ -------------------------------------------------------------------------------- /src/d3d12/d3d12_constant_buffer_pool.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | #include "../constant_buffer_pool.hpp" 18 | #include "d3d12_structs.hpp" 19 | 20 | namespace wr 21 | { 22 | 23 | struct D3D12ConstantBufferHandle : ConstantBufferHandle 24 | { 25 | d3d12::HeapResource* m_native; 26 | }; 27 | 28 | class D3D12RenderSystem; 29 | 30 | class D3D12ConstantBufferPool : public ConstantBufferPool 31 | { 32 | public: 33 | explicit D3D12ConstantBufferPool(D3D12RenderSystem& render_system, std::size_t size_in_bytes); 34 | ~D3D12ConstantBufferPool() final; 35 | 36 | void Evict() final; 37 | void MakeResident() final; 38 | 39 | protected: 40 | ConstantBufferHandle* AllocateConstantBuffer(std::size_t buffer_size) final; 41 | void WriteConstantBufferData(ConstantBufferHandle* handle, size_t size, size_t offset, std::uint8_t* data) final; 42 | void WriteConstantBufferData(ConstantBufferHandle* handle, size_t size, size_t offset, size_t frame_idx, std::uint8_t* data) final; 43 | void DeallocateConstantBuffer(ConstantBufferHandle* handle) final; 44 | 45 | std::vector m_constant_buffer_handles; 46 | 47 | d3d12::Heap* m_heap; 48 | D3D12RenderSystem& m_render_system; 49 | }; 50 | 51 | } /* wr */ 52 | -------------------------------------------------------------------------------- /src/d3d12/d3d12_defines.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "../util/log.hpp" 19 | 20 | #pragma warning(push, 0) 21 | 22 | #define D3DX12_INC d3dx12_rt.h 23 | 24 | /*Helper function to get readable error messages from HResults 25 | code originated from https://docs.microsoft.com/en-us/windows/desktop/cossdk/interpreting-error-codes 26 | */ 27 | inline std::string HResultToString(HRESULT hr) 28 | { 29 | if (FACILITY_WINDOWS == HRESULT_FACILITY(hr)) 30 | { 31 | hr = HRESULT_CODE(hr); 32 | } 33 | TCHAR* sz_err_msg; 34 | 35 | if (FormatMessage( 36 | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 37 | NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 38 | (LPTSTR)&sz_err_msg, 0, NULL) != 0) 39 | { 40 | std::string retval = sz_err_msg; 41 | LocalFree(sz_err_msg); 42 | return(retval); 43 | } 44 | else 45 | { 46 | return(std::string("[Could not find a description for error # %#x.", hr)); 47 | } 48 | } 49 | 50 | //! Checks whether the d3d12 object exists before releasing it. 51 | #define SAFE_RELEASE(obj) { if ( obj ) { obj->Release(); obj = NULL; } } 52 | 53 | //! Handles a hresult. 54 | #define TRY(result) if (FAILED(result)) { LOGC("An hresult returned a error!. File: " + std::string(__FILE__) + " Line: " + std::to_string(__LINE__) + " HRResult: " + HResultToString(result)); } 55 | 56 | //! Handles a hresult and outputs a specific message. 57 | #define TRY_M(result, msg) if (FAILED(result)) { LOGC(static_cast(msg) + " HRResult: " + HResultToString(result)); } 58 | 59 | //! This macro is used to name d3d12 resources. 60 | #define NAME_D3D12RESOURCE(r, n) { auto temp = std::string(__FILE__); \ 61 | r->SetName(std::wstring(std::wstring(n) + L" (line: " + std::to_wstring(__LINE__) + L" file: " + std::wstring(temp.begin(), temp.end())).c_str()); } 62 | 63 | //! This macro is used to name d3d12 resources with a placeholder name. TODO: "Unamed Resource" should be "Unamed [typename]" 64 | #define NAME_D3D12RESOURCE(r) { auto temp = std::string(__FILE__); \ 65 | r->SetName(std::wstring(L"Unnamed Resource (line: " + std::to_wstring(__LINE__) + L" file: " + std::wstring(temp.begin(), temp.end())).c_str()); } 66 | 67 | // Particular version automatically rounds the alignment to a two power. 68 | template 69 | constexpr inline T SizeAlignTwoPower(T size, A alignment) 70 | { 71 | return (size + (alignment - 1U)) & ~(alignment - 1U); 72 | } 73 | 74 | // Particular version always aligns to the provided alignment 75 | template 76 | constexpr inline T SizeAlignAnyAlignment(T size, A alignment) 77 | { 78 | return (size / alignment + (size%alignment > 0))*alignment; 79 | } 80 | 81 | #pragma warning(pop) 82 | -------------------------------------------------------------------------------- /src/d3d12/d3d12_device.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeamWisp/WispRenderer/1f1493f9c9038dcd226c44fe154078a00168c3d9/src/d3d12/d3d12_device.cpp -------------------------------------------------------------------------------- /src/d3d12/d3d12_fence.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "d3d12_functions.hpp" 17 | 18 | #include "../util/log.hpp" 19 | #include "d3d12_defines.hpp" 20 | 21 | namespace wr::d3d12 22 | { 23 | 24 | Fence* CreateFence(Device* device) 25 | { 26 | auto fence = new Fence(); 27 | auto n_device = device->m_native; 28 | 29 | // create the fences 30 | TRY_M(n_device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence->m_native)), 31 | "Failed to create fence"); 32 | fence->m_native->SetName(L"SimpleFence"); 33 | 34 | // create a handle to a fence event 35 | fence->m_fence_event = CreateEvent(nullptr, FALSE, FALSE, nullptr); 36 | if (fence->m_fence_event == nullptr) 37 | { 38 | LOGC("Failed to create fence event"); 39 | } 40 | 41 | return fence; 42 | } 43 | 44 | void SetName(Fence * fence, std::wstring name) 45 | { 46 | fence->m_native->SetName(name.c_str()); 47 | } 48 | 49 | void Signal(Fence* fence, CommandQueue* cmd_queue) 50 | { 51 | TRY_M(cmd_queue->m_native->Signal(fence->m_native, fence->m_fence_value), 52 | "Failed to set fence signal"); 53 | } 54 | 55 | void WaitFor(Fence* fence) 56 | { 57 | if (fence->m_native->GetCompletedValue() < fence->m_fence_value) 58 | { 59 | // we have the fence create an event which is signaled once the fence's current value is "fenceValue" 60 | TRY_M(fence->m_native->SetEventOnCompletion(fence->m_fence_value, fence->m_fence_event), 61 | "Failed to set fence event."); 62 | 63 | WaitForSingleObject(fence->m_fence_event, INFINITE); 64 | } 65 | 66 | // increment fenceValue for next frame (or usage) 67 | fence->m_fence_value++; 68 | } 69 | 70 | void Destroy(Fence* fence) 71 | { 72 | SAFE_RELEASE(fence->m_native) 73 | CloseHandle(fence->m_fence_event); 74 | delete fence; 75 | } 76 | 77 | } /* wr::d3d12 */ -------------------------------------------------------------------------------- /src/d3d12/d3d12_indirect_command_buffer.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "d3d12_functions.hpp" 17 | 18 | #include "../util/log.hpp" 19 | #include "d3d12_defines.hpp" 20 | 21 | namespace wr::d3d12 22 | { 23 | 24 | IndirectCommandBuffer* CreateIndirectCommandBuffer(Device* device, std::size_t max_commands, std::size_t command_size, uint32_t versions) 25 | { 26 | auto buffer = new IndirectCommandBuffer(); 27 | 28 | buffer->m_num_max_commands = max_commands; 29 | buffer->m_num_commands = 0; 30 | buffer->m_command_size = command_size; 31 | 32 | buffer->m_native.resize(versions); 33 | buffer->m_native_upload.resize(versions); 34 | 35 | CD3DX12_HEAP_PROPERTIES heap_properties_default = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT); 36 | CD3DX12_HEAP_PROPERTIES heap_properties_upload = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD); 37 | CD3DX12_RESOURCE_DESC buffer_desc = CD3DX12_RESOURCE_DESC::Buffer(max_commands * command_size); 38 | 39 | for (uint32_t i = 0; i < versions; ++i) 40 | { 41 | 42 | TRY(device->m_native->CreateCommittedResource( 43 | &heap_properties_default, 44 | D3D12_HEAP_FLAG_NONE, 45 | &buffer_desc, 46 | D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT, 47 | nullptr, 48 | IID_PPV_ARGS(buffer->m_native.data() + i))); 49 | 50 | TRY(device->m_native->CreateCommittedResource( 51 | &heap_properties_upload, 52 | D3D12_HEAP_FLAG_NONE, 53 | &buffer_desc, 54 | D3D12_RESOURCE_STATE_GENERIC_READ, 55 | nullptr, 56 | IID_PPV_ARGS(buffer->m_native_upload.data() + i))); 57 | 58 | } 59 | 60 | return buffer; 61 | } 62 | 63 | void SetName(IndirectCommandBuffer* buffer, std::wstring name) 64 | { 65 | for (uint32_t i = 0, j = (uint32_t)buffer->m_native.size(); i < j; ++i) 66 | { 67 | buffer->m_native[i]->SetName((name + L" #" + std::to_wstring(i)).c_str()); 68 | buffer->m_native_upload[i]->SetName((name + L" #" + std::to_wstring(i) + L" Upload Buffer").c_str()); 69 | } 70 | } 71 | 72 | void StageBuffer(CommandList* cmd_list, IndirectCommandBuffer* buffer, void* data, std::size_t num_commands, uint32_t frame_idx) 73 | { 74 | D3D12_SUBRESOURCE_DATA cmd_data = {}; 75 | cmd_data.pData = reinterpret_cast(data); 76 | cmd_data.RowPitch = num_commands * buffer->m_command_size; 77 | cmd_data.SlicePitch = cmd_data.RowPitch; 78 | 79 | buffer->m_num_commands = num_commands; 80 | 81 | UpdateSubresources<1>(cmd_list->m_native, buffer->m_native[frame_idx], buffer->m_native_upload[frame_idx], 0, 0, 1, &cmd_data); 82 | } 83 | 84 | } /* wr::d3d12 */ -------------------------------------------------------------------------------- /src/d3d12/d3d12_material_pool.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "d3d12_material_pool.hpp" 17 | 18 | namespace wr 19 | { 20 | D3D12MaterialPool::D3D12MaterialPool(D3D12RenderSystem & render_system) : 21 | m_render_system(render_system) 22 | { 23 | m_constant_buffer_pool = m_render_system.CreateConstantBufferPool(1_mb); 24 | } 25 | 26 | D3D12MaterialPool::~D3D12MaterialPool() 27 | { 28 | 29 | } 30 | 31 | void D3D12MaterialPool::Evict() 32 | { 33 | m_constant_buffer_pool->Evict(); 34 | } 35 | 36 | void D3D12MaterialPool::MakeResident() 37 | { 38 | m_constant_buffer_pool->MakeResident(); 39 | } 40 | 41 | } /* wr */ -------------------------------------------------------------------------------- /src/d3d12/d3d12_material_pool.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "../material_pool.hpp" 19 | 20 | #include "d3d12_renderer.hpp" 21 | 22 | namespace wr 23 | { 24 | 25 | class D3D12MaterialPool : public MaterialPool 26 | { 27 | public: 28 | explicit D3D12MaterialPool(D3D12RenderSystem& render_system); 29 | ~D3D12MaterialPool() final; 30 | 31 | void Evict() final; 32 | void MakeResident() final; 33 | 34 | protected: 35 | D3D12RenderSystem& m_render_system; 36 | }; 37 | 38 | } /* wr */ 39 | -------------------------------------------------------------------------------- /src/d3d12/d3d12_readback_buffer.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "d3d12_functions.hpp" 17 | 18 | #include "d3d12_defines.hpp" 19 | #include "d3dx12.hpp" 20 | #include "../util/log.hpp" 21 | 22 | namespace wr::d3d12 23 | { 24 | ReadbackBufferResource* wr::d3d12::CreateReadbackBuffer(Device* device, std::uint32_t aligned_buffer_size) 25 | { 26 | auto native_device = device->m_native; 27 | 28 | auto* readbackBuffer = new ReadbackBufferResource(); 29 | 30 | CD3DX12_HEAP_PROPERTIES heap_properties_readback = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_READBACK); 31 | CD3DX12_RESOURCE_DESC buffer_desc = CD3DX12_RESOURCE_DESC::Buffer(aligned_buffer_size); 32 | 33 | HRESULT res = native_device->CreateCommittedResource( 34 | &heap_properties_readback, 35 | D3D12_HEAP_FLAG_NONE, 36 | &buffer_desc, 37 | D3D12_RESOURCE_STATE_COPY_DEST, 38 | nullptr, 39 | IID_PPV_ARGS(&readbackBuffer->m_resource)); 40 | 41 | if (FAILED(res)) 42 | { 43 | LOGC("Error: Could not create a readback buffer!"); 44 | } 45 | 46 | return readbackBuffer; 47 | } 48 | 49 | void* MapReadbackBuffer(ReadbackBufferResource* const readback_buffer, std::uint32_t buffer_size) 50 | { 51 | if (!readback_buffer) 52 | return nullptr; 53 | 54 | void* memory = nullptr; 55 | CD3DX12_RANGE buffer_range = CD3DX12_RANGE(0, buffer_size); 56 | 57 | readback_buffer->m_resource->Map(0, &buffer_range, &memory); 58 | 59 | return memory; 60 | } 61 | 62 | void UnmapReadbackBuffer(ReadbackBufferResource* const readback_buffer) 63 | { 64 | if (!readback_buffer) 65 | return; 66 | 67 | CD3DX12_RANGE buffer_range = CD3DX12_RANGE(0, 0); 68 | readback_buffer->m_resource->Unmap(0, &buffer_range); 69 | } 70 | 71 | void SetName(ReadbackBufferResource* readback_buffer, std::wstring name) 72 | { 73 | readback_buffer->m_resource->SetName(name.c_str()); 74 | } 75 | 76 | void Destroy(ReadbackBufferResource* readback_buffer) 77 | { 78 | SAFE_RELEASE(readback_buffer->m_resource); 79 | delete readback_buffer; 80 | } 81 | 82 | } /* wr::d3d12 */ 83 | -------------------------------------------------------------------------------- /src/d3d12/d3d12_structured_buffer.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "d3d12_functions.hpp" 17 | 18 | namespace wr::d3d12 19 | { 20 | 21 | void CreateSRVFromStructuredBuffer(HeapResource* structured_buffer, DescHeapCPUHandle& handle, unsigned int id) 22 | { 23 | auto& resources = structured_buffer->m_heap_bsbo->m_resources[structured_buffer->m_heap_vector_location]; 24 | auto& resource = resources.second[id]; 25 | 26 | decltype(Device::m_native) n_device; 27 | resource->GetDevice(IID_PPV_ARGS(&n_device)); 28 | 29 | unsigned int increment_size = n_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); 30 | 31 | D3D12_SHADER_RESOURCE_VIEW_DESC srv_desc = {}; 32 | srv_desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; 33 | srv_desc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER; 34 | srv_desc.Buffer.FirstElement = 0; 35 | srv_desc.Buffer.NumElements = static_cast(structured_buffer->m_unaligned_size / structured_buffer->m_stride); 36 | srv_desc.Buffer.StructureByteStride = static_cast(structured_buffer->m_stride); 37 | srv_desc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_NONE; 38 | 39 | n_device->CreateShaderResourceView(resource, &srv_desc, handle.m_native); 40 | Offset(handle, 1, increment_size); 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /src/d3d12/d3d12_structured_buffer_pool.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "../structured_buffer_pool.hpp" 19 | #include "d3d12_structs.hpp" 20 | 21 | #include 22 | 23 | 24 | namespace wr 25 | { 26 | struct D3D12StructuredBufferHandle : StructuredBufferHandle 27 | { 28 | d3d12::HeapResource* m_native; 29 | }; 30 | 31 | struct BufferUpdateInfo 32 | { 33 | D3D12StructuredBufferHandle* m_buffer_handle; 34 | std::vector m_data; 35 | std::size_t m_offset; 36 | std::size_t m_size; 37 | ResourceState m_new_state; 38 | }; 39 | 40 | class D3D12RenderSystem; 41 | 42 | class D3D12StructuredBufferPool : public StructuredBufferPool 43 | { 44 | public: 45 | explicit D3D12StructuredBufferPool(D3D12RenderSystem& render_system, 46 | std::size_t size_in_bytes); 47 | 48 | ~D3D12StructuredBufferPool() final; 49 | 50 | void UpdateBuffers(d3d12::CommandList* cmd_list, std::size_t frame_idx); 51 | 52 | void SetBufferState(StructuredBufferHandle* handle, ResourceState state); 53 | 54 | void Evict() final; 55 | void MakeResident() final; 56 | 57 | protected: 58 | [[nodiscard]] StructuredBufferHandle* CreateBuffer(std::size_t size, std::size_t stride, bool used_as_uav) final; 59 | void DestroyBuffer(StructuredBufferHandle* handle) final; 60 | void UpdateBuffer(StructuredBufferHandle* handle, void* data, std::size_t size, std::size_t offset) final; 61 | 62 | D3D12RenderSystem& m_render_system; 63 | 64 | d3d12::Heap* m_heap; 65 | 66 | std::vector m_handles; 67 | std::vector> m_buffer_update_queues; 68 | }; 69 | 70 | 71 | } /* wr */ -------------------------------------------------------------------------------- /src/d3d12/d3d12_texture_resources.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | #include "../structs.hpp" 18 | 19 | #include "d3d12_enums.hpp" 20 | #include "d3d12_settings.hpp" 21 | #include "d3dx12.hpp" 22 | 23 | #include "d3d12_descriptors_allocations.hpp" 24 | 25 | #include 26 | 27 | namespace wr::d3d12 28 | { 29 | struct TextureResource : Texture 30 | { 31 | std::size_t m_width = 0; 32 | std::size_t m_height = 0; 33 | std::size_t m_depth = 0; 34 | std::size_t m_array_size = 0; 35 | std::size_t m_mip_levels = 0; 36 | 37 | Format m_format = wr::Format::UNKNOWN; 38 | 39 | ID3D12Resource* m_resource = nullptr; 40 | ID3D12Resource* m_intermediate = nullptr; 41 | std::vector m_subresource_states; 42 | DescriptorAllocation m_srv_allocation; 43 | DescriptorAllocation m_uav_allocation; 44 | 45 | std::vector m_subresources; 46 | 47 | //This allocation can be either 1 or 6 continous descriptors based on m_is_cubemap 48 | std::optional m_rtv_allocation = std::nullopt; 49 | 50 | bool m_is_staged = false; 51 | bool m_need_mips = false; 52 | bool m_is_cubemap = false; 53 | bool m_allow_render_dest = false; 54 | }; 55 | } -------------------------------------------------------------------------------- /src/d3d12/d3d12_viewport.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "d3d12_functions.hpp" 17 | 18 | namespace wr::d3d12 19 | { 20 | 21 | Viewport CreateViewport(int width, int height) 22 | { 23 | Viewport viewport; 24 | 25 | // Define viewport. 26 | viewport.m_viewport.TopLeftX = 0; 27 | viewport.m_viewport.TopLeftY = 0; 28 | viewport.m_viewport.Width = static_cast(width); 29 | viewport.m_viewport.Height = static_cast(height); 30 | viewport.m_viewport.MinDepth = 0.0f; 31 | viewport.m_viewport.MaxDepth = 1.0f; 32 | 33 | // Define scissor rect 34 | viewport.m_scissor_rect.left = 0; 35 | viewport.m_scissor_rect.top = 0; 36 | viewport.m_scissor_rect.right = width; 37 | viewport.m_scissor_rect.bottom = height; 38 | 39 | return viewport; 40 | } 41 | 42 | void ResizeViewport(Viewport& viewport, int width, int height) 43 | { 44 | // Define viewport. 45 | viewport.m_viewport.Width = static_cast(width); 46 | viewport.m_viewport.Height = static_cast(height); 47 | 48 | // Define scissor rect 49 | viewport.m_scissor_rect.right = width; 50 | viewport.m_scissor_rect.bottom = height; 51 | } 52 | 53 | } /* wr::d3d12 */ -------------------------------------------------------------------------------- /src/entry.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #define WISP_ENTRY(func) \ 19 | int main() \ 20 | { \ 21 | return func(); \ 22 | } \ 23 | int CALLBACK WinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPSTR, _In_ int) \ 24 | { \ 25 | return main(); \ 26 | } -------------------------------------------------------------------------------- /src/id_factory.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "id_factory.hpp" 17 | 18 | namespace wr 19 | { 20 | 21 | IDFactory::IDFactory() 22 | : m_id(0) 23 | { 24 | } 25 | 26 | void IDFactory::MakeIDAvailable(std::uint32_t unused_id) 27 | { 28 | m_unused_ids.push_back(unused_id); 29 | } 30 | 31 | std::uint32_t IDFactory::GetUnusedID() 32 | { 33 | std::uint32_t ret_id; 34 | 35 | if (m_unused_ids.empty()) 36 | { 37 | ret_id = m_id; 38 | m_id++; 39 | } 40 | else 41 | { 42 | ret_id = *(m_unused_ids.end() - 1); 43 | m_unused_ids.pop_back(); 44 | } 45 | 46 | return ret_id; 47 | } 48 | 49 | } /* wr */ -------------------------------------------------------------------------------- /src/id_factory.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | #include 18 | #include 19 | 20 | namespace wr 21 | { 22 | 23 | class IDFactory 24 | { 25 | public: 26 | 27 | IDFactory(); 28 | virtual ~IDFactory() = default; 29 | 30 | IDFactory(IDFactory const &) = delete; 31 | IDFactory& operator=(IDFactory const &) = delete; 32 | IDFactory(IDFactory&&) = delete; 33 | IDFactory& operator=(IDFactory&&) = delete; 34 | 35 | void MakeIDAvailable(std::uint32_t unused_id); 36 | std::uint32_t GetUnusedID(); 37 | 38 | protected: 39 | 40 | std::uint32_t m_id; 41 | std::vector m_unused_ids; 42 | }; 43 | 44 | } /* wr */ -------------------------------------------------------------------------------- /src/imgui/imgui_impl_dx12.hpp: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer for DirectX12 2 | // This needs to be used along with a Platform Binding (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. 6 | // Issues: 7 | // [ ] 64-bit only for now! (Because sizeof(ImTextureId) == sizeof(void*)). See github.com/ocornut/imgui/pull/301 8 | 9 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 10 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. 11 | // https://github.com/ocornut/imgui 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | enum DXGI_FORMAT : std::int32_t; 18 | struct ID3D12Device; 19 | struct ID3D12GraphicsCommandList; 20 | struct D3D12_CPU_DESCRIPTOR_HANDLE; 21 | struct D3D12_GPU_DESCRIPTOR_HANDLE; 22 | 23 | // cmd_list is the command list that the implementation will use to render imgui draw lists. 24 | // Before calling the render function, caller must prepare cmd_list by resetting it and setting the appropriate 25 | // render target and descriptor heap that contains font_srv_cpu_desc_handle/font_srv_gpu_desc_handle. 26 | // font_srv_cpu_desc_handle and font_srv_gpu_desc_handle are handles to a single SRV descriptor to use for the internal font texture. 27 | IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, 28 | D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle); 29 | IMGUI_IMPL_API void ImGui_ImplDX12_Shutdown(); 30 | IMGUI_IMPL_API void ImGui_ImplDX12_NewFrame(); 31 | IMGUI_IMPL_API void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandList* graphics_command_list); 32 | 33 | // Use if you want to reset your rendering device without losing ImGui state. 34 | IMGUI_IMPL_API void ImGui_ImplDX12_InvalidateDeviceObjects(); 35 | IMGUI_IMPL_API bool ImGui_ImplDX12_CreateDeviceObjects(); 36 | 37 | // Wisp Extension 38 | IMGUI_IMPL_API bool ImGui_ImplDX12_IsInitialized(); -------------------------------------------------------------------------------- /src/imgui/imgui_impl_win32.hpp: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Binding for Windows (standard windows API for 32 and 64 bits applications) 2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) 3 | 4 | // Implemented features: 5 | // [X] Platform: Clipboard support (for Win32 this is actually part of core imgui) 6 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 7 | // [X] Platform: Keyboard arrays indexed using VK_* Virtual Key Codes, e.g. ImGui::IsKeyPressed(VK_SPACE). 8 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 9 | // [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 10 | 11 | #pragma once 12 | 13 | IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); 14 | IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); 15 | IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); 16 | 17 | // DPI-related helpers (which run and compile without requiring 8.1 or 10, neither Windows version, neither associated SDK) 18 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness(); 19 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd); // HWND hwnd 20 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor); // HMONITOR monitor 21 | 22 | // Handler for Win32 messages, update mouse/keyboard data. 23 | // You may or not need this for your implementation, but it can serve as reference for handling inputs. 24 | // Intentionally commented out to avoid dragging dependencies on types. You can COPY this line into your .cpp code instead. 25 | /* 26 | IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 27 | */ 28 | -------------------------------------------------------------------------------- /src/model_loader_assimp.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "model_loader.hpp" 19 | 20 | #undef min 21 | #undef max 22 | #include 23 | #include 24 | #include 25 | 26 | namespace wr 27 | { 28 | class AssimpModelLoader : public ModelLoader 29 | { 30 | public: 31 | AssimpModelLoader(); 32 | 33 | ~AssimpModelLoader() final; 34 | 35 | protected: 36 | ModelData* LoadModel(std::string_view model_path) final; 37 | ModelData* LoadModel(void* data, std::size_t length, std::string format) final; 38 | 39 | private: 40 | void LoadMeshes(ModelData* model, const aiScene* scene, aiNode* node); 41 | void LoadMaterials(ModelData* model, const aiScene* scene); 42 | void LoadEmbeddedTextures(ModelData* model, const aiScene* scene); 43 | }; 44 | } -------------------------------------------------------------------------------- /src/model_loader_tinygltf.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "model_loader.hpp" 19 | 20 | namespace wr 21 | { 22 | class TinyGLTFModelLoader : public ModelLoader 23 | { 24 | public: 25 | TinyGLTFModelLoader(); 26 | 27 | ~TinyGLTFModelLoader() final; 28 | 29 | protected: 30 | ModelData* LoadModel(std::string_view model_path) final; 31 | ModelData* LoadModel(void* data, std::size_t length, std::string format) final; 32 | 33 | private: 34 | //void LoadMeshes(ModelData* model, tinygltf::Model tg_model, tinygltf::Node node); 35 | //void LoadMaterials(ModelData* model, const aiScene* scene); 36 | //void LoadEmbeddedTextures(ModelData* model, const aiScene* scene); 37 | }; 38 | } -------------------------------------------------------------------------------- /src/pipeline_registry.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "pipeline_registry.hpp" 17 | 18 | namespace wr 19 | { 20 | 21 | PipelineRegistry::PipelineRegistry() : Registry() 22 | { 23 | } 24 | 25 | } /* wr */ 26 | -------------------------------------------------------------------------------- /src/pipeline_registry.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "registry.hpp" 19 | 20 | #include 21 | #include 22 | 23 | #include "vertex.hpp" 24 | #include "util/named_type.hpp" 25 | #include "d3d12/d3d12_enums.hpp" 26 | 27 | namespace wr 28 | { 29 | 30 | using Pipeline = void; 31 | 32 | struct PipelineDescription 33 | { 34 | std::optional m_vertex_shader_handle; 35 | std::optional m_pixel_shader_handle; 36 | std::optional m_compute_shader_handle; 37 | RegistryHandle m_root_signature_handle; 38 | 39 | Format m_dsv_format; 40 | std::array m_rtv_formats; 41 | unsigned int m_num_rtv_formats; 42 | 43 | PipelineType m_type = PipelineType::GRAPHICS_PIPELINE; 44 | CullMode m_cull_mode = wr::CullMode::CULL_BACK; 45 | bool m_depth_enabled = false; 46 | bool m_counter_clockwise = false; 47 | TopologyType m_topology_type = wr::TopologyType::TRIANGLE; 48 | 49 | std::vector m_input_layout = {}; 50 | }; 51 | 52 | class PipelineRegistry : public internal::Registry 53 | { 54 | public: 55 | PipelineRegistry(); 56 | virtual ~PipelineRegistry() = default; 57 | 58 | template 59 | RegistryHandle Register(PipelineDescription description); 60 | }; 61 | 62 | template 63 | RegistryHandle PipelineRegistry::Register(PipelineDescription description) 64 | { 65 | IS_PROPER_VERTEX_CLASS(VT) 66 | 67 | auto handle = m_next_handle; 68 | 69 | description.m_input_layout = VT::GetInputLayout(); 70 | m_descriptions.insert({ handle, description }); 71 | 72 | m_next_handle++; 73 | return handle; 74 | } 75 | 76 | } /* wr */ -------------------------------------------------------------------------------- /src/platform_independend_structs.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "d3d12/d3d12_enums.hpp" 23 | #include "util/named_type.hpp" 24 | #include "util/user_literals.hpp" 25 | 26 | namespace wr 27 | { 28 | using CommandList = void; 29 | using RenderTarget = void; 30 | 31 | struct RenderTargetProperties 32 | { 33 | using IsRenderWindow = util::NamedType; 34 | using Width = util::NamedType>; 35 | using Height = util::NamedType>; 36 | using ExecuteResourceState = util::NamedType>; 37 | using FinishedResourceState = util::NamedType>; 38 | using CreateDSVBuffer = util::NamedType; 39 | using DSVFormat = util::NamedType; 40 | using RTVFormats = util::NamedType>; 41 | using NumRTVFormats = util::NamedType; 42 | using Clear = util::NamedType; 43 | using ClearDepth = util::NamedType; 44 | using ResolutionScalar = util::NamedType; 45 | 46 | IsRenderWindow m_is_render_window; 47 | Width m_width; 48 | Height m_height; 49 | ExecuteResourceState m_state_execute; 50 | FinishedResourceState m_state_finished; 51 | CreateDSVBuffer m_create_dsv_buffer; 52 | DSVFormat m_dsv_format; 53 | RTVFormats m_rtv_formats; 54 | NumRTVFormats m_num_rtv_formats; 55 | 56 | Clear m_clear = Clear(false); 57 | ClearDepth m_clear_depth = ClearDepth(false); 58 | 59 | ResolutionScalar m_resolution_scale = ResolutionScalar(1.0f); 60 | }; 61 | 62 | enum class LightType : int 63 | { 64 | POINT, DIRECTIONAL, SPOT, FREE 65 | }; 66 | 67 | struct Light 68 | { 69 | DirectX::XMFLOAT3 pos = { 0, 0, 0 }; //Position in world space for spot & point 70 | float rad = 5.f; //Radius for point, height for spot 71 | 72 | DirectX::XMFLOAT3 col = { 1, 1, 1 }; //Color (and strength) 73 | uint32_t tid = (uint32_t)LightType::FREE; //Type id; LightType::x 74 | 75 | DirectX::XMFLOAT3 dir = { 0, 0, 1 }; //Direction for spot & directional 76 | float ang = 40._deg; //Angle for spot; in radians 77 | 78 | DirectX::XMFLOAT3 padding; 79 | float light_size = 0.0f; 80 | }; 81 | 82 | } /* wr */ -------------------------------------------------------------------------------- /src/registry.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include 19 | #include 20 | 21 | #include "util/log.hpp" 22 | 23 | #undef GetObject // Prevent macro collision 24 | 25 | namespace wr 26 | { 27 | using RegistryHandle = std::uint64_t; 28 | } 29 | 30 | namespace wr::internal 31 | { 32 | template 33 | class Registry 34 | { 35 | protected: 36 | Registry() : m_next_handle(0) { } 37 | 38 | public: 39 | virtual ~Registry() = default; 40 | 41 | TO* Find(RegistryHandle handle) 42 | { 43 | auto it = m_objects.find(handle); 44 | if (it != m_objects.end()) 45 | { 46 | return (*it).second; 47 | } 48 | else 49 | { 50 | LOGE("Failed to find registry object related to registry handle."); 51 | return nullptr; 52 | } 53 | } 54 | 55 | static C& Get() 56 | { 57 | static C instance = {}; 58 | return instance; 59 | } 60 | 61 | void Lock() 62 | { 63 | m_mutex.lock(); 64 | } 65 | 66 | void Unlock() 67 | { 68 | m_mutex.unlock(); 69 | } 70 | 71 | void ClearReloadRequests() 72 | { 73 | m_requested_reload.clear(); 74 | } 75 | 76 | std::vector const & GetReloadRequests() 77 | { 78 | return m_requested_reload; 79 | } 80 | 81 | void RequestReload(RegistryHandle handle) 82 | { 83 | Lock(); 84 | m_requested_reload.push_back(handle); 85 | Unlock(); 86 | } 87 | 88 | std::map m_descriptions; 89 | std::map m_objects; 90 | 91 | protected: 92 | std::vector m_requested_reload; 93 | std::mutex m_mutex; 94 | RegistryHandle m_next_handle; 95 | }; 96 | 97 | } /* wr::internal */ -------------------------------------------------------------------------------- /src/render_tasks/d3d12_deferred_composition.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "../d3d12/d3d12_renderer.hpp" 19 | #include "../pipeline_registry.hpp" 20 | #include "../frame_graph/frame_graph.hpp" 21 | #include "../d3d12/d3d12_descriptors_allocations.hpp" 22 | #include "../d3d12/d3d12_texture_resources.hpp" 23 | 24 | namespace wr 25 | { 26 | struct DeferredCompositionTaskData 27 | { 28 | d3d12::PipelineState* in_pipeline = nullptr; 29 | d3d12::RenderTarget* out_deferred_main_rt = nullptr; 30 | 31 | DescriptorAllocator* out_allocator = nullptr; 32 | 33 | DescriptorAllocation out_gbuffer_albedo_alloc; 34 | DescriptorAllocation out_gbuffer_normal_alloc; 35 | DescriptorAllocation out_gbuffer_emissive_alloc; 36 | DescriptorAllocation out_gbuffer_depth_alloc; 37 | DescriptorAllocation out_lights_alloc; 38 | DescriptorAllocation out_buffer_refl_alloc; 39 | DescriptorAllocation out_buffer_shadow_alloc; 40 | DescriptorAllocation out_screen_space_irradiance_alloc; 41 | DescriptorAllocation out_screen_space_ao_alloc; 42 | DescriptorAllocation out_output_alloc; 43 | 44 | d3d12::TextureResource* out_skybox = nullptr; 45 | d3d12::TextureResource* out_irradiance = nullptr; 46 | d3d12::TextureResource* out_pref_env_map = nullptr; 47 | 48 | std::array out_bundle_cmd_lists = {}; 49 | bool out_requires_bundle_recording = false; 50 | 51 | bool is_hybrid = false; 52 | bool has_rt_reflection = false; 53 | bool has_rt_shadows = false; 54 | bool has_rt_shadows_denoiser = false; 55 | bool is_path_tracer = false; 56 | bool is_rtao = false; 57 | bool is_hbao = false; 58 | }; 59 | 60 | namespace internal 61 | { 62 | void RecordDrawCommands(D3D12RenderSystem& render_system, d3d12::CommandList* cmd_list, d3d12::HeapResource* camera_cb, DeferredCompositionTaskData const & data, unsigned int frame_idx); 63 | 64 | void SetupDeferredCompositionTask(RenderSystem& rs, FrameGraph& fg, RenderTaskHandle handle); 65 | void ExecuteDeferredCompositionTask(RenderSystem& rs, FrameGraph& fg, SceneGraph& scene_graph, RenderTaskHandle handle); 66 | void DestroyDeferredCompositionTask(FrameGraph& fg, RenderTaskHandle handle); 67 | 68 | } 69 | 70 | void AddDeferredCompositionTask(FrameGraph& fg, std::optional target_width, std::optional target_height); 71 | 72 | } -------------------------------------------------------------------------------- /src/renderer.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "renderer.hpp" 17 | 18 | void wr::RenderSystem::RequestRenderTargetSaveToDisc(std::string const & path, RenderTarget* render_target, unsigned int index) 19 | { 20 | m_requested_rt_saves.emplace(SaveRenderTargetRequest{ path, render_target, index }); 21 | } 22 | -------------------------------------------------------------------------------- /src/resource_pool_texture.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "resource_pool_texture.hpp" 17 | #include "util/log.hpp" 18 | #include "util/strings.hpp" 19 | 20 | namespace wr 21 | { 22 | 23 | TexturePool::TexturePool() 24 | { 25 | #ifdef _DEBUG 26 | std::lock_guard lock(m_mutex); 27 | 28 | static uint16_t pool_count = 0u; 29 | 30 | m_name = "TexturePool_" + std::to_string(pool_count); 31 | 32 | pool_count++; 33 | #endif 34 | } 35 | 36 | TextureHandle TexturePool::LoadFromMemory(unsigned char* data, size_t width, size_t height, const std::string& texture_extension, bool srgb, bool generate_mips) 37 | { 38 | std::string new_str = texture_extension; 39 | 40 | std::transform(texture_extension.begin(), texture_extension.end(), new_str.begin(), ::tolower); 41 | 42 | TextureFormat type; 43 | 44 | if (new_str == "png"|| new_str == "jpg" 45 | || new_str == "jpeg" || new_str == "bmp") 46 | { 47 | type = TextureFormat::WIC; 48 | } 49 | else if (new_str.compare("dds") == 0) 50 | { 51 | type = TextureFormat::DDS; 52 | } 53 | else if (new_str.compare("hdr") == 0) 54 | { 55 | type = TextureFormat::HDR; 56 | } 57 | else 58 | { 59 | LOGC("[ERROR]: Texture format not supported."); 60 | return {}; 61 | } 62 | 63 | std::lock_guard lock(m_mutex); 64 | return LoadFromMemory(data, width, height, type, srgb, generate_mips); 65 | } 66 | } -------------------------------------------------------------------------------- /src/resource_pool_texture.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "structs.hpp" 26 | #include "util/defines.hpp" 27 | #include "util/strings.hpp" 28 | #include "platform_independend_structs.hpp" 29 | #include "id_factory.hpp" 30 | 31 | namespace wr 32 | { 33 | enum class TextureFormat 34 | { 35 | WIC, 36 | DDS, 37 | HDR, 38 | RAW 39 | }; 40 | 41 | class TexturePool 42 | { 43 | public: 44 | explicit TexturePool(); 45 | virtual ~TexturePool() = default; 46 | 47 | TexturePool(TexturePool const &) = delete; 48 | TexturePool& operator=(TexturePool const &) = delete; 49 | TexturePool(TexturePool&&) = delete; 50 | TexturePool& operator=(TexturePool&&) = delete; 51 | 52 | [[nodiscard]] virtual TextureHandle LoadFromFile(std::string_view path, bool srgb, bool generate_mips) = 0; 53 | [[nodiscard]] virtual TextureHandle LoadFromMemory(unsigned char* data, size_t width, size_t height, const std::string& texture_extension, bool srgb, bool generate_mips); 54 | [[nodiscard]] virtual TextureHandle LoadFromMemory(unsigned char* data, size_t width, size_t height, TextureFormat type, bool srgb, bool generate_mips) = 0; 55 | [[nodiscard]] virtual TextureHandle CreateCubemap(std::string_view name, uint32_t width, uint32_t height, uint32_t mip_levels, Format format, bool allow_render_dest) = 0; 56 | [[nodiscard]] virtual TextureHandle CreateTexture(std::string_view name, uint32_t width, uint32_t height, uint32_t mip_levels, Format format, bool allow_render_dest) = 0; 57 | virtual void MarkForUnload(TextureHandle& handle, unsigned int frame_idx) = 0; 58 | virtual void UnloadTextures(unsigned int frame_idx) = 0; 59 | 60 | virtual void Evict() = 0; 61 | virtual void MakeResident() = 0; 62 | virtual void Stage(CommandList* cmd_list) = 0; 63 | virtual void PostStageClear() = 0; 64 | virtual void ReleaseTemporaryResources() = 0; 65 | 66 | virtual Texture* GetTextureResource(TextureHandle handle) = 0; 67 | 68 | protected: 69 | 70 | std::size_t m_loaded_textures = 0; 71 | std::mutex m_mutex; 72 | 73 | IDFactory m_id_factory; 74 | 75 | #ifdef _DEBUG 76 | std::string m_name; 77 | #endif 78 | }; 79 | 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/root_signature_registry.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "root_signature_registry.hpp" 17 | 18 | namespace wr 19 | { 20 | 21 | RootSignatureRegistry::RootSignatureRegistry() : Registry() 22 | { 23 | } 24 | 25 | RegistryHandle RootSignatureRegistry::Register(RootSignatureDescription description) 26 | { 27 | auto handle = m_next_handle; 28 | 29 | m_descriptions.insert({ handle, description }); 30 | 31 | m_next_handle++; 32 | return handle; 33 | } 34 | 35 | } /* wr */ 36 | -------------------------------------------------------------------------------- /src/root_signature_registry.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "registry.hpp" 19 | 20 | #include 21 | 22 | #include "d3d12/d3d12_enums.hpp" 23 | #include "d3d12/d3d12_structs.hpp" 24 | #include "d3d12/d3dx12.hpp" 25 | #include "util/named_type.hpp" 26 | 27 | namespace wr 28 | { 29 | using RootSignature = void; 30 | 31 | struct RootSignatureDescription 32 | { 33 | std::vector m_parameters; // TODO: Write platform independend version. 34 | std::vector m_samplers; // TODO: Move to platform independed location 35 | bool m_rtx = false; 36 | bool m_rtx_local = false; 37 | std::wstring name = L"Unknown root signature"; 38 | }; 39 | 40 | class RootSignatureRegistry : public internal::Registry 41 | { 42 | public: 43 | RootSignatureRegistry(); 44 | virtual ~RootSignatureRegistry() = default; 45 | 46 | RegistryHandle Register(RootSignatureDescription description); 47 | }; 48 | 49 | } /* wr */ 50 | -------------------------------------------------------------------------------- /src/rt_pipeline_registry.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "rt_pipeline_registry.hpp" 17 | 18 | namespace wr 19 | { 20 | 21 | RTPipelineRegistry::RTPipelineRegistry() : Registry() 22 | { 23 | } 24 | 25 | } /* wr */ 26 | -------------------------------------------------------------------------------- /src/rt_pipeline_registry.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "registry.hpp" 19 | 20 | #include 21 | #include 22 | 23 | #include "vertex.hpp" 24 | #include "d3d12/d3dx12.hpp" 25 | #include "d3d12/d3d12_enums.hpp" 26 | #include "util/named_type.hpp" 27 | 28 | namespace wr 29 | { 30 | 31 | using StateObject = void; 32 | 33 | struct StateObjectDescription 34 | { 35 | struct LibraryDesc 36 | { 37 | RegistryHandle shader_handle; 38 | std::vector exports; 39 | std::vector> m_hit_groups; // first = hit group | second = entry 40 | }; 41 | 42 | CD3DX12_STATE_OBJECT_DESC desc; 43 | LibraryDesc library_desc; 44 | 45 | std::uint64_t max_payload_size; 46 | std::uint64_t max_attributes_size; 47 | std::uint64_t max_recursion_depth; 48 | 49 | std::optional global_root_signature; 50 | std::vector local_root_signatures; 51 | }; 52 | 53 | class RTPipelineRegistry : public internal::Registry 54 | { 55 | public: 56 | RTPipelineRegistry(); 57 | virtual ~RTPipelineRegistry() = default; 58 | 59 | RegistryHandle Register(StateObjectDescription description) 60 | { 61 | auto handle = m_next_handle; 62 | 63 | m_descriptions.insert({ handle, description }); 64 | 65 | m_next_handle++; 66 | return handle; 67 | } 68 | }; 69 | 70 | } /* wr */ 71 | -------------------------------------------------------------------------------- /src/scene_graph/light_node.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "node.hpp" 19 | 20 | #include "../platform_independend_structs.hpp" 21 | 22 | namespace wr 23 | { 24 | 25 | struct LightNode : Node 26 | { 27 | explicit LightNode(LightType tid, DirectX::XMVECTOR col = { 1, 1, 1 }); 28 | explicit LightNode(DirectX::XMVECTOR rot, DirectX::XMVECTOR col = { 1, 1, 1 }); 29 | LightNode(DirectX::XMVECTOR pos, float rad, DirectX::XMVECTOR col = { 1, 1, 1 }); 30 | LightNode(DirectX::XMVECTOR pos, float rad, DirectX::XMVECTOR rot, float ang, DirectX::XMVECTOR col = { 1, 1, 1 }); 31 | 32 | LightNode(const LightNode& old); 33 | LightNode& operator=(const LightNode& old); 34 | 35 | //! Set angle 36 | void SetAngle(float ang); 37 | 38 | //! Set radius 39 | void SetRadius(float rad); 40 | 41 | //! Set type 42 | void SetType(LightType tid); 43 | 44 | //! Sets color 45 | void SetColor(DirectX::XMVECTOR col); 46 | 47 | //! Set data for a directional light 48 | void SetDirectional(DirectX::XMVECTOR rot, DirectX::XMVECTOR col = { 1, 1, 1 }); 49 | 50 | //! Set data for a point light 51 | void SetPoint(DirectX::XMVECTOR pos, float rad, DirectX::XMVECTOR col = { 1, 1, 1 }); 52 | 53 | //! Set data for a spot light 54 | void SetSpot(DirectX::XMVECTOR pos, float rad, DirectX::XMVECTOR rot, float ang, DirectX::XMVECTOR col = { 1, 1, 1 }); 55 | 56 | //! Set data for light physical size 57 | void SetLightSize(float size); 58 | 59 | //! Update 60 | void Update(uint32_t frame_idx); 61 | 62 | //! Helper for getting the LightType (doesn't include light count for the first light) 63 | LightType GetType(); 64 | 65 | //! Allocated data (either temp or array data) 66 | Light* m_light; 67 | 68 | //! Physical data 69 | Light m_temp; 70 | 71 | }; 72 | 73 | } /* wr */ -------------------------------------------------------------------------------- /src/scene_graph/mesh_node.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "mesh_node.hpp" 17 | 18 | namespace wr { 19 | 20 | MeshNode::MeshNode(Model* model) : Node(typeid(MeshNode)), m_model(model), m_materials(), m_visible(true) 21 | { 22 | } 23 | 24 | void MeshNode::Update(uint32_t frame_idx) 25 | { 26 | m_aabb = AABB::FromTransform(m_model->m_box, m_transform); 27 | 28 | SignalUpdate(frame_idx); 29 | } 30 | 31 | void MeshNode::AddMaterial(MaterialHandle handle) 32 | { 33 | m_materials.push_back(handle); 34 | 35 | CheckMaterialCount(); 36 | } 37 | 38 | std::vector& MeshNode::GetMaterials() 39 | { 40 | return m_materials; 41 | } 42 | 43 | void MeshNode::SetMaterials(std::vector const & materials) 44 | { 45 | m_materials = materials; 46 | 47 | CheckMaterialCount(); 48 | } 49 | 50 | void MeshNode::ClearMaterials() 51 | { 52 | m_materials.clear(); 53 | } 54 | 55 | void MeshNode::CheckMaterialCount() const 56 | { 57 | if (m_materials.size() > m_model->m_meshes.size()) 58 | { 59 | LOGW("A mesh node has more materials than meshes.") 60 | } 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /src/scene_graph/mesh_node.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "node.hpp" 19 | #include "../model_pool.hpp" 20 | #include "../util/aabb.hpp" 21 | 22 | namespace wr 23 | { 24 | 25 | struct MeshNode : Node 26 | { 27 | explicit MeshNode(Model* model); 28 | 29 | void Update(uint32_t frame_idx); 30 | /*! Add a material */ 31 | /*! 32 | You can add a material for every single sub-mesh. 33 | */ 34 | void AddMaterial(MaterialHandle handle); 35 | /*! Get all materials */ 36 | std::vector& GetMaterials(); 37 | /*! Set the materials */ 38 | void SetMaterials(std::vector const & materials); 39 | /*! Remove materials */ 40 | void ClearMaterials(); 41 | 42 | Model* m_model; 43 | AABB m_aabb; 44 | std::vector m_materials; 45 | bool m_visible; 46 | 47 | private: 48 | /*! Check whether their are more materials than meshes */ 49 | /*! 50 | If there are more materials than meshes. 51 | This function will throw a warning. 52 | */ 53 | void CheckMaterialCount() const; 54 | }; 55 | 56 | } /* wr */ -------------------------------------------------------------------------------- /src/scene_graph/node.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace wr 24 | { 25 | struct Node : std::enable_shared_from_this 26 | { 27 | Node(); 28 | explicit Node(std::type_info const & type_info); 29 | 30 | void SignalChange(); 31 | void SignalUpdate(unsigned int frame_idx); 32 | bool RequiresUpdate(unsigned int frame_idx); 33 | 34 | void SignalTransformChange(); 35 | void SignalTransformUpdate(unsigned int frame_idx); 36 | bool RequiresTransformUpdate(unsigned int frame_idx); 37 | 38 | //Takes roll, pitch and yaw and converts it to quaternion 39 | virtual void SetRotation(DirectX::XMVECTOR roll_pitch_yaw); 40 | virtual void SetRotationQuaternion(DirectX::XMVECTOR rotation); 41 | 42 | //Takes raw values of a quaternion 43 | virtual void SetQuaternionRotation( float x, float y, float z, float w ); 44 | 45 | //Sets position 46 | virtual void SetPosition(DirectX::XMVECTOR position); 47 | 48 | //Sets scale 49 | virtual void SetScale(DirectX::XMVECTOR scale); 50 | 51 | //Position, rotation (roll, pitch, yaw) and scale 52 | virtual void SetTransform(DirectX::XMVECTOR position, DirectX::XMVECTOR rotation, DirectX::XMVECTOR scale); 53 | 54 | //Update the transform; done automatically when SignalChange is called 55 | void UpdateTransform(); 56 | 57 | std::shared_ptr m_parent; 58 | std::vector> m_children; 59 | 60 | //Translation of mesh node 61 | DirectX::XMVECTOR m_position = { 0, 0, 0, 1 }; 62 | 63 | //Rotation as quaternion 64 | DirectX::XMVECTOR m_rotation; 65 | 66 | //Rotation in radians 67 | DirectX::XMVECTOR m_rotation_radians = { 0,0,0 }; 68 | 69 | //Scale 70 | DirectX::XMVECTOR m_scale = { 1, 1, 1, 0 }; 71 | 72 | //Transformation 73 | DirectX::XMMATRIX m_local_transform, m_transform, m_prev_transform; 74 | 75 | const std::type_info& m_type_info; 76 | 77 | protected: 78 | bool m_use_quaternion = false; 79 | 80 | private: 81 | std::bitset<3> m_requires_update; 82 | std::bitset<3> m_requires_transform_update; 83 | }; 84 | } // namespace wr 85 | -------------------------------------------------------------------------------- /src/scene_graph/skybox_node.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "skybox_node.hpp" 17 | 18 | namespace wr 19 | { 20 | void SkyboxNode::UpdateSkybox(TextureHandle new_equirectangular, unsigned int frame_idx) 21 | { 22 | m_irradiance.value().m_pool->MarkForUnload(m_irradiance.value(), frame_idx); 23 | m_irradiance = std::nullopt; 24 | 25 | m_skybox.value().m_pool->MarkForUnload(m_skybox.value(), frame_idx); 26 | m_skybox = std::nullopt; 27 | 28 | m_prefiltered_env_map.value().m_pool->MarkForUnload(m_prefiltered_env_map.value(), frame_idx); 29 | m_prefiltered_env_map = std::nullopt; 30 | 31 | if (m_hdr.m_pool) 32 | { 33 | m_hdr.m_pool->MarkForUnload(m_hdr, frame_idx); 34 | 35 | #ifdef _DEBUG 36 | //Decide if we want to break when developing in case we enter this function 37 | //as in theory m_hdr needed to be cleaned from the render task, if that's not the case something went wrong. 38 | LOGC("[ERROR]: M_HDR is supposed to be an invalid handle at this stage. If that's not the case, the next line of code could leak memory"); 39 | #endif // DEBUG 40 | } 41 | 42 | m_hdr = new_equirectangular; 43 | } 44 | } /* wr */ 45 | -------------------------------------------------------------------------------- /src/scene_graph/skybox_node.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | #include "scene_graph.hpp" 18 | 19 | namespace wr { 20 | 21 | struct SkyboxNode : Node 22 | { 23 | explicit SkyboxNode(wr::TextureHandle hdr_texture, std::optional cubemap = std::nullopt, std::optional irradiance = std::nullopt) 24 | : Node::Node(typeid(SkyboxNode)) 25 | , m_hdr(hdr_texture) 26 | , m_skybox(cubemap) 27 | , m_irradiance(irradiance) 28 | {} 29 | 30 | void UpdateSkybox(TextureHandle new_equirectangular, unsigned int frame_idx); 31 | 32 | wr::TextureHandle m_hdr; 33 | std::optional m_skybox; 34 | std::optional m_irradiance; 35 | std::optional m_prefiltered_env_map; 36 | }; 37 | 38 | };// namespace wr -------------------------------------------------------------------------------- /src/settings.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | namespace wr::settings 19 | { 20 | 21 | static const constexpr bool use_multithreading = true; 22 | static const constexpr unsigned int num_frame_graph_threads = 4; 23 | 24 | static const constexpr std::uint8_t default_textures_count = 5; 25 | static const constexpr std::uint32_t default_textures_size_in_bytes = 4ul * 1024ul * 1024ul; 26 | static constexpr const char* default_albedo_path = "resources/materials/metalgrid2_basecolor.png"; 27 | static constexpr const char* default_normal_path = "resources/materials/flat_normal.png"; 28 | static constexpr const char* default_white_texture = "resources/materials/white.png"; 29 | static constexpr const char* default_black_texture = "resources/materials/black.png"; 30 | 31 | } /* wr::settings */ 32 | -------------------------------------------------------------------------------- /src/shader_registry.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "shader_registry.hpp" 17 | 18 | namespace wr 19 | { 20 | 21 | ShaderRegistry::ShaderRegistry() : Registry() 22 | { 23 | } 24 | 25 | RegistryHandle ShaderRegistry::Register(ShaderDescription description) 26 | { 27 | auto handle = m_next_handle; 28 | 29 | m_descriptions.insert({ handle, description }); 30 | 31 | m_next_handle++; 32 | return handle; 33 | } 34 | 35 | } /* wr */ 36 | -------------------------------------------------------------------------------- /src/shader_registry.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "registry.hpp" 19 | #include "d3d12/d3d12_enums.hpp" 20 | #include "util/named_type.hpp" 21 | 22 | namespace wr 23 | { 24 | using Shader = void; 25 | 26 | struct ShaderDescription 27 | { 28 | std::string path; 29 | std::string entry; 30 | ShaderType type; 31 | std::vector> defines; 32 | }; 33 | 34 | class ShaderRegistry : public internal::Registry 35 | { 36 | public: 37 | ShaderRegistry(); 38 | virtual ~ShaderRegistry() = default; 39 | 40 | RegistryHandle Register(ShaderDescription description); 41 | }; 42 | 43 | } /* wr */ 44 | -------------------------------------------------------------------------------- /src/structs.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | #include 18 | #include 19 | 20 | namespace wr 21 | { 22 | 23 | struct Texture { }; 24 | 25 | struct ReadbackBuffer { }; 26 | 27 | class TexturePool; 28 | 29 | struct TextureHandle 30 | { 31 | TexturePool* m_pool = nullptr; 32 | std::uint32_t m_id = 0; 33 | }; 34 | 35 | struct MaterialUVScales 36 | { 37 | float m_albedo_scale = 1.0f; 38 | float m_normal_scale = 1.0f; 39 | float m_roughness_scale = 1.0f; 40 | float m_metallic_scale = 1.0f; 41 | float m_emissive_scale = 1.0f; 42 | float m_ao_scale = 1.0f; 43 | }; 44 | 45 | struct CPUTexture 46 | { 47 | float* m_data = nullptr; 48 | unsigned int m_buffer_width; 49 | unsigned int m_buffer_height; 50 | unsigned int m_bytes_per_pixel; 51 | }; 52 | 53 | class MaterialPool; 54 | 55 | struct MaterialHandle 56 | { 57 | MaterialPool* m_pool; 58 | std::uint32_t m_id; 59 | 60 | friend bool operator ==(MaterialHandle const & lhs, MaterialHandle const & rhs) 61 | { 62 | return lhs.m_pool == rhs.m_pool && lhs.m_id == rhs.m_id; 63 | } 64 | 65 | friend bool operator!=(MaterialHandle const& lhs, MaterialHandle const& rhs) 66 | { 67 | return lhs.m_pool != rhs.m_pool || lhs.m_id != rhs.m_id; 68 | } 69 | }; 70 | 71 | } -------------------------------------------------------------------------------- /src/structured_buffer_pool.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "structured_buffer_pool.hpp" 17 | 18 | namespace wr 19 | { 20 | StructuredBufferPool::StructuredBufferPool(std::size_t size_in_bytes) : 21 | m_size_in_bytes(size_in_bytes) 22 | { 23 | } 24 | 25 | StructuredBufferHandle * StructuredBufferPool::Create(std::size_t size, std::size_t stride, bool used_as_uav) 26 | { 27 | std::lock_guard lock(m_mutex); 28 | 29 | return CreateBuffer(size, stride, used_as_uav); 30 | } 31 | 32 | void StructuredBufferPool::Destroy(StructuredBufferHandle * handle) 33 | { 34 | std::lock_guard lock(m_mutex); 35 | 36 | DestroyBuffer(handle); 37 | } 38 | 39 | void StructuredBufferPool::Update(StructuredBufferHandle * handle, void * data, std::size_t size, std::size_t offset) 40 | { 41 | std::lock_guard lock(m_mutex); 42 | 43 | UpdateBuffer(handle, data, size, offset); 44 | } 45 | 46 | } /* wr */ -------------------------------------------------------------------------------- /src/structured_buffer_pool.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include 19 | #include 20 | 21 | namespace wr 22 | { 23 | class StructuredBufferPool; 24 | 25 | struct StructuredBufferHandle 26 | { 27 | StructuredBufferPool* m_pool; 28 | }; 29 | 30 | class StructuredBufferPool 31 | { 32 | public: 33 | explicit StructuredBufferPool(std::size_t size_in_bytes); 34 | virtual ~StructuredBufferPool() = default; 35 | 36 | StructuredBufferPool(StructuredBufferPool const &) = delete; 37 | StructuredBufferPool& operator=(StructuredBufferPool const &) = delete; 38 | StructuredBufferPool(StructuredBufferPool&&) = delete; 39 | StructuredBufferPool& operator=(StructuredBufferPool&&) = delete; 40 | 41 | [[nodiscard]] StructuredBufferHandle* Create(std::size_t size, std::size_t stride, bool used_as_uav); 42 | void Destroy(StructuredBufferHandle* handle); 43 | 44 | void Update(StructuredBufferHandle* handle, void* data, std::size_t size, std::size_t offset); 45 | 46 | virtual void Evict() = 0; 47 | virtual void MakeResident() = 0; 48 | 49 | protected: 50 | [[nodiscard]] virtual StructuredBufferHandle* CreateBuffer(std::size_t size, std::size_t stride, bool used_as_uav) = 0; 51 | virtual void DestroyBuffer(StructuredBufferHandle* handle) = 0; 52 | virtual void UpdateBuffer(StructuredBufferHandle* handle, void* data, std::size_t size, std::size_t offset) = 0; 53 | 54 | std::size_t m_size_in_bytes; 55 | std::mutex m_mutex; 56 | }; 57 | 58 | 59 | } /* wr */ -------------------------------------------------------------------------------- /src/util/aabb.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace wr 23 | { 24 | struct Box 25 | { 26 | struct Corners 27 | { 28 | DirectX::XMVECTOR m_xmin, m_xmax, m_ymin, m_ymax, m_zmin, m_zmax; 29 | }; 30 | 31 | union 32 | { 33 | Corners m_corners; 34 | DirectX::XMVECTOR m_data[6]; 35 | }; 36 | 37 | //Max bounds on each corner 38 | Box(); 39 | 40 | Box(DirectX::XMVECTOR (&corners)[6]); 41 | 42 | DirectX::XMVECTOR &operator[](size_t i); 43 | 44 | //Expand bounds using position 45 | void ExpandFromVector(DirectX::XMVECTOR pos); 46 | 47 | void Expand(float(&pos)[3]); 48 | 49 | }; 50 | 51 | struct Sphere 52 | { 53 | 54 | union 55 | { 56 | DirectX::XMVECTOR m_sphere; 57 | 58 | struct 59 | { 60 | DirectX::XMFLOAT3 m_center; 61 | float m_radius; 62 | }; 63 | 64 | struct { 65 | float m_data[4]; 66 | }; 67 | 68 | }; 69 | 70 | Sphere(); 71 | Sphere(DirectX::XMVECTOR center, float radius); 72 | 73 | }; 74 | 75 | struct AABB 76 | { 77 | union 78 | { 79 | 80 | DirectX::XMVECTOR m_data[2]; 81 | 82 | struct 83 | { 84 | DirectX::XMVECTOR m_min, m_max; 85 | }; 86 | 87 | struct { 88 | 89 | float m_minf[3]; 90 | float m_pad0; 91 | 92 | float m_maxf[3]; 93 | float m_pad1; 94 | 95 | }; 96 | 97 | }; 98 | 99 | AABB(); 100 | AABB(DirectX::XMVECTOR min, DirectX::XMVECTOR max); 101 | 102 | DirectX::XMVECTOR& operator[](size_t i); 103 | 104 | //Uses position to expand the AABB 105 | void Expand(DirectX::XMVECTOR pos); 106 | 107 | //Check if the frustum planes intersect with the AABB 108 | bool InFrustum(const std::array& planes) const; 109 | 110 | //Check if the sphere intersects with the AABB 111 | bool Contains(const Sphere& sphere) const; 112 | 113 | //Generates AABB from transform and box 114 | static AABB FromTransform(Box box, DirectX::XMMATRIX transform); 115 | 116 | }; 117 | 118 | } -------------------------------------------------------------------------------- /src/util/file_watcher.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "delegate.hpp" 26 | 27 | namespace util 28 | { 29 | 30 | //! FileWatcher 31 | /*! 32 | This is a simple file watcher that checks every X milliseconds whether a file has been created, modified or erased 33 | and gives you a callback if a change is detected. 34 | This file watcher can run both asyncronously and syncrounously. 35 | */ 36 | class FileWatcher 37 | { 38 | public: 39 | enum class FileStatus 40 | { 41 | MODIFIED, 42 | CREATED, 43 | ERASED 44 | }; 45 | 46 | //! FileWatcher constructor 47 | /*! 48 | \param path The path to watch for changes. 49 | \param delay The interval used to check changes. 50 | \param regular_files_only Setting this to true will ignore all non-regular files. 51 | */ 52 | FileWatcher(std::string const & path, const std::chrono::milliseconds delay, bool regular_files_only = false); 53 | ~FileWatcher(); 54 | 55 | //! Launches the file watcher. This will stall the current thread. 56 | void Start(util::Delegate const & callback); 57 | //! Launches the file watcher asynchrounously. When the file watcher goes out of scope the thread gets killed. 58 | void StartAsync(util::Delegate const & callback); 59 | 60 | private: 61 | bool m_running; 62 | bool m_regular_files_only; 63 | const std::chrono::milliseconds m_delay; 64 | std::string m_watch_path; 65 | std::unordered_map m_paths; 66 | std::thread m_thread; 67 | }; 68 | 69 | } /* util */ 70 | -------------------------------------------------------------------------------- /src/util/log.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "log.hpp" 17 | 18 | namespace util 19 | { 20 | std::function log_callback::impl = nullptr; 21 | wr::LogfileHandler* log_file_handler = nullptr; 22 | } 23 | -------------------------------------------------------------------------------- /src/util/logfile_handler.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "logfile_handler.hpp" 17 | 18 | #include 19 | 20 | wr::LogfileHandler::LogfileHandler() 21 | { 22 | std::filesystem::path path("./logs/"); 23 | if (!std::filesystem::exists(path)) 24 | { 25 | std::filesystem::create_directory(path); 26 | } 27 | std::stringstream ss; 28 | ss << "log-default"; 29 | path /= ss.str(); 30 | std::filesystem::create_directory(path); 31 | path /= "default-wisp.log"; 32 | m_file = fopen(path.string().c_str(), "w"); 33 | } 34 | 35 | wr::LogfileHandler::LogfileHandler(std::filesystem::path& dir_path, std::string& file_name) 36 | { 37 | std::filesystem::path path("./logs/"); 38 | if (!std::filesystem::exists(path)) 39 | { 40 | std::filesystem::create_directory(path); 41 | } 42 | path /= dir_path; 43 | std::filesystem::create_directory(path); 44 | path /= file_name; 45 | m_file = fopen(path.string().c_str(), "w"); 46 | } 47 | 48 | std::FILE* wr::LogfileHandler::GetFilePtr() 49 | { 50 | return m_file; 51 | } 52 | 53 | wr::LogfileHandler::~LogfileHandler() 54 | { 55 | fflush(m_file); 56 | fclose(m_file); 57 | } 58 | 59 | const std::filesystem::path& wr::LogfileHandler::GetDirPath() 60 | { 61 | return dir_path; 62 | } 63 | -------------------------------------------------------------------------------- /src/util/logfile_handler.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | #include 18 | 19 | namespace wr 20 | { 21 | class LogfileHandler { 22 | public: 23 | LogfileHandler(); 24 | LogfileHandler(std::filesystem::path& dir_path, std::string& file_name); 25 | ~LogfileHandler(); 26 | 27 | std::FILE* GetFilePtr(); 28 | const std::filesystem::path& GetDirPath(); 29 | 30 | private: 31 | std::FILE* m_file = nullptr; 32 | std::filesystem::path dir_path; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /src/util/named_type.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | namespace util 19 | { 20 | 21 | //! Named Type 22 | /*! 23 | This is a naive named type implementation. 24 | Its only use is for member variables. 25 | For a more detailed implementation see Jonathan Boccara's general purpose implementation 26 | */ 27 | template 28 | class NamedType 29 | { 30 | public: 31 | explicit constexpr NamedType(T const& value) : m_value(value) 32 | { } 33 | 34 | constexpr T& Get() 35 | { 36 | return m_value; 37 | } 38 | constexpr T const& Get() const 39 | { 40 | return m_value; 41 | } 42 | 43 | operator T&() 44 | { 45 | return m_value; 46 | } 47 | 48 | private: 49 | T m_value; 50 | }; 51 | 52 | } /* util */ -------------------------------------------------------------------------------- /src/util/pair_hash.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | namespace util 19 | { 20 | 21 | struct PairHash { 22 | template 23 | std::size_t operator() (const std::pair &pair) const 24 | { 25 | std::uint64_t hash = 0; 26 | for(int i=0;i()(pair.first) ^ hash; 31 | } 32 | }; 33 | 34 | } /* util */ 35 | -------------------------------------------------------------------------------- /src/util/strings.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | #include 18 | 19 | namespace util 20 | { 21 | inline std::optional GetFileExtension(std::string_view path) 22 | { 23 | std::size_t pos = path.find_last_of("."); 24 | 25 | if (pos != std::string_view::npos) 26 | { 27 | std::size_t length = path.length(); 28 | std::string_view extension = path.substr(pos, length); 29 | 30 | return extension; 31 | } 32 | else 33 | { 34 | return {}; 35 | } 36 | } 37 | 38 | inline bool MatchFileExtension(std::string_view path, std::string_view extension) 39 | { 40 | std::size_t dot_position = path.find_last_of("."); 41 | 42 | if (dot_position == std::string_view::npos) 43 | return false; 44 | 45 | std::size_t last_occurrence_pos = path.rfind(extension); 46 | 47 | if (last_occurrence_pos == std::string_view::npos) 48 | return false; 49 | 50 | return last_occurrence_pos >= dot_position; 51 | } 52 | } -------------------------------------------------------------------------------- /src/util/user_literals.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | constexpr float operator"" _deg(long double deg) 19 | { 20 | return DirectX::XMConvertToRadians(static_cast(deg)); 21 | } 22 | 23 | constexpr float operator"" _rad(long double rad) 24 | { 25 | return DirectX::XMConvertToDegrees(static_cast(rad)); 26 | } 27 | 28 | constexpr float operator"" _deg(unsigned long long int deg) 29 | { 30 | return DirectX::XMConvertToRadians(static_cast(deg)); 31 | } 32 | 33 | constexpr float operator"" _rad(unsigned long long int rad) 34 | { 35 | return DirectX::XMConvertToDegrees(static_cast(rad)); 36 | } 37 | 38 | constexpr std::size_t operator"" _kb(std::size_t kilobytes) 39 | { 40 | return kilobytes * 1024; 41 | } 42 | 43 | constexpr std::size_t operator"" _mb(std::size_t megabytes) 44 | { 45 | return megabytes * 1024 * 1024; 46 | } -------------------------------------------------------------------------------- /src/wisp.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | // Core 19 | #include "entry.hpp" 20 | #include "window.hpp" 21 | #include "vertex.hpp" 22 | #include "renderer.hpp" 23 | 24 | // Scene Graph 25 | #include "scene_graph/scene_graph.hpp" 26 | #include "scene_graph/mesh_node.hpp" 27 | #include "scene_graph/camera_node.hpp" 28 | #include "scene_graph/skybox_node.hpp" 29 | 30 | // Frame Graph 31 | #include "frame_graph/frame_graph.hpp" -------------------------------------------------------------------------------- /src/wisprenderer_export.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef WISPRENDERER_EXPORT_H 18 | #define WISPRENDERER_EXPORT_H 19 | 20 | #ifdef WISPRENDERER_STATIC_DEFINE 21 | # define WISPRENDERER_EXPORT 22 | # define WISPRENDERER_NO_EXPORT 23 | #else 24 | # ifndef WISPRENDERER_EXPORT 25 | # ifdef WispRenderer_EXPORTS 26 | /* We are building this library */ 27 | # define WISPRENDERER_EXPORT __declspec(dllexport) 28 | # else 29 | /* We are using this library */ 30 | # define WISPRENDERER_EXPORT __declspec(dllimport) 31 | # endif 32 | # endif 33 | 34 | # ifndef WISPRENDERER_NO_EXPORT 35 | # define WISPRENDERER_NO_EXPORT 36 | # endif 37 | #endif 38 | 39 | #ifndef WISPRENDERER_DEPRECATED 40 | # define WISPRENDERER_DEPRECATED __declspec(deprecated) 41 | #endif 42 | 43 | #ifndef WISPRENDERER_DEPRECATED_EXPORT 44 | # define WISPRENDERER_DEPRECATED_EXPORT WISPRENDERER_EXPORT WISPRENDERER_DEPRECATED 45 | #endif 46 | 47 | #ifndef WISPRENDERER_DEPRECATED_NO_EXPORT 48 | # define WISPRENDERER_DEPRECATED_NO_EXPORT WISPRENDERER_NO_EXPORT WISPRENDERER_DEPRECATED 49 | #endif 50 | 51 | #if 0 /* DEFINE_NO_DEPRECATED */ 52 | # ifndef WISPRENDERER_NO_DEPRECATED 53 | # define WISPRENDERER_NO_DEPRECATED 54 | # endif 55 | #endif 56 | 57 | #endif /* WISPRENDERER_EXPORT_H */ 58 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | file(GLOB COMMON_SOURCES "common/*.cpp") 15 | file(GLOB COMMON_HEADERS "common/*.hpp") 16 | 17 | function(add_test TEST_DIR TEST_NAME) 18 | message(STATUS "Configuring example ${TEST_NAME} in ${TEST_DIR}") 19 | 20 | # source 21 | file(GLOB SOURCES "${TEST_DIR}/*.cpp") 22 | file(GLOB HEADERS "${TEST_DIR}/*.hpp") 23 | 24 | add_executable(${TEST_NAME} ${HEADERS} ${SOURCES} ${COMMON_HEADERS} ${COMMON_SOURCES}) 25 | target_include_directories(${TEST_NAME} PUBLIC ../src/) 26 | target_link_libraries(${TEST_NAME} WispRenderer BulletCollision BulletDynamics LinearMath) 27 | set_target_properties(${TEST_NAME} PROPERTIES CXX_STANDARD 20) 28 | set_target_properties(${TEST_NAME} PROPERTIES CXX_EXTENSIONS OFF) 29 | set_target_properties(${TEST_NAME} PROPERTIES CMAKE_CXX_STANDARD_REQUIRED ON) 30 | set_target_properties(${TEST_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/../") 31 | endfunction(add_test) 32 | 33 | function(add_example EXAMPLE_DIR EXAMPLE_NAME) 34 | message(STATUS "Configuring example ${EXAMPLE_NAME} in ${EXAMPLE_DIR}") 35 | 36 | # source 37 | file(GLOB SOURCES "${EXAMPLE_DIR}/*.cpp") 38 | file(GLOB HEADERS "${EXAMPLE_DIR}/*.hpp") 39 | 40 | add_executable(${EXAMPLE_NAME} WIN32 ${HEADERS} ${SOURCES} ${COMMON_HEADERS} ${COMMON_SOURCES}) 41 | target_include_directories(${EXAMPLE_NAME} PUBLIC ../src/) 42 | target_link_libraries(${EXAMPLE_NAME} WispRenderer BulletCollision BulletDynamics LinearMath) 43 | set_target_properties(${EXAMPLE_NAME} PROPERTIES CXX_STANDARD 20) 44 | set_target_properties(${EXAMPLE_NAME} PROPERTIES CXX_EXTENSIONS OFF) 45 | set_target_properties(${EXAMPLE_NAME} PROPERTIES CMAKE_CXX_STANDARD_REQUIRED ON) 46 | set_target_properties(${EXAMPLE_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/../") 47 | endfunction(add_example) 48 | 49 | add_test(demo Demo) 50 | add_test(graphics_benchmark GraphicsBenchmark) 51 | -------------------------------------------------------------------------------- /tests/common/scene.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include 19 | 20 | #include "wisp.hpp" 21 | #include "d3d12/d3d12_renderer.hpp" 22 | #include "util/user_literals.hpp" 23 | 24 | class Scene 25 | { 26 | public: 27 | Scene(std::size_t material_pool_size, 28 | std::size_t model_pool_vb_size, 29 | std::size_t model_pool_ib_size); 30 | virtual ~Scene(); 31 | 32 | virtual void Init(wr::D3D12RenderSystem* rs, unsigned int width, unsigned int height, void* extra = nullptr); 33 | virtual void Update(float delta = 0) = 0; 34 | std::shared_ptr GetSceneGraph(); 35 | template 36 | std::shared_ptr GetCamera(); 37 | 38 | void LoadLightsFromJSON(); 39 | void SaveLightsToJSON(); 40 | 41 | protected: 42 | virtual void LoadResources() = 0; 43 | virtual void BuildScene(unsigned int width, unsigned int height, void* extra = nullptr) = 0; 44 | 45 | const std::size_t m_material_pool_size; 46 | const std::size_t m_model_pool_vb_size; 47 | const std::size_t m_model_pool_ib_size; 48 | 49 | std::shared_ptr m_scene_graph; 50 | std::shared_ptr m_model_pool; 51 | std::shared_ptr m_texture_pool; 52 | std::shared_ptr m_material_pool; 53 | 54 | std::optional m_lights_path; 55 | }; 56 | 57 | template 58 | std::shared_ptr Scene::GetCamera() 59 | { 60 | return std::static_pointer_cast(m_scene_graph->GetActiveCamera()); 61 | } 62 | -------------------------------------------------------------------------------- /tests/demo/physics_engine.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "wisp.hpp" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #define USE_MOTIONSTATE 1 27 | 28 | namespace wr 29 | { 30 | struct Model; 31 | } 32 | 33 | namespace phys 34 | { 35 | namespace util 36 | { 37 | inline btVector3 DXV3toBV3(DirectX::XMVECTOR v) 38 | { 39 | return btVector3(v.m128_f32[0], v.m128_f32[1], v.m128_f32[2]); 40 | } 41 | inline DirectX::XMVECTOR BV3toDXV3(btVector3 v) 42 | { 43 | return { v.x(), v.y(), v.z() }; 44 | } 45 | } 46 | 47 | struct PhysicsEngine 48 | { 49 | btAlignedObjectArray collision_shapes; 50 | btBroadphaseInterface* broadphase; 51 | btCollisionDispatcher* coll_dispatcher; 52 | btConstraintSolver* constraint_solver; 53 | btDefaultCollisionConfiguration* collision_config; 54 | btDiscreteDynamicsWorld* phys_world; 55 | 56 | void CreatePhysicsWorld(); 57 | 58 | btBoxShape* CreateBoxShape(const btVector3& halfExtents); 59 | btSphereShape* CreateSphereShape(const float radius); 60 | btCapsuleShape* CreateCapsuleShape(const float width, const float height); 61 | std::vector CreateConvexShape(wr::ModelData* model); 62 | std::vector CreateTriangleMeshShape(wr::ModelData* model); 63 | 64 | btRigidBody* CreateRigidBody(float mass, const btTransform& startTransform, btCollisionShape* shape); 65 | 66 | void UpdateSim(float delta, wr::SceneGraph& sg); 67 | 68 | ~PhysicsEngine(); 69 | }; 70 | 71 | } /* phys*/ -------------------------------------------------------------------------------- /tests/demo/physics_node.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "scene_graph/mesh_node.hpp" 24 | 25 | namespace phys 26 | { 27 | struct PhysicsEngine; 28 | } 29 | 30 | struct PhysicsMeshNode : public wr::MeshNode 31 | { 32 | btCollisionShape* m_shape = nullptr; 33 | btRigidBody* m_rigid_body = nullptr; 34 | 35 | std::optional> m_shapes; 36 | std::optional> m_rigid_bodies; 37 | 38 | phys::PhysicsEngine& m_phys_engine; 39 | 40 | float m_mass = 0; 41 | 42 | PhysicsMeshNode(phys::PhysicsEngine* phys_engine, wr::Model* model) : MeshNode(model), m_phys_engine(*phys_engine) { } 43 | ~PhysicsMeshNode(); 44 | 45 | void SetMass(float mass); 46 | void SetRestitution(float value); 47 | 48 | void SetupSimpleBoxColl(phys::PhysicsEngine& phys_engine, DirectX::XMVECTOR scale); 49 | void SetupSimpleSphereColl(phys::PhysicsEngine& phys_engine, float radius); 50 | void SetupConvex(phys::PhysicsEngine& phys_engine, wr::ModelData* model); 51 | void SetupTriangleMesh(phys::PhysicsEngine& phys_engine, wr::ModelData* model); 52 | 53 | void SetPosition(DirectX::XMVECTOR position) override; 54 | void SetRotation(DirectX::XMVECTOR roll_pitch_yaw) override; 55 | void SetScale(DirectX::XMVECTOR scale) override; 56 | }; -------------------------------------------------------------------------------- /tests/demo/scene_alien.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "scene_alien.hpp" 19 | 20 | AlienScene::AlienScene() : 21 | Scene(256, 20_mb, 20_mb), 22 | m_alien_model(nullptr), 23 | m_skybox({}) 24 | { 25 | m_lights_path = "resources/alien_lights.json"; 26 | } 27 | 28 | void AlienScene::LoadResources() 29 | { 30 | // Models 31 | m_alien_model = m_model_pool->LoadWithMaterials(m_material_pool.get(), m_texture_pool.get(), "resources/models/alien/scene.gltf"); 32 | 33 | // Textures 34 | m_skybox = m_texture_pool->LoadFromFile("resources/materials/Ice_Lake_Ref.hdr", false, false); 35 | } 36 | 37 | void AlienScene::BuildScene(unsigned int width, unsigned int height, void* extra) 38 | { 39 | m_camera = m_scene_graph->CreateChild(nullptr, 90.f, (float)width / (float)height); 40 | m_camera->SetPosition({ 1.243, 1.025, -0.640 }); 41 | m_camera->SetRotation({ 1.719_deg, 117.456_deg, 0 }); 42 | m_camera->SetSpeed(5); 43 | 44 | m_camera_spline_node = m_scene_graph->CreateChild(nullptr, "Camera Spline", false); 45 | 46 | auto skybox = m_scene_graph->CreateChild(nullptr, m_skybox); 47 | 48 | // Geometry 49 | auto alien = m_scene_graph->CreateChild(nullptr, m_alien_model); 50 | alien->SetPosition({ 0, -1, 0 }); 51 | alien->SetRotation({ 0, 90_deg, 0 }); 52 | alien->SetScale({ 0.01f,0.01f,0.01f }); 53 | 54 | // Lights 55 | LoadLightsFromJSON(); 56 | } 57 | 58 | void AlienScene::Update(float delta) 59 | { 60 | m_camera->Update(delta); 61 | m_camera_spline_node->UpdateSplineNode(delta, m_camera); 62 | } 63 | -------------------------------------------------------------------------------- /tests/demo/scene_alien.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "wisp.hpp" 20 | #include "window.hpp" 21 | #include "scene_graph/scene_graph.hpp" 22 | #include "imgui/imgui.hpp" 23 | #include "physics_node.hpp" 24 | #include "debug_camera.hpp" 25 | #include "spline_node.hpp" 26 | #include "../common/scene.hpp" 27 | 28 | class AlienScene : public Scene 29 | { 30 | public: 31 | AlienScene(); 32 | 33 | void Update(float delta = 0) final; 34 | 35 | protected: 36 | void LoadResources() final; 37 | void BuildScene(unsigned int width, unsigned int height, void* extra = nullptr) final; 38 | 39 | private: 40 | // Models 41 | wr::Model* m_alien_model; 42 | 43 | // Textures 44 | wr::TextureHandle m_skybox; 45 | 46 | // Nodes 47 | std::shared_ptr m_camera; 48 | std::shared_ptr m_camera_spline_node; 49 | }; 50 | -------------------------------------------------------------------------------- /tests/demo/scene_emibl.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "wisp.hpp" 20 | #include "window.hpp" 21 | #include "scene_graph/scene_graph.hpp" 22 | #include "imgui/imgui.hpp" 23 | #include "debug_camera.hpp" 24 | #include "../common/scene.hpp" 25 | 26 | class EmiblScene : public Scene 27 | { 28 | public: 29 | EmiblScene(); 30 | ~EmiblScene(); 31 | 32 | void Update(float delta = 0) final; 33 | 34 | protected: 35 | void LoadResources() final; 36 | void BuildScene(unsigned int width, unsigned int height, void* extra = nullptr) final; 37 | 38 | private: 39 | // Models 40 | wr::Model* m_cube_model; 41 | wr::Model* m_plane_model; 42 | wr::Model* m_material_knob_model; 43 | 44 | // Textures 45 | wr::TextureHandle m_skybox; 46 | 47 | // Materials 48 | wr::MaterialHandle m_rusty_metal_material; 49 | wr::MaterialHandle m_knob_material; 50 | wr::MaterialHandle m_material_handles[11]; 51 | 52 | // Nodes 53 | std::shared_ptr m_camera; 54 | std::shared_ptr m_models[10]; 55 | std::shared_ptr m_platforms[10]; 56 | }; -------------------------------------------------------------------------------- /tests/demo/scene_sponza.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "wisp.hpp" 20 | #include "window.hpp" 21 | #include "scene_graph/scene_graph.hpp" 22 | #include "imgui/imgui.hpp" 23 | #include "physics_node.hpp" 24 | #include "debug_camera.hpp" 25 | #include "spline_node.hpp" 26 | #include "../common/scene.hpp" 27 | 28 | class SponzaScene : public Scene 29 | { 30 | public: 31 | SponzaScene(); 32 | ~SponzaScene(); 33 | 34 | void Update(float delta = 0) final; 35 | 36 | protected: 37 | void LoadResources() final; 38 | void BuildScene(unsigned int width, unsigned int height, void* extra = nullptr) final; 39 | 40 | private: 41 | // Models 42 | wr::Model* m_sphere_model; 43 | wr::Model* m_sponza_model; 44 | wr::ModelData* m_sponza_model_data; 45 | 46 | // Textures 47 | wr::TextureHandle m_skybox; 48 | 49 | // Materials 50 | std::vector m_mirror_materials; 51 | 52 | // Nodes 53 | std::shared_ptr m_camera; 54 | std::shared_ptr m_camera_spline_node; 55 | std::shared_ptr m_sponza_node; 56 | 57 | float m_time; 58 | }; -------------------------------------------------------------------------------- /tests/demo/scene_viknell.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "wisp.hpp" 20 | #include "window.hpp" 21 | #include "scene_graph/scene_graph.hpp" 22 | #include "imgui/imgui.hpp" 23 | #include "physics_node.hpp" 24 | #include "debug_camera.hpp" 25 | #include "spline_node.hpp" 26 | #include "../common/scene.hpp" 27 | 28 | class ViknellScene : public Scene 29 | { 30 | public: 31 | ViknellScene(); 32 | ~ViknellScene(); 33 | 34 | void Update(float delta = 0) final; 35 | 36 | protected: 37 | void LoadResources() final; 38 | void BuildScene(unsigned int width, unsigned int height, void* extra = nullptr) final; 39 | 40 | private: 41 | // Models 42 | wr::Model* m_sphere_model; 43 | wr::Model* m_plane_model; 44 | wr::ModelData* m_plane_model_data; 45 | wr::Model* m_xbot_model; 46 | 47 | // Textures 48 | wr::TextureHandle m_skybox; 49 | 50 | // Materials 51 | wr::MaterialHandle m_bamboo_material; 52 | wr::MaterialHandle m_mirror_material; 53 | 54 | // Nodes 55 | std::shared_ptr m_camera; 56 | std::shared_ptr m_camera_spline_node; 57 | std::shared_ptr m_xbot_node; 58 | 59 | float m_time; 60 | }; -------------------------------------------------------------------------------- /tests/demo/spline_library/utils/calculus.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class SplineLibraryCalculus { 7 | private: 8 | SplineLibraryCalculus() = default; 9 | 10 | public: 11 | //use the gauss-legendre quadrature algorithm to numerically integrate f from a to b 12 | //as of this writing, hardcoded to use 13 points 13 | template 14 | inline static IntegrandType gaussLegendreQuadratureIntegral(Function f, floating_t a, floating_t b) 15 | { 16 | const size_t NUM_POINTS = 13; 17 | 18 | //these are precomputed :( It would be cool to compute these at compile time, but apparently 19 | //it's not easy to compute the points/weights just given the number of points. 20 | //it involves computing every root of a polynomial. which can obviously be done, but not in a reasonable amount of code 21 | std::array quadraturePoints = { 22 | floating_t( 0.0000000000000000), 23 | floating_t(-0.2304583159551348), 24 | floating_t( 0.2304583159551348), 25 | floating_t(-0.4484927510364469), 26 | floating_t( 0.4484927510364469), 27 | floating_t(-0.6423493394403402), 28 | floating_t( 0.6423493394403402), 29 | floating_t(-0.8015780907333099), 30 | floating_t( 0.8015780907333099), 31 | floating_t(-0.9175983992229779), 32 | floating_t( 0.9175983992229779), 33 | floating_t(-0.9841830547185881), 34 | floating_t( 0.9841830547185881) 35 | }; 36 | 37 | std::array quadratureWeights = { 38 | floating_t(0.2325515532308739), 39 | floating_t(0.2262831802628972), 40 | floating_t(0.2262831802628972), 41 | floating_t(0.2078160475368885), 42 | floating_t(0.2078160475368885), 43 | floating_t(0.1781459807619457), 44 | floating_t(0.1781459807619457), 45 | floating_t(0.1388735102197872), 46 | floating_t(0.1388735102197872), 47 | floating_t(0.0921214998377285), 48 | floating_t(0.0921214998377285), 49 | floating_t(0.0404840047653159), 50 | floating_t(0.0404840047653159) 51 | }; 52 | 53 | floating_t halfDiff = (b - a) / 2; 54 | floating_t halfSum = (a + b) / 2; 55 | 56 | IntegrandType sum{}; 57 | for(size_t i = 0; i < NUM_POINTS; i++) 58 | { 59 | sum += quadratureWeights[i] * f(halfDiff * quadraturePoints[i] + halfSum); 60 | } 61 | return halfDiff * sum; 62 | } 63 | }; 64 | -------------------------------------------------------------------------------- /tests/demo/spline_node.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2019 Breda University of Applied Sciences and Team Wisp (Viktor Zoutman, Emilio Laiso, Jens Hagen, Meine Zeinstra, Tahar Meijs, Koen Buitenhuis, Niels Brunekreef, Darius Bouma, Florian Schut) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include 19 | #include "spline_library/splines/natural_spline.h" 20 | #include "spline_library/vector.h" 21 | #include 22 | 23 | class SplineNode : public wr::Node 24 | { 25 | struct ControlPoint 26 | { 27 | DirectX::XMVECTOR m_position; 28 | DirectX::XMVECTOR m_rotation; 29 | }; 30 | 31 | public: 32 | explicit SplineNode(std::string name, bool looping = false); 33 | ~SplineNode(); 34 | 35 | void UpdateSplineNode(float delta, std::shared_ptr node); 36 | 37 | private: 38 | void UpdateNaturalSpline(); 39 | 40 | static std::optional LoadDialog(); 41 | static std::optional SaveDialog(); 42 | void SaveSplineToFile(std::string const & path); 43 | void LoadSplineFromFile(std::string const & path); 44 | 45 | bool m_animate; 46 | 47 | void* m_spline; 48 | void* m_quat_spline; 49 | 50 | std::vector m_control_points; 51 | float m_speed; 52 | float m_time; 53 | 54 | bool m_looping; 55 | 56 | std::string m_name; 57 | }; -------------------------------------------------------------------------------- /tests/graphics_benchmark/frame_graphs.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeamWisp/WispRenderer/1f1493f9c9038dcd226c44fe154078a00168c3d9/tests/graphics_benchmark/frame_graphs.cpp -------------------------------------------------------------------------------- /tests/graphics_benchmark/spheres_scene.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "spheres_scene.hpp" 4 | 5 | SpheresScene::SpheresScene() : 6 | Scene(256, 2_mb, 2_mb), 7 | m_sphere_model(nullptr), 8 | m_skybox({}) 9 | { 10 | 11 | } 12 | 13 | void SpheresScene::LoadResources() 14 | { 15 | // Models 16 | m_sphere_model = m_model_pool->Load(m_material_pool.get(), m_texture_pool.get(), "resources/models/sphere.fbx"); 17 | 18 | // Textures 19 | m_skybox = m_texture_pool->LoadFromFile("resources/materials/Circus_Backstage_3k.hdr", false, false); 20 | m_flat_normal = m_texture_pool->LoadFromFile("resources/materials/flat_normal.png", false, false); 21 | } 22 | 23 | void SpheresScene::BuildScene(unsigned int width, unsigned int height) 24 | { 25 | auto camera = m_scene_graph->CreateChild(nullptr, (float)width / height); 26 | camera->SetFov(45.f); 27 | camera->SetPosition({ 0.0f, 0.0f, 30.f }); 28 | 29 | m_scene_graph->CreateChild(nullptr, m_skybox); 30 | 31 | std::shared_ptr spheres[49]; 32 | for (uint32_t i = 0; i <= 6; ++i) 33 | { 34 | for (uint32_t j = 0; j <= 6; ++j) 35 | { 36 | spheres[i * 7 + j] = m_scene_graph->CreateChild(nullptr, m_sphere_model); 37 | 38 | float x_pos = Lerp(10.0f, -10.0f, (float)i / 6.f); 39 | float y_pos = Lerp(10.0f, -10.0f, (float)j / 6.f); 40 | 41 | spheres[i * 7 + j]->SetPosition({ x_pos, y_pos, 0.0f, 0.0f }); 42 | spheres[i * 7 + j]->SetRotation({ 90.0_deg, 0.0_deg, 0.0_deg }); 43 | 44 | float roughness = Lerp(1.0f, 0.0f, (float)i / 6); 45 | float metallic = Lerp(1.0f, 0.0f, (float)j / 6); 46 | 47 | //Create new material 48 | wr::MaterialHandle mat = m_material_pool->Create(m_texture_pool.get()); 49 | auto mat_internal = mat.m_pool->GetMaterial(mat); 50 | 51 | mat_internal->SetConstant({ 1, 0, 0 }); 52 | mat_internal->SetTexture(wr::TextureType::NORMAL, m_flat_normal); 53 | mat_internal->SetConstant(roughness); 54 | mat_internal->SetConstant(metallic); 55 | 56 | spheres[i * 7 + j]->SetMaterials({ mat }); 57 | } 58 | } 59 | 60 | auto dir_light = m_scene_graph->CreateChild(nullptr, wr::LightType::DIRECTIONAL, DirectX::XMVECTOR{ 0, 1, 0 }); 61 | dir_light->SetDirectional({ 136._deg, 0, 0 }, { 4, 4, 4 }); 62 | } 63 | 64 | void SpheresScene::Update() 65 | { 66 | 67 | } 68 | 69 | float SpheresScene::Lerp(float v0, float v1, float t) 70 | { 71 | return (1.0f - t) * v0 + t * v1; 72 | } -------------------------------------------------------------------------------- /tests/graphics_benchmark/spheres_scene.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "scene.hpp" 4 | 5 | class SpheresScene : public Scene 6 | { 7 | public: 8 | SpheresScene(); 9 | 10 | void Update() final; 11 | 12 | protected: 13 | void LoadResources() final; 14 | void BuildScene(unsigned int width, unsigned int height) final; 15 | 16 | private: 17 | float Lerp(float v0, float v1, float t); 18 | 19 | // Models 20 | wr::Model* m_sphere_model; 21 | 22 | // Textures 23 | wr::TextureHandle m_skybox; 24 | wr::TextureHandle m_flat_normal; 25 | }; -------------------------------------------------------------------------------- /wisp.version: -------------------------------------------------------------------------------- 1 | "1.3.1" 2 | --------------------------------------------------------------------------------