Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 72 additions & 72 deletions Cargo.lock

Large diffs are not rendered by default.

37 changes: 25 additions & 12 deletions crates/processing_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2833,17 +2833,26 @@ pub extern "C" fn processing_geometry_sphere(radius: f32, sectors: u32, stacks:
.unwrap_or(0)
}

/// A `reach` or `range` of zero or less means none.
fn light_falloff(reach: f32, exponent: f32, range: f32) -> processing::prelude::light::Falloff {
processing::prelude::light::Falloff {
reach: (reach > 0.0).then_some(reach),
exponent,
range: (range > 0.0).then_some(range),
}
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_light_create_directional(
graphics_id: u64,
color: Color,
illuminance: f32,
strength: f32,
) -> u64 {
error::clear_error();
let graphics_entity = Entity::from_bits(graphics_id);
error::check(|| {
let mode = graphics_get_color_mode(graphics_entity)?;
light_create_directional(graphics_entity, color.resolve(&mode), illuminance)
light_create_directional(graphics_entity, color.resolve(&mode), strength)
})
.map(|e| e.to_bits())
.unwrap_or(0)
Expand All @@ -2853,7 +2862,9 @@ pub extern "C" fn processing_light_create_directional(
pub extern "C" fn processing_light_create_point(
graphics_id: u64,
color: Color,
intensity: f32,
strength: f32,
reach: f32,
falloff: f32,
range: f32,
radius: f32,
) -> u64 {
Expand All @@ -2864,8 +2875,8 @@ pub extern "C" fn processing_light_create_point(
light_create_point(
graphics_entity,
color.resolve(&mode),
intensity,
range,
strength,
light_falloff(reach, falloff, range),
radius,
)
})
Expand All @@ -2877,11 +2888,13 @@ pub extern "C" fn processing_light_create_point(
pub extern "C" fn processing_light_create_spot(
graphics_id: u64,
color: Color,
intensity: f32,
strength: f32,
reach: f32,
falloff: f32,
range: f32,
radius: f32,
inner_angle: f32,
outer_angle: f32,
angle: f32,
softness: f32,
) -> u64 {
error::clear_error();
let graphics_entity = Entity::from_bits(graphics_id);
Expand All @@ -2890,11 +2903,11 @@ pub extern "C" fn processing_light_create_spot(
light_create_spot(
graphics_entity,
color.resolve(&mode),
intensity,
range,
strength,
light_falloff(reach, falloff, range),
radius,
inner_angle,
outer_angle,
angle,
softness,
)
})
.map(|e| e.to_bits())
Expand Down
40 changes: 26 additions & 14 deletions crates/processing_node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1977,13 +1977,13 @@ pub fn js_light_create_directional(
c3: f64,
a: f64,
space: u8,
illuminance: f64,
strength: f64,
) -> Result<BigInt> {
let graphics = ent(graphics_id);
let color = Color::new(c1, c2, c3, a, space);
check((|| {
let mode = graphics_get_color_mode(graphics)?;
light_create_directional(graphics, color.resolve(&mode), illuminance as f32)
light_create_directional(graphics, color.resolve(&mode), strength as f32)
})())
.map(id)
}
Expand All @@ -1996,8 +1996,10 @@ pub fn js_light_create_point(
c3: f64,
a: f64,
space: u8,
intensity: f64,
range: f64,
strength: f64,
reach: Option<f64>,
falloff: f64,
range: Option<f64>,
radius: f64,
) -> Result<BigInt> {
let graphics = ent(graphics_id);
Expand All @@ -2007,8 +2009,12 @@ pub fn js_light_create_point(
light_create_point(
graphics,
color.resolve(&mode),
intensity as f32,
range as f32,
strength as f32,
light::Falloff {
reach: reach.map(|v| v as f32),
exponent: falloff as f32,
range: range.map(|v| v as f32),
},
radius as f32,
)
})())
Expand All @@ -2023,11 +2029,13 @@ pub fn js_light_create_spot(
c3: f64,
a: f64,
space: u8,
intensity: f64,
range: f64,
strength: f64,
reach: Option<f64>,
falloff: f64,
range: Option<f64>,
radius: f64,
inner_angle: f64,
outer_angle: f64,
angle: f64,
softness: f64,
) -> Result<BigInt> {
let graphics = ent(graphics_id);
let color = Color::new(c1, c2, c3, a, space);
Expand All @@ -2036,11 +2044,15 @@ pub fn js_light_create_spot(
light_create_spot(
graphics,
color.resolve(&mode),
intensity as f32,
range as f32,
strength as f32,
light::Falloff {
reach: reach.map(|v| v as f32),
exponent: falloff as f32,
range: range.map(|v| v as f32),
},
radius as f32,
inner_angle as f32,
outer_angle as f32,
angle as f32,
softness as f32,
)
})())
.map(id)
Expand Down
2 changes: 1 addition & 1 deletion crates/processing_pyo3/examples/Basics/Camera/move_eye.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setup():


def draw():
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
lights()
background(0.0)

# Change height of the camera with mouseY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setup():


def draw():
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
lights()
background(0.0)
far = remap(mouse_x, 0, width, 120, 400)
if show_perspective:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setup():


def draw():
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
lights()
background(0.0)
camera_y = height / 2.0
# A fov of 0 would divide by zero below
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def setup():


def draw():
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
lights()
background(0.0)

no_stroke()
Expand Down
3 changes: 1 addition & 2 deletions crates/processing_pyo3/examples/Basics/Lights/directional.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def setup():
mode_3d()
no_stroke()
fill(0.8)
# The shapes become lit once a material property is set
roughness(0.6)


Expand All @@ -22,7 +21,7 @@ def draw():
background(0.0)
dir_y = (mouse_y / height - 0.5) * 2
dir_x = (mouse_x / width - 0.5) * 2
directional_light((0.8, 0.8, 0.8), 2500.0, look_at=(-dir_x, -dir_y, -1))
directional_light(204, look_at=(-dir_x, -dir_y, -1))
translate(-100, 0, 0)
sphere(80)
translate(200, 0, 0)
Expand Down
8 changes: 4 additions & 4 deletions crates/processing_pyo3/examples/Basics/Lights/mixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ def draw():
background(0.0)

# Orange point light on the right
point_light((0.59, 0.39, 0.0), 3000000000.0, 600.0, 1.0, # Color
point_light((150, 100, 0), # Color
position=(200, -150, 0)) # Position

# Blue directional light from the left
directional_light((0.0, 0.4, 1.0), 4000.0, # Color
directional_light((0, 102, 255), # Color
look_at=(1, 0, 0)) # The x-, y-, z-axis direction

# Yellow spotlight from the front
spot_light((1.0, 1.0, 0.43), 2000000000.0, 600.0, 1.0, # Color
PI / 4, PI / 2, # Angle, concentration
spot_light((255, 255, 109), # Color
angle=PI / 2, softness=0.5, # Angle, softness
position=(0, 40, 200), # Position
look_at=(0, 40 - 0.5, 200 - 0.5)) # Direction

Expand Down
8 changes: 4 additions & 4 deletions crates/processing_pyo3/examples/Basics/Lights/mixture_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ def draw():
def define_lights():
# The lights are placed in the original's top-left coordinates
# Orange point light on the right
point_light((0.59, 0.39, 0.0), 3000000000.0, 600.0, 1.0, # Color
point_light((150, 100, 0), # Color
position=(200 - width / 2, -150 - height / 2, 0)) # Position

# Blue directional light from the left
directional_light((0.0, 0.4, 1.0), 4000.0, # Color
directional_light((0, 102, 255), # Color
look_at=(1, 0, 0)) # The x-, y-, z-axis direction

# Yellow spotlight from the front
spot_light((1.0, 1.0, 0.43), 2000000000.0, 600.0, 1.0, # Color
PI / 4, PI / 2, # Angle, concentration
spot_light((255, 255, 109), # Color
angle=PI / 2, softness=0.5, # Angle, softness
position=(-width / 2, 40 - height / 2, 200), # Position
look_at=(-width / 2, 40 - height / 2 - 0.5, 200 - 0.5)) # Direction

Expand Down
2 changes: 1 addition & 1 deletion crates/processing_pyo3/examples/Basics/Lights/on_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def setup():

def draw():
global spin
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
lights()
background(0.2)

# A lit material turns the lights on; unlit() turns them off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setup():


def draw():
directional_light((0.8, 0.8, 0.8), 4000.0, look_at=(0, 0, -1))
directional_light(204, look_at=(0, 0, -1))
background(0.0)
# A smoother (less rough) material gives a stronger specular highlight
s = mouse_x / width
Expand Down
6 changes: 3 additions & 3 deletions crates/processing_pyo3/examples/Basics/Lights/spot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ def draw():

# Lights are positioned in the original's top-left coordinates
# Light the bottom of the sphere
directional_light((0.2, 0.4, 0.49), 4000.0, look_at=(0, -1, 0))
directional_light((51, 102, 126), look_at=(0, -1, 0))

# Orange light on the upper-right of the sphere
spot_light((0.8, 0.6, 0.0), 10000000000.0, 1200.0, 1.0, 0.0, PI / 12,
spot_light((204, 153, 0), angle=PI / 12, softness=1.0,
position=(360 - width / 2, 160 - height / 2, 600),
look_at=(360 - width / 2, 160 - height / 2, 0))

# Moving spotlight that follows the mouse
spot_light((0.4, 0.6, 0.8), 10000000000.0, 1200.0, 1.0, 0.0, PI / 12,
spot_light((102, 153, 204), angle=PI / 12, softness=1.0,
position=(360 - width / 2, mouse_y - height / 2, 600),
look_at=(360 - width / 2, mouse_y - height / 2, 0))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setup():

def draw():
global ry
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
lights()
background(0.0)

translate(0, 100, -200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setup():

def draw():
global a
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
lights()
background(0.0, 0.0, 0.1)

for i in range(num):
Expand Down
2 changes: 1 addition & 1 deletion crates/processing_pyo3/examples/Demos/Graphics/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def setup():

def draw():
# lights()
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
lights()
background(1.0)
scale(0.9)
rotate_y(remap(mouse_x, 0, width, -PI, PI))
Expand Down
4 changes: 2 additions & 2 deletions crates/processing_pyo3/examples/Demos/Graphics/planets.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def draw():

# pointLight(255, 255, 255, 0, 0, 0) at the sun's position, and
# pointLight(255, 255, 255, 0, 0, -150) at the screen corner for planet1
point_light((1.0, 1.0, 1.0), 1000000.0, 1200.0, 1.0, position=(0, 0, -300))
point_light((1.0, 1.0, 1.0), 1000000.0, 1200.0, 1.0, position=(-width / 2, -height / 2, -150))
point_light(255, position=(0, 0, -300))
point_light(255, position=(-width / 2, -height / 2, -150))

push_matrix()
translate(0, 0, -300)
Expand Down
2 changes: 1 addition & 1 deletion crates/processing_pyo3/examples/Demos/Graphics/ribbons.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def setup():

def draw():
# ambient(80); lights()
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
lights()
background(0.0)

translate(0, 0, 200)
Expand Down
2 changes: 1 addition & 1 deletion crates/processing_pyo3/examples/Demos/Graphics/trefoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def setup():

def draw():
# ambient(250, 250, 250); pointLight(255, 255, 255, 0, 0, 200)
point_light((1.0, 1.0, 1.0), 1000000.0, 600.0, 1.0, position=(0, 0, 200))
point_light(255, position=(0, 0, 200))
background(0.0)

pg.begin_draw()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def draw():
no_stroke()

background(1.0)
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
lights()

# ------ set view ------
push_matrix()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def draw():
global rotation_x, rotation_y, agent_color

background(1.0)
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
lights()

push_matrix()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def draw():
global rotation_x, rotation_y

background(1.0)
directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0))
lights()

push_matrix()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def draw():
global offset_x, offset_y, target_rotation_x, target_rotation_y, rotation_x, rotation_y
background(1.0)

directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0)) # GAP: lights() is missing (ambient + directional, lighting both sides); with this single light the faces turned away from it render black
lights()

# ------ set view ------
translate(0, 0, zoom)
Expand Down
Loading