This commit is contained in:
2024-12-23 16:14:50 -06:00
parent c87f13b063
commit 698aeb2afc
4 changed files with 54 additions and 11 deletions

View File

@ -1,10 +1,14 @@
cbuffer Uniforms { struct MVP {
float4x4 u_Projection; float4x4 projection;
float4x4 u_View; float4x4 view;
float4x4 u_Model; float4x4 model;
}
struct Uniforms {
MVP mvp;
float4 u_Color; float4 u_Color;
bool u_HasTexture; bool u_HasTexture;
uniform Sampler2D u_Texture; Sampler2D u_Texture;
}; };
struct AssembledVertex { struct AssembledVertex {
@ -26,7 +30,10 @@ float4 someFunction(float4 color) {
} }
[shader("vertex")] [shader("vertex")]
VertexStageOutput vertexMain(AssembledVertex assembledVertex) { VertexStageOutput vertexMain(
uniform ParameterBlock<Uniforms> uniforms,
AssembledVertex assembledVertex
) {
VertexStageOutput output; VertexStageOutput output;
float3 position = assembledVertex.position; float3 position = assembledVertex.position;
@ -35,19 +42,22 @@ VertexStageOutput vertexMain(AssembledVertex assembledVertex) {
output.sv_position = mul( output.sv_position = mul(
float4(position, 1.0), 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; return output;
} }
[shader("fragment")] [shader("fragment")]
Fragment fragmentMain(float2 uv: UV) : SV_Target { Fragment fragmentMain(
uniform ParameterBlock<Uniforms> uniforms,
float2 uv: UV
) : SV_Target {
Fragment output; Fragment output;
if(u_HasTexture) { if(uniforms.u_HasTexture) {
output.color = u_Texture.Sample(uv) * u_Color; output.color = uniforms.u_Texture.Sample(uv) * uniforms.u_Color;
} else { } else {
output.color = someFunction(u_Color); output.color = someFunction(uniforms.u_Color);
} }
return output; return output;
} }

View File

@ -54,6 +54,7 @@ if(DAWN_ENABLE_PHYSICS)
endif() endif()
# SLANG # SLANG
set(SLANG_ENABLE_GFX ON CACHE BOOL "Enable GFX" FORCE)
FetchContent_Declare( FetchContent_Declare(
slang slang
GIT_REPOSITORY https://github.com/shader-slang/slang GIT_REPOSITORY https://github.com/shader-slang/slang

View File

@ -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<IShaderEntry> entries;
protected:
public:
};
}

View File

@ -12,6 +12,7 @@
#include "component/RPGMap.hpp" #include "component/RPGMap.hpp"
#include "asset/loader/ShaderLoader.hpp" #include "asset/loader/ShaderLoader.hpp"
#include <fstream>
using namespace Dawn; using namespace Dawn;
@ -32,8 +33,16 @@ void Game::initManagers() {
auto sl = assetManager->get<ShaderLoader>("shaders/hello-world.slang"); auto sl = assetManager->get<ShaderLoader>("shaders/hello-world.slang");
sl->loadImmediately(); sl->loadImmediately();
auto code1 = sl->getEntryPointCode("vertexMain"); auto code1 = sl->getEntryPointCode("vertexMain");
std::fstream file("vertexMain.glsl", std::ios::out);
file << code1;
file.close();
auto code2 = sl->getEntryPointCode("fragmentMain"); auto code2 = sl->getEntryPointCode("fragmentMain");
std::fstream file2("fragmentMain.glsl", std::ios::out);
file2 << code2;
file2.close();
} }
Game::~Game() { Game::~Game() {