idk shaders
This commit is contained in:
@ -8,5 +8,4 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
ShaderProgram.cpp
|
||||
SimpleTexturedShader.cpp
|
||||
SimpleTexturedShaderProgram.cpp
|
||||
)
|
@ -3,11 +3,11 @@
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SimpleTexturedShaderProgram.hpp"
|
||||
#include "SimpleBillboardedShader.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void SimpleTexturedShaderProgram::compile() {
|
||||
void SimpleBillboardedShaderProgram::compile() {
|
||||
#if DAWN_OPENGL_GLSL
|
||||
this->compileShader(
|
||||
{
|
||||
@ -25,7 +25,10 @@ void SimpleTexturedShaderProgram::compile() {
|
||||
|
||||
"out vec2 o_TextCoord;\n"
|
||||
"void main() {\n"
|
||||
"gl_Position = u_Proj * u_View * u_Model * vec4(aPos, 1.0);\n"
|
||||
"vec3 camRight = vec3(view[0][0], view[1][0], view[2][0]);\n"
|
||||
"vec3 camUp = vec3(view[0][1], view[1][1], view[2][1]);\n"
|
||||
"vec3 billboardPos = view[3].xyz + position.x * camRight + position.y * camUp;\n"
|
||||
"gl_Position = u_Proj * u_View * u_Model * vec4(billboardPos, 1.0);\n"
|
||||
"o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);\n"
|
||||
"}",
|
||||
|
||||
@ -45,45 +48,6 @@ void SimpleTexturedShaderProgram::compile() {
|
||||
"}\n"
|
||||
"}\n"
|
||||
);
|
||||
#elif DAWN_OPENGL_HLSL
|
||||
this->compileShader(
|
||||
{
|
||||
{ "aPos", 0 },
|
||||
{ "aTexCoord", 1 }
|
||||
},
|
||||
// Vertex Shader
|
||||
"uniform float4x4 u_Proj;\n"
|
||||
"uniform float4x4 u_View;\n"
|
||||
"uniform float4x4 u_Model;\n"
|
||||
"void main("
|
||||
"float3 aPos,\n"
|
||||
"float2 aTexCoord,\n"
|
||||
"float2 out o_TextCoord : TEXCOORD0,\n"
|
||||
"float4 out gl_Position : POSITION\n"
|
||||
") {\n"
|
||||
"o_TextCoord = aTexCoord;\n"
|
||||
"gl_Position = mul(mul(mul(float4(aPos, 1.0), u_Model), u_View), u_Proj);\n"
|
||||
"}",
|
||||
|
||||
// Fragment Shader
|
||||
"uniform float4 u_Color;\n"
|
||||
"uniform bool u_HasTexture;\n"
|
||||
"uniform sampler2D u_Text : TEXUNIT0;\n"
|
||||
|
||||
"float4 main(\n"
|
||||
"float2 o_TextCoord : TEXCOORD0\n"
|
||||
") {\n"
|
||||
"float4 o_Color;\n"
|
||||
"if(u_HasTexture) {\n"
|
||||
"o_Color = mul(tex2D(u_Text, o_TextCoord), u_Color);\n"
|
||||
"} else {\n"
|
||||
"o_Color = u_Color;\n"
|
||||
"}\n"
|
||||
"return o_Color;\n"
|
||||
"}\n"
|
||||
);
|
||||
#else
|
||||
#error Shader Type must be either GLSL or HLSL
|
||||
#endif
|
||||
|
||||
this->paramProjection = this->getParameterByName("u_Proj");
|
34
src/dawnopengl/display/shader/SimpleBillboardedShader.hpp
Normal file
34
src/dawnopengl/display/shader/SimpleBillboardedShader.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/shader/Shader.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SimpleBillboardedShader : public ShaderProgram {
|
||||
public:
|
||||
shaderparameter_t paramProjection;
|
||||
shaderparameter_t paramView;
|
||||
shaderparameter_t paramModel;
|
||||
shaderparameter_t paramColor;
|
||||
shaderparameter_t paramTexture;
|
||||
shaderparameter_t paramHasTexture;
|
||||
|
||||
void compile() override;
|
||||
};
|
||||
|
||||
class SimpleBillboardedShader : public Shader {
|
||||
public:
|
||||
SimpleBillboardedShaderProgram program;
|
||||
|
||||
void compile() override;
|
||||
|
||||
std::vector<struct ShaderPassItem> getPassItems(
|
||||
Mesh *mesh,
|
||||
Material *material,
|
||||
Camera *camera
|
||||
) override;
|
||||
};
|
||||
}
|
@ -9,6 +9,95 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void SimpleTexturedShaderProgram::compile() {
|
||||
#if DAWN_OPENGL_GLSL
|
||||
this->compileShader(
|
||||
{
|
||||
{ "aPos", 0 },
|
||||
{ "aTexCoord", 1 }
|
||||
},
|
||||
// Vertex Shader
|
||||
"#version 330 core\n"
|
||||
"layout (location = 0) in vec3 aPos;\n"
|
||||
"layout (location = 1) in vec2 aTexCoord;\n"
|
||||
|
||||
"uniform mat4 u_Proj;\n"
|
||||
"uniform mat4 u_View;\n"
|
||||
"uniform mat4 u_Model;\n"
|
||||
|
||||
"out vec2 o_TextCoord;\n"
|
||||
"void main() {\n"
|
||||
"gl_Position = u_Proj * u_View * u_Model * vec4(aPos, 1.0);\n"
|
||||
"o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);\n"
|
||||
"}",
|
||||
|
||||
// Fragment Shader
|
||||
"#version 330 core\n"
|
||||
"in vec2 o_TextCoord;\n"
|
||||
"out vec4 o_Color;\n"
|
||||
"uniform vec4 u_Color;\n"
|
||||
"uniform bool u_HasTexture;\n"
|
||||
"uniform sampler2D u_Text;\n"
|
||||
|
||||
"void main() {\n"
|
||||
"if(u_HasTexture) {\n"
|
||||
"o_Color = texture(u_Text, o_TextCoord) * u_Color;\n"
|
||||
"} else {\n"
|
||||
"o_Color = u_Color;"
|
||||
"}\n"
|
||||
"}\n"
|
||||
);
|
||||
#elif DAWN_OPENGL_HLSL
|
||||
this->compileShader(
|
||||
{
|
||||
{ "aPos", 0 },
|
||||
{ "aTexCoord", 1 }
|
||||
},
|
||||
// Vertex Shader
|
||||
"uniform float4x4 u_Proj;\n"
|
||||
"uniform float4x4 u_View;\n"
|
||||
"uniform float4x4 u_Model;\n"
|
||||
"void main("
|
||||
"float3 aPos,\n"
|
||||
"float2 aTexCoord,\n"
|
||||
"float2 out o_TextCoord : TEXCOORD0,\n"
|
||||
"float4 out gl_Position : POSITION\n"
|
||||
") {\n"
|
||||
"o_TextCoord = aTexCoord;\n"
|
||||
"gl_Position = mul(mul(mul(float4(aPos, 1.0), u_Model), u_View), u_Proj);\n"
|
||||
"}",
|
||||
|
||||
// Fragment Shader
|
||||
"uniform float4 u_Color;\n"
|
||||
"uniform bool u_HasTexture;\n"
|
||||
"uniform sampler2D u_Text : TEXUNIT0;\n"
|
||||
|
||||
"float4 main(\n"
|
||||
"float2 o_TextCoord : TEXCOORD0\n"
|
||||
") {\n"
|
||||
"float4 o_Color;\n"
|
||||
"if(u_HasTexture) {\n"
|
||||
"o_Color = mul(tex2D(u_Text, o_TextCoord), u_Color);\n"
|
||||
"} else {\n"
|
||||
"o_Color = u_Color;\n"
|
||||
"}\n"
|
||||
"return o_Color;\n"
|
||||
"}\n"
|
||||
);
|
||||
#else
|
||||
#error Shader Type must be either GLSL or HLSL
|
||||
#endif
|
||||
|
||||
this->paramProjection = this->getParameterByName("u_Proj");
|
||||
this->paramView = this->getParameterByName("u_View");
|
||||
this->paramModel = this->getParameterByName("u_Model");
|
||||
this->paramColor = this->getParameterByName("u_Color");
|
||||
this->paramTexture = this->getParameterByName("u_Text");
|
||||
this->paramHasTexture = this->getParameterByName("u_HasTexture");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SimpleTexturedShader::compile() {
|
||||
this->program.compile();
|
||||
}
|
||||
|
@ -5,10 +5,21 @@
|
||||
|
||||
#pragma once
|
||||
#include "display/shader/Shader.hpp"
|
||||
#include "SimpleTexturedShaderProgram.hpp"
|
||||
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SimpleTexturedShaderProgram : public ShaderProgram {
|
||||
public:
|
||||
shaderparameter_t paramProjection;
|
||||
shaderparameter_t paramView;
|
||||
shaderparameter_t paramModel;
|
||||
shaderparameter_t paramColor;
|
||||
shaderparameter_t paramTexture;
|
||||
shaderparameter_t paramHasTexture;
|
||||
|
||||
void compile() override;
|
||||
};
|
||||
|
||||
class SimpleTexturedShader : public Shader {
|
||||
public:
|
||||
SimpleTexturedShaderProgram program;
|
||||
|
@ -1,21 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/shader/Shader.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SimpleTexturedShaderProgram : public ShaderProgram {
|
||||
public:
|
||||
shaderparameter_t paramProjection;
|
||||
shaderparameter_t paramView;
|
||||
shaderparameter_t paramModel;
|
||||
shaderparameter_t paramColor;
|
||||
shaderparameter_t paramTexture;
|
||||
shaderparameter_t paramHasTexture;
|
||||
|
||||
void compile() override ;
|
||||
};
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "SimpleTexturedShaderProgram.hpp"
|
||||
#include "SimpleTexturedShader.hpp"
|
||||
|
||||
#define UI_SHADER_PROGRAM_PRIORITY 100
|
||||
|
||||
|
Reference in New Issue
Block a user