diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 58b6cb84..aa9c2347 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -18,6 +18,7 @@ #include #include "Scripting/SHScriptEngine.h" +#include "Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h" namespace Sandbox { @@ -56,6 +57,9 @@ namespace Sandbox // Set up scripting SHADE::SHScriptEngine::Init(); + + // Create temp meshes + } void SBApplication::Update(void) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 09177993..f4a7d402 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -127,19 +127,20 @@ namespace SHADE auto node = worldRenderGraph->AddNode("G-Buffer", { "Composite", "Position", "Normals", "Present" }, {}); // no predecessors //First subpass to write to G-Buffer - auto writeSubpass = node->AddSubpass("G-Buffer Write"); - writeSubpass->AddColorOutput("Position"); - writeSubpass->AddColorOutput("Normals"); + auto gBufferWriteSubpass = node->AddSubpass("G-Buffer Write"); + gBufferWriteSubpass->AddColorOutput("Present"); + //writeSubpass->AddColorOutput("Normals"); - //Second subpass to read from G-Buffer - auto compositeSubpass = node->AddSubpass("G-Buffer Composite"); - compositeSubpass->AddColorOutput("Present"); // TODO: This should be "Composite" and then composite will write to swapchain image "Present" - compositeSubpass->AddInput("Normals"); - compositeSubpass->AddInput("Position"); + // //Second subpass to read from G-Buffer + //auto compositeSubpass = node->AddSubpass("G-Buffer Composite"); + //compositeSubpass->AddColorOutput("Present"); // TODO: This should be "Composite" and then composite will write to swapchain image "Present" + //compositeSubpass->AddInput("Normals"); + //compositeSubpass->AddInput("Position"); - auto imguiNode = worldRenderGraph->AddNode("ImGui Node", { "Present" }, {}); - auto imguiSubpass = imguiNode->AddSubpass("ImGui Draw"); - imguiSubpass->AddColorOutput("Present"); + // TODO: Use macro to add this node when SH_EDITOR is enabled + //auto imguiNode = worldRenderGraph->AddNode("ImGui Node", { "Present" }, {}); + //auto imguiSubpass = imguiNode->AddSubpass("ImGui Draw"); + //imguiSubpass->AddColorOutput("Present"); worldRenderGraph->Generate(); @@ -160,6 +161,19 @@ namespace SHADE worldRenderer->SetCamera(worldCamera); + // TODO: This is VERY temporarily here until a more solid resource management system is implemented + shaderSourceLibrary.Init("../../TempShaderFolder/"); + + shaderSourceLibrary.LoadShader(0, "TestCubeVs.glsl", SH_SHADER_TYPE::VERTEX, true); + shaderSourceLibrary.LoadShader(1, "TestCubeFs.glsl", SH_SHADER_TYPE::FRAGMENT, true); + + shaderModuleLibrary.ImportFromSourceLibrary(device, shaderSourceLibrary); + auto cubeVS = shaderModuleLibrary.GetShaderModule("TestCubeVs.glsl"); + auto cubeFS = shaderModuleLibrary.GetShaderModule("TestCubeFs.glsl"); + //triVS->Reflect(); + //triFS->Reflect(); + + AddMaterial(cubeVS, cubeFS, gBufferWriteSubpass); } /***************************************************************************/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 1c1d7710..f1eca3cc 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -25,6 +25,8 @@ of DigiPen Institute of Technology is prohibited. #include "ECS_Base/System/SHSystemRoutine.h" #include "Graphics/Descriptors/SHVkDescriptorPool.h" #include "Graphics/RenderGraph/SHRenderGraph.h" +#include "Graphics/MiddleEnd/Shaders/SHShaderSourceLibrary.h" +#include "Graphics/MiddleEnd/Shaders/SHShaderModuleLibrary.h" namespace SHADE { @@ -159,27 +161,35 @@ namespace SHADE // Not Owned Resources SHWindow* window; - + // Global descriptor set layouts std::vector> globalDescSetLayouts; // Middle End Resources ResourceManager resourceManager; + // Viewports Handle defaultViewport; // Whole screen std::vector> viewports; // Additional viewports + // Debug Renderers Handle debugWorldRenderer; Handle debugScreenRenderer; + // Temp renderers + Handle worldRenderer; + // Temp Cameras Handle worldCamera; Handle screenCamera; - // Temp renderers - Handle worldRenderer; - + // Default vertex input state (used by everything). SHVertexInputState defaultVertexInputState; + // TODO: Temporary only until resource library from Xiao Qi is implemented + SHShaderSourceLibrary shaderSourceLibrary; + SHShaderModuleLibrary shaderModuleLibrary; + + /*-----------------------------------------------------------------------------*/ /* Private member functions */ /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp index bf681a81..1ad82a80 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp @@ -24,8 +24,8 @@ namespace SHADE void SHRenderable::OnCreate() { materialChanged = true; - sharedMaterial = {}; - material = {}; + sharedMaterial = {}; + material = {}; oldMaterial = {}; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Shaders/SHShaderSourceLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Shaders/SHShaderSourceLibrary.cpp index dd0f1612..d9bf9ddc 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Shaders/SHShaderSourceLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Shaders/SHShaderSourceLibrary.cpp @@ -269,4 +269,40 @@ namespace SHADE } + SHShaderData::SHShaderData(SHShaderData const& rhs) noexcept + : spirvBinary{rhs.spirvBinary} + , shaderType{ rhs.shaderType} + , name{rhs.name } + , id{rhs.id } + { + + } + + SHShaderData& SHShaderData::operator=(SHShaderData const& rhs) noexcept + { + if (this == &rhs) + return *this; + + spirvBinary = rhs.spirvBinary; + shaderType = rhs.shaderType; + name = rhs.name; + id = rhs.id; + + + return *this; + } + + SHShaderData& SHShaderData::operator=(SHShaderData&& rhs) noexcept + { + if (this == &rhs) + return *this; + + spirvBinary = std::move(rhs.spirvBinary); + shaderType = std::move (rhs.shaderType); + name = std::move (rhs.name); + id = std::move (rhs.id); + + return *this; + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Shaders/SHShaderSourceLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/Shaders/SHShaderSourceLibrary.h index 505afa97..bb346111 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Shaders/SHShaderSourceLibrary.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Shaders/SHShaderSourceLibrary.h @@ -25,7 +25,10 @@ namespace SHADE uint32_t id; SHShaderData(void) noexcept; + SHShaderData(SHShaderData const& rhs) noexcept; SHShaderData(SHShaderData&& rhs) noexcept; + SHShaderData& operator= (SHShaderData&& rhs) noexcept; + SHShaderData& operator= (SHShaderData const& rhs) noexcept; }; // TODO: This class is purely temporary and will be converted/changed when XQ implements his resource manager diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index 1c995e12..ee5049e3 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -1,4 +1,4 @@ -#include "SHPch.h" +#include "SHPch.h" #include "SHRenderGraph.h" #include "Graphics/Swapchain/SHVkSwapchain.h" #include "Graphics/Framebuffer/SHVkFramebuffer.h" @@ -338,6 +338,7 @@ namespace SHADE void SHSubpass::Execute(Handle& commandBuffer) noexcept { // Draw all the batches + superBatch->Draw(commandBuffer); // Draw all the exterior draw calls for (auto& drawCall : exteriorDrawCalls) @@ -584,7 +585,7 @@ namespace SHADE Handle SHRenderGraphNode::GetOrCreatePipeline(std::pair, Handle> const& vsFsPair, Handle subpass) noexcept { // verify subpass exists - if (subpass->GetIndex() >= subpasses.size() - 1) + if (subpass->GetIndex() >= subpasses.size()) { SHLOG_ERROR("Subpass index passed in is not valid. RenderGraphNode does not have that many passes. "); return {}; diff --git a/TempShaderFolder/TestCubeFs.glsl b/TempShaderFolder/TestCubeFs.glsl new file mode 100644 index 00000000..dc069eda --- /dev/null +++ b/TempShaderFolder/TestCubeFs.glsl @@ -0,0 +1,72 @@ +#version 450 +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout(location = 0) in struct +{ + //mat3 BTN; + vec4 vertColor; + //vec3 localSpacePosition; + //vec2 uv; + //vec3 localLightPosition; + //vec3 localEyePosition; + +} In; + +//layout(std140, push_constant) uniform TestPushConstant +//{ +// mat4 pvMat; +// vec4 lightPosition; +// vec4 eyePosition; +// vec4 ambientColor; +// vec4 lightColor; +// +//} testPushConstant; + +layout(location = 0) out vec4 outColor; + +//layout(binding = 0) uniform sampler2D diffuseMap; +//layout(binding = 1) uniform sampler2D normalMap; +//layout(binding = 2) uniform sampler2D aoMap; +//layout(binding = 3) uniform sampler2D glossinessMap; +//layout(binding = 4) uniform sampler2D samplerRoughnessMap; + +void main() +{ + //vec3 normal; + + //// Get the tangent space normal from normal map. It is a BC5 texture and therefore only use red and green + //normal.xy = (texture (normalMap, In.uv).gr * 2.0f) - 1.0f; + + //// z value is derived (TODO: Find out what this does) + //normal.z = sqrt(1.0f - dot(normal.xy, normal.xy)); + + //// Transform the normal from tangent space to local space + //normal = In.BTN * normal; + + //// Get the vector from fragment to light + //vec3 localLightDir = normalize(In.localLightPosition - In.localSpacePosition); + + //// get the value of dot between normal from texture and frag to light + //float diffuse = max(0, dot(normal, localLightDir)); + + //// sample the diffuse texture + //vec4 diffuseColor = texture (diffuseMap, In.uv) * In.vertColor; + + //vec3 eyeDirection = normalize(In.localSpacePosition - In.localEyePosition); + + //const float shininess = mix(1, 100, 1 - texture (samplerRoughnessMap, In.uv).r); + + //float specular = pow(max(0, dot(normal, normalize(localLightDir - eyeDirection))), shininess); + + //outColor.rgb = testPushConstant.ambientColor.rgb * diffuseColor.rgb * texture (aoMap, In.uv).rgb; + + //outColor.rgb += testPushConstant.lightColor.rgb * (specular.rrr * 0.4 + diffuse.rrr * diffuseColor.rgb); + + //const float gamma = testPushConstant.eyePosition.w; + //outColor.rgb = pow(outColor.rgb, vec3(1.0f / gamma)); + //outColor.a = diffuseColor.a; + + + outColor = In.vertColor; +} \ No newline at end of file diff --git a/TempShaderFolder/TestCubeFs.spv b/TempShaderFolder/TestCubeFs.spv new file mode 100644 index 00000000..f0dbc449 Binary files /dev/null and b/TempShaderFolder/TestCubeFs.spv differ diff --git a/TempShaderFolder/TestCubeVs.glsl b/TempShaderFolder/TestCubeVs.glsl new file mode 100644 index 00000000..f7dce787 --- /dev/null +++ b/TempShaderFolder/TestCubeVs.glsl @@ -0,0 +1,53 @@ +#version 450 +#extension GL_KHR_vulkan_glsl : enable + +layout(location = 0) in vec3 aVertexPos; +layout(location = 1) in vec2 aUV; +layout(location = 2) in vec3 aNormal; +layout(location = 3) in vec3 aTangent; +layout(location = 4) in mat4 worldTransform; + +//layout(std140, push_constant) uniform TestPushConstant +//{ +// mat4 pvMat; +// vec4 lightPosition; +// vec4 eyePosition; +// vec4 ambientColor; +// vec4 lightColor; +// +//} testPushConstant; + +layout(location = 0) out struct +{ + //mat3 BTN; + vec4 vertColor; + //vec3 localSpacePosition; + //vec2 uv; + //vec3 localLightPosition; + //vec3 localEyePosition; + +} Out; + +void main() +{ + //const float gamma = testPushConstant.eyePosition.w; + //mat4 W2L = inverse(worldTransform); + + //// Since attributes are instanced we want the local positions of light and eye (camera) + //Out.localLightPosition = vec3(W2L * vec4(testPushConstant.lightPosition.xyz, 1.0f)); + //Out.localEyePosition = vec3(W2L * vec4(testPushConstant.eyePosition.xyz, 1.0f)); + + //vec3 biTangent = normalize(cross(aNormal, aTangent)); + + //gl_Position = testPushConstant.pvMat * worldTransform * vec4(aVertexPos, 1.0); + + //// Since the normal we are sampling is in tangent space, we want to later convert them to local space + //// so we need this matrix to multiply with the sampled texel of the normal map. + //Out.BTN = mat3(aTangent, biTangent, aNormal); + //Out.localSpacePosition = aVertexPos; + //Out.uv = aUV; + + // render NDC first + gl_Position = vec4(aVertexPos, 1.0); + Out.vertColor = vec4 (aVertexPos, 1.0f); +} \ No newline at end of file diff --git a/TempShaderFolder/TestCubeVs.spv b/TempShaderFolder/TestCubeVs.spv new file mode 100644 index 00000000..2b0d3b93 Binary files /dev/null and b/TempShaderFolder/TestCubeVs.spv differ