Commit f287ffb7 authored by Johannes Braun's avatar Johannes Braun
Browse files

Just a tiny little bit of cleanup

parent c2cce79b
#include <util/hemisphere1d.h>
#include <cinttypes>
#include <util/log.h>
#include <core/time.h>
int main(int argc, char* argv[])
{
auto vec = glm::normalize(glm::vec3(1.f, 0.7f, 0.f));
auto id = hemisphere::id_from_direction(vec, 2, 1, 0, 2);
using uint = unsigned;
for (uint h = 0; h < 200; ++h)
{
int k = rand()%1902;
Log_Info << "----------------------------------------------";
std::vector<int> t1(1000000);
glare::core::ClockNS clock;
for (uint i = 0; i < 1000000; ++i)
{
if (i % k == 0)
{
t1[i] = i;
}
else
{
t1[i] = -i;
}
}
Log_Info << "Took " << clock.restart() << "ns";
std::vector<int> t2(1000000);
clock.restart();
for (uint i = 0; i < 1000000; ++i)
{
switch (i % k == 0)
{
case true:
{ t2[i] = i; } break;
case false:
{ t2[i] = -i; } break;
}
}
return 0;
Log_Info << "Took " << clock.time() << "ns";
}
system("pause");
}
\ No newline at end of file
......@@ -114,10 +114,10 @@ namespace glare
//quitPromptDefault(0);
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_glass_0r.dae", 1.f);
initializeScene(m_current_scene_root / "benchmark_stfd_bunny_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "glass.dae", 1.f);
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_mirror_0r.dae", 1.f);
initializeScene(m_current_scene_root / "artifact_suzanne_x2_transparent.dae", 1.f);
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_transparent.dae", 1.f);
//initializeScene(m_current_scene_root / "bunny.dae", 1.f);
//initializeScene(m_current_scene_root / "kubas.dae", 1.f);
......
......@@ -65,19 +65,16 @@ namespace glare
for (Face face = Face::ePosX; unsigned(face) <= unsigned(Face::eNegZ); face = Face(unsigned(face) + 1))
{
const unsigned patches = m_subdivision.resolution[face_width_axises[unsigned(face) % 3]] * m_subdivision.resolution[face_height_axises[unsigned(face) % 3]];
Log_Info << "Starting at " << unsigned(face);
const size_t count_and_radial = patches * m_lines_per_patch;
Log_Info << "COUNT patches " << patches;
Log_Info << "COUNT lpp " << m_lines_per_patch;
Log_Info << "COUNT at " << count_and_radial;
Log_Info << "Computing for face " << unsigned(face) << ": " << patches << " patches, " << m_lines_per_patch << " lines per patch and " << count_and_radial << " lines in total.";
#pragma omp parallel for schedule(dynamic)
for (int gid = 0; gid < int(count_and_radial); ++gid)
{
const unsigned width = m_subdivision.resolution[face_width_axises[unsigned(face) % 3]];
const unsigned axis = unsigned(face) % 3;
const unsigned width = m_subdivision.resolution[face_width_axises[axis]];
const unsigned id = unsigned(gid / m_lines_per_patch);
const unsigned radial_id = gid % m_lines_per_patch;
......@@ -85,17 +82,7 @@ namespace glare
patch.index_horizontal = id % width;
patch.index_vertical = id / width;
glm::vec3 direction = hemisphere::direction_from_id(radial_id, radial_subdivisions, unsigned(face) % 3, face_width_axises[unsigned(face) % 3], face_height_axises[unsigned(face) % 3]);
uint32_t index = offset(patch) + radial_id;
// flip generated direction on positive faces as those will point outwards.
bool neg = unsigned(face) > 2;
if (!neg) direction *= -1;
//if (direction[unsigned(face) % 3] < 0) direction *= -1;
//direction *= unsigned(face) > 2 ? -1 : 1; // mirror through normal
glm::vec3 direction = hemisphere::direction_from_id(radial_id, radial_subdivisions, axis, face_width_axises[axis], face_height_axises[axis], unsigned(face) <= 2);
Ray test_ray;
test_ray.origin = patchCenter(patch);
......@@ -106,6 +93,7 @@ namespace glare
nearest.triangle = -1;
line_bvh.nearestIntersection(test_ray, nearest);
uint32_t index = offset(patch) + radial_id;
m_lines[index].triangle = (nearest.barycentric.x != -1) ? int(nearest.triangle) : -1;
}
}
......@@ -136,6 +124,7 @@ namespace glare
const unsigned count_y = m_subdivision.resolution[face_width_axises[1]] * m_subdivision.resolution[face_height_axises[1]];
const unsigned count_z = m_subdivision.resolution[face_width_axises[2]] * m_subdivision.resolution[face_height_axises[2]];
//A switch is actually very performant for this purpose, did't find a faster solution.
switch (patch.face)
{
case Face::ePosX: patch_offset = 0; break;
......
......@@ -11,7 +11,7 @@
namespace hemisphere
{
glm::vec3 direction_from_id(unsigned id, unsigned quarter_subdivision, unsigned axis_up, unsigned axis_horizontal, unsigned axis_vertical)
glm::vec3 direction_from_id(unsigned id, unsigned quarter_subdivision, unsigned axis_up, unsigned axis_horizontal, unsigned axis_vertical, bool upside_down)
{
//start at the second row. The first one will be flat against the patch plane and won't hit anything anyways.
unsigned row = id / (4 * quarter_subdivision) + 1;
......@@ -38,15 +38,16 @@ namespace hemisphere
//this is "vertical"
direction[axis_vertical] = scaled.y;
return direction;
return direction * (upside_down ? -1 : 1);
}
unsigned id_from_direction(glm::vec3 direction, unsigned quarter_subdivision, unsigned axis_up, unsigned axis_horizontal, unsigned axis_vertical)
{
if (direction[axis_up] < 0)
{
direction = -direction;
}
unsigned id_from_direction(glm::vec3 direction, unsigned quarter_subdivision, unsigned axis_up, unsigned axis_horizontal, unsigned axis_vertical, bool upside_down)
{
// flip on positive faces to make it "look" inwards
if (upside_down) direction *= -1;
// flip again if the direction points outwards.
if (direction[axis_up] < 0) direction *= -1;
//save some results
float half_circular_subdivision = 2.f * quarter_subdivision * glm::one_over_pi<float>();
......
......@@ -20,8 +20,9 @@ namespace hemisphere
* @param axis_up The up-axis component
* @param axis_horizontal A perpendicular axis component
* @param axis_vertical The perpendicular axis component to up and horizontal
* @param upside_down If set to true, it will reverse the result direction so it will point along the negative up axis
*/
glm::vec3 direction_from_id(unsigned id, unsigned quarter_subdivision, unsigned axis_up, unsigned axis_horizontal, unsigned axis_vertical);
glm::vec3 direction_from_id(unsigned id, unsigned quarter_subdivision, unsigned axis_up, unsigned axis_horizontal, unsigned axis_vertical, bool upside_down);
/*
* @brief Converts back the direction to a linear id.
......@@ -30,8 +31,9 @@ namespace hemisphere
* @param axis_up The up-axis component
* @param axis_horizontal A perpendicular axis component
* @param axis_vertical The perpendicular axis component to up and horizontal
* @param upside_down If set to true, it will the input result direction so it will point along the negative up axis
*/
unsigned id_from_direction(glm::vec3 direction, unsigned quarter_subdivision, unsigned axis_up, unsigned axis_horizontal, unsigned axis_vertical);
unsigned id_from_direction(glm::vec3 direction, unsigned quarter_subdivision, unsigned axis_up, unsigned axis_horizontal, unsigned axis_vertical, bool upside_down);
}
#endif //INCLUDE_HEMISPHERE1D_H
Markdown is supported
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