slang
This commit is contained in:
		@@ -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> 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> 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;
 | 
			
		||||
}
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										23
									
								
								src/dawn/display/shader/IShaderProgram2.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/dawn/display/shader/IShaderProgram2.hpp
									
									
									
									
									
										Normal 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:
 | 
			
		||||
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
@@ -12,6 +12,7 @@
 | 
			
		||||
#include "component/RPGMap.hpp"
 | 
			
		||||
 | 
			
		||||
#include "asset/loader/ShaderLoader.hpp"
 | 
			
		||||
#include <fstream>
 | 
			
		||||
 | 
			
		||||
using namespace Dawn;
 | 
			
		||||
 | 
			
		||||
@@ -32,8 +33,16 @@ void Game::initManagers() {
 | 
			
		||||
 | 
			
		||||
  auto sl = assetManager->get<ShaderLoader>("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() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user