diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..dcf16f8 --- /dev/null +++ b/.clang-format @@ -0,0 +1,244 @@ +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterExternBlock: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakArrays: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: Attach +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +KeepEmptyLinesAtEOF: false +LambdaBodyIndentation: Signature +LineEnding: DeriveLF +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +PPIndentWidth: -1 +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseTab: Never +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE +... + diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..e69de29 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e41f858 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vcpkg"] + path = vcpkg + url = https://github.com/Microsoft/vcpkg.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 5384cca..d6f896c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,9 @@ if(${CMAKE_VERSION} VERSION_LESS 3.12) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) endif() set(CMAKE_CXX_STANDARD 20) +set(VCPKG_INSTALL_OPTIONS "--allow-unsupported") + +set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake) project(MeshShadingDemo) @@ -24,7 +27,14 @@ find_package(Ktx CONFIG REQUIRED) find_package(nlohmann_json CONFIG REQUIRED) find_package(fmt CONFIG REQUIRED) find_package(VulkanMemoryAllocator CONFIG REQUIRED) +find_package(glslang CONFIG REQUIRED) find_package(Seele REQUIRED) -add_library(MeshShadingDemo main.cpp) +add_library(MeshShadingDemo SHARED "") target_link_libraries(MeshShadingDemo PUBLIC Seele::Engine) + +target_include_directories(MeshShadingDemo PRIVATE src/) + +target_compile_definitions(MeshShadingDemo PRIVATE BUILD_DLL) + +add_subdirectory(src/) diff --git a/import/models/cube.fbx b/import/models/cube.fbx new file mode 100644 index 0000000..0c8add8 Binary files /dev/null and b/import/models/cube.fbx differ diff --git a/import/models/cubeMaterial0.json b/import/models/cubeMaterial0.json new file mode 100644 index 0000000..b886006 --- /dev/null +++ b/import/models/cubeMaterial0.json @@ -0,0 +1,22 @@ +{ + "code": [ + { + "exp": "Const", + "value": "input.vertexColor.xyz" + }, + { + "exp": "Const", + "value": "float3(0, 0, 1)" + }, + { + "exp": "BRDF", + "profile": "CelShading", + "values": { + "baseColor": 0, + "normal": 1 + } + } + ], + "name": "cubeMaterial0", + "profile": "CelShading" +} \ No newline at end of file diff --git a/src/Actor/CMakeLists.txt b/src/Actor/CMakeLists.txt new file mode 100644 index 0000000..53ff0be --- /dev/null +++ b/src/Actor/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(MeshShadingDemo + PUBLIC + FlyCam.h + FlyCam.cpp) \ No newline at end of file diff --git a/src/Actor/FlyCam.cpp b/src/Actor/FlyCam.cpp new file mode 100644 index 0000000..a1391d3 --- /dev/null +++ b/src/Actor/FlyCam.cpp @@ -0,0 +1,21 @@ +#include "FlyCam.h" + +FlyCam::FlyCam(PScene scene) + : Actor(scene) +{ + attachComponent().mainCamera = true; + attachComponent(); +} + +FlyCam::~FlyCam() +{} + +Component::Camera& FlyCam::getCamera() +{ + return accessComponent(); +} + +Component::KeyboardInput& FlyCam::getKeyboardInput() +{ + return accessComponent(); +} \ No newline at end of file diff --git a/src/Actor/FlyCam.h b/src/Actor/FlyCam.h new file mode 100644 index 0000000..1975890 --- /dev/null +++ b/src/Actor/FlyCam.h @@ -0,0 +1,17 @@ +#pragma once +#include "Define.h" +#include "Seele/MinimalEngine.h" +#include +#include +#include + +class FlyCam : public Actor +{ +public: + FlyCam(PScene scene); + virtual ~FlyCam(); + Component::KeyboardInput& getKeyboardInput(); + Component::Camera& getCamera(); +private: +}; +DEFINE_REF(FlyCam) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..b9a2e61 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,8 @@ +target_sources(MeshShadingDemo + PUBLIC + Define.h + MeshShadingDemoGame.h + MeshShadingDemoGame.cpp) + +add_subdirectory(Actor/) +add_subdirectory(System/) diff --git a/src/Define.h b/src/Define.h new file mode 100644 index 0000000..77727e0 --- /dev/null +++ b/src/Define.h @@ -0,0 +1,14 @@ +#pragma once +#include "Seele/MinimalEngine.h" + +using namespace Seele; + +#ifdef WIN32 +#ifdef BUILD_DLL +#define MESHSHADINGDEMO_API __declspec(dllexport) +#else +#define MESHSHADINGDEMO_API __declspec(dllimport) +#endif +#else +#define MESHSHADINGDEMO_API +#endif \ No newline at end of file diff --git a/src/MeshShadingDemoGame.cpp b/src/MeshShadingDemoGame.cpp new file mode 100644 index 0000000..c13a679 --- /dev/null +++ b/src/MeshShadingDemoGame.cpp @@ -0,0 +1,32 @@ +#include "MeshShadingDemoGame.h" +#include "Actor/FlyCam.h" +#include "Seele/Asset/AssetRegistry.h" +#include "Seele/Component/Transform.h" +#include "System/FlyCamSystem.h" + +MeshShadingDemoGame::MeshShadingDemoGame() +{ +} + +MeshShadingDemoGame::~MeshShadingDemoGame() +{ +} + +void MeshShadingDemoGame::setupScene(PScene scene, PSystemGraph graph) +{ + cube = new StaticMeshActor(scene, AssetRegistry::findMesh("cube")); + // cube->accessComponent().setScale(Vector(50, 50, 50)); + camera = new FlyCam(scene); + light = new DirectionalLightActor(scene, Vector4(1, 1, 1, 1), Vector(0, -1, 0)); + graph->addSystem(new FlyCamSystem(scene)); +} + +Game* createInstance() +{ + return new MeshShadingDemoGame(); +} + +void destroyInstance(Game *game) +{ + delete game; +} \ No newline at end of file diff --git a/src/MeshShadingDemoGame.h b/src/MeshShadingDemoGame.h new file mode 100644 index 0000000..8825491 --- /dev/null +++ b/src/MeshShadingDemoGame.h @@ -0,0 +1,21 @@ +#pragma once +#include "Actor/FlyCam.h" +#include "Define.h" +#include +#include +#include + +class MESHSHADINGDEMO_API MeshShadingDemoGame : public Game { +public: + MeshShadingDemoGame(); + virtual ~MeshShadingDemoGame(); + virtual void setupScene(PScene scene, PSystemGraph graph) override; + +private: + OStaticMeshActor cube; + OFlyCam camera; + ODirectionalLightActor light; +}; + +extern "C" MESHSHADINGDEMO_API Game *createInstance(); +extern "C" MESHSHADINGDEMO_API void destroyInstance(Game *game); \ No newline at end of file diff --git a/src/System/CMakeLists.txt b/src/System/CMakeLists.txt new file mode 100644 index 0000000..dd9248d --- /dev/null +++ b/src/System/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(MeshShadingDemo + PUBLIC + FlyCamSystem.h + FlyCamSystem.cpp) \ No newline at end of file diff --git a/src/System/FlyCamSystem.cpp b/src/System/FlyCamSystem.cpp new file mode 100644 index 0000000..657e726 --- /dev/null +++ b/src/System/FlyCamSystem.cpp @@ -0,0 +1,48 @@ +#include "FlyCamSystem.h" +#include "Seele/System/ComponentSystem.h" + +FlyCamSystem::FlyCamSystem(PScene scene) + : System::ComponentSystem(scene) {} + +FlyCamSystem::~FlyCamSystem() {} + +void FlyCamSystem::update(Component::KeyboardInput& input, Component::Camera& camera, Component::Transform& transform) { + float cameraMove = static_cast(deltaTime); + if(input.keys[KeyCode::KEY_LEFT_SHIFT]) + { + cameraMove *= 100; + } + Vector forward = transform.getForward(); + Vector side = transform.getRight(); + Vector moveVector = Vector(); + + if(input.keys[KeyCode::KEY_W]) + { + moveVector += forward * cameraMove; + } + if(input.keys[KeyCode::KEY_S]) + { + moveVector += forward * -cameraMove; + } + if(input.keys[KeyCode::KEY_A]) + { + moveVector += side * cameraMove; + } + if(input.keys[KeyCode::KEY_D]) + { + moveVector += side * -cameraMove; + } + if(input.keys[KeyCode::KEY_E]) + { + moveVector += Vector(0, cameraMove, 0); + } + if(input.keys[KeyCode::KEY_Q]) + { + moveVector += Vector(0, -cameraMove, 0); + } + transform.translate(moveVector); + if(input.mouse2) + { + camera.mouseMove(input.deltaX, input.deltaY); + } +} \ No newline at end of file diff --git a/src/System/FlyCamSystem.h b/src/System/FlyCamSystem.h new file mode 100644 index 0000000..e38d7f4 --- /dev/null +++ b/src/System/FlyCamSystem.h @@ -0,0 +1,22 @@ +#pragma once +#include "Define.h" +#include "Seele/MinimalEngine.h" +#include +#include +#include +#include + +class FlyCamSystem : public System::ComponentSystem< + Component::KeyboardInput, + Component::Camera, + Component::Transform> +{ +public: + FlyCamSystem(PScene scene); + virtual ~FlyCamSystem(); + virtual void update(Seele::Component::KeyboardInput& input, Seele::Component::Camera& camera, Seele::Component::Transform& transform) override; +private: + float lastMouseX; + float lastMouseY; +}; +DEFINE_REF(FlyCamSystem) \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index e1c3eb9..0000000 --- a/src/main.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include -#include - -using namespace Seele; - -int main() -{ - Gfx::PGraphics graphics = new Vulkan::Graphics(); - GraphicsInitializer initializer; - graphics->init(initializer); - - PWindowManager windowManager = new WindowManager(); - AssetRegistry::init("Assets", graphics); - - WindowCreateInfo mainWindowInfo; - mainWindowInfo.title = "MeshShadingDemo"; - mainWindowInfo.width = 1280; - mainWindowInfo.height = 720; - mainWindowInfo.bFullscreen = false; - mainWindowInfo.numSamples = 1; - mainWindowInfo.pixelFormat = Gfx::SE_FORMAT_B8G8R8A8_UNORM; - auto window = windowManager->addWindow(graphics, mainWindowInfo); - ViewportCreateInfo sceneViewInfo; - sceneViewInfo.dimensions.size.x = 1280; - sceneViewInfo.dimensions.size.y = 720; - sceneViewInfo.dimensions.offset.x = 0; - sceneViewInfo.dimensions.offset.y = 0; - PGameView sceneView = new GameView(graphics, window, sceneViewInfo, ""); - sceneView->setFocused(); - window->render(); - return 0; -} diff --git a/vcpkg b/vcpkg new file mode 160000 index 0000000..501cb01 --- /dev/null +++ b/vcpkg @@ -0,0 +1 @@ +Subproject commit 501cb01e517ee5689577bb01ba8bd1b4c1041a53 diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..e07c93c --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,19 @@ +{ + "dependencies": [ + "assimp", + "entt", + "stb", + "entt", + "freetype", + "glfw3", + "glm", + "ktx", + "nlohmann-json", + "fmt", + "gtest", + "vulkan-memory-allocator", + "shader-slang", + "spirv-cross", + "glslang" + ] +} \ No newline at end of file