Shader files: hlsl & glsl
- Moved #define LT_ENGINE_RESOURCES_*_SHADER_* definitions to files * Note: This was done so for a gcc compilation error caused by R"()" string - Removed test print fps in 'Application::GameLoop()'
This commit is contained in:
parent
a3f0693655
commit
033a3b1dd1
15 changed files with 116 additions and 179 deletions
|
@ -37,8 +37,9 @@ project "Engine"
|
||||||
includedirs
|
includedirs
|
||||||
{
|
{
|
||||||
-- engine
|
-- engine
|
||||||
"%{prj.location}/src" ,
|
"%{prj.location}" ,
|
||||||
"%{prj.location}/src/Engine" ,
|
"%{prj.location}/src" ,
|
||||||
|
"%{prj.location}/src/Engine" ,
|
||||||
"%{prj.location}/src/Platform/GraphicsAPI" ,
|
"%{prj.location}/src/Platform/GraphicsAPI" ,
|
||||||
"%{prj.location}/src/Platform/OS" ,
|
"%{prj.location}/src/Platform/OS" ,
|
||||||
|
|
||||||
|
@ -109,3 +110,7 @@ project "Engine"
|
||||||
filter "configurations:Distribution"
|
filter "configurations:Distribution"
|
||||||
defines "LIGHT_DIST"
|
defines "LIGHT_DIST"
|
||||||
optimize "on"
|
optimize "on"
|
||||||
|
|
||||||
|
filter { "files:**.hlsl" }
|
||||||
|
flags "ExcludeFromBuild"
|
||||||
|
shadermodel "4.0"
|
10
Engine/res/Shaders/Quad/Quad_PS.glsl
Normal file
10
Engine/res/Shaders/Quad/Quad_PS.glsl
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#version 440 core
|
||||||
|
|
||||||
|
in vec4 vso_FragmentColor;
|
||||||
|
|
||||||
|
out vec4 fso_FragmentColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
fso_FragmentColor = vso_FragmentColor;
|
||||||
|
}
|
4
Engine/res/Shaders/Quad/Quad_PS.hlsl
Normal file
4
Engine/res/Shaders/Quad/Quad_PS.hlsl
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
float4 main(float4 Color : COLOR) : SV_Target
|
||||||
|
{
|
||||||
|
return Color;
|
||||||
|
}
|
17
Engine/res/Shaders/Quad/Quad_VS.glsl
Normal file
17
Engine/res/Shaders/Quad/Quad_VS.glsl
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#version 440 core
|
||||||
|
|
||||||
|
layout(location = 0) in vec3 a_Position;
|
||||||
|
layout(location = 1) in vec4 a_Color;
|
||||||
|
|
||||||
|
layout(std140, binding = 0) uniform ub_ViewProjection
|
||||||
|
{
|
||||||
|
mat4 viewProjection;
|
||||||
|
};
|
||||||
|
|
||||||
|
out vec4 vso_FragmentColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = viewProjection * vec4(a_Position, 1.0);
|
||||||
|
vso_FragmentColor = a_Color;
|
||||||
|
}
|
14
Engine/res/Shaders/Quad/Quad_VS.hlsl
Normal file
14
Engine/res/Shaders/Quad/Quad_VS.hlsl
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
struct VertexOut
|
||||||
|
{
|
||||||
|
float4 Color : COLOR;
|
||||||
|
float4 Position : SV_Position;
|
||||||
|
};
|
||||||
|
|
||||||
|
VertexOut main(float3 InPosition : POSITION, float4 InColor : COLOR)
|
||||||
|
{
|
||||||
|
VertexOut vso;
|
||||||
|
vso.Position = float4(InPosition.x, InPosition.y, InPosition.z, 1.0);
|
||||||
|
vso.Color = InColor;
|
||||||
|
|
||||||
|
return vso;
|
||||||
|
}
|
|
@ -1,63 +0,0 @@
|
||||||
#define LT_ENGINE_RESOURCES_QUAD_SHADER_VS \
|
|
||||||
R"(
|
|
||||||
+GLSL
|
|
||||||
#version 440 core
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 a_Position;
|
|
||||||
layout(location = 1) in vec4 a_Color;
|
|
||||||
|
|
||||||
layout(std140, binding = 0) uniform ub_ViewProjection
|
|
||||||
{
|
|
||||||
mat4 viewProjection;
|
|
||||||
};
|
|
||||||
|
|
||||||
out vec4 vso_FragmentColor;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = viewProjection * vec4(a_Position, 1.0);
|
|
||||||
vso_FragmentColor = a_Color;
|
|
||||||
}
|
|
||||||
-GLSL
|
|
||||||
|
|
||||||
|
|
||||||
+HLSL
|
|
||||||
struct VertexOut
|
|
||||||
{
|
|
||||||
float4 Color : COLOR;
|
|
||||||
float4 Position : SV_Position;
|
|
||||||
};
|
|
||||||
|
|
||||||
VertexOut main(float3 InPosition : POSITION, float4 InColor : COLOR)
|
|
||||||
{
|
|
||||||
VertexOut vso;
|
|
||||||
vso.Position = float4(InPosition.x, InPosition.y, InPosition.z, 1.0);
|
|
||||||
vso.Color = InColor;
|
|
||||||
|
|
||||||
return vso;
|
|
||||||
}
|
|
||||||
-HLSL)"
|
|
||||||
|
|
||||||
#define LT_ENGINE_RESOURCES_QUAD_SHADER_PS \
|
|
||||||
R"(
|
|
||||||
+GLSL
|
|
||||||
#version 440 core
|
|
||||||
|
|
||||||
in vec4 vso_FragmentColor;
|
|
||||||
|
|
||||||
out vec4 fso_FragmentColor;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
fso_FragmentColor = vso_FragmentColor;
|
|
||||||
}
|
|
||||||
-GLSL
|
|
||||||
|
|
||||||
|
|
||||||
+HLSL
|
|
||||||
float4 main(float4 Color : COLOR) : SV_Target
|
|
||||||
{
|
|
||||||
return Color;
|
|
||||||
}
|
|
||||||
-HLSL
|
|
||||||
)"
|
|
12
Engine/res/Shaders/Texture/Texture_PS.glsl
Normal file
12
Engine/res/Shaders/Texture/Texture_PS.glsl
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#version 440 core
|
||||||
|
|
||||||
|
in vec2 vso_TexCoord;
|
||||||
|
|
||||||
|
uniform sampler2D u_Texture;
|
||||||
|
|
||||||
|
out vec4 fso_FragmentColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
fso_FragmentColor = texture(u_Texture, vso_TexCoord);
|
||||||
|
}
|
7
Engine/res/Shaders/Texture/Texture_PS.hlsl
Normal file
7
Engine/res/Shaders/Texture/Texture_PS.hlsl
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
sampler samplerState : register(s0);
|
||||||
|
Texture2D<float4> myTexture : register(t0);
|
||||||
|
|
||||||
|
float4 main(float2 InTexChoord : TEXCOORD) : SV_Target
|
||||||
|
{
|
||||||
|
return myTexture.Sample(samplerState, InTexChoord);
|
||||||
|
}
|
17
Engine/res/Shaders/Texture/Texture_VS.glsl
Normal file
17
Engine/res/Shaders/Texture/Texture_VS.glsl
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#version 440 core
|
||||||
|
|
||||||
|
layout(location = 0) in vec3 a_Position;
|
||||||
|
layout(location = 1) in vec2 a_TexCoord;
|
||||||
|
|
||||||
|
layout(std140, binding = 0) uniform ub_ViewProjection
|
||||||
|
{
|
||||||
|
mat4 u_ViewProjection;
|
||||||
|
};
|
||||||
|
|
||||||
|
out vec2 vso_TexCoord;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = u_ViewProjection * vec4(a_Position, 1.0);
|
||||||
|
vso_TexCoord = a_TexCoord;
|
||||||
|
}
|
19
Engine/res/Shaders/Texture/Texture_VS.hlsl
Normal file
19
Engine/res/Shaders/Texture/Texture_VS.hlsl
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
struct VertexOut
|
||||||
|
{
|
||||||
|
float2 TexChoord : TEXCOORD;
|
||||||
|
float4 Position : SV_Position;
|
||||||
|
};
|
||||||
|
|
||||||
|
cbuffer cb_ViewProjection : register(b0)
|
||||||
|
{
|
||||||
|
row_major matrix viewProjection;
|
||||||
|
}
|
||||||
|
|
||||||
|
VertexOut main(float3 InPosition : POSITION, float2 InTexChoord : TEXCOORD)
|
||||||
|
{
|
||||||
|
VertexOut vso;
|
||||||
|
vso.Position = mul(float4(InPosition, 1.0), viewProjection);
|
||||||
|
vso.TexChoord = InTexChoord;
|
||||||
|
|
||||||
|
return vso;
|
||||||
|
}
|
|
@ -1,76 +0,0 @@
|
||||||
#define LT_ENGINE_RESOURCES_TEXTURE_SHADER_VS \
|
|
||||||
R"(
|
|
||||||
+GLSL
|
|
||||||
#version 440 core
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 a_Position;
|
|
||||||
layout(location = 1) in vec2 a_TexCoord;
|
|
||||||
|
|
||||||
layout(std140, binding = 0) uniform ub_ViewProjection
|
|
||||||
{
|
|
||||||
mat4 u_ViewProjection;
|
|
||||||
};
|
|
||||||
|
|
||||||
out vec2 vso_TexCoord;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = u_ViewProjection * vec4(a_Position, 1.0);
|
|
||||||
vso_TexCoord = a_TexCoord;
|
|
||||||
}
|
|
||||||
-GLSL
|
|
||||||
|
|
||||||
|
|
||||||
+HLSL
|
|
||||||
struct VertexOut
|
|
||||||
{
|
|
||||||
float2 TexChoord : TEXCHOORD;
|
|
||||||
float4 Position : SV_Position;
|
|
||||||
};
|
|
||||||
|
|
||||||
cbuffer cb_ViewProjection : register(b0)
|
|
||||||
{
|
|
||||||
row_major matrix viewProjection;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
VertexOut main(float3 InPosition : POSITION, float2 InTexChoord : TEXCOORD)
|
|
||||||
{
|
|
||||||
VertexOut vso;
|
|
||||||
vso.Position = mul(float4(InPosition, 1.0), viewProjection);
|
|
||||||
vso.TexChoord = InTexChoord;
|
|
||||||
|
|
||||||
return vso;
|
|
||||||
}
|
|
||||||
-HLSL
|
|
||||||
)"
|
|
||||||
|
|
||||||
#define LT_ENGINE_RESOURCES_TEXTURE_SHADER_PS \
|
|
||||||
R"(
|
|
||||||
+GLSL
|
|
||||||
#version 440 core
|
|
||||||
|
|
||||||
in vec2 vso_TexCoord;
|
|
||||||
|
|
||||||
uniform sampler2D u_Texture;
|
|
||||||
|
|
||||||
out vec4 fso_FragmentColor;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
fso_FragmentColor = texture(u_Texture, vso_TexCoord);
|
|
||||||
}
|
|
||||||
-GLSL
|
|
||||||
|
|
||||||
|
|
||||||
+HLSL
|
|
||||||
sampler samplerState : register(s0);
|
|
||||||
Texture2D<float4> myTexture : register(t0);
|
|
||||||
|
|
||||||
float4 main(float2 InTexChoord : TEXCHOORD) : SV_Target
|
|
||||||
{
|
|
||||||
return myTexture.Sample(samplerState, InTexChoord);
|
|
||||||
}
|
|
||||||
|
|
||||||
-HLSL
|
|
||||||
)"
|
|
|
@ -43,8 +43,6 @@ namespace Light {
|
||||||
m_Window->SetVisibility(true);
|
m_Window->SetVisibility(true);
|
||||||
|
|
||||||
DeltaTimer deltaTimer;
|
DeltaTimer deltaTimer;
|
||||||
Timer timer;
|
|
||||||
int frames = 0;
|
|
||||||
|
|
||||||
//** GAMELOOP **//
|
//** GAMELOOP **//
|
||||||
while (!m_Window->IsClosed())
|
while (!m_Window->IsClosed())
|
||||||
|
@ -52,15 +50,6 @@ namespace Light {
|
||||||
// update layers
|
// update layers
|
||||||
m_LayerStack.OnUpdate(deltaTimer.GetDeltaTime());
|
m_LayerStack.OnUpdate(deltaTimer.GetDeltaTime());
|
||||||
|
|
||||||
frames++;
|
|
||||||
if (timer.GetElapsedTime() > 1.0f)
|
|
||||||
{
|
|
||||||
LT_ENGINE_INFO(frames);
|
|
||||||
|
|
||||||
frames = 0;
|
|
||||||
timer.Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
// render layers
|
// render layers
|
||||||
m_Window->GetGfxContext()->GetRenderer()->BeginFrame();
|
m_Window->GetGfxContext()->GetRenderer()->BeginFrame();
|
||||||
m_LayerStack.OnRender();
|
m_LayerStack.OnRender();
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
#include "Graphics/Buffers.h"
|
#include "Graphics/Buffers.h"
|
||||||
#include "Graphics/VertexLayout.h"
|
#include "Graphics/VertexLayout.h"
|
||||||
|
|
||||||
#include "../res/Shaders/QuadShader.h"
|
|
||||||
|
|
||||||
#include "Utility/ResourceManager.h"
|
#include "Utility/ResourceManager.h"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
@ -16,7 +14,7 @@ namespace Light {
|
||||||
QuadRendererProgram::QuadRendererProgram(unsigned int maxVertices, std::shared_ptr<SharedContext> sharedContext)
|
QuadRendererProgram::QuadRendererProgram(unsigned int maxVertices, std::shared_ptr<SharedContext> sharedContext)
|
||||||
: m_MaxVertices(maxVertices)
|
: m_MaxVertices(maxVertices)
|
||||||
{
|
{
|
||||||
ResourceManager::CreateShader("LT_ENGINE_RESOURCES_QUAD_SHADER", LT_ENGINE_RESOURCES_QUAD_SHADER_VS, LT_ENGINE_RESOURCES_QUAD_SHADER_PS);
|
ResourceManager::LoadShader("LT_ENGINE_RESOURCES_QUAD_SHADER", "../Engine/res/Shaders/Quad/Quad_VS", "../Engine//res/Shaders/Quad/Quad_PS");
|
||||||
|
|
||||||
m_Shader = ResourceManager::GetShader("LT_ENGINE_RESOURCES_QUAD_SHADER");
|
m_Shader = ResourceManager::GetShader("LT_ENGINE_RESOURCES_QUAD_SHADER");
|
||||||
m_VertexBuffer = std::shared_ptr<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(QuadVertexData), maxVertices, sharedContext));
|
m_VertexBuffer = std::shared_ptr<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(QuadVertexData), maxVertices, sharedContext));
|
||||||
|
@ -63,4 +61,5 @@ namespace Light {
|
||||||
m_VertexBuffer->Bind();
|
m_VertexBuffer->Bind();
|
||||||
m_IndexBuffer->Bind();
|
m_IndexBuffer->Bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,8 +7,6 @@
|
||||||
#include "Graphics/Buffers.h"
|
#include "Graphics/Buffers.h"
|
||||||
#include "Graphics/VertexLayout.h"
|
#include "Graphics/VertexLayout.h"
|
||||||
|
|
||||||
#include "../res/Shaders/TextureShader.h"
|
|
||||||
|
|
||||||
#include "Utility/ResourceManager.h"
|
#include "Utility/ResourceManager.h"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
@ -16,7 +14,7 @@ namespace Light {
|
||||||
TextureRendererProgram::TextureRendererProgram(unsigned int maxVertices, std::shared_ptr<SharedContext> sharedContext)
|
TextureRendererProgram::TextureRendererProgram(unsigned int maxVertices, std::shared_ptr<SharedContext> sharedContext)
|
||||||
: m_MaxVertices(maxVertices)
|
: m_MaxVertices(maxVertices)
|
||||||
{
|
{
|
||||||
ResourceManager::CreateShader("LT_ENGINE_RESOURCES_TEXTURE_SHADER", LT_ENGINE_RESOURCES_TEXTURE_SHADER_VS, LT_ENGINE_RESOURCES_TEXTURE_SHADER_PS);
|
ResourceManager::LoadShader("LT_ENGINE_RESOURCES_TEXTURE_SHADER", "../Engine/res/Shaders/Texture/Texture_VS", "../Engine/res/Shaders/Texture/Texture_PS");
|
||||||
|
|
||||||
m_Shader = ResourceManager::GetShader("LT_ENGINE_RESOURCES_TEXTURE_SHADER");
|
m_Shader = ResourceManager::GetShader("LT_ENGINE_RESOURCES_TEXTURE_SHADER");
|
||||||
m_VertexBuffer = std::shared_ptr<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(TextureVertexData), maxVertices, sharedContext));
|
m_VertexBuffer = std::shared_ptr<VertexBuffer>(VertexBuffer::Create(nullptr, sizeof(TextureVertexData), maxVertices, sharedContext));
|
||||||
|
|
|
@ -55,21 +55,14 @@ namespace Light {
|
||||||
LT_ENGINE_ASSERT(!vertexPath.empty(), "ResourceManager::LoadShader: 'vertexPath' is empty");
|
LT_ENGINE_ASSERT(!vertexPath.empty(), "ResourceManager::LoadShader: 'vertexPath' is empty");
|
||||||
LT_ENGINE_ASSERT(!pixelPath.empty(), "ResourceManager::LoadShader: 'pixelPath' is empty");
|
LT_ENGINE_ASSERT(!pixelPath.empty(), "ResourceManager::LoadShader: 'pixelPath' is empty");
|
||||||
|
|
||||||
|
std::string vPath = vertexPath + (GraphicsContext::GetGraphicsAPI() == GraphicsAPI::OpenGL ? ".glsl" : ".hlsl");
|
||||||
|
std::string pPath = pixelPath + (GraphicsContext::GetGraphicsAPI() == GraphicsAPI::OpenGL ? ".glsl" : ".hlsl");
|
||||||
|
|
||||||
// initialize
|
// initialize
|
||||||
std::ifstream vsStream(vertexPath), psStream(pixelPath);
|
std::ifstream vsStream(vPath), psStream(pPath);
|
||||||
std::stringstream vsSS, psSS; // pss pss pss pss :D
|
std::stringstream vsSS, psSS; // pss pss pss pss :D
|
||||||
std::string vertexSource, pixelSource;
|
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
||||||
// delim
|
|
||||||
std::string delim = GraphicsContext::GetGraphicsAPI() == GraphicsAPI::OpenGL ? "GLSL" :
|
|
||||||
GraphicsContext::GetGraphicsAPI() == GraphicsAPI::DirectX ? "HLSL" : NULL;
|
|
||||||
|
|
||||||
// check
|
|
||||||
LT_ENGINE_ASSERT(!delim.empty(), "ResourceManager::LoadShader: invalid/unsupported 'GraphicsAPI': {}", GraphicsContext::GetGraphicsAPI());
|
|
||||||
LT_ENGINE_ASSERT(vsStream.is_open(), "ResourceManager::LoadShader: invalid 'vertexPath': {}", vertexPath);
|
|
||||||
LT_ENGINE_ASSERT(psStream.is_open(), "ResourceManager::LoadShader: invalid 'pixelPath': {}", pixelPath);
|
|
||||||
|
|
||||||
// read
|
// read
|
||||||
while (std::getline(vsStream, line))
|
while (std::getline(vsStream, line))
|
||||||
vsSS << line << '\n';
|
vsSS << line << '\n';
|
||||||
|
@ -77,16 +70,8 @@ namespace Light {
|
||||||
while (std::getline(psStream, line))
|
while (std::getline(psStream, line))
|
||||||
psSS << line << '\n';
|
psSS << line << '\n';
|
||||||
|
|
||||||
// save to string
|
|
||||||
vertexSource = vsSS.str();
|
|
||||||
pixelSource = psSS.str();
|
|
||||||
|
|
||||||
// extract source
|
|
||||||
ResourceManager::ExtractShaderSource(vertexSource, delim);
|
|
||||||
ResourceManager::ExtractShaderSource(pixelSource, delim);
|
|
||||||
|
|
||||||
// create shader
|
// create shader
|
||||||
m_Shaders[name] = std::shared_ptr<Shader>(Shader::Create(vertexSource, pixelSource, m_SharedContext));
|
m_Shaders[name] = std::shared_ptr<Shader>(Shader::Create(vsSS.str(), psSS.str(), m_SharedContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceManager::LoadTextureImpl(const std::string& name, const std::string& path, unsigned int desiredComponents /* = 4u */)
|
void ResourceManager::LoadTextureImpl(const std::string& name, const std::string& path, unsigned int desiredComponents /* = 4u */)
|
||||||
|
|
Loading…
Add table
Reference in a new issue