spheres: cache inverse transform to accelerate normal_at.
This commit is contained in:
@@ -20,8 +20,9 @@ fn main() -> Result<()> {
|
||||
let half = wall_size / 2.;
|
||||
let color = Color::new(1., 0., 0.);
|
||||
let mut shape = Sphere::default();
|
||||
shape.transform =
|
||||
Matrix4x4::shearing(1., 0., 0., 0., 0., 0.) * Matrix4x4::scaling(0.5, 1., 1.0);
|
||||
shape.set_transform(
|
||||
Matrix4x4::shearing(1., 0., 0., 0., 0., 0.) * Matrix4x4::scaling(0.5, 1., 1.0),
|
||||
);
|
||||
|
||||
for y in 0..h {
|
||||
let world_y = half - pixel_size * y as f32;
|
||||
|
||||
@@ -16,8 +16,8 @@ use rtchallenge::{
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let start = Instant::now();
|
||||
let width = 640;
|
||||
let height = 480;
|
||||
let width = 1024;
|
||||
let height = 1024;
|
||||
let light_position = Tuple::point(-10., 10., -10.);
|
||||
let light_color = WHITE;
|
||||
let light = PointLight::new(light_position, light_color);
|
||||
@@ -28,7 +28,7 @@ fn main() -> Result<()> {
|
||||
camera.transform = view_transform(from, to, up);
|
||||
|
||||
let mut floor = Sphere::default();
|
||||
floor.transform = Matrix4x4::scaling(10., 0.01, 10.);
|
||||
floor.set_transform(Matrix4x4::scaling(10., 0.01, 10.));
|
||||
floor.material = Material {
|
||||
color: Color::new(1., 0.9, 0.9),
|
||||
specular: 0.,
|
||||
@@ -36,21 +36,25 @@ fn main() -> Result<()> {
|
||||
};
|
||||
|
||||
let mut left_wall = Sphere::default();
|
||||
left_wall.transform = Matrix4x4::translation(0., 0., 5.)
|
||||
* Matrix4x4::rotation_y(-PI / 4.)
|
||||
* Matrix4x4::rotation_x(PI / 2.)
|
||||
* Matrix4x4::scaling(10., 0.01, 10.);
|
||||
left_wall.set_transform(
|
||||
Matrix4x4::translation(0., 0., 5.)
|
||||
* Matrix4x4::rotation_y(-PI / 4.)
|
||||
* Matrix4x4::rotation_x(PI / 2.)
|
||||
* Matrix4x4::scaling(10., 0.01, 10.),
|
||||
);
|
||||
left_wall.material = floor.material.clone();
|
||||
|
||||
let mut right_wall = Sphere::default();
|
||||
right_wall.transform = Matrix4x4::translation(0., 0., 5.)
|
||||
* Matrix4x4::rotation_y(PI / 4.)
|
||||
* Matrix4x4::rotation_x(PI / 2.)
|
||||
* Matrix4x4::scaling(10., 0.01, 10.);
|
||||
right_wall.set_transform(
|
||||
Matrix4x4::translation(0., 0., 5.)
|
||||
* Matrix4x4::rotation_y(PI / 4.)
|
||||
* Matrix4x4::rotation_x(PI / 2.)
|
||||
* Matrix4x4::scaling(10., 0.01, 10.),
|
||||
);
|
||||
right_wall.material = floor.material.clone();
|
||||
|
||||
let mut middle = Sphere::default();
|
||||
middle.transform = Matrix4x4::translation(-0.5, 1., 0.5);
|
||||
middle.set_transform(Matrix4x4::translation(-0.5, 1., 0.5));
|
||||
middle.material = Material {
|
||||
color: Color::new(0.1, 1., 0.5),
|
||||
diffuse: 0.7,
|
||||
@@ -59,7 +63,7 @@ fn main() -> Result<()> {
|
||||
};
|
||||
|
||||
let mut right = Sphere::default();
|
||||
right.transform = Matrix4x4::translation(1.5, 0.5, -0.5) * Matrix4x4::scaling(0.5, 0.5, 0.5);
|
||||
right.set_transform(Matrix4x4::translation(1.5, 0.5, -0.5) * Matrix4x4::scaling(0.5, 0.5, 0.5));
|
||||
right.material = Material {
|
||||
color: Color::new(0.5, 1., 0.1),
|
||||
diffuse: 0.7,
|
||||
@@ -68,8 +72,9 @@ fn main() -> Result<()> {
|
||||
};
|
||||
|
||||
let mut left = Sphere::default();
|
||||
left.transform =
|
||||
Matrix4x4::translation(-1.5, 0.33, -0.75) * Matrix4x4::scaling(0.33, 0.33, 0.33);
|
||||
left.set_transform(
|
||||
Matrix4x4::translation(-1.5, 0.33, -0.75) * Matrix4x4::scaling(0.33, 0.33, 0.33),
|
||||
);
|
||||
left.material = Material {
|
||||
color: Color::new(1., 0.8, 0.1),
|
||||
diffuse: 0.7,
|
||||
|
||||
Reference in New Issue
Block a user