Skip to content

Commit 03190ca

Browse files
committed
feat: expose ambient light settings
1 parent 447906b commit 03190ca

File tree

6 files changed

+1019
-1334
lines changed

6 files changed

+1019
-1334
lines changed

pyraydeon/examples/py_sphere.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def paths(self, cam):
9292
PySphere(Point3(0, 0, 0), 1.0, Material(3.0, 3.0, 3)),
9393
PyPlane(Point3(0, -2, 0), Vec3(0, 1, 0), Material(9000.0, 3.0, 3)),
9494
],
95-
lights=[PointLight((4, 3, 10), 4.0, 2.0, 0.15, 0.4, 0.11)],
95+
lights=[PointLight((4, 3, 10), 3.6, 2.0, 0.15, 0.4, 0.11)],
96+
ambient_light=0.13,
9697
)
9798

9899

pyraydeon/examples/py_sphere_expected.svg

Lines changed: 1 addition & 1 deletion
Loading

pyraydeon/src/scene.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::Arc;
22

33
use numpy::{Ix1, PyArray, PyReadonlyArray1};
44
use pyo3::prelude::*;
5-
use raydeon::WorldSpace;
5+
use raydeon::{SceneLighting, WorldSpace};
66

77
use crate::light::PointLight;
88
use crate::linear::{ArbitrarySpace, Point2, Point3, Vec3};
@@ -101,11 +101,12 @@ pub(crate) struct Scene {
101101
#[pymethods]
102102
impl Scene {
103103
#[new]
104-
#[pyo3(signature = (geometry=None, lights=None))]
104+
#[pyo3(signature = (geometry=None, lights=None, ambient_light=0.0))]
105105
fn new(
106106
py: Python,
107107
geometry: Option<Vec<PyObject>>,
108108
lights: Option<Vec<PointLight>>,
109+
ambient_light: f64,
109110
) -> PyResult<Self> {
110111
let geometry = geometry.unwrap_or_default();
111112
let lights = lights.unwrap_or_default();
@@ -123,10 +124,13 @@ impl Scene {
123124
.into_iter()
124125
.map(|l| Arc::new(l.0) as Arc<dyn raydeon::lights::Light>)
125126
.collect();
127+
let lighting = SceneLighting::new()
128+
.with_lights(lights)
129+
.with_ambient_lighting(ambient_light);
126130
let scene = Arc::new(
127131
raydeon::Scene::new()
128132
.with_geometry(geometry)
129-
.with_lighting(lights),
133+
.with_lighting(lighting),
130134
);
131135
Ok(Self { scene })
132136
}

raydeon/examples/lit_cubes.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use raydeon::lights::PointLight;
22
use raydeon::material::Material;
33
use raydeon::shapes::AxisAlignedCuboid;
4-
use raydeon::{Camera, Scene, WPoint3, WVec3};
4+
use raydeon::{Camera, Scene, SceneLighting, WPoint3, WVec3};
55
use std::sync::Arc;
66

77
fn main() {
@@ -27,14 +27,18 @@ fn main() {
2727
Material::new(3.0, 2.0, 2.0, 0),
2828
)),
2929
])
30-
.with_lighting(vec![Arc::new(PointLight::new(
31-
20.0,
32-
100.0,
33-
(5.5, 12.0, 7.3),
34-
0.0,
35-
0.09,
36-
0.23,
37-
))]);
30+
.with_lighting(
31+
SceneLighting::new()
32+
.with_lights(vec![Arc::new(PointLight::new(
33+
20.0,
34+
100.0,
35+
(5.5, 12.0, 7.3),
36+
0.0,
37+
0.09,
38+
0.23,
39+
))])
40+
.with_ambient_lighting(0.13),
41+
);
3842

3943
let eye = WPoint3::new(8.0, 6.0, 4.0);
4044
let focus = WVec3::new(0.0, 0.0, 0.0);

0 commit comments

Comments
 (0)