new scene from inside a spherical mirror

main
Codinget 4 years ago
parent fcde73c1ef
commit 3cb4dcb330
  1. 1
      README.md
  2. BIN
      prod/insidemirror.png
  3. 42
      scenes/insidemirror.lua
  4. 4
      src/lua/obj.rs
  5. 4
      src/main.rs
  6. 2
      src/object/mod.rs
  7. 33
      src/object/negation.rs

@ -29,6 +29,7 @@ A ray marching renderer in rust
![3rd test scene](prod/3.png) ![3rd test scene](prod/3.png)
![randomly generated spheres](prod/randomspheres.png) ![randomly generated spheres](prod/randomspheres.png)
![randomly generated objects](prod/smolgalaxy.png) ![randomly generated objects](prod/smolgalaxy.png)
![inside a spherical mirror](prod/insidemirror.png)
## License ## License
MIT MIT

Binary file not shown.

After

Width:  |  Height:  |  Size: 722 KiB

@ -0,0 +1,42 @@
local mirror = obj.withmaterial(
obj.negation(
obj.sphere(vec3.O, 8)
),
material.newfromdiagonal(
colorvec.new(0, 0, 0, 0),
colorvec.new(1, 1, 1, 1),
surfacetype.REFLECTIVE
)
)
local objects = {
obj.withmaterial(
obj.torus(vec3.new(1, 0, -3), 2, 1),
material.newfromdiagonal(
colorvec.new(1, .5, .2, 0),
colorvec.new(1, 1, 1, 1),
surfacetype.DIFFUSE
)
),
obj.withmaterial(
obj.sphere(vec3.new(3, 2, 0), 1),
material.newfromdiagonal(
colorvec.new(0, 0, 0, 0),
colorvec.new(.2, .5, 1, 0),
surfacetype.DIFFUSE
)
),
obj.withmaterial(
obj.cuboid(vec3.new(-3, -1, 2), vec3.new(1, 1, 1)),
material.newfromdiagonal(
colorvec.new(0, 0, 0, 0),
colorvec.new(.2, 1, .5, 0),
surfacetype.DIFFUSE
)
)
}
return obj.union(
util.union(objects),
mirror
)

@ -46,6 +46,10 @@ pub fn obj<'lua>(ctx: Context<'lua>, _env: Table<'lua>) -> rlua::Result<Table<'l
|ctx, (a, b): (LuaObject, LuaObject)| LuaObject::new(Intersection::new(a.get(), b.get())) |ctx, (a, b): (LuaObject, LuaObject)| LuaObject::new(Intersection::new(a.get(), b.get()))
)?)?; )?)?;
module.set("negation", ctx.create_function(
|ctx, obj: LuaObject| LuaObject::new(Negation::new(obj.get()))
)?)?;
module.set("plane", ctx.create_function( module.set("plane", ctx.create_function(
|ctx, (normal, offset): (Vec3, f64)| LuaObject::new(Plane::new(normal, offset)) |ctx, (normal, offset): (Vec3, f64)| LuaObject::new(Plane::new(normal, offset))
)?)?; )?)?;

@ -85,8 +85,8 @@ fn default_scene3() -> Scene {
fn main() { fn main() {
// get scene and camera // get scene and camera
//let scene = scene_from_file("scenes/randomspheres.lua".to_owned()).unwrap(); let scene = scene_from_file("scenes/insidemirror.lua".to_owned()).unwrap();
let scene = default_scene3(); //let scene = default_scene3();
let cam = default_cam(); let cam = default_cam();
// get stats on the scene we're about to render // get stats on the scene we're about to render

@ -10,6 +10,7 @@ mod plane;
mod union; mod union;
mod intersection; mod intersection;
mod exclusion; mod exclusion;
mod negation;
mod cuboid; mod cuboid;
mod cylinder; mod cylinder;
mod torus; mod torus;
@ -65,6 +66,7 @@ pub use plane::Plane;
pub use union::Union; pub use union::Union;
pub use intersection::Intersection; pub use intersection::Intersection;
pub use exclusion::Exclusion; pub use exclusion::Exclusion;
pub use negation::Negation;
pub use cuboid::Cuboid; pub use cuboid::Cuboid;
pub use cylinder::Cylinder; pub use cylinder::Cylinder;
pub use torus::Torus; pub use torus::Torus;

@ -0,0 +1,33 @@
use crate::object::Obj;
use crate::structs::Vec3;
use crate::material::Material;
use crate::light::Light;
#[derive(Debug, Clone, PartialEq)]
pub struct Negation<T: Obj> {
obj: T
}
impl<T: Obj> Negation<T> {
pub fn new(obj: T) -> Negation<T> {
Negation { obj }
}
}
impl<T: Obj> Obj for Negation<T> {
fn distance_to(&self, point: Vec3) -> f64 {
-self.obj.distance_to(point)
}
fn normal_at(&self, point: Vec3) -> Vec3 {
-self.obj.normal_at(point)
}
fn material_at(&self, point: Vec3) -> Material {
self.obj.material_at(point)
}
fn get_lights(&self) -> Vec<Light> {
self.obj.get_lights()
}
fn node_count(&self) -> u32 {
self.obj.node_count() + 1
}
}
Loading…
Cancel
Save