Material update, before changing prefabs
This commit is contained in:
@ -1,102 +1,33 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
// 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"
|
||||
#include "scene/components/Components.hpp"
|
||||
#include "SimpleTexturedShaderProgram.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SimpleTexturedShader : public Shader {
|
||||
protected:
|
||||
SimpleTexturedShaderProgram program;
|
||||
|
||||
public:
|
||||
shaderparameter_t paramProjection;
|
||||
shaderparameter_t paramView;
|
||||
shaderparameter_t paramModel;
|
||||
shaderparameter_t paramColor;
|
||||
shaderparameter_t paramTexture;
|
||||
shaderparameter_t paramHasTexture;
|
||||
|
||||
std::map<shaderparameter_t, enum ShaderParameterType>
|
||||
getParameters() override {
|
||||
std::map<shaderparameter_t, enum ShaderParameterType> ps;
|
||||
|
||||
ps[this->paramColor] = SHADER_PARAMETER_TYPE_COLOR;
|
||||
ps[this->paramHasTexture] = SHADER_PARAMETER_TYPE_BOOLEAN;
|
||||
ps[this->paramTexture] = SHADER_PARAMETER_TYPE_TEXTURE;
|
||||
|
||||
return ps;
|
||||
}
|
||||
|
||||
void setDefaultParameters(Material *material) override {
|
||||
material->colorValues[this->paramColor] = COLOR_WHITE;
|
||||
material->textureValues[this->paramTexture] = nullptr;
|
||||
}
|
||||
|
||||
void setGlobalParameters(glm::mat4 proj, glm::mat4 view) override {
|
||||
this->setMatrix(this->paramProjection, proj);
|
||||
this->setMatrix(this->paramView, view);
|
||||
}
|
||||
|
||||
void setMeshParameters(glm::mat4 transform) override {
|
||||
this->setMatrix(this->paramModel, transform);
|
||||
}
|
||||
|
||||
void bindTexture(
|
||||
shaderparameter_t param,
|
||||
Texture *texture
|
||||
) override {
|
||||
if(texture == nullptr || !texture->isReady()) {
|
||||
this->setBoolean(this->paramHasTexture, false);
|
||||
} else {
|
||||
this->setBoolean(this->paramHasTexture, true);
|
||||
this->setTextureSlot(param, 0x01);
|
||||
texture->bind(0x01);
|
||||
}
|
||||
}
|
||||
|
||||
void compile() override {
|
||||
this->compileShader(
|
||||
// Vertex Shader
|
||||
"#version 330 core\n"
|
||||
"layout (location = 0) in vec3 aPos;\n"
|
||||
"layout (location = 1) in vec2 aTexCoord;\n"
|
||||
this->program.compile();
|
||||
}
|
||||
|
||||
"uniform mat4 u_Proj;\n"
|
||||
"uniform mat4 u_View;\n"
|
||||
"uniform mat4 u_Model;\n"
|
||||
std::vector<struct ShaderPass> getItemPasses(
|
||||
MeshRenderer *mesh,
|
||||
Material *material
|
||||
) override {
|
||||
return std::vector<struct ShaderPass>();
|
||||
}
|
||||
|
||||
"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"
|
||||
);
|
||||
|
||||
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");
|
||||
|
||||
this->setBoolean(this->paramHasTexture, false);
|
||||
void setGlobalParameters(
|
||||
glm::mat4 cameraProjection,
|
||||
glm::mat4 cameraView
|
||||
) override {
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user