Commit 62cdd5c6 authored by Johannes Braun's avatar Johannes Braun
Browse files

Linespace generation is now up and running.

parent 3c473089
......@@ -10,8 +10,8 @@
struct Patch
{
uint face;
uvec2 index;
uint padding;
uvec2 index;
};
struct Line
......@@ -19,11 +19,11 @@ struct Line
vec4 center_begin;
vec4 center_end;
Patch begin;
Patch end;
Hit nearest;
Hit farthest;
Patch begin;
Patch end;
};
STD_BUFFER line_buffer
......@@ -38,6 +38,7 @@ uniform mat4 u_view_projection;
uniform uint u_mesh;
uniform uint u_triangle_count;
uniform bool u_full_ls;
out vec4 color;
......@@ -48,60 +49,54 @@ void main()
Line line = b_lines[tbi_id];
vec4 last_position;
gl_Position = u_view_projection * line.center_begin;
color = vec4(0, 1, 0, 1);
if (line.end.face == 6) {
if (u_full_ls) {
gl_Position = u_view_projection * line.center_begin;
color = vec4(0, 1, 0, 1);
EmitVertex();
}
gl_Position = u_view_projection * line.center_end;
color = vec4(1, 0, 0, 1);
if (line.end.face == 6) {
gl_Position = u_view_projection * line.center_end;
color = vec4(1, 0, 0, 1);
EmitVertex();
}
EndPrimitive();
return;
if (line.nearest.triangle < u_triangle_count && line.farthest.triangle < u_triangle_count) {
Mesh mesh = b_meshes[u_mesh];
Triangle triangle = mesh.triangles[line.nearest.triangle];
Vertex v1 = mesh.vertices[triangle.indices[1]];
Vertex v2 = mesh.vertices[triangle.indices[2]];
Vertex v3 = mesh.vertices[triangle.indices[0]];
vec4 position = hit__getFromBarycentric(line.nearest.barycentric, triangle, position);
gl_Position = u_view_projection * position;
color = vec4(0, 1, 0, 1);
last_position = position;
color.b = (line.begin.face) / 6.f;
EmitVertex();
EndPrimitive();
}
else {
if (line.nearest.triangle < u_triangle_count && line.farthest.triangle < u_triangle_count) {
Mesh mesh = b_meshes[u_mesh];
Triangle triangle = mesh.triangles[line.nearest.triangle];
Vertex v1 = mesh.vertices[triangle.indices[1]];
Vertex v2 = mesh.vertices[triangle.indices[2]];
Vertex v3 = mesh.vertices[triangle.indices[0]];
vec4 position = hit__getFromBarycentric(line.nearest.barycentric, triangle, position);
gl_Position = u_view_projection * position;
color = vec4(0, 1, 0, 1);
last_position = position;
color.b = (line.begin.face) / 6.f;
EmitVertex();
}
if (line.farthest.triangle < u_triangle_count) {
Mesh mesh = b_meshes[u_mesh];
Triangle triangle = mesh.triangles[line.farthest.triangle];
Vertex v1 = mesh.vertices[triangle.indices[1]];
Vertex v2 = mesh.vertices[triangle.indices[2]];
Vertex v3 = mesh.vertices[triangle.indices[0]];
if (line.farthest.triangle < u_triangle_count) {
Mesh mesh = b_meshes[u_mesh];
Triangle triangle = mesh.triangles[line.farthest.triangle];
Vertex v1 = mesh.vertices[triangle.indices[1]];
Vertex v2 = mesh.vertices[triangle.indices[2]];
Vertex v3 = mesh.vertices[triangle.indices[0]];
vec4 position = hit__getFromBarycentric(line.farthest.barycentric, triangle, position);
vec4 position = hit__getFromBarycentric(line.farthest.barycentric, triangle, position);
if (position == last_position)
{
position += vec4(vec3(1e-2), 0);
}
if (position == last_position)
{
position += vec4(vec3(1e-2), 0);
}
gl_Position = u_view_projection * position;
color = vec4(1, 0, 0, 1);
color.b = (line.end.face) / 6.f;
EmitVertex();
gl_Position = u_view_projection * position;
color = vec4(1, 0, 0, 1);
color.b = (line.end.face) / 6.f;
EmitVertex();
}
EndPrimitive();
}
EndPrimitive();
}
\ No newline at end of file
......@@ -69,7 +69,10 @@ namespace glare
//Exemplary Line generation
unsigned line_mesh_id = 0;
const auto &mesh_collector = m_collector->meshCollectors().at(line_mesh_id);
std::vector<advanced::lsmath::Line> lines = advanced::lsmath::generateLines(*mesh_collector, 10);
Log_Info << "Size of line: " << sizeof(advanced::lsmath::Line);
std::vector<advanced::lsmath::Line> lines = advanced::lsmath::generateLines(*mesh_collector, 32);
std::vector<std::shared_ptr<core::Shader>> shaders = {
std::make_shared<core::Shader>(gl::ShaderType::eVertex, "/linespace/visualize/lines.vert"),
......@@ -119,20 +122,18 @@ namespace glare
break;
case AppRenderState::eVoxels:
{
//TODO: Render voxels? Which ones? local ones!
m_collector->collect();
lines_program->use();
lines_program->updateStorageBuffer("mesh_buffer", m_collector->meshBuffer());
lines_program->updateStorageBuffer("line_buffer", line_buffer);
/* auto vec = line_buffer.read<advanced::lsmath::Line>(lines.size());
for (auto && bla : vec) {
if (*reinterpret_cast<unsigned*>(&bla.end.face) == 6) {
Log_Error << "BELAJE";
}
}*/
static bool u_full_ls = true;
ImGui::Begin("LineSpace");
ImGui::Checkbox("Show full LS", &u_full_ls);
ImGui::End();
lines_program->updateUniformInt("u_full_ls", int(u_full_ls));
lines_program->updateUniformUInt("u_mesh", line_mesh_id);
lines_program->updateUniformUInt("u_triangle_count", unsigned(mesh_collector->triangles().size()));
......
......@@ -52,14 +52,6 @@ namespace glare
ray.direction = glm::normalize(line.center_end - line.center_begin);
ray.origin = line.center_begin;
glm::vec3 normal(0);
normal[unsigned(line.begin.face) % 3] = 1 - 2 * (line.begin.face >= Face::eNegX);
if (unsigned(line.end.face) == 6) {
Log_Error << "Wat?";
line.center_begin = glm::vec4(getPatchCenter(collector.bounds(), subdivision, line.begin), 1);
}
line.nearest.barycentric = glm::vec3(-1);
line.farthest.barycentric = glm::vec3(-1);
......@@ -69,7 +61,7 @@ namespace glare
}
}
Log_Info << "Linespace generation took " << clock.time() << "ms";
Log_Info << "[Linespace Data] Generation Time: " << clock.time() << "ms";
Log_Info << "[Linespace Data] Lines: " << lines.size();
Log_Info << "[Linespace Data] Memory: " << (lines.size() * sizeof(Line)) << " Bytes";
Log_Info << "[Linespace Data] Patch Subdivisions: " << subdivision.subdivisions.x << ", " << subdivision.subdivisions.y << ", " << subdivision.subdivisions.z;
......
......@@ -28,7 +28,8 @@ namespace glare
Patch(Face face, unsigned id_horizontal, unsigned id_vertical) : face(face), index(id_horizontal, id_vertical) {}
Face face;
unsigned padding;
union {
struct {
unsigned index_horizontal;
......@@ -37,8 +38,6 @@ namespace glare
glm::uvec2 index;
};
unsigned padding;
};
struct Line
......@@ -46,11 +45,11 @@ namespace glare
glm::vec4 center_begin;
glm::vec4 center_end;
Patch begin;
Patch end;
math::Hit nearest;
math::Hit farthest;
Patch begin;
Patch end;
};
unsigned faceAxis(Face face);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment