First pass of new shader manager

This commit is contained in:
2023-04-04 21:49:20 -07:00
parent a52f54b3e6
commit 095a60e5dc
26 changed files with 302 additions and 31 deletions

View File

@ -8,4 +8,5 @@ target_sources(${DAWN_TARGET_NAME}
PRIVATE
ShaderProgram.cpp
SimpleTexturedShader.cpp
SimpleBillboardedShader.cpp
)

View File

@ -4,6 +4,8 @@
// https://opensource.org/licenses/MIT
#include "SimpleBillboardedShader.hpp"
#include "scene/components/display/mesh/MeshRenderer.hpp"
#include "scene/components/display/Camera.hpp"
using namespace Dawn;
@ -25,9 +27,9 @@ void SimpleBillboardedShaderProgram::compile() {
"out vec2 o_TextCoord;\n"
"void main() {\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"
"vec3 camRight = vec3(u_View[0][0], u_View[1][0], u_View[2][0]);\n"
"vec3 camUp = vec3(u_View[0][1], u_View[1][1], u_View[2][1]);\n"
"vec3 billboardPos = u_View[3].xyz + aPos.x * camRight + aPos.y * camUp;\n"
"gl_Position = u_Proj * u_View * u_Model * vec4(billboardPos, 1.0);\n"
"o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);\n"
"}",
@ -56,4 +58,43 @@ void SimpleBillboardedShaderProgram::compile() {
this->paramColor = this->getParameterByName("u_Color");
this->paramTexture = this->getParameterByName("u_Text");
this->paramHasTexture = this->getParameterByName("u_HasTexture");
}
void SimpleBillboardedShader::compile() {
this->program.compile();
}
std::vector<struct ShaderPassItem> SimpleBillboardedShader::getPassItems(
Mesh *mesh,
Material *material,
Camera *camera
) {
auto simpleMaterial = dynamic_cast<SimpleBillboardedMaterial*>(material);
assertNotNull(simpleMaterial);
struct ShaderPassItem onlyPass;
onlyPass.mesh = mesh;
onlyPass.shaderProgram = &program;
onlyPass.colorValues[program.paramColor] = simpleMaterial->color;
onlyPass.matrixValues[program.paramModel] = material->transform->getWorldTransform();
onlyPass.matrixValues[program.paramView] = camera->transform->getWorldTransform();
onlyPass.matrixValues[program.paramProjection] = camera->getProjection();
onlyPass.renderFlags = (
RENDER_MANAGER_RENDER_FLAG_BLEND |
RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST
);
if(simpleMaterial->texture != nullptr) {
onlyPass.boolValues[program.paramHasTexture] = true;
onlyPass.textureSlots[0] = simpleMaterial->texture;
onlyPass.textureValues[program.paramTexture] = 0;
} else {
onlyPass.boolValues[program.paramHasTexture] = false;
}
std::vector<struct ShaderPassItem> passes;
passes.push_back(onlyPass);
return passes;
}

View File

@ -4,10 +4,10 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "display/shader/Shader.hpp"
#include "scene/components/display/material/SimpleBillboardedMaterial.hpp"
namespace Dawn {
class SimpleBillboardedShader : public ShaderProgram {
class SimpleBillboardedShaderProgram : public ShaderProgram {
public:
shaderparameter_t paramProjection;
shaderparameter_t paramView;

View File

@ -4,7 +4,7 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "display/shader/Shader.hpp"
#include "display/shader/ShaderManager.hpp"
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
namespace Dawn {