add hit "animation"

This commit is contained in:
2023-01-02 16:37:18 +01:00
parent 1200a6e087
commit fcda12e321
7 changed files with 109 additions and 83 deletions

View File

@@ -70,6 +70,7 @@ void Renderer::RenderVAO(const GL::VertexArray& vao) {
void Renderer::RenderModel(const Model& model) {
m_EntityShader->Start();
m_EntityShader->SetModelPos(model.positon);
m_EntityShader->SetColorEffect(model.color);
model.vao->Bind();
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(model.vao->GetVertexCount()));
model.vao->Unbind();

View File

@@ -87,6 +87,7 @@ void WorldRenderer::RenderMobs() const {
Renderer::Model model;
model.vao = m_MobVao.get();
model.positon = { mob->GetCenterX(), mob->GetCenterY() };
model.color = mob->HasTakenDamage() ? Vec3f{ 1, 0.5, 0.5 } : Vec3f{ 1, 1, 1 };
m_Renderer->RenderModel(model);
}
}

View File

@@ -39,13 +39,16 @@ flat in int pass_color;
out vec4 out_color;
uniform vec3 ColorEffect;
void main(void){
float r = float(pass_color >> 24 & 0xFF) / 255.0;
float g = float(pass_color >> 16 & 0xFF) / 255.0;
float b = float(pass_color >> 8 & 0xFF) / 255.0;
float a = float(pass_color & 0xFF) / 255.0;
out_color = vec4(r, g, b, a);
vec3 intermediate_color = vec3(r, g, b) * ColorEffect;
out_color = vec4(intermediate_color, a);
}
)";
@@ -81,13 +84,16 @@ flat in int pass_color;
out vec4 out_color;
uniform vec3 ColorEffect;
void main(void){
float r = float(pass_color >> 24 & 0xFF) / 255.0;
float g = float(pass_color >> 16 & 0xFF) / 255.0;
float b = float(pass_color >> 8 & 0xFF) / 255.0;
float a = float(pass_color & 0xFF) / 255.0;
out_color = vec4(r, g, b, a);
float a = float(pass_color & 0xFF) / 255.0;
vec3 intermediate_color = vec3(r, g, b) * ColorEffect;
out_color = vec4(intermediate_color, a);
}
)";
@@ -105,6 +111,7 @@ void EntityShader::GetAllUniformLocation() {
m_LocationCam = static_cast<unsigned int>(GetUniformLocation("camPos"));
m_LocationTranslation = static_cast<unsigned int>(GetUniformLocation("translation"));
m_LocationViewtype = static_cast<unsigned int>(GetUniformLocation("isometricView"));
m_LocationColorEffect = static_cast<unsigned int>(GetUniformLocation("ColorEffect"));
}
void EntityShader::SetCamPos(const Vec2f& camPos) {
@@ -122,7 +129,9 @@ void EntityShader::SetModelPos(const Vec2f& modelPos) {
void EntityShader::SetIsometricView(float isometric) {
LoadFloat(m_LocationViewtype, isometric);
}
void EntityShader::SetColorEffect(const Vec3f& color) {
LoadVector(m_LocationColorEffect, color);
}
} // namespace shader
} // namespace td