├── .clang-format ├── .editorconfig ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── assets ├── images │ └── skybox │ │ ├── back.jpg │ │ ├── bottom.jpg │ │ ├── front.jpg │ │ ├── left.jpg │ │ ├── right.jpg │ │ └── top.jpg ├── models │ ├── DamagedHelmet.glb │ └── sponza │ │ ├── 10381718147657362067.jpg │ │ ├── 10388182081421875623.jpg │ │ ├── 11474523244911310074.jpg │ │ ├── 11490520546946913238.jpg │ │ ├── 11872827283454512094.jpg │ │ ├── 11968150294050148237.jpg │ │ ├── 1219024358953944284.jpg │ │ ├── 12501374198249454378.jpg │ │ ├── 13196865903111448057.jpg │ │ ├── 13824894030729245199.jpg │ │ ├── 13982482287905699490.jpg │ │ ├── 14118779221266351425.jpg │ │ ├── 14170708867020035030.jpg │ │ ├── 14267839433702832875.jpg │ │ ├── 14650633544276105767.jpg │ │ ├── 15295713303328085182.jpg │ │ ├── 15722799267630235092.jpg │ │ ├── 16275776544635328252.png │ │ ├── 16299174074766089871.jpg │ │ ├── 16885566240357350108.jpg │ │ ├── 17556969131407844942.jpg │ │ ├── 17876391417123941155.jpg │ │ ├── 2051777328469649772.jpg │ │ ├── 2185409758123873465.jpg │ │ ├── 2299742237651021498.jpg │ │ ├── 2374361008830720677.jpg │ │ ├── 2411100444841994089.jpg │ │ ├── 2775690330959970771.jpg │ │ ├── 2969916736137545357.jpg │ │ ├── 332936164838540657.jpg │ │ ├── 3371964815757888145.jpg │ │ ├── 3455394979645218238.jpg │ │ ├── 3628158980083700836.jpg │ │ ├── 3827035219084910048.jpg │ │ ├── 4477655471536070370.jpg │ │ ├── 4601176305987539675.jpg │ │ ├── 466164707995436622.jpg │ │ ├── 4675343432951571524.jpg │ │ ├── 4871783166746854860.jpg │ │ ├── 4910669866631290573.jpg │ │ ├── 4975155472559461469.jpg │ │ ├── 5061699253647017043.png │ │ ├── 5792855332885324923.jpg │ │ ├── 5823059166183034438.jpg │ │ ├── 6047387724914829168.jpg │ │ ├── 6151467286084645207.jpg │ │ ├── 6593109234861095314.jpg │ │ ├── 6667038893015345571.jpg │ │ ├── 6772804448157695701.jpg │ │ ├── 7056944414013900257.jpg │ │ ├── 715093869573992647.jpg │ │ ├── 7268504077753552595.jpg │ │ ├── 7441062115984513793.jpg │ │ ├── 755318871556304029.jpg │ │ ├── 759203620573749278.jpg │ │ ├── 7645212358685992005.jpg │ │ ├── 7815564343179553343.jpg │ │ ├── 8006627369776289000.png │ │ ├── 8051790464816141987.jpg │ │ ├── 8114461559286000061.jpg │ │ ├── 8481240838833932244.jpg │ │ ├── 8503262930880235456.jpg │ │ ├── 8747919177698443163.jpg │ │ ├── 8750083169368950601.jpg │ │ ├── 8773302468495022225.jpg │ │ ├── 8783994986360286082.jpg │ │ ├── 9288698199695299068.jpg │ │ ├── 9916269861720640319.jpg │ │ ├── Sponza.bin │ │ ├── Sponza.gltf │ │ └── white.png └── shaders │ ├── color_space.hlsli │ ├── composition_shader.hlsl │ ├── globals.hlsli │ ├── grid_shader.hlsl │ ├── pbr_shader.hlsl │ ├── shader_interop.h │ └── skybox_shader.hlsl ├── cmake ├── CompilerWarnings.cmake ├── Doxygen.cmake ├── PreventInSourceBuilds.cmake ├── StandardProjectSettings.cmake └── Utils.cmake ├── hyper_engine ├── CMakeLists.txt ├── include │ ├── core │ │ ├── assertion.hpp │ │ ├── bit_flags.hpp │ │ ├── filesystem.hpp │ │ ├── logger.hpp │ │ ├── prerequisites.hpp │ │ ├── resource_id.hpp │ │ ├── resource_owner.hpp │ │ └── string_utils.hpp │ ├── drivers │ │ └── vulkan │ │ │ ├── vulkan_render_conversion.hpp │ │ │ └── vulkan_render_driver.hpp │ ├── engine.hpp │ ├── scene │ │ └── resources │ │ │ └── asset.hpp │ └── systems │ │ ├── input_system.hpp │ │ ├── render │ │ ├── camera.hpp │ │ ├── render_driver.hpp │ │ ├── render_types.hpp │ │ ├── resource_handle.hpp │ │ └── shader_compiler.hpp │ │ ├── render_system.hpp │ │ ├── window │ │ ├── event_bus.hpp │ │ ├── event_handler.hpp │ │ ├── key_codes.hpp │ │ ├── key_events.hpp │ │ ├── mouse_codes.hpp │ │ ├── mouse_events.hpp │ │ └── window_events.hpp │ │ └── window_system.hpp └── src │ ├── core │ ├── filesystem.cpp │ ├── logger.cpp │ └── string_utils.cpp │ ├── drivers │ └── vulkan │ │ ├── vulkan_render_conversion.cpp │ │ └── vulkan_render_driver.cpp │ ├── engine.cpp │ ├── main.cpp │ ├── scene │ └── resources │ │ └── asset.cpp │ └── systems │ ├── input_system.cpp │ ├── render │ ├── camera.cpp │ └── shader_compiler.cpp │ ├── render_system.cpp │ └── window_system.cpp └── third_party ├── CMakeLists.txt └── stb ├── CMakeLists.txt └── src └── stb_image.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | AccessModifierOffset: -4 2 | AlignAfterOpenBracket: AlwaysBreak 3 | AlignArrayOfStructures: Left 4 | AlignConsecutiveAssignments: None 5 | AlignConsecutiveBitFields: None 6 | AlignConsecutiveDeclarations: None 7 | AlignConsecutiveMacros: None 8 | AlignConsecutiveShortCaseStatements: 9 | Enabled: false 10 | AlignEscapedNewlines: Left 11 | AlignOperands: true 12 | AlignTrailingComments: false 13 | AllowAllArgumentsOnNextLine: true 14 | AllowAllParametersOfDeclarationOnNextLine: true 15 | AllowBreakBeforeNoexceptSpecifier: Never 16 | AllowShortBlocksOnASingleLine: Empty 17 | AllowShortCaseLabelsOnASingleLine: true 18 | AllowShortCompoundRequirementOnASingleLine: true 19 | AllowShortEnumsOnASingleLine: false 20 | AllowShortFunctionsOnASingleLine: All 21 | AllowShortIfStatementsOnASingleLine: Never 22 | AllowShortLambdasOnASingleLine: Empty 23 | AllowShortLoopsOnASingleLine: true 24 | AlwaysBreakBeforeMultilineStrings: false 25 | BinPackArguments: true 26 | BinPackParameters: false 27 | BitFieldColonSpacing: Both 28 | BracedInitializerIndentWidth: 4 29 | BreakAdjacentStringLiterals: false 30 | BreakBeforeBinaryOperators: All 31 | BreakBeforeBraces: Allman 32 | BreakBeforeConceptDeclarations: Always 33 | BreakBeforeTernaryOperators: true 34 | BreakConstructorInitializers: BeforeComma 35 | BreakFunctionDefinitionParameters: false 36 | BreakInheritanceList: BeforeComma 37 | BreakStringLiterals: true 38 | BreakTemplateDeclarations: Yes 39 | ColumnLimit: 125 40 | CompactNamespaces: false 41 | ConstructorInitializerIndentWidth: 4 42 | ContinuationIndentWidth: 4 43 | Cpp11BracedListStyle: false 44 | DerivePointerAlignment: false 45 | DisableFormat: false 46 | EmptyLineAfterAccessModifier: Never 47 | EmptyLineBeforeAccessModifier: Always 48 | FixNamespaceComments: true 49 | IncludeBlocks: Regroup 50 | IncludeCategories: 51 | - Regex: '<([A-Za-z0-9\Q/-_\E])+>' 52 | Priority: 1 53 | - Regex: '<([A-Za-z0-9.\Q/-_\E])+>' 54 | Priority: 2 55 | - Regex: '"([A-Za-z0-9.\Q/-_\E])+"' 56 | Priority: 3 57 | IndentAccessModifiers: false 58 | IndentCaseBlocks: true 59 | IndentCaseLabels: false 60 | IndentPPDirectives: AfterHash 61 | IndentRequiresClause: true 62 | IndentWidth: 4 63 | IndentWrappedFunctionNames: true 64 | InsertBraces: true 65 | InsertNewlineAtEOF: true 66 | KeepEmptyLines: 67 | AtEndOfFile: false 68 | AtStartOfBlock: false 69 | AtStartOfFile: false 70 | LambdaBodyIndentation: Signature 71 | Language: Cpp 72 | MaxEmptyLinesToKeep: 1 73 | NamespaceIndentation: All 74 | PPIndentWidth: 4 75 | PackConstructorInitializers: Never 76 | PenaltyBreakAssignment: 2 77 | PenaltyBreakBeforeFirstCallParameter: 19 78 | PenaltyBreakComment: 300 79 | PenaltyBreakFirstLessLess: 120 80 | PenaltyBreakString: 1000 81 | PenaltyExcessCharacter: 1000000 82 | PenaltyReturnTypeOnItsOwnLine: 60 83 | PointerAlignment: Right 84 | QualifierAlignment: Left 85 | ReferenceAlignment: Right 86 | ReflowComments: true 87 | RemoveParentheses: Leave 88 | RemoveSemicolon: false 89 | RequiresClausePosition: OwnLine 90 | RequiresExpressionIndentation: OuterScope 91 | SeparateDefinitionBlocks: Leave 92 | ShortNamespaceLines: 0 93 | SortIncludes: CaseInsensitive 94 | SortUsingDeclarations: Lexicographic 95 | SpaceAfterCStyleCast: true 96 | SpaceAfterLogicalNot: false 97 | SpaceAfterTemplateKeyword: true 98 | SpaceAroundPointerQualifiers: Default 99 | SpaceBeforeAssignmentOperators: true 100 | SpaceBeforeCaseColon: false 101 | SpaceBeforeCpp11BracedList: true 102 | SpaceBeforeCtorInitializerColon: true 103 | SpaceBeforeInheritanceColon: true 104 | SpaceBeforeParens: ControlStatements 105 | SpaceBeforeRangeBasedForLoopColon: true 106 | SpaceBeforeSquareBrackets: false 107 | SpaceInEmptyBlock: false 108 | SpacesBeforeTrailingComments: 1 109 | SpacesInAngles: false 110 | SpacesInParens: Never 111 | SpacesInSquareBrackets: false 112 | Standard: Auto 113 | TabWidth: 4 114 | UseTab: Never 115 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------------------- 2 | # Copyright (c) 2024-present, SkillerRaptor 3 | # 4 | # SPDX-License-Identifier: MIT 5 | #------------------------------------------------------------------------------------------- 6 | 7 | #------------------------------------------------------------------------------------------- 8 | # Editor Config 9 | #------------------------------------------------------------------------------------------- 10 | root = true 11 | 12 | # All files 13 | [*] 14 | end_of_line = lf 15 | charset = utf-8 16 | insert_final_newline = true 17 | trim_trailing_whitespace = true 18 | 19 | # C++ files 20 | [*.{c++,cc,cpp,cxx,h,h++,hh,hpp,hxx,inl,ipp,tlh,tli}] 21 | indent_style = space 22 | indent_size = 4 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------------------- 2 | # Copyright (c) 2024-present, SkillerRaptor 3 | # 4 | # SPDX-License-Identifier: MIT 5 | #------------------------------------------------------------------------------------------- 6 | 7 | #------------------------------------------------------------------------------------------- 8 | # Editor files 9 | #------------------------------------------------------------------------------------------- 10 | .cache/ 11 | .vs/ 12 | .idea/ 13 | .vscode/ 14 | !.vscode/settings.json 15 | !.vscode/tasks.json 16 | !.vscode/launch.json 17 | !.vscode/extensions.json 18 | *.bak 19 | *.swp 20 | *~ 21 | _ReSharper* 22 | *.log 23 | 24 | #------------------------------------------------------------------------------------------- 25 | # Build directories and binary files 26 | #------------------------------------------------------------------------------------------- 27 | build/ 28 | out/ 29 | out/coverage/* 30 | cmake-build-*/ 31 | 32 | #------------------------------------------------------------------------------------------- 33 | # OS Generated Files 34 | #------------------------------------------------------------------------------------------- 35 | .DS_Store 36 | .AppleDouble 37 | .LSOverride 38 | ._* 39 | .Spotlight-V100 40 | .Trashes 41 | .Trash-* 42 | $RECYCLE.BIN/ 43 | .TemporaryItems 44 | ehthumbs.db 45 | Thumbs.db 46 | 47 | #------------------------------------------------------------------------------------------- 48 | # User spesific settings 49 | #------------------------------------------------------------------------------------------- 50 | CMakeUserPresets.json 51 | 52 | #------------------------------------------------------------------------------------------- 53 | # Third party files 54 | #------------------------------------------------------------------------------------------- 55 | third_party/DirectXShaderCompiler/ 56 | 57 | #------------------------------------------------------------------------------------------- 58 | # ImGui 59 | #------------------------------------------------------------------------------------------- 60 | imgui.ini -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------------------- 2 | # Copyright (c) 2024-present, SkillerRaptor 3 | # 4 | # SPDX-License-Identifier: MIT 5 | #------------------------------------------------------------------------------------------- 6 | 7 | #------------------------------------------------------------------------------------------- 8 | # CMake Info 9 | #------------------------------------------------------------------------------------------- 10 | cmake_minimum_required(VERSION 3.25) 11 | project(HyperEngine LANGUAGES C CXX) 12 | 13 | #------------------------------------------------------------------------------------------- 14 | # Standard Settings 15 | #------------------------------------------------------------------------------------------- 16 | include(cmake/StandardProjectSettings.cmake) 17 | include(cmake/PreventInSourceBuilds.cmake) 18 | include(cmake/Doxygen.cmake) 19 | 20 | option(HE_ENABLE_DOXYGEN "Enabling doxygen generation" OFF) 21 | if (HE_ENABLE_DOXYGEN) 22 | enable_doxygen() 23 | endif () 24 | 25 | #------------------------------------------------------------------------------------------- 26 | # Project Libraries 27 | #------------------------------------------------------------------------------------------- 28 | add_library(ProjectOptions INTERFACE) 29 | target_compile_features(ProjectOptions INTERFACE cxx_std_20) 30 | 31 | add_library(ProjectWarnings INTERFACE) 32 | 33 | #------------------------------------------------------------------------------------------- 34 | # Warnings 35 | #------------------------------------------------------------------------------------------- 36 | set(CMAKE_CXX_STANDARD 20) 37 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 38 | set(CMAKE_CXX_EXTENSIONS OFF) 39 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 40 | 41 | include(cmake/CompilerWarnings.cmake) 42 | enable_warnings(ProjectWarnings) 43 | 44 | include(cmake/Utils.cmake) 45 | 46 | #------------------------------------------------------------------------------------------- 47 | # Source 48 | #------------------------------------------------------------------------------------------- 49 | add_subdirectory(third_party) 50 | 51 | add_subdirectory(hyper_engine) 52 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024-present SkillerRaptor 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /assets/images/skybox/back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/images/skybox/back.jpg -------------------------------------------------------------------------------- /assets/images/skybox/bottom.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/images/skybox/bottom.jpg -------------------------------------------------------------------------------- /assets/images/skybox/front.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/images/skybox/front.jpg -------------------------------------------------------------------------------- /assets/images/skybox/left.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/images/skybox/left.jpg -------------------------------------------------------------------------------- /assets/images/skybox/right.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/images/skybox/right.jpg -------------------------------------------------------------------------------- /assets/images/skybox/top.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/images/skybox/top.jpg -------------------------------------------------------------------------------- /assets/models/DamagedHelmet.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/DamagedHelmet.glb -------------------------------------------------------------------------------- /assets/models/sponza/10381718147657362067.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/10381718147657362067.jpg -------------------------------------------------------------------------------- /assets/models/sponza/10388182081421875623.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/10388182081421875623.jpg -------------------------------------------------------------------------------- /assets/models/sponza/11474523244911310074.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/11474523244911310074.jpg -------------------------------------------------------------------------------- /assets/models/sponza/11490520546946913238.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/11490520546946913238.jpg -------------------------------------------------------------------------------- /assets/models/sponza/11872827283454512094.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/11872827283454512094.jpg -------------------------------------------------------------------------------- /assets/models/sponza/11968150294050148237.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/11968150294050148237.jpg -------------------------------------------------------------------------------- /assets/models/sponza/1219024358953944284.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/1219024358953944284.jpg -------------------------------------------------------------------------------- /assets/models/sponza/12501374198249454378.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/12501374198249454378.jpg -------------------------------------------------------------------------------- /assets/models/sponza/13196865903111448057.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/13196865903111448057.jpg -------------------------------------------------------------------------------- /assets/models/sponza/13824894030729245199.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/13824894030729245199.jpg -------------------------------------------------------------------------------- /assets/models/sponza/13982482287905699490.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/13982482287905699490.jpg -------------------------------------------------------------------------------- /assets/models/sponza/14118779221266351425.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/14118779221266351425.jpg -------------------------------------------------------------------------------- /assets/models/sponza/14170708867020035030.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/14170708867020035030.jpg -------------------------------------------------------------------------------- /assets/models/sponza/14267839433702832875.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/14267839433702832875.jpg -------------------------------------------------------------------------------- /assets/models/sponza/14650633544276105767.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/14650633544276105767.jpg -------------------------------------------------------------------------------- /assets/models/sponza/15295713303328085182.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/15295713303328085182.jpg -------------------------------------------------------------------------------- /assets/models/sponza/15722799267630235092.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/15722799267630235092.jpg -------------------------------------------------------------------------------- /assets/models/sponza/16275776544635328252.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/16275776544635328252.png -------------------------------------------------------------------------------- /assets/models/sponza/16299174074766089871.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/16299174074766089871.jpg -------------------------------------------------------------------------------- /assets/models/sponza/16885566240357350108.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/16885566240357350108.jpg -------------------------------------------------------------------------------- /assets/models/sponza/17556969131407844942.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/17556969131407844942.jpg -------------------------------------------------------------------------------- /assets/models/sponza/17876391417123941155.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/17876391417123941155.jpg -------------------------------------------------------------------------------- /assets/models/sponza/2051777328469649772.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/2051777328469649772.jpg -------------------------------------------------------------------------------- /assets/models/sponza/2185409758123873465.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/2185409758123873465.jpg -------------------------------------------------------------------------------- /assets/models/sponza/2299742237651021498.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/2299742237651021498.jpg -------------------------------------------------------------------------------- /assets/models/sponza/2374361008830720677.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/2374361008830720677.jpg -------------------------------------------------------------------------------- /assets/models/sponza/2411100444841994089.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/2411100444841994089.jpg -------------------------------------------------------------------------------- /assets/models/sponza/2775690330959970771.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/2775690330959970771.jpg -------------------------------------------------------------------------------- /assets/models/sponza/2969916736137545357.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/2969916736137545357.jpg -------------------------------------------------------------------------------- /assets/models/sponza/332936164838540657.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/332936164838540657.jpg -------------------------------------------------------------------------------- /assets/models/sponza/3371964815757888145.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/3371964815757888145.jpg -------------------------------------------------------------------------------- /assets/models/sponza/3455394979645218238.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/3455394979645218238.jpg -------------------------------------------------------------------------------- /assets/models/sponza/3628158980083700836.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/3628158980083700836.jpg -------------------------------------------------------------------------------- /assets/models/sponza/3827035219084910048.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/3827035219084910048.jpg -------------------------------------------------------------------------------- /assets/models/sponza/4477655471536070370.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/4477655471536070370.jpg -------------------------------------------------------------------------------- /assets/models/sponza/4601176305987539675.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/4601176305987539675.jpg -------------------------------------------------------------------------------- /assets/models/sponza/466164707995436622.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/466164707995436622.jpg -------------------------------------------------------------------------------- /assets/models/sponza/4675343432951571524.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/4675343432951571524.jpg -------------------------------------------------------------------------------- /assets/models/sponza/4871783166746854860.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/4871783166746854860.jpg -------------------------------------------------------------------------------- /assets/models/sponza/4910669866631290573.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/4910669866631290573.jpg -------------------------------------------------------------------------------- /assets/models/sponza/4975155472559461469.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/4975155472559461469.jpg -------------------------------------------------------------------------------- /assets/models/sponza/5061699253647017043.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/5061699253647017043.png -------------------------------------------------------------------------------- /assets/models/sponza/5792855332885324923.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/5792855332885324923.jpg -------------------------------------------------------------------------------- /assets/models/sponza/5823059166183034438.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/5823059166183034438.jpg -------------------------------------------------------------------------------- /assets/models/sponza/6047387724914829168.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/6047387724914829168.jpg -------------------------------------------------------------------------------- /assets/models/sponza/6151467286084645207.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/6151467286084645207.jpg -------------------------------------------------------------------------------- /assets/models/sponza/6593109234861095314.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/6593109234861095314.jpg -------------------------------------------------------------------------------- /assets/models/sponza/6667038893015345571.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/6667038893015345571.jpg -------------------------------------------------------------------------------- /assets/models/sponza/6772804448157695701.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/6772804448157695701.jpg -------------------------------------------------------------------------------- /assets/models/sponza/7056944414013900257.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/7056944414013900257.jpg -------------------------------------------------------------------------------- /assets/models/sponza/715093869573992647.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/715093869573992647.jpg -------------------------------------------------------------------------------- /assets/models/sponza/7268504077753552595.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/7268504077753552595.jpg -------------------------------------------------------------------------------- /assets/models/sponza/7441062115984513793.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/7441062115984513793.jpg -------------------------------------------------------------------------------- /assets/models/sponza/755318871556304029.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/755318871556304029.jpg -------------------------------------------------------------------------------- /assets/models/sponza/759203620573749278.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/759203620573749278.jpg -------------------------------------------------------------------------------- /assets/models/sponza/7645212358685992005.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/7645212358685992005.jpg -------------------------------------------------------------------------------- /assets/models/sponza/7815564343179553343.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/7815564343179553343.jpg -------------------------------------------------------------------------------- /assets/models/sponza/8006627369776289000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/8006627369776289000.png -------------------------------------------------------------------------------- /assets/models/sponza/8051790464816141987.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/8051790464816141987.jpg -------------------------------------------------------------------------------- /assets/models/sponza/8114461559286000061.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/8114461559286000061.jpg -------------------------------------------------------------------------------- /assets/models/sponza/8481240838833932244.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/8481240838833932244.jpg -------------------------------------------------------------------------------- /assets/models/sponza/8503262930880235456.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/8503262930880235456.jpg -------------------------------------------------------------------------------- /assets/models/sponza/8747919177698443163.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/8747919177698443163.jpg -------------------------------------------------------------------------------- /assets/models/sponza/8750083169368950601.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/8750083169368950601.jpg -------------------------------------------------------------------------------- /assets/models/sponza/8773302468495022225.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/8773302468495022225.jpg -------------------------------------------------------------------------------- /assets/models/sponza/8783994986360286082.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/8783994986360286082.jpg -------------------------------------------------------------------------------- /assets/models/sponza/9288698199695299068.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/9288698199695299068.jpg -------------------------------------------------------------------------------- /assets/models/sponza/9916269861720640319.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/9916269861720640319.jpg -------------------------------------------------------------------------------- /assets/models/sponza/Sponza.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/Sponza.bin -------------------------------------------------------------------------------- /assets/models/sponza/white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SkillerRaptor/hyper_engine/acab2e6a0b0bc09fdc312de4d9dc9b9e5f2a0377/assets/models/sponza/white.png -------------------------------------------------------------------------------- /assets/shaders/color_space.hlsli: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | float3 apply_srgb(float3 x) { 8 | return pow(x, 1.0 / 2.2); 9 | } 10 | 11 | float3 remove_srgb(float3 x) { 12 | return pow(x, 2.2); 13 | } 14 | 15 | float3 apply_reinhard_tone_mapping(float3 x) { 16 | return x / (x + float3(1.0, 1.0, 1.0)); 17 | } 18 | -------------------------------------------------------------------------------- /assets/shaders/composition_shader.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #include "color_space.hlsli" 8 | #include "globals.hlsli" 9 | #include "shader_interop.h" 10 | 11 | HE_PUSH_CONSTANT(CompositionPushConstants, g_push); 12 | 13 | struct VertexOutput { 14 | float4 position : SV_POSITION; 15 | float2 uv : TEXCOORD; 16 | }; 17 | 18 | VertexOutput vs_main( 19 | uint vertex_id : SV_VertexID 20 | ) { 21 | float2 uv = float2((vertex_id << 1) & 2, vertex_id & 2); 22 | const float4 position = float4(uv * 2.0 - 1.0, 0.0, 1.0); 23 | 24 | #if HE_VULKAN 25 | uv.y = 1.0 - uv.y; 26 | #endif 27 | 28 | VertexOutput output = (VertexOutput) 0; 29 | output.position = position; 30 | output.uv = uv; 31 | return output; 32 | } 33 | 34 | float4 fs_main(VertexOutput input) : SV_TARGET { 35 | const SamplerState composition_sampler = g_push.composition_sampler.load(); 36 | const float4 color = g_push.composition_texture.sample_2d(composition_sampler, input.uv); 37 | return color; 38 | } 39 | -------------------------------------------------------------------------------- /assets/shaders/globals.hlsli: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #ifndef HE_GLOBALS_HLSLI 8 | #define HE_GLOBALS_HLSLI 9 | 10 | //////////////////////////////////////////////////////////////////////////////// 11 | // Constants 12 | //////////////////////////////////////////////////////////////////////////////// 13 | static const float PI = 3.14159265359; 14 | 15 | //////////////////////////////////////////////////////////////////////////////// 16 | // Bindless 17 | //////////////////////////////////////////////////////////////////////////////// 18 | 19 | struct ResourceHandle { 20 | uint index; 21 | 22 | bool is_valid() { 23 | return index != 0xffffffff; 24 | } 25 | 26 | uint read_index() { 27 | return index; 28 | } 29 | 30 | #ifdef HE_VULKAN 31 | uint write_index() { 32 | return read_index(); 33 | } 34 | #else 35 | uint write_index() { 36 | return read_index() + 1; 37 | } 38 | #endif 39 | }; 40 | 41 | #ifdef HE_VULKAN 42 | static const uint DESCRIPTOR_SET_BINDLESS_STORAGE_BUFFER = 0; 43 | static const uint DESCRIPTOR_SET_BINDLESS_SAMPLED_IMAGE = 1; 44 | static const uint DESCRIPTOR_SET_BINDLESS_STORAGE_IMAGE = 2; 45 | static const uint DESCRIPTOR_SET_BINDLESS_SAMPLER = 3; 46 | 47 | #define DEFINE_BUFFER_HEAP(type) \ 48 | struct type##Handle { \ 49 | uint internal_index; \ 50 | }; \ 51 | [[vk::binding(0, DESCRIPTOR_SET_BINDLESS_STORAGE_BUFFER)]] type g##_##type[] 52 | 53 | #define DEFINE_TEXTURE_HEAP(texture_type) \ 54 | template \ 55 | struct texture_type##Handle { \ 56 | uint internal_index; \ 57 | }; \ 58 | [[vk::binding(0, DESCRIPTOR_SET_BINDLESS_SAMPLED_IMAGE)]] texture_type g##_##texture_type##_##float[]; \ 59 | [[vk::binding(0, DESCRIPTOR_SET_BINDLESS_SAMPLED_IMAGE)]] texture_type g##_##texture_type##_##float2[]; \ 60 | [[vk::binding(0, DESCRIPTOR_SET_BINDLESS_SAMPLED_IMAGE)]] texture_type g##_##texture_type##_##float3[]; \ 61 | [[vk::binding(0, DESCRIPTOR_SET_BINDLESS_SAMPLED_IMAGE)]] texture_type g##_##texture_type##_##float4[] 62 | 63 | #define DEFINE_RW_TEXTURE_HEAP(texture_type) \ 64 | template \ 65 | struct texture_type##Handle { \ 66 | uint internal_index; \ 67 | }; \ 68 | [[vk::binding(0, DESCRIPTOR_SET_BINDLESS_STORAGE_IMAGE)]] texture_type g##_##texture_type##_##float[]; \ 69 | [[vk::binding(0, DESCRIPTOR_SET_BINDLESS_STORAGE_IMAGE)]] texture_type g##_##texture_type##_##float2[]; \ 70 | [[vk::binding(0, DESCRIPTOR_SET_BINDLESS_STORAGE_IMAGE)]] texture_type g##_##texture_type##_##float3[]; \ 71 | [[vk::binding(0, DESCRIPTOR_SET_BINDLESS_STORAGE_IMAGE)]] texture_type g##_##texture_type##_##float4[] 72 | 73 | #define DEFINE_SAMPLER_HEAP(type) \ 74 | struct type##Handle { \ 75 | uint internal_index; \ 76 | }; \ 77 | [[vk::binding(0, DESCRIPTOR_SET_BINDLESS_SAMPLER)]] type g##_##type[] 78 | 79 | #define DEFINE_BUFFER_HEAP_OPERATOR(type) \ 80 | type operator[](type##Handle identifier) { \ 81 | return g_##type[NonUniformResourceIndex(identifier.internal_index)]; \ 82 | } 83 | 84 | #define DEFINE_TEXTURE_HEAP_OPERATOR_VALUE(resource_type, register_name, value_type, handle_name) \ 85 | resource_type operator[](handle_name identifier) { \ 86 | return register_name##_##value_type[NonUniformResourceIndex(identifier.internal_index)]; \ 87 | } 88 | 89 | #define DEFINE_TEXTURE_HEAP_OPERATOR(texture_type) \ 90 | DEFINE_TEXTURE_HEAP_OPERATOR_VALUE(texture_type, g_##texture_type, float, texture_type##Handle) \ 91 | DEFINE_TEXTURE_HEAP_OPERATOR_VALUE(texture_type, g_##texture_type, float2, texture_type##Handle) \ 92 | DEFINE_TEXTURE_HEAP_OPERATOR_VALUE(texture_type, g_##texture_type, float3, texture_type##Handle) \ 93 | DEFINE_TEXTURE_HEAP_OPERATOR_VALUE(texture_type, g_##texture_type, float4, texture_type##Handle) 94 | 95 | #define DEFINE_SAMPLER_HEAP_OPERATOR(type) \ 96 | type operator[](type##Handle identifier) { \ 97 | return g_##type[NonUniformResourceIndex(identifier.internal_index)]; \ 98 | } 99 | 100 | DEFINE_BUFFER_HEAP(ByteAddressBuffer); 101 | DEFINE_BUFFER_HEAP(RWByteAddressBuffer); 102 | 103 | DEFINE_TEXTURE_HEAP(Texture1D); 104 | DEFINE_TEXTURE_HEAP(Texture2D); 105 | DEFINE_TEXTURE_HEAP(Texture3D); 106 | DEFINE_TEXTURE_HEAP(TextureCube); 107 | 108 | DEFINE_RW_TEXTURE_HEAP(RWTexture1D); 109 | DEFINE_RW_TEXTURE_HEAP(RWTexture2D); 110 | DEFINE_RW_TEXTURE_HEAP(RWTexture3D); 111 | 112 | DEFINE_SAMPLER_HEAP(SamplerState); 113 | 114 | struct VulkanResourceDescriptorHeapInternal { 115 | DEFINE_BUFFER_HEAP_OPERATOR(ByteAddressBuffer) 116 | DEFINE_BUFFER_HEAP_OPERATOR(RWByteAddressBuffer) 117 | 118 | DEFINE_TEXTURE_HEAP_OPERATOR(Texture1D) 119 | DEFINE_TEXTURE_HEAP_OPERATOR(RWTexture1D) 120 | DEFINE_TEXTURE_HEAP_OPERATOR(Texture2D) 121 | DEFINE_TEXTURE_HEAP_OPERATOR(RWTexture2D) 122 | DEFINE_TEXTURE_HEAP_OPERATOR(Texture3D) 123 | DEFINE_TEXTURE_HEAP_OPERATOR(RWTexture3D) 124 | DEFINE_TEXTURE_HEAP_OPERATOR(TextureCube) 125 | 126 | DEFINE_SAMPLER_HEAP_OPERATOR(SamplerState) 127 | }; 128 | 129 | #undef DEFINE_BUFFER_HEAP 130 | #undef DEFINE_TEXTURE_HEAP 131 | #undef DEFINE_RW_TEXTURE_HEAP 132 | #undef DEFINE_SAMPPLER_HEAP 133 | #undef DEFINE_BUFFER_HEAP_OPERATOR 134 | #undef DEFINE_TEXTURE_HEAP_OPERATOR_VALUE 135 | #undef DEFINE_TEXTURE_HEAP_OPERATOR 136 | #undef DEFINE_SAMPLER_HEAP_OPERATOR 137 | 138 | static VulkanResourceDescriptorHeapInternal VkResourceDescriptorHeap; 139 | 140 | #define DESCRIPTOR_HEAP(handle_type, handle) VkResourceDescriptorHeap[(handle_type) handle] 141 | #define SAMPLER_HEAP(handle_type, handle) VkResourceDescriptorHeap[(handle_type) handle] 142 | #else 143 | #define DESCRIPTOR_HEAP(handle_type, handle) ResourceDescriptorHeap[NonUniformResourceIndex(handle)] 144 | #define SAMPLER_HEAP(handle_type, handle) SamplerDescriptorHeap[NonUniformResourceIndex(handle)] 145 | #endif 146 | 147 | struct SimpleBuffer { 148 | ResourceHandle handle; 149 | 150 | template 151 | T load() { 152 | ByteAddressBuffer buffer = DESCRIPTOR_HEAP(ByteAddressBufferHandle, this.handle.read_index()); 153 | T result = buffer.Load(0); 154 | return result; 155 | } 156 | }; 157 | 158 | struct RwSimpleBuffer { 159 | ResourceHandle handle; 160 | 161 | template 162 | T load() { 163 | RWByteAddressBuffer buffer = DESCRIPTOR_HEAP(RWByteAddressBufferHandle, this.handle.read_index()); 164 | T result = buffer.Load(0); 165 | return result; 166 | } 167 | 168 | template 169 | void store(T value) { 170 | RWByteAddressBuffer buffer = DESCRIPTOR_HEAP(RWByteAddressBufferHandle, this.handle.write_index()); 171 | buffer.Store(0, value); 172 | } 173 | }; 174 | 175 | struct ArrayBuffer { 176 | ResourceHandle handle; 177 | 178 | template 179 | T load(uint index) { 180 | ByteAddressBuffer buffer = DESCRIPTOR_HEAP(ByteAddressBufferHandle, this.handle.read_index()); 181 | T result = buffer.Load(sizeof(T) * index); 182 | return result; 183 | } 184 | }; 185 | 186 | struct RwArrayBuffer { 187 | ResourceHandle handle; 188 | 189 | template 190 | T load(uint index) { 191 | RWByteAddressBuffer buffer = DESCRIPTOR_HEAP(RWByteAddressBufferHandle, this.handle.read_index()); 192 | T result = buffer.Load(sizeof(T) * index); 193 | return result; 194 | } 195 | 196 | template 197 | void store(uint index, T value) { 198 | RWByteAddressBuffer buffer = DESCRIPTOR_HEAP(RWByteAddressBufferHandle, this.handle.write_index()); 199 | buffer.Store(sizeof(T) * index, value); 200 | } 201 | }; 202 | 203 | struct Texture { 204 | ResourceHandle handle; 205 | 206 | template 207 | T load_1d(uint pos) { 208 | Texture1D texture = DESCRIPTOR_HEAP(Texture1DHandle, this.handle.read_index()); 209 | return texture.Load(uint2(pos, 0)); 210 | } 211 | 212 | template 213 | T load_2d(uint2 pos) { 214 | Texture2D texture = DESCRIPTOR_HEAP(Texture2DHandle, this.handle.read_index()); 215 | return texture.Load(uint3(pos, 0)); 216 | } 217 | 218 | template 219 | T load_3d(uint3 pos) { 220 | Texture3D texture = DESCRIPTOR_HEAP(Texture3DHandle, this.handle.read_index()); 221 | return texture.Load(uint4(pos, 0)); 222 | } 223 | 224 | template 225 | T sample_1d(SamplerState s, float u) { 226 | Texture1D texture = DESCRIPTOR_HEAP(Texture1DHandle, this.handle.read_index()); 227 | return texture.Sample(s, u); 228 | } 229 | 230 | template 231 | T sample_2d(SamplerState s, float2 uv) { 232 | Texture2D texture = DESCRIPTOR_HEAP(Texture2DHandle, this.handle.read_index()); 233 | return texture.Sample(s, uv); 234 | } 235 | 236 | template 237 | T sample_3d(SamplerState s, float3 uvw) { 238 | Texture3D texture = DESCRIPTOR_HEAP(Texture3DHandle, this.handle.read_index()); 239 | return texture.Sample(s, uvw); 240 | } 241 | 242 | template 243 | T sample_cube(SamplerState s, float3 uvw) { 244 | TextureCube texture = DESCRIPTOR_HEAP(TextureCubeHandle, this.handle.read_index()); 245 | return texture.Sample(s, uvw); 246 | } 247 | 248 | template 249 | T sample_level_1d(SamplerState s, float u, float mip) { 250 | Texture1D texture = DESCRIPTOR_HEAP(Texture1DHandle, this.handle.read_index()); 251 | return texture.SampleLevel(s, u, mip); 252 | } 253 | 254 | template 255 | T sample_level_2d(SamplerState s, float2 uv, float mip) { 256 | Texture2D texture = DESCRIPTOR_HEAP(Texture2DHandle, this.handle.read_index()); 257 | return texture.SampleLevel(s, uv, mip); 258 | } 259 | 260 | template 261 | T sample_level_3d(SamplerState s, float3 uvw, float mip) { 262 | Texture3D texture = DESCRIPTOR_HEAP(Texture3DHandle, this.handle.read_index()); 263 | return texture.SampleLevel(s, uvw, mip); 264 | } 265 | 266 | template 267 | T sample_level_cube(SamplerState s, float3 uvw, float mip) { 268 | TextureCube texture = DESCRIPTOR_HEAP(TextureCubeHandle, this.handle.read_index()); 269 | return texture.SampleLevel(s, uvw, mip); 270 | } 271 | }; 272 | 273 | struct RwTexture { 274 | ResourceHandle handle; 275 | 276 | template 277 | T load_1d(uint pos) { 278 | Texture1D texture = DESCRIPTOR_HEAP(Texture1DHandle, this.handle.read_index()); 279 | return texture.Load(uint2(pos, 0)); 280 | } 281 | 282 | template 283 | T load_2d(uint2 pos) { 284 | Texture2D texture = DESCRIPTOR_HEAP(Texture2DHandle, this.handle.read_index()); 285 | return texture.Load(uint3(pos, 0)); 286 | } 287 | 288 | template 289 | T load_3d(uint3 pos) { 290 | Texture3D texture = DESCRIPTOR_HEAP(Texture3DHandle, this.handle.read_index()); 291 | return texture.Load(uint4(pos, 0)); 292 | } 293 | 294 | template 295 | void store_1d(uint pos, T value) { 296 | RWTexture1D texture = DESCRIPTOR_HEAP(RWTexture1DHandle, this.handle.write_index()); 297 | texture[pos] = value; 298 | } 299 | 300 | template 301 | void store_2d(uint2 pos, T value) { 302 | RWTexture2D texture = DESCRIPTOR_HEAP(RWTexture2DHandle, this.handle.write_index()); 303 | texture[pos] = value; 304 | } 305 | 306 | template 307 | void store_3d(uint3 pos, T value) { 308 | RWTexture3D texture = DESCRIPTOR_HEAP(RWTexture3DHandle, this.handle.write_index()); 309 | texture[pos] = value; 310 | } 311 | 312 | template 313 | T sample_1d(SamplerState sampler, float u) { 314 | Texture1D texture = DESCRIPTOR_HEAP(Texture1DHandle, this.handle.read_index()); 315 | return texture.Sample(sampler, u); 316 | } 317 | 318 | template 319 | T sample_2d(SamplerState sampler, float2 uv) { 320 | Texture2D texture = DESCRIPTOR_HEAP(Texture2DHandle, this.handle.read_index()); 321 | return texture.Sample(sampler, uv); 322 | } 323 | 324 | template 325 | T sample_3d(SamplerState sampler, float3 uvw) { 326 | Texture3D texture = DESCRIPTOR_HEAP(Texture3DHandle, this.handle.read_index()); 327 | return texture.Sample(sampler, uvw); 328 | } 329 | 330 | template 331 | T sample_cube(SamplerState s, float3 uvw) { 332 | TextureCube texture = DESCRIPTOR_HEAP(TextureCubeHandle, this.handle.read_index()); 333 | return texture.Sample(s, uvw); 334 | } 335 | 336 | template 337 | T sample_level_1d(SamplerState sampler, float u, float mip) { 338 | Texture1D texture = DESCRIPTOR_HEAP(Texture1DHandle, this.handle.read_index()); 339 | return texture.SampleLevel(sampler, u, mip); 340 | } 341 | 342 | template 343 | T sample_level_2d(SamplerState sampler, float2 uv, float mip) { 344 | Texture2D texture = DESCRIPTOR_HEAP(Texture2DHandle, this.handle.read_index()); 345 | return texture.SampleLevel(sampler, uv, mip); 346 | } 347 | 348 | template 349 | T sample_level_3d(SamplerState sampler, float3 uvw, float mip) { 350 | Texture3D texture = DESCRIPTOR_HEAP(Texture3DHandle, this.handle.read_index()); 351 | return texture.SampleLevel(sampler, uvw, mip); 352 | } 353 | 354 | template 355 | T sample_level_cube(SamplerState s, float3 uvw, float mip) { 356 | TextureCube texture = DESCRIPTOR_HEAP(TextureCubeHandle, this.handle.read_index()); 357 | return texture.SampleLevel(s, uvw, mip); 358 | } 359 | }; 360 | 361 | struct Sampler { 362 | ResourceHandle handle; 363 | 364 | SamplerState load() { 365 | SamplerState sampler_state_value = SAMPLER_HEAP(SamplerStateHandle, this.handle.read_index()); 366 | return sampler_state_value; 367 | } 368 | }; 369 | 370 | #undef DESCRIPTOR_HEAP 371 | 372 | #endif // HE_GLOBALS_HLSLI 373 | -------------------------------------------------------------------------------- /assets/shaders/grid_shader.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | // NOTE: Implementation based on https://asliceofrendering.com/scene%20helper/2020/01/05/InfiniteGrid/ 8 | 9 | #include "globals.hlsli" 10 | #include "shader_interop.h" 11 | 12 | static float3 s_grid_plane[6] = { 13 | float3( 1.0, 1.0, 0.0), 14 | float3(-1.0, -1.0, 0.0), 15 | float3(-1.0, 1.0, 0.0), 16 | float3(-1.0, -1.0, 0.0), 17 | float3( 1.0, 1.0, 0.0), 18 | float3( 1.0, -1.0, 0.0), 19 | }; 20 | 21 | struct VertexOutput { 22 | float4 position : SV_POSITION; 23 | float3 near_point : TEXCOORD0; 24 | float3 far_point : TEXCOORD1; 25 | }; 26 | 27 | float3 unproject_point(float3 xyz, float4x4 inverse_view, float4x4 inverse_projection) { 28 | const float4 unprojected_point = mul(mul(inverse_view, inverse_projection), float4(xyz, 1.0)); 29 | return unprojected_point.xyz / unprojected_point.w; 30 | } 31 | 32 | VertexOutput vs_main( 33 | uint vertex_id : SV_VertexID 34 | ) { 35 | const ShaderCamera camera = get_camera(); 36 | 37 | const float3 grid_point = s_grid_plane[vertex_id]; 38 | const float3 near_point = unproject_point(float3(grid_point.x, grid_point.y, 0.0), camera.inverse_view, camera.inverse_projection); 39 | const float3 far_point = unproject_point(float3(grid_point.x, grid_point.y, 1.0), camera.inverse_view, camera.inverse_projection); 40 | 41 | VertexOutput output = (VertexOutput) 0; 42 | output.position = float4(s_grid_plane[vertex_id], 1.0); 43 | output.near_point = near_point; 44 | output.far_point = far_point; 45 | return output; 46 | } 47 | 48 | struct FragmentOutput { 49 | float4 color : SV_TARGET; 50 | float depth : SV_DEPTH; 51 | }; 52 | 53 | float4 grid(float3 fragment_position, float scale) { 54 | const float2 coordinate = fragment_position.xz * scale; 55 | const float2 derivative = fwidth(coordinate); 56 | const float2 grid = abs(frac(coordinate - 0.5) - 0.5) / derivative; 57 | const float l = min(grid.x, grid.y); 58 | const float minimum_z = min(derivative.y, 1.0); 59 | const float minimum_x = min(derivative.x, 1.0); 60 | 61 | float4 color = float4(0.2, 0.2, 0.2, 1.0 - min(l, 1.0)); 62 | if (fragment_position.x > -0.1 * minimum_x && fragment_position.x < 0.1 * minimum_x) { 63 | color.b = 1.0; 64 | } 65 | 66 | if (fragment_position.z > -0.1 * minimum_z && fragment_position.z < 0.1 * minimum_z) { 67 | color.r = 1.0; 68 | } 69 | 70 | return color; 71 | } 72 | 73 | float compute_depth(float3 position, float4x4 view_projection) { 74 | const float4 clip_space_position = mul(view_projection, float4(position.xyz, 1.0)); 75 | return (clip_space_position.z / clip_space_position.w); 76 | } 77 | 78 | float compute_linear_depth(float3 position, float4x4 view_projection, float near_plane, float far_plane) { 79 | const float4 clip_space_position = mul(view_projection, float4(position.xyz, 1.0)); 80 | const float clip_space_depth = (clip_space_position.z / clip_space_position.w) * 2.0 - 1.0; 81 | const float linear_depth = (2.0 * near_plane * far_plane) / (far_plane + near_plane - clip_space_depth * (far_plane - near_plane)); 82 | return linear_depth / far_plane; 83 | } 84 | 85 | FragmentOutput fs_main(VertexOutput input) { 86 | const ShaderCamera camera = get_camera(); 87 | 88 | const float t = -input.near_point.y / (input.far_point.y - input.near_point.y); 89 | const float3 fragment_position = input.near_point + t * (input.far_point - input.near_point); 90 | 91 | const float linear_depth = compute_linear_depth(fragment_position, camera.view_projection, camera.near_plane, camera.far_plane); 92 | const float fading = max(0.0, (0.5 - linear_depth)); 93 | 94 | float4 color = (grid(fragment_position, 10.0) + grid(fragment_position, 1.0)) * float(t > 0.0); 95 | color.a *= fading; 96 | 97 | FragmentOutput output = (FragmentOutput) 0; 98 | output.color = color; 99 | output.depth = compute_depth(fragment_position, camera.view_projection); 100 | 101 | return output; 102 | } 103 | -------------------------------------------------------------------------------- /assets/shaders/pbr_shader.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #include "color_space.hlsli" 8 | #include "globals.hlsli" 9 | #include "shader_interop.h" 10 | 11 | HE_PUSH_CONSTANT(ObjectPushConstants, g_push); 12 | 13 | struct VertexOutput { 14 | float4 position : SV_POSITION; 15 | float3 normal : NORMAL; 16 | float3x3 tbn : TBN; 17 | float3 color : COLOR; 18 | float2 uv : TEXCOORD; 19 | float3 world_pos : TEXCOORD1; 20 | }; 21 | 22 | VertexOutput vs_main( 23 | uint vertex_id : SV_VertexID 24 | ) { 25 | const ShaderCamera camera = get_camera(); 26 | 27 | const ShaderMaterial material = g_push.get_material(); 28 | 29 | const ShaderModel model = g_push.get_model(); 30 | const float4 position = float4(model.get_position(vertex_id), 1.0); 31 | const float3 normal = model.get_normal(vertex_id); 32 | const float4 tangent = model.get_tangent(vertex_id); 33 | const float3 color = model.get_color(vertex_id); 34 | const float2 uv = model.get_uv(vertex_id); 35 | 36 | const float3 n = normalize(float3(mul(g_push.transform_matrix, float4(normal, 0.0)).xyz)); 37 | float3 t = normalize(float3(mul(g_push.transform_matrix, float4(tangent.xyz, 0.0)).xyz)); 38 | 39 | t = normalize(t - dot(t, n) * n); 40 | 41 | const float3 b = cross(n, t) * tangent.w; 42 | const float3x3 tbn = float3x3(t, b, n); 43 | 44 | const float4 world_position = mul(g_push.transform_matrix, position); 45 | 46 | VertexOutput output = (VertexOutput) 0; 47 | output.position = mul(camera.view_projection, world_position); 48 | output.normal = n; 49 | output.tbn = transpose(tbn); 50 | output.color = color; 51 | output.uv = uv; 52 | output.world_pos = world_position.xyz; 53 | return output; 54 | } 55 | 56 | // Approximates the amount the surface's microfacets are aligned to the halfway vector, influenced by the roughness of the surface 57 | float distribution_ggx(float3 n, float3 h, float roughness) { 58 | const float a = roughness * roughness; 59 | const float a_2 = a * a; 60 | 61 | const float n_dot_h = max(dot(n, h), 0.0); 62 | const float n_dot_h_2 = n_dot_h * n_dot_h; 63 | 64 | const float number = a_2; 65 | float denominator = (n_dot_h_2 * (a_2 - 1.0) + 1.0); 66 | denominator = PI * denominator * denominator; 67 | 68 | return number / denominator; 69 | } 70 | 71 | // Describes the self-shadowing property of the microfacets 72 | float geometry_schlick_ggx(float n_dot_v, float roughness) { 73 | const float r = (roughness + 1.0); 74 | const float k = (r * r) / 8.0; 75 | 76 | const float num = n_dot_v; 77 | const float denom = n_dot_v * (1.0 - k) + k; 78 | 79 | return num / denom; 80 | } 81 | 82 | float geometry_smith(float3 n, float3 v, float3 l, float roughness) { 83 | const float n_dot_l = max(dot(n, l), 0.0); 84 | const float ggx1 = geometry_schlick_ggx(n_dot_l, roughness); 85 | 86 | const float n_dot_v = max(dot(n, v), 0.0); 87 | const float ggx2 = geometry_schlick_ggx(n_dot_v, roughness); 88 | 89 | return ggx1 * ggx2; 90 | } 91 | 92 | // Describes the ratio of surface reflection at different surface angles 93 | float3 fresnel_schlick(float cos_theta, float3 f_0) { 94 | return f_0 + (1.0 - f_0) * pow(clamp(1.0 - cos_theta, 0.0, 1.0), 5.0); 95 | } 96 | 97 | float4 fs_main(VertexOutput input) : SV_TARGET { 98 | const ShaderScene scene = g_push.get_scene(); 99 | const ShaderMaterial material = g_push.get_material(); 100 | 101 | float3 albedo = input.color; 102 | if (material.albedo_texture.handle.is_valid()) { 103 | const SamplerState albedo_sampler = material.albedo_sampler.load(); 104 | const float3 albedo_value = material.albedo_texture.sample_2d(albedo_sampler, input.uv); 105 | const float3 final_albedo_value = material.albedo_factors.xyz * albedo_value; 106 | albedo = final_albedo_value; 107 | } 108 | 109 | float roughness = 1.0; 110 | float metallic = 0.0; 111 | if (material.metal_roughness_texture.handle.is_valid()) { 112 | const SamplerState metal_roughness_sampler = material.metal_roughness_sampler.load(); 113 | const float3 metal_roughness_value = material.metal_roughness_texture.sample_2d(metal_roughness_sampler, input.uv); 114 | 115 | const float final_roughness_value = material.metal_roughness_factors.x * metal_roughness_value.g; 116 | roughness = final_roughness_value; 117 | 118 | const float final_metallic_value = material.metal_roughness_factors.y * metal_roughness_value.b; 119 | metallic = final_metallic_value; 120 | } 121 | 122 | float3 normal = normalize(input.normal); 123 | if (material.normal_texture.handle.is_valid()) { 124 | const SamplerState normal_sampler = material.normal_sampler.load(); 125 | const float3 normal_value = material.normal_texture.sample_2d(normal_sampler, input.uv); 126 | 127 | const float3 tangent_space_normal = normalize(normal_value * 2.0 - 1.0); 128 | const float3 scaled_tangent_space_normal = material.normal_scale * tangent_space_normal; 129 | const float3 tbn_normal = mul(input.tbn, tangent_space_normal); 130 | normal = normalize(tbn_normal); 131 | } 132 | 133 | const ShaderCamera camera = get_camera(); 134 | const float3 view_direction = normalize(camera.position.xyz - input.world_pos); 135 | 136 | float3 f_0 = float3(0.04, 0.04, 0.04); 137 | f_0 = lerp(f_0, albedo, metallic); 138 | 139 | float3 l_0 = float3(0.0, 0.0, 0.0); 140 | // FIXME: Loop through all lights 141 | { 142 | /**/ 143 | const float3 light_position = float3(0.0, 5.0, 0.0); 144 | const float3 light_color = float3(100.0, 100.0, 100.0); 145 | /**/ 146 | 147 | const float3 light_direction = normalize(light_position - input.world_pos); 148 | const float3 halfway = normalize(view_direction + light_direction); 149 | 150 | const float distance = length(light_position - input.world_pos); 151 | const float attenuation = 1.0 / (distance * distance); 152 | const float3 radiance = light_color * attenuation; 153 | 154 | // Cook-Torrance BRDF 155 | const float ndf = distribution_ggx(normal, halfway, roughness); 156 | const float g = geometry_smith(normal, view_direction, light_direction, roughness); 157 | const float3 f = fresnel_schlick(max(dot(halfway, view_direction), 0.0), f_0); 158 | 159 | const float3 k_s = f; 160 | float3 k_d = float3(1.0, 1.0, 1.0) - k_s; 161 | k_d *= 1.0 - metallic; 162 | 163 | const float3 numerator = ndf * g * f; 164 | const float denominator = 4.0 * max(dot(normal, view_direction), 0.0) * max(dot(normal, light_direction), 0.0) + 0.0001; 165 | const float3 specular = numerator / denominator; 166 | 167 | // Add to outgoing radiance L_0 168 | const float n_dot_l = max(dot(normal, light_direction), 0.0); 169 | l_0 += (k_d * albedo / PI + specular) * radiance * n_dot_l; 170 | } 171 | 172 | // FIXME: Add Ambient Occlusion 173 | const float3 ambient = float3(0.03, 0.03, 0.03) * albedo; 174 | 175 | float3 color = ambient + l_0; 176 | 177 | // Reinhard Tone Mapping 178 | color = apply_reinhard_tone_mapping(color); 179 | 180 | // Applying Gamme Correction 181 | color = apply_srgb(color); 182 | 183 | return float4(color, 1.0); 184 | } 185 | -------------------------------------------------------------------------------- /assets/shaders/shader_interop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #ifndef HE_SHADER_INTEROP_HPP 8 | #define HE_SHADER_INTEROP_HPP 9 | 10 | #ifdef __cplusplus 11 | # include 12 | # 13 | # include 14 | 15 | # define float2 ::glm::vec2 16 | # define float3 ::glm::vec3 17 | # define float4 ::glm::vec4 18 | # define float3x3 ::glm::mat3 19 | # define float4x4 ::glm::mat4 20 | 21 | # define int2 ::glm::i32vec2 22 | # define int3 ::glm::i32vec3 23 | # define int4 ::glm::i32vec4 24 | 25 | # define uint uint32_t 26 | # define uint2 ::glm::u32vec2 27 | # define uint3 ::glm::u32vec3 28 | # define uint4 ::glm::u32vec4 29 | 30 | # define RESOURCE_HANDLE ::ResourceHandle 31 | # define SIMPLE_BUFFER RESOURCE_HANDLE 32 | # define RW_SIMPLE_BUFFER RESOURCE_HANDLE 33 | # define ARRAY_BUFFER RESOURCE_HANDLE 34 | # define RW_ARRAY_BUFFER RESOURCE_HANDLE 35 | # define TEXTURE RESOURCE_HANDLE 36 | # define RW_TEXTURE RESOURCE_HANDLE 37 | # define SAMPLER RESOURCE_HANDLE 38 | #else 39 | # include "globals.hlsli" 40 | 41 | # define RESOURCE_HANDLE uint 42 | # define SIMPLE_BUFFER SimpleBuffer 43 | # define RW_SIMPLE_BUFFER RwSimpleBuffer 44 | # define ARRAY_BUFFER ArrayBuffer 45 | # define RW_ARRAY_BUFFER RwArrayBuffer 46 | # define TEXTURE Texture 47 | # define RW_TEXTURE RwTexture 48 | # define SAMPLER Sampler 49 | #endif 50 | 51 | //////////////////////////////////////////////////////////////////////////////// 52 | // Shader Interop 53 | //////////////////////////////////////////////////////////////////////////////// 54 | 55 | struct ShaderScene 56 | { 57 | float4 ambient_color; 58 | float4 sunlight_direction; // .w for sun power 59 | float4 sunlight_color; 60 | float4 padding_0; 61 | }; 62 | 63 | struct ShaderModel 64 | { 65 | ARRAY_BUFFER positions; 66 | ARRAY_BUFFER normals; 67 | ARRAY_BUFFER tangents; 68 | ARRAY_BUFFER colors; 69 | ARRAY_BUFFER uvs; 70 | 71 | #ifndef __cplusplus 72 | inline float3 get_position(uint index) 73 | { 74 | return positions.load(index); 75 | } 76 | 77 | inline float3 get_normal(uint index) 78 | { 79 | return normals.load(index); 80 | } 81 | 82 | inline float4 get_tangent(uint index) 83 | { 84 | return tangents.load(index); 85 | } 86 | 87 | inline float3 get_color(uint index) 88 | { 89 | return colors.load(index); 90 | } 91 | 92 | inline float2 get_uv(uint index) 93 | { 94 | return uvs.load(index); 95 | } 96 | #endif 97 | }; 98 | 99 | struct ShaderMaterial 100 | { 101 | float4 albedo_factors; 102 | TEXTURE albedo_texture; 103 | SAMPLER albedo_sampler; 104 | uint padding_0; 105 | uint padding_1; 106 | 107 | float2 metal_roughness_factors; 108 | TEXTURE metal_roughness_texture; 109 | SAMPLER metal_roughness_sampler; 110 | 111 | TEXTURE normal_texture; 112 | SAMPLER normal_sampler; 113 | float normal_scale; 114 | uint padding_2; 115 | }; 116 | 117 | //////////////////////////////////////////////////////////////////////////////// 118 | // Push Constants 119 | //////////////////////////////////////////////////////////////////////////////// 120 | 121 | #ifndef __cplusplus 122 | # ifdef HE_VULKAN 123 | # define HE_PUSH_CONSTANT(value_type, name) [[vk::push_constant]] value_type name 124 | # else 125 | # define HE_PUSH_CONSTANT(value_type, name) ConstantBuffer name : register(b0, space0) 126 | # endif 127 | #endif 128 | 129 | struct ObjectPushConstants 130 | { 131 | SIMPLE_BUFFER scene; 132 | SIMPLE_BUFFER model; 133 | SIMPLE_BUFFER material; 134 | uint padding_0; 135 | float4x4 transform_matrix; 136 | float3x3 normal_matrix; 137 | 138 | #ifndef __cplusplus 139 | inline ShaderScene get_scene() 140 | { 141 | return scene.load(); 142 | } 143 | 144 | inline ShaderModel get_model() 145 | { 146 | return model.load(); 147 | } 148 | 149 | inline ShaderMaterial get_material() 150 | { 151 | return material.load(); 152 | } 153 | #endif 154 | }; 155 | 156 | // NOTE: Should the skybox be a push constant? 157 | struct SkyboxPushConstants 158 | { 159 | TEXTURE skybox_texture; 160 | SAMPLER skybox_sampler; 161 | uint padding_0; 162 | uint padding_1; 163 | }; 164 | 165 | // NOTE: Should the skybox be a push constant? 166 | struct CompositionPushConstants 167 | { 168 | TEXTURE composition_texture; 169 | SAMPLER composition_sampler; 170 | uint padding_0; 171 | uint padding_1; 172 | }; 173 | 174 | //////////////////////////////////////////////////////////////////////////////// 175 | // Globals 176 | //////////////////////////////////////////////////////////////////////////////// 177 | 178 | // NOTE: This assumes we have 1000 * 1000 descriptors available. This might need refining 179 | #define HE_DESCRIPTOR_SET_SLOT_FRAME ((1000 * 1000) - 1) 180 | #define HE_DESCRIPTOR_SET_SLOT_CAMERA ((1000 * 1000) - 2) 181 | 182 | struct ShaderFrame 183 | { 184 | float time; 185 | float delta_time; 186 | float unused_0; 187 | float unused_1; 188 | 189 | uint frame_count; 190 | uint unused_2; 191 | uint unused_3; 192 | uint unused_4; 193 | 194 | float2 screen_size; 195 | float2 unused_5; 196 | }; 197 | 198 | #ifndef __cplusplus 199 | inline ShaderFrame get_frame() 200 | { 201 | SimpleBuffer buffer = (SimpleBuffer) HE_DESCRIPTOR_SET_SLOT_FRAME; 202 | return buffer.load(); 203 | } 204 | #endif 205 | 206 | struct ShaderCamera 207 | { 208 | float4 position; 209 | 210 | float4x4 view; 211 | float4x4 inverse_view; 212 | float4x4 projection; 213 | float4x4 inverse_projection; 214 | float4x4 view_projection; 215 | float4x4 inverse_view_projection; 216 | 217 | float4x4 smaller_view; 218 | 219 | float near_plane; 220 | float far_plane; 221 | float padding_0; 222 | float padding_1; 223 | }; 224 | 225 | #ifndef __cplusplus 226 | inline ShaderCamera get_camera() 227 | { 228 | SimpleBuffer buffer = (SimpleBuffer) HE_DESCRIPTOR_SET_SLOT_CAMERA; 229 | return buffer.load(); 230 | } 231 | #endif 232 | 233 | #ifdef __cplusplus 234 | # undef float2 235 | # undef float3 236 | # undef float4 237 | # undef float4x4 238 | 239 | # undef int2 240 | # undef int3 241 | # undef int4 242 | 243 | # undef uint 244 | # undef uint2 245 | # undef uint3 246 | # undef uint4 247 | 248 | # undef RESOURCE_HANDLE 249 | # undef ARRAY_BUFFER 250 | #else 251 | # undef RESOURCE_HANDLE 252 | # undef ARRAY_BUFFER 253 | #endif 254 | 255 | #endif // HE_SHADER_INTEROP_HPP 256 | -------------------------------------------------------------------------------- /assets/shaders/skybox_shader.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #include "color_space.hlsli" 8 | #include "globals.hlsli" 9 | #include "shader_interop.h" 10 | 11 | static float3 s_skybox[36] = { 12 | float3(-1.0, 1.0, -1.0), 13 | float3(-1.0, -1.0, -1.0), 14 | float3( 1.0, -1.0, -1.0), 15 | float3( 1.0, -1.0, -1.0), 16 | float3( 1.0, 1.0, -1.0), 17 | float3(-1.0, 1.0, -1.0), 18 | 19 | float3(-1.0, -1.0, 1.0), 20 | float3(-1.0, -1.0, -1.0), 21 | float3(-1.0, 1.0, -1.0), 22 | float3(-1.0, 1.0, -1.0), 23 | float3(-1.0, 1.0, 1.0), 24 | float3(-1.0, -1.0, 1.0), 25 | 26 | float3( 1.0, -1.0, -1.0), 27 | float3( 1.0, -1.0, 1.0), 28 | float3( 1.0, 1.0, 1.0), 29 | float3( 1.0, 1.0, 1.0), 30 | float3( 1.0, 1.0, -1.0), 31 | float3( 1.0, -1.0, -1.0), 32 | 33 | float3(-1.0, -1.0, 1.0), 34 | float3(-1.0, 1.0, 1.0), 35 | float3( 1.0, 1.0, 1.0), 36 | float3( 1.0, 1.0, 1.0), 37 | float3( 1.0, -1.0, 1.0), 38 | float3(-1.0, -1.0, 1.0), 39 | 40 | float3(-1.0, 1.0, -1.0), 41 | float3( 1.0, 1.0, -1.0), 42 | float3( 1.0, 1.0, 1.0), 43 | float3( 1.0, 1.0, 1.0), 44 | float3(-1.0, 1.0, 1.0), 45 | float3(-1.0, 1.0, -1.0), 46 | 47 | float3(-1.0, -1.0, -1.0), 48 | float3(-1.0, -1.0, 1.0), 49 | float3( 1.0, -1.0, -1.0), 50 | float3( 1.0, -1.0, -1.0), 51 | float3(-1.0, -1.0, 1.0), 52 | float3( 1.0, -1.0, 1.0) 53 | }; 54 | 55 | HE_PUSH_CONSTANT(SkyboxPushConstants, g_push); 56 | 57 | struct VertexOutput { 58 | float4 position : SV_POSITION; 59 | float3 uvw : TEXCOORD; 60 | }; 61 | 62 | VertexOutput vs_main( 63 | uint vertex_id : SV_VertexID 64 | ) { 65 | const ShaderCamera camera = get_camera(); 66 | 67 | const float4 position = float4(s_skybox[vertex_id], 1.0); 68 | 69 | VertexOutput output = (VertexOutput) 0; 70 | output.position = mul(camera.projection, mul(camera.smaller_view, position)).xyww; 71 | output.uvw = position.xyz; 72 | return output; 73 | } 74 | 75 | float4 fs_main(VertexOutput input) : SV_TARGET { 76 | float3 color = g_push.skybox_texture.sample_cube(g_push.skybox_sampler.load(), input.uvw).xyz; 77 | 78 | color = apply_reinhard_tone_mapping(color); 79 | color = apply_srgb(color); 80 | 81 | return float4(color, 1.0); 82 | } 83 | -------------------------------------------------------------------------------- /cmake/CompilerWarnings.cmake: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------------------- 2 | # Copyright (c) 2024-present, SkillerRaptor 3 | # 4 | # SPDX-License-Identifier: MIT 5 | #------------------------------------------------------------------------------------------- 6 | 7 | function(enable_warnings project_name) 8 | option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF) 9 | 10 | set(MSVC_WARNINGS 11 | /W4 12 | /w14242 13 | /w14254 14 | /w14263 15 | /w14265 16 | /w14287 17 | /we4289 18 | /w14296 19 | /w14311 20 | /w14545 21 | /w14546 22 | /w14547 23 | /w14549 24 | /w14555 25 | /w14619 26 | /w14640 27 | /w14826 28 | /w14905 29 | /w14906 30 | /w14928 31 | /permissive-) 32 | 33 | set(CLANG_WARNINGS 34 | -Wall 35 | -Wextra 36 | -Wshadow 37 | -Wnon-virtual-dtor 38 | -Wold-style-cast 39 | -Wcast-align 40 | -Wunused 41 | -Woverloaded-virtual 42 | -Wpedantic 43 | -Wconversion 44 | -Wsign-conversion 45 | -Wnull-dereference 46 | -Wdouble-promotion 47 | -Wformat=2) 48 | 49 | set(GCC_WARNINGS 50 | ${CLANG_WARNINGS} 51 | -Wmisleading-indentation 52 | -Wduplicated-cond 53 | -Wduplicated-branches 54 | -Wlogical-op 55 | -Wuseless-cast) 56 | 57 | if (WARNINGS_AS_ERRORS) 58 | set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror) 59 | set(GCC_WARNINGS ${GCC_WARNINGS} -Werror) 60 | set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX) 61 | endif () 62 | 63 | if (MSVC) 64 | set(PROJECT_WARNINGS ${MSVC_WARNINGS}) 65 | elseif (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") 66 | set(PROJECT_WARNINGS ${CLANG_WARNINGS}) 67 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 68 | set(PROJECT_WARNINGS ${GCC_WARNINGS}) 69 | else () 70 | message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.") 71 | endif () 72 | 73 | target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS}) 74 | endfunction() 75 | -------------------------------------------------------------------------------- /cmake/Doxygen.cmake: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------------------- 2 | # Copyright (c) 2024-present, SkillerRaptor 3 | # 4 | # SPDX-License-Identifier: MIT 5 | #------------------------------------------------------------------------------------------- 6 | 7 | function(enable_doxygen) 8 | if ((NOT DOXYGEN_USE_MDFILE_AS_MAINPAGE) AND EXISTS "${PROJECT_SOURCE_DIR}/README.md") 9 | set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "${PROJECT_SOURCE_DIR}/README.md") 10 | endif () 11 | 12 | set(DOXYGEN_QUIET NO) 13 | set(DOXYGEN_CALLER_GRAPH YES) 14 | set(DOXYGEN_CALL_GRAPH YES) 15 | set(DOXYGEN_EXTRACT_ALL YES) 16 | set(DOXYGEN_GENERATE_TREEVIEW YES) 17 | set(DOXYGEN_DOT_IMAGE_FORMAT svg) 18 | set(DOXYGEN_DOT_TRANSPARENT YES) 19 | 20 | if (NOT DOXYGEN_EXCLUDE_PATTERNS) 21 | set(DOXYGEN_EXCLUDE_PATTERNS "${PROJECT_SOURCE_DIR}/third_party" "${CMAKE_CURRENT_BINARY_DIR}/_deps/*") 22 | endif () 23 | 24 | find_package(Doxygen OPTIONAL_COMPONENTS dot) 25 | 26 | if (Doxygen_FOUND) 27 | include(FetchContent) 28 | 29 | FetchContent_Declare(_doxygen_theme URL https://github.com/jothepro/doxygen-awesome-css/archive/refs/tags/v2.3.4.zip) 30 | FetchContent_MakeAvailable(_doxygen_theme) 31 | set(DOXYGEN_HTML_EXTRA_STYLESHEET "${_doxygen_theme_SOURCE_DIR}/doxygen-awesome.css") 32 | 33 | message(STATUS "Adding `doxygen-docs` target that builds the documentation.") 34 | doxygen_add_docs( 35 | doxygen-docs 36 | ALL 37 | ${PROJECT_SOURCE_DIR} 38 | COMMENT 39 | "Generating documentation - entry file: ${CMAKE_CURRENT_BINARY_DIR}/html/index.html") 40 | endif () 41 | endfunction() -------------------------------------------------------------------------------- /cmake/PreventInSourceBuilds.cmake: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------------------- 2 | # Copyright (c) 2024-present, SkillerRaptor 3 | # 4 | # SPDX-License-Identifier: MIT 5 | #------------------------------------------------------------------------------------------- 6 | 7 | get_filename_component(SOURCE_DIR "${CMAKE_SOURCE_DIR}" REALPATH) 8 | get_filename_component(BINARY_DIR "${CMAKE_BINARY_DIR}" REALPATH) 9 | 10 | if ("${SOURCE_DIR}" STREQUAL "${BINARY_DIR}") 11 | message(STATUS "######################################################") 12 | message(STATUS "Warning: in-source builds are disabled") 13 | message(STATUS "Please create a separate build directory and run cmake from there") 14 | message(STATUS "######################################################") 15 | message(FATAL_ERROR "Quitting configuration") 16 | endif () 17 | -------------------------------------------------------------------------------- /cmake/StandardProjectSettings.cmake: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------------------- 2 | # Copyright (c) 2024-present, SkillerRaptor 3 | # 4 | # SPDX-License-Identifier: MIT 5 | #------------------------------------------------------------------------------------------- 6 | 7 | if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 8 | message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.") 9 | set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE) 10 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") 11 | endif () 12 | 13 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 14 | 15 | option(ENABLE_IPO "Enable Interprocedural Optimization / Link Time Optimization" OFF) 16 | if (ENABLE_IPO) 17 | include(CheckIPOSupported) 18 | check_ipo_supported(RESULT IPO_RESULT OUTPUT IPO_OUTPUT) 19 | if (IPO_RESULT) 20 | set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) 21 | else () 22 | message(SEND_ERROR "IPO is not supported: ${IPO_OUTPUT}") 23 | endif () 24 | endif () 25 | 26 | if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") 27 | add_compile_options(-fcolor-diagnostics) 28 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 29 | add_compile_options(-fdiagnostics-color=always) 30 | else () 31 | message(STATUS "No colored compiler diagnostic set for '${CMAKE_CXX_COMPILER_ID}' compiler.") 32 | endif () 33 | -------------------------------------------------------------------------------- /cmake/Utils.cmake: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------------------- 2 | # Copyright (c) 2024-present, SkillerRaptor 3 | # 4 | # SPDX-License-Identifier: MIT 5 | #------------------------------------------------------------------------------------------- 6 | 7 | function(hyperengine_group_source SOURCE) 8 | foreach (item IN ITEMS ${SOURCE}) 9 | get_filename_component(src_path "${item}" PATH) 10 | string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "" group_path "${src_path}") 11 | string(REPLACE ".." "\\" group_path "${group_path}") 12 | source_group("${group_path}" FILES "${item}") 13 | endforeach () 14 | endfunction() 15 | 16 | function(hyperengine_define_executable target) 17 | hyperengine_group_source(${SOURCES}) 18 | if (HEADERS) 19 | hyperengine_group_source(${HEADERS}) 20 | endif () 21 | 22 | add_executable(${target} ${SOURCES} ${HEADERS}) 23 | target_link_libraries(${target} PRIVATE ProjectOptions ProjectWarnings) 24 | target_include_directories(${target} PUBLIC include) 25 | target_compile_options(${target} PUBLIC "$<$:/Zc:preprocessor>") 26 | 27 | if (WIN32) 28 | target_compile_definitions( 29 | ${target} 30 | PUBLIC 31 | HE_WINDOWS=1 32 | _CRT_SECURE_NO_WARNINGS 33 | NOMINMAX 34 | WIN32_LEAN_AND_MEAN) 35 | else () 36 | target_compile_definitions(${target} PUBLIC HE_LINUX=1) 37 | endif () 38 | endfunction() 39 | 40 | function(hyperengine_download_and_extract URL DESTINATION FOLDER_NAME) 41 | if (NOT EXISTS ${CMAKE_BINARY_DIR}/download/${FOLDER_NAME}.zip) 42 | message(STATUS " Downloading ${URL} and unpacking to ${DESTINATION}/${FOLDER_NAME}.") 43 | file( 44 | DOWNLOAD 45 | ${URL} 46 | ${CMAKE_BINARY_DIR}/download/${FOLDER_NAME}.zip) 47 | else () 48 | message(STATUS "${CMAKE_BINARY_DIR}/download/${FOLDER_NAME}.zip already exists. No download required.") 49 | endif () 50 | 51 | if (NOT EXISTS ${DESTINATION}/${FOLDER_NAME}) 52 | message(STATUS "Extracting ${CMAKE_BINARY_DIR}/download/${FOLDER_NAME}.zip to ${DESTINATION}/${FOLDER_NAME}.") 53 | file( 54 | ARCHIVE_EXTRACT 55 | INPUT ${CMAKE_BINARY_DIR}/download/${FOLDER_NAME}.zip 56 | DESTINATION ${DESTINATION}/${FOLDER_NAME}) 57 | else () 58 | message(STATUS "${CMAKE_BINARY_DIR}/download/${FOLDER_NAME}.zip is already extracted to ${DESTINATION}/${FOLDER_NAME}.") 59 | endif () 60 | endfunction() 61 | 62 | 63 | function(hyperengine_deploy_files SOURCE DESTINATION) 64 | set(DEPLOY_FILES_DESTINATION ${CMAKE_BINARY_DIR}/${DESTINATION}) 65 | message(STATUS "Copying ${SOURCE} to ${DEPLOY_FILES_DESTINATION}") 66 | file(COPY ${SOURCE} DESTINATION ${DEPLOY_FILES_DESTINATION}) 67 | endfunction() -------------------------------------------------------------------------------- /hyper_engine/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------------------- 2 | # Copyright (c) 2024-present, SkillerRaptor 3 | # 4 | # SPDX-License-Identifier: MIT 5 | #------------------------------------------------------------------------------------------- 6 | set(SOURCES 7 | src/engine.cpp 8 | src/main.cpp 9 | src/core/filesystem.cpp 10 | src/core/logger.cpp 11 | src/core/string_utils.cpp 12 | src/drivers/vulkan/vulkan_render_conversion.cpp 13 | src/drivers/vulkan/vulkan_render_driver.cpp 14 | src/scene/resources/asset.cpp 15 | src/systems/input_system.cpp 16 | src/systems/render_system.cpp 17 | src/systems/window_system.cpp 18 | src/systems/render/camera.cpp 19 | src/systems/render/shader_compiler.cpp) 20 | 21 | set(HEADERS 22 | include/engine.hpp 23 | include/core/assertion.hpp 24 | include/core/bit_flags.hpp 25 | include/core/filesystem.hpp 26 | include/core/logger.hpp 27 | include/core/prerequisites.hpp 28 | include/core/resource_id.hpp 29 | include/core/resource_owner.hpp 30 | include/core/string_utils.hpp 31 | include/drivers/vulkan/vulkan_render_conversion.hpp 32 | include/drivers/vulkan/vulkan_render_driver.hpp 33 | include/scene/resources/asset.hpp 34 | include/systems/input_system.hpp 35 | include/systems/render_system.hpp 36 | include/systems/window_system.hpp 37 | include/systems/render/camera.hpp 38 | include/systems/render/render_driver.hpp 39 | include/systems/render/render_types.hpp 40 | include/systems/render/resource_handle.hpp 41 | include/systems/render/shader_compiler.hpp 42 | include/systems/window/event_bus.hpp 43 | include/systems/window/event_handler.hpp 44 | include/systems/window/key_codes.hpp 45 | include/systems/window/key_events.hpp 46 | include/systems/window/mouse_codes.hpp 47 | include/systems/window/mouse_events.hpp 48 | include/systems/window/window_events.hpp) 49 | 50 | #------------------------------------------------------------------------------------------- 51 | 52 | link_libraries( 53 | DirectXShaderCompiler 54 | EnTT::EnTT 55 | fastgltf 56 | fmt 57 | glm 58 | imgui 59 | libassert::assert 60 | SDL3::SDL3 61 | spdlog 62 | stb 63 | TracyClient 64 | volk 65 | VulkanMemoryAllocator) 66 | if (WIN32) 67 | link_libraries( 68 | d3d12.lib 69 | dxgi.lib 70 | D3D12MemoryAllocator) 71 | endif () 72 | 73 | add_compile_definitions( 74 | -DGLM_FORCE_RADIANS 75 | -DGLM_FORCE_DEPTH_ZE_TO_ONE) 76 | 77 | include_directories(${CMAKE_SOURCE_DIR}/assets/shaders) 78 | 79 | #------------------------------------------------------------------------------------------- 80 | 81 | hyperengine_define_executable(hyper_engine) 82 | target_link_libraries( 83 | hyper_engine 84 | PRIVATE 85 | Catch2::Catch2) 86 | 87 | hyperengine_define_executable(hyper_engine_tests) 88 | target_link_libraries( 89 | hyper_engine_tests 90 | PRIVATE 91 | Catch2::Catch2WithMain) 92 | target_compile_definitions( 93 | hyper_engine_tests 94 | PRIVATE 95 | -DCATCH_CONFIG_MAIN 96 | -DHE_TESTS=1) 97 | 98 | hyperengine_define_executable(hyper_engine_profiling) 99 | target_link_libraries( 100 | hyper_engine_profiling 101 | PRIVATE 102 | Catch2::Catch2) 103 | target_compile_definitions( 104 | hyper_engine_tests 105 | PRIVATE 106 | -DTRACY_ENABLE 107 | -DHE_PROFILING=1) -------------------------------------------------------------------------------- /hyper_engine/include/core/assertion.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #define HE_ASSERT(expression, ...) LIBASSERT_ASSERT(expression, __VA_ARGS__) 12 | #define HE_ASSERT_VALUE(expression, ...) LIBASSERT_ASSERT_VAL(expression, __VA_ARGS__) 13 | #define HE_DEBUG_ASSERT(expression, ...) LIBASSERT_DEBUG_ASSERT(expression, __VA_ARGS__) 14 | #define HE_DEBUG_ASSERT_VALUE(expression, ...) LIBASSERT_DEBUG_ASSERT_VAL(expression, __VA_ARGS__) 15 | #define HE_PANIC(...) LIBASSERT_PANIC(__VA_ARGS__) 16 | #define HE_UNREACHABLE(...) LIBASSERT_UNREACHABLE(__VA_ARGS__) 17 | -------------------------------------------------------------------------------- /hyper_engine/include/core/bit_flags.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | // Credit goes to: https://voithos.io/articles/type-safe-enum-class-bit-flags/ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | template 15 | class BitFlags 16 | { 17 | private: 18 | using UnderlyingT = std::underlying_type_t; 19 | 20 | public: 21 | constexpr BitFlags() 22 | : m_flags { static_cast(0) } 23 | { 24 | } 25 | 26 | constexpr BitFlags(const T flag) 27 | : m_flags { static_cast(flag) } 28 | { 29 | } 30 | 31 | constexpr BitFlags(const std::initializer_list flags) 32 | : BitFlags {} 33 | { 34 | for (const T flag : flags) 35 | { 36 | m_flags |= static_cast(flag); 37 | } 38 | } 39 | 40 | constexpr operator bool() const { return m_flags != static_cast(0); } 41 | 42 | friend constexpr BitFlags operator|(const BitFlags left, const T right) 43 | { 44 | return BitFlags(left.m_flags | static_cast(right)); 45 | } 46 | 47 | friend constexpr BitFlags operator|(const BitFlags left, const BitFlags right) 48 | { 49 | return BitFlags(left.m_flags | right.m_flags); 50 | } 51 | 52 | friend constexpr BitFlags operator&(const BitFlags left, const T right) 53 | { 54 | return BitFlags(left.m_flags & static_cast(right)); 55 | } 56 | 57 | friend constexpr BitFlags operator&(const BitFlags left, const BitFlags right) 58 | { 59 | return BitFlags(left.m_flags & right.m_flags); 60 | } 61 | 62 | friend constexpr BitFlags operator^(const BitFlags left, const T right) 63 | { 64 | return BitFlags(left.m_flags ^ static_cast(right)); 65 | } 66 | 67 | friend constexpr BitFlags operator^(const BitFlags left, const BitFlags right) 68 | { 69 | return BitFlags(left.m_flags ^ right.m_flags); 70 | } 71 | 72 | friend constexpr BitFlags &operator|=(BitFlags &left, const T right) 73 | { 74 | left.m_flags |= static_cast(right); 75 | return left; 76 | } 77 | 78 | friend constexpr BitFlags &operator|=(BitFlags &left, const BitFlags right) 79 | { 80 | left.m_flags |= right.m_flags; 81 | return left; 82 | } 83 | 84 | friend constexpr BitFlags &operator&=(BitFlags &left, const T right) 85 | { 86 | left.m_flags &= static_cast(right); 87 | return left; 88 | } 89 | 90 | friend constexpr BitFlags &operator&=(BitFlags &left, const BitFlags right) 91 | { 92 | left.m_flags &= right.m_flags; 93 | return left; 94 | } 95 | 96 | friend constexpr BitFlags &operator^=(BitFlags &left, const T right) 97 | { 98 | left.m_flags ^= static_cast(right); 99 | return left; 100 | } 101 | 102 | friend constexpr BitFlags &operator^=(BitFlags &left, const BitFlags right) 103 | { 104 | left.m_flags ^= right.m_flags; 105 | return left; 106 | } 107 | 108 | friend constexpr BitFlags operator~(const BitFlags &bit_flags) { return BitFlags(~bit_flags.m_flags); } 109 | 110 | friend constexpr bool operator==(const BitFlags &left, const BitFlags &right) { return left.m_flags == right.m_flags; } 111 | 112 | friend constexpr bool operator!=(const BitFlags &left, const BitFlags &right) { return left.m_flags != right.m_flags; } 113 | 114 | static constexpr BitFlags from_raw(const UnderlyingT flags) { return BitFlags(flags); } 115 | 116 | constexpr UnderlyingT to_raw() const { return m_flags; } 117 | 118 | private: 119 | constexpr explicit BitFlags(const UnderlyingT flags) 120 | : m_flags { flags } 121 | { 122 | } 123 | 124 | private: 125 | UnderlyingT m_flags { 0 }; 126 | }; 127 | -------------------------------------------------------------------------------- /hyper_engine/include/core/filesystem.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace filesystem 13 | { 14 | std::vector read_file(std::string_view path); 15 | } // namespace filesystem 16 | -------------------------------------------------------------------------------- /hyper_engine/include/core/logger.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | 13 | class Logger 14 | { 15 | public: 16 | static void initialize(); 17 | 18 | static std::shared_ptr internal_logger() { return s_internal_logger; }; 19 | 20 | private: 21 | static std::shared_ptr s_internal_logger; 22 | }; 23 | 24 | #define HE_INFO(...) SPDLOG_LOGGER_CALL(::Logger::internal_logger(), spdlog::level::info, __VA_ARGS__) 25 | #define HE_WARN(...) SPDLOG_LOGGER_CALL(::Logger::internal_logger(), spdlog::level::warn, __VA_ARGS__) 26 | #define HE_ERROR(...) SPDLOG_LOGGER_CALL(::Logger::internal_logger(), spdlog::level::err, __VA_ARGS__) 27 | #define HE_CRITICAL(...) SPDLOG_LOGGER_CALL(::Logger::internal_logger(), spdlog::level::critical, __VA_ARGS__) 28 | #define HE_DEBUG(...) SPDLOG_LOGGER_CALL(::Logger::internal_logger(), spdlog::level::debug, __VA_ARGS__) 29 | #define HE_TRACE(...) SPDLOG_LOGGER_CALL(::Logger::internal_logger(), spdlog::level::trace, __VA_ARGS__) 30 | -------------------------------------------------------------------------------- /hyper_engine/include/core/prerequisites.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #define HE_STRINGIFY_HELPER(x) #x 10 | #define HE_STRINGIFY(x) HE_STRINGIFY_HELPER(x) 11 | #define HE_EXPAND_MACRO(x) x 12 | 13 | #ifndef NDEBUG 14 | # define HE_DEBUG_BUILD 1 15 | #else 16 | # define HE_RELEASE_BUILD 1 17 | #endif 18 | 19 | #define HE_BIND_FUNCTION(function) \ 20 | [this](auto &&...args) -> decltype(auto) \ 21 | { \ 22 | return this->function(std::forward(args)...); \ 23 | } 24 | -------------------------------------------------------------------------------- /hyper_engine/include/core/resource_id.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | class ResourceId 12 | { 13 | public: 14 | static constexpr uint64_t s_id_mask { 0xffffffff00000000 }; 15 | static constexpr uint64_t s_id_shift { 32 }; 16 | 17 | static constexpr uint64_t s_version_mask { ~s_id_mask }; 18 | 19 | public: 20 | ResourceId() = default; 21 | 22 | ResourceId::ResourceId(const uint32_t id, const uint32_t version) 23 | : m_id { ((static_cast(id) << s_id_shift) & s_id_mask) 24 | | (static_cast(version) & s_version_mask) } 25 | { 26 | } 27 | 28 | uint32_t id() const { return static_cast((m_id & s_id_mask) >> s_id_shift); } 29 | uint32_t version() const { return static_cast(m_id & s_version_mask); } 30 | 31 | uint64_t get() const { return m_id; } 32 | 33 | private: 34 | uint64_t m_id { 0 }; 35 | }; 36 | 37 | #define HE_DEFINE_ID(name) \ 38 | class name##Id : public ResourceId \ 39 | { \ 40 | public: \ 41 | name##Id() = default; \ 42 | \ 43 | explicit name##Id(const uint32_t id, const uint32_t version) \ 44 | : ResourceId { id, version } \ 45 | { \ 46 | } \ 47 | } 48 | -------------------------------------------------------------------------------- /hyper_engine/include/core/resource_owner.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | #include "core/assertion.hpp" 13 | #include "core/resource_id.hpp" 14 | 15 | template 16 | requires std::derived_from 17 | class ResourceOwner 18 | { 19 | public: 20 | Id create(const T &resource) 21 | { 22 | // FIXME: Replace this with placement new, when adding custom memory pool 23 | const Id id = create_id(); 24 | m_resources.insert({ id.get(), resource }); 25 | 26 | return id; 27 | } 28 | 29 | void destroy(const Id id) 30 | { 31 | HE_ASSERT(contains(id)); 32 | 33 | m_resources.erase(id.get()); 34 | destroy_id(id); 35 | } 36 | 37 | T &get(const Id id) 38 | { 39 | HE_ASSERT(contains(id)); 40 | 41 | return m_resources[id.get()]; 42 | } 43 | 44 | const T &get(const Id id) const 45 | { 46 | HE_ASSERT(contains(id)); 47 | 48 | return m_resources.at(id.get()); 49 | } 50 | 51 | bool contains(const Id id) const 52 | { 53 | const uint64_t internal_id = id.id(); 54 | if (m_ids.size() < internal_id) 55 | { 56 | return false; 57 | } 58 | 59 | return m_ids[internal_id].get() == id.get(); 60 | } 61 | 62 | private: 63 | Id create_id() 64 | { 65 | // 1. Check if there is any unrecyclable id available 66 | if (m_unrecycled_ids == 0) 67 | { 68 | // 2. Create new id based on the size of already created ids 69 | const uint32_t new_id = static_cast(m_ids.size()); 70 | const Id id { new_id, 0 }; 71 | m_ids.push_back(id); 72 | 73 | return id; 74 | } 75 | 76 | // 2. Retrieve the `Id` in the vector at `m_next_unrecycled_id` 77 | const uint32_t current_unrecycled_id = m_next_unrecycled_id; 78 | const Id unrecycled_id = m_ids.at(current_unrecycled_id); 79 | 80 | // 3. Swap the internal id of `m_next_unrecycled_id` and the `Id` pointed by `m_next_unrecycled_id` 81 | m_ids[current_unrecycled_id] = { current_unrecycled_id, unrecycled_id.version() }; 82 | m_next_unrecycled_id = unrecycled_id.id(); 83 | 84 | // 4. Decrease the amount of unrecycled ids 85 | m_unrecycled_ids -= 1; 86 | 87 | return m_ids[current_unrecycled_id]; 88 | } 89 | 90 | void destroy_id(const Id id) 91 | { 92 | // 1. Retrieve the `Id` in the vector at the internal id of `p_id` 93 | const uint32_t internal_id = id.id(); 94 | const Id real_id = m_ids.at(internal_id); 95 | 96 | // 2. Swap the internal id of `m_next_unrecycled_id` and the retrieved `Id` 97 | const uint32_t next_unrecycled_id = m_next_unrecycled_id; 98 | m_ids[internal_id] = { next_unrecycled_id, real_id.version() + 1 }; 99 | m_next_unrecycled_id = real_id.id(); 100 | 101 | // 3. Increase the amount of unrecycled ids 102 | m_unrecycled_ids += 1; 103 | } 104 | 105 | private: 106 | size_t m_unrecycled_ids { 0 }; 107 | uint32_t m_next_unrecycled_id { std::numeric_limits::max() }; 108 | std::vector m_ids {}; 109 | 110 | std::unordered_map m_resources {}; 111 | }; 112 | -------------------------------------------------------------------------------- /hyper_engine/include/core/string_utils.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace string_utils 12 | { 13 | std::wstring to_wstring(const std::string &); 14 | } // namespace string_utils 15 | -------------------------------------------------------------------------------- /hyper_engine/include/drivers/vulkan/vulkan_render_conversion.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include "systems/render/render_types.hpp" 12 | 13 | Format map_vk_format(VkFormat format); 14 | 15 | VkAttachmentLoadOp map_attachment_load_operation(LoadOperation load_operation); 16 | VkAttachmentStoreOp map_attachment_store_operation(StoreOperation store_operation); 17 | 18 | VkBlendFactor map_blend_factor(BlendFactor blend_factor); 19 | VkBlendOp map_blend_operation(BlendOperation blend_operation); 20 | VkBorderColor map_border_color(BorderColor border_color); 21 | VkBufferUsageFlags map_buffer_usage_flags(BitFlags buffer_usage_flags); 22 | 23 | VkColorComponentFlags map_color_component_flags(BitFlags color_writes); 24 | VkCompareOp map_compare_operation(CompareOperation compare_operation); 25 | VkCullModeFlags map_cull_mode_flags(Face face); 26 | 27 | VkFilter map_filter(Filter filter); 28 | VkFormat map_format(Format format); 29 | VkFrontFace map_front_face(FrontFace front_face); 30 | 31 | VkImageAspectFlags map_image_aspect_flags(Format format); 32 | VkImageType map_image_type(Dimension dimension); 33 | VkImageUsageFlags map_image_usage_flags(BitFlags texture_usage_flags, Format format); 34 | VkImageViewType map_image_view_type(Dimension dimension); 35 | 36 | VkPolygonMode map_polygon_mode(PolygonMode polygon_mode); 37 | VkPrimitiveTopology map_primitive_topology(PrimitiveTopology primitive_topology); 38 | 39 | VkSamplerAddressMode map_sampler_address_mode(AddressMode filter); 40 | VkSamplerMipmapMode map_sampler_mipmap_mode(Filter filter); -------------------------------------------------------------------------------- /hyper_engine/include/drivers/vulkan/vulkan_render_driver.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | // clang-format off 12 | #include 13 | #include 14 | // clang-format on 15 | 16 | #include "systems/render/render_driver.hpp" 17 | #include "systems/render/shader_compiler.hpp" 18 | #include "systems/render_system.hpp" 19 | #include "systems/window/window_events.hpp" 20 | 21 | class VulkanRenderDriver final : public RenderDriver 22 | { 23 | private: 24 | static constexpr const char *s_validation_layer = "VK_LAYER_KHRONOS_validation"; 25 | 26 | static constexpr std::array s_device_extensions = { 27 | VK_KHR_SWAPCHAIN_EXTENSION_NAME, 28 | }; 29 | 30 | static constexpr std::array s_descriptor_types = { 31 | VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 32 | VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 33 | VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 34 | VK_DESCRIPTOR_TYPE_SAMPLER, 35 | }; 36 | 37 | static constexpr size_t s_descriptor_count = s_descriptor_types.size(); 38 | static constexpr uint32_t s_descriptor_limit = 1000 * 1000; 39 | 40 | private: 41 | struct VulkanBuffer : Buffer 42 | { 43 | VkBuffer buffer = VK_NULL_HANDLE; 44 | VmaAllocation allocation = VK_NULL_HANDLE; 45 | }; 46 | 47 | struct VulkanShader : Shader 48 | { 49 | VkShaderModule shader_module = VK_NULL_HANDLE; 50 | }; 51 | 52 | struct VulkanSampler : Sampler 53 | { 54 | VkSampler sampler = VK_NULL_HANDLE; 55 | }; 56 | 57 | struct VulkanTexture : Texture 58 | { 59 | VkImage image = VK_NULL_HANDLE; 60 | VmaAllocation allocation = VK_NULL_HANDLE; 61 | VkImageView image_view = VK_NULL_HANDLE; 62 | VkImageLayout image_layout = VK_IMAGE_LAYOUT_UNDEFINED; 63 | }; 64 | 65 | struct VulkanPipelineLayout : PipelineLayout 66 | { 67 | VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; 68 | }; 69 | 70 | struct VulkanComputePipeline : ComputePipeline 71 | { 72 | VkPipeline pipeline = VK_NULL_HANDLE; 73 | }; 74 | 75 | struct VulkanRenderPipeline : RenderPipeline 76 | { 77 | VkPipeline pipeline = VK_NULL_HANDLE; 78 | }; 79 | 80 | struct VulkanCommandBuffer : CommandBuffer 81 | { 82 | VkCommandPool command_pool = VK_NULL_HANDLE; 83 | VkCommandBuffer command_buffer = VK_NULL_HANDLE; 84 | VkFence render_fence = VK_NULL_HANDLE; 85 | VkSemaphore submit_semaphore = VK_NULL_HANDLE; 86 | uint64_t semaphore_counter = 0; 87 | }; 88 | 89 | public: 90 | void initialize(WindowSystem &window_system, WindowId window) override; 91 | void shutdown() override; 92 | 93 | void wait_idle() const override; 94 | 95 | std::vector query_swapchain_textures() override; 96 | 97 | // Buffer 98 | Buffer *create_buffer(const std::optional &label, uint64_t byte_size, BitFlags usage, bool staging) const override; 99 | void destroy_buffer(const Buffer *buffer) const override; 100 | 101 | void *map_buffer(const Buffer *buffer) const override; 102 | void unmap_buffer(const Buffer *buffer) const override; 103 | 104 | // Shader 105 | Shader * 106 | create_shader(const std::optional &label, ShaderType type, std::string_view entry, std::string_view path) const override; 107 | void destroy_shader(const Shader *shader) const override; 108 | 109 | // Sampler 110 | Sampler *create_sampler( 111 | const std::optional &label, 112 | Filter mag_filter, 113 | Filter min_filter, 114 | Filter mipmap_filter, 115 | AddressMode address_mode_u, 116 | AddressMode address_mode_v, 117 | AddressMode address_mode_w, 118 | float mip_lod_bias, 119 | CompareOperation compare_operation, 120 | float min_lod, 121 | float max_lod, 122 | BorderColor border_color) const override; 123 | void destroy_sampler(const Sampler *sampler) const override; 124 | 125 | // Textures 126 | Texture *create_texture( 127 | const std::optional &label, 128 | uint32_t width, 129 | uint32_t height, 130 | uint32_t depth, 131 | uint32_t array_size, 132 | uint32_t mip_levels, 133 | Format format, 134 | Dimension dimension, 135 | BitFlags usage) const override; 136 | void destroy_texture(const Texture *texture) const override; 137 | 138 | // Pipeline Layout 139 | PipelineLayout *create_pipeline_layout(const std::optional &label, size_t push_constant_size) const override; 140 | void destroy_pipeline_layout(const PipelineLayout *pipeline_layout) const override; 141 | 142 | // Compute Pipeline 143 | ComputePipeline * 144 | create_compute_pipeline(const std::optional &label, const PipelineLayout *layout, const Shader *shader) const override; 145 | void destroy_compute_pipeline(const ComputePipeline *compute_pipeline) const override; 146 | 147 | // Render Pipeline 148 | RenderPipeline *create_render_pipeline( 149 | const std::optional &label, 150 | const PipelineLayout *layout, 151 | const Shader *vertex_shader, 152 | const Shader *fragment_shader, 153 | const std::vector &color_attachment_states, 154 | const PrimitiveState &primitive_state, 155 | const DepthStencilState &depth_stencil_state) const override; 156 | void destroy_render_pipeline(const RenderPipeline *render_pipeline) const override; 157 | 158 | // Command Buffer 159 | CommandBuffer *create_command_buffer() const override; 160 | void destroy_command_buffer(const CommandBuffer *command_buffer) const override; 161 | 162 | void acquire_command_buffer(const CommandBuffer *command_buffer) const override; 163 | void submit_command_buffer(CommandBuffer *command_buffer) const override; 164 | 165 | void bind_buffer(const Buffer *buffer) const override; 166 | void bind_sampler(const Sampler *sampler) const override; 167 | void bind_texture(const Texture *texture) const override; 168 | 169 | void copy_buffer_to_buffer( 170 | const CommandBuffer *command_buffer, 171 | const Buffer *src, 172 | uint64_t src_offset, 173 | const Buffer *dst, 174 | uint64_t dst_offset, 175 | size_t size) const override; 176 | void copy_buffer_to_texture( 177 | const CommandBuffer *command_buffer, 178 | const Buffer *src, 179 | uint64_t src_offset, 180 | Texture *dst, 181 | Offset3d dst_offset, 182 | Extent3d dst_extent, 183 | uint32_t dst_mip_level, 184 | uint32_t dst_array_index) const override; 185 | void copy_texture_to_buffer( 186 | const CommandBuffer *command_buffer, 187 | Texture *src, 188 | Offset3d src_offset, 189 | Extent3d src_extent, 190 | uint32_t src_mip_level, 191 | uint32_t src_array_index, 192 | const Buffer *dst, 193 | uint64_t dst_offset) const override; 194 | void copy_texture_to_texture( 195 | const CommandBuffer *command_buffer, 196 | Texture *src, 197 | Offset3d src_offset, 198 | uint32_t src_mip_level, 199 | uint32_t src_array_index, 200 | Texture *dst, 201 | Offset3d dst_offset, 202 | uint32_t dst_mip_level, 203 | uint32_t dst_array_index, 204 | Extent3d extent) const override; 205 | 206 | void push_constants(const CommandBuffer *command_buffer, const PipelineLayout *pipeline_layout, const void *data, size_t size) override; 207 | 208 | std::pair acquire_swapchain_texture(const CommandBuffer *command_buffer) override; 209 | void present() override; 210 | 211 | void begin_gpu_marker(const CommandBuffer *command_buffer, Label label) const override; 212 | void end_gpu_marker(const CommandBuffer *command_buffer) const override; 213 | 214 | // Compute Pass 215 | void begin_compute_pass(const CommandBuffer *command_buffer) const override; 216 | void end_compute_pass(const CommandBuffer *command_buffer) const override; 217 | 218 | void bind_compute_pipeline(const CommandBuffer *command_buffer, const ComputePipeline *pipeline) const override; 219 | 220 | // Render Pass 221 | void begin_render_pass( 222 | const CommandBuffer *command_buffer, 223 | const std::vector &color_attachments, 224 | const std::optional &depth_stencil_attachment) const override; 225 | void end_render_pass(const CommandBuffer *command_buffer) const override; 226 | 227 | void bind_render_pipeline(const CommandBuffer *command_buffer, const RenderPipeline *pipeline) const override; 228 | void bind_index_buffer(const CommandBuffer *command_buffer, const Buffer *buffer) const override; 229 | 230 | void set_viewport(const CommandBuffer *command_buffer, float x, float y, float width, float height, float min_depth, float max_depth) 231 | const override; 232 | void set_scissor(const CommandBuffer *command_buffer, int32_t x, int32_t y, uint32_t width, uint32_t height) const override; 233 | void 234 | draw(const CommandBuffer *command_buffer, uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex, uint32_t first_instance) 235 | const override; 236 | void draw_indexed( 237 | const CommandBuffer *command_buffer, 238 | uint32_t index_count, 239 | uint32_t instance_count, 240 | uint32_t first_index, 241 | int32_t vertex_offset, 242 | uint32_t first_instance) const override; 243 | 244 | private: 245 | void create_instance(); 246 | void create_debug_messenger(); 247 | void choose_physical_device(); 248 | uint32_t rate_physical_device(const VkPhysicalDevice &physical_device) const; 249 | std::optional find_queue_family(const VkPhysicalDevice &physical_device) const; 250 | void create_device(); 251 | void create_allocator(); 252 | 253 | void create_surface(const WindowSystem &window_system, WindowId id); 254 | void create_swapchain(uint32_t width, uint32_t height); 255 | 256 | void recreate_swapchain(); 257 | void destroy_swapchain(); 258 | 259 | void on_resize(const WindowResizeEvent &event); 260 | 261 | void find_descriptor_counts(); 262 | void create_descriptor_pool(); 263 | void create_descriptor_set_layouts(); 264 | void create_descriptor_sets(); 265 | 266 | VkImageView create_internal_image_view(VkImage image, Dimension dimension, Format format, uint32_t mip_levels, uint32_t array_size) const; 267 | 268 | static bool is_validation_layer_supported(); 269 | static bool check_extension_support(const VkPhysicalDevice &physical_device); 270 | static bool check_feature_support(const VkPhysicalDevice &physical_device); 271 | 272 | static VKAPI_ATTR VkBool32 VKAPI_CALL debug_callback( 273 | VkDebugUtilsMessageSeverityFlagBitsEXT message_severity, 274 | VkDebugUtilsMessageTypeFlagsEXT message_type, 275 | const VkDebugUtilsMessengerCallbackDataEXT *callback_data, 276 | void *); 277 | 278 | static void transition_texture_layout( 279 | const CommandBuffer *command_buffer, 280 | Texture *texture, 281 | VkImageLayout new_layout, 282 | uint32_t mip_level, 283 | uint32_t array_index); 284 | 285 | static VkExtent2D choose_extent(uint32_t width, uint32_t height, const VkSurfaceCapabilitiesKHR &capabilities); 286 | static VkSurfaceFormatKHR choose_format(const std::vector &formats); 287 | static VkPresentModeKHR choose_present_mode(const std::vector &present_modes); 288 | 289 | private: 290 | ShaderCompiler m_compiler = ShaderCompiler(ShaderCompiler::CompilerTarget::Spirv); 291 | 292 | bool m_validation_layer_enabled = false; 293 | VkInstance m_instance = VK_NULL_HANDLE; 294 | VkDebugUtilsMessengerEXT m_debug_messenger = VK_NULL_HANDLE; 295 | VkPhysicalDevice m_physical_device = VK_NULL_HANDLE; 296 | VkDevice m_device = VK_NULL_HANDLE; 297 | uint32_t m_queue_family = 0; 298 | VkQueue m_queue = VK_NULL_HANDLE; 299 | VmaAllocator m_allocator = VK_NULL_HANDLE; 300 | 301 | VkSurfaceKHR m_surface = VK_NULL_HANDLE; 302 | VkSwapchainKHR m_swapchain = VK_NULL_HANDLE; 303 | uint32_t m_swapchain_width = 0; 304 | uint32_t m_swapchain_height = 0; 305 | uint32_t m_min_image_count = 0; 306 | uint32_t m_image_count = 0; 307 | VkFormat m_swapchain_format = VK_FORMAT_UNDEFINED; 308 | std::vector m_swapchain_textures; 309 | 310 | bool m_swapchain_out_of_date = false; 311 | uint32_t m_swapchain_texture_index = 0; 312 | 313 | std::array m_descriptor_counts = {}; 314 | 315 | VkDescriptorPool m_descriptor_pool = VK_NULL_HANDLE; 316 | std::array m_descriptor_set_layouts = {}; 317 | std::array m_descriptor_sets = {}; 318 | }; 319 | -------------------------------------------------------------------------------- /hyper_engine/include/engine.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "scene/resources/asset.hpp" 10 | #include "systems/input_system.hpp" 11 | #include "systems/render/camera.hpp" 12 | #include "systems/render_system.hpp" 13 | #include "systems/window_system.hpp" 14 | 15 | class Engine 16 | { 17 | private: 18 | struct GpuMesh 19 | { 20 | size_t start_index = 0; 21 | size_t index_count = 0; 22 | 23 | BufferId material_buffer; 24 | }; 25 | 26 | struct GpuModel 27 | { 28 | glm::mat4 transform = glm::mat4(1.0f); 29 | BufferId model_buffer; 30 | BufferId indices_buffer; 31 | 32 | std::vector meshes; 33 | }; 34 | 35 | public: 36 | void initialize(); 37 | void shutdown() const; 38 | 39 | void run(); 40 | 41 | private: 42 | void fixed_update(float delta_time); 43 | void update(float delta_time); 44 | void render() const; 45 | 46 | void create_pbr(); 47 | void create_skybox(); 48 | void create_grid(); 49 | void create_composition(); 50 | void create_default(); 51 | 52 | std::vector upload_asset(const Asset &asset); 53 | void upload_model( 54 | CommandBufferId command_buffer, 55 | const Asset &asset, 56 | const Asset::Node *node, 57 | const glm::mat4 &parent_transform, 58 | std::vector &models); 59 | 60 | private: 61 | WindowSystem *m_window_system = nullptr; 62 | InputSystem *m_input_system = nullptr; 63 | RenderSystem *m_render_system = nullptr; 64 | 65 | WindowId m_window; 66 | 67 | Camera m_camera = Camera(glm::vec3(0.0f, 0.0f, 3.0f), -90.0f, 0.0f); 68 | BufferId m_camera_buffer; 69 | BufferId m_scene_buffer; 70 | 71 | PipelineLayoutId m_pbr_layout; 72 | RenderPipelineId m_pbr_pipeline; 73 | 74 | PipelineLayoutId m_skybox_layout; 75 | RenderPipelineId m_skybox_pipeline; 76 | TextureId m_skybox_texture; 77 | SamplerId m_skybox_sampler; 78 | 79 | RenderPipelineId m_grid_pipeline; 80 | 81 | PipelineLayoutId m_composition_layout; 82 | RenderPipelineId m_composition_pipeline; 83 | TextureId m_composition_texture; 84 | SamplerId m_composition_sampler; 85 | TextureId m_depth_texture; 86 | 87 | TextureId m_default_texture; 88 | SamplerId m_default_sampler; 89 | 90 | Asset m_sponza; 91 | std::vector m_renderables; 92 | 93 | bool m_running = true; 94 | }; -------------------------------------------------------------------------------- /hyper_engine/include/scene/resources/asset.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include "systems/render/render_types.hpp" 18 | 19 | class Asset 20 | { 21 | public: 22 | struct Sampler 23 | { 24 | Filter mag_filter { Filter::Nearest }; 25 | Filter min_filter { Filter::Nearest }; 26 | }; 27 | 28 | struct Texture 29 | { 30 | uint32_t width { 0 }; 31 | uint32_t height { 0 }; 32 | uint8_t channels { 0 }; 33 | std::vector data {}; 34 | }; 35 | 36 | enum class AlphaMode 37 | { 38 | Opaque, 39 | Transparent, 40 | }; 41 | 42 | struct Material 43 | { 44 | glm::vec4 color_factors { 0.0f }; 45 | std::optional base_color_texture_index { std::nullopt }; 46 | std::optional base_color_sampler_index { std::nullopt }; 47 | 48 | glm::vec2 metallic_roughness_factor { 0.0f }; 49 | std::optional metallic_roughness_texture_index { std::nullopt }; 50 | std::optional metallic_roughness_sampler_index { std::nullopt }; 51 | 52 | std::optional normal_texture_index { std::nullopt }; 53 | std::optional normal_sampler_index { std::nullopt }; 54 | float normal_scale { 1.0f }; 55 | 56 | AlphaMode alpha_mode { AlphaMode::Opaque }; 57 | float alpha_cutoff { 0.0f }; 58 | 59 | bool double_sided { false }; 60 | }; 61 | 62 | struct Mesh 63 | { 64 | size_t start_index { 0 }; 65 | size_t index_count { 0 }; 66 | size_t material_index { 0 }; 67 | }; 68 | 69 | struct Model 70 | { 71 | std::vector positions {}; 72 | std::vector normals {}; 73 | std::vector tangents {}; 74 | std::vector colors {}; 75 | std::vector uvs {}; 76 | std::vector indices {}; 77 | std::vector meshes {}; 78 | }; 79 | 80 | struct Node 81 | { 82 | Node *parent { nullptr }; 83 | std::vector children {}; 84 | 85 | glm::mat4 local_transform { 1.0 }; 86 | std::optional model_index { std::nullopt }; 87 | }; 88 | 89 | struct Scene 90 | { 91 | std::vector node_indices {}; 92 | }; 93 | 94 | public: 95 | Asset() = default; 96 | 97 | static Asset load(std::string_view path); 98 | 99 | std::span samplers() const { return m_samplers; }; 100 | std::span textures() const { return m_textures; }; 101 | std::span materials() const { return m_materials; }; 102 | std::span models() const { return m_models; }; 103 | std::span> nodes() const { return m_nodes; }; 104 | std::span scenes() const { return m_scenes; } 105 | 106 | private: 107 | Asset::Asset( 108 | std::vector samplers, 109 | std::vector textures, 110 | std::vector materials, 111 | std::vector models, 112 | std::vector> nodes, 113 | std::vector scenes) 114 | : m_samplers(std::move(samplers)) 115 | , m_textures(std::move(textures)) 116 | , m_materials(std::move(materials)) 117 | , m_models(std::move(models)) 118 | , m_nodes(std::move(nodes)) 119 | , m_scenes(std::move(scenes)) 120 | { 121 | } 122 | 123 | private: 124 | std::vector m_samplers {}; 125 | std::vector m_textures {}; 126 | std::vector m_materials {}; 127 | std::vector m_models {}; 128 | std::vector> m_nodes {}; 129 | std::vector m_scenes {}; 130 | }; 131 | -------------------------------------------------------------------------------- /hyper_engine/include/systems/input_system.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "systems/window/key_events.hpp" 10 | #include "systems/window/mouse_events.hpp" 11 | #include "systems/window_system.hpp" 12 | 13 | class InputSystem 14 | { 15 | public: 16 | void initialize(WindowSystem &); 17 | 18 | // Keys 19 | bool is_key_pressed(KeyCode) const; 20 | 21 | // Mouse 22 | bool is_mouse_button_pressed(MouseCode) const; 23 | glm::vec2 mouse_position() const { return m_mouse_position; } 24 | 25 | private: 26 | void on_mouse_move(const MouseMoveEvent &event); 27 | void on_mouse_button_press(const MouseButtonPressEvent &event); 28 | void on_mouse_button_release(const MouseButtonReleaseEvent &event); 29 | void on_key_press(const KeyPressEvent &event); 30 | void on_key_release(const KeyReleaseEvent &event); 31 | 32 | private: 33 | std::unordered_map m_keys {}; 34 | std::unordered_map m_mouse_buttons {}; 35 | glm::vec2 m_mouse_position { 0.0f, 0.0f }; 36 | }; 37 | -------------------------------------------------------------------------------- /hyper_engine/include/systems/render/camera.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | class Camera 12 | { 13 | public: 14 | enum class Movement 15 | { 16 | Forward, 17 | Backward, 18 | Left, 19 | Right, 20 | }; 21 | 22 | public: 23 | Camera(glm::vec3 position, float yaw, float pitch); 24 | 25 | void process_keyboard(Movement, float delta_time); 26 | void process_mouse_movement(float x_position, float y_position, bool mouse_button_pressed); 27 | void process_mouse_scroll(float y_offset); 28 | 29 | void set_aspect_ratio(const float aspect_ratio) { m_aspect_ratio = aspect_ratio; }; 30 | 31 | glm::vec3 position() const { return m_position; } 32 | 33 | float near_plane() const { return m_near; } 34 | float far_plane() const { return m_far; }; 35 | 36 | glm::mat4 projection_matrix() const; 37 | glm::mat4 view_matrix() const; 38 | 39 | private: 40 | void update_camera_vectors(); 41 | 42 | private: 43 | glm::vec3 m_position { 0.0f, 0.0f, 0.0f }; 44 | glm::vec3 m_front { 0.0f, 0.0f, 0.0f }; 45 | glm::vec3 m_up { 0.0f, 0.0f, 0.0f }; 46 | glm::vec3 m_right { 0.0f, 0.0f, 0.0f }; 47 | 48 | float m_yaw { 0.0f }; 49 | float m_pitch { 0.0f }; 50 | 51 | float m_movement_speed { 2.5f }; 52 | float m_mouse_sensitivity { 0.1f }; 53 | float m_fov { 90.0f }; 54 | 55 | float m_near { 0.01f }; 56 | float m_far { 1000.0f }; 57 | float m_aspect_ratio { 1280.0f / 720.0f }; 58 | 59 | bool m_first_mouse { true }; 60 | float m_last_x { 0.0f }; 61 | float m_last_y { 0.0f }; 62 | }; 63 | -------------------------------------------------------------------------------- /hyper_engine/include/systems/render/render_driver.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include "systems/render/render_types.hpp" 12 | #include "systems/render/resource_handle.hpp" 13 | #include "systems/window_system.hpp" 14 | 15 | struct Buffer 16 | { 17 | std::optional label; 18 | size_t size = 0; 19 | BitFlags usage = BufferUsage::None; 20 | std::optional handle = std::nullopt; 21 | }; 22 | 23 | struct Shader 24 | { 25 | std::optional label; 26 | ShaderType type = ShaderType::None; 27 | std::string entry; 28 | std::string path; 29 | }; 30 | 31 | struct Sampler 32 | { 33 | std::optional label; 34 | Filter mag_filter = Filter::Linear; 35 | Filter min_filter = Filter::Linear; 36 | Filter mipmap_filter = Filter::Linear; 37 | AddressMode address_mode_u = AddressMode::ClampToEdge; 38 | AddressMode address_mode_v = AddressMode::ClampToEdge; 39 | AddressMode address_mode_w = AddressMode::ClampToEdge; 40 | float mip_lod_bias = 0.0; 41 | CompareOperation compare_operation = CompareOperation::Less; 42 | float min_lod = 0.0; 43 | float max_lod = 1.0; 44 | BorderColor border_color = BorderColor::TransparentBlack; 45 | std::optional handle = std::nullopt; 46 | }; 47 | 48 | struct Texture 49 | { 50 | std::optional label; 51 | uint32_t width = 1; 52 | uint32_t height = 1; 53 | uint32_t depth = 1; 54 | uint32_t array_size = 1; 55 | uint32_t mip_levels = 1; 56 | Format format = Format::Unknown; 57 | Dimension dimension = Dimension::Unknown; 58 | BitFlags usage = TextureUsage::None; 59 | std::optional handle = std::nullopt; 60 | }; 61 | 62 | struct PipelineLayout 63 | { 64 | std::optional label; 65 | size_t push_constant_size = 0; 66 | }; 67 | 68 | struct ComputePipeline 69 | { 70 | std::optional label; 71 | PipelineLayout *layout = nullptr; 72 | Shader *shader = nullptr; 73 | }; 74 | 75 | struct RenderPipeline 76 | { 77 | std::optional label; 78 | PipelineLayout *layout; 79 | Shader *vertex_shader; 80 | Shader *fragment_shader; 81 | std::vector color_attachment_states; 82 | PrimitiveState primitive_state; 83 | DepthStencilState depth_stencil_state; 84 | }; 85 | 86 | struct CommandBuffer 87 | { 88 | uint32_t generation = 0; 89 | bool compute_pass_in_progress = false; 90 | bool render_pass_in_progress = false; 91 | bool swapchain_texture_acquired = false; 92 | }; 93 | 94 | struct ComputePass 95 | { 96 | CommandBuffer *command_buffer = nullptr; 97 | ComputePipeline *compute_pipeline = nullptr; 98 | bool has_label = false; 99 | bool ended = false; 100 | }; 101 | 102 | struct RenderPassColorAttachment 103 | { 104 | Texture *texture = nullptr; 105 | Operations operations = {}; 106 | }; 107 | 108 | struct RenderPassDepthStencilAttachment 109 | { 110 | Texture *texture = nullptr; 111 | Operations depth_operations = {}; 112 | }; 113 | 114 | struct RenderPass 115 | { 116 | CommandBuffer *command_buffer = nullptr; 117 | RenderPipeline *render_pipeline = nullptr; 118 | bool has_label = false; 119 | bool ended = false; 120 | }; 121 | 122 | class RenderDriver 123 | { 124 | public: 125 | virtual ~RenderDriver() = default; 126 | 127 | virtual void initialize(WindowSystem &window_system, WindowId window) = 0; 128 | virtual void shutdown() = 0; 129 | 130 | virtual void wait_idle() const = 0; 131 | 132 | virtual std::vector query_swapchain_textures() = 0; 133 | 134 | // Buffer 135 | virtual Buffer *create_buffer(const std::optional &label, size_t size, BitFlags usage, bool staging) const = 0; 136 | virtual void destroy_buffer(const Buffer *buffer) const = 0; 137 | 138 | virtual void *map_buffer(const Buffer *buffer) const = 0; 139 | virtual void unmap_buffer(const Buffer *buffer) const = 0; 140 | 141 | // Shader 142 | virtual Shader * 143 | create_shader(const std::optional &label, ShaderType type, std::string_view entry, std::string_view path) const = 0; 144 | virtual void destroy_shader(const Shader *shader) const = 0; 145 | 146 | // Sampler 147 | virtual Sampler *create_sampler( 148 | const std::optional &label, 149 | Filter mag_filter, 150 | Filter min_filter, 151 | Filter mipmap_filter, 152 | AddressMode address_mode_u, 153 | AddressMode address_mode_v, 154 | AddressMode address_mode_w, 155 | float mip_lod_bias, 156 | CompareOperation compare_operation, 157 | float min_lod, 158 | float max_lod, 159 | BorderColor border_color) const = 0; 160 | virtual void destroy_sampler(const Sampler *sampler) const = 0; 161 | 162 | // Textures 163 | virtual Texture *create_texture( 164 | const std::optional &label, 165 | uint32_t width, 166 | uint32_t height, 167 | uint32_t depth, 168 | uint32_t array_size, 169 | uint32_t mip_levels, 170 | Format format, 171 | Dimension dimension, 172 | BitFlags usage) const = 0; 173 | virtual void destroy_texture(const Texture *texture) const = 0; 174 | 175 | // Pipeline Layout 176 | virtual PipelineLayout *create_pipeline_layout(const std::optional &label, size_t push_constant_size) const = 0; 177 | virtual void destroy_pipeline_layout(const PipelineLayout *pipeline_layout) const = 0; 178 | 179 | // Compute Pipeline 180 | virtual ComputePipeline * 181 | create_compute_pipeline(const std::optional &label, const PipelineLayout *layout, const Shader *shader) const = 0; 182 | virtual void destroy_compute_pipeline(const ComputePipeline *compute_pipeline) const = 0; 183 | 184 | // Render Pipeline 185 | virtual RenderPipeline *create_render_pipeline( 186 | const std::optional &label, 187 | const PipelineLayout *layout, 188 | const Shader *vertex_shader, 189 | const Shader *fragment_shader, 190 | const std::vector &color_attachment_states, 191 | const PrimitiveState &primitive_state, 192 | const DepthStencilState &depth_stencil_state) const = 0; 193 | virtual void destroy_render_pipeline(const RenderPipeline *render_pipeline) const = 0; 194 | 195 | // Command Buffer 196 | virtual CommandBuffer *create_command_buffer() const = 0; 197 | virtual void destroy_command_buffer(const CommandBuffer *command_buffer) const = 0; 198 | 199 | virtual void acquire_command_buffer(const CommandBuffer *command_buffer) const = 0; 200 | virtual void submit_command_buffer(CommandBuffer *command_buffer) const = 0; 201 | 202 | virtual void bind_buffer(const Buffer *buffer) const = 0; 203 | virtual void bind_sampler(const Sampler *sampler) const = 0; 204 | virtual void bind_texture(const Texture *texture) const = 0; 205 | 206 | virtual void copy_buffer_to_buffer( 207 | const CommandBuffer *command_buffer, 208 | const Buffer *src, 209 | uint64_t src_offset, 210 | const Buffer *dst, 211 | uint64_t dst_offset, 212 | size_t size) const = 0; 213 | virtual void copy_buffer_to_texture( 214 | const CommandBuffer *command_buffer, 215 | const Buffer *src, 216 | uint64_t src_offset, 217 | Texture *dst, 218 | Offset3d dst_offset, 219 | Extent3d dst_extent, 220 | uint32_t dst_mip_level, 221 | uint32_t dst_array_index) const = 0; 222 | virtual void copy_texture_to_buffer( 223 | const CommandBuffer *command_buffer, 224 | Texture *src, 225 | Offset3d src_offset, 226 | Extent3d src_extent, 227 | uint32_t src_mip_level, 228 | uint32_t src_array_index, 229 | const Buffer *dst, 230 | uint64_t dst_offset) const = 0; 231 | virtual void copy_texture_to_texture( 232 | const CommandBuffer *command_buffer, 233 | Texture *src, 234 | Offset3d src_offset, 235 | uint32_t src_mip_level, 236 | uint32_t src_array_index, 237 | Texture *dst, 238 | Offset3d dst_offset, 239 | uint32_t dst_mip_level, 240 | uint32_t dst_array_index, 241 | Extent3d extent) const = 0; 242 | 243 | virtual void push_constants(const CommandBuffer *command_buffer, const PipelineLayout *pipeline_layout, const void *data, size_t size) = 0; 244 | 245 | virtual std::pair acquire_swapchain_texture(const CommandBuffer *command_buffer) = 0; 246 | virtual void present() = 0; 247 | 248 | virtual void begin_gpu_marker(const CommandBuffer *command_buffer, Label label) const = 0; 249 | virtual void end_gpu_marker(const CommandBuffer *command_buffer) const = 0; 250 | 251 | // Compute Pass 252 | virtual void begin_compute_pass(const CommandBuffer *command_buffer) const = 0; 253 | virtual void end_compute_pass(const CommandBuffer *command_buffer) const = 0; 254 | 255 | virtual void bind_compute_pipeline(const CommandBuffer *command_buffer, const ComputePipeline *pipeline) const = 0; 256 | 257 | // Render Pass 258 | virtual void begin_render_pass( 259 | const CommandBuffer *command_buffer, 260 | const std::vector &color_attachments, 261 | const std::optional &depth_stencil_attachment) const = 0; 262 | virtual void end_render_pass(const CommandBuffer *command_buffer) const = 0; 263 | 264 | virtual void bind_render_pipeline(const CommandBuffer *command_buffer, const RenderPipeline *pipeline) const = 0; 265 | virtual void bind_index_buffer(const CommandBuffer *command_buffer, const Buffer *buffer) const = 0; 266 | 267 | virtual void set_viewport(const CommandBuffer *command_buffer, float x, float y, float width, float height, float min_depth, float max_depth) 268 | const = 0; 269 | virtual void set_scissor(const CommandBuffer *command_buffer, int32_t x, int32_t y, uint32_t width, uint32_t height) const = 0; 270 | virtual void 271 | draw(const CommandBuffer *command_buffer, uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex, uint32_t first_instance) 272 | const = 0; 273 | virtual void draw_indexed( 274 | const CommandBuffer *command_buffer, 275 | uint32_t index_count, 276 | uint32_t instance_count, 277 | uint32_t first_index, 278 | int32_t vertex_offset, 279 | uint32_t first_instance) const = 0; 280 | }; -------------------------------------------------------------------------------- /hyper_engine/include/systems/render/render_types.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include "core/bit_flags.hpp" 12 | 13 | enum class BufferUsage : uint8_t 14 | { 15 | None = 0, 16 | Index = 1 << 0, 17 | Indirect = 1 << 1, 18 | Storage = 1 << 2, 19 | ShaderResource = 1 << 3, 20 | }; 21 | 22 | enum class ShaderType : uint8_t 23 | { 24 | None, 25 | Compute, 26 | Fragment, 27 | Vertex 28 | }; 29 | 30 | enum class Filter : uint8_t 31 | { 32 | Nearest, 33 | Linear, 34 | }; 35 | 36 | enum class AddressMode : uint8_t 37 | { 38 | Repeat, 39 | MirroredRepeat, 40 | ClampToEdge, 41 | ClampToBorder, 42 | MirrorClampToEdge 43 | }; 44 | 45 | enum class CompareOperation : uint8_t 46 | { 47 | Never, 48 | Less, 49 | Equal, 50 | LessEqual, 51 | Greater, 52 | NotEqual, 53 | GreaterEqual, 54 | Always, 55 | }; 56 | 57 | enum class BorderColor : uint8_t 58 | { 59 | TransparentBlack, 60 | OpaqueBlack, 61 | OpaqueWhite, 62 | }; 63 | 64 | enum class Format : uint8_t 65 | { 66 | Unknown, 67 | 68 | R8Unorm, 69 | R8Snorm, 70 | R8Uint, 71 | R8Sint, 72 | R8Srgb, 73 | 74 | Rg8Unorm, 75 | Rg8Snorm, 76 | Rg8Uint, 77 | Rg8Sint, 78 | Rg8Srgb, 79 | 80 | Rgb8Unorm, 81 | Rgb8Snorm, 82 | Rgb8Uint, 83 | Rgb8Sint, 84 | Rgb8Srgb, 85 | 86 | Bgr8Unorm, 87 | Bgr8Snorm, 88 | Bgr8Uint, 89 | Bgr8Sint, 90 | Bgr8Srgb, 91 | 92 | Rgba8Unorm, 93 | Rgba8Snorm, 94 | Rgba8Uint, 95 | Rgba8Sint, 96 | Rgba8Srgb, 97 | 98 | Bgra8Unorm, 99 | Bgra8Snorm, 100 | Bgra8Uint, 101 | Bgra8Sint, 102 | Bgra8Srgb, 103 | 104 | R16Unorm, 105 | R16Snorm, 106 | R16Uint, 107 | R16Sint, 108 | R16Sfloat, 109 | 110 | Rg16Unorm, 111 | Rg16Snorm, 112 | Rg16Uint, 113 | Rg16Sint, 114 | Rg16Sfloat, 115 | 116 | Rgb16Unorm, 117 | Rgb16Snorm, 118 | Rgb16Uint, 119 | Rgb16Sint, 120 | Rgb16Sfloat, 121 | 122 | Rgba16Unorm, 123 | Rgba16Snorm, 124 | Rgba16Uint, 125 | Rgba16Sint, 126 | Rgba16Sfloat, 127 | 128 | R32Uint, 129 | R32Sint, 130 | R32Sfloat, 131 | 132 | Rg32Uint, 133 | Rg32Sint, 134 | Rg32Sfloat, 135 | 136 | Rgb32Uint, 137 | Rgb32Sint, 138 | Rgb32Sfloat, 139 | 140 | Rgba32Uint, 141 | Rgba32Sint, 142 | Rgba32Sfloat, 143 | 144 | R64Uint, 145 | R64Sint, 146 | R64Sfloat, 147 | 148 | Rg64Uint, 149 | Rg64Sint, 150 | Rg64Sfloat, 151 | 152 | Rgb64Uint, 153 | Rgb64Sint, 154 | Rgb64Sfloat, 155 | 156 | Rgba64Uint, 157 | Rgba64Sint, 158 | Rgba64Sfloat, 159 | 160 | D16Unorm, 161 | D32Sfloat, 162 | S8Uint, 163 | D16UnormS8Uint, 164 | D24UnormS8Uint, 165 | D32SfloatS8Uint 166 | }; 167 | 168 | enum class Dimension : uint8_t 169 | { 170 | Unknown, 171 | Texture1D, 172 | Texture1DArray, 173 | Texture2D, 174 | Texture2DArray, 175 | Texture3D, 176 | TextureCube, 177 | }; 178 | 179 | enum class TextureUsage : uint8_t 180 | { 181 | None = 0, 182 | Storage = 1 << 0, 183 | RenderAttachment = 1 << 1, 184 | ShaderResource = 1 << 2, 185 | }; 186 | 187 | enum class BlendFactor : uint8_t 188 | { 189 | Zero, 190 | One, 191 | SrcColor, 192 | OneMinusSrcColor, 193 | DstColor, 194 | OneMinusDstColor, 195 | SrcAlpha, 196 | OneMinusSrcAlpha, 197 | DstAlpha, 198 | OneMinusDstAlpha, 199 | ConstantColor, 200 | OneMinusConstantColor, 201 | ConstantAlpha, 202 | OneMinusConstantAlpha, 203 | SrcAlphaSaturate, 204 | Src1Color, 205 | OneMinusSrc1Color, 206 | Src1Alpha, 207 | OneMinusSrc1Alpha, 208 | }; 209 | 210 | enum class BlendOperation : uint8_t 211 | { 212 | Add, 213 | Subtract, 214 | ReverseSubtract, 215 | Min, 216 | Max, 217 | }; 218 | 219 | enum class ColorWrites : uint8_t 220 | { 221 | R = 1 << 0, 222 | G = 1 << 1, 223 | B = 1 << 2, 224 | A = 1 << 3, 225 | Color = R | G | B, 226 | All = R | G | B | A, 227 | }; 228 | 229 | struct BlendState 230 | { 231 | bool blend_enable = false; 232 | BlendFactor src_blend_factor = BlendFactor::One; 233 | BlendFactor dst_blend_factor = BlendFactor::Zero; 234 | BlendOperation operation = BlendOperation::Add; 235 | BlendFactor alpha_src_blend_factor = BlendFactor::One; 236 | BlendFactor alpha_dst_blend_factor = BlendFactor::Zero; 237 | BlendOperation alpha_operation = BlendOperation::Add; 238 | BitFlags color_writes = ColorWrites::All; 239 | }; 240 | 241 | struct ColorAttachmentState 242 | { 243 | Format format = Format::Unknown; 244 | BlendState blend_state = {}; 245 | }; 246 | 247 | enum class PrimitiveTopology : uint8_t 248 | { 249 | PointList, 250 | LineList, 251 | LineStrip, 252 | TriangleList, 253 | TriangleStrip, 254 | TriangleFan, 255 | }; 256 | 257 | enum class FrontFace : uint8_t 258 | { 259 | CounterClockwise, 260 | Clockwise, 261 | }; 262 | 263 | enum class Face : uint8_t 264 | { 265 | None, 266 | Front, 267 | Back 268 | }; 269 | 270 | enum class PolygonMode : uint8_t 271 | { 272 | Fill, 273 | Line, 274 | Point, 275 | }; 276 | 277 | struct PrimitiveState 278 | { 279 | PrimitiveTopology topology = PrimitiveTopology::TriangleList; 280 | FrontFace front_face = FrontFace::CounterClockwise; 281 | Face cull_mode = Face::None; 282 | PolygonMode polygon_mode = PolygonMode::Fill; 283 | }; 284 | 285 | struct DepthBiasState 286 | { 287 | bool depth_bias_enable = false; 288 | float constant = 0.0f; 289 | float clamp = 0.0f; 290 | float slope = 0.0f; 291 | }; 292 | 293 | struct DepthStencilState 294 | { 295 | bool depth_test_enable = false; 296 | bool depth_write_enable = false; 297 | Format depth_format = Format::Unknown; 298 | CompareOperation depth_compare_operation = CompareOperation::Less; 299 | DepthBiasState depth_bias_state; 300 | }; 301 | 302 | struct LabelColor 303 | { 304 | uint8_t r = 255; 305 | uint8_t g = 255; 306 | uint8_t b = 255; 307 | }; 308 | 309 | struct Label 310 | { 311 | std::string name; 312 | LabelColor color; 313 | }; 314 | 315 | enum class LoadOperation : uint8_t 316 | { 317 | Clear, 318 | Load, 319 | DontCare, 320 | }; 321 | 322 | enum class StoreOperation : uint8_t 323 | { 324 | None, 325 | Store, 326 | DontCare, 327 | }; 328 | 329 | struct Operations 330 | { 331 | LoadOperation load_operation = LoadOperation::Clear; 332 | StoreOperation store_operation = StoreOperation::Store; 333 | }; 334 | 335 | struct SubresourceRange 336 | { 337 | uint32_t base_mip_level = 0; 338 | uint32_t mip_level_count = 1; 339 | uint32_t base_array_level = 0; 340 | uint32_t array_layer_count = 1; 341 | }; 342 | 343 | struct Extent3d 344 | { 345 | uint32_t width = 0; 346 | uint32_t height = 0; 347 | uint32_t depth = 0; 348 | }; 349 | 350 | struct Offset3d 351 | { 352 | int32_t x = 0; 353 | int32_t y = 0; 354 | int32_t z = 0; 355 | }; -------------------------------------------------------------------------------- /hyper_engine/include/systems/render/resource_handle.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | class ResourceHandle 12 | { 13 | public: 14 | explicit ResourceHandle::ResourceHandle(const uint32_t handle) 15 | : m_handle(handle) 16 | { 17 | } 18 | 19 | bool is_valid() const { return m_handle != 0xffffffff; } 20 | uint32_t handle() const { return m_handle; } 21 | 22 | private: 23 | uint32_t m_handle { 0xffffffff }; 24 | }; 25 | -------------------------------------------------------------------------------- /hyper_engine/include/systems/render/shader_compiler.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | // clang-format off 14 | #include 15 | #include 16 | // clang-format on 17 | 18 | #include "systems/render_system.hpp" 19 | 20 | struct ShaderCompilationDescriptor 21 | { 22 | std::string entry_name { "main" }; 23 | ShaderType type { ShaderType::None }; 24 | std::vector data {}; 25 | }; 26 | 27 | class ShaderCompiler 28 | { 29 | public: 30 | enum class CompilerTarget 31 | { 32 | Dxil, 33 | Spirv, 34 | }; 35 | 36 | private: 37 | static constexpr std::array s_compiler_args = { 38 | L"-HV", 39 | L"2021", 40 | L"-Zpc", 41 | L"-O3", 42 | }; 43 | 44 | static constexpr std::array s_spirv_args = { 45 | L"-D", 46 | L"HE_VULKAN=1", 47 | L"-spirv", 48 | L"-fvk-use-dx-position-w", 49 | }; 50 | 51 | public: 52 | explicit ShaderCompiler(const CompilerTarget &); 53 | 54 | std::vector compile(const ShaderCompilationDescriptor &) const; 55 | 56 | private: 57 | CompilerTarget m_compiler_target { CompilerTarget::Spirv }; 58 | Microsoft::WRL::ComPtr m_compiler { nullptr }; 59 | Microsoft::WRL::ComPtr m_utils { nullptr }; 60 | }; 61 | -------------------------------------------------------------------------------- /hyper_engine/include/systems/render_system.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025-present, SkillerRaptor 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "core/bit_flags.hpp" 14 | #include "core/resource_owner.hpp" 15 | #include "systems/render/render_types.hpp" 16 | #include "systems/render/resource_handle.hpp" 17 | #include "systems/window_system.hpp" 18 | 19 | HE_DEFINE_ID(Buffer); 20 | HE_DEFINE_ID(Shader); 21 | HE_DEFINE_ID(Sampler); 22 | HE_DEFINE_ID(Texture); 23 | HE_DEFINE_ID(PipelineLayout); 24 | HE_DEFINE_ID(ComputePipeline); 25 | HE_DEFINE_ID(RenderPipeline); 26 | HE_DEFINE_ID(CommandBuffer); 27 | HE_DEFINE_ID(ComputePass); 28 | HE_DEFINE_ID(RenderPass); 29 | 30 | struct BufferDescriptor 31 | { 32 | std::optional label; 33 | size_t size = 0; 34 | BitFlags usage = BufferUsage::None; 35 | std::optional handle; 36 | }; 37 | 38 | struct ShaderDescriptor 39 | { 40 | std::optional label; 41 | ShaderType type = ShaderType::None; 42 | std::string entry; 43 | std::string path; 44 | }; 45 | 46 | struct SamplerDescriptor 47 | { 48 | std::optional label; 49 | Filter mag_filter = Filter::Linear; 50 | Filter min_filter = Filter::Linear; 51 | Filter mipmap_filter = Filter::Linear; 52 | AddressMode address_mode_u = AddressMode::ClampToEdge; 53 | AddressMode address_mode_v = AddressMode::ClampToEdge; 54 | AddressMode address_mode_w = AddressMode::ClampToEdge; 55 | float mip_lod_bias = 0.0; 56 | CompareOperation compare_operation = CompareOperation::Less; 57 | float min_lod = 0.0; 58 | float max_lod = 1.0; 59 | BorderColor border_color = BorderColor::TransparentBlack; 60 | std::optional handle; 61 | }; 62 | 63 | struct TextureDescriptor 64 | { 65 | std::optional label; 66 | uint32_t width = 1; 67 | uint32_t height = 1; 68 | uint32_t depth = 1; 69 | uint32_t array_size = 1; 70 | uint32_t mip_levels = 1; 71 | Format format = Format::Unknown; 72 | Dimension dimension = Dimension::Unknown; 73 | BitFlags usage = TextureUsage::None; 74 | std::optional handle; 75 | }; 76 | 77 | struct PipelineLayoutDescriptor 78 | { 79 | std::optional label; 80 | size_t push_constant_size = 0; 81 | }; 82 | 83 | struct ComputePipelineDescriptor 84 | { 85 | std::optional label; 86 | PipelineLayoutId layout; 87 | ShaderId shader; 88 | }; 89 | 90 | struct RenderPipelineDescriptor 91 | { 92 | std::optional label; 93 | PipelineLayoutId layout; 94 | ShaderId vertex_shader; 95 | ShaderId fragment_shader; 96 | std::vector color_attachment_states; 97 | PrimitiveState primitive_state; 98 | DepthStencilState depth_stencil_state; 99 | }; 100 | 101 | struct BufferTarget 102 | { 103 | BufferId buffer; 104 | uint64_t offset = 0; 105 | }; 106 | 107 | struct TextureTarget 108 | { 109 | TextureId texture; 110 | Offset3d offset = {}; 111 | Extent3d extent = {}; 112 | uint32_t mip_level = 0; 113 | uint32_t array_index = 0; 114 | }; 115 | 116 | struct ComputePassDescriptor 117 | { 118 | std::optional