Skip to content

Commit

Permalink
Remove GLSL calls to mix() using bvec
Browse files Browse the repository at this point in the history
Apparently this isn't supported on older graphics cards.
  • Loading branch information
HactarCE committed Feb 21, 2021
1 parent c975a65 commit cee3e69
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to NDCell will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), except for minor stylistic changes to organize features and accomodate named versions. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) with respect to the Rust API for `ndcell_core`, the NDCA API for `ndcell_lang`, and the combined Lua/NDCA API for `ndcell_ui`, the main application.

## [0.2.1] Blinker (2020-02-21)

### Fixed

- Fix crash on startup with an NVIDIA GPU

## [0.2.0] Blinker (2020-02-21)

![Blinker](https://user-images.githubusercontent.com/6060305/108616710-f3316780-73dd-11eb-858f-1cda97cad993.png)
Expand Down
29 changes: 14 additions & 15 deletions ui/src/gridview/render/shaders/octree.frag
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ float vec3_min(vec3 v) {

// Given the parameters `t0` at which the ray enters a node along each axis and
// `tm` at which the ray crosses the middle of a node along each axis, returns
// the `bvec3` of the first child of that node intersected by the ray.
bvec3 entryChild(vec3 t0, vec3 tm) {
// the `bvec3` of the first child of that node intersected by the ray, convert
// to a `vec3`.
vec3 entryChild(vec3 t0, vec3 tm) {
float max_t0 = vec3_max(t0); // when the ray actually enters the node
return greaterThanEqual(vec3(max_t0), tm);
return vec3(greaterThanEqual(vec3(max_t0), tm));
}

// Given the parameters `t0` at which the ray enters a node along each axis,
Expand Down Expand Up @@ -109,7 +110,7 @@ void main() {
// is, then mirror the ray along that axis so that the delta vector is
// positive and also mirror the quadtree along that axis using
// `invert_mask`, which will flip bits of child indices.
bvec3 invert_mask = lessThan(delta, vec3(0));
vec3 invert_mask = vec3(lessThan(delta, vec3(0)));
start -= octree_base;
start = mix(start, octree_side_len - start, invert_mask);
delta = mix(delta, -delta, invert_mask);
Expand Down Expand Up @@ -140,12 +141,12 @@ void main() {
// that would cause precision problems and stuff, so that should be
// plenty of stack space.
int layer = layer_count; // current layer (used as index into stack)
uint [32] node_idx_stack; // index of current node
bool [32] has_next_child; // whether the ray intersects another child of the current node
bvec3[32] next_child_stack; // index of the child of the current node that the ray intersects next
vec3 [32] t0_stack; // time of entry along axis
vec3 [32] tm_stack; // time of reaching middle along axis
vec3 [32] t1_stack; // time of exit along axis
uint[32] node_idx_stack; // index of current node
bool[32] has_next_child; // whether the ray intersects another child of the current node
vec3[32] next_child_stack; // index of the child of the current node that the ray intersects next
vec3[32] t0_stack; // time of entry along axis
vec3[32] tm_stack; // time of reaching middle along axis
vec3[32] t1_stack; // time of exit along axis

// Set initial stack values.
node_idx_stack[layer] = root_idx;
Expand All @@ -164,7 +165,7 @@ void main() {
} else {
count++;

bvec3 next_child = next_child_stack[layer];
vec3 next_child = next_child_stack[layer];

// Compute the parameter `t` values for the `next_child`.
t0 = mix(t0_stack[layer], tm_stack[layer], next_child);
Expand All @@ -173,15 +174,13 @@ void main() {

// Compute the sibling of `next_child` to visit after this one.
uint exit_axis = exitAxis(t1);
// `== true` is required to work around a bug in AMD drivers.
// Yes this is cursed.
if (next_child[exit_axis] == true) {
if (next_child[exit_axis] == 1.0) {
// `next_child` is the last child of the current node that
// the ray intersects.
has_next_child[layer] = false;
} else {
// Advance along `exit_axis` to get the next child to visit.
next_child_stack[layer][exit_axis] = true;
next_child_stack[layer][exit_axis] = 1.0;
}

if (vec3_min(t1) < 0) {
Expand Down

0 comments on commit cee3e69

Please sign in to comment.