This commit is contained in:
Brandon Mak 2022-09-19 00:00:07 +08:00
parent 41daaaba9c
commit 643efbe1bb
11 changed files with 212 additions and 19 deletions

View File

@ -18,6 +18,7 @@
#include <SDL.h> #include <SDL.h>
#include "Scripting/SHScriptEngine.h" #include "Scripting/SHScriptEngine.h"
#include "Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h"
namespace Sandbox namespace Sandbox
{ {
@ -56,6 +57,9 @@ namespace Sandbox
// Set up scripting // Set up scripting
SHADE::SHScriptEngine::Init(); SHADE::SHScriptEngine::Init();
// Create temp meshes
} }
void SBApplication::Update(void) void SBApplication::Update(void)

View File

@ -127,19 +127,20 @@ namespace SHADE
auto node = worldRenderGraph->AddNode("G-Buffer", { "Composite", "Position", "Normals", "Present" }, {}); // no predecessors auto node = worldRenderGraph->AddNode("G-Buffer", { "Composite", "Position", "Normals", "Present" }, {}); // no predecessors
//First subpass to write to G-Buffer //First subpass to write to G-Buffer
auto writeSubpass = node->AddSubpass("G-Buffer Write"); auto gBufferWriteSubpass = node->AddSubpass("G-Buffer Write");
writeSubpass->AddColorOutput("Position"); gBufferWriteSubpass->AddColorOutput("Present");
writeSubpass->AddColorOutput("Normals"); //writeSubpass->AddColorOutput("Normals");
//Second subpass to read from G-Buffer // //Second subpass to read from G-Buffer
auto compositeSubpass = node->AddSubpass("G-Buffer Composite"); //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->AddColorOutput("Present"); // TODO: This should be "Composite" and then composite will write to swapchain image "Present"
compositeSubpass->AddInput("Normals"); //compositeSubpass->AddInput("Normals");
compositeSubpass->AddInput("Position"); //compositeSubpass->AddInput("Position");
auto imguiNode = worldRenderGraph->AddNode("ImGui Node", { "Present" }, {}); // TODO: Use macro to add this node when SH_EDITOR is enabled
auto imguiSubpass = imguiNode->AddSubpass("ImGui Draw"); //auto imguiNode = worldRenderGraph->AddNode("ImGui Node", { "Present" }, {});
imguiSubpass->AddColorOutput("Present"); //auto imguiSubpass = imguiNode->AddSubpass("ImGui Draw");
//imguiSubpass->AddColorOutput("Present");
worldRenderGraph->Generate(); worldRenderGraph->Generate();
@ -160,6 +161,19 @@ namespace SHADE
worldRenderer->SetCamera(worldCamera); 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);
} }
/***************************************************************************/ /***************************************************************************/

View File

@ -25,6 +25,8 @@ of DigiPen Institute of Technology is prohibited.
#include "ECS_Base/System/SHSystemRoutine.h" #include "ECS_Base/System/SHSystemRoutine.h"
#include "Graphics/Descriptors/SHVkDescriptorPool.h" #include "Graphics/Descriptors/SHVkDescriptorPool.h"
#include "Graphics/RenderGraph/SHRenderGraph.h" #include "Graphics/RenderGraph/SHRenderGraph.h"
#include "Graphics/MiddleEnd/Shaders/SHShaderSourceLibrary.h"
#include "Graphics/MiddleEnd/Shaders/SHShaderModuleLibrary.h"
namespace SHADE namespace SHADE
{ {
@ -159,27 +161,35 @@ namespace SHADE
// Not Owned Resources // Not Owned Resources
SHWindow* window; SHWindow* window;
// Global descriptor set layouts
std::vector<Handle<SHVkDescriptorSetLayout>> globalDescSetLayouts; std::vector<Handle<SHVkDescriptorSetLayout>> globalDescSetLayouts;
// Middle End Resources // Middle End Resources
ResourceManager resourceManager; ResourceManager resourceManager;
// Viewports // Viewports
Handle<SHViewport> defaultViewport; // Whole screen Handle<SHViewport> defaultViewport; // Whole screen
std::vector<Handle<SHViewport>> viewports; // Additional viewports std::vector<Handle<SHViewport>> viewports; // Additional viewports
// Debug Renderers // Debug Renderers
Handle<SHRenderer> debugWorldRenderer; Handle<SHRenderer> debugWorldRenderer;
Handle<SHRenderer> debugScreenRenderer; Handle<SHRenderer> debugScreenRenderer;
// Temp renderers
Handle<SHRenderer> worldRenderer;
// Temp Cameras // Temp Cameras
Handle<SHCamera> worldCamera; Handle<SHCamera> worldCamera;
Handle<SHCamera> screenCamera; Handle<SHCamera> screenCamera;
// Temp renderers // Default vertex input state (used by everything).
Handle<SHRenderer> worldRenderer;
SHVertexInputState defaultVertexInputState; SHVertexInputState defaultVertexInputState;
// TODO: Temporary only until resource library from Xiao Qi is implemented
SHShaderSourceLibrary shaderSourceLibrary;
SHShaderModuleLibrary shaderModuleLibrary;
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Private member functions */ /* Private member functions */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/

View File

@ -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;
}
} }

View File

@ -25,7 +25,10 @@ namespace SHADE
uint32_t id; uint32_t id;
SHShaderData(void) noexcept; SHShaderData(void) noexcept;
SHShaderData(SHShaderData const& rhs) noexcept;
SHShaderData(SHShaderData&& 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 // TODO: This class is purely temporary and will be converted/changed when XQ implements his resource manager

View File

@ -338,6 +338,7 @@ namespace SHADE
void SHSubpass::Execute(Handle<SHVkCommandBuffer>& commandBuffer) noexcept void SHSubpass::Execute(Handle<SHVkCommandBuffer>& commandBuffer) noexcept
{ {
// Draw all the batches // Draw all the batches
superBatch->Draw(commandBuffer);
// Draw all the exterior draw calls // Draw all the exterior draw calls
for (auto& drawCall : exteriorDrawCalls) for (auto& drawCall : exteriorDrawCalls)
@ -584,7 +585,7 @@ namespace SHADE
Handle<SHVkPipeline> SHRenderGraphNode::GetOrCreatePipeline(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, Handle<SHSubpass> subpass) noexcept Handle<SHVkPipeline> SHRenderGraphNode::GetOrCreatePipeline(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, Handle<SHSubpass> subpass) noexcept
{ {
// verify subpass exists // 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. "); SHLOG_ERROR("Subpass index passed in is not valid. RenderGraphNode does not have that many passes. ");
return {}; return {};

View File

@ -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;
}

Binary file not shown.

View File

@ -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);
}

Binary file not shown.