Commit 023daad4 authored by unknown's avatar unknown
Browse files

Added a kind of distance check for OLS

parent 05f0ca0d
......@@ -138,7 +138,7 @@ struct Mesh
LineSpace linespace;
uint offsets[15];
uint poff;
uint line_count;
mat4 transformation;
mat4 inverse_transformation;
......
......@@ -33,7 +33,7 @@ struct PatchInfo
float t;
};
float getDistance(const in Ray ray, const in Hit hit, int dir_sign)
float getDistance(const in Ray ray, const in Hit hit, inout float dir_sign)
{
Mesh mesh = b_meshes[hit.mesh];
Triangle triangle = mesh.triangles[hit.triangle];
......@@ -44,7 +44,7 @@ float getDistance(const in Ray ray, const in Hit hit, int dir_sign)
vec3 vector = hit__getFromBarycentric(hit.barycentric, triangle, position).xyz - ray.origin;
dir_sign = int(sign(dot(vector, ray.direction)));
dir_sign = dot(vector, ray.direction);
return length(vector);
}
......@@ -98,7 +98,7 @@ bool getLineIndex(const in Ray ray, const in Mesh mesh, inout uint line_id, inou
uint start = (entry_info.patch_index.y + entry_info.patch_index.x * start_height) * end_width * end_height;
uint end = (exit_info.patch_index.y + exit_info.patch_index.x * end_height);
line_id = offset + start + end;
line_id = clamp(offset + start + end, 0, mesh.line_count);
return true;
}
......@@ -112,40 +112,53 @@ bool linespace__traverse(const in uint mesh_id, const in Ray ray, inout Hit hit)
ray_in.origin = (mesh.inverse_transformation * vec4(ray_in.origin.xyz, 1)).xyz;
Ray real = ray_in;
real.origin = real.origin - 1000*real.direction;
uint line_id;
bool direction_swapped;
if (!getLineIndex(ray_in, mesh, line_id, direction_swapped))
{
return false;
}
else
if (getLineIndex(real, mesh, line_id, direction_swapped))
{
// TODO: Add a distance check.
Line line = mesh.lines[line_id];
Hit first = direction_swapped ? line.farthest : line.nearest;
Hit second = direction_swapped ? line.nearest : line.farthest;
// Hit first = direction_swapped ? line.farthest : line.nearest;
// Hit second = direction_swapped ? line.nearest : line.farthest;
bool use_second = false;
// bool use_second = false;
int dir_sign;
float nearest_distance = getDistance(ray, first, dir_sign);
// float dir_sign;
// float nearest_distance = getDistance(ray_in, first, dir_sign);
if(dir_sign == -1){
float farthest_distance = getDistance(ray, second, dir_sign);
// if(dir_sign < 0){
// float farthest_distance = getDistance(ray_in, second, dir_sign);
use_second = true;
if(dir_sign == -1)
{
return false;
}
// use_second = true;
// if(dir_sign < 0)
// {
// return false; // }
// }
hit = direction_swapped ? line.farthest : line.nearest;
float dir_sign;
float nearest_distance = getDistance(ray_in, hit, dir_sign);
if(dir_sign > 0 && nearest_distance > 1){
hit.mesh = mesh_id;
//Found an intersected shaft. But we don't yet know whether it contains geometry, so look it up as a last step.
return hit.barycentric.x != -1;
}
hit = use_second ? second : first;
hit.mesh = mesh_id;
//Found an intersected shaft. But we don't yet know whether it contains geometry, so look it up as a last step.
return hit.barycentric.x != -1;
hit = direction_swapped ? line.nearest : line.farthest;
float farthest_distance = getDistance(ray_in, hit, dir_sign);
if(dir_sign > 0 && farthest_distance > 1) {
hit.mesh = mesh_id;
//Found an intersected shaft. But we don't yet know whether it contains geometry, so look it up as a last step.
return hit.barycentric.x != -1;
}
}
return false;
}
Bounds getNodeBounds(int index, const in Mesh mesh)
......@@ -301,7 +314,7 @@ bool bvh__intersectsAny(const in Ray ray, const in float max_distance)
Hit unused_hit;
#ifdef USE_LS
return false;
//return false;
return linespace__traverse(0, ray, unused_hit);
#endif
......
......@@ -148,7 +148,7 @@ namespace glare
#define DEBUG__ADD_ROTATOR
#ifdef DEBUG__ADD_ROTATOR
if (auto &&node = m_scene_root->findFirstWithName("#bun_zipper_res2-mesh")) {
if (auto &&node = m_scene_root->findFirstWithName("#Suzanne-mesh")) {
node->addComponent(std::make_shared<component::Rotator>());
}
#endif
......
......@@ -84,7 +84,7 @@ namespace glare
LineSpaceData linespace;
glm::uint offsets[15];
glm::uint poff;
glm::uint line_count;
glm::mat4 transformation;
glm::mat4 inverse_transformation;
......
......@@ -105,6 +105,7 @@ namespace glare
mesh.offsets[i] = glm::uint(m_linespace->offsets()[i]);
}
mesh.line_count = glm::uint(m_linespace->lines().size());
mesh.material = glm::uint(material_index);
return mesh;
}
......
......@@ -330,19 +330,20 @@ namespace glare
void Texture<Format, InternalFormat, T>::bindToShader(std::shared_ptr<ShaderProgram> shader, std::string uniform_name) const
{
gl::bindTexture(gl::TextureTarget::e2D, m_handle);
gl::makeTextureHandleResident(m_texture_id_bindless);
if (!gl::isTextureHandleResident(m_texture_id_bindless))
gl::makeTextureHandleResident(m_texture_id_bindless);
shader->updateUniformPointer(uniform_name, m_texture_id_bindless);
gl::makeTextureHandleNonResident(m_texture_id_bindless);
//gl::makeTextureHandleNonResident(m_texture_id_bindless);
}
template<gl::TextureFormat Format, gl::TextureInternalFormat InternalFormat, gl::Type T>
void Texture<Format, InternalFormat, T>::bindToShader(const ShaderProgram &shader, std::string uniform_name) const
{
gl::bindTexture(gl::TextureTarget::e2D, m_handle);
gl::makeTextureHandleResident(m_texture_id_bindless);
if(!gl::isTextureHandleResident(m_texture_id_bindless))
gl::makeTextureHandleResident(m_texture_id_bindless);
shader.updateUniformPointer(uniform_name, m_texture_id_bindless);
gl::makeTextureHandleNonResident(m_texture_id_bindless);
//gl::makeTextureHandleNonResident(m_texture_id_bindless);
}
......
......@@ -20,7 +20,7 @@ namespace glare
unsigned goodSubdivision(size_t polygon_count, glm::vec3 bounds_size)
{
return 2*unsigned(glm::ceil(glm::log2(glm::max(size_t(2), polygon_count)) * glm::log(log2((glm::compMax(bounds_size) / glm::compMin(bounds_size)) + 2 * glm::e<float>()))));
return unsigned(5*glm::ceil(glm::log2(glm::max(size_t(2), polygon_count)) * glm::log(log2((glm::compMax(bounds_size) / glm::compMin(bounds_size)) + 2 * glm::e<float>()))));
}
}
......
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