Point lights

This commit is contained in:
Confideo-IOM
2026-08-28 16:36:25 +01:00
parent 30538ae7ab
commit e3d37e3f8a
60 changed files with 458 additions and 184 deletions
@@ -8,6 +8,7 @@
#include "../../ecs/components/HydraRenderableComponent.h"
#include "../../ecs/components/HydraMaterialComponent.h"
#include "../../ecs/components/HydraPhysicsComponent.h"
#include "../../ecs/components/HydraLightComponent.h"
#include "../../buffer/HydraMaterialBufferManager.h"
#include "../../buffer/HydraTextureBufferManager.h"
#include "../../buffer/HydraMaterialBuffer.h"
@@ -22,6 +23,7 @@ void HydraSpawnedLightActor::InitialiseComponents()
_CreateMaterial();
_CreateMesh();
_CreateRenderableComponent();
_CreateLightComponent();
}
void HydraSpawnedLightActor::DeferredInitialiseComponents()
@@ -46,9 +48,9 @@ void HydraSpawnedLightActor::_CreateMesh()
mesh->vertexes.resize(24);
mesh->indexes.resize(36);
float scale_x = 0.3f;
float scale_y = 0.3f;
float scale_z = 0.3f;
float scale_x = 0.1f;
float scale_y = 0.1f;
float scale_z = 0.1f;
float min_x = -0.5f * scale_x;
float min_y = -0.5f * scale_y;
@@ -158,26 +160,41 @@ void HydraSpawnedLightActor::_CreateMesh()
mesh_comp.mesh_state = HYDRA_STATE::Waiting;
ecs->AddComponent<HydraMeshComponent>(GetID(), mesh_comp);
}
void HydraSpawnedLightActor::_CreateMaterial()
{
HydraEngine *engine = GetEngine();
std::string filename = std::string(texture_base) + std::string("/DesignArea/DesignArea_Albedo.png");
//std::string filename = std::string(texture_base) + std::string("/DesignArea/DesignArea_Albedo.png");
HydraID tex_id = engine->TextureBufferManager()->LoadTexture(filename);
//HydraID tex_id = engine->TextureBufferManager()->LoadTexture(filename);
HydraMaterialBuffer material = {};
std::srand(std::time({})); // use current time as seed for random generator
const float red = static_cast<float>(std::rand() % 2) + 0.1f;
const float green = static_cast<float>(std::rand() % 2)+ 0.1f;
const float blue = static_cast<float>(std::rand() % 2)+ 0.1f;
material.diffuse_texture_id = tex_id;
material.diffuse_colour = glm::vec4(1, 1, 1, 1);
material.metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
//material.diffuse_texture_id = tex_id;
material.diffuse_colour = glm::vec4(glm::normalize(glm::vec3(red, green, blue)), 1) * 10.0f;
material.emmissive_metalic_rough = glm::vec4(10.0f, 0.5f, 0.2f, 1.0f);
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
HydraMaterialComponent mat_comp = {};
mat_comp.material_id = mat_id;
engine->ECS()->AddComponent<HydraMaterialComponent>(GetID(), mat_comp);
HydraLightComponent light_comp = {};
HydraECS *ecs = GetEngine()->ECS();
light_comp.diffuse = glm::vec4(glm::normalize(glm::vec3(red, green, blue)), 1);
light_comp.intensity = 100.0f;
light_comp.light_type = static_cast<uint32_t>(HYDRA_LIGHT_TYPE::HYDRA_LIGHT_POINT);
light_comp.entity_id = GetID();
ecs->AddComponent<HydraLightComponent>(GetID(), light_comp);
}
void HydraSpawnedLightActor::_CreatePhysics()
@@ -188,9 +205,9 @@ void HydraSpawnedLightActor::_CreatePhysics()
phys_comp.phyics_type = HYDRA_PHYSICS_TYPE::HYDRA_RIGID_BODY;
phys_comp.physics_shape = HYDRA_PHYSICS_SHAPE::HYDRA_PHYSICS_BOX;
phys_comp.depth = 0.3f;
phys_comp.height = 0.3f;
phys_comp.width = 0.3f;
phys_comp.depth = 0.1f;
phys_comp.height = 0.1f;
phys_comp.width = 0.1f;
engine->ECS()->AddComponent<HydraPhysicsComponent>(GetID(), phys_comp);
}
@@ -198,6 +215,12 @@ void HydraSpawnedLightActor::_CreateRenderableComponent()
{
HydraRenderableComponent render_comp;
HydraECS *ecs = GetEngine()->ECS();
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR, true);
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR, true);
ecs->AddComponent<HydraRenderableComponent>(GetID(), render_comp);
}
void HydraSpawnedLightActor::_CreateLightComponent()
{
}