HEHEHEHEHEHEHEHEHA
This commit is contained in:
@ -102,16 +102,14 @@ fn traverse2(max_depth: u32, root_color: vec4<f32>, root_subdivided: bool, eye_p
|
||||
{
|
||||
if max_depth == 0 || !root_subdivided
|
||||
{
|
||||
return inferno_quintic(0.);
|
||||
return root_color;
|
||||
return inferno_quintic(0.);
|
||||
}
|
||||
|
||||
var node_structs = structure_tiles[0];
|
||||
var node_colors = color_tiles[0];
|
||||
// var node_structs = structure_tiles[0];
|
||||
// var node_colors = color_tiles[0];
|
||||
var node_tile_idx = u32(0);
|
||||
//var stack = array<u32, 4>(0, 0, 0, 0);
|
||||
var stack_struct = array<StructureTile, 4>(node_structs, node_structs, node_structs, node_structs);
|
||||
var stack_colors = array<ColorTile, 4>(node_colors, node_colors, node_colors, node_colors);
|
||||
var stack = array<u32, 4>(0, 0, 0, 0);
|
||||
|
||||
var voxel_scale = N * N * N;
|
||||
var scale_exp = 3;
|
||||
@ -129,34 +127,29 @@ fn traverse2(max_depth: u32, root_color: vec4<f32>, root_subdivided: bool, eye_p
|
||||
let wall_offset = select(vec3(0.), vec3(1.), ray_dir > vec3(0.));
|
||||
var voxel_pos = clamp(vec3<u32>(floor(pos)), vec3(0), vec3(N * N * N * N - 1));
|
||||
let max = 20.;
|
||||
for(var iter = 0; iter < 60; iter++)
|
||||
for(var iter = 0; iter < 256; iter++)
|
||||
{
|
||||
var voxel_pos = vec3<u32>(floor(pos));
|
||||
var child_pos = voxel_pos >> vec3<u32>(scale_exp * 2);
|
||||
var local_child_pos = child_pos & vec3<u32>(3);
|
||||
var child_idx = local_child_pos.x + local_child_pos.y * N + local_child_pos.z * N * N;
|
||||
|
||||
while (node_structs.children[child_idx] >> 31) != 0 && (u32(4 - scale_exp) < max_depth)
|
||||
while (structure_tiles[node_tile_idx].children[child_idx] >> 31) != 0 && (u32(4 - scale_exp) < max_depth)
|
||||
{
|
||||
//stack[scale_exp] = u32(node_tile_idx);
|
||||
stack_struct[scale_exp] = node_structs;
|
||||
stack_colors[scale_exp] = node_colors;
|
||||
stack[scale_exp] = u32(node_tile_idx);
|
||||
scale_exp -= 1;
|
||||
voxel_scale = voxel_scale_lut[scale_exp];
|
||||
|
||||
node_tile_idx = node_structs.children[child_idx] & 0x3fffffff;
|
||||
node_structs = structure_tiles[node_tile_idx];
|
||||
node_colors = color_tiles[node_tile_idx];
|
||||
node_tile_idx = structure_tiles[node_tile_idx].children[child_idx] & 0x3fffffff;
|
||||
|
||||
child_pos = voxel_pos >> vec3<u32>(scale_exp * 2);
|
||||
local_child_pos = child_pos & vec3<u32>(3);
|
||||
child_idx = local_child_pos.x + local_child_pos.y * N + local_child_pos.z * N * N;
|
||||
}
|
||||
|
||||
if node_colors.colors[child_idx].w != 0
|
||||
if color_tiles[node_tile_idx].colors[child_idx].w != 0
|
||||
{
|
||||
return color_tiles[node_tile_idx].colors[child_idx] * sample_mat(vec3<i32>(voxel_pos));
|
||||
return inferno_quintic(f32(iter) / max);
|
||||
return node_colors.colors[child_idx];
|
||||
}
|
||||
|
||||
// Compute intersection
|
||||
@ -167,24 +160,23 @@ fn traverse2(max_depth: u32, root_color: vec4<f32>, root_subdivided: bool, eye_p
|
||||
|
||||
let t_far = min(t1.x, min(t1.y, t1.z)) + 0.001;
|
||||
pos = origin + t_far * ray_dir;
|
||||
voxel_pos = vec3<u32>(floor(pos));
|
||||
|
||||
let diff = vec3<u32>(pos + 256) ^ vec3<u32>(global_voxel + 256);
|
||||
let diff_exp = (firstLeadingBit((diff.x | diff.y | diff.z)) >> 1);
|
||||
|
||||
if diff_exp > 3
|
||||
{
|
||||
return inferno_quintic(f32(iter) / max);
|
||||
discard;
|
||||
}
|
||||
|
||||
if diff_exp > u32(scale_exp)
|
||||
{
|
||||
scale_exp = i32(diff_exp);
|
||||
if diff_exp > 3
|
||||
{
|
||||
discard;
|
||||
return inferno_quintic(f32(iter) / max);
|
||||
}
|
||||
|
||||
scale_exp = i32(diff_exp);
|
||||
voxel_scale = voxel_scale_lut[scale_exp];
|
||||
//node_tile_idx = stack[scale_exp];
|
||||
node_structs = stack_struct[scale_exp];
|
||||
node_colors = stack_colors[scale_exp];
|
||||
node_tile_idx = stack[scale_exp];
|
||||
}
|
||||
}
|
||||
|
||||
@ -364,15 +356,9 @@ fn fragment_tree_main(in: VertexOutput) -> @location(0) vec4<f32>
|
||||
var hit_pos = vec3(0.);
|
||||
let dir = normalize(in.world_pos.xyz - in.eye_pos);
|
||||
let chunk_size = 4 * 4 * 4 * 4;
|
||||
if all(in.eye_pos > in.cube_pos) && all(in.eye_pos < (in.cube_pos + vec3(1.)))
|
||||
{
|
||||
hit_pos = in.eye_pos - in.cube_pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
let aabb = intersectAABB(in.eye_pos, dir, in.cube_pos, in.cube_pos + vec3(1.));
|
||||
hit_pos = in.eye_pos + aabb.x * dir - in.cube_pos;
|
||||
}
|
||||
|
||||
let aabb = intersectAABB(in.eye_pos, dir, in.cube_pos, in.cube_pos + vec3(1.));
|
||||
hit_pos = in.eye_pos + max(aabb.x, 0.) * dir - in.cube_pos;
|
||||
|
||||
let cube_color = vec3(1.);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user