cleanup
This commit is contained in:
+2
-2
@@ -6,7 +6,7 @@ use crate::{
|
||||
|
||||
#[allow(dead_code)]
|
||||
use nalgebra::{distance, Point3, Vector3};
|
||||
use roots::{find_roots_quadratic, find_roots_quartic, FloatType, Roots};
|
||||
use roots::{find_roots_quadratic, find_roots_quartic, Roots};
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::rc::Rc;
|
||||
@@ -44,7 +44,7 @@ impl Sphere {
|
||||
|
||||
impl Primitive for Sphere {
|
||||
fn intersect_ray(&self, ray: &Ray) -> Option<Intersection> {
|
||||
let pos = &ray.a;
|
||||
let pos = ray.a;
|
||||
let dir = &ray.b;
|
||||
|
||||
let l = pos - self.position;
|
||||
|
||||
+26
-10
@@ -6,8 +6,9 @@ use crate::{gui::Gui, scene::Scene};
|
||||
use crate::{gui::GuiEvent, log_error};
|
||||
use std::path::Path;
|
||||
|
||||
use nalgebra::Vector3;
|
||||
use rand::seq::SliceRandom;
|
||||
use rand::thread_rng;
|
||||
use rand::{random, thread_rng};
|
||||
|
||||
use std::error::Error;
|
||||
|
||||
@@ -20,8 +21,10 @@ use winit::window::{Window, WindowBuilder};
|
||||
|
||||
const START_WIDTH: i32 = 1200;
|
||||
const START_HEIGHT: i32 = 700;
|
||||
const COLOUR_CLEAR: [u8; 4] = [0x22, 0x00, 0x11, 0x00];
|
||||
const PIXEL_CLEAR: [u8; 4] = [0x55, 0x00, 0x22, 0x00];
|
||||
const RAY_SAMPLES: i8 = 5;
|
||||
const RAY_RANDOMNESS: f64 = 100.0;
|
||||
const COLOUR_CLEAR: [u8; 4] = [0x22, 0x00, 0x11, 0x55];
|
||||
const PIXEL_CLEAR: [u8; 4] = [0x55, 0x00, 0x22, 0x55];
|
||||
|
||||
pub const INIT_FILE: &str = "rhai/scene.rhai";
|
||||
pub const SAVE_FILE: &str = "img.png";
|
||||
@@ -153,13 +156,26 @@ impl State {
|
||||
None => break,
|
||||
};
|
||||
//Shade colour for selected ray
|
||||
let rgba = match &self.rays[index].shade_ray(&self.scene, 0) {
|
||||
Some(mut colour) => {
|
||||
colour = colour * 255.0;
|
||||
[colour.x as u8, colour.y as u8, colour.z as u8, 0xff]
|
||||
}
|
||||
None => PIXEL_CLEAR,
|
||||
};
|
||||
let mut colour = Vector3::zeros();
|
||||
for _ in 0..RAY_SAMPLES {
|
||||
let ray = &self.rays[index];
|
||||
let point = ray.a;
|
||||
let dir = ray.b;
|
||||
let rx = (random::<f64>() - 0.5) / RAY_RANDOMNESS;
|
||||
let ry = (random::<f64>() - 0.5) / RAY_RANDOMNESS;
|
||||
let rz = (random::<f64>() - 0.5) / RAY_RANDOMNESS;
|
||||
let nx = dir.x + rx;
|
||||
let ny = dir.y + ry;
|
||||
let nz = dir.z + rz;
|
||||
|
||||
let rand_ray = Ray::new(point, Vector3::new(nx, ny, nz));
|
||||
|
||||
if let Some(ray_colour) = rand_ray.shade_ray(&self.scene, 0) {
|
||||
colour += ray_colour;
|
||||
};
|
||||
}
|
||||
colour = (colour / RAY_SAMPLES as f32) * 255.0;
|
||||
let rgba = [colour.x as u8, colour.y as u8, colour.z as u8, 0xff];
|
||||
frame[index * 4..(index + 1) * 4].copy_from_slice(&rgba);
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user