Skip to content

Commit

Permalink
feat: expose ambient light settings
Browse files Browse the repository at this point in the history
  • Loading branch information
cbgbt committed Nov 26, 2024
1 parent 447906b commit 03190ca
Show file tree
Hide file tree
Showing 6 changed files with 1,019 additions and 1,334 deletions.
3 changes: 2 additions & 1 deletion pyraydeon/examples/py_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def paths(self, cam):
PySphere(Point3(0, 0, 0), 1.0, Material(3.0, 3.0, 3)),
PyPlane(Point3(0, -2, 0), Vec3(0, 1, 0), Material(9000.0, 3.0, 3)),
],
lights=[PointLight((4, 3, 10), 4.0, 2.0, 0.15, 0.4, 0.11)],
lights=[PointLight((4, 3, 10), 3.6, 2.0, 0.15, 0.4, 0.11)],
ambient_light=0.13,
)


Expand Down
2 changes: 1 addition & 1 deletion pyraydeon/examples/py_sphere_expected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions pyraydeon/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use numpy::{Ix1, PyArray, PyReadonlyArray1};
use pyo3::prelude::*;
use raydeon::WorldSpace;
use raydeon::{SceneLighting, WorldSpace};

use crate::light::PointLight;
use crate::linear::{ArbitrarySpace, Point2, Point3, Vec3};
Expand Down Expand Up @@ -101,11 +101,12 @@ pub(crate) struct Scene {
#[pymethods]
impl Scene {
#[new]
#[pyo3(signature = (geometry=None, lights=None))]
#[pyo3(signature = (geometry=None, lights=None, ambient_light=0.0))]
fn new(
py: Python,
geometry: Option<Vec<PyObject>>,
lights: Option<Vec<PointLight>>,
ambient_light: f64,
) -> PyResult<Self> {
let geometry = geometry.unwrap_or_default();
let lights = lights.unwrap_or_default();
Expand All @@ -123,10 +124,13 @@ impl Scene {
.into_iter()
.map(|l| Arc::new(l.0) as Arc<dyn raydeon::lights::Light>)
.collect();
let lighting = SceneLighting::new()
.with_lights(lights)
.with_ambient_lighting(ambient_light);
let scene = Arc::new(
raydeon::Scene::new()
.with_geometry(geometry)
.with_lighting(lights),
.with_lighting(lighting),
);
Ok(Self { scene })
}
Expand Down
22 changes: 13 additions & 9 deletions raydeon/examples/lit_cubes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use raydeon::lights::PointLight;
use raydeon::material::Material;
use raydeon::shapes::AxisAlignedCuboid;
use raydeon::{Camera, Scene, WPoint3, WVec3};
use raydeon::{Camera, Scene, SceneLighting, WPoint3, WVec3};
use std::sync::Arc;

fn main() {
Expand All @@ -27,14 +27,18 @@ fn main() {
Material::new(3.0, 2.0, 2.0, 0),
)),
])
.with_lighting(vec![Arc::new(PointLight::new(
20.0,
100.0,
(5.5, 12.0, 7.3),
0.0,
0.09,
0.23,
))]);
.with_lighting(
SceneLighting::new()
.with_lights(vec![Arc::new(PointLight::new(
20.0,
100.0,
(5.5, 12.0, 7.3),
0.0,
0.09,
0.23,
))])
.with_ambient_lighting(0.13),
);

let eye = WPoint3::new(8.0, 6.0, 4.0);
let focus = WVec3::new(0.0, 0.0, 0.0);
Expand Down
Loading

0 comments on commit 03190ca

Please sign in to comment.