Point lights
This commit is contained in:
@@ -12,7 +12,7 @@ bool HydraGame::Initialise()
|
||||
GetEngine()->ActorManager()->InitialiseActor(m_spawner_id);
|
||||
GetEngine()->ActorManager()->SetPosition(m_spawner_id, glm::dvec3(0, 1.0, 0));
|
||||
HydraLightSpawnerActor* actor = static_cast<HydraLightSpawnerActor*>(GetEngine()->ActorManager()->GetActor(m_spawner_id));
|
||||
actor->SpawnSettings(2.0f, glm::vec3(0.0f, 2.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 10.0f, 0.0f, 20.0f);
|
||||
actor->SpawnSettings(3.0f, glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 15.0f, 0.0f, 50.0f);
|
||||
actor->SetEnabled(true);
|
||||
|
||||
|
||||
@@ -35,12 +35,12 @@ bool HydraGame::Initialise()
|
||||
// m_cube_actor_id = GetEngine()->ActorManager()->CreateActor<HydraTestCubeActor>();
|
||||
// GetEngine()->ActorManager()->InitialiseActor(m_cube_actor_id);
|
||||
// GetEngine()->ActorManager()->SetPosition(m_cube_actor_id, glm::dvec3(0, 1.0, 0));
|
||||
// GetEngine()->ActorManager()->SetLinearVelocity(m_cube_actor_id, glm::dvec3(0, 10.0, 0));
|
||||
// GetEngine()->ActorManager()->SetLinearVelocity(m_cube_actor_id, glm::vec3(0,20,0));
|
||||
|
||||
m_plane_actor_id = GetEngine()->ActorManager()->CreateActor<HydraPlaneActor>();
|
||||
GetEngine()->ActorManager()->InitialiseActor(m_plane_actor_id);
|
||||
GetEngine()->ActorManager()->SetPosition(m_plane_actor_id, glm::dvec3(0, 0, 0));
|
||||
GetEngine()->ActorManager()->SetOrientation(m_plane_actor_id, 0.0f, 0.0f, 0.2f);
|
||||
GetEngine()->ActorManager()->SetOrientation(m_plane_actor_id, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
|
||||
// m_plane_actor_id1 = GetEngine()->ActorManager()->CreateActor<HydraPlaneActor>();
|
||||
|
||||
@@ -45,7 +45,7 @@ const uint32_t MAX_DIRECTIONAL_SHADOWS = 10;
|
||||
const uint32_t MAX_SPOT_SHADOWS = 10;
|
||||
const uint32_t MAX_POINT_SHADOWS = 10;
|
||||
//const uint32_t SHADOW_MAP_SIZE = 1024;
|
||||
const uint32_t DIRECTIONAL_SHADOW_MAP_SIZE = 4096;
|
||||
const uint32_t DIRECTIONAL_SHADOW_MAP_SIZE = 2048;
|
||||
const uint32_t SPOT_SHADOW_MAP_SIZE = 1024;
|
||||
const uint32_t POINT_SHADOW_MAP_SIZE = 2048;
|
||||
|
||||
@@ -65,7 +65,7 @@ enum class HYDRA_PHYSICS_SHAPE
|
||||
enum class HYDRA_RENDERABLE_TYPE
|
||||
{
|
||||
HYDRA_COLOUR = 1,
|
||||
HYDRA_SHADOW,
|
||||
HYDRA_SHADOW_CASTER,
|
||||
HYDRA_TRANSPARENT,
|
||||
HYDRA_LIGHTING,
|
||||
HYDRA_OUTPUT,
|
||||
|
||||
@@ -232,7 +232,7 @@ vec3 DirectionalShading(vec3 normal,
|
||||
{
|
||||
|
||||
float distance = length(light_pos - world_pos);
|
||||
float attenuation = 1.0;
|
||||
float attenuation = 3.5;
|
||||
|
||||
vec3 radiance = diffuse * attenuation;
|
||||
|
||||
@@ -251,10 +251,12 @@ vec3 PointShading(vec3 normal,
|
||||
float light_constant,
|
||||
float light_linear,
|
||||
float light_quadratic,
|
||||
vec3 light_colour,
|
||||
vec3 world_pos,
|
||||
vec3 view_pos,
|
||||
float shadow_val)
|
||||
{
|
||||
|
||||
float distance = length(light_pos - world_pos);
|
||||
float attenuation = 1.0;
|
||||
|
||||
@@ -263,7 +265,7 @@ vec3 PointShading(vec3 normal,
|
||||
|
||||
vec3 light_dir = normalize(light_pos - world_pos);
|
||||
vec3 Lo = CalculatePBR(normal, view_pos, world_pos, light_dir, diffuse, radiance, roughness, metallic);
|
||||
|
||||
Lo = Lo * light_colour;
|
||||
return Lo;
|
||||
}
|
||||
vec3 SpotShading(vec3 normal,
|
||||
@@ -339,9 +341,17 @@ float SampleCascadeShadow(vec4 frag_clip_space, sampler2DArray sampler_shadow_ma
|
||||
// check whether current frag pos is in shadow
|
||||
// float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
|
||||
// PCF
|
||||
if(shadow_trans_idx < 3)
|
||||
if(shadow_trans_idx < 1)
|
||||
{
|
||||
bias = 0.00001;
|
||||
bias = 0.0000005;
|
||||
}
|
||||
if(shadow_trans_idx < 2)
|
||||
{
|
||||
bias = 0.00005;
|
||||
}
|
||||
else if(shadow_trans_idx < 3)
|
||||
{
|
||||
bias = 0.00005;
|
||||
}
|
||||
else if(shadow_trans_idx == 3)
|
||||
{
|
||||
@@ -351,9 +361,6 @@ float SampleCascadeShadow(vec4 frag_clip_space, sampler2DArray sampler_shadow_ma
|
||||
{
|
||||
bias = 0.0005;
|
||||
}
|
||||
|
||||
|
||||
|
||||
float shadow = 0.0;
|
||||
vec2 texel_size = 1.0 / textureSize(sampler_shadow_map, 0).xy;
|
||||
if((frag_light_space.x >= 0.0)&&(frag_light_space.y >= 0.0)
|
||||
@@ -418,6 +425,12 @@ vec3 CalculateDirectionalShadow(vec4 world_pos, uint shadow_idx, vec3 normal, ve
|
||||
//measure the distance of the fragment from the light
|
||||
float frag_distance = abs(length(viewer_pos - world_pos.xyz));
|
||||
|
||||
float back_face = dot(normal, light_dir);
|
||||
if(back_face < 0)
|
||||
{
|
||||
return vec3(1);
|
||||
}
|
||||
|
||||
uint shadow_trans_idx = 5;
|
||||
uint ignore_shadow = 0;
|
||||
//Work out which shadowmap is appropriate for this distance
|
||||
@@ -548,14 +561,22 @@ void main()
|
||||
float ao = 1;
|
||||
vec3 ambient = vec3(0.05) * diffuse.xyz * ao;
|
||||
vec3 Lo = ambient;
|
||||
if(metal_rough[0] > 0)
|
||||
{
|
||||
uFragColor = vec4(diffuse.xyz * metal_rough[0], diffuse.a);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < ubo_per_frame.light_count; i ++)
|
||||
{
|
||||
mat4 model = model_matrix[lights[i].entity_id];
|
||||
mat3 rot_mat = GetRotationOnlyMatrix(model);
|
||||
vec3 light_direction = normalize(rot_mat * vec3(0,0,1));
|
||||
|
||||
vec3 light_pos = GetPositionFromView(model);
|
||||
light_pos = model[3].xyx;
|
||||
vec4 light_pos_model_space = vec4(0,0,0,1);
|
||||
light_pos_model_space = model * light_pos_model_space;
|
||||
vec3 light_pos = light_pos_model_space.xyz;
|
||||
//vec3 light_pos = GetPositionFromView(model);
|
||||
//light_pos = model[3].xyx;
|
||||
if(lights[i].light_type == HYDRA_LIGHT_DIRECTIONAL)
|
||||
{
|
||||
Lo += DirectionalShading(normal, diffuse.xyz, rough, metal, lights[i].intensity, light_direction, light_pos, world_pos, ubo_per_frame.viewer_pos);
|
||||
@@ -563,6 +584,7 @@ void main()
|
||||
if(lights[i].shadow_caster == 1)
|
||||
{
|
||||
vec3 shadow = CalculateDirectionalShadow(vec4(world_pos, 1.0), lights[i].shadow_map_id, normal, light_direction, ubo_per_frame.viewer_pos);
|
||||
|
||||
Lo = Lo * shadow;
|
||||
|
||||
}
|
||||
@@ -586,6 +608,7 @@ void main()
|
||||
lights[i].constant,
|
||||
lights[i].linear,
|
||||
lights[i].quadratic,
|
||||
lights[i].diffuse.xyz,
|
||||
world_pos,
|
||||
ubo_per_frame.viewer_pos,
|
||||
shadow);
|
||||
@@ -626,11 +649,13 @@ void main()
|
||||
vec3 output_color = Lo;
|
||||
|
||||
// HDR tonemapping
|
||||
output_color = output_color / (output_color + vec3(1.0));
|
||||
// gamma correct
|
||||
output_color = pow(output_color, vec3(1.0/2.1));
|
||||
output_color = output_color / (output_color + vec3(1.0));
|
||||
// gamma correct
|
||||
output_color = pow(output_color, vec3(1.0/2.1));
|
||||
uFragColor = vec4(output_color, 1.0);
|
||||
}
|
||||
|
||||
|
||||
uFragColor = vec4(output_color, 1.0);
|
||||
// float light = dot(lights[0].light_direction, normal);
|
||||
|
||||
// uFragColor = vec4(diffuse.xyz * light,1);
|
||||
|
||||
@@ -2,8 +2,3 @@
|
||||
#include "HydraActorManager.h"
|
||||
#include "../engine/HydraEngine.h"
|
||||
#include "../ecs/HydraECS.h"
|
||||
void HydraActor::Delete()
|
||||
{
|
||||
GetEngine()->ECS()->DestroyEntity(GetID());
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class CLASS_DEFINE HydraActor : public HydraObject
|
||||
std::vector<HydraID> m_children;
|
||||
std::vector<uint32_t> m_component_types;
|
||||
uint32_t m_components_waiting = 0;
|
||||
void Delete();
|
||||
|
||||
friend class HydraActorManager;
|
||||
friend class HydraDeleteActorTask;
|
||||
protected:
|
||||
|
||||
@@ -35,7 +35,7 @@ void HydraActorManager::DeleteActor(HydraID actorID)
|
||||
if(m_actors[actorID] != nullptr)
|
||||
{
|
||||
|
||||
m_actors[actorID]->Delete();
|
||||
GetEngine()->ECS()->DestroyEntity(actorID);
|
||||
_SetActorDeleted(actorID);
|
||||
}
|
||||
|
||||
@@ -194,15 +194,22 @@ void HydraActorManager::SetLinearVelocity(HydraID actor_id, glm::vec3 velocity)
|
||||
void HydraActorManager::SetPositionAndOrientation(HydraID actorID, glm::dvec3 position, glm::vec3 euler_angles, bool ignore_physics)
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
|
||||
HydraPositionComponent &pos_comp = ecs->GetComponent<HydraPositionComponent>(actorID);
|
||||
pos_comp.position = position;
|
||||
pos_comp.orientation = glm::vec3(euler_angles.x,euler_angles.y,euler_angles.z);
|
||||
|
||||
if(!pos_comp.needs_update)
|
||||
if(ecs->HasComponent<HydraPositionComponent>(actorID))
|
||||
{
|
||||
ecs->GetSystem<HydraTransformSystem>()->UpdateTransform(actorID, ignore_physics);
|
||||
HydraPositionComponent &pos_comp = ecs->GetComponent<HydraPositionComponent>(actorID);
|
||||
pos_comp.position = position;
|
||||
pos_comp.orientation = glm::vec3(euler_angles.x,euler_angles.y,euler_angles.z);
|
||||
|
||||
if(!pos_comp.needs_update)
|
||||
{
|
||||
ecs->GetSystem<HydraTransformSystem>()->UpdateTransform(actorID, ignore_physics);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "HERE";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HydraActorManager::SetScale(HydraID actor_id, glm::dvec3 scaling)
|
||||
|
||||
@@ -21,8 +21,8 @@ void HydraDirectionalLightActor::InitialiseComponents()
|
||||
HydraLightComponent light_comp = {};
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
|
||||
light_comp.diffuse = glm::vec4(1.0,0.8,0.6,1);
|
||||
light_comp.intensity = 100000.0f;
|
||||
light_comp.diffuse = glm::vec4(1.0f, 1.0f, 1.0f ,1.0f);
|
||||
light_comp.intensity = 1000.0f;
|
||||
light_comp.light_type = static_cast<uint32_t>(HYDRA_LIGHT_TYPE::HYDRA_LIGHT_DIRECTIONAL);
|
||||
light_comp.entity_id = GetID();
|
||||
light_comp.shadow_caster =1;
|
||||
|
||||
@@ -175,7 +175,7 @@ void HydraPlaneActor::_CreateMaterial()
|
||||
|
||||
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.emmissive_metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
|
||||
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
|
||||
|
||||
HydraMaterialComponent mat_comp = {};
|
||||
|
||||
@@ -47,7 +47,7 @@ void HydraPlayerActor::HandleInput(float delta_t)
|
||||
bool move_right = GetEngine()->KeyPressed(HYDRA_KEY_CODES::HYDRA_KEY_D);
|
||||
|
||||
HydraRenderSettings render_settings = GetEngine()->RenderSettings();
|
||||
float scale = 0.2f;
|
||||
float scale = 1.0f;
|
||||
|
||||
float x_angle = (change.x / render_settings.DisplayWidth) * -500 * delta_t * scale;
|
||||
float y_angle = (change.y / render_settings.DisplayHeight) * -500 * delta_t * scale;
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include "../ecs/components/HydraRenderableComponent.h"
|
||||
#include "../ecs/components/HydraMaterialComponent.h"
|
||||
#include "../ecs/components/HydraPhysicsComponent.h"
|
||||
#include "../ecs/components/HydraShadowCasterComponent.h"
|
||||
#include "../ecs/components/HydraLightComponent.h"
|
||||
#include "../buffer/HydraMaterialBufferManager.h"
|
||||
#include "../buffer/HydraTextureBufferManager.h"
|
||||
#include "../buffer/HydraMaterialBuffer.h"
|
||||
@@ -24,6 +26,7 @@ void HydraTestCubeActor::InitialiseComponents()
|
||||
_CreateMaterial();
|
||||
_CreateMesh();
|
||||
_CreateRenderableComponent();
|
||||
_CreateLightComponent();
|
||||
}
|
||||
|
||||
void HydraTestCubeActor::DeferredInitialiseComponents()
|
||||
@@ -174,7 +177,8 @@ void HydraTestCubeActor::_CreateMaterial()
|
||||
|
||||
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.emmissive_metalic_rough = glm::vec4(0.0f, 0.5f, 0.3f, 1.0f);
|
||||
|
||||
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
|
||||
|
||||
HydraMaterialComponent mat_comp = {};
|
||||
@@ -199,7 +203,23 @@ void HydraTestCubeActor::_CreatePhysics()
|
||||
void HydraTestCubeActor::_CreateRenderableComponent()
|
||||
{
|
||||
HydraRenderableComponent render_comp;
|
||||
HydraShadowCasterComponent shad_caster;
|
||||
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_SHADOW_CASTER, true);
|
||||
ecs->AddComponent<HydraRenderableComponent>(GetID(), render_comp);
|
||||
ecs->AddComponent<HydraShadowCasterComponent>(GetID(), shad_caster);
|
||||
|
||||
}
|
||||
void HydraTestCubeActor::_CreateLightComponent()
|
||||
{
|
||||
HydraLightComponent light_comp = {};
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
|
||||
light_comp.diffuse = glm::vec4(1,1,1,1);
|
||||
light_comp.intensity = 1000.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);
|
||||
}
|
||||
@@ -18,6 +18,7 @@ class CLASS_DEFINE HydraTestCubeActor : public HydraActor
|
||||
void _CreateMaterial();
|
||||
void _CreatePhysics();
|
||||
void _CreateRenderableComponent();
|
||||
void _CreateLightComponent();
|
||||
public:
|
||||
virtual void InitialiseComponents();
|
||||
virtual void DeferredInitialiseComponents();
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "../ecs/components/HydraMeshComponent.h"
|
||||
#include "../ecs/components/HydraRenderableComponent.h"
|
||||
#include "../ecs/components/HydraMaterialComponent.h"
|
||||
#include "../ecs/components/HydraLightComponent.h"
|
||||
#include "../buffer/HydraMaterialBufferManager.h"
|
||||
#include "../buffer/HydraTextureBufferManager.h"
|
||||
#include "../buffer/HydraMaterialBuffer.h"
|
||||
@@ -23,6 +24,7 @@ void HydraTestLightActor::InitialiseComponents()
|
||||
_CreateMaterial();
|
||||
_CreateMesh();
|
||||
_CreateRenderableComponent();
|
||||
|
||||
}
|
||||
|
||||
void HydraTestLightActor::DeferredInitialiseComponents()
|
||||
@@ -173,7 +175,7 @@ void HydraTestLightActor::_CreateMaterial()
|
||||
|
||||
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.emmissive_metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
|
||||
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
|
||||
|
||||
HydraMaterialComponent mat_comp = {};
|
||||
@@ -181,7 +183,6 @@ void HydraTestLightActor::_CreateMaterial()
|
||||
engine->ECS()->AddComponent<HydraMaterialComponent>(GetID(), mat_comp);
|
||||
}
|
||||
|
||||
|
||||
void HydraTestLightActor::_CreateRenderableComponent()
|
||||
{
|
||||
HydraRenderableComponent render_comp;
|
||||
@@ -189,3 +190,4 @@ void HydraTestLightActor::_CreateRenderableComponent()
|
||||
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR, true);
|
||||
ecs->AddComponent<HydraRenderableComponent>(GetID(), render_comp);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ class CLASS_DEFINE HydraTestLightActor : public HydraActor
|
||||
void _CreateMesh();
|
||||
void _CreateMaterial();
|
||||
void _CreateRenderableComponent();
|
||||
|
||||
public:
|
||||
virtual void InitialiseComponents();
|
||||
virtual void DeferredInitialiseComponents();
|
||||
|
||||
@@ -24,11 +24,26 @@ void HydraLightSpawnerActor::FixedTick(float delta_t)
|
||||
actor_manager->InitialiseActor(actor_id);
|
||||
actor_manager->SetPosition(actor_id, pos_comp.position);
|
||||
actor_manager->SetLinearVelocity(actor_id, m_spawn_direction * m_spawn_velocity);
|
||||
SpawnedActor actor = {};
|
||||
actor.actor_id = actor_id;
|
||||
actor.spawned_time = current_tick;
|
||||
m_spawned_actors.push(actor);
|
||||
m_last_tick = current_tick;
|
||||
|
||||
}
|
||||
|
||||
if(m_spawned_actors.size() > 0)
|
||||
{
|
||||
SpawnedActor actor = m_spawned_actors.front();
|
||||
long actor_spawned_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(current_tick - actor.spawned_time).count();
|
||||
if(actor_spawned_time_ms > (m_spawn_duration * 1000.0f ))
|
||||
{
|
||||
GetEngine()->ActorManager()->DeleteActor(actor.actor_id);
|
||||
m_spawned_actors.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void HydraLightSpawnerActor::_CreatePosition()
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
#include <chrono>
|
||||
#include <queue>
|
||||
#include <GLMIncludes.h>
|
||||
|
||||
struct SpawnedActor
|
||||
{
|
||||
HydraID actor_id;
|
||||
std::chrono::time_point<std::chrono::steady_clock> spawned_time;
|
||||
};
|
||||
|
||||
class CLASS_DEFINE HydraLightSpawnerActor : public HydraActor
|
||||
{
|
||||
public:
|
||||
@@ -30,7 +37,7 @@ class CLASS_DEFINE HydraLightSpawnerActor : public HydraActor
|
||||
float m_interval = 0.0f;
|
||||
bool m_enabled = false;
|
||||
std::chrono::time_point<std::chrono::steady_clock> m_last_tick;
|
||||
std::queue<HydraID> m_spawned_actors;
|
||||
std::queue<SpawnedActor> m_spawned_actors;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -201,3 +218,9 @@ void HydraSpawnedLightActor::_CreateRenderableComponent()
|
||||
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR, true);
|
||||
ecs->AddComponent<HydraRenderableComponent>(GetID(), render_comp);
|
||||
}
|
||||
|
||||
void HydraSpawnedLightActor::_CreateLightComponent()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ class CLASS_DEFINE HydraSpawnedLightActor : public HydraActor
|
||||
void _CreateMaterial();
|
||||
void _CreatePhysics();
|
||||
void _CreateRenderableComponent();
|
||||
void _CreateLightComponent();
|
||||
public:
|
||||
void InitialiseComponents() override;
|
||||
void DeferredInitialiseComponents() override;
|
||||
|
||||
@@ -174,7 +174,7 @@ void HydraPlanetActor::_CreateMaterial()
|
||||
|
||||
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.emmissive_metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
|
||||
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
|
||||
|
||||
HydraMaterialComponent mat_comp = {};
|
||||
|
||||
@@ -173,7 +173,7 @@ void HydraPlanetQuadActor::_CreateMaterial()
|
||||
|
||||
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.emmissive_metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
|
||||
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
|
||||
|
||||
HydraMaterialComponent mat_comp = {};
|
||||
|
||||
@@ -50,7 +50,6 @@ void HydraLightBufferManager::AddLight(HydraLightComponent light)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto it = std::find(m_light_lookup.begin(), m_light_lookup.end(), light.entity_id);
|
||||
|
||||
if(it == m_light_lookup.end())
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
struct HydraMaterialBuffer
|
||||
{
|
||||
glm::vec4 diffuse_colour = {0, 0, 0, 0}; //0 - 16
|
||||
glm::vec4 metalic_rough = {0, 0, 0, 0}; //28 - 12
|
||||
glm::vec4 emmissive_metalic_rough = {0, 0, 0, 0}; //28 - 12
|
||||
uint32_t diffuse_texture_id = INVALID_HYDRA_ID; //32 - 4
|
||||
uint32_t metallic_rough_texture_id = INVALID_HYDRA_ID; //36 - 4
|
||||
uint32_t normal_texture_id = INVALID_HYDRA_ID; //40 - 4
|
||||
|
||||
@@ -1,4 +1,16 @@
|
||||
#include "HydraMaterialBufferManager.h"
|
||||
#include "../engine/HydraEngine.h"
|
||||
#include "../ecs/HydraECS.h"
|
||||
#include "../ecs/components/HydraMaterialComponent.h"
|
||||
|
||||
#include "../buffer/HydraMaterialBufferManager.h"
|
||||
#include "../buffer/HydraTextureBufferManager.h"
|
||||
|
||||
#include "../scheduler/HydraTaskScheduler.h"
|
||||
#include "../task/buffer/HydraCreateGPUBufferTask.hpp"
|
||||
#include "../task/buffer/HydraDeleteGPUBufferTask.hpp"
|
||||
#include "../task/buffer/HydraUpdateWholeGPUBufferTask.hpp"
|
||||
#include "../actor/HydraActorManager.h"
|
||||
|
||||
void HydraMaterialBufferManager::Intialise()
|
||||
{
|
||||
@@ -7,10 +19,33 @@ void HydraMaterialBufferManager::Intialise()
|
||||
{
|
||||
m_available_material_ids.push(mat_idx);
|
||||
}
|
||||
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
HydraID create_gpu_buffer_task_id = task_scheduler->CreateTask<HydraCreateGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraCreateGPUBufferTask *task = static_cast<HydraCreateGPUBufferTask *>(task_scheduler->GetTask(create_gpu_buffer_task_id));
|
||||
task->Intialise("MaterialBuffer", 1, MAX_MATERIALS * sizeof(HydraMaterialBuffer), &m_material_buffer_id, HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
task_scheduler->WaitForTask(create_gpu_buffer_task_id);
|
||||
|
||||
create_gpu_buffer_task_id = task_scheduler->CreateTask<HydraCreateGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
task = static_cast<HydraCreateGPUBufferTask *>(task_scheduler->GetTask(create_gpu_buffer_task_id));
|
||||
task->Intialise("TextureBuffer", 1, MAX_TEXTURES * sizeof(uint64_t), &m_texture_buffer_id, HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
task_scheduler->WaitForTask(create_gpu_buffer_task_id);
|
||||
}
|
||||
|
||||
void HydraMaterialBufferManager::Shutdown()
|
||||
{
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
HydraID delete_gpu_buffer_task_id = task_scheduler->CreateTask<HydraDeleteGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraDeleteGPUBufferTask *task = static_cast<HydraDeleteGPUBufferTask *>(task_scheduler->GetTask(delete_gpu_buffer_task_id));
|
||||
task->Intialise(m_material_buffer_id);
|
||||
task_scheduler->WaitForTask(delete_gpu_buffer_task_id);
|
||||
|
||||
delete_gpu_buffer_task_id = task_scheduler->CreateTask<HydraDeleteGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
task = static_cast<HydraDeleteGPUBufferTask *>(task_scheduler->GetTask(delete_gpu_buffer_task_id));
|
||||
task->Intialise(m_texture_buffer_id);
|
||||
task_scheduler->WaitForTask(delete_gpu_buffer_task_id);
|
||||
}
|
||||
|
||||
HydraID HydraMaterialBufferManager::CreateMaterial(const HydraMaterialBuffer &material)
|
||||
@@ -26,10 +61,35 @@ HydraID HydraMaterialBufferManager::CreateMaterial(const HydraMaterialBuffer &ma
|
||||
return mat_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HydraMaterialBufferManager::DeleteMaterial(HydraID material_id)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if(material_id < MAX_MATERIALS)
|
||||
{
|
||||
m_material[material_id] = {};
|
||||
m_available_material_ids.push(material_id);
|
||||
}
|
||||
}
|
||||
|
||||
void *HydraMaterialBufferManager::GetMaterialBuffer()
|
||||
{
|
||||
return &m_material[0];
|
||||
}
|
||||
|
||||
void HydraMaterialBufferManager::UpdateBuffer()
|
||||
{
|
||||
void* buffer = GetEngine()->MaterialBufferManager()->GetMaterialBuffer();
|
||||
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
HydraID update_buffer_task_id = task_scheduler->CreateTask<HydraUpdateWholeGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraUpdateWholeGPUBufferTask *task = static_cast<HydraUpdateWholeGPUBufferTask *>(task_scheduler->GetTask(update_buffer_task_id));
|
||||
task->Intialise(m_material_buffer_id, buffer);
|
||||
task_scheduler->WaitForTask(update_buffer_task_id);
|
||||
|
||||
buffer = GetEngine()->TextureBufferManager()->GetTextureBuffer();
|
||||
update_buffer_task_id = task_scheduler->CreateTask<HydraUpdateWholeGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
task = static_cast<HydraUpdateWholeGPUBufferTask *>(task_scheduler->GetTask(update_buffer_task_id));
|
||||
task->Intialise(m_texture_buffer_id, buffer);
|
||||
task_scheduler->WaitForTask(update_buffer_task_id);
|
||||
}
|
||||
|
||||
@@ -19,9 +19,12 @@ class HydraMaterialBufferManager : public HydraObject
|
||||
void Intialise();
|
||||
void Shutdown();
|
||||
HydraID CreateMaterial(const HydraMaterialBuffer& material);
|
||||
void DeleteMaterial(HydraID material_id);
|
||||
void* GetMaterialBuffer();
|
||||
|
||||
void UpdateBuffer();
|
||||
private:
|
||||
uint32_t m_material_buffer_id =0;
|
||||
uint32_t m_texture_buffer_id =0;
|
||||
std::mutex m_mutex;
|
||||
std::queue<HydraID> m_available_material_ids;
|
||||
std::vector<HydraMaterialBuffer> m_material;
|
||||
|
||||
@@ -15,7 +15,7 @@ class IHydraComponentArray
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class HydraComponentArray : public IHydraComponentArray
|
||||
class HydraComponentArray : public IHydraComponentArray, HydraObject
|
||||
{
|
||||
private:
|
||||
std::array<T, MAX_ACTORS> m_components;
|
||||
@@ -28,11 +28,12 @@ class HydraComponentArray : public IHydraComponentArray
|
||||
void RemoveComponent(HydraID entity_id)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
if(m_entity_to_component.find(entity_id) == m_entity_to_component.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DebugLog("COMPONENT DELETED:" + std::to_string(entity_id) + "\n");
|
||||
HydraID component_index = m_entity_to_component[entity_id];
|
||||
HydraID last_component_index = m_component_count -1;
|
||||
HydraID last_entity_id = m_component_to_entity[last_component_index];
|
||||
@@ -41,15 +42,21 @@ class HydraComponentArray : public IHydraComponentArray
|
||||
{
|
||||
m_components[component_index] = m_components[last_component_index];
|
||||
m_entity_to_component[last_entity_id] = component_index;
|
||||
m_component_to_entity.erase(last_component_index);
|
||||
m_component_to_entity[component_index] = last_entity_id;
|
||||
m_components[last_component_index] = {};
|
||||
DebugLog("COMPONENT MOVED:" + std::to_string(last_entity_id) + "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_components[component_index] = {};
|
||||
m_components[last_component_index] = {};
|
||||
m_entity_to_component.erase(entity_id);
|
||||
m_component_to_entity.erase(last_component_index);
|
||||
}
|
||||
|
||||
m_entity_to_component.erase(entity_id);
|
||||
m_component_to_entity.erase(component_index);
|
||||
|
||||
|
||||
m_component_count--;
|
||||
|
||||
}
|
||||
|
||||
@@ -85,6 +92,10 @@ class HydraComponentArray : public IHydraComponentArray
|
||||
{
|
||||
RemoveComponent(entity_id);
|
||||
}
|
||||
T const * const GetComponents()
|
||||
{
|
||||
return &m_components[0];
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* HYDRACOMPONENTARRAY */
|
||||
|
||||
@@ -19,12 +19,14 @@ class HydraComponentManager :public HydraObject
|
||||
std::shared_ptr<HydraComponentArray<T>> _GetComponentArray()
|
||||
{
|
||||
std::string type_name = std::string(typeid(T).name());
|
||||
|
||||
if(m_component_types.find(type_name) == m_component_types.end())
|
||||
{
|
||||
std::cout << "Error";
|
||||
}
|
||||
assert(m_component_types.find(type_name) != m_component_types.end() && "Component type does not exist");
|
||||
return std::static_pointer_cast<HydraComponentArray<T>>(m_component_arrays[type_name]);
|
||||
}
|
||||
public:
|
||||
|
||||
template<typename T>
|
||||
ComponentTypeID RegisterComponentType()
|
||||
{
|
||||
@@ -58,6 +60,12 @@ class HydraComponentManager :public HydraObject
|
||||
{
|
||||
return _GetComponentArray<T>()->GetComponent(entity_id);
|
||||
}
|
||||
template<typename T>
|
||||
T const * const GetComponents()
|
||||
{
|
||||
return _GetComponentArray<T>()->GetComponents();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
bool HasComponent(HydraID entity_id)
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
{
|
||||
// Remove the component from the entity
|
||||
m_component_manager->RemoveComponent<T>(entity_id);
|
||||
|
||||
std::string(typeid(T).name());
|
||||
// Get the current signature, remove the component from it and update
|
||||
auto signature = m_entity_manager->GetSignature(entity_id);
|
||||
signature.set(m_component_manager->GetComponentTypeID<T>(), false);
|
||||
@@ -79,6 +79,11 @@ public:
|
||||
{
|
||||
return m_component_manager->GetComponent<T>(entity_id);
|
||||
}
|
||||
template <typename T>
|
||||
T &GetComponents()
|
||||
{
|
||||
return m_component_manager->GetComponents<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<T> RegisterSystem()
|
||||
@@ -100,6 +105,10 @@ public:
|
||||
{
|
||||
m_system_manager->InitialiseComponents();
|
||||
}
|
||||
void DeleteComponents()
|
||||
{
|
||||
m_system_manager->DeleteComponents();
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* HYDRAECS */
|
||||
|
||||
@@ -6,11 +6,12 @@ void HydraSystem::Update(float delta_t_seconds)
|
||||
UpdateSystem(delta_t_seconds);
|
||||
|
||||
}
|
||||
|
||||
void HydraSystem::Shutdown()
|
||||
{
|
||||
for(HydraID entity_id : Entities)
|
||||
{
|
||||
DestroyComponents(entity_id);
|
||||
DestroyComponent(entity_id);
|
||||
}
|
||||
FreeSystemResources();
|
||||
}
|
||||
@@ -23,13 +24,20 @@ void HydraSystem::InitialiseComponents()
|
||||
}
|
||||
EntitiesToCreate.clear();
|
||||
}
|
||||
|
||||
void HydraSystem::DestroyComponents(HydraID actor_id)
|
||||
void HydraSystem::DeleteComponents()
|
||||
{
|
||||
auto it = std::find(Entities.begin(), Entities.end(), actor_id);
|
||||
if(it == Entities.end())
|
||||
for(auto it = EntitiesToDelete.begin(); it != EntitiesToDelete.end(); ++it)
|
||||
{
|
||||
return;
|
||||
HydraID actor_id = *it;
|
||||
DestroyComponent(actor_id);
|
||||
}
|
||||
EntitiesToDelete.clear();
|
||||
}
|
||||
|
||||
void HydraSystem::DeleteComponent(HydraID actor_id)
|
||||
{
|
||||
if(std::find(Entities.begin(), Entities.end(), actor_id)!= Entities.end())
|
||||
{
|
||||
DestroyComponent(actor_id);
|
||||
}
|
||||
DestroyComponent(actor_id);
|
||||
}
|
||||
|
||||
@@ -10,17 +10,19 @@ class HydraSystem : public HydraObject
|
||||
public:
|
||||
std::set<HydraID> Entities;
|
||||
std::set<HydraID> EntitiesToCreate;
|
||||
std::set<HydraID> EntitiesToDelete;
|
||||
|
||||
void Update(float delta_t_seconds);
|
||||
void InitialiseComponents();
|
||||
void DeleteComponents();
|
||||
void DeleteComponent(HydraID actor_id);
|
||||
virtual void InitialiseComponent(HydraID actor_id) {};
|
||||
void DestroyComponents(HydraID actor_id);
|
||||
|
||||
virtual void Shutdown();
|
||||
virtual void Initialise(){};
|
||||
protected:
|
||||
|
||||
virtual void UpdateSystem(float delta_t_seconds) = 0;
|
||||
|
||||
virtual void DestroyComponent(HydraID actor_id) {};
|
||||
virtual void FreeSystemResources(){};
|
||||
};
|
||||
|
||||
@@ -75,7 +75,8 @@ public:
|
||||
// Entity signature does not match system signature - erase from set
|
||||
else
|
||||
{
|
||||
system->DestroyComponents(entity_id);
|
||||
//system->DestroyComponents(entity_id);
|
||||
//system->DeleteComponent(entity_id);
|
||||
system->Entities.erase(entity_id);
|
||||
system->EntitiesToCreate.erase(entity_id);
|
||||
}
|
||||
@@ -87,11 +88,20 @@ public:
|
||||
for (auto const& pair : m_systems)
|
||||
{
|
||||
auto const& system = pair.second;
|
||||
system->DestroyComponents(entity_id);
|
||||
system->DeleteComponent(entity_id);
|
||||
//system->EntitiesToDelete.insert(entity_id);
|
||||
system->Entities.erase(entity_id);
|
||||
system->EntitiesToCreate.erase(entity_id);
|
||||
}
|
||||
}
|
||||
void DeleteComponents()
|
||||
{
|
||||
for (auto const& pair : m_systems)
|
||||
{
|
||||
auto const& system = pair.second;
|
||||
system->DeleteComponents();
|
||||
}
|
||||
}
|
||||
void InitialiseComponents()
|
||||
{
|
||||
for (auto const& pair : m_systems)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef HYDRASHADOWCASTERCOMPONENT
|
||||
#define HYDRASHADOWCASTERCOMPONENT
|
||||
#include "../../engine/HydraEngine.h"
|
||||
|
||||
struct HydraShadowCasterComponent
|
||||
{
|
||||
|
||||
};
|
||||
#endif /* HYDRASHADOWCASTERCOMPONENT */
|
||||
@@ -16,58 +16,22 @@
|
||||
|
||||
void HydraMaterialSystem::Initialise()
|
||||
{
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
HydraID create_gpu_buffer_task_id = task_scheduler->CreateTask<HydraCreateGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraCreateGPUBufferTask *task = static_cast<HydraCreateGPUBufferTask *>(task_scheduler->GetTask(create_gpu_buffer_task_id));
|
||||
task->Intialise("MaterialBuffer", 1, MAX_MATERIALS * sizeof(HydraMaterialBuffer), &m_material_buffer_id, HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
task_scheduler->WaitForTask(create_gpu_buffer_task_id);
|
||||
|
||||
create_gpu_buffer_task_id = task_scheduler->CreateTask<HydraCreateGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
task = static_cast<HydraCreateGPUBufferTask *>(task_scheduler->GetTask(create_gpu_buffer_task_id));
|
||||
task->Intialise("TextureBuffer", 1, MAX_TEXTURES * sizeof(uint64_t), &m_texture_buffer_id, HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
task_scheduler->WaitForTask(create_gpu_buffer_task_id);
|
||||
}
|
||||
|
||||
void HydraMaterialSystem::InitialiseComponent(HydraID entity_id)
|
||||
{
|
||||
}
|
||||
|
||||
void HydraMaterialSystem::FreeSystemResources()
|
||||
{
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
HydraID delete_gpu_buffer_task_id = task_scheduler->CreateTask<HydraDeleteGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraDeleteGPUBufferTask *task = static_cast<HydraDeleteGPUBufferTask *>(task_scheduler->GetTask(delete_gpu_buffer_task_id));
|
||||
task->Intialise(m_material_buffer_id);
|
||||
task_scheduler->WaitForTask(delete_gpu_buffer_task_id);
|
||||
|
||||
delete_gpu_buffer_task_id = task_scheduler->CreateTask<HydraDeleteGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
task = static_cast<HydraDeleteGPUBufferTask *>(task_scheduler->GetTask(delete_gpu_buffer_task_id));
|
||||
task->Intialise(m_texture_buffer_id);
|
||||
task_scheduler->WaitForTask(delete_gpu_buffer_task_id);
|
||||
}
|
||||
|
||||
void HydraMaterialSystem::UpdateSystem(float delta_t_seconds)
|
||||
{
|
||||
_WriteToGPU();
|
||||
GetEngine()->MaterialBufferManager()->UpdateBuffer();
|
||||
}
|
||||
|
||||
|
||||
void HydraMaterialSystem::_WriteToGPU()
|
||||
void HydraMaterialSystem::DestroyComponent(HydraID entity_id)
|
||||
{
|
||||
void* buffer = GetEngine()->MaterialBufferManager()->GetMaterialBuffer();
|
||||
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
HydraID update_buffer_task_id = task_scheduler->CreateTask<HydraUpdateWholeGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraUpdateWholeGPUBufferTask *task = static_cast<HydraUpdateWholeGPUBufferTask *>(task_scheduler->GetTask(update_buffer_task_id));
|
||||
task->Intialise(m_material_buffer_id, buffer);
|
||||
task_scheduler->WaitForTask(update_buffer_task_id);
|
||||
|
||||
buffer = GetEngine()->TextureBufferManager()->GetTextureBuffer();
|
||||
update_buffer_task_id = task_scheduler->CreateTask<HydraUpdateWholeGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
task = static_cast<HydraUpdateWholeGPUBufferTask *>(task_scheduler->GetTask(update_buffer_task_id));
|
||||
task->Intialise(m_texture_buffer_id, buffer);
|
||||
task_scheduler->WaitForTask(update_buffer_task_id);
|
||||
HydraMaterialComponent mat_comp = GetEngine()->ECS()->GetComponent<HydraMaterialComponent>(entity_id);
|
||||
GetEngine()->MaterialBufferManager()->DeleteMaterial(mat_comp.material_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,11 @@ class HydraMaterialSystem : public HydraSystem
|
||||
public:
|
||||
void Initialise() override;
|
||||
void InitialiseComponent(HydraID entity_id) override;
|
||||
|
||||
protected:
|
||||
void FreeSystemResources() override;
|
||||
|
||||
virtual void UpdateSystem(float delta_t_seconds);
|
||||
void DestroyComponent(HydraID entity_id) override;
|
||||
private:
|
||||
void _WriteToGPU();
|
||||
HydraID m_material_buffer_id = INVALID_HYDRA_ID;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "../../task/physics/HydraGetPhysicsUpdatesTask.hpp"
|
||||
#include "../../task/physics/HydraStepPhysicsTask.h"
|
||||
#include "../../task/physics/HydraSetPhysicsLinearVelocity.hpp"
|
||||
#include "../../task/physics/HydraDeletePhysicsObjectTask.h"
|
||||
#include "../../ecs/HydraECS.h"
|
||||
#include "../../ecs/components/HydraPhysicsComponent.h"
|
||||
#include "../../ecs/components/HydraPositionComponent.h"
|
||||
@@ -86,12 +87,27 @@ void HydraPhysicsSystem::InitialiseComponent(HydraID entity_id)
|
||||
set_task->Initialise(body_id, pos_comp.position, glm::quat(pos_comp.orientation));
|
||||
task_scheduler->WaitForTask(task_id);
|
||||
phys_comp.initialised = true;
|
||||
DebugLog("PHYSICS CREATED:" + std::to_string(entity_id) + "\n");
|
||||
|
||||
}
|
||||
|
||||
void HydraPhysicsSystem::DestroyComponent(HydraID entity_id)
|
||||
{
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
HydraPhysicsComponent& phys_comp = GetEngine()->ECS()->GetComponent<HydraPhysicsComponent>(entity_id);
|
||||
|
||||
if(phys_comp.initialised)
|
||||
{
|
||||
HydraID task_id = task_scheduler->CreateTask<HydraDeletePhysicsObjectTask>(HydraThreadAffinity::Physics);
|
||||
HydraDeletePhysicsObjectTask *task = static_cast<HydraDeletePhysicsObjectTask *>(task_scheduler->GetTask(task_id));
|
||||
task->Initialise(phys_comp.body_id);
|
||||
task_scheduler->WaitForTask(task_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "here";
|
||||
}
|
||||
DebugLog("PHYSICS DELETED:" + std::to_string(entity_id) + "\n");
|
||||
}
|
||||
|
||||
void HydraPhysicsSystem::UpdateSystem(float delta_t_seconds)
|
||||
@@ -101,6 +117,7 @@ void HydraPhysicsSystem::UpdateSystem(float delta_t_seconds)
|
||||
{
|
||||
HydraID entity_id = m_bodies_to_set_transform.front();
|
||||
m_bodies_to_set_transform.pop();
|
||||
|
||||
HydraPhysicsComponent& phys_comp = GetEngine()->ECS()->GetComponent<HydraPhysicsComponent>(entity_id);
|
||||
HydraPositionComponent& pos_comp = GetEngine()->ECS()->GetComponent<HydraPositionComponent>(entity_id);
|
||||
|
||||
|
||||
@@ -69,7 +69,6 @@ void HydraPointShadowSourceSystem::_UpdateShadowMap(HydraID entity_id)
|
||||
float view_near = 0.1f;
|
||||
float view_far = 100.0f;
|
||||
|
||||
|
||||
glm::vec3 camera_pos = GetEngine()->Camera()->GetPosition();
|
||||
|
||||
float aspect = (float)POINT_SHADOW_MAP_SIZE/(float)POINT_SHADOW_MAP_SIZE;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef HYDRASHADOWCASTERSYSTEM
|
||||
#define HYDRASHADOWCASTERSYSTEM
|
||||
|
||||
#include "../../engine/HydraObject.h"
|
||||
#include "../HydraSystem.h"
|
||||
#include <GLMIncludes.h>
|
||||
#include <queue>
|
||||
|
||||
class HydraShadowCasterSystem : public HydraSystem
|
||||
{
|
||||
public:
|
||||
|
||||
protected:
|
||||
void UpdateSystem(float delta_t_seconds) override {}
|
||||
};
|
||||
#endif /* HYDRASHADOWCASTERSYSTEM */
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "../ecs/systems/HydraPointShadowSourceSystem.h"
|
||||
#include "../ecs/systems/HydraPhysicsSystem.h"
|
||||
#include "../ecs/systems/HydraTickActorsSystem.h"
|
||||
#include "../ecs/systems/HydraShadowCasterSystem.h"
|
||||
|
||||
#include "../ecs/components/HydraPositionComponent.h"
|
||||
#include "../ecs/components/HydraMeshComponent.h"
|
||||
@@ -38,6 +39,7 @@
|
||||
#include "../ecs/components/HydraPointShadowSourceComponent.h"
|
||||
#include "../ecs/components/HydraPhysicsComponent.h"
|
||||
#include "../ecs/components/HydraTickComponent.h"
|
||||
#include "../ecs/components/HydraShadowCasterComponent.h"
|
||||
|
||||
#include "../camera/HydraCamera.h"
|
||||
#include "../actor/HydraActorManager.h"
|
||||
@@ -58,6 +60,7 @@
|
||||
|
||||
#include "../task/ecs/HydraUpdateSystemTask.hpp"
|
||||
#include "../task/ecs/HydraInitialiseComponentsTask.hpp"
|
||||
#include "../task/ecs/HydraDeleteComponentsTask.hpp"
|
||||
#include "../task/buffer/HydraShutdownBufferManagerTask.hpp"
|
||||
#include "../task/buffer/HydraInitialiseTextureManagerTask.hpp"
|
||||
#include "../task/buffer/HydraInitialiseShadowBufferTask.hpp"
|
||||
@@ -210,7 +213,7 @@ void HydraEngine::_CreateManagers()
|
||||
|
||||
void HydraEngine::_InitialiseManagers()
|
||||
{
|
||||
m_task_scheduler->Initialise(1);
|
||||
m_task_scheduler->Initialise(4);
|
||||
HydraID create_window_task_id = m_task_scheduler->CreateTask<HydraInitialiseWindowManagerTask>(HydraThreadAffinity::Render);
|
||||
m_task_scheduler->WaitForTask(create_window_task_id);
|
||||
|
||||
@@ -245,6 +248,7 @@ void HydraEngine::_InitialiseSystems()
|
||||
m_ecs->RegisterComponentType<HydraPointShadowSourceComponent>();
|
||||
m_ecs->RegisterComponentType<HydraPhysicsComponent>();
|
||||
m_ecs->RegisterComponentType<HydraTickComponent>();
|
||||
m_ecs->RegisterComponentType<HydraShadowCasterComponent>();
|
||||
|
||||
m_mesh_system = m_ecs->RegisterSystem<HydraMeshSystem>();
|
||||
m_transform_system = m_ecs->RegisterSystem<HydraTransformSystem>();
|
||||
@@ -256,6 +260,7 @@ void HydraEngine::_InitialiseSystems()
|
||||
m_point_shadow_system = m_ecs->RegisterSystem<HydraPointShadowSourceSystem>();
|
||||
m_physics_system = m_ecs->RegisterSystem<HydraPhysicsSystem>();
|
||||
m_tick_system = m_ecs->RegisterSystem<HydraTickActorsSystem>();
|
||||
m_shadow_caster_system = m_ecs->RegisterSystem<HydraShadowCasterSystem>();
|
||||
|
||||
HydraSignature mesh_sig;
|
||||
HydraSignature trans_sig;
|
||||
@@ -267,6 +272,7 @@ void HydraEngine::_InitialiseSystems()
|
||||
HydraSignature point_shadow_sig;
|
||||
HydraSignature physics_sig;
|
||||
HydraSignature tick_sig;
|
||||
HydraSignature shadow_caster_sig;
|
||||
|
||||
mesh_sig.set(m_ecs->GetComponentType<HydraMeshComponent>(),true);
|
||||
trans_sig.set(m_ecs->GetComponentType<HydraPositionComponent>(),true);
|
||||
@@ -293,6 +299,8 @@ void HydraEngine::_InitialiseSystems()
|
||||
|
||||
tick_sig.set(m_ecs->GetComponentType<HydraTickComponent>(), true);
|
||||
|
||||
shadow_caster_sig.set(m_ecs->GetComponentType<HydraShadowCasterComponent>(), true);
|
||||
|
||||
m_ecs->SetSystemSignature<HydraMeshSystem>(mesh_sig);
|
||||
m_ecs->SetSystemSignature<HydraTransformSystem>(trans_sig);
|
||||
m_ecs->SetSystemSignature<HydraRenderSystem>(render_sig);
|
||||
@@ -303,9 +311,10 @@ void HydraEngine::_InitialiseSystems()
|
||||
m_ecs->SetSystemSignature<HydraPointShadowSourceSystem>(point_shadow_sig);
|
||||
m_ecs->SetSystemSignature<HydraPhysicsSystem>(physics_sig);
|
||||
m_ecs->SetSystemSignature<HydraTickActorsSystem>(tick_sig);
|
||||
m_ecs->SetSystemSignature<HydraShadowCasterSystem>(shadow_caster_sig);
|
||||
}
|
||||
|
||||
void HydraEngine::_UpdateSystems()
|
||||
void HydraEngine::_UpdateSystems(bool fixed_update)
|
||||
{
|
||||
|
||||
//Update physics system with any changes from the transform system
|
||||
@@ -350,8 +359,10 @@ void HydraEngine::_InitialiseSystems()
|
||||
m_task_scheduler->StartTask(update_spot_shadow_id);
|
||||
m_task_scheduler->StartTask(update_point_shadow_id);
|
||||
m_task_scheduler->WaitForBarrier(shadow_barrier);
|
||||
|
||||
m_tick_system->FixedUpdate(m_fixed_delta_t);
|
||||
if(fixed_update)
|
||||
{
|
||||
m_tick_system->FixedUpdate(m_fixed_delta_t);
|
||||
}
|
||||
m_shadow_buffer_manager->UpdateShadowBuffer();
|
||||
}
|
||||
|
||||
@@ -426,6 +437,9 @@ void HydraEngine::_GameLoop()
|
||||
|
||||
fpsFrameCount++;
|
||||
|
||||
HydraID delete_components_id = m_task_scheduler->CreateTask<HydraDeleteComponentsTask>(HydraThreadAffinity::General);
|
||||
m_task_scheduler->WaitForTask(delete_components_id);
|
||||
|
||||
HydraID processInputID = m_task_scheduler->CreateTask<HydraProcessInputTask>(HydraThreadAffinity::Render, barrierID);
|
||||
HydraProcessInputTask* m_input_task = static_cast<HydraProcessInputTask*>(m_task_scheduler->GetTask(processInputID));
|
||||
m_input_task->Initialise(fixed_tick);
|
||||
@@ -441,11 +455,13 @@ void HydraEngine::_GameLoop()
|
||||
|
||||
if(fixed_tick)
|
||||
{
|
||||
|
||||
m_game->FixedUpdate(m_delta_t);
|
||||
|
||||
}
|
||||
m_game->Update(m_delta_t);
|
||||
|
||||
_UpdateSystems();
|
||||
_UpdateSystems(fixed_tick);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ class HydraShadowBufferManager;
|
||||
class HydraPointShadowSourceSystem;
|
||||
class HydraPhysicsSystem;
|
||||
class HydraTickActorsSystem;
|
||||
class HydraShadowCasterSystem;
|
||||
|
||||
class CLASS_DEFINE HydraEngine : public HydraObject
|
||||
{
|
||||
@@ -74,7 +75,7 @@ private:
|
||||
void _CreateManagers();
|
||||
void _InitialiseManagers();
|
||||
void _InitialiseSystems();
|
||||
void _UpdateSystems();
|
||||
void _UpdateSystems(bool fixed_update);
|
||||
void _GameLoop();
|
||||
void _Shutdown();
|
||||
|
||||
@@ -108,6 +109,7 @@ private:
|
||||
std::shared_ptr<HydraPointShadowSourceSystem> m_point_shadow_system;
|
||||
std::shared_ptr<HydraPhysicsSystem> m_physics_system;
|
||||
std::shared_ptr<HydraTickActorsSystem> m_tick_system;
|
||||
std::shared_ptr<HydraShadowCasterSystem> m_shadow_caster_system;
|
||||
bool m_running = true;
|
||||
float m_delta_t = 0.0f;
|
||||
float m_fixed_delta_t = 0.0f;
|
||||
|
||||
@@ -8,7 +8,14 @@ HydraEngine *const HydraObject::GetEngine()
|
||||
|
||||
void HydraObject::DebugLog(std::string log_entry)
|
||||
{
|
||||
std::cout << log_entry + "\r\n";
|
||||
|
||||
|
||||
#ifdef __unix__ /* __unix__ is usually defined by compilers targeting Unix systems */
|
||||
std::cout << log_entry + "\r\n";
|
||||
#elif defined(_WIN32) || defined(WIN32) /* _Win32 is usually defined by compilers targeting 32 or 64 bit Windows systems */
|
||||
OutputDebugString(log_entry.c_str());
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void HydraObject::ClearLog()
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
#include "../ecs/systems/HydraDirectionalShadowSourceSystem.h"
|
||||
#include "../ecs/systems/HydraSpotShadowSourceSystem.h"
|
||||
#include "../ecs/systems/HydraPointShadowSourceSystem.h"
|
||||
#include "../ecs/systems/HydraShadowCasterSystem.h"
|
||||
#include "../ecs/components/HydraLightComponent.h"
|
||||
#include "../ecs/components/HydraRenderableComponent.h"
|
||||
#include "../mesh/StandardVertex.h"
|
||||
#include "../actor/HydraActorManager.h"
|
||||
#include "../actor/HydraOutputActor.h"
|
||||
@@ -35,7 +37,6 @@ void HydraShadowPipeline::Shutdown()
|
||||
void HydraShadowPipeline::Render()
|
||||
{
|
||||
|
||||
|
||||
glEnable(GL_DEPTH_TEST); // Depth testing must be active
|
||||
glDepthMask(GL_TRUE); // Depth buffer must be writable
|
||||
glDepthFunc(GL_LESS);
|
||||
@@ -43,59 +44,61 @@ void HydraShadowPipeline::Render()
|
||||
_RenderDirectionalShadowMaps();
|
||||
_RenderSpotShadowMaps();
|
||||
_RenderPointShadowMaps();
|
||||
|
||||
}
|
||||
|
||||
void HydraShadowPipeline::_RenderPointShadowMaps()
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
std::shared_ptr<HydraRenderSystem> render_system = ecs->GetSystem<HydraRenderSystem>();
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
std::shared_ptr<HydraShadowCasterSystem> render_system = ecs->GetSystem<HydraShadowCasterSystem>();
|
||||
std::shared_ptr<HydraPointShadowSourceSystem> shadow_system = ecs->GetSystem<HydraPointShadowSourceSystem>();
|
||||
glViewport(0, 0, POINT_SHADOW_MAP_SIZE, POINT_SHADOW_MAP_SIZE);
|
||||
|
||||
for (HydraID entity_id : shadow_system->Entities)
|
||||
{
|
||||
HydraPointShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraPointShadowSourceComponent>(entity_id);
|
||||
HydraLightComponent light_comp = GetEngine()->ECS()->GetComponent<HydraLightComponent>(entity_id);
|
||||
HydraPointShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraPointShadowSourceComponent>(entity_id);
|
||||
HydraLightComponent light_comp = GetEngine()->ECS()->GetComponent<HydraLightComponent>(entity_id);
|
||||
|
||||
_UpdateUBO(light_comp.shadow_map_id);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, shad_comp.frame_buffer_id);
|
||||
_UpdateUBO(light_comp.shadow_map_id);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, shad_comp.frame_buffer_id);
|
||||
|
||||
float depth_value = 1.0f;
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
float depth_value = 1.0f;
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
m_render_stages[POINT_RENDER_STAGE]->Render(render_system->Entities, INVALID_HYDRA_ID);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
m_render_stages[POINT_RENDER_STAGE]->Render(render_system->Entities, INVALID_HYDRA_ID);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HydraShadowPipeline::_RenderDirectionalShadowMaps()
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
std::shared_ptr<HydraRenderSystem> render_system = ecs->GetSystem<HydraRenderSystem>();
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
std::shared_ptr<HydraShadowCasterSystem> render_system = ecs->GetSystem<HydraShadowCasterSystem>();
|
||||
std::shared_ptr<HydraDirectionalShadowSourceSystem> shadow_system = ecs->GetSystem<HydraDirectionalShadowSourceSystem>();
|
||||
glViewport(0, 0, DIRECTIONAL_SHADOW_MAP_SIZE, DIRECTIONAL_SHADOW_MAP_SIZE);
|
||||
|
||||
for (HydraID entity_id : shadow_system->Entities)
|
||||
{
|
||||
HydraDirectionalShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraDirectionalShadowSourceComponent>(entity_id);
|
||||
HydraLightComponent light_comp = GetEngine()->ECS()->GetComponent<HydraLightComponent>(entity_id);
|
||||
_UpdateUBO(light_comp.shadow_map_id);
|
||||
HydraDirectionalShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraDirectionalShadowSourceComponent>(entity_id);
|
||||
HydraLightComponent light_comp = GetEngine()->ECS()->GetComponent<HydraLightComponent>(entity_id);
|
||||
_UpdateUBO(light_comp.shadow_map_id);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, shad_comp.frame_buffer_id);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, shad_comp.frame_buffer_id);
|
||||
|
||||
float depth_value = 1.0f;
|
||||
glClearNamedFramebufferfv(shad_comp.frame_buffer_id, GL_DEPTH, 0, &depth_value);
|
||||
m_render_stages[DIRECTIONAL_RENDER_STAGE]->Render(render_system->Entities, INVALID_HYDRA_ID);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
float depth_value = 1.0f;
|
||||
glClearNamedFramebufferfv(shad_comp.frame_buffer_id, GL_DEPTH, 0, &depth_value);
|
||||
|
||||
m_render_stages[DIRECTIONAL_RENDER_STAGE]->Render(render_system->Entities, INVALID_HYDRA_ID);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void HydraShadowPipeline::_RenderSpotShadowMaps()
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
std::shared_ptr<HydraRenderSystem> render_system = ecs->GetSystem<HydraRenderSystem>();
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
std::shared_ptr<HydraShadowCasterSystem> render_system = ecs->GetSystem<HydraShadowCasterSystem>();
|
||||
std::shared_ptr<HydraSpotShadowSourceSystem> shadow_system = ecs->GetSystem<HydraSpotShadowSourceSystem>();
|
||||
glViewport(0, 0, SPOT_SHADOW_MAP_SIZE, SPOT_SHADOW_MAP_SIZE);
|
||||
|
||||
for (HydraID entity_id : shadow_system->Entities)
|
||||
{
|
||||
HydraSpotShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraSpotShadowSourceComponent>(entity_id);
|
||||
@@ -273,7 +276,6 @@ void HydraShadowPipeline::_CreateSpotRenderStage()
|
||||
m_render_stages[SPOT_RENDER_STAGE] = render_stage;
|
||||
}
|
||||
|
||||
|
||||
void HydraShadowPipeline::_UpdateUBO(uint32_t shadow_idx)
|
||||
{
|
||||
HydraBufferManager *buffer_manager = GetEngine()->BufferManager();
|
||||
@@ -288,7 +290,6 @@ void HydraShadowPipeline::_BindFrameBufferAttachments(HydraID entity_id)
|
||||
glBindTextureUnit(0, 0);
|
||||
}
|
||||
|
||||
|
||||
void HydraShadowPipeline::_CreateUBOs()
|
||||
{
|
||||
HydraBufferManager *buffer_manager = GetEngine()->BufferManager();
|
||||
|
||||
@@ -26,8 +26,8 @@ void HydraRenderer::Initialise(HydraRenderSettings render_settings)
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
glfwSwapInterval(1);
|
||||
glDebugMessageCallback(MessageCallback, 0);
|
||||
glfwSwapInterval(0);
|
||||
// glDebugMessageCallback(MessageCallback, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef HYDRADELETECOMPONENTSTASK
|
||||
#define HYDRADELETECOMPONENTSTASK
|
||||
|
||||
|
||||
#include "../HydraTask.h"
|
||||
#include "../../engine/HydraEngine.h"
|
||||
#include "../../ecs/HydraECS.h"
|
||||
#include <memory>
|
||||
|
||||
|
||||
class HydraDeleteComponentsTask : public HydraTask
|
||||
{
|
||||
private:
|
||||
|
||||
protected:
|
||||
public:
|
||||
virtual void Process() override
|
||||
{
|
||||
|
||||
// GetEngine()->ECS()->DeleteComponents();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* HYDRADELETECOMPONENTSTASK */
|
||||
@@ -14,6 +14,7 @@ class HydraInitialiseComponentsTask : public HydraTask
|
||||
public:
|
||||
virtual void Process() override
|
||||
{
|
||||
|
||||
GetEngine()->ECS()->InitialiseComponents();
|
||||
}
|
||||
|
||||
|
||||
@@ -57,9 +57,10 @@ public:
|
||||
b3Pos pos = {};
|
||||
|
||||
shapeDef.density = 1.0f;
|
||||
shapeDef.baseMaterial.restitution = 0.4f;
|
||||
shapeDef.baseMaterial.restitution = 0.6f;
|
||||
|
||||
b3CreateHullShape(*m_body_id, &shapeDef, &box.base );
|
||||
DebugLog("B3LOG " + std::to_string(m_entity_id) + " BODY " + std::to_string(m_body_id->index1) + "\n");
|
||||
}
|
||||
|
||||
void Initialise(b3WorldId world_id, HydraPhysicsComponent physics_comp, b3BodyId* body_id, HydraID entity_id)
|
||||
|
||||
@@ -20,6 +20,7 @@ public:
|
||||
void Process() override
|
||||
{
|
||||
b3DestroyBody(m_body_id);
|
||||
DebugLog("B3 DELETE " + std::to_string(m_body_id.index1) + "\n");
|
||||
}
|
||||
|
||||
void Initialise(b3BodyId body_id)
|
||||
|
||||
@@ -20,9 +20,9 @@ public:
|
||||
void Process() override
|
||||
{
|
||||
b3WorldDef world_def = b3DefaultWorldDef();
|
||||
world_def.workerCount = 1;
|
||||
world_def.workerCount = 4;
|
||||
world_def.enableSleep = true;
|
||||
|
||||
world_def.enableContinuous = true;
|
||||
|
||||
*m_world_id = b3CreateWorld( &world_def );
|
||||
|
||||
|
||||
@@ -24,11 +24,11 @@ public:
|
||||
b3BodyEvents events = b3World_GetBodyEvents(m_world_id);
|
||||
|
||||
HydraTaskScheduler* task_scheduler = GetEngine()->TaskScheduler();
|
||||
HydraID barrier_id = task_scheduler->CreateBarrier();
|
||||
// HydraID barrier_id = task_scheduler->CreateBarrier();
|
||||
|
||||
for(uint32_t i = 0; i < events.moveCount; i ++)
|
||||
{
|
||||
HydraID task_id = task_scheduler->CreateTask<HydraSetWorldTransformTask>(HydraThreadAffinity::General, barrier_id);
|
||||
HydraID task_id = task_scheduler->CreateTask<HydraSetWorldTransformTask>(HydraThreadAffinity::General);//, barrier_id);
|
||||
HydraSetWorldTransformTask *set_task = static_cast<HydraSetWorldTransformTask *>(task_scheduler->GetTask(task_id));
|
||||
|
||||
glm::dvec3 position = {events.moveEvents[i].transform.p.x, events.moveEvents[i].transform.p.y, events.moveEvents[i].transform.p.z};
|
||||
@@ -37,9 +37,10 @@ public:
|
||||
HydraID* entity_id = reinterpret_cast<HydraID*>(events.moveEvents[i].userData);
|
||||
|
||||
set_task->Initialise(*entity_id, position, rotation);
|
||||
task_scheduler->StartTask(task_id);
|
||||
//task_scheduler->StartTask(task_id);
|
||||
task_scheduler->WaitForTask(task_id);
|
||||
}
|
||||
task_scheduler->WaitForBarrier(barrier_id);
|
||||
//task_scheduler->WaitForBarrier(barrier_id);
|
||||
}
|
||||
void Initialise(b3WorldId world_id, float delta_t_seconds)
|
||||
{
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,8 +1,11 @@
|
||||
================================================================================
|
||||
Linker Errors
|
||||
Generated: 2026-08-23T11:17:59.197Z
|
||||
Total Errors: 1
|
||||
Generated: 2026-08-27T18:38:11.302Z
|
||||
Total Errors: 2
|
||||
================================================================================
|
||||
|
||||
[LNK4098] (MSVC)
|
||||
defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library [C:\Code\HydraV3\build\HydraEngine\HydraEngine.vcxproj]
|
||||
[LNK2001] (MSVC)
|
||||
unresolved external symbol "protected: virtual void __cdecl HydraMaterialSystem::FreeSystemResources(void)" (?FreeSystemResources@HydraMaterialSystem@@MEAAXXZ) [C:\Code\HydraV3\build\HydraEngine\HydraEngine.vcxproj]
|
||||
|
||||
[LNK1120] (MSVC)
|
||||
1 unresolved externals [C:\Code\HydraV3\build\HydraEngine\HydraEngine.vcxproj]
|
||||
|
||||
Reference in New Issue
Block a user