Commit 8038a3bd authored by 's avatar
Browse files

Added minor functionality for LS

parent 0bdf6069
#version 430
in vec2 pass_texcoord;
uniform sampler2D u_grid_texture;
layout(location = 0) out vec4 out_final_color;
void main()
{
out_final_color = vec4(1, 1, 1, texture(u_grid_texture, pass_texcoord).a);
/*if (out_final_color.a < 0.9f)
discard;*/
}
\ No newline at end of file
#version 430
layout(location = 0) in vec4 in_position;
layout(location = 2) in vec2 in_texcoord;
uniform mat4 u_model_view_projection;
out vec2 pass_texcoord;
void main()
{
gl_Position = u_model_view_projection * in_position;
pass_texcoord = in_texcoord;
}
\ No newline at end of file
......@@ -2,10 +2,8 @@
#define __GLARE_INCLUDE_ADVANCED
#include <advanced/IntersectionTests.h>
#include <advanced/KdTree.h>
#include <advanced/linespace/LineSpaceMath.h>
#include <advanced/linespace/LineSpaceMaskGenerator.h>
#include <advanced/tracer/RayGenerator.h>
#include <advanced/tracer/Raytracer.h>
......
......@@ -2,6 +2,7 @@
#include <engine/graphics/ImageTexture2DMultisample.h>
#include <components/Rotator.h>
#include <advanced/linespace/LineSpaceMath.h>
namespace glare
{
......@@ -46,13 +47,37 @@ namespace glare
//Create a skybox from cube map.
m_skybox = std::make_shared<core::Skybox>(core::Skybox::collectFilesFrom(core::asset("/textures/ryfjallet/")));
initializeScene(core::asset("/meshes/s.dae"), 1.f);
initializeScene(core::asset("/meshes/scenery/Spheres.dae"), 1.f);
initializeRenderRequirements();
initializeAdvanced();
initializeGUI();
gl::setEnabled(gl::EnableParameter::eMultisample, true);
////////////////////////////////////////////////////////////////////////////////
/////
///// LS STUFF
/////
{
m_collector->collect();
const auto &mesh_collector = m_collector->meshCollectors().begin()->second;
math::UniformBoundsSubdivision subdivision(mesh_collector.bounds(), 20);
size_t lines = advanced::lsmath::calculateLineCount(subdivision);
Log_Info << subdivision.subdivisions.x << "; " << subdivision.subdivisions.y << "; " << subdivision.subdivisions.z;
quitPromptDefault(0);
}
/////
////////////////////////////////////////////////////////////////////////////////
glare::core::EngineState::opengl_core->loop([&](double delta)
{
//General state updates (camera and so on)
......
......@@ -3,7 +3,34 @@ namespace glare
{
namespace advanced
{
size_t LineSpaceMath::calculateLineCount(math::UniformBoundsSubdivision subdivision)
unsigned lsmath::faceAxis(Face face)
{
return unsigned(face) / 2;
}
size_t lsmath::patchIndex(const math::UniformBoundsSubdivision &subdivision, const Patch &patch)
{
float offset_x = subdivision.subdivisions.y * subdivision.subdivisions.z;
float offset_y = subdivision.subdivisions.x * subdivision.subdivisions.z;
float offset_z = subdivision.subdivisions.x * subdivision.subdivisions.y;
glm::uvec3 face_widths = { subdivision.subdivisions.z, subdivision.subdivisions.x, subdivision.subdivisions.x };
int face_width = face_widths[faceAxis(patch.face)];
size_t patch_index_on_face = (patch.index_vertical * face_width + patch.index_horizontal) * targetPatchCount(subdivision, patch.face);
}
size_t lsmath::targetPatchCount(const math::UniformBoundsSubdivision &subdivision, Face face)
{
return subdivision.subdivisions[((unsigned(face) + 1) % 3)] * subdivision.subdivisions[((unsigned(face) + 2) % 3)] + //Opposite Face
2 * subdivision.subdivisions[((unsigned(face) + 2) % 3)] * subdivision.subdivisions[((unsigned(face) + 3) % 3)] + //perpendicular Face
2 * subdivision.subdivisions[((unsigned(face) + 3) % 3)] * subdivision.subdivisions[((unsigned(face) + 4) % 3)]; //Remaining Face
}
size_t lsmath::calculateLineCount(const math::UniformBoundsSubdivision &subdivision)
{
return ((subdivision.subdivisions.x * subdivision.subdivisions.y * 2 * (subdivision.subdivisions.x*subdivision.subdivisions.z + subdivision.subdivisions.y*subdivision.subdivisions.z))
+ subdivision.subdivisions.x * subdivision.subdivisions.y * subdivision.subdivisions.x * subdivision.subdivisions.y
......
......@@ -7,9 +7,43 @@ namespace glare
{
namespace advanced
{
namespace LineSpaceMath
namespace lsmath
{
size_t calculateLineCount(math::UniformBoundsSubdivision subdivision);
enum class Face : uint32_t
{
ePosX = 0,
eNegX = 1,
ePosY = 2,
eNegY = 3,
ePosZ = 4,
eNegZ = 5
};
struct Patch
{
Patch() : face(Face::ePosX), index(0) {}
Patch(Face face) : face(face), index(0) {}
Patch(Face face, glm::uvec2 index) : face(face), index(index) {}
Patch(Face face, unsigned id_horizontal, unsigned id_vertical) : face(face), index(id_horizontal, id_vertical) {}
Face face;
union {
struct {
unsigned index_horizontal;
unsigned index_vertical;
};
glm::uvec2 index;
};
};
unsigned faceAxis(Face face);
size_t patchIndex(const math::UniformBoundsSubdivision &subdivision, const Patch &patch);
size_t targetPatchCount(const math::UniformBoundsSubdivision &subdivision, Face face);
size_t calculateLineCount(const math::UniformBoundsSubdivision &subdivision);
}
}
}
......
......@@ -31,6 +31,8 @@ namespace glare
Triangle triangle;
for (int index = 0; index < 3; index++) {
triangle.indices[index] = mesh.getMesh()->getIndices()[i + index];
m_bounds.expand(mesh.getMesh()->getVertices()[mesh.getMesh()->getIndices()[i + index]].position);
}
triangle.material_id = 0;
......
......@@ -241,9 +241,9 @@ namespace glare
UniformBoundsSubdivision::UniformBoundsSubdivision(Bounds bounds, int max_subdivisions)
{
int largest_axis = bounds.largest();
glm::vec3 size = bounds.size().xyz + glm::vec3(1e-5f);
float largest_axis_value = glm::compMax(size);
child_size = largest_axis_value / float(max_subdivisions);
glm::vec3 bounds_size = glm::max(glm::vec3(bounds.size().xyz), glm::vec3(1e-5f));
float largest_axis_value = glm::compMax(bounds_size);
this->size = largest_axis_value / float(max_subdivisions);
subdivisions = glm::ivec3(0);
subdivisions[largest_axis] = max_subdivisions;
......@@ -251,11 +251,11 @@ namespace glare
for (unsigned char offset = 1; offset < 3; ++offset)
{
unsigned char side = (largest_axis + offset) % 3;
float side_size = size[side];
float side_size = bounds_size[side];
while (side_size > 0)
{
side_size -= child_size;
side_size -= this->size;
++subdivisions[side];
}
}
......
......@@ -242,14 +242,14 @@ namespace glare
struct UniformBoundsSubdivision
{
UniformBoundsSubdivision(): child_size(0)
UniformBoundsSubdivision(): size(0)
{ }
UniformBoundsSubdivision(Bounds bounds, int max_subdivisions);
size_t childCount() const;
glm::ivec3 subdivisions;
float child_size;
float size;
};
template<typename T>
......
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