Commit 02aa841f authored by unknown's avatar unknown
Browse files

Improved functionality of ALS - still broken'ish

parent 03baa419
<linespace version="1.0">
<item name="subdivisions" value="4"/>
<item name="radial-subdivision" value="12"/>
<item name="subdivisions" value="20"/>
<item name="radial-subdivision" value="40"/>
<item name="generator" value="gpu"/>
</linespace>
......@@ -43,7 +43,7 @@ struct PatchInfo
float t;
};
const uint m_radial_subdivisions = 12; //TODO: put into ssbo
const uint m_radial_subdivisions = 40; //TODO: put into ssbo
uint id_from_direction(vec3 direction, uint quarter_subdivision, uint axis_up, uint axis_horizontal, uint axis_vertical)
{
......@@ -51,7 +51,8 @@ uint id_from_direction(vec3 direction, uint quarter_subdivision, uint axis_up, u
float half_circular_subdivision = 2.f * float(quarter_subdivision) * ONE_OVER_PI;
float up = direction[axis_up];
uint row = uint(round(half_circular_subdivision * asin(up))) - 1;
float row_float = max(abs(round(half_circular_subdivision * asin(up)))-1, 0.f);
uint row = uint(row_float);
if (row >= quarter_subdivision - 1) {
//I'll return here because there might be some issues with normalizing a near-zero planar direction later on.
......@@ -70,29 +71,50 @@ uint id_from_direction(vec3 direction, uint quarter_subdivision, uint axis_up, u
uint lineIndex(const in Ray ray, const in Mesh mesh, float t, int face, bool reverse)
{
const Linespace linespace = mesh.linespace;
const Linespace linespace = mesh.linespace;
vec3 direction = reverse ? -ray.direction : ray.direction;
// In facing normal
vec3 face_normal = vec3(0);
face_normal[face % 3] = face > 2 ? -1 : 1;
//vec3 direction = faceforward(ray.direction, ray.direction, face_normal);
uint dir_id = id_from_direction(direction, m_radial_subdivisions, face % 3, face_width_axis[face % 3], face_width_axis[face % 3]);
vec3 direction = ray.direction;
const uint per_patch = 4 * m_radial_subdivisions * (m_radial_subdivisions-1) + 1;
//direction *= (face > 2) ? -1 : 1;
vec3 horizontal = vec3(0);
horizontal[face_width_axis[face % 3]] = face >= 2 ? -1 : 1;
direction *= (reverse) ? -1 : 1;
vec3 vertical = vec3(0);
vertical[face_width_axis[face % 3]] = face >= 2 ? -1 : 1;
//direction[face % 3] *= (dot(face_normal, direction) < 0) ? -1 : 1;
const uvec2 entry_patch = getPatch(mesh, ray.origin + t * ray.direction - linespace.bounds.min.xyz, face % 3, face);
// float dir1 = dot(direction, vec3(0, 1, 0));
// float dir2 = dot(direction, vec3(1, 0, 0));
// float dir3 = dot(direction, vec3(0, 0, 1));
// direction = -vec3(dir1, dir2, dir3);
// direction = vec3(0, 0, 0);
const uint n = uint(max(int(face)-1, 0));
//direction[face % 3] = 1;
uint patch_offset = uint(n % 3 >= 1) * (linespace.resolution[face_width_axis[0]] + (uint(n % 3 >= 2) * linespace.resolution[face_width_axis[1]])) * linespace.resolution[face_height_axis[0]];
patch_offset += uint((n / 3) * dot(linespace.resolution.zzx, linespace.resolution.yxy));
const uint patch_sub_offset = linespace.resolution[face_width_axis[uint(face) % 3]] * entry_patch.y + entry_patch.x;
direction = normalize(direction);
return patch_offset * per_patch + patch_sub_offset * per_patch + dir_id;
// direction[face_width_axis[face % 3]] *= (face > 2) ? 1 : 1;
// direction[face_height_axis[face % 3]] *= (face > 2) ? 1 : 1;
//direction[face % 3] *= (reverse) ? -1 : 1;
// uint dir_id = id_from_direction(direction, m_radial_subdivisions, 1, 0, 2);
uint dir_id = id_from_direction(direction, m_radial_subdivisions, face % 3, face_width_axis[face % 3], face_height_axis[face % 3]);
const uint per_patch = 4 * m_radial_subdivisions * (m_radial_subdivisions-1) + 1;
const uvec2 entry_patch = getPatch(mesh, ray.origin + t * ray.direction - linespace.bounds.min.xyz, face % 3, face);
const uint n = uint(max(int(face)-1, 0));
uint patch_offset = uint(n % 3 >= 1) * (linespace.resolution[face_width_axis[0]] + (uint(n % 3 >= 2) * linespace.resolution[face_width_axis[1]])) * linespace.resolution[face_height_axis[0]];
patch_offset += uint((n / 3) * dot(linespace.resolution.zzx, linespace.resolution.yxy));
const uint patch_sub_offset = linespace.resolution[face_width_axis[uint(face) % 3]] * entry_patch.y + entry_patch.x;
return patch_offset * per_patch + patch_sub_offset * per_patch + dir_id;
}
bool traverseLineSpace(const in Mesh mesh, const in Ray local_ray, const in bool use_first, const in float max_distance, inout Hit hit, inout float t_min)
......@@ -102,7 +124,7 @@ bool traverseLineSpace(const in Mesh mesh, const in Ray local_ray, const in bool
int face_tmin;
int face_tmax;
float offset = mesh.linespace.patch_size;
float offset = 1e-5;//mesh.linespace.patch_size;
Ray offset_ray = local_ray;
offset_ray.origin += local_ray.direction * offset;
......@@ -132,7 +154,7 @@ bool traverseLineSpace(const in Mesh mesh, const in Ray local_ray, const in bool
return true;
}
}
}
}
line_id = lineIndex(offset_ray, mesh, tmax, face_tmax, true);
near_data = mesh.linespace.lines[line_id];
......
#include <util/hemisphere1d.h>
int main(int argc, char* argv[])
{
unsigned subdiv = 2;
unsigned up = 1;
unsigned h = 0;
unsigned v = 2;
auto dir = hemisphere::direction_from_id(5, subdiv, up, h, v);
auto dir2 = glm::normalize(glm::vec3(0.2f, -0.4f, -0.2f));
auto id1 = hemisphere::id_from_direction(dir2, subdiv, up, h, v);
auto dir3 = glm::normalize(glm::vec3(0.72f, -0.1f, 0.2f));
auto id2 = hemisphere::id_from_direction(dir3, subdiv, up, h, v);
auto dir4 = glm::normalize(glm::vec3(0, 1, 0));
auto id3 = hemisphere::id_from_direction(dir4, subdiv, up, h, v);
auto dir5 = glm::normalize(glm::vec3(0, 0, 1));
auto id4 = hemisphere::id_from_direction(dir5, subdiv, up, h, v);
return 0;
}
\ No newline at end of file
......@@ -118,8 +118,8 @@ namespace glare
//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 / "benchmark_stfd_bunny_diff.dae", 1.f);
initializeScene(m_current_scene_root / "gizmoed.dae", 1.f);
//initializeScene(m_current_scene_root / "bunny.dae", 1.f);
initializeScene(m_current_scene_root / "kjube.dae", 1.f);
initializeRenderRequirements();
initializeAdvanced();
......
......@@ -23,7 +23,7 @@ namespace glare
{
public:
using texture_color_type = TTextureBase<gl::TextureFormat::eRGBA, gl::TextureInternalFormat::eRGBA32Float, gl::Type::eFloat>;
using texture_depth_type = TTextureBase<gl::TextureFormat::eDepthComponent, gl::TextureInternalFormat::eDepthComponent32Float, gl::Type::eFloat>;
using texture_depth_type = TTextureBase<gl::TextureFormat::eDepthStencil, gl::TextureInternalFormat::eDepthStencil, gl::Type::eFloat>;
static constexpr bool is_multisampled = texture_color_type::is_multisampled;
......@@ -156,7 +156,7 @@ namespace glare
gl::namedFramebufferDrawBuffers(m_handle, m_draw_buffers);
}
if (auto status = gl::checkNamedFramebufferStatus(m_handle, gl::FramebufferTarget::eDefault) != gl::FramebufferStatus::eComplete)
if (auto status = gl::checkNamedFramebufferStatus(m_handle, gl::FramebufferTarget::eDraw) != gl::FramebufferStatus::eComplete)
Log_Error << "An error occured when generating the framebuffer: " << int(status);
}
......
......@@ -9,7 +9,7 @@ namespace math
Flags::operator bool() const
{
return bool(m_flags) != 0;
return m_flags != 0;
}
Flags::operator unsigned() const
......
......@@ -94,7 +94,7 @@ namespace glare
bool Skybox::resident() const
{
return gl::isTextureHandleResident(m_resident_address);
return m_resident_address != 0 && gl::isTextureHandleResident(m_resident_address);
}
uint64_t Skybox::makeResident() const
......
......@@ -26,7 +26,7 @@ namespace glare
m_gbuffer_framebuffer->attach(gl::Attachment::eColor4);
m_gbuffer_framebuffer->attach(gl::Attachment::eColor5);
m_gbuffer_framebuffer->attach(gl::Attachment::eColor6);
m_gbuffer_framebuffer->attach(gl::Attachment::eDepth);
m_gbuffer_framebuffer->attach(gl::Attachment::eDepthStencil);
m_lights_buffer = std::make_unique<Buffer<gl::BufferType::eShaderStorage>>();
}
......
......@@ -217,8 +217,8 @@ namespace glare
gl::TextureFilterMag m_filter_mag;
gl::handle::texture m_handle;
mutable uint64_t m_resident_texture_address;
mutable uint64_t m_resident_image_address;
mutable uint64_t m_resident_texture_address = 0;
mutable uint64_t m_resident_image_address = 0;
};
//General n-component textures.
......@@ -473,13 +473,13 @@ namespace glare
template <gl::TextureFormat Format, gl::TextureInternalFormat InternalFormat, gl::Type T>
bool Texture<Format, InternalFormat, T>::textureResident() const
{
return gl::isTextureHandleResident(m_resident_texture_address);
return m_resident_texture_address != 0 && gl::isTextureHandleResident(m_resident_texture_address);
}
template <gl::TextureFormat Format, gl::TextureInternalFormat InternalFormat, gl::Type T>
bool Texture<Format, InternalFormat, T>::imageResident() const
{
return gl::isImageHandleResident(m_resident_image_address);
return m_resident_image_address != 0 && gl::isImageHandleResident(m_resident_image_address);
}
template <gl::TextureFormat Format, gl::TextureInternalFormat InternalFormat, gl::Type T>
......
......@@ -57,8 +57,8 @@ namespace glare
unsigned m_samples;
gl::handle::texture m_handle;
mutable uint64_t m_resident_texture_address;
mutable uint64_t m_resident_image_address;
mutable uint64_t m_resident_texture_address = 0;
mutable uint64_t m_resident_image_address = 0;
};
//General typed textures.
......@@ -146,13 +146,13 @@ namespace glare
template <gl::TextureFormat Format, gl::TextureInternalFormat InternalFormat, gl::Type T>
bool TextureMultisampled<Format, InternalFormat, T>::textureResident() const
{
return gl::isTextureHandleResident(m_resident_texture_address);
return m_resident_texture_address != 0 && gl::isTextureHandleResident(m_resident_texture_address);
}
template <gl::TextureFormat Format, gl::TextureInternalFormat InternalFormat, gl::Type T>
bool TextureMultisampled<Format, InternalFormat, T>::imageResident() const
{
return gl::isImageHandleResident(m_resident_image_address);
return m_resident_image_address != 0 && gl::isImageHandleResident(m_resident_image_address);
}
template <gl::TextureFormat Format, gl::TextureInternalFormat InternalFormat, gl::Type T>
......
......@@ -63,8 +63,8 @@ namespace glare
gl::TextureFilterMag m_filter_mag;
gl::handle::texture m_handle;
mutable uint64_t m_resident_texture_address;
mutable uint64_t m_resident_image_address;
mutable uint64_t m_resident_texture_address = 0;
mutable uint64_t m_resident_image_address = 0;
};
//General n-component textures.
......@@ -193,13 +193,13 @@ namespace glare
template <gl::TextureFormat Format, gl::TextureInternalFormat InternalFormat, gl::Type T>
bool Texture3D<Format, InternalFormat, T>::textureResident() const
{
return gl::isTextureHandleResident(m_resident_texture_address);
return m_resident_texture_address != 0 && gl::isTextureHandleResident(m_resident_texture_address);
}
template <gl::TextureFormat Format, gl::TextureInternalFormat InternalFormat, gl::Type T>
bool Texture3D<Format, InternalFormat, T>::imageResident() const
{
return gl::isImageHandleResident(m_resident_image_address);
return m_resident_image_address != 0 && gl::isImageHandleResident(m_resident_image_address);
}
template <gl::TextureFormat Format, gl::TextureInternalFormat InternalFormat, gl::Type T>
......
......@@ -89,15 +89,28 @@ namespace glare
uint32_t index = offset(patch) + radial_id;
direction *= unsigned(face) > 2 ? -1 : 1;
Ray test_ray;
test_ray.origin = patchCenter(patch);
test_ray.direction = direction;
test_ray.origin -= 1e2 * direction;
Hit nearest;
nearest.triangle = -1;
line_bvh.nearestIntersection(test_ray, nearest);
m_lines[index].triangle = (nearest.barycentric.x != -1) ? int(nearest.triangle) : -1;
//direction *= unsigned(face) > 2 ? 1 : -1;
/* if (radial_id != hemisphere::id_from_direction(direction, radial_subdivisions, unsigned(face) % 3, face_width_axises[unsigned(face) % 3], face_height_axises[unsigned(face) % 3]))
{
Log_Info << "Kjbfaosihndoihj";
}*/
/*if (m_lines[index].triangle == -1)
{
Log_Error << "lajbfhpasiodhpaso";
}*/
}
}
......
......@@ -47,9 +47,10 @@ namespace hemisphere
float half_circular_subdivision = 2.f * quarter_subdivision * glm::one_over_pi<float>();
float up = direction[axis_up];
unsigned row = unsigned(glm::round(half_circular_subdivision * glm::asin(up))) - 1;
float row_float = glm::max(glm::abs(glm::round(half_circular_subdivision * glm::asin(up)))-1, 0.f);
unsigned row = unsigned(row_float);
if (row >= quarter_subdivision - 1) {
if (row >= quarter_subdivision-1) {
//I'll return here because there might be some issues with normalizing a near-zero planar direction later on.
return 4 * quarter_subdivision * (quarter_subdivision - 1);
}
......@@ -61,6 +62,6 @@ namespace hemisphere
//goes from 0->0 to r/2->r/2 and counts down afterwards.
int id_y = int(glm::round(half_circular_subdivision * glm::acos(planar_direction.y)));
return 4 * quarter_subdivision*row + (id_x >= 0 ? id_y : (4 * quarter_subdivision - id_y));
return 4 * quarter_subdivision * row + (id_x >= 0 ? id_y : (4 * quarter_subdivision - id_y));
}
}
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