Adding a really basic ambient light component

This commit is contained in:
2022-10-23 17:33:49 +02:00
parent adf2331ab1
commit f0984b6117
7 changed files with 67 additions and 19 deletions

View File

@ -35,10 +35,8 @@ void GUIManager::Render()
ImGui::NewFrame();
ImGui::Begin("##App");
ImmediateGraphicsDraw();
ImGui::End();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

View File

@ -48,16 +48,20 @@ void BarinkEngine::Renderer::Prepare(Scene& scene ) {
void BarinkEngine::Renderer::Render(Scene& scene)
{
auto group = scene.getReg().view<TransformComponent, Render3DComponent>();
group.each([](auto entity , TransformComponent& trans, Render3DComponent& renderComponent)
group.each([&](auto entity , TransformComponent& trans, Render3DComponent& renderComponent)
{
glBindVertexArray(renderComponent.VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, renderComponent.IBO);
renderComponent.shader.Use();
renderComponent.shader.setUniformVec3("Color", renderComponent.color);
auto lights = scene.getReg().view<LightComponent>();
lights.each([&](auto entity, LightComponent& light) {
renderComponent.shader.setUniformVec3("lighting.color", light.Color);
renderComponent.shader.setUniformFloat("lighting.strength", light.Strength);
});
renderComponent.shader.setUniformVec3("Color", renderComponent.color);
renderComponent.shader.setUniformMat4("M", trans.transform);
renderComponent.shader.setUniformMat4("V", cam.GetViewMatrix());
renderComponent.shader.setUniformMat4("P", projection);

View File

@ -39,7 +39,7 @@ inline void SamplePerformance(void) {
inline void ShowStats() {
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize );
ImGui::Text("FPS: %i", ES.FPS);
ImGui::Text("Frame Time: %f", ES.frameTime);

View File

@ -12,6 +12,12 @@ namespace BarinkEngine {
};
struct LightComponent {
float Strength = 1.0f;
glm::vec3 Color = glm::vec3(1.0f, 1.0f, 1.0f);
};
struct CameraComponent {
glm::mat4 view;
@ -22,7 +28,6 @@ namespace BarinkEngine {
unsigned int VAO = 0;
unsigned int IBO = 0;
Mesh mesh;
// TODO: becomes a material
glm::vec3 color;
Shader shader;

View File

@ -8,11 +8,12 @@ Scene::Scene()
Scene::~Scene()
{}
Entity Scene::AddEntity(std::string& name)
Entity Scene::AddEntity(std::string name)
{
Entity entity = { m_registry.create(), this };
entity.AddComponent<BarinkEngine::IdentifierComponent>();
auto& ident = entity.AddComponent<BarinkEngine::IdentifierComponent>();
ident.name = name;
entity.AddComponent<BarinkEngine::TransformComponent>();

View File

@ -9,7 +9,7 @@ public:
Scene();
~Scene();
Entity AddEntity(std::string& name);
Entity AddEntity(std::string name);
entt::registry& getReg() { return m_registry; }