Commit c2cce79b authored by unknown's avatar unknown
Browse files

The angular LS is finally working nicely enough

parent 784ef175
<linespace version="1.0">
<item name="subdivisions" value="4"/>
<item name="radial-subdivision" value="4"/>
<item name="subdivisions" value="100"/>
<item name="radial-subdivision" value="20"/>
<item name="generator" value="gpu"/>
</linespace>
......@@ -43,18 +43,20 @@ struct PatchInfo
float t;
};
uint id_from_direction(vec3 direction, uint quarter_subdivision, uint axis_up, uint axis_horizontal, uint axis_vertical)
uint id_from_direction(vec3 direction, uint quarter_subdivision, uint face, uint axis_up, uint axis_horizontal, uint axis_vertical)
{
if(direction[axis_up] < 0)
{
direction = -direction;
}
// flip on positive faces to make it "look" inwards
bool neg = face > 2;
if (!neg) direction *= -1;
// Some issue with +x axis.
if ((neg && direction[face % 3] < 0) || (!neg && direction[face % 3] < 0)) direction *= -1;
//save some results
float half_circular_subdivision = 2.f * float(quarter_subdivision) * ONE_OVER_PI;
float up = direction[axis_up];
float row_float = max(abs(floor(half_circular_subdivision * asin(up)))-1, 0.f);
float row_float = max(abs(round(half_circular_subdivision * asin(up)))-1, 0.f);
uint row = uint(row_float);
if (row >= quarter_subdivision - 1) {
......@@ -77,14 +79,27 @@ uint lineIndex(const in Ray ray, const in Mesh mesh, float t, int face, bool rev
const Linespace linespace = mesh.linespace;
const uint radial_subdivisions = linespace.offsets[0];
uint dir_id = id_from_direction(normalize(ray.direction), radial_subdivisions, face % 3, face_width_axis[face % 3], face_height_axis[face % 3]);
uint dir_id = id_from_direction(normalize(ray.direction), radial_subdivisions, face, face % 3, face_width_axis[face % 3], face_height_axis[face % 3]);
const uint per_patch = 4 * radial_subdivisions * (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));
uint patch_offset;
uint count_x = linespace.resolution[face_width_axis[0]] * linespace.resolution[face_height_axis[0]];
uint count_y = linespace.resolution[face_width_axis[1]] * linespace.resolution[face_height_axis[1]];
uint count_z = linespace.resolution[face_width_axis[2]] * linespace.resolution[face_height_axis[2]];
switch (face)
{
case 0: patch_offset = 0; break;
case 1: patch_offset = count_x; break;
case 2: patch_offset = count_x + count_y; break;
case 3: patch_offset = count_x + count_y + count_z; break;
case 4: patch_offset = 2 * count_x + count_y + count_z; break;
case 5: patch_offset = 2 * count_x + 2 * count_y + count_z; break;
}
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;
......@@ -97,7 +112,7 @@ bool traverseLineSpace(const in Mesh mesh, const in Ray local_ray, const in bool
int face_tmin;
int face_tmax;
float offset = 1e-5;//mesh.linespace.patch_size;
float offset = mesh.linespace.patch_size;
Ray offset_ray = local_ray;
offset_ray.origin += local_ray.direction * offset;
......
......@@ -117,9 +117,9 @@ namespace glare
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_glass_0r.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 / "kjube.dae", 1.f);
//initializeScene(m_current_scene_root / "kubas.dae", 1.f);
initializeRenderRequirements();
initializeAdvanced();
......
......@@ -89,7 +89,13 @@ namespace glare
uint32_t index = offset(patch) + radial_id;
direction *= unsigned(face) > 2 ? 1 : -1;
// 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
Ray test_ray;
test_ray.origin = patchCenter(patch);
......@@ -118,14 +124,27 @@ namespace glare
uint32_t AngularLinespace::offset(const SurfacePatch &patch)
{
const unsigned n = unsigned(glm::max(0, int(patch.face)-1));
//const unsigned n = unsigned(glm::max(0, int(patch.face)-1));
// patch offset at face 0 is 0
// patch offset at face 1 is x * y
// patch offset at face 2 is (x+z)*y
// patch offsets larger than that have x*y + y*z + x*z added
unsigned patch_offset = unsigned(n % 3 >= 1) * (m_subdivision.resolution[face_width_axises[0]] + (unsigned(n % 3 >= 2) * m_subdivision.resolution[face_width_axises[1]])) * m_subdivision.resolution[face_height_axises[0]];
patch_offset += unsigned((n / 3) * glm::dot(glm::vec3(glm::vec3(m_subdivision.resolution).zzx), glm::vec3(glm::vec3(m_subdivision.resolution).yxy)));
unsigned patch_offset;
const unsigned count_x = m_subdivision.resolution[face_width_axises[0]] * m_subdivision.resolution[face_height_axises[0]];
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]];
switch (patch.face)
{
case Face::ePosX: patch_offset = 0; break;
case Face::ePosY: patch_offset = count_x; break;
case Face::ePosZ: patch_offset = count_x + count_y; break;
case Face::eNegX: patch_offset = count_x + count_y + count_z; break;
case Face::eNegY: patch_offset = 2 * count_x + count_y + count_z; break;
case Face::eNegZ: patch_offset = 2 * count_x + 2 * count_y + count_z; break;
}
const unsigned patch_sub_offset = m_subdivision.resolution[face_width_axises[unsigned(patch.face) % 3]] * patch.index_vertical + patch.index_horizontal;
......
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