Tess
This commit is contained in:
@@ -5,6 +5,14 @@
|
||||
// this value controls the size of the input and output arrays
|
||||
layout (vertices=4) out;
|
||||
|
||||
layout(binding = 0) uniform uniform_per_frame
|
||||
{
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
vec3 viewer_pos;
|
||||
uint light_count;
|
||||
} ubo_per_frame;
|
||||
|
||||
layout (location=0) in VS_OUT
|
||||
{
|
||||
vec2 vsUV;
|
||||
@@ -29,6 +37,11 @@ layout (location=0) out TC_OUT
|
||||
flat uint vsMaterialID;
|
||||
}tc_out[];
|
||||
|
||||
float inv_lerp (float a, float b, float t)
|
||||
{
|
||||
return (t - a) / (b - a);
|
||||
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
@@ -44,17 +57,31 @@ void main()
|
||||
tc_out[gl_InvocationID].vsChunkID = tc_in[gl_InvocationID].vsChunkID;
|
||||
tc_out[gl_InvocationID].vsMaterialID = tc_in[gl_InvocationID].vsMaterialID;
|
||||
|
||||
|
||||
vec3 centre = (gl_in[0].gl_Position.xyz +
|
||||
gl_in[1].gl_Position.xyz +
|
||||
gl_in[2].gl_Position.xyz +
|
||||
gl_in[3].gl_Position.xyz) / 4.0;
|
||||
|
||||
float patch_width = abs(length(gl_in[2].gl_Position.xyz - gl_in[0].gl_Position.xyz));
|
||||
float player_dist = abs(length(centre - ubo_per_frame.viewer_pos)) * 0.1;
|
||||
|
||||
float tess_factor = 1.0 - inv_lerp(0, patch_width, player_dist);
|
||||
tess_factor = max(0.5, tess_factor);
|
||||
// ----------------------------------------------------------------------
|
||||
// invocation zero controls tessellation levels for the entire patch
|
||||
if (gl_InvocationID == 0)
|
||||
{
|
||||
|
||||
int divs = 63;
|
||||
gl_TessLevelOuter[0] = divs;
|
||||
gl_TessLevelOuter[1] = divs;
|
||||
gl_TessLevelOuter[2] = divs;
|
||||
gl_TessLevelOuter[3] = divs;
|
||||
gl_TessLevelInner[0] = divs;
|
||||
gl_TessLevelInner[1] = divs;
|
||||
float edgedivs = 32.0;
|
||||
float innerdivs = tess_factor * 64.0;
|
||||
|
||||
gl_TessLevelOuter[0] = edgedivs;
|
||||
gl_TessLevelOuter[1] = edgedivs;
|
||||
gl_TessLevelOuter[2] = edgedivs;
|
||||
gl_TessLevelOuter[3] = edgedivs;
|
||||
|
||||
gl_TessLevelInner[0] = innerdivs;
|
||||
gl_TessLevelInner[1] = innerdivs;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// tessellation evaluation shader
|
||||
#version 450 core
|
||||
|
||||
layout (quads, equal_spacing, ccw) in;
|
||||
layout (quads, fractional_even_spacing, ccw) in;
|
||||
|
||||
layout(std430, binding = 1) readonly buffer positions_buffer
|
||||
{
|
||||
@@ -67,6 +67,8 @@ void main()
|
||||
vec4 p10 = gl_in[2].gl_Position;
|
||||
vec4 p11 = gl_in[3].gl_Position;
|
||||
|
||||
|
||||
|
||||
// compute patch surface normal
|
||||
vec4 uVec = p01 - p00;
|
||||
vec4 vVec = p10 - p00;
|
||||
@@ -90,4 +92,7 @@ void main()
|
||||
mat4 view = ubo_per_frame.view;
|
||||
mat4 proj = ubo_per_frame.proj;
|
||||
gl_Position = proj * view * model * p;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -44,7 +44,7 @@ void main()
|
||||
mat4 view = ubo_per_frame.view;
|
||||
mat4 proj = ubo_per_frame.proj;
|
||||
//model = mat4(1);
|
||||
gl_Position = proj * view * model * vec4(inPos, 1.0);
|
||||
gl_Position = vec4(inPos, 1.0);// proj * view * model * vec4(inPos, 1.0);
|
||||
vs_out.vsWorldPos = model * vec4(inPos,1);
|
||||
|
||||
vs_out.vsNormal = normalize(vec3(model * vec4(normalize(inNormal),0)));
|
||||
|
||||
@@ -20,33 +20,16 @@
|
||||
void HydraPlanetActor::FixedTick(float delta_t)
|
||||
{
|
||||
HydraTaskScheduler* task_scheduler = GetEngine()->TaskScheduler();
|
||||
if(task_scheduler->BarrierComplete(m_update_barrier))
|
||||
{
|
||||
//if(task_scheduler->BarrierComplete(m_update_barrier))
|
||||
//{
|
||||
// m_update_barrier = task_scheduler->CreateBarrier();
|
||||
// HydraID task_id = task_scheduler->CreateTask<HydraCheckPlanetResolutionTask>(HydraThreadAffinity::General, m_update_barrier);
|
||||
// HydraCheckPlanetResolutionTask* task = static_cast<HydraCheckPlanetResolutionTask*>(task_scheduler->GetTask(task_id));
|
||||
// task->Initialise(m_quads);
|
||||
// task_scheduler->StartTask(task_id);
|
||||
|
||||
m_update_barrier = task_scheduler->CreateBarrier();
|
||||
HydraID task_id = task_scheduler->CreateTask<HydraCheckPlanetResolutionTask>(HydraThreadAffinity::General, m_update_barrier);
|
||||
HydraCheckPlanetResolutionTask* task = static_cast<HydraCheckPlanetResolutionTask*>(task_scheduler->GetTask(task_id));
|
||||
task->Initialise(m_quads);
|
||||
task_scheduler->StartTask(task_id);
|
||||
// HydraID player_id = GetEngine()->GetPossessedPlayer();
|
||||
// HydraPositionComponent pos_comp = GetEngine()->ECS()->GetComponent<HydraPositionComponent>(player_id);
|
||||
// HydraActorManager* actor_manager = GetEngine()->ActorManager();
|
||||
// HydraECS* ecs = GetEngine()->ECS();
|
||||
|
||||
// HydraPlanetQuadActor* quad0 = static_cast<HydraPlanetQuadActor*>(actor_manager->GetActor(m_quads[0]));
|
||||
// HydraPlanetQuadActor* quad1 = static_cast<HydraPlanetQuadActor*>(actor_manager->GetActor(m_quads[1]));
|
||||
// HydraPlanetQuadActor* quad2 = static_cast<HydraPlanetQuadActor*>(actor_manager->GetActor(m_quads[2]));
|
||||
// HydraPlanetQuadActor* quad3 = static_cast<HydraPlanetQuadActor*>(actor_manager->GetActor(m_quads[3]));
|
||||
// HydraPlanetQuadActor* quad4 = static_cast<HydraPlanetQuadActor*>(actor_manager->GetActor(m_quads[4]));
|
||||
// HydraPlanetQuadActor* quad5 = static_cast<HydraPlanetQuadActor*>(actor_manager->GetActor(m_quads[5]));
|
||||
|
||||
// quad0->CheckResolution(pos_comp.position);
|
||||
// quad1->CheckResolution(pos_comp.position);
|
||||
// quad2->CheckResolution(pos_comp.position);
|
||||
// quad3->CheckResolution(pos_comp.position);
|
||||
// quad4->CheckResolution(pos_comp.position);
|
||||
// quad5->CheckResolution(pos_comp.position);
|
||||
}
|
||||
|
||||
//}
|
||||
}
|
||||
|
||||
void HydraPlanetActor::InitialiseComponents()
|
||||
|
||||
@@ -33,7 +33,6 @@ void HydraPlanetQuadActor::DeferredInitialiseComponents()
|
||||
|
||||
void HydraPlanetQuadActor::Destroy()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void HydraPlanetQuadActor::InitialiseQuad(HydraID parent_id, float planet_diameter, float quad_dimension, uint32_t divisions, glm::dvec3 origin, glm::vec3 orientation)
|
||||
@@ -44,7 +43,7 @@ void HydraPlanetQuadActor::InitialiseQuad(HydraID parent_id, float planet_diamet
|
||||
m_quad_dimension = quad_dimension;
|
||||
m_orientation = orientation;
|
||||
m_parent_id = parent_id;
|
||||
//GetEngine()->ActorManager()->SetPositionAndOrientation(GetID(), origin, orientation, true);
|
||||
// GetEngine()->ActorManager()->SetPositionAndOrientation(GetID(), origin, orientation, true);
|
||||
_CreateMesh();
|
||||
}
|
||||
|
||||
@@ -58,11 +57,11 @@ void HydraPlanetQuadActor::CheckResolution(glm::dvec3 player_position)
|
||||
double distance_to_quad = glm::length(player_position - m_centre);
|
||||
|
||||
// might need to bias this so it splits sooner and merges later
|
||||
if ((distance_to_quad < m_quad_dimension)&& (m_quad_dimension > 64))
|
||||
{
|
||||
if ((distance_to_quad < m_quad_dimension) && (m_quad_dimension > 64))
|
||||
{
|
||||
should_split = true;
|
||||
}
|
||||
if(distance_to_quad > m_quad_dimension * 1.1f)
|
||||
if (distance_to_quad > m_quad_dimension * 1.1f)
|
||||
{
|
||||
should_merge = true;
|
||||
}
|
||||
@@ -93,7 +92,7 @@ void HydraPlanetQuadActor::CheckResolution(glm::dvec3 player_position)
|
||||
{
|
||||
for (HydraID child_id : m_child_quads)
|
||||
{
|
||||
HydraPlanetQuadActor* child = static_cast<HydraPlanetQuadActor*>(GetEngine()->ActorManager()->GetActor(child_id));
|
||||
HydraPlanetQuadActor *child = static_cast<HydraPlanetQuadActor *>(GetEngine()->ActorManager()->GetActor(child_id));
|
||||
child->CheckResolution(player_position);
|
||||
GetEngine()->ActorManager()->DeleteActor(child_id);
|
||||
}
|
||||
@@ -107,11 +106,10 @@ void HydraPlanetQuadActor::CheckResolution(glm::dvec3 player_position)
|
||||
|
||||
HydraPlanetQuadActor::~HydraPlanetQuadActor()
|
||||
{
|
||||
if(m_center_actor != INVALID_HYDRA_ID)
|
||||
if (m_center_actor != INVALID_HYDRA_ID)
|
||||
{
|
||||
GetEngine()->ActorManager()->DeleteActor(m_center_actor);
|
||||
GetEngine()->ActorManager()->DeleteActor(m_center_actor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HydraPlanetQuadActor::_MergeQuads()
|
||||
@@ -121,7 +119,7 @@ void HydraPlanetQuadActor::_MergeQuads()
|
||||
glm::vec3 HydraPlanetQuadActor::_ProjectSphere(glm::dvec4 vert_in, glm::dmat4 trans, glm::dmat4 inv_trans, double diameter, glm::vec3 origin)
|
||||
{
|
||||
|
||||
|
||||
return glm::dvec3(vert_in);
|
||||
glm::dvec4 vert = trans * vert_in;
|
||||
vert = glm::normalize(vert);
|
||||
vert = vert * (m_planet_diameter / 2.0);
|
||||
@@ -142,12 +140,12 @@ glm::vec3 HydraPlanetQuadActor::_ProjectSphere(glm::dvec4 vert_in, glm::dmat4 tr
|
||||
glm::dvec3 HydraPlanetQuadActor::_ProjectCentre(glm::vec3 vert_in, glm::dmat4 trans, double diameter)
|
||||
{
|
||||
|
||||
|
||||
glm::dvec4 vert = trans * glm::dvec4(vert_in,1);
|
||||
|
||||
return glm::dvec3(vert_in);
|
||||
glm::dvec4 vert = trans * glm::dvec4(vert_in, 1);
|
||||
|
||||
vert = glm::normalize(vert);
|
||||
vert = vert * (m_planet_diameter / 2.0);
|
||||
|
||||
|
||||
// vert_in = glm::normalize(vert_in);
|
||||
// vert_in = vert_in * (m_planet_diameter / 2.0f);
|
||||
FastNoiseLite fnl;
|
||||
@@ -157,7 +155,6 @@ glm::dvec3 HydraPlanetQuadActor::_ProjectCentre(glm::vec3 vert_in, glm::dmat4 tr
|
||||
fnl.SetFrequency(0.00009);
|
||||
fnl.SetFractalOctaves(15);
|
||||
fnl.SetFractalLacunarity(2.1);
|
||||
|
||||
|
||||
float noise = fnl.GetNoise(vert.x, vert.y, vert.z);
|
||||
|
||||
@@ -189,7 +186,7 @@ void HydraPlanetQuadActor::_Split()
|
||||
HydraPlanetQuadActor *quad = static_cast<HydraPlanetQuadActor *>(GetEngine()->ActorManager()->GetActor(quad_id));
|
||||
GetEngine()->ActorManager()->InitialiseActor(quad_id);
|
||||
quad->InitialiseQuad(GetID(), m_planet_diameter, child_quad_size, m_divisions, origins[i], m_orientation);
|
||||
|
||||
|
||||
m_child_quads.push_back(quad_id);
|
||||
}
|
||||
}
|
||||
@@ -207,12 +204,13 @@ void HydraPlanetQuadActor::_CreateMesh()
|
||||
HydraMeshManager *mesh_manager = GetEngine()->MeshManager();
|
||||
HydraID mesh_id = mesh_manager->CreateMesh();
|
||||
HydraMesh *mesh = mesh_manager->GetMesh(mesh_id);
|
||||
|
||||
|
||||
HydraMaterialComponent mat_comp = GetEngine()->ECS()->GetComponent<HydraMaterialComponent>(GetID());
|
||||
HydraPositionComponent pos_comp = GetEngine()->ECS()->GetComponent<HydraPositionComponent>(GetID());
|
||||
|
||||
uint32_t vert_counts = m_divisions * m_divisions;
|
||||
uint32_t index_counts = ((m_divisions - 1) * (m_divisions - 1)) * 6;
|
||||
uint32_t vert_counts = 4;
|
||||
uint32_t index_counts = 4;
|
||||
|
||||
mesh->vertexes.resize(vert_counts);
|
||||
mesh->indexes.resize(index_counts);
|
||||
|
||||
@@ -225,33 +223,20 @@ void HydraPlanetQuadActor::_CreateMesh()
|
||||
float max_z = 0.0f;
|
||||
|
||||
float min_u = 0;
|
||||
float min_v = 1 * (m_divisions - 1);
|
||||
float min_v = 0;
|
||||
|
||||
float max_u = 1 * (m_divisions - 1);
|
||||
float max_v = 0;
|
||||
|
||||
float xy_inc = m_quad_dimension / (m_divisions - 1);
|
||||
float u_inc = max_u / (m_divisions - 1);
|
||||
float v_inc = -min_v / (m_divisions - 1);
|
||||
float max_u = 1;
|
||||
float max_v = 1;
|
||||
|
||||
// 1---2
|
||||
// | / |
|
||||
// 0---3
|
||||
|
||||
HydraID actor_id = GetID();
|
||||
|
||||
float y = min_y;
|
||||
float x = min_x;
|
||||
float u = min_u;
|
||||
float v = min_v;
|
||||
|
||||
uint32_t vert_idx = 0;
|
||||
uint32_t index_idx = 0;
|
||||
// glm::mat4 trans = GetEngine()->ActorManager()->GetActorPose(actor_id);
|
||||
|
||||
|
||||
glm::dvec4 quad_direction = glm::toMat4(glm::quat(m_orientation)) * glm::dvec4(0,0,1,1);
|
||||
glm::dvec4 quad_direction = glm::toMat4(glm::quat(m_orientation)) * glm::dvec4(0, 0, 1, 1);
|
||||
glm::dvec4 transformed_origin = glm::toMat4(glm::quat(m_orientation)) * glm::dvec4(m_origin, 1);
|
||||
glm::dvec4 quad_position = transformed_origin + (quad_direction * (m_planet_diameter /2.0));
|
||||
glm::dvec4 quad_position = transformed_origin + (quad_direction * (m_planet_diameter / 2.0));
|
||||
|
||||
glm::dmat4 trans_matrix = glm::translate(glm::dvec3(quad_position));
|
||||
glm::dmat4 rot_matrix = glm::toMat4(glm::quat(m_orientation));
|
||||
@@ -260,66 +245,32 @@ void HydraPlanetQuadActor::_CreateMesh()
|
||||
|
||||
GetEngine()->ActorManager()->SetPositionAndOrientation(GetID(), quad_position, m_orientation, true);
|
||||
|
||||
m_centre = _ProjectCentre(glm::vec3(0,0,1), trans, m_planet_diameter);
|
||||
m_centre = _ProjectCentre(glm::vec3(0, 0, 1), trans, m_planet_diameter);
|
||||
|
||||
// Create Vertex
|
||||
glm::dvec4 vert = glm::dvec4(min_x, min_y, min_z, 1.0);
|
||||
glm::vec3 final_vert = _ProjectSphere(vert, trans, inv_trans, m_planet_diameter, m_origin);
|
||||
mesh->vertexes[0] = {final_vert.x, final_vert.y, final_vert.z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
vert = glm::dvec4(min_x, max_y, min_z, 1.0);
|
||||
final_vert = _ProjectSphere(vert, trans, inv_trans, m_planet_diameter, m_origin);
|
||||
mesh->vertexes[1] = {final_vert.x, final_vert.y, final_vert.z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
vert = glm::dvec4(max_x, max_y, min_z, 1.0);
|
||||
final_vert = _ProjectSphere(vert, trans, inv_trans, m_planet_diameter, m_origin);
|
||||
mesh->vertexes[2] = {final_vert.x, final_vert.y, final_vert.z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
vert = glm::dvec4(max_x, min_y, min_z, 1.0);
|
||||
final_vert = _ProjectSphere(vert, trans, inv_trans, m_planet_diameter, m_origin);
|
||||
mesh->vertexes[3] = {final_vert.x, final_vert.y, final_vert.z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
mesh->indexes[0] = 0;
|
||||
mesh->indexes[1] = 3;
|
||||
mesh->indexes[2] = 1;
|
||||
mesh->indexes[3] = 2;
|
||||
|
||||
|
||||
// m_center_actor = GetEngine()->ActorManager()->CreateActor<HydraTestCubeActor>();
|
||||
// HydraTestCubeActor* center_actor = static_cast<HydraTestCubeActor*>(GetEngine()->ActorManager()->GetActor(m_center_actor));
|
||||
// center_actor->SetScale(1);
|
||||
// GetEngine()->ActorManager()->InitialiseActor(m_center_actor);
|
||||
// GetEngine()->ActorManager()->SetPosition(m_center_actor, m_centre);
|
||||
|
||||
for (uint32_t y_count = 0; y_count < m_divisions - 1; y_count++)
|
||||
{
|
||||
for (uint32_t x_count = 0; x_count < m_divisions - 1; x_count++)
|
||||
{
|
||||
// Create Vertex
|
||||
glm::dvec4 vert = glm::dvec4(x, y, min_z, 1.0);
|
||||
glm::vec3 final_vert = _ProjectSphere(vert, trans, inv_trans, m_planet_diameter, m_origin);
|
||||
|
||||
mesh->vertexes[vert_idx] = {final_vert.x, final_vert.y, final_vert.z, u, v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
uint32_t ind0 = vert_idx;
|
||||
uint32_t ind1 = vert_idx + m_divisions;
|
||||
uint32_t ind2 = vert_idx + m_divisions + 1;
|
||||
uint32_t ind3 = vert_idx + 1;
|
||||
|
||||
mesh->indexes[index_idx + 0] = ind0;
|
||||
mesh->indexes[index_idx + 1] = ind2;
|
||||
mesh->indexes[index_idx + 2] = ind1;
|
||||
mesh->indexes[index_idx + 3] = ind0;
|
||||
mesh->indexes[index_idx + 4] = ind3;
|
||||
mesh->indexes[index_idx + 5] = ind2;
|
||||
|
||||
x += xy_inc;
|
||||
u += u_inc;
|
||||
vert_idx++;
|
||||
index_idx += 6;
|
||||
}
|
||||
|
||||
glm::dvec4 vert = glm::dvec4(x, y, min_z, 1.0);
|
||||
glm::vec3 final_vert = _ProjectSphere(vert, trans, inv_trans, m_planet_diameter, m_origin);
|
||||
mesh->vertexes[vert_idx] = {final_vert.x, final_vert.y, final_vert.z, u, v, actor_id, mat_comp.material_id, 0};
|
||||
// Add the end vert but no indexes
|
||||
// mesh->vertexes[vert_idx] = {x, y, min_z, u, v, actor_id, mat_comp.material_id, 0};
|
||||
vert_idx++;
|
||||
y += xy_inc;
|
||||
v += v_inc;
|
||||
x = min_x;
|
||||
u = min_u;
|
||||
}
|
||||
// the last row
|
||||
for (uint32_t x_count = 0; x_count < m_divisions; x_count++)
|
||||
{
|
||||
glm::dvec4 vert = glm::dvec4(x, y, min_z, 1.0);
|
||||
glm::vec3 final_vert = _ProjectSphere(vert, trans, inv_trans, m_planet_diameter, m_origin);
|
||||
mesh->vertexes[vert_idx] = {final_vert.x, final_vert.y, final_vert.z, u, v, actor_id, mat_comp.material_id, 0};
|
||||
x += xy_inc;
|
||||
u += u_inc;
|
||||
vert_idx++;
|
||||
}
|
||||
|
||||
mesh_manager->CalculateNormals(mesh->mesh_id);
|
||||
//mesh_manager->CalculateNormals(mesh->mesh_id);
|
||||
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
HydraMeshComponent mesh_comp;
|
||||
@@ -328,9 +279,136 @@ void HydraPlanetQuadActor::_CreateMesh()
|
||||
mesh_comp.mesh_state = HYDRA_STATE::Waiting;
|
||||
|
||||
ecs->AddComponent<HydraMeshComponent>(GetID(), mesh_comp);
|
||||
HydraRenderableComponent& render_comp = GetEngine()->ECS()->GetComponent<HydraRenderableComponent>(GetID());
|
||||
HydraRenderableComponent &render_comp = GetEngine()->ECS()->GetComponent<HydraRenderableComponent>(GetID());
|
||||
render_comp.active = true;
|
||||
}
|
||||
// void HydraPlanetQuadActor::_CreateMesh()
|
||||
// {
|
||||
// HydraMeshManager *mesh_manager = GetEngine()->MeshManager();
|
||||
// HydraID mesh_id = mesh_manager->CreateMesh();
|
||||
// HydraMesh *mesh = mesh_manager->GetMesh(mesh_id);
|
||||
|
||||
// HydraMaterialComponent mat_comp = GetEngine()->ECS()->GetComponent<HydraMaterialComponent>(GetID());
|
||||
// HydraPositionComponent pos_comp = GetEngine()->ECS()->GetComponent<HydraPositionComponent>(GetID());
|
||||
|
||||
// uint32_t vert_counts = m_divisions * m_divisions;
|
||||
// uint32_t index_counts = ((m_divisions - 1) * (m_divisions - 1)) * 6;
|
||||
// mesh->vertexes.resize(vert_counts);
|
||||
// mesh->indexes.resize(index_counts);
|
||||
|
||||
// float min_x = -m_quad_dimension / 2.0f;
|
||||
// float min_y = -m_quad_dimension / 2.0f;
|
||||
// float min_z = 0.0f;
|
||||
|
||||
// float max_x = m_quad_dimension / 2.0f;
|
||||
// float max_y = m_quad_dimension / 2.0f;
|
||||
// float max_z = 0.0f;
|
||||
|
||||
// float min_u = 0;
|
||||
// float min_v = 1 * (m_divisions - 1);
|
||||
|
||||
// float max_u = 1 * (m_divisions - 1);
|
||||
// float max_v = 0;
|
||||
|
||||
// float xy_inc = m_quad_dimension / (m_divisions - 1);
|
||||
// float u_inc = max_u / (m_divisions - 1);
|
||||
// float v_inc = -min_v / (m_divisions - 1);
|
||||
|
||||
// // 1---2
|
||||
// // | / |
|
||||
// // 0---3
|
||||
// HydraID actor_id = GetID();
|
||||
|
||||
// float y = min_y;
|
||||
// float x = min_x;
|
||||
// float u = min_u;
|
||||
// float v = min_v;
|
||||
|
||||
// uint32_t vert_idx = 0;
|
||||
// uint32_t index_idx = 0;
|
||||
// // glm::mat4 trans = GetEngine()->ActorManager()->GetActorPose(actor_id);
|
||||
|
||||
// glm::dvec4 quad_direction = glm::toMat4(glm::quat(m_orientation)) * glm::dvec4(0,0,1,1);
|
||||
// glm::dvec4 transformed_origin = glm::toMat4(glm::quat(m_orientation)) * glm::dvec4(m_origin, 1);
|
||||
// glm::dvec4 quad_position = transformed_origin + (quad_direction * (m_planet_diameter /2.0));
|
||||
|
||||
// glm::dmat4 trans_matrix = glm::translate(glm::dvec3(quad_position));
|
||||
// glm::dmat4 rot_matrix = glm::toMat4(glm::quat(m_orientation));
|
||||
// glm::dmat4 trans = trans_matrix * rot_matrix;
|
||||
// glm::dmat4 inv_trans = glm::inverse(trans);
|
||||
|
||||
// GetEngine()->ActorManager()->SetPositionAndOrientation(GetID(), quad_position, m_orientation, true);
|
||||
|
||||
// m_centre = _ProjectCentre(glm::vec3(0,0,1), trans, m_planet_diameter);
|
||||
|
||||
// // m_center_actor = GetEngine()->ActorManager()->CreateActor<HydraTestCubeActor>();
|
||||
// // HydraTestCubeActor* center_actor = static_cast<HydraTestCubeActor*>(GetEngine()->ActorManager()->GetActor(m_center_actor));
|
||||
// // center_actor->SetScale(1);
|
||||
// // GetEngine()->ActorManager()->InitialiseActor(m_center_actor);
|
||||
// // GetEngine()->ActorManager()->SetPosition(m_center_actor, m_centre);
|
||||
|
||||
// for (uint32_t y_count = 0; y_count < m_divisions - 1; y_count++)
|
||||
// {
|
||||
// for (uint32_t x_count = 0; x_count < m_divisions - 1; x_count++)
|
||||
// {
|
||||
// // Create Vertex
|
||||
// glm::dvec4 vert = glm::dvec4(x, y, min_z, 1.0);
|
||||
// glm::vec3 final_vert = _ProjectSphere(vert, trans, inv_trans, m_planet_diameter, m_origin);
|
||||
|
||||
// mesh->vertexes[vert_idx] = {final_vert.x, final_vert.y, final_vert.z, u, v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
// uint32_t ind0 = vert_idx;
|
||||
// uint32_t ind1 = vert_idx + m_divisions;
|
||||
// uint32_t ind2 = vert_idx + m_divisions + 1;
|
||||
// uint32_t ind3 = vert_idx + 1;
|
||||
|
||||
// mesh->indexes[index_idx + 0] = ind0;
|
||||
// mesh->indexes[index_idx + 1] = ind2;
|
||||
// mesh->indexes[index_idx + 2] = ind1;
|
||||
// mesh->indexes[index_idx + 3] = ind0;
|
||||
// mesh->indexes[index_idx + 4] = ind3;
|
||||
// mesh->indexes[index_idx + 5] = ind2;
|
||||
|
||||
// x += xy_inc;
|
||||
// u += u_inc;
|
||||
// vert_idx++;
|
||||
// index_idx += 6;
|
||||
// }
|
||||
|
||||
// glm::dvec4 vert = glm::dvec4(x, y, min_z, 1.0);
|
||||
// glm::vec3 final_vert = _ProjectSphere(vert, trans, inv_trans, m_planet_diameter, m_origin);
|
||||
// mesh->vertexes[vert_idx] = {final_vert.x, final_vert.y, final_vert.z, u, v, actor_id, mat_comp.material_id, 0};
|
||||
// // Add the end vert but no indexes
|
||||
// // mesh->vertexes[vert_idx] = {x, y, min_z, u, v, actor_id, mat_comp.material_id, 0};
|
||||
// vert_idx++;
|
||||
// y += xy_inc;
|
||||
// v += v_inc;
|
||||
// x = min_x;
|
||||
// u = min_u;
|
||||
// }
|
||||
// // the last row
|
||||
// for (uint32_t x_count = 0; x_count < m_divisions; x_count++)
|
||||
// {
|
||||
// glm::dvec4 vert = glm::dvec4(x, y, min_z, 1.0);
|
||||
// glm::vec3 final_vert = _ProjectSphere(vert, trans, inv_trans, m_planet_diameter, m_origin);
|
||||
// mesh->vertexes[vert_idx] = {final_vert.x, final_vert.y, final_vert.z, u, v, actor_id, mat_comp.material_id, 0};
|
||||
// x += xy_inc;
|
||||
// u += u_inc;
|
||||
// vert_idx++;
|
||||
// }
|
||||
|
||||
// mesh_manager->CalculateNormals(mesh->mesh_id);
|
||||
|
||||
// HydraECS *ecs = GetEngine()->ECS();
|
||||
// HydraMeshComponent mesh_comp;
|
||||
|
||||
// mesh_comp.mesh_id = mesh_id;
|
||||
// mesh_comp.mesh_state = HYDRA_STATE::Waiting;
|
||||
|
||||
// ecs->AddComponent<HydraMeshComponent>(GetID(), mesh_comp);
|
||||
// HydraRenderableComponent& render_comp = GetEngine()->ECS()->GetComponent<HydraRenderableComponent>(GetID());
|
||||
// render_comp.active = true;
|
||||
// }
|
||||
|
||||
void HydraPlanetQuadActor::_CreateMaterial()
|
||||
{
|
||||
@@ -374,8 +452,8 @@ void HydraPlanetQuadActor::_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);
|
||||
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_LANDSCAPE, 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);
|
||||
render_comp.active = false;
|
||||
|
||||
@@ -38,7 +38,7 @@ HydraID HydraTextureBufferManager::LoadTexture(std::string texture_filename)
|
||||
int height = 0;
|
||||
int channels = 0;
|
||||
|
||||
//stbi_set_flip_vertically_on_load(true);
|
||||
stbi_set_flip_vertically_on_load(true);
|
||||
data = stbi_load(texture_filename.c_str(), &width, &height, &channels, 0);
|
||||
|
||||
if (data == nullptr)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "HydraDeferredPipeline.h"
|
||||
#include "HydraRenderStage.h"
|
||||
#include "HydraLandscapeRenderStage.h"
|
||||
#include "../engine/HydraEngine.h"
|
||||
#include "../buffer/HydraBufferManager.h"
|
||||
#include "../buffer/HydraTextureBufferManager.h"
|
||||
@@ -216,13 +217,14 @@ void HydraDeferredPipeline::_CreateColourRenderStage()
|
||||
true,
|
||||
GL_BACK,
|
||||
true,
|
||||
GL_FILL,
|
||||
HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR);
|
||||
m_render_stages.push_back(render_stage);
|
||||
}
|
||||
|
||||
void HydraDeferredPipeline::_CreateLandscapeRenderStage()
|
||||
{
|
||||
HydraRenderStage* render_stage = new HydraRenderStage();
|
||||
HydraLandscapeRenderStage* render_stage = new HydraLandscapeRenderStage();
|
||||
std::string shader_path = std::string(shader_base);
|
||||
HydraBufferManager* buffer_manager = GetEngine()->BufferManager();
|
||||
|
||||
@@ -265,6 +267,7 @@ void HydraDeferredPipeline::_CreateLandscapeRenderStage()
|
||||
true,
|
||||
GL_BACK,
|
||||
true,
|
||||
GL_LINE,
|
||||
HYDRA_RENDERABLE_TYPE::HYDRA_LANDSCAPE);
|
||||
m_render_stages.push_back(render_stage);
|
||||
}
|
||||
@@ -340,6 +343,7 @@ void HydraDeferredPipeline::_CreateOutputRenderStage()
|
||||
false,
|
||||
GL_BACK,
|
||||
true,
|
||||
GL_FILL,
|
||||
HYDRA_RENDERABLE_TYPE::HYDRA_OUTPUT);
|
||||
m_render_stages.push_back(render_stage);
|
||||
}
|
||||
@@ -385,6 +389,7 @@ void HydraDeferredPipeline::_CreateTextureDebugOutputStage()
|
||||
false,
|
||||
GL_BACK,
|
||||
false,
|
||||
GL_FILL,
|
||||
HYDRA_RENDERABLE_TYPE::HYDRA_TEXTURE_DEBUG);
|
||||
m_render_stages.push_back(render_stage);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ void HydraForwardPipeline::Initialise()
|
||||
std::vector<uint32_t> textures;
|
||||
std::vector<uint32_t> rb_attachments;
|
||||
|
||||
render_stage->Initialise(shader_path + "forward_shader.vert", shader_path + "forward_shader.frag", "", "", "", shader_binding, 0, textures, true, GL_BACK, true, HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR);
|
||||
render_stage->Initialise(shader_path + "forward_shader.vert", shader_path + "forward_shader.frag", "", "", "", shader_binding, 0, textures, true, GL_BACK, true, GL_FILL, HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR);
|
||||
m_render_stages.push_back(render_stage);
|
||||
|
||||
m_per_frame_ubo = buffer_manager->CreateGPUBuffer("PerFrameUBO",
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#include "HydraLandscapeRenderStage.h"
|
||||
#include "../ecs/HydraECS.h"
|
||||
#include "../ecs/components/HydraMeshComponent.h"
|
||||
#include "../ecs/components/HydraRenderableComponent.h"
|
||||
|
||||
#include "../engine/HydraEngine.h"
|
||||
#include "../buffer/HydraVertexBufferManager.h"
|
||||
#include "../buffer/HydraBufferManager.h"
|
||||
#include <set>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <GLMIncludes.h>
|
||||
|
||||
void HydraLandscapeRenderStage::Render(std::set<HydraID> &entities, uint32_t framebuffer_id)
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
if (framebuffer_id != INVALID_HYDRA_ID)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id);
|
||||
}
|
||||
// glDrawBuffers(m_rb_attachments.size(), &m_rb_attachments[0]);
|
||||
HydraVertexBufferManager *vert_buffer_mananger = GetEngine()->VertexBufferManager();
|
||||
glUseProgram(m_program);
|
||||
_BindBuffers();
|
||||
_BindTextures();
|
||||
HydraSignature signature = {};
|
||||
signature.set(m_renderable_type, true);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, m_fill_mode);
|
||||
if (m_cull)
|
||||
{
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(m_cull_face);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDisable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
if (m_depth_enable)
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
glPatchParameteri(GL_PATCH_VERTICES, 4);
|
||||
for (const auto &entity_id : entities)
|
||||
{
|
||||
HydraRenderableComponent render_comp = ecs->GetComponent<HydraRenderableComponent>(entity_id);
|
||||
if (((render_comp.renderable_types & signature) == signature) && (render_comp.active))
|
||||
{
|
||||
if (ecs->HasComponent<HydraMeshComponent>(entity_id))
|
||||
{
|
||||
HydraMeshComponent mesh_comp = ecs->GetComponent<HydraMeshComponent>(entity_id);
|
||||
if (mesh_comp.mesh_state == HYDRA_STATE::Ready)
|
||||
{
|
||||
HydraVertexBuffer &vertex_buffer = vert_buffer_mananger->GetVertexBuffer(mesh_comp.vertex_buffer_id);
|
||||
|
||||
glBindVertexArray(vertex_buffer.vao);
|
||||
|
||||
glDrawElements(GL_PATCHES, vertex_buffer.triangle_count, GL_UNSIGNED_INT, (void *)0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
glBindVertexArray(0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef HYDRALANDSCAPERENDERSTAGE
|
||||
#define HYDRALANDSCAPERENDERSTAGE
|
||||
|
||||
#include "../engine/HydraObject.h"
|
||||
#include "../windowmanager/HydraRenderSettings.h"
|
||||
#include "HydraShaderBinding.hpp"
|
||||
#include "../GlewIncludes.h"
|
||||
#include "HydraRenderStage.h"
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
class HydraLandscapeRenderStage : public HydraRenderStage
|
||||
{
|
||||
public:
|
||||
|
||||
void Render(std::set<HydraID>& entities, uint32_t framebuffer_id) override;
|
||||
|
||||
private:
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* HYDRALANDSCAPERENDERSTAGE */
|
||||
@@ -23,6 +23,7 @@ void HydraRenderStage::Initialise(std::string vertex_shader_file,
|
||||
bool enable_culling,
|
||||
uint32_t cull_face,
|
||||
bool depth_enable,
|
||||
uint32_t fill_mode,
|
||||
HYDRA_RENDERABLE_TYPE renderable_type)
|
||||
{
|
||||
m_framebuffer_id = framebuffer_id;
|
||||
@@ -33,6 +34,7 @@ void HydraRenderStage::Initialise(std::string vertex_shader_file,
|
||||
m_cull = enable_culling;
|
||||
m_program = glCreateProgram();
|
||||
m_cull_face = cull_face;
|
||||
m_fill_mode = fill_mode;
|
||||
if (vertex_shader_file.length() > 0)
|
||||
{
|
||||
m_vertex_shader = _LoadShader(vertex_shader_file, GL_VERTEX_SHADER);
|
||||
@@ -102,7 +104,7 @@ void HydraRenderStage::Render(std::set<HydraID> &entities, uint32_t framebuffer_
|
||||
_BindTextures();
|
||||
HydraSignature signature = {};
|
||||
signature.set(m_renderable_type, true);
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, m_fill_mode);
|
||||
if (m_cull)
|
||||
{
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
@@ -21,14 +21,17 @@ class HydraRenderStage : public HydraObject
|
||||
bool enable_culling,
|
||||
uint32_t cull_face,
|
||||
bool depth_enable,
|
||||
uint32_t fill_mode,
|
||||
HYDRA_RENDERABLE_TYPE renderable_type);
|
||||
void ShutDown();
|
||||
void Render(std::set<HydraID>& entities, uint32_t framebuffer_id);
|
||||
virtual void Render(std::set<HydraID>& entities, uint32_t framebuffer_id);
|
||||
void Render(std::set<HydraID>& entities);
|
||||
private:
|
||||
uint32_t _LoadShader(std::string filename, uint32_t shader_type);
|
||||
std::string _LoadShaderSource(std::string filename);
|
||||
void _BindBuffers();
|
||||
|
||||
protected:
|
||||
void _BindBuffers();
|
||||
void _BindTextures();
|
||||
HydraShaderBinding m_shader_binding;
|
||||
uint32_t m_vertex_shader = GL_INVALID_VALUE;
|
||||
@@ -40,6 +43,7 @@ class HydraRenderStage : public HydraObject
|
||||
uint32_t m_renderable_type;
|
||||
uint32_t m_framebuffer_id = 0;
|
||||
uint32_t m_cull_face = GL_NONE;
|
||||
uint32_t m_fill_mode = GL_FILL;
|
||||
bool m_cull = false;
|
||||
bool m_depth_enable = true;
|
||||
std::vector<uint32_t> m_textures;
|
||||
|
||||
@@ -165,6 +165,7 @@ void HydraShadowPipeline::_CreatePointRenderStage()
|
||||
true,
|
||||
GL_BACK,
|
||||
true,
|
||||
GL_FILL,
|
||||
HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR);
|
||||
m_render_stages[POINT_RENDER_STAGE] = render_stage;
|
||||
}
|
||||
@@ -218,8 +219,9 @@ void HydraShadowPipeline::_CreateDirectionalRenderStage()
|
||||
0,
|
||||
textures,
|
||||
true,
|
||||
GL_NONE,
|
||||
GL_BACK,
|
||||
true,
|
||||
GL_FILL,
|
||||
HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR);
|
||||
m_render_stages[DIRECTIONAL_RENDER_STAGE] = render_stage;
|
||||
}
|
||||
@@ -274,6 +276,7 @@ void HydraShadowPipeline::_CreateSpotRenderStage()
|
||||
true,
|
||||
GL_BACK,
|
||||
true,
|
||||
GL_FILL,
|
||||
HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR);
|
||||
m_render_stages[SPOT_RENDER_STAGE] = render_stage;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ void HydraRenderer::Initialise(HydraRenderSettings render_settings)
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
|
||||
glfwSwapInterval(0);
|
||||
// glDebugMessageCallback(MessageCallback, 0);
|
||||
glDebugMessageCallback(MessageCallback, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user