ADD: Load Material to shader
This commit is contained in:
parent
0b2f7ba60f
commit
86e15013d0
BIN
assets/models/chess_blue.png
Normal file
BIN
assets/models/chess_blue.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 367 B |
@ -3,8 +3,10 @@
|
||||
in vec2 pass_textureCoords;
|
||||
|
||||
uniform sampler2D textureSampler;
|
||||
uniform float opacity;
|
||||
out vec4 fragColor;
|
||||
|
||||
void main() {
|
||||
fragColor = texture(textureSampler, pass_textureCoords);
|
||||
vec4 texColor = texture(textureSampler, pass_textureCoords);
|
||||
fragColor = vec4(texColor.rgb, texColor.a * opacity);
|
||||
}
|
||||
@ -50,3 +50,8 @@ void Model::drawSection(const std::string& name) const {
|
||||
reinterpret_cast<const void*>(it->indexOffset * sizeof(unsigned int)));
|
||||
unbind();
|
||||
}
|
||||
|
||||
void Model::drawSectionRange(unsigned int indexOffset, unsigned int indexCount) const {
|
||||
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(indexCount), GL_UNSIGNED_INT,
|
||||
reinterpret_cast<const void*>(indexOffset * sizeof(unsigned int)));
|
||||
}
|
||||
|
||||
@ -20,11 +20,13 @@ namespace engine {
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
void draw() const;
|
||||
void drawSection(const std::string& name) const; // neu
|
||||
void drawSection(const std::string& name) const;
|
||||
void drawSectionRange(unsigned int indexOffset, unsigned int indexCount) const;
|
||||
|
||||
[[nodiscard]] int getVertexCount() const { return m_vertexCount; }
|
||||
[[nodiscard]] bool isIndexed() const { return m_isIndexed; }
|
||||
[[nodiscard]] bool hasSections() const { return !m_sections.empty(); }
|
||||
[[nodiscard]] const std::vector<MeshSection>& getSections() const { return m_sections; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<Vao> m_vao;
|
||||
|
||||
@ -13,7 +13,11 @@ void engine::MeshRenderer::render(RenderQueue &queue, const Camera &camera) {
|
||||
m_shader->loadTransformationMatrix(transformationMatrix);
|
||||
|
||||
mesh->bind();
|
||||
mesh->draw();
|
||||
for (const auto& section : mesh->getSections()) {
|
||||
m_shader->loadMaterial(*section.material);
|
||||
section.material->bind();
|
||||
mesh->drawSectionRange(section.indexOffset, section.indexCount);
|
||||
}
|
||||
mesh->unbind();
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#define COLORRACE_STATICSHADER_H
|
||||
#include <functional>
|
||||
|
||||
#include "loader/models/Material.h"
|
||||
#include "utils/openglWrapper/shader/ShaderProgram.h"
|
||||
#include "utils/openglWrapper/shader/UniformValue.h"
|
||||
|
||||
@ -17,7 +18,8 @@ namespace engine {
|
||||
storeAllUniformLocations({
|
||||
std::ref(transformationMatrix),
|
||||
std::ref(projectionMatrix),
|
||||
std::ref(viewMatrix)
|
||||
std::ref(viewMatrix),
|
||||
std::ref(opacity)
|
||||
});
|
||||
};
|
||||
|
||||
@ -32,11 +34,17 @@ namespace engine {
|
||||
void loadViewMatrix(const glm::mat4& matrix) {
|
||||
viewMatrix.load(matrix);
|
||||
}
|
||||
|
||||
void loadMaterial(const Material& material) {
|
||||
//shininess.load(material.getShininess());
|
||||
opacity.load(material.getOpacity());
|
||||
}
|
||||
private:
|
||||
engine::UniformValue<glm::mat4> transformationMatrix{"transformationMatrix"};
|
||||
engine::UniformValue<glm::mat4> projectionMatrix{"projectionMatrix"};
|
||||
engine::UniformValue<glm::mat4> viewMatrix{"viewMatrix"};
|
||||
|
||||
engine::UniformValue<float> shininess{"shininess"};
|
||||
engine::UniformValue<float> opacity{"opacity"};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user