diff --git a/assets/shaders/hello-world.slang b/assets/shaders/hello-world.slang index db40e70f..552e1f5f 100644 --- a/assets/shaders/hello-world.slang +++ b/assets/shaders/hello-world.slang @@ -1,10 +1,14 @@ -cbuffer Uniforms { - float4x4 u_Projection; - float4x4 u_View; - float4x4 u_Model; +struct MVP { + float4x4 projection; + float4x4 view; + float4x4 model; +} + +struct Uniforms { + MVP mvp; float4 u_Color; bool u_HasTexture; - uniform Sampler2D u_Texture; + Sampler2D u_Texture; }; struct AssembledVertex { @@ -26,7 +30,10 @@ float4 someFunction(float4 color) { } [shader("vertex")] -VertexStageOutput vertexMain(AssembledVertex assembledVertex) { +VertexStageOutput vertexMain( + uniform ParameterBlock uniforms, + AssembledVertex assembledVertex +) { VertexStageOutput output; float3 position = assembledVertex.position; @@ -35,19 +42,22 @@ VertexStageOutput vertexMain(AssembledVertex assembledVertex) { output.sv_position = mul( float4(position, 1.0), - mul(u_Model, mul(u_View, u_Projection)) + mul(uniforms.mvp.model, mul(uniforms.mvp.view, uniforms.mvp.projection)) ); return output; } [shader("fragment")] -Fragment fragmentMain(float2 uv: UV) : SV_Target { +Fragment fragmentMain( + uniform ParameterBlock uniforms, + float2 uv: UV +) : SV_Target { Fragment output; - if(u_HasTexture) { - output.color = u_Texture.Sample(uv) * u_Color; + if(uniforms.u_HasTexture) { + output.color = uniforms.u_Texture.Sample(uv) * uniforms.u_Color; } else { - output.color = someFunction(u_Color); + output.color = someFunction(uniforms.u_Color); } return output; } \ No newline at end of file diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 272c8ea1..01ac6add 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -54,6 +54,7 @@ if(DAWN_ENABLE_PHYSICS) endif() # SLANG +set(SLANG_ENABLE_GFX ON CACHE BOOL "Enable GFX" FORCE) FetchContent_Declare( slang GIT_REPOSITORY https://github.com/shader-slang/slang diff --git a/src/dawn/display/shader/IShaderProgram2.hpp b/src/dawn/display/shader/IShaderProgram2.hpp new file mode 100644 index 00000000..df79dbc9 --- /dev/null +++ b/src/dawn/display/shader/IShaderProgram2.hpp @@ -0,0 +1,23 @@ +// Copyright (c) 2024 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "dawn.hpp" + +namespace Dawn { + class IShaderEntry { + + }; + + class IShaderProgram2 { + private: + std::vector entries; + + protected: + + public: + + }; +} \ No newline at end of file diff --git a/src/dawnrpg/game/Game.cpp b/src/dawnrpg/game/Game.cpp index 0e0e627b..abf9bbc3 100644 --- a/src/dawnrpg/game/Game.cpp +++ b/src/dawnrpg/game/Game.cpp @@ -12,6 +12,7 @@ #include "component/RPGMap.hpp" #include "asset/loader/ShaderLoader.hpp" +#include using namespace Dawn; @@ -32,8 +33,16 @@ void Game::initManagers() { auto sl = assetManager->get("shaders/hello-world.slang"); sl->loadImmediately(); + auto code1 = sl->getEntryPointCode("vertexMain"); + std::fstream file("vertexMain.glsl", std::ios::out); + file << code1; + file.close(); + auto code2 = sl->getEntryPointCode("fragmentMain"); + std::fstream file2("fragmentMain.glsl", std::ios::out); + file2 << code2; + file2.close(); } Game::~Game() {