continue traversing nodes if brick not hit
This commit is contained in:
@@ -41,6 +41,7 @@ impl CameraController {
|
|||||||
let mut movement = CameraMovement::default();
|
let mut movement = CameraMovement::default();
|
||||||
movement.speed = 2.0;
|
movement.speed = 2.0;
|
||||||
let mut rotation = CameraRotation::default();
|
let mut rotation = CameraRotation::default();
|
||||||
|
rotation.yaw = 45.0;
|
||||||
rotation.sensitivity = 0.2;
|
rotation.sensitivity = 0.2;
|
||||||
Self { enabled: false, movement, rotation }
|
Self { enabled: false, movement, rotation }
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -58,7 +58,7 @@ fn main() {
|
|||||||
|
|
||||||
// Display FPS
|
// Display FPS
|
||||||
let elapsed = fps_timer.elapsed().as_secs_f64();
|
let elapsed = fps_timer.elapsed().as_secs_f64();
|
||||||
if elapsed >= 0.5 {
|
if elapsed >= 1.5 {
|
||||||
let fps = (fps_counter as f64) / elapsed;
|
let fps = (fps_counter as f64) / elapsed;
|
||||||
println!("FPS: {}", (fps*100.0_f64).floor()/100.0);
|
println!("FPS: {}", (fps*100.0_f64).floor()/100.0);
|
||||||
fps_timer = std::time::Instant::now();
|
fps_timer = std::time::Instant::now();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use wgpu::util::DeviceExt;
|
|||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
const BRICK_SIZE : usize = 32; // 32x32x32 brick size
|
const BRICK_SIZE : usize = 32; // 32x32x32 brick size
|
||||||
const BRICK_NUM : usize = 2; // x bricks in texture
|
const BRICK_NUM : usize = 10000; // x bricks in texture
|
||||||
|
|
||||||
const BRICK_LEN : usize = BRICK_SIZE*BRICK_SIZE*BRICK_SIZE;
|
const BRICK_LEN : usize = BRICK_SIZE*BRICK_SIZE*BRICK_SIZE;
|
||||||
const DATA_LEN : usize = BRICK_LEN * BRICK_NUM;
|
const DATA_LEN : usize = BRICK_LEN * BRICK_NUM;
|
||||||
@@ -102,7 +102,7 @@ impl BrickBuffer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bricks.set(0, 0, 0, 0, 0);
|
bricks.set(1, 20, 5, 16, 1);
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
Self { bricks, texture, size, bind_layout, bind_group }
|
Self { bricks, texture, size, bind_layout, bind_group }
|
||||||
|
|||||||
@@ -70,7 +70,9 @@ impl NodeBuffer {
|
|||||||
|
|
||||||
// Data
|
// Data
|
||||||
let mut nodes : [u32; NUM_NODES] = [Default::default(); NUM_NODES];
|
let mut nodes : [u32; NUM_NODES] = [Default::default(); NUM_NODES];
|
||||||
nodes[0] = 2;
|
nodes[0] = 1;
|
||||||
|
nodes[1] = 2;
|
||||||
|
nodes[2] = 2;
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
Self { nodes, texture, size, bind_layout, bind_group }
|
Self { nodes, texture, size, bind_layout, bind_group }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use cgmath::{Point3, Vector3, Matrix4, Deg};
|
use cgmath::{Point3, Vector3, Matrix4, Deg, InnerSpace};
|
||||||
|
|
||||||
pub struct Camera {
|
pub struct Camera {
|
||||||
pub position: Point3<f32>,
|
pub position: Point3<f32>,
|
||||||
@@ -14,8 +14,8 @@ impl Camera {
|
|||||||
|
|
||||||
pub fn new(aspect: f32, fov: f32) -> Self {
|
pub fn new(aspect: f32, fov: f32) -> Self {
|
||||||
Self {
|
Self {
|
||||||
position: (0.0, 1.0, 0.0).into(),
|
position: (2.0, 1.0, -1.0).into(),
|
||||||
forward: (0.0, 0.0, 1.0).into(),
|
forward: (-0.66, -0.33, 0.66).into(),
|
||||||
up: Vector3::unit_y(),
|
up: Vector3::unit_y(),
|
||||||
aspect,
|
aspect,
|
||||||
fovy: fov,
|
fovy: fov,
|
||||||
|
|||||||
Binary file not shown.
@@ -24,7 +24,7 @@ vec3 solve(vec3 hitPoint, vec3 view, vec3 normal)
|
|||||||
* dir: Camera view direction (ray direction)
|
* dir: Camera view direction (ray direction)
|
||||||
* addr: Number given by node, afaik brick offset in brick array
|
* addr: Number given by node, afaik brick offset in brick array
|
||||||
*/
|
*/
|
||||||
vec3 castBricks(vec3 origin, vec3 start, vec3 dir, uint addr)
|
vec4 castBricks(vec3 origin, vec3 start, vec3 dir, vec3 incAxis, uint addr)
|
||||||
{
|
{
|
||||||
// Change scale
|
// Change scale
|
||||||
origin = start - origin;
|
origin = start - origin;
|
||||||
@@ -38,7 +38,8 @@ vec3 castBricks(vec3 origin, vec3 start, vec3 dir, uint addr)
|
|||||||
vec3 dist = (pos-origin+0.5 + raySign*0.5) * rayInv;
|
vec3 dist = (pos-origin+0.5 + raySign*0.5) * rayInv;
|
||||||
|
|
||||||
ivec3 offset = ivec3(0, 0, (addr-1)*32);
|
ivec3 offset = ivec3(0, 0, (addr-1)*32);
|
||||||
vec3 incAxis = vec3(0,0,0);
|
|
||||||
|
vec3 tmp = abs(raySign);
|
||||||
for(int i=0;i<110;i++)
|
for(int i=0;i<110;i++)
|
||||||
{
|
{
|
||||||
// Get brick
|
// Get brick
|
||||||
@@ -48,11 +49,11 @@ vec3 castBricks(vec3 origin, vec3 start, vec3 dir, uint addr)
|
|||||||
// Hit point
|
// Hit point
|
||||||
vec3 mini = (pos-origin+0.5 - raySign*0.5) * rayInv;
|
vec3 mini = (pos-origin+0.5 - raySign*0.5) * rayInv;
|
||||||
float len = max(mini.x, max(mini.y, mini.z));
|
float len = max(mini.x, max(mini.y, mini.z));
|
||||||
vec3 hitPoint = (origin + dir * len) + start;
|
vec3 hitPoint = (origin + dir * len) / 32.0;
|
||||||
|
|
||||||
// Normal vector (negate previous increment axis and mult by sign)
|
// Normal vector (negate previous increment axis and mult by sign)
|
||||||
vec3 normal = -incAxis * raySign;
|
vec3 normal = -incAxis * raySign;
|
||||||
return solve(hitPoint, dir, normal);
|
return vec4(solve(hitPoint, dir, normal), 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get new closest axis to increment
|
// Get new closest axis to increment
|
||||||
@@ -60,12 +61,12 @@ vec3 castBricks(vec3 origin, vec3 start, vec3 dir, uint addr)
|
|||||||
dist += incAxis * raySign * rayInv;
|
dist += incAxis * raySign * rayInv;
|
||||||
pos += incAxis * raySign;
|
pos += incAxis * raySign;
|
||||||
|
|
||||||
// Outside bounds
|
// Check for bounds
|
||||||
if(pos.x < 0 || pos.y < 0 || pos.z < 0) { break; }
|
if(pos.x < 0 || pos.y < 0 || pos.z < 0) { break; }
|
||||||
if(pos.x > 32 || pos.y > 32 || pos.z > 32) { break; }
|
if(pos.x > 32 || pos.y > 32 || pos.z > 32) { break; }
|
||||||
}
|
}
|
||||||
|
|
||||||
return vec3(0.5,0.5,0.5);
|
return vec4(0.5,0.5,0.5, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -102,7 +103,8 @@ vec3 castNodes(vec3 origin, vec3 dir)
|
|||||||
//return solve(hitPoint, dir, normal);
|
//return solve(hitPoint, dir, normal);
|
||||||
|
|
||||||
// Cast brick
|
// Cast brick
|
||||||
return castBricks(pos, hitPoint, dir, node); //todo: continue if not hit
|
vec4 result = castBricks(pos, hitPoint, dir, incAxis, node);
|
||||||
|
if(result.a > 0.0) return result.rgb; //todo: continue if not hit
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get new closest axis to increment
|
// Get new closest axis to increment
|
||||||
@@ -111,7 +113,7 @@ vec3 castNodes(vec3 origin, vec3 dir)
|
|||||||
pos += incAxis * raySign;
|
pos += incAxis * raySign;
|
||||||
|
|
||||||
// Outside bounds
|
// Outside bounds
|
||||||
// if(pos.x < 0 || pos.y < 0 || pos.z < 0) { break; }
|
//if(pos.x < 0 || pos.y < 0 || pos.z < 0) { break; }
|
||||||
// if(pos.x > 1 || pos.y > 1 || pos.z > 1) { break; }
|
// if(pos.x > 1 || pos.y > 1 || pos.z > 1) { break; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user