From 2da5e66c7c74dad14ef1e4ee34f452617c71f9c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?charlotte=20=F0=9F=8C=B8?= Date: Tue, 1 Dec 2026 19:30:51 -0800 Subject: [PATCH] Lights. --- Cargo.lock | 144 +++++------ crates/processing_ffi/src/lib.rs | 37 ++- crates/processing_node/src/lib.rs | 40 +-- .../examples/Basics/Camera/move_eye.py | 2 +- .../examples/Basics/Camera/orthographic.py | 2 +- .../examples/Basics/Camera/perspective.py | 2 +- .../examples/Basics/Form/primitives_3d.py | 2 +- .../examples/Basics/Lights/directional.py | 3 +- .../examples/Basics/Lights/mixture.py | 8 +- .../examples/Basics/Lights/mixture_grid.py | 8 +- .../examples/Basics/Lights/on_off.py | 2 +- .../examples/Basics/Lights/reflection.py | 2 +- .../examples/Basics/Lights/spot.py | 6 +- .../examples/Basics/Shape/load_display_obj.py | 2 +- .../Basics/Transform/rotate_push_pop.py | 2 +- .../examples/Demos/Graphics/patch.py | 2 +- .../examples/Demos/Graphics/planets.py | 4 +- .../examples/Demos/Graphics/ribbons.py | 2 +- .../examples/Demos/Graphics/trefoil.py | 2 +- .../02_M/M_1_4_01/M_1_4_01.py | 2 +- .../02_M/M_1_6_01_TOOL/M_1_6_01_TOOL.py | 2 +- .../02_M/M_1_6_02_TOOL/M_1_6_02_TOOL.py | 2 +- .../02_M/M_2_4_01/M_2_4_01.py | 2 +- .../02_M/M_3_3_01/M_3_3_01.py | 4 +- .../02_M/M_3_3_02/M_3_3_02.py | 4 +- .../02_M/M_3_3_03/M_3_3_03.py | 2 +- .../02_M/M_3_3_04/M_3_3_04.py | 4 +- .../02_M/M_3_4_01_TOOL/M_3_4_01_TOOL.py | 2 +- .../02_M/M_3_4_03_TOOL/M_3_4_03_TOOL.py | 2 +- .../02_M/M_3_5_01/M_3_5_01.py | 2 +- .../examples/Topics/Geometry/icosahedra.py | 2 +- .../Topics/Geometry/shape_transform.py | 2 +- .../examples/Topics/Geometry/space_junk.py | 6 +- .../examples/Topics/Geometry/toroid.py | 2 +- .../examples/Topics/Geometry/vertices.py | 2 +- .../Topics/Motion/cubes_within_cube.py | 2 +- .../examples/Topics/Shaders/edge_filter.py | 2 +- .../examples/Topics/Shaders/toon_shading.py | 2 +- .../Simulate/gravitational_attraction_3d.py | 2 +- .../examples/camera_controllers.py | 2 +- .../processing_pyo3/examples/flocking_duck.py | 3 +- .../processing_pyo3/examples/flocking_gpu.py | 3 +- crates/processing_pyo3/examples/lights.py | 8 +- crates/processing_pyo3/examples/materials.py | 4 +- .../examples/particles_animated.py | 3 +- .../examples/particles_basic.py | 3 +- .../examples/particles_emit_gpu.py | 3 +- .../examples/particles_from_mesh.py | 3 +- .../examples/particles_noise.py | 3 +- .../examples/particles_stress.py | 7 +- .../processing_pyo3/examples/primitives_3d.py | 1 + .../examples/test_jupyter_3d.ipynb | 2 +- crates/processing_pyo3/src/graphics.rs | 165 ++++++++----- crates/processing_pyo3/src/lib.rs | 136 ++++++----- crates/processing_render/src/gltf.rs | 2 + crates/processing_render/src/graphics.rs | 30 ++- crates/processing_render/src/lib.rs | 58 +++-- crates/processing_render/src/light.rs | 227 +++++++++++++++++- .../processing_render/src/render/command.rs | 7 + crates/processing_render/src/render/mod.rs | 44 +++- crates/processing_wasm/src/lib.rs | 40 +-- docs/api.md | 12 +- examples/camera_controllers.rs | 2 +- examples/lights.rs | 29 ++- examples/materials.rs | 16 +- examples/particles_animated.rs | 4 +- examples/particles_basic.rs | 4 +- examples/particles_colored_pbr.rs | 3 +- examples/particles_emit_gpu.rs | 3 +- examples/particles_from_mesh.rs | 3 +- examples/particles_noise.rs | 3 +- examples/particles_oriented.rs | 4 +- examples/particles_scatter.rs | 4 +- examples/particles_stress.rs | 8 +- examples/pbr.rs | 16 +- examples/primitives_3d.rs | 3 +- examples/stroke_3d.rs | 3 +- examples/text_3d.rs | 2 +- 78 files changed, 829 insertions(+), 366 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 99d71672..937d9df6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -539,7 +539,7 @@ checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" [[package]] name = "bevy" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_internal", ] @@ -547,7 +547,7 @@ dependencies = [ [[package]] name = "bevy_a11y" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "accesskit", "bevy_app", @@ -559,7 +559,7 @@ dependencies = [ [[package]] name = "bevy_android" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "android-activity", ] @@ -567,7 +567,7 @@ dependencies = [ [[package]] name = "bevy_animation" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_animation_macros", "bevy_app", @@ -601,7 +601,7 @@ dependencies = [ [[package]] name = "bevy_animation_macros" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_macro_utils", "quote", @@ -611,12 +611,12 @@ dependencies = [ [[package]] name = "bevy_annotations" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" [[package]] name = "bevy_anti_alias" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", @@ -638,7 +638,7 @@ dependencies = [ [[package]] name = "bevy_app" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_derive", "bevy_ecs", @@ -659,7 +659,7 @@ dependencies = [ [[package]] name = "bevy_asset" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "async-broadcast", "async-channel", @@ -702,7 +702,7 @@ dependencies = [ [[package]] name = "bevy_asset_macros" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_macro_utils", "proc-macro2", @@ -713,7 +713,7 @@ dependencies = [ [[package]] name = "bevy_audio" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", @@ -728,7 +728,7 @@ dependencies = [ [[package]] name = "bevy_camera" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", @@ -754,7 +754,7 @@ dependencies = [ [[package]] name = "bevy_camera_controller" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_camera", @@ -777,7 +777,7 @@ dependencies = [ [[package]] name = "bevy_clipboard" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "arboard", "bevy_app", @@ -792,7 +792,7 @@ dependencies = [ [[package]] name = "bevy_color" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_curve", "bevy_math", @@ -808,7 +808,7 @@ dependencies = [ [[package]] name = "bevy_core_pipeline" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", @@ -851,7 +851,7 @@ dependencies = [ [[package]] name = "bevy_curve" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "approx", "bevy_math", @@ -865,7 +865,7 @@ dependencies = [ [[package]] name = "bevy_derive" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_macro_utils", "quote", @@ -875,7 +875,7 @@ dependencies = [ [[package]] name = "bevy_dev_tools" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_animation", "bevy_app", @@ -914,7 +914,7 @@ dependencies = [ [[package]] name = "bevy_diagnostic" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "atomic-waker", "bevy_app", @@ -931,7 +931,7 @@ dependencies = [ [[package]] name = "bevy_ecs" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "arrayvec", "bevy_ecs_macros", @@ -958,7 +958,7 @@ dependencies = [ [[package]] name = "bevy_ecs_macro_logic" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_macro_utils", "proc-macro2", @@ -969,7 +969,7 @@ dependencies = [ [[package]] name = "bevy_ecs_macros" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_ecs_macro_logic", "bevy_macro_utils", @@ -981,7 +981,7 @@ dependencies = [ [[package]] name = "bevy_encase_derive" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_macro_utils", "encase_derive_impl", @@ -990,7 +990,7 @@ dependencies = [ [[package]] name = "bevy_extract" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_camera", @@ -1007,7 +1007,7 @@ dependencies = [ [[package]] name = "bevy_extract_macros" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_macro_utils", "proc-macro2", @@ -1018,7 +1018,7 @@ dependencies = [ [[package]] name = "bevy_feathers" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "accesskit", "bevy_a11y", @@ -1049,12 +1049,12 @@ dependencies = [ [[package]] name = "bevy_fuzzy" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" [[package]] name = "bevy_gilrs" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_ecs", @@ -1069,7 +1069,7 @@ dependencies = [ [[package]] name = "bevy_gizmos" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", @@ -1093,7 +1093,7 @@ dependencies = [ [[package]] name = "bevy_gizmos_macros" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_macro_utils", "quote", @@ -1103,7 +1103,7 @@ dependencies = [ [[package]] name = "bevy_gizmos_render" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", @@ -1133,7 +1133,7 @@ dependencies = [ [[package]] name = "bevy_gltf" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "async-lock", "base64", @@ -1169,7 +1169,7 @@ dependencies = [ [[package]] name = "bevy_image" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", @@ -1197,7 +1197,7 @@ dependencies = [ [[package]] name = "bevy_input" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_ecs", @@ -1213,7 +1213,7 @@ dependencies = [ [[package]] name = "bevy_input_focus" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_camera", @@ -1230,7 +1230,7 @@ dependencies = [ [[package]] name = "bevy_internal" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_a11y", "bevy_android", @@ -1294,7 +1294,7 @@ dependencies = [ [[package]] name = "bevy_light" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", @@ -1321,7 +1321,7 @@ dependencies = [ [[package]] name = "bevy_log" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "android_log-sys", "bevy_app", @@ -1338,7 +1338,7 @@ dependencies = [ [[package]] name = "bevy_macro_utils" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "proc-macro2", "quote", @@ -1349,7 +1349,7 @@ dependencies = [ [[package]] name = "bevy_material" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_asset", "bevy_derive", @@ -1371,7 +1371,7 @@ dependencies = [ [[package]] name = "bevy_material_macros" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_macro_utils", "quote", @@ -1381,7 +1381,7 @@ dependencies = [ [[package]] name = "bevy_math" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "approx", "bevy_reflect", @@ -1397,7 +1397,7 @@ dependencies = [ [[package]] name = "bevy_mesh" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", @@ -1440,7 +1440,7 @@ dependencies = [ [[package]] name = "bevy_pbr" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "arrayvec", "bevy_app", @@ -1484,7 +1484,7 @@ dependencies = [ [[package]] name = "bevy_picking" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", @@ -1508,7 +1508,7 @@ dependencies = [ [[package]] name = "bevy_platform" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bytemuck", "critical-section", @@ -1530,7 +1530,7 @@ dependencies = [ [[package]] name = "bevy_post_process" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", @@ -1556,12 +1556,12 @@ dependencies = [ [[package]] name = "bevy_ptr" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" [[package]] name = "bevy_reflect" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "assert_type_match", "bevy_annotations", @@ -1590,7 +1590,7 @@ dependencies = [ [[package]] name = "bevy_reflect_derive" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_macro_utils", "indexmap", @@ -1603,7 +1603,7 @@ dependencies = [ [[package]] name = "bevy_render" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "async-channel", "bevy_app", @@ -1661,7 +1661,7 @@ dependencies = [ [[package]] name = "bevy_render_macros" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_extract_macros", "bevy_macro_utils", @@ -1673,7 +1673,7 @@ dependencies = [ [[package]] name = "bevy_scene" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", @@ -1692,7 +1692,7 @@ dependencies = [ [[package]] name = "bevy_scene_macros" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_ecs_macro_logic", "bevy_macro_utils", @@ -1704,7 +1704,7 @@ dependencies = [ [[package]] name = "bevy_shader" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_asset", "bevy_platform", @@ -1720,7 +1720,7 @@ dependencies = [ [[package]] name = "bevy_shape" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "arrayvec", "bevy_math", @@ -1735,7 +1735,7 @@ dependencies = [ [[package]] name = "bevy_sprite" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", @@ -1760,7 +1760,7 @@ dependencies = [ [[package]] name = "bevy_sprite_render" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", @@ -1796,7 +1796,7 @@ dependencies = [ [[package]] name = "bevy_state" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_ecs", @@ -1811,7 +1811,7 @@ dependencies = [ [[package]] name = "bevy_state_macros" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_macro_utils", "quote", @@ -1821,7 +1821,7 @@ dependencies = [ [[package]] name = "bevy_tasks" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "async-channel", "async-executor", @@ -1839,7 +1839,7 @@ dependencies = [ [[package]] name = "bevy_text" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", @@ -1866,7 +1866,7 @@ dependencies = [ [[package]] name = "bevy_time" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_ecs", @@ -1880,7 +1880,7 @@ dependencies = [ [[package]] name = "bevy_transform" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_ecs", @@ -1896,7 +1896,7 @@ dependencies = [ [[package]] name = "bevy_ui" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "accesskit", "bevy_a11y", @@ -1933,7 +1933,7 @@ dependencies = [ [[package]] name = "bevy_ui_render" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_a11y", "bevy_app", @@ -1968,7 +1968,7 @@ dependencies = [ [[package]] name = "bevy_ui_widgets" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "accesskit", "bevy_a11y", @@ -1995,7 +1995,7 @@ dependencies = [ [[package]] name = "bevy_utils" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "async-channel", "bevy_platform", @@ -2007,7 +2007,7 @@ dependencies = [ [[package]] name = "bevy_window" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", @@ -2026,7 +2026,7 @@ dependencies = [ [[package]] name = "bevy_winit" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "accesskit", "accesskit_winit", @@ -2058,7 +2058,7 @@ dependencies = [ [[package]] name = "bevy_world_serialization" version = "0.20.0-dev" -source = "git+https://github.com/processing/bevy?branch=main#f65b12082e0322f0a498b2958fb0712ff5c73bd6" +source = "git+https://github.com/processing/bevy?branch=main#675cbaa954c3c8c7e1ba7738614d9e641b7779ab" dependencies = [ "bevy_app", "bevy_asset", diff --git a/crates/processing_ffi/src/lib.rs b/crates/processing_ffi/src/lib.rs index 1ee0a73f..01db4294 100644 --- a/crates/processing_ffi/src/lib.rs +++ b/crates/processing_ffi/src/lib.rs @@ -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) @@ -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 { @@ -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, ) }) @@ -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); @@ -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()) diff --git a/crates/processing_node/src/lib.rs b/crates/processing_node/src/lib.rs index d268b84c..c937828d 100644 --- a/crates/processing_node/src/lib.rs +++ b/crates/processing_node/src/lib.rs @@ -1977,13 +1977,13 @@ pub fn js_light_create_directional( c3: f64, a: f64, space: u8, - illuminance: f64, + strength: f64, ) -> Result { 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) } @@ -1996,8 +1996,10 @@ pub fn js_light_create_point( c3: f64, a: f64, space: u8, - intensity: f64, - range: f64, + strength: f64, + reach: Option, + falloff: f64, + range: Option, radius: f64, ) -> Result { let graphics = ent(graphics_id); @@ -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, ) })()) @@ -2023,11 +2029,13 @@ pub fn js_light_create_spot( c3: f64, a: f64, space: u8, - intensity: f64, - range: f64, + strength: f64, + reach: Option, + falloff: f64, + range: Option, radius: f64, - inner_angle: f64, - outer_angle: f64, + angle: f64, + softness: f64, ) -> Result { let graphics = ent(graphics_id); let color = Color::new(c1, c2, c3, a, space); @@ -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) diff --git a/crates/processing_pyo3/examples/Basics/Camera/move_eye.py b/crates/processing_pyo3/examples/Basics/Camera/move_eye.py index cc87e848..aea858f3 100644 --- a/crates/processing_pyo3/examples/Basics/Camera/move_eye.py +++ b/crates/processing_pyo3/examples/Basics/Camera/move_eye.py @@ -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 diff --git a/crates/processing_pyo3/examples/Basics/Camera/orthographic.py b/crates/processing_pyo3/examples/Basics/Camera/orthographic.py index fbca5f75..31460932 100644 --- a/crates/processing_pyo3/examples/Basics/Camera/orthographic.py +++ b/crates/processing_pyo3/examples/Basics/Camera/orthographic.py @@ -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: diff --git a/crates/processing_pyo3/examples/Basics/Camera/perspective.py b/crates/processing_pyo3/examples/Basics/Camera/perspective.py index a5f3f1da..970a19c1 100644 --- a/crates/processing_pyo3/examples/Basics/Camera/perspective.py +++ b/crates/processing_pyo3/examples/Basics/Camera/perspective.py @@ -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 diff --git a/crates/processing_pyo3/examples/Basics/Form/primitives_3d.py b/crates/processing_pyo3/examples/Basics/Form/primitives_3d.py index 77e0dbc8..7c375701 100644 --- a/crates/processing_pyo3/examples/Basics/Form/primitives_3d.py +++ b/crates/processing_pyo3/examples/Basics/Form/primitives_3d.py @@ -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() diff --git a/crates/processing_pyo3/examples/Basics/Lights/directional.py b/crates/processing_pyo3/examples/Basics/Lights/directional.py index c9abf838..f45f4379 100644 --- a/crates/processing_pyo3/examples/Basics/Lights/directional.py +++ b/crates/processing_pyo3/examples/Basics/Lights/directional.py @@ -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) @@ -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) diff --git a/crates/processing_pyo3/examples/Basics/Lights/mixture.py b/crates/processing_pyo3/examples/Basics/Lights/mixture.py index 68ea8dbd..0416be3a 100644 --- a/crates/processing_pyo3/examples/Basics/Lights/mixture.py +++ b/crates/processing_pyo3/examples/Basics/Lights/mixture.py @@ -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 diff --git a/crates/processing_pyo3/examples/Basics/Lights/mixture_grid.py b/crates/processing_pyo3/examples/Basics/Lights/mixture_grid.py index a23c7b00..169366d9 100644 --- a/crates/processing_pyo3/examples/Basics/Lights/mixture_grid.py +++ b/crates/processing_pyo3/examples/Basics/Lights/mixture_grid.py @@ -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 diff --git a/crates/processing_pyo3/examples/Basics/Lights/on_off.py b/crates/processing_pyo3/examples/Basics/Lights/on_off.py index 99832b36..3587695d 100644 --- a/crates/processing_pyo3/examples/Basics/Lights/on_off.py +++ b/crates/processing_pyo3/examples/Basics/Lights/on_off.py @@ -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 diff --git a/crates/processing_pyo3/examples/Basics/Lights/reflection.py b/crates/processing_pyo3/examples/Basics/Lights/reflection.py index 1e5c98d4..6f7520d8 100644 --- a/crates/processing_pyo3/examples/Basics/Lights/reflection.py +++ b/crates/processing_pyo3/examples/Basics/Lights/reflection.py @@ -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 diff --git a/crates/processing_pyo3/examples/Basics/Lights/spot.py b/crates/processing_pyo3/examples/Basics/Lights/spot.py index bba31b78..4f64156b 100644 --- a/crates/processing_pyo3/examples/Basics/Lights/spot.py +++ b/crates/processing_pyo3/examples/Basics/Lights/spot.py @@ -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)) diff --git a/crates/processing_pyo3/examples/Basics/Shape/load_display_obj.py b/crates/processing_pyo3/examples/Basics/Shape/load_display_obj.py index a19d0bc7..520fde76 100644 --- a/crates/processing_pyo3/examples/Basics/Shape/load_display_obj.py +++ b/crates/processing_pyo3/examples/Basics/Shape/load_display_obj.py @@ -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) diff --git a/crates/processing_pyo3/examples/Basics/Transform/rotate_push_pop.py b/crates/processing_pyo3/examples/Basics/Transform/rotate_push_pop.py index e05b228b..5c867ae1 100644 --- a/crates/processing_pyo3/examples/Basics/Transform/rotate_push_pop.py +++ b/crates/processing_pyo3/examples/Basics/Transform/rotate_push_pop.py @@ -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): diff --git a/crates/processing_pyo3/examples/Demos/Graphics/patch.py b/crates/processing_pyo3/examples/Demos/Graphics/patch.py index 71d20563..b3f10e2c 100644 --- a/crates/processing_pyo3/examples/Demos/Graphics/patch.py +++ b/crates/processing_pyo3/examples/Demos/Graphics/patch.py @@ -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)) diff --git a/crates/processing_pyo3/examples/Demos/Graphics/planets.py b/crates/processing_pyo3/examples/Demos/Graphics/planets.py index 2689b979..270cc447 100644 --- a/crates/processing_pyo3/examples/Demos/Graphics/planets.py +++ b/crates/processing_pyo3/examples/Demos/Graphics/planets.py @@ -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) diff --git a/crates/processing_pyo3/examples/Demos/Graphics/ribbons.py b/crates/processing_pyo3/examples/Demos/Graphics/ribbons.py index 5025c077..2d1fd6dd 100644 --- a/crates/processing_pyo3/examples/Demos/Graphics/ribbons.py +++ b/crates/processing_pyo3/examples/Demos/Graphics/ribbons.py @@ -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) diff --git a/crates/processing_pyo3/examples/Demos/Graphics/trefoil.py b/crates/processing_pyo3/examples/Demos/Graphics/trefoil.py index a2b2e7d0..0f2ddff9 100644 --- a/crates/processing_pyo3/examples/Demos/Graphics/trefoil.py +++ b/crates/processing_pyo3/examples/Demos/Graphics/trefoil.py @@ -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() diff --git a/crates/processing_pyo3/examples/Generative Design/02_M/M_1_4_01/M_1_4_01.py b/crates/processing_pyo3/examples/Generative Design/02_M/M_1_4_01/M_1_4_01.py index 1454883f..6559131e 100644 --- a/crates/processing_pyo3/examples/Generative Design/02_M/M_1_4_01/M_1_4_01.py +++ b/crates/processing_pyo3/examples/Generative Design/02_M/M_1_4_01/M_1_4_01.py @@ -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() diff --git a/crates/processing_pyo3/examples/Generative Design/02_M/M_1_6_01_TOOL/M_1_6_01_TOOL.py b/crates/processing_pyo3/examples/Generative Design/02_M/M_1_6_01_TOOL/M_1_6_01_TOOL.py index 2e076607..a5672f1a 100644 --- a/crates/processing_pyo3/examples/Generative Design/02_M/M_1_6_01_TOOL/M_1_6_01_TOOL.py +++ b/crates/processing_pyo3/examples/Generative Design/02_M/M_1_6_01_TOOL/M_1_6_01_TOOL.py @@ -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() diff --git a/crates/processing_pyo3/examples/Generative Design/02_M/M_1_6_02_TOOL/M_1_6_02_TOOL.py b/crates/processing_pyo3/examples/Generative Design/02_M/M_1_6_02_TOOL/M_1_6_02_TOOL.py index 269516ce..306396e2 100644 --- a/crates/processing_pyo3/examples/Generative Design/02_M/M_1_6_02_TOOL/M_1_6_02_TOOL.py +++ b/crates/processing_pyo3/examples/Generative Design/02_M/M_1_6_02_TOOL/M_1_6_02_TOOL.py @@ -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() diff --git a/crates/processing_pyo3/examples/Generative Design/02_M/M_2_4_01/M_2_4_01.py b/crates/processing_pyo3/examples/Generative Design/02_M/M_2_4_01/M_2_4_01.py index 85b215bd..57cd6607 100644 --- a/crates/processing_pyo3/examples/Generative Design/02_M/M_2_4_01/M_2_4_01.py +++ b/crates/processing_pyo3/examples/Generative Design/02_M/M_2_4_01/M_2_4_01.py @@ -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) diff --git a/crates/processing_pyo3/examples/Generative Design/02_M/M_3_3_01/M_3_3_01.py b/crates/processing_pyo3/examples/Generative Design/02_M/M_3_3_01/M_3_3_01.py index d5b39f8a..15decbe5 100644 --- a/crates/processing_pyo3/examples/Generative Design/02_M/M_3_3_01/M_3_3_01.py +++ b/crates/processing_pyo3/examples/Generative Design/02_M/M_3_3_01/M_3_3_01.py @@ -650,8 +650,8 @@ def setup(): fill(0.0) # setup lights - directional_light((200 / 255, 200 / 255, 200 / 255), 4000.0, look_at=(-0.25, -0.25, 1)) # GAP: a light added in setup() does not light the shapes drawn in setup() - directional_light((200 / 255, 200 / 255, 200 / 255), 4000.0, look_at=(0.25, 0.25, -1)) # GAP: a light added in setup() does not light the shapes drawn in setup() + directional_light(200 / 255, look_at=(-0.25, -0.25, 1)) # GAP: a light added in setup() does not light the shapes drawn in setup() + directional_light(200 / 255, look_at=(0.25, 0.25, -1)) # GAP: a light added in setup() does not light the shapes drawn in setup() roughness(0.6) # GAP: no light_specular() / specular() / shininess(); roughness() stands in for lightSpecular(230, 230, 230), specular(color(200)), shininess(5.0) # setup view diff --git a/crates/processing_pyo3/examples/Generative Design/02_M/M_3_3_02/M_3_3_02.py b/crates/processing_pyo3/examples/Generative Design/02_M/M_3_3_02/M_3_3_02.py index e5920764..676a3da7 100644 --- a/crates/processing_pyo3/examples/Generative Design/02_M/M_3_3_02/M_3_3_02.py +++ b/crates/processing_pyo3/examples/Generative Design/02_M/M_3_3_02/M_3_3_02.py @@ -650,8 +650,8 @@ def setup(): fill(0.0) # setup lights - directional_light((200 / 255, 200 / 255, 200 / 255), 4000.0, look_at=(-0.0, -0.0, 1)) # GAP: a light added in setup() does not light the shapes drawn in setup() - directional_light((200 / 255, 200 / 255, 200 / 255), 4000.0, look_at=(0.0, 0.0, -1)) # GAP: a light added in setup() does not light the shapes drawn in setup() + directional_light(200 / 255, look_at=(-0.0, -0.0, 1)) # GAP: a light added in setup() does not light the shapes drawn in setup() + directional_light(200 / 255, look_at=(0.0, 0.0, -1)) # GAP: a light added in setup() does not light the shapes drawn in setup() roughness(0.6) # GAP: no light_specular() / specular() / shininess(); roughness() stands in for lightSpecular(230, 230, 230), specular(color(200)), shininess(5.0) # setup view diff --git a/crates/processing_pyo3/examples/Generative Design/02_M/M_3_3_03/M_3_3_03.py b/crates/processing_pyo3/examples/Generative Design/02_M/M_3_3_03/M_3_3_03.py index eebffff0..ba573630 100644 --- a/crates/processing_pyo3/examples/Generative Design/02_M/M_3_3_03/M_3_3_03.py +++ b/crates/processing_pyo3/examples/Generative Design/02_M/M_3_3_03/M_3_3_03.py @@ -650,7 +650,7 @@ def setup(): fill(0.0) # setup lights - directional_light((200 / 255, 200 / 255, 200 / 255), 4000.0, look_at=(0.5, 0.5, -1)) # GAP: a light added in setup() does not light the shapes drawn in setup() + directional_light(200 / 255, look_at=(0.5, 0.5, -1)) # GAP: a light added in setup() does not light the shapes drawn in setup() roughness(0.6) # GAP: no light_specular() / specular() / shininess(); roughness() stands in for lightSpecular(230, 230, 230), specular(color(200)), shininess(5.0) # setup view diff --git a/crates/processing_pyo3/examples/Generative Design/02_M/M_3_3_04/M_3_3_04.py b/crates/processing_pyo3/examples/Generative Design/02_M/M_3_3_04/M_3_3_04.py index 0695d601..6ee8564b 100644 --- a/crates/processing_pyo3/examples/Generative Design/02_M/M_3_3_04/M_3_3_04.py +++ b/crates/processing_pyo3/examples/Generative Design/02_M/M_3_3_04/M_3_3_04.py @@ -650,8 +650,8 @@ def setup(): fill(0.0) # setup lights - directional_light((200 / 255, 200 / 255, 200 / 255), 4000.0, look_at=(0.5, 0.5, -1)) # GAP: a light added in setup() does not light the shapes drawn in setup() - directional_light((200 / 255, 200 / 255, 200 / 255), 4000.0, look_at=(-0.5, -0.5, 1)) # GAP: a light added in setup() does not light the shapes drawn in setup() + directional_light(200 / 255, look_at=(0.5, 0.5, -1)) # GAP: a light added in setup() does not light the shapes drawn in setup() + directional_light(200 / 255, look_at=(-0.5, -0.5, 1)) # GAP: a light added in setup() does not light the shapes drawn in setup() roughness(0.6) # GAP: no light_specular() / specular() / shininess(); roughness() stands in for lightSpecular(230, 230, 230), specular(color(200)), shininess(5.0) # setup view diff --git a/crates/processing_pyo3/examples/Generative Design/02_M/M_3_4_01_TOOL/M_3_4_01_TOOL.py b/crates/processing_pyo3/examples/Generative Design/02_M/M_3_4_01_TOOL/M_3_4_01_TOOL.py index 387cc5d3..844b2820 100644 --- a/crates/processing_pyo3/examples/Generative Design/02_M/M_3_4_01_TOOL/M_3_4_01_TOOL.py +++ b/crates/processing_pyo3/examples/Generative Design/02_M/M_3_4_01_TOOL/M_3_4_01_TOOL.py @@ -726,7 +726,7 @@ def draw(): background(1.0) # Set lights - directional_light((1.0, 1.0, 1.0), 4000.0, look_at=(1, 1, -1)) + directional_light(1.0, look_at=(1, 1, -1)) roughness(1.0 - mesh_specular / 255 * 0.6) # GAP: no light_specular() / specular() / shininess(); roughness() stands in for lightSpecular(255, 255, 255), specular(meshSpecular, meshSpecular, meshSpecular), shininess(5.0) # ------ set view ------ diff --git a/crates/processing_pyo3/examples/Generative Design/02_M/M_3_4_03_TOOL/M_3_4_03_TOOL.py b/crates/processing_pyo3/examples/Generative Design/02_M/M_3_4_03_TOOL/M_3_4_03_TOOL.py index 395b0d36..5329e486 100644 --- a/crates/processing_pyo3/examples/Generative Design/02_M/M_3_4_03_TOOL/M_3_4_03_TOOL.py +++ b/crates/processing_pyo3/examples/Generative Design/02_M/M_3_4_03_TOOL/M_3_4_03_TOOL.py @@ -727,7 +727,7 @@ def draw(): background(1.0) # Set lights - directional_light((1.0, 1.0, 1.0), 4000.0, look_at=(1, 1, -1)) + directional_light(1.0, look_at=(1, 1, -1)) roughness(1.0 - mesh_specular / 255 * 0.6) # GAP: no light_specular() / specular() / shininess(); roughness() stands in for lightSpecular(255, 255, 255), specular(meshSpecular, meshSpecular, meshSpecular), shininess(5.0) # Set view diff --git a/crates/processing_pyo3/examples/Generative Design/02_M/M_3_5_01/M_3_5_01.py b/crates/processing_pyo3/examples/Generative Design/02_M/M_3_5_01/M_3_5_01.py index 698de299..a7c5919f 100644 --- a/crates/processing_pyo3/examples/Generative Design/02_M/M_3_5_01/M_3_5_01.py +++ b/crates/processing_pyo3/examples/Generative Design/02_M/M_3_5_01/M_3_5_01.py @@ -681,7 +681,7 @@ def draw(): background(1.0) # setup lights - directional_light((1.0, 1.0, 1.0), 4000.0, look_at=(1, 1, -1)) + directional_light(1.0, look_at=(1, 1, -1)) roughness(0.6) # GAP: no light_specular() / shininess(); roughness() stands in for lightSpecular(255, 255, 255), shininess(5.0) # setup view diff --git a/crates/processing_pyo3/examples/Topics/Geometry/icosahedra.py b/crates/processing_pyo3/examples/Topics/Geometry/icosahedra.py index aa3b448f..d2b7a64a 100644 --- a/crates/processing_pyo3/examples/Topics/Geometry/icosahedra.py +++ b/crates/processing_pyo3/examples/Topics/Geometry/icosahedra.py @@ -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) push_matrix() diff --git a/crates/processing_pyo3/examples/Topics/Geometry/shape_transform.py b/crates/processing_pyo3/examples/Topics/Geometry/shape_transform.py index b13a83dd..37cd4391 100644 --- a/crates/processing_pyo3/examples/Topics/Geometry/shape_transform.py +++ b/crates/processing_pyo3/examples/Topics/Geometry/shape_transform.py @@ -36,7 +36,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.67, 0.37, 0.37) fill(1.0, 0.78, 0.78) rotate_x(frame_count * angle_inc) diff --git a/crates/processing_pyo3/examples/Topics/Geometry/space_junk.py b/crates/processing_pyo3/examples/Topics/Geometry/space_junk.py index aa35927d..2e42f1cf 100644 --- a/crates/processing_pyo3/examples/Topics/Geometry/space_junk.py +++ b/crates/processing_pyo3/examples/Topics/Geometry/space_junk.py @@ -37,13 +37,13 @@ def draw(): fill(0.78) # Set up some different colored lights, in the original's top-left coordinates - point_light((0.2, 0.4, 1.0), 3000000000.0, 600.0, 1.0, + point_light((51, 102, 255), position=(65 - width / 2, 60 - height / 2, 100)) - point_light((0.78, 0.16, 0.24), 3000000000.0, 600.0, 1.0, + point_light((200, 40, 60), position=(-65 - width / 2, -60 - height / 2, -150)) # Raise overall light in scene - ambient_light(0.27, 0.27, 0.04) # GAP: ambient_light() + ambient_light((70, 70, 10)) # Center geometry in display windwow. # you can changlee 3rd argument ('0') diff --git a/crates/processing_pyo3/examples/Topics/Geometry/toroid.py b/crates/processing_pyo3/examples/Topics/Geometry/toroid.py index d87002b5..f6d16804 100644 --- a/crates/processing_pyo3/examples/Topics/Geometry/toroid.py +++ b/crates/processing_pyo3/examples/Topics/Geometry/toroid.py @@ -49,7 +49,7 @@ def setup(): def draw(): # basic lighting setup - directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0)) + lights() background(0.2, 0.25, 0.16) # 2 rendering styles # wireframe or solid diff --git a/crates/processing_pyo3/examples/Topics/Geometry/vertices.py b/crates/processing_pyo3/examples/Topics/Geometry/vertices.py index 27b97039..59b9de66 100644 --- a/crates/processing_pyo3/examples/Topics/Geometry/vertices.py +++ b/crates/processing_pyo3/examples/Topics/Geometry/vertices.py @@ -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) rotate_y(remap(mouse_x, 0, width, 0, PI)) rotate_z(remap(mouse_y, 0, height, 0, -PI)) diff --git a/crates/processing_pyo3/examples/Topics/Motion/cubes_within_cube.py b/crates/processing_pyo3/examples/Topics/Motion/cubes_within_cube.py index 79faef79..f14410e5 100644 --- a/crates/processing_pyo3/examples/Topics/Motion/cubes_within_cube.py +++ b/crates/processing_pyo3/examples/Topics/Motion/cubes_within_cube.py @@ -25,7 +25,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.2) # Center in display window diff --git a/crates/processing_pyo3/examples/Topics/Shaders/edge_filter.py b/crates/processing_pyo3/examples/Topics/Shaders/edge_filter.py index 6c4ec9f6..a6127192 100644 --- a/crates/processing_pyo3/examples/Topics/Shaders/edge_filter.py +++ b/crates/processing_pyo3/examples/Topics/Shaders/edge_filter.py @@ -19,7 +19,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) push_matrix() diff --git a/crates/processing_pyo3/examples/Topics/Shaders/toon_shading.py b/crates/processing_pyo3/examples/Topics/Shaders/toon_shading.py index 73ab111e..60682ef2 100644 --- a/crates/processing_pyo3/examples/Topics/Shaders/toon_shading.py +++ b/crates/processing_pyo3/examples/Topics/Shaders/toon_shading.py @@ -28,7 +28,7 @@ def draw(): dir_y = (mouse_y / height - 0.5) * 2 dir_x = (mouse_x / width - 0.5) * 2 # directionalLight(204, 204, 204, -dirX, -dirY, -1) - directional_light((0.8, 0.8, 0.8), 4000.0, look_at=(-dir_x, -dir_y, -1)) + directional_light(204, look_at=(-dir_x, -dir_y, -1)) if shader_enabled: # the custom material does not see the scene lights: pass the # direction toward the light as a uniform diff --git a/crates/processing_pyo3/examples/Topics/Simulate/gravitational_attraction_3d.py b/crates/processing_pyo3/examples/Topics/Simulate/gravitational_attraction_3d.py index 0ac63aa4..2620145e 100644 --- a/crates/processing_pyo3/examples/Topics/Simulate/gravitational_attraction_3d.py +++ b/crates/processing_pyo3/examples/Topics/Simulate/gravitational_attraction_3d.py @@ -36,7 +36,7 @@ def setup(): def draw(): global angle - directional_light((1.0, 1.0, 1.0), 4000.0, position=(0, 0, 1), look_at=(0, 0, 0)) + lights() background(0.0) # Setup the scene rotate_y(angle) diff --git a/crates/processing_pyo3/examples/camera_controllers.py b/crates/processing_pyo3/examples/camera_controllers.py index 977e699d..051e16f8 100644 --- a/crates/processing_pyo3/examples/camera_controllers.py +++ b/crates/processing_pyo3/examples/camera_controllers.py @@ -10,7 +10,7 @@ def setup(): mode_3d() orbit_camera() - dir_light = create_directional_light((1.0, 0.98, 0.95), 1500.0) + dir_light = create_directional_light((1.0, 0.98, 0.95), 0.5) dir_light.position(300.0, -400.0, 300.0) dir_light.look_at(0.0, 0.0, 0.0) diff --git a/crates/processing_pyo3/examples/flocking_duck.py b/crates/processing_pyo3/examples/flocking_duck.py index dd69dcd3..1f54e6a5 100644 --- a/crates/processing_pyo3/examples/flocking_duck.py +++ b/crates/processing_pyo3/examples/flocking_duck.py @@ -57,7 +57,7 @@ def setup(): size(900, 700) mode_3d() - sun = create_directional_light((0.95, 0.9, 0.85), 800.0) + sun = create_directional_light((0.95, 0.9, 0.85), 0.25) gltf = load_gltf("gltf/Duck.glb") duck = gltf.geometry("LOD3spShape") @@ -125,6 +125,7 @@ def draw(): camera_position(center[0] + cos(t) * r, center[1] - extent * 0.35, center[2] + sin(t) * r) camera_look_at(center[0], center[1], center[2]) background(10, 12, 18) + ambient_light(1.0, 0.04) light(sun) material(mat) diff --git a/crates/processing_pyo3/examples/flocking_gpu.py b/crates/processing_pyo3/examples/flocking_gpu.py index 834594a0..195f0a53 100644 --- a/crates/processing_pyo3/examples/flocking_gpu.py +++ b/crates/processing_pyo3/examples/flocking_gpu.py @@ -56,7 +56,7 @@ def setup(): window_title(f"GPU Flocking — {BOID_COUNT:,} boids") mode_3d() - sun = create_directional_light((0.95, 0.9, 0.85), 800.0) + sun = create_directional_light((0.95, 0.9, 0.85), 0.25) p = create_particles(BOID_COUNT) @@ -135,6 +135,7 @@ def draw(): camera_position(cos(t) * r, -BOUND * 0.8, sin(t) * r) camera_look_at(0.0, 0.0, 0.0) background(10, 12, 18) + ambient_light(1.0, 0.04) light(sun) flock() diff --git a/crates/processing_pyo3/examples/lights.py b/crates/processing_pyo3/examples/lights.py index 6c0412d7..10986bb7 100644 --- a/crates/processing_pyo3/examples/lights.py +++ b/crates/processing_pyo3/examples/lights.py @@ -12,19 +12,19 @@ def setup(): mode_3d() # Directional Light - dir_light = create_directional_light((0.5, 0.24, 1.0), 1500.0) + dir_light = create_directional_light((0.5, 0.24, 1.0), 0.5) # Point Lights - point_light_a = create_point_light((1.0, 0.5, 0.25), 1000000.0, 200.0, 0.5) + point_light_a = create_point_light((1.0, 0.5, 0.25), reach=60.0, range=200.0, radius=0.5) point_light_a.position(-25.0, -5.0, 51.0) point_light_a.look_at(0.0, 0.0, 0.0) - point_light_b = create_point_light((0.0, 0.5, 0.75), 2000000.0, 200.0, 0.25) + point_light_b = create_point_light((0.0, 0.5, 0.75), reach=60.0, range=200.0, radius=0.25) point_light_b.position(0.0, -5.0, 50.5) point_light_b.look_at(0.0, 0.0, 0.0) # Spot Light - spot_light_a = create_spot_light((0.25, 0.8, 0.19), 15.0 * 1000000.0, 200.0, 0.84, 0.0, 0.7854) + spot_light_a = create_spot_light((0.25, 0.8, 0.19), reach=80.0, range=200.0, radius=0.84, angle=PI / 4, softness=1.0) spot_light_a.position(40.0, 0.0, 70.0) spot_light_a.look_at(0.0, 0.0, 0.0) diff --git a/crates/processing_pyo3/examples/materials.py b/crates/processing_pyo3/examples/materials.py index 8a2dfdc7..703249cc 100644 --- a/crates/processing_pyo3/examples/materials.py +++ b/crates/processing_pyo3/examples/materials.py @@ -9,8 +9,8 @@ def setup(): size(800, 600) mode_3d() - dir_light = create_directional_light((1.0, 0.98, 0.95), 1500.0) - p_light = create_point_light((1.0, 1.0, 1.0), 100000.0, 800.0, 0.0) + dir_light = create_directional_light((1.0, 0.98, 0.95), 0.5) + p_light = create_point_light(1.0, 0.5, reach=500.0, range=800.0) p_light.position(200.0, -200.0, 400.0) mat = create_material( diff --git a/crates/processing_pyo3/examples/particles_animated.py b/crates/processing_pyo3/examples/particles_animated.py index c31b35ff..d5f5b6ce 100644 --- a/crates/processing_pyo3/examples/particles_animated.py +++ b/crates/processing_pyo3/examples/particles_animated.py @@ -13,7 +13,7 @@ def setup(): size(900, 700) mode_3d() - sun = create_directional_light((0.9, 0.85, 0.8), 300.0) + sun = create_directional_light((0.9, 0.85, 0.8), 0.1) sphere = Geometry.sphere(0.25, 12, 8) @@ -36,6 +36,7 @@ def draw(): camera_position(0.0, -8.0, 25.0) camera_look_at(0.0, 0.0, 0.0) background(15, 15, 20) + ambient_light(1.0, 0.04) light(sun) fill(230, 128, 75) diff --git a/crates/processing_pyo3/examples/particles_basic.py b/crates/processing_pyo3/examples/particles_basic.py index 4de0fe5b..d78948c1 100644 --- a/crates/processing_pyo3/examples/particles_basic.py +++ b/crates/processing_pyo3/examples/particles_basic.py @@ -12,7 +12,7 @@ def setup(): size(900, 700) mode_3d() - sun = create_directional_light((0.95, 0.9, 0.85), 600.0) + sun = create_directional_light((0.95, 0.9, 0.85), 0.2) source = Geometry.sphere(5.0, 32, 24) p = create_particles( @@ -37,6 +37,7 @@ def draw(): camera_position(0.0, -4.0, 18.0) camera_look_at(0.0, 0.0, 0.0) background(15, 15, 20) + ambient_light(1.0, 0.04) light(sun) material(mat) diff --git a/crates/processing_pyo3/examples/particles_emit_gpu.py b/crates/processing_pyo3/examples/particles_emit_gpu.py index 5c7e2972..ea7c25e5 100644 --- a/crates/processing_pyo3/examples/particles_emit_gpu.py +++ b/crates/processing_pyo3/examples/particles_emit_gpu.py @@ -22,7 +22,7 @@ def setup(): size(900, 700) mode_3d() - sun = create_directional_light((0.95, 0.9, 0.85), 800.0) + sun = create_directional_light((0.95, 0.9, 0.85), 0.25) particle = Geometry.sphere(0.12, 8, 6) @@ -51,6 +51,7 @@ def draw(): camera_position(0.0, -4.0, 16.0) camera_look_at(0.0, -2.0, 0.0) background(10, 10, 18) + ambient_light(1.0, 0.04) light(sun) material(mat) diff --git a/crates/processing_pyo3/examples/particles_from_mesh.py b/crates/processing_pyo3/examples/particles_from_mesh.py index c1df9bcd..cfaaa8e7 100644 --- a/crates/processing_pyo3/examples/particles_from_mesh.py +++ b/crates/processing_pyo3/examples/particles_from_mesh.py @@ -12,7 +12,7 @@ def setup(): size(900, 700) mode_3d() - sun = create_directional_light((0.95, 0.9, 0.85), 200.0) + sun = create_directional_light((0.95, 0.9, 0.85), 0.06) source = Geometry.sphere(5.0, 32, 24) p = create_particles( @@ -37,6 +37,7 @@ def draw(): camera_position(0.0, -4.0, 18.0) camera_look_at(0.0, 0.0, 0.0) background(15, 15, 20) + ambient_light(1.0, 0.04) light(sun) material(mat) diff --git a/crates/processing_pyo3/examples/particles_noise.py b/crates/processing_pyo3/examples/particles_noise.py index da0b827b..bc23e94a 100644 --- a/crates/processing_pyo3/examples/particles_noise.py +++ b/crates/processing_pyo3/examples/particles_noise.py @@ -13,7 +13,7 @@ def setup(): size(900, 700) mode_3d() - sun = create_directional_light((0.95, 0.9, 0.85), 200.0) + sun = create_directional_light((0.95, 0.9, 0.85), 0.06) source = Geometry.sphere(5.0, 32, 24) p = create_particles( @@ -39,6 +39,7 @@ def draw(): camera_position(0.0, -4.0, 18.0) camera_look_at(0.0, 0.0, 0.0) background(15, 15, 20) + ambient_light(1.0, 0.04) light(sun) material(mat) diff --git a/crates/processing_pyo3/examples/particles_stress.py b/crates/processing_pyo3/examples/particles_stress.py index 4e454abf..d160eb01 100644 --- a/crates/processing_pyo3/examples/particles_stress.py +++ b/crates/processing_pyo3/examples/particles_stress.py @@ -23,9 +23,9 @@ def setup(): camera_look_at(0.0, 0.0, 0.0) orbit_camera() - red_light = create_directional_light((1.0, 0.0, 0.0), 1000.0, position=Vec3.X, look_at=Vec3.ZERO) - green_light = create_directional_light((0.0, 1.0, 0.0), 1000.0, position=Vec3(0.0, -1.0, 0.0), look_at=Vec3.ZERO) - blue_light = create_directional_light((0.0, 0.0, 1.0), 1000.0, position=Vec3.Z, look_at=Vec3.ZERO) + red_light = create_directional_light((1.0, 0.0, 0.0), 0.3, position=Vec3.X, look_at=Vec3.ZERO) + green_light = create_directional_light((0.0, 1.0, 0.0), 0.3, position=Vec3(0.0, -1.0, 0.0), look_at=Vec3.ZERO) + blue_light = create_directional_light((0.0, 0.0, 1.0), 0.3, position=Vec3.Z, look_at=Vec3.ZERO) p = create_particles( Geometry.grid(GRID, GRID, GRID, SPACING), @@ -49,6 +49,7 @@ def setup(): def draw(): background(10, 10, 18) + ambient_light(1.0, 0.04) light(red_light) light(green_light) light(blue_light) diff --git a/crates/processing_pyo3/examples/primitives_3d.py b/crates/processing_pyo3/examples/primitives_3d.py index 63ad0350..c1d4b695 100644 --- a/crates/processing_pyo3/examples/primitives_3d.py +++ b/crates/processing_pyo3/examples/primitives_3d.py @@ -11,6 +11,7 @@ def draw(): camera_position(0, -80, 800) camera_look_at(0, 0, 0) background(15, 15, 20) + lights() fill(255) roughness(0.35) diff --git a/crates/processing_pyo3/examples/test_jupyter_3d.ipynb b/crates/processing_pyo3/examples/test_jupyter_3d.ipynb index 3d437846..2c964e86 100644 --- a/crates/processing_pyo3/examples/test_jupyter_3d.ipynb +++ b/crates/processing_pyo3/examples/test_jupyter_3d.ipynb @@ -22,7 +22,7 @@ "size(200, 100)\n", "mode_3d()\n", "\n", - "sun = create_directional_light((1.0, 0.98, 0.95), 1500.0)\n", + "sun = create_directional_light((1.0, 0.98, 0.95), 0.5)\n", "camera_position(0.0, 80.0, 200.0)\n", "camera_look_at(0.0, 0.0, 0.0)\n", "\n", diff --git a/crates/processing_pyo3/src/graphics.rs b/crates/processing_pyo3/src/graphics.rs index 8ada3759..55a479f1 100644 --- a/crates/processing_pyo3/src/graphics.rs +++ b/crates/processing_pyo3/src/graphics.rs @@ -2616,6 +2616,11 @@ impl Graphics { .map_err(|e| PyRuntimeError::new_err(format!("{e}"))) } + /// Draws that follow are not lit. + pub fn no_lights(&self) -> PyResult<()> { + self.unlit() + } + pub fn draw_geometry(&self, geometry: &Geometry) -> PyResult<()> { graphics_record_command(self.entity, DrawCommand::Geometry(geometry.entity)) .map_err(|e| PyRuntimeError::new_err(format!("{e}"))) @@ -3016,122 +3021,156 @@ impl Graphics { camera_reset(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}"))) } - /// Adds a directional light to this frame. - #[pyo3(signature = (color, illuminance, *, position=None, look_at=None))] + /// Adds a directional light to this frame; a strength of 1 lights a white surface facing it to white. + #[pyo3(signature = (color, strength=1.0, *, position=None, look_at=None))] pub fn directional_light( &self, - color: crate::color::ColorLike, - illuminance: f32, + color: &Bound<'_, PyAny>, + strength: f32, position: Option, look_at: Option, ) -> PyResult<()> { - let kind = LightKind::Directional { - color: color.into_color()?, - illuminance, - }; + let kind = LightKind::directional(self.light_color(color)?, strength); self.add_light(kind, position, look_at) } - /// Adds a point light to this frame. - #[pyo3(signature = (color, intensity, range, radius, *, position=None, look_at=None))] + /// Adds a point light to this frame; with a `reach` it dims with distance and has its strength at that distance. + #[pyo3(signature = (color, strength=1.0, *, position=None, look_at=None, reach=None, falloff=2.0, range=None, radius=0.0))] + #[allow(clippy::too_many_arguments)] pub fn point_light( &self, - color: crate::color::ColorLike, - intensity: f32, - range: f32, - radius: f32, + color: &Bound<'_, PyAny>, + strength: f32, position: Option, look_at: Option, + reach: Option, + falloff: f32, + range: Option, + radius: f32, ) -> PyResult<()> { - let kind = LightKind::Point { - color: color.into_color()?, - intensity, + let falloff = light::Falloff { + reach, + exponent: falloff, range, - radius, }; + let kind = LightKind::point(self.light_color(color)?, strength, falloff, radius); self.add_light(kind, position, look_at) } - /// Adds a spot light to this frame. - #[pyo3(signature = (color, intensity, range, radius, inner_angle, outer_angle, *, position=None, look_at=None))] + /// Adds a spot light to this frame; `angle` is from its axis to the edge of the cone. + #[pyo3(signature = (color, strength=1.0, *, angle=std::f32::consts::FRAC_PI_4, softness=0.15, position=None, look_at=None, reach=None, falloff=2.0, range=None, radius=0.0))] #[allow(clippy::too_many_arguments)] pub fn spot_light( &self, - color: crate::color::ColorLike, - intensity: f32, - range: f32, - radius: f32, - inner_angle: f32, - outer_angle: f32, + color: &Bound<'_, PyAny>, + strength: f32, + angle: f32, + softness: f32, position: Option, look_at: Option, + reach: Option, + falloff: f32, + range: Option, + radius: f32, ) -> PyResult<()> { - let kind = LightKind::Spot { - color: color.into_color()?, - intensity, + let falloff = light::Falloff { + reach, + exponent: falloff, range, - radius, - inner_angle, - outer_angle, }; + let kind = LightKind::spot( + self.light_color(color)?, + strength, + falloff, + radius, + angle, + softness, + ); self.add_light(kind, position, look_at) } + /// Adds light from every direction to this frame; a strength of 1 shows surfaces in their own color. + #[pyo3(signature = (color, strength=1.0))] + pub fn ambient_light(&self, color: &Bound<'_, PyAny>, strength: f32) -> PyResult<()> { + graphics_ambient_light(self.entity, self.light_color(color)?, strength) + .map_err(|e| PyRuntimeError::new_err(format!("{e}"))) + } + + /// Adds the default lighting to this frame: a gray ambient light and a light along the -z axis. + pub fn lights(&self) -> PyResult<()> { + graphics_lights(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}"))) + } + /// Creates a directional light. - #[pyo3(signature = (color, illuminance, *, position=None, look_at=None))] + #[pyo3(signature = (color, strength=1.0, *, position=None, look_at=None))] pub fn create_directional_light( &self, - color: crate::color::ColorLike, - illuminance: f32, + color: &Bound<'_, PyAny>, + strength: f32, position: Option, look_at: Option, ) -> PyResult { - let color = color.into_color()?; - let entity = light_create_directional(self.entity, color, illuminance) + let color = self.light_color(color)?; + let entity = light_create_directional(self.entity, color, strength) .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; Light::placed(entity, position, look_at) } /// Creates a point light. - #[pyo3(signature = (color, intensity, range, radius, *, position=None, look_at=None))] + #[pyo3(signature = (color, strength=1.0, *, position=None, look_at=None, reach=None, falloff=2.0, range=None, radius=0.0))] + #[allow(clippy::too_many_arguments)] pub fn create_point_light( &self, - color: crate::color::ColorLike, - intensity: f32, - range: f32, - radius: f32, + color: &Bound<'_, PyAny>, + strength: f32, position: Option, look_at: Option, + reach: Option, + falloff: f32, + range: Option, + radius: f32, ) -> PyResult { - let color = color.into_color()?; - let entity = light_create_point(self.entity, color, intensity, range, radius) + let color = self.light_color(color)?; + let falloff = light::Falloff { + reach, + exponent: falloff, + range, + }; + let entity = light_create_point(self.entity, color, strength, falloff, radius) .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; Light::placed(entity, position, look_at) } /// Creates a spot light. - #[pyo3(signature = (color, intensity, range, radius, inner_angle, outer_angle, *, position=None, look_at=None))] + #[pyo3(signature = (color, strength=1.0, *, angle=std::f32::consts::FRAC_PI_4, softness=0.15, position=None, look_at=None, reach=None, falloff=2.0, range=None, radius=0.0))] #[allow(clippy::too_many_arguments)] pub fn create_spot_light( &self, - color: crate::color::ColorLike, - intensity: f32, - range: f32, - radius: f32, - inner_angle: f32, - outer_angle: f32, + color: &Bound<'_, PyAny>, + strength: f32, + angle: f32, + softness: f32, position: Option, look_at: Option, + reach: Option, + falloff: f32, + range: Option, + radius: f32, ) -> PyResult { - let color = color.into_color()?; + let color = self.light_color(color)?; + let falloff = light::Falloff { + reach, + exponent: falloff, + range, + }; let entity = light_create_spot( self.entity, color, - intensity, - range, + strength, + falloff, radius, - inner_angle, - outer_angle, + angle, + softness, ) .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; Light::placed(entity, position, look_at) @@ -3194,6 +3233,20 @@ impl Graphics { } impl Graphics { + /// A light's color, written like the arguments of `fill()`; several channels go in a tuple. + fn light_color(&self, color: &Bound<'_, PyAny>) -> PyResult { + let args = match color.cast::() { + Ok(channels) => channels.clone(), + Err(_) => match color.cast::() { + Ok(channels) => channels.to_tuple(), + Err(_) => PyTuple::new(color.py(), [color])?, + }, + }; + let mode = graphics_get_color_mode(self.entity) + .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; + extract_color_with_mode(&args, &mode) + } + fn add_light( &self, kind: LightKind, diff --git a/crates/processing_pyo3/src/lib.rs b/crates/processing_pyo3/src/lib.rs index a89ef86b..b324e18f 100644 --- a/crates/processing_pyo3/src/lib.rs +++ b/crates/processing_pyo3/src/lib.rs @@ -2036,119 +2036,137 @@ pub mod processing_py { graphics!(module).light(&*light.extract::>()?) } - /// Adds a directional light to this frame. + /// Adds a directional light to this frame; a strength of 1 lights a white surface facing it to white. #[pyfunction] - #[pyo3(pass_module, signature = (color, illuminance, *, position=None, look_at=None))] + #[pyo3(pass_module, signature = (color, strength=1.0, *, position=None, look_at=None))] fn directional_light( module: &Bound<'_, PyModule>, - color: super::color::ColorLike, - illuminance: f32, + color: &Bound<'_, PyAny>, + strength: f32, position: Option, look_at: Option, ) -> PyResult<()> { - graphics!(module).directional_light(color, illuminance, position, look_at) + graphics!(module).directional_light(color, strength, position, look_at) } - /// Adds a point light to this frame. + /// Adds a point light to this frame; with a `reach` it dims with distance and has its strength at that distance. #[pyfunction] - #[pyo3(pass_module, signature = (color, intensity, range, radius, *, position=None, look_at=None))] + #[pyo3(pass_module, signature = (color, strength=1.0, *, position=None, look_at=None, reach=None, falloff=2.0, range=None, radius=0.0))] + #[allow(clippy::too_many_arguments)] fn point_light( module: &Bound<'_, PyModule>, - color: super::color::ColorLike, - intensity: f32, - range: f32, - radius: f32, + color: &Bound<'_, PyAny>, + strength: f32, position: Option, look_at: Option, + reach: Option, + falloff: f32, + range: Option, + radius: f32, ) -> PyResult<()> { - graphics!(module).point_light(color, intensity, range, radius, position, look_at) + graphics!(module).point_light( + color, strength, position, look_at, reach, falloff, range, radius, + ) } - /// Adds a spot light to this frame. + /// Adds a spot light to this frame; `angle` is from its axis to the edge of the cone. #[pyfunction] - #[pyo3(pass_module, signature = (color, intensity, range, radius, inner_angle, outer_angle, *, position=None, look_at=None))] + #[pyo3(pass_module, signature = (color, strength=1.0, *, angle=std::f32::consts::FRAC_PI_4, softness=0.15, position=None, look_at=None, reach=None, falloff=2.0, range=None, radius=0.0))] #[allow(clippy::too_many_arguments)] fn spot_light( module: &Bound<'_, PyModule>, - color: super::color::ColorLike, - intensity: f32, - range: f32, - radius: f32, - inner_angle: f32, - outer_angle: f32, + color: &Bound<'_, PyAny>, + strength: f32, + angle: f32, + softness: f32, position: Option, look_at: Option, + reach: Option, + falloff: f32, + range: Option, + radius: f32, ) -> PyResult<()> { graphics!(module).spot_light( - color, - intensity, - range, - radius, - inner_angle, - outer_angle, - position, - look_at, + color, strength, angle, softness, position, look_at, reach, falloff, range, radius, ) } - /// Creates a directional light. + /// Adds light from every direction to this frame; a strength of 1 shows surfaces in their own color. #[pyfunction] - #[pyo3(pass_module, signature = (color, illuminance, *, position=None, look_at=None))] + #[pyo3(pass_module, signature = (color, strength=1.0))] + fn ambient_light( + module: &Bound<'_, PyModule>, + color: &Bound<'_, PyAny>, + strength: f32, + ) -> PyResult<()> { + graphics!(module).ambient_light(color, strength) + } + + /// Adds the default lighting to this frame: a gray ambient light and a light along the -z axis. + #[pyfunction] + #[pyo3(pass_module)] + fn lights(module: &Bound<'_, PyModule>) -> PyResult<()> { + graphics!(module).lights() + } + + /// Creates a directional light; a strength of 1 lights a white surface facing it to white. + #[pyfunction] + #[pyo3(pass_module, signature = (color, strength=1.0, *, position=None, look_at=None))] fn create_directional_light( module: &Bound<'_, PyModule>, - color: super::color::ColorLike, - illuminance: f32, + color: &Bound<'_, PyAny>, + strength: f32, position: Option, look_at: Option, ) -> PyResult { get_graphics(module)? .ok_or_else(|| PyRuntimeError::new_err("call size() first"))? - .create_directional_light(color, illuminance, position, look_at) + .create_directional_light(color, strength, position, look_at) } - /// Creates a point light. + /// Creates a point light; with a `reach` it dims with distance and has its strength at that distance. #[pyfunction] - #[pyo3(pass_module, signature = (color, intensity, range, radius, *, position=None, look_at=None))] + #[pyo3(pass_module, signature = (color, strength=1.0, *, position=None, look_at=None, reach=None, falloff=2.0, range=None, radius=0.0))] + #[allow(clippy::too_many_arguments)] fn create_point_light( module: &Bound<'_, PyModule>, - color: super::color::ColorLike, - intensity: f32, - range: f32, - radius: f32, + color: &Bound<'_, PyAny>, + strength: f32, position: Option, look_at: Option, + reach: Option, + falloff: f32, + range: Option, + radius: f32, ) -> PyResult { get_graphics(module)? .ok_or_else(|| PyRuntimeError::new_err("call size() first"))? - .create_point_light(color, intensity, range, radius, position, look_at) + .create_point_light( + color, strength, position, look_at, reach, falloff, range, radius, + ) } - /// Creates a spot light. + /// Creates a spot light; `angle` is from its axis to the edge of the cone. #[pyfunction] - #[pyo3(pass_module, signature = (color, intensity, range, radius, inner_angle, outer_angle, *, position=None, look_at=None))] + #[pyo3(pass_module, signature = (color, strength=1.0, *, angle=std::f32::consts::FRAC_PI_4, softness=0.15, position=None, look_at=None, reach=None, falloff=2.0, range=None, radius=0.0))] #[allow(clippy::too_many_arguments)] fn create_spot_light( module: &Bound<'_, PyModule>, - color: super::color::ColorLike, - intensity: f32, - range: f32, - radius: f32, - inner_angle: f32, - outer_angle: f32, + color: &Bound<'_, PyAny>, + strength: f32, + angle: f32, + softness: f32, position: Option, look_at: Option, + reach: Option, + falloff: f32, + range: Option, + radius: f32, ) -> PyResult { get_graphics(module)? .ok_or_else(|| PyRuntimeError::new_err("call size() first"))? .create_spot_light( - color, - intensity, - range, - radius, - inner_angle, - outer_angle, - position, - look_at, + color, strength, angle, softness, position, look_at, reach, falloff, range, radius, ) } @@ -2485,6 +2503,12 @@ pub mod processing_py { graphics!(module).unlit() } + #[pyfunction] + #[pyo3(pass_module)] + fn no_lights(module: &Bound<'_, PyModule>) -> PyResult<()> { + graphics!(module).no_lights() + } + #[pyfunction] #[pyo3(pass_module)] fn ellipse(module: &Bound<'_, PyModule>, cx: f32, cy: f32, w: f32, h: f32) -> PyResult<()> { diff --git a/crates/processing_render/src/gltf.rs b/crates/processing_render/src/gltf.rs index bbe19100..8cd19fe9 100644 --- a/crates/processing_render/src/gltf.rs +++ b/crates/processing_render/src/gltf.rs @@ -469,6 +469,7 @@ fn scene_light_kind(world: &World, entity: Entity) -> Option { intensity: light.intensity, range: light.range, radius: light.radius, + falloff_exponent: light.falloff_exponent, }); } let light = world.get::(entity)?; @@ -477,6 +478,7 @@ fn scene_light_kind(world: &World, entity: Entity) -> Option { intensity: light.intensity, range: light.range, radius: light.radius, + falloff_exponent: light.falloff_exponent, inner_angle: light.inner_angle, outer_angle: light.outer_angle, }) diff --git a/crates/processing_render/src/graphics.rs b/crates/processing_render/src/graphics.rs index 235f1b14..e71dd122 100644 --- a/crates/processing_render/src/graphics.rs +++ b/crates/processing_render/src/graphics.rs @@ -48,7 +48,14 @@ impl Plugin for GraphicsPlugin { fn build(&self, app: &mut App) { app.init_resource::() .add_systems(First, crate::image::clear_background_blits) - .add_systems(PostUpdate, sync_to_surface); + .add_systems( + PostUpdate, + ( + sync_to_surface, + cluster_view_range + .before(bevy::light::SimulationLightSystems::AssignLightsToClusters), + ), + ); if let Some(render_app) = app.get_sub_app_mut(RenderApp) { render_app.add_systems( Render, @@ -352,6 +359,9 @@ pub fn create( dirty: None, }, )); + // no ambient light until a sketch asks for one + entity_commands.insert(crate::light::ambient(LinearRgba::BLACK, 0.0)); + entity_commands.insert(bevy::light::cluster::ClusterConfig::default()); if is_hdr { entity_commands.insert(Hdr); @@ -416,6 +426,24 @@ pub fn sync_to_surface( } } +/// Light clusters span the view's depth range; Bevy's default lags frames behind a new light. +fn cluster_view_range( + mut cameras: Query< + (&Projection, &mut bevy::light::cluster::ClusterConfig), + (Changed, With), + >, +) { + use bevy::light::cluster::{ClusterConfig, ClusterFarZMode}; + for (projection, mut config) in &mut cameras { + let far = ClusterFarZMode::Constant(projection.far()); + if let ClusterConfig::XYZ { z_config, .. } | ClusterConfig::FixedZ { z_config, .. } = + &mut *config + { + z_config.far_z_mode = far; + } + } +} + /// The view `mode_3d()` sets up for a canvas, which `camera()`, `perspective()` and `ortho()` /// fall back to for arguments left out. #[derive(Debug, Clone, Copy)] diff --git a/crates/processing_render/src/lib.rs b/crates/processing_render/src/lib.rs index 1cef2997..5b445ddb 100644 --- a/crates/processing_render/src/lib.rs +++ b/crates/processing_render/src/lib.rs @@ -1391,54 +1391,68 @@ pub fn image_destroy(entity: Entity) -> error::Result<()> { }) } +/// A strength of 1 lights a white matte surface facing the light to white. pub fn light_create_directional( graphics_entity: Entity, color: Color, - illuminance: f32, + strength: f32, ) -> error::Result { light_create( graphics_entity, - render::command::LightKind::Directional { color, illuminance }, + render::command::LightKind::directional(color, strength), ) } pub fn light_create_point( graphics_entity: Entity, color: Color, - intensity: f32, - range: f32, + strength: f32, + falloff: light::Falloff, radius: f32, ) -> error::Result { light_create( graphics_entity, - render::command::LightKind::Point { - color, - intensity, - range, - radius, - }, + render::command::LightKind::point(color, strength, falloff, radius), ) } pub fn light_create_spot( graphics_entity: Entity, color: Color, - intensity: f32, - range: f32, + strength: f32, + falloff: light::Falloff, radius: f32, - inner_angle: f32, - outer_angle: f32, + angle: f32, + softness: f32, ) -> error::Result { light_create( graphics_entity, - render::command::LightKind::Spot { - color, - intensity, - range, - radius, - inner_angle, - outer_angle, - }, + render::command::LightKind::spot(color, strength, falloff, radius, angle, softness), + ) +} + +/// Adds light from every direction to the frame; a strength of 1 shows surfaces in their own color. +pub fn graphics_ambient_light( + graphics_entity: Entity, + color: Color, + strength: f32, +) -> error::Result<()> { + graphics_record_command( + graphics_entity, + DrawCommand::AmbientLight { color, strength }, + ) +} + +/// Adds the default lighting to the frame: a gray ambient light and a light along the -z axis. +pub fn graphics_lights(graphics_entity: Entity) -> error::Result<()> { + // an edge-on face shows mid gray and a facing one white, like Processing's `lights()` + let ambient = Color::srgb_u8(128, 128, 128); + let direct = 1.0 - ambient.to_linear().red; + graphics_ambient_light(graphics_entity, ambient, 1.0)?; + graphics_immediate_light( + graphics_entity, + render::command::LightKind::directional(Color::WHITE, direct), + Transform::default().looking_to(Vec3::NEG_Z, Vec3::Y), ) } diff --git a/crates/processing_render/src/light.rs b/crates/processing_render/src/light.rs index 0c085d15..781e92c3 100644 --- a/crates/processing_render/src/light.rs +++ b/crates/processing_render/src/light.rs @@ -1,7 +1,13 @@ //! A light in Processing //! -use bevy::{camera::visibility::RenderLayers, math::Affine3A, prelude::*}; +use std::f32::consts::{FRAC_PI_2, PI}; + +use bevy::{ + camera::{Exposure, visibility::RenderLayers}, + math::Affine3A, + prelude::*, +}; use crate::{ error::ProcessingError, @@ -28,6 +34,108 @@ pub struct LightOf(pub Entity); #[relationship_target(relationship = LightOf, linked_spawn)] pub struct Lights(Vec); +/// Illuminance at which a white matte surface facing the light renders white. +fn full_illuminance() -> f32 { + PI / Exposure::default().exposure() +} + +/// Ambient brightness at which a white matte surface renders white. +fn full_ambient() -> f32 { + // Bevy's ambient term keeps this fraction of a matte surface's color + const AMBIENT_DIFFUSE: f32 = 0.4523; + 1.0 / (AMBIENT_DIFFUSE * Exposure::default().exposure()) +} + +/// Far enough that the range cut-off never shows. +const UNBOUNDED_RANGE: f32 = 1.0e6; + +/// How a point or spot light dims with distance. +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Falloff { + /// Distance at which the light has its stated strength; `None` is the same strength everywhere. + pub reach: Option, + /// With a `reach`, brightness goes as `1 / distance^exponent`; 2 is physical. + pub exponent: f32, + /// Distance past which the light does nothing; `None` is no cut-off. + pub range: Option, +} + +impl Default for Falloff { + fn default() -> Self { + Self { + reach: None, + exponent: 2.0, + range: None, + } + } +} + +impl Falloff { + /// The Bevy intensity, range and falloff exponent for a light of `strength`. + fn resolve(&self, strength: f32) -> (f32, f32, f32) { + let (exponent, at_reach) = match self.reach { + Some(reach) => (self.exponent, reach.max(0.0).powf(self.exponent)), + None => (0.0, 1.0), + }; + // Bevy spreads `intensity` over the sphere + let intensity = 4.0 * PI * full_illuminance() * strength * at_reach; + (intensity, self.range.unwrap_or(UNBOUNDED_RANGE), exponent) + } +} + +impl LightKind { + /// A strength of 1 lights a white matte surface facing the light to white. + pub fn directional(color: Color, strength: f32) -> Self { + Self::Directional { + color, + illuminance: full_illuminance() * strength, + } + } + + pub fn point(color: Color, strength: f32, falloff: Falloff, radius: f32) -> Self { + let (intensity, range, falloff_exponent) = falloff.resolve(strength); + Self::Point { + color, + intensity, + range, + radius, + falloff_exponent, + } + } + + /// `angle` is from the axis to the edge of the cone; `softness` fades that much of it. + pub fn spot( + color: Color, + strength: f32, + falloff: Falloff, + radius: f32, + angle: f32, + softness: f32, + ) -> Self { + let (intensity, range, falloff_exponent) = falloff.resolve(strength); + // Bevy's cone stops short of a half sphere + let outer_angle = angle.clamp(0.0, FRAC_PI_2 - 1.0e-3); + Self::Spot { + color, + intensity, + range, + radius, + falloff_exponent, + inner_angle: outer_angle * (1.0 - softness.clamp(0.0, 1.0)), + outer_angle, + } + } +} + +/// The Bevy ambient light for a color and strength. +pub fn ambient(color: LinearRgba, strength: f32) -> AmbientLight { + AmbientLight { + color: Color::LinearRgba(color), + brightness: full_ambient() * strength, + ..default() + } +} + /// Places a light's `Transform` with `matrix`. pub fn place(matrix: Affine3A, transform: &Transform) -> Transform { let position = matrix.transform_point3(transform.translation); @@ -58,12 +166,14 @@ pub(crate) fn spawn_bevy_light( intensity, range, radius, + falloff_exponent, } => { entity.insert(PointLight { color, intensity, range, radius, + falloff_exponent, ..default() }); } @@ -72,6 +182,7 @@ pub(crate) fn spawn_bevy_light( intensity, range, radius, + falloff_exponent, inner_angle, outer_angle, } => { @@ -80,6 +191,7 @@ pub(crate) fn spawn_bevy_light( intensity, range, radius, + falloff_exponent, inner_angle, outer_angle, ..default() @@ -145,6 +257,7 @@ mod tests { intensity: 1000.0, range: 10.0, radius: 0.0, + falloff_exponent: 2.0, }; fn create_light(world: &mut World, graphics: Entity, kind: LightKind) -> Entity { @@ -171,6 +284,118 @@ mod tests { .unwrap_or_default() } + /// Illuminance a Bevy point light gives a facing surface at `distance`. + fn point_illuminance(kind: LightKind, distance: f32) -> f32 { + let LightKind::Point { + intensity, + falloff_exponent, + .. + } = kind + else { + panic!("not a point light"); + }; + intensity / (4.0 * PI * distance.powf(falloff_exponent)) + } + + #[test] + fn full_strength_lights_white_to_white() { + // a matte surface reflects illuminance / pi, which exposure then scales + let exposure = Exposure::default().exposure(); + let LightKind::Directional { illuminance, .. } = LightKind::directional(Color::WHITE, 1.0) + else { + panic!("not a directional light"); + }; + assert!((illuminance / PI * exposure - 1.0).abs() < 1.0e-5); + + let half = LightKind::directional(Color::WHITE, 0.5); + let LightKind::Directional { illuminance, .. } = half else { + panic!("not a directional light"); + }; + assert!((illuminance / full_illuminance() - 0.5).abs() < 1.0e-5); + } + + #[test] + fn a_light_without_reach_does_not_dim() { + let light = LightKind::point(Color::WHITE, 0.5, Falloff::default(), 0.0); + for distance in [1.0, 100.0, 5000.0] { + let strength = point_illuminance(light, distance) / full_illuminance(); + assert!((strength - 0.5).abs() < 1.0e-4); + } + let LightKind::Point { range, .. } = light else { + panic!("not a point light"); + }; + assert_eq!(range, UNBOUNDED_RANGE); + } + + #[test] + fn reach_is_where_a_light_has_its_strength() { + let falloff = Falloff { + reach: Some(300.0), + ..default() + }; + let light = LightKind::point(Color::WHITE, 1.0, falloff, 0.0); + let at = |distance| point_illuminance(light, distance) / full_illuminance(); + assert!((at(300.0) - 1.0).abs() < 1.0e-4); + assert!((at(600.0) - 0.25).abs() < 1.0e-4); + + let linear = Falloff { + reach: Some(300.0), + exponent: 1.0, + range: Some(900.0), + }; + let light = LightKind::point(Color::WHITE, 1.0, linear, 0.0); + let at = |distance| point_illuminance(light, distance) / full_illuminance(); + assert!((at(300.0) - 1.0).abs() < 1.0e-4); + assert!((at(600.0) - 0.5).abs() < 1.0e-4); + let LightKind::Point { range, .. } = light else { + panic!("not a point light"); + }; + assert_eq!(range, 900.0); + } + + #[test] + fn spot_softness_fades_the_edge_of_the_cone() { + let spot = |angle, softness| { + let kind = LightKind::spot(Color::WHITE, 1.0, Falloff::default(), 0.0, angle, softness); + let LightKind::Spot { + inner_angle, + outer_angle, + .. + } = kind + else { + panic!("not a spot light"); + }; + (inner_angle, outer_angle) + }; + assert_eq!(spot(0.5, 0.0), (0.5, 0.5)); + assert_eq!(spot(0.5, 1.0), (0.0, 0.5)); + let (inner, outer) = spot(0.4, 0.25); + assert!((inner - 0.3).abs() < 1.0e-6 && outer == 0.4); + // Bevy's cone stops short of a half sphere + assert!(spot(PI, 0.0).1 < FRAC_PI_2); + } + + #[test] + fn full_ambient_lights_white_to_white() { + let light = ambient(LinearRgba::WHITE, 1.0); + let lit = light.brightness * 0.4523 * Exposure::default().exposure(); + assert!((lit - 1.0).abs() < 1.0e-5); + assert_eq!(ambient(LinearRgba::WHITE, 0.0).brightness, 0.0); + } + + #[test] + fn a_light_makes_the_draws_after_it_lit() { + use crate::render::material::MaterialKey; + + let mut state = RenderState::new(); + assert!(matches!(state.material_key(), MaterialKey::Color { .. })); + state.lit = true; + assert!(matches!(state.material_key(), MaterialKey::Pbr { .. })); + // the style itself is untouched, so the next frame starts unlit + state.begin_frame(); + assert!(matches!(state.material_key(), MaterialKey::Color { .. })); + } + #[test] fn each_light_spawns_a_bevy_light() { let mut world = World::new(); diff --git a/crates/processing_render/src/render/command.rs b/crates/processing_render/src/render/command.rs index 5187af8a..2aecb957 100644 --- a/crates/processing_render/src/render/command.rs +++ b/crates/processing_render/src/render/command.rs @@ -560,6 +560,7 @@ impl BlendMode { } } +/// A light in Bevy's physical units; `crate::light` builds these from strengths. #[derive(Debug, Clone, Copy)] pub enum LightKind { Directional { @@ -571,12 +572,14 @@ pub enum LightKind { intensity: f32, range: f32, radius: f32, + falloff_exponent: f32, }, Spot { color: Color, intensity: f32, range: f32, radius: f32, + falloff_exponent: f32, inner_angle: f32, outer_angle: f32, }, @@ -585,6 +588,10 @@ pub enum LightKind { #[derive(Debug, Clone)] pub enum DrawCommand { Light(Entity), + AmbientLight { + color: Color, + strength: f32, + }, BackgroundColor(Color), BackgroundImage(Entity), Fill(Color), diff --git a/crates/processing_render/src/render/mod.rs b/crates/processing_render/src/render/mod.rs index 354332f5..2b007942 100644 --- a/crates/processing_render/src/render/mod.rs +++ b/crates/processing_render/src/render/mod.rs @@ -188,6 +188,10 @@ pub struct RenderState { pub texture_mode: TextureMode, /// stroke weight is in world units instead of pixels pub stroke_perspective: bool, + /// this frame's ambient light, in linear color + pub ambient: Vec3, + /// a light was used this frame; the draws after it are lit + pub lit: bool, } impl RenderState { @@ -201,6 +205,8 @@ impl RenderState { shape_normal: None, texture_mode: TextureMode::default(), stroke_perspective: false, + ambient: Vec3::ZERO, + lit: false, } } @@ -212,6 +218,7 @@ impl RenderState { self.shape_normal = None; self.texture_mode = TextureMode::default(); self.stroke_perspective = false; + self.lit = false; } pub fn begin_frame(&mut self) { @@ -219,6 +226,16 @@ impl RenderState { self.style.clear_saved(); self.shape_builder = None; self.clear_depth = true; + self.ambient = Vec3::ZERO; + self.lit = false; + } + + /// The style's material, lit once a light has been used this frame. + pub fn material_key(&self) -> MaterialKey { + match &self.style.material_key { + key @ MaterialKey::Color { .. } if self.lit => key.as_pbr().into(), + key => key.clone(), + } } pub fn fill_is_transparent(&self) -> bool { @@ -342,6 +359,7 @@ pub fn flush_draw_commands( }; match cmd { DrawCommand::Light(entity) => { + state.lit = true; if let Ok((light, transform)) = p_lights.get(entity) { let placed = crate::light::place(state.transform.current(), transform); crate::light::spawn_bevy_light( @@ -353,6 +371,10 @@ pub fn flush_draw_commands( ); } } + DrawCommand::AmbientLight { color, strength } => { + state.lit = true; + state.ambient += color.to_linear().to_vec3() * strength; + } DrawCommand::Fill(color) => { state.style.fill = Fill::Color(color); } @@ -456,6 +478,7 @@ pub fn flush_draw_commands( } }, DrawCommand::Unlit => { + state.lit = false; state.style.material_key = state.style.material_key.as_unlit(); } DrawCommand::RectMode(mode) => { @@ -1193,11 +1216,7 @@ pub fn flush_draw_commands( }; let material_handle = if let Fill::Buffer(buf_entity) = state.style.fill { - match particles_fill_material( - &mut res, - buf_entity, - &state.style.material_key, - ) { + match particles_fill_material(&mut res, buf_entity, &state.material_key()) { Some(h) => h, None => { warn!("fill(buffer) entity {:?} not found", buf_entity); @@ -1584,6 +1603,11 @@ pub fn flush_draw_commands( flush_lines(&mut res, &mut batch); draws.pool.end(&mut res.commands); + let ambient = LinearRgba::from_vec3(state.ambient); + res.commands + .entity(graphics_entity) + .insert(crate::light::ambient(ambient, 1.0)); + // a pass cut short by a mid-frame `background()` is wiped by the next one, so it // must not reach the window camera.output_mode = if presents && drained { @@ -1868,11 +1892,7 @@ fn material_key_with_colors(state: &RenderState, colors: &[Color]) -> Option Option MaterialKey { let color = state.style.fill.color().unwrap_or(Color::WHITE); - let key = material_key_with_color(&state.style.material_key, color, state.style.blend_state); + let key = material_key_with_color(&state.material_key(), color, state.style.blend_state); styled(state, key) } @@ -2223,7 +2243,7 @@ fn draw_mesh3d( let (material, tag) = match color { None => (None, None), - Some(color) => match &state.style.material_key { + Some(color) => match &state.material_key() { MaterialKey::Custom { entity, .. } => { let Some(untyped) = material_handles.get(*entity).ok() else { warn!("Custom material entity {:?} not found", entity); diff --git a/crates/processing_wasm/src/lib.rs b/crates/processing_wasm/src/lib.rs index 672e3aed..88791ccd 100644 --- a/crates/processing_wasm/src/lib.rs +++ b/crates/processing_wasm/src/lib.rs @@ -1600,7 +1600,7 @@ pub fn js_light_create_directional( c3: f32, a: f32, space: u8, - illuminance: f32, + strength: f32, ) -> Result { let graphics_entity = Entity::from_bits(graphics_id); let color = Color { @@ -1612,7 +1612,7 @@ pub fn js_light_create_directional( }; 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()) } @@ -1625,8 +1625,10 @@ pub fn js_light_create_point( c3: f32, a: f32, space: u8, - intensity: f32, - range: f32, + strength: f32, + reach: Option, + falloff: f32, + range: Option, radius: f32, ) -> Result { let graphics_entity = Entity::from_bits(graphics_id); @@ -1642,8 +1644,12 @@ pub fn js_light_create_point( light_create_point( graphics_entity, color.resolve(&mode), - intensity, - range, + strength, + light::Falloff { + reach, + exponent: falloff, + range, + }, radius, ) })()) @@ -1658,11 +1664,13 @@ pub fn js_light_create_spot( c3: f32, a: f32, space: u8, - intensity: f32, - range: f32, + strength: f32, + reach: Option, + falloff: f32, + range: Option, radius: f32, - inner_angle: f32, - outer_angle: f32, + angle: f32, + softness: f32, ) -> Result { let graphics_entity = Entity::from_bits(graphics_id); let color = Color { @@ -1677,11 +1685,15 @@ pub fn js_light_create_spot( light_create_spot( graphics_entity, color.resolve(&mode), - intensity, - range, + strength, + light::Falloff { + reach, + exponent: falloff, + range, + }, radius, - inner_angle, - outer_angle, + angle, + softness, ) })()) .map(|e| e.to_bits()) diff --git a/docs/api.md b/docs/api.md index ef760330..d9fbbf5e 100644 --- a/docs/api.md +++ b/docs/api.md @@ -40,7 +40,17 @@ not guaranteed to be the same as a user-created image. `create_point_light` and `create_spot_light` return a `Light` that `light(l)` adds to the frame. Both use the current matrix. A `Light` belongs to the graphics that created it. -A light also lights shapes drawn before it in the frame, unless a flush (such as `filter`) came between them. +A light's strength is a plain number: at 1, a white matte surface facing a directional light renders white. The color +is separate, and strengths add up in linear light. `ambient_light` lights every surface evenly, and `lights()` is an +ambient light plus a directional light along the -z axis. There is no light until a sketch adds one. + +Point and spot lights are equally strong at every distance unless `reach` is given, which is the distance at which the +light has its stated strength; `falloff` is the exponent it dims by with distance (2 is physical) and `range` +cuts it off. A spot light's `angle` runs from its axis to the edge of the cone, and `softness` fades that much of it. + +Shapes drawn after a light in the frame are lit; `no_lights()` turns that off for the shapes that follow. A shape with +a material property set (such as `roughness`) is lit wherever it is drawn, also by lights that come later in the frame, +unless a flush (such as `filter`) came between them. ### Image diff --git a/examples/camera_controllers.rs b/examples/camera_controllers.rs index e49492df..900deb2f 100644 --- a/examples/camera_controllers.rs +++ b/examples/camera_controllers.rs @@ -31,7 +31,7 @@ fn sketch() -> error::Result<()> { graphics_orbit_camera(graphics)?; let dir_light = - light_create_directional(graphics, bevy::color::Color::srgb(1.0, 0.98, 0.95), 1_500.0)?; + light_create_directional(graphics, bevy::color::Color::srgb(1.0, 0.98, 0.95), 0.5)?; transform_set_position(dir_light, Vec3::new(300.0, -400.0, 300.0))?; transform_look_at(dir_light, Vec3::ZERO)?; diff --git a/examples/lights.rs b/examples/lights.rs index 657c849b..5db59213 100644 --- a/examples/lights.rs +++ b/examples/lights.rs @@ -2,6 +2,7 @@ use processing_glfw::GlfwContext; use bevy::math::Vec3; use processing::prelude::*; +use processing_render::light::Falloff; use processing_render::render::command::DrawCommand; fn main() { @@ -31,14 +32,18 @@ fn sketch() -> error::Result<()> { // create a directional light let dir_light = - light_create_directional(graphics, bevy::color::Color::srgb(0.35, 0.25, 0.5), 500.0)?; + light_create_directional(graphics, bevy::color::Color::srgb(0.35, 0.25, 0.5), 0.16)?; // create a point light let point_light_a = light_create_point( graphics, bevy::color::Color::srgb(1.0, 0.5, 0.25), - 1_000_000.0, - 200.0, + 1.0, + Falloff { + reach: Some(60.0), + range: Some(200.0), + ..default() + }, 0.5, )?; transform_set_position(point_light_a, Vec3::new(-25.0, -5.0, 51.0))?; @@ -48,8 +53,12 @@ fn sketch() -> error::Result<()> { let point_light_b = light_create_point( graphics, bevy::color::Color::srgb(0.0, 0.5, 0.75), - 2_000_000.0, - 200.0, + 1.0, + Falloff { + reach: Some(60.0), + range: Some(200.0), + ..default() + }, 0.25, )?; transform_set_position(point_light_b, Vec3::new(0.0, -5.0, 50.5))?; @@ -59,11 +68,15 @@ fn sketch() -> error::Result<()> { let spot_light = light_create_spot( graphics, bevy::color::Color::srgb(0.25, 0.8, 0.19), - 15.0 * 1_000_000.0, - 200.0, + 1.0, + Falloff { + reach: Some(80.0), + range: Some(200.0), + ..default() + }, 0.84, - 0.0, core::f32::consts::FRAC_PI_4, + 1.0, )?; transform_set_position(spot_light, Vec3::new(40.0, 0.0, 70.0))?; transform_look_at(spot_light, Vec3::new(0.0, 0.0, 0.0))?; diff --git a/examples/materials.rs b/examples/materials.rs index ecf01210..ed5f73e1 100644 --- a/examples/materials.rs +++ b/examples/materials.rs @@ -2,6 +2,7 @@ use processing_glfw::GlfwContext; use bevy::math::{Vec2, Vec3}; use processing::prelude::*; +use processing_render::light::Falloff; use processing_render::render::command::DrawCommand; fn main() { @@ -32,12 +33,21 @@ fn sketch() -> error::Result<()> { transform_look_at(graphics, Vec3::new(0.0, 0.0, 0.0))?; let dir_light = - light_create_directional(graphics, bevy::color::Color::srgb(1.0, 0.98, 0.95), 1_500.0)?; + light_create_directional(graphics, bevy::color::Color::srgb(1.0, 0.98, 0.95), 0.5)?; transform_set_position(dir_light, Vec3::new(300.0, -400.0, 300.0))?; transform_look_at(dir_light, Vec3::new(0.0, 0.0, 0.0))?; - let point_light = - light_create_point(graphics, bevy::color::Color::WHITE, 100_000.0, 800.0, 0.0)?; + let point_light = light_create_point( + graphics, + bevy::color::Color::WHITE, + 0.5, + Falloff { + reach: Some(500.0), + range: Some(800.0), + ..default() + }, + 0.0, + )?; transform_set_position(point_light, Vec3::new(200.0, -200.0, 400.0))?; // Grid of materials varying roughness (x) and metallic (y) diff --git a/examples/particles_animated.rs b/examples/particles_animated.rs index 6f5d1760..3014397e 100644 --- a/examples/particles_animated.rs +++ b/examples/particles_animated.rs @@ -44,8 +44,7 @@ fn sketch() -> error::Result<()> { transform_set_position(graphics, Vec3::new(0.0, -8.0, 25.0))?; transform_look_at(graphics, Vec3::new(0.0, 0.0, 0.0))?; - let light = - light_create_directional(graphics, bevy::color::Color::srgb(0.9, 0.85, 0.8), 300.0)?; + let light = light_create_directional(graphics, bevy::color::Color::srgb(0.9, 0.85, 0.8), 0.1)?; let sphere = geometry_sphere(0.25, 12, 8)?; @@ -76,6 +75,7 @@ fn sketch() -> error::Result<()> { while glfw_ctx.poll_events() { graphics_begin_draw(graphics)?; + graphics_ambient_light(graphics, bevy::color::Color::WHITE, 0.04)?; graphics_light(graphics, light)?; graphics_record_command( graphics, diff --git a/examples/particles_basic.rs b/examples/particles_basic.rs index 2a383fc8..56b6b005 100644 --- a/examples/particles_basic.rs +++ b/examples/particles_basic.rs @@ -20,8 +20,7 @@ fn sketch() -> error::Result<()> { transform_set_position(graphics, Vec3::new(0.0, 0.0, 25.0))?; transform_look_at(graphics, Vec3::new(0.0, 0.0, 0.0))?; - let light = - light_create_directional(graphics, bevy::color::Color::srgb(0.9, 0.85, 0.8), 300.0)?; + let light = light_create_directional(graphics, bevy::color::Color::srgb(0.9, 0.85, 0.8), 0.1)?; let sphere = geometry_sphere(0.25, 12, 8)?; @@ -49,6 +48,7 @@ fn sketch() -> error::Result<()> { while glfw_ctx.poll_events() { graphics_begin_draw(graphics)?; + graphics_ambient_light(graphics, bevy::color::Color::WHITE, 0.04)?; graphics_light(graphics, light)?; graphics_record_command( graphics, diff --git a/examples/particles_colored_pbr.rs b/examples/particles_colored_pbr.rs index 4b121be4..dadc9e3a 100644 --- a/examples/particles_colored_pbr.rs +++ b/examples/particles_colored_pbr.rs @@ -21,7 +21,7 @@ fn sketch() -> error::Result<()> { transform_look_at(graphics, Vec3::new(0.0, 0.0, 0.0))?; let light = - light_create_directional(graphics, bevy::color::Color::srgb(0.95, 0.9, 0.85), 200.0)?; + light_create_directional(graphics, bevy::color::Color::srgb(0.95, 0.9, 0.85), 0.06)?; let sphere = geometry_sphere(0.3, 16, 12)?; @@ -66,6 +66,7 @@ fn sketch() -> error::Result<()> { while glfw_ctx.poll_events() { graphics_begin_draw(graphics)?; + graphics_ambient_light(graphics, bevy::color::Color::WHITE, 0.04)?; graphics_light(graphics, light)?; graphics_record_command( graphics, diff --git a/examples/particles_emit_gpu.rs b/examples/particles_emit_gpu.rs index 743ec55d..a5b60221 100644 --- a/examples/particles_emit_gpu.rs +++ b/examples/particles_emit_gpu.rs @@ -131,7 +131,7 @@ fn sketch() -> error::Result<()> { transform_look_at(graphics, Vec3::new(0.0, -2.0, 0.0))?; let light = - light_create_directional(graphics, bevy::color::Color::srgb(0.95, 0.9, 0.85), 800.0)?; + light_create_directional(graphics, bevy::color::Color::srgb(0.95, 0.9, 0.85), 0.25)?; let particle = geometry_sphere(0.12, 8, 6)?; @@ -178,6 +178,7 @@ fn sketch() -> error::Result<()> { while glfw_ctx.poll_events() { graphics_begin_draw(graphics)?; + graphics_ambient_light(graphics, bevy::color::Color::WHITE, 0.04)?; graphics_light(graphics, light)?; graphics_record_command( graphics, diff --git a/examples/particles_from_mesh.rs b/examples/particles_from_mesh.rs index 13a88aac..5f847888 100644 --- a/examples/particles_from_mesh.rs +++ b/examples/particles_from_mesh.rs @@ -21,7 +21,7 @@ fn sketch() -> error::Result<()> { transform_look_at(graphics, Vec3::new(0.0, 0.0, 0.0))?; let light = - light_create_directional(graphics, bevy::color::Color::srgb(0.95, 0.9, 0.85), 200.0)?; + light_create_directional(graphics, bevy::color::Color::srgb(0.95, 0.9, 0.85), 0.06)?; let source = geometry_sphere(5.0, 32, 24)?; @@ -56,6 +56,7 @@ fn sketch() -> error::Result<()> { while glfw_ctx.poll_events() { graphics_begin_draw(graphics)?; + graphics_ambient_light(graphics, bevy::color::Color::WHITE, 0.04)?; graphics_light(graphics, light)?; graphics_record_command( graphics, diff --git a/examples/particles_noise.rs b/examples/particles_noise.rs index 9ab17126..4379d96f 100644 --- a/examples/particles_noise.rs +++ b/examples/particles_noise.rs @@ -21,7 +21,7 @@ fn sketch() -> error::Result<()> { transform_look_at(graphics, Vec3::new(0.0, 0.0, 0.0))?; let light = - light_create_directional(graphics, bevy::color::Color::srgb(0.95, 0.9, 0.85), 200.0)?; + light_create_directional(graphics, bevy::color::Color::srgb(0.95, 0.9, 0.85), 0.06)?; let source = geometry_sphere(5.0, 32, 24)?; let position_attr = geometry_attribute_position(); @@ -54,6 +54,7 @@ fn sketch() -> error::Result<()> { while glfw_ctx.poll_events() { graphics_begin_draw(graphics)?; + graphics_ambient_light(graphics, bevy::color::Color::WHITE, 0.04)?; graphics_light(graphics, light)?; graphics_record_command( graphics, diff --git a/examples/particles_oriented.rs b/examples/particles_oriented.rs index bdb784ec..b45b56a5 100644 --- a/examples/particles_oriented.rs +++ b/examples/particles_oriented.rs @@ -55,8 +55,7 @@ fn sketch() -> error::Result<()> { transform_set_position(graphics, Vec3::new(0.0, -6.0, 18.0))?; transform_look_at(graphics, Vec3::new(0.0, 0.0, 0.0))?; - let light = - light_create_directional(graphics, bevy::color::Color::srgb(0.9, 0.85, 0.8), 300.0)?; + let light = light_create_directional(graphics, bevy::color::Color::srgb(0.9, 0.85, 0.8), 0.1)?; let cube = geometry_box(0.6, 0.6, 0.6)?; @@ -113,6 +112,7 @@ fn sketch() -> error::Result<()> { while glfw_ctx.poll_events() { graphics_begin_draw(graphics)?; + graphics_ambient_light(graphics, bevy::color::Color::WHITE, 0.04)?; graphics_light(graphics, light)?; graphics_record_command( graphics, diff --git a/examples/particles_scatter.rs b/examples/particles_scatter.rs index f1b51961..503f60cc 100644 --- a/examples/particles_scatter.rs +++ b/examples/particles_scatter.rs @@ -50,8 +50,7 @@ fn sketch() -> error::Result<()> { transform_set_position(graphics, Vec3::new(0.0, -0.4, 4.5))?; transform_look_at(graphics, Vec3::ZERO)?; - let key = - light_create_directional(graphics, bevy::color::Color::srgb(1.0, 0.95, 0.85), 4500.0)?; + let key = light_create_directional(graphics, bevy::color::Color::srgb(1.0, 0.95, 0.85), 1.4)?; let source = geometry_sphere(1.2, 96, 48)?; let scatter = particles_scatter_create(source)?; @@ -86,6 +85,7 @@ fn sketch() -> error::Result<()> { while glfw_ctx.poll_events() { graphics_begin_draw(graphics)?; + graphics_ambient_light(graphics, bevy::color::Color::WHITE, 0.04)?; graphics_light(graphics, key)?; graphics_record_command( graphics, diff --git a/examples/particles_stress.rs b/examples/particles_stress.rs index 006c4902..cfd58f39 100644 --- a/examples/particles_stress.rs +++ b/examples/particles_stress.rs @@ -60,16 +60,15 @@ fn sketch() -> error::Result<()> { transform_look_at(graphics, Vec3::new(0.0, 0.0, 0.0))?; graphics_orbit_camera(graphics)?; - let red = light_create_directional(graphics, bevy::color::Color::srgb(1.0, 0.0, 0.0), 1000.0)?; + let red = light_create_directional(graphics, bevy::color::Color::srgb(1.0, 0.0, 0.0), 0.3)?; transform_set_position(red, Vec3::new(1.0, 0.0, 0.0))?; transform_look_at(red, Vec3::ZERO)?; - let green = - light_create_directional(graphics, bevy::color::Color::srgb(0.0, 1.0, 0.0), 1000.0)?; + let green = light_create_directional(graphics, bevy::color::Color::srgb(0.0, 1.0, 0.0), 0.3)?; transform_set_position(green, Vec3::new(0.0, -1.0, 0.0))?; transform_look_at(green, Vec3::ZERO)?; - let blue = light_create_directional(graphics, bevy::color::Color::srgb(0.0, 0.0, 1.0), 1000.0)?; + let blue = light_create_directional(graphics, bevy::color::Color::srgb(0.0, 0.0, 1.0), 0.3)?; transform_set_position(blue, Vec3::new(0.0, 0.0, 1.0))?; transform_look_at(blue, Vec3::ZERO)?; @@ -120,6 +119,7 @@ fn sketch() -> error::Result<()> { while glfw_ctx.poll_events() { graphics_begin_draw(graphics)?; + graphics_ambient_light(graphics, bevy::color::Color::WHITE, 0.04)?; graphics_light(graphics, red)?; graphics_light(graphics, green)?; graphics_light(graphics, blue)?; diff --git a/examples/pbr.rs b/examples/pbr.rs index af13268e..1b296625 100644 --- a/examples/pbr.rs +++ b/examples/pbr.rs @@ -2,6 +2,7 @@ use processing_glfw::GlfwContext; use bevy::math::{Vec2, Vec3}; use processing::prelude::*; +use processing_render::light::Falloff; use processing_render::render::command::DrawCommand; fn main() { @@ -31,12 +32,21 @@ fn sketch() -> error::Result<()> { transform_look_at(graphics, Vec3::new(0.0, 0.0, 0.0))?; let dir_light = - light_create_directional(graphics, bevy::color::Color::srgb(1.0, 0.98, 0.95), 1_500.0)?; + light_create_directional(graphics, bevy::color::Color::srgb(1.0, 0.98, 0.95), 0.5)?; transform_set_position(dir_light, Vec3::new(300.0, -400.0, 300.0))?; transform_look_at(dir_light, Vec3::new(0.0, 0.0, 0.0))?; - let point_light = - light_create_point(graphics, bevy::color::Color::WHITE, 100_000.0, 800.0, 0.0)?; + let point_light = light_create_point( + graphics, + bevy::color::Color::WHITE, + 0.5, + Falloff { + reach: Some(500.0), + range: Some(800.0), + ..default() + }, + 0.0, + )?; transform_set_position(point_light, Vec3::new(200.0, -200.0, 400.0))?; let cols = 11; diff --git a/examples/primitives_3d.rs b/examples/primitives_3d.rs index ceda4cd4..46519e51 100644 --- a/examples/primitives_3d.rs +++ b/examples/primitives_3d.rs @@ -20,8 +20,7 @@ fn sketch() -> error::Result<()> { transform_set_position(graphics, Vec3::new(0.0, -80.0, 800.0))?; transform_look_at(graphics, Vec3::new(0.0, 0.0, 0.0))?; - let light = - light_create_directional(graphics, bevy::color::Color::srgb(0.9, 0.85, 0.8), 300.0)?; + let light = light_create_directional(graphics, bevy::color::Color::srgb(0.9, 0.85, 0.8), 0.1)?; let pbr = material_create_pbr()?; material_set(pbr, "roughness", shader_value::ShaderValue::Float(0.35))?; diff --git a/examples/stroke_3d.rs b/examples/stroke_3d.rs index d2067946..b10f9fa4 100644 --- a/examples/stroke_3d.rs +++ b/examples/stroke_3d.rs @@ -20,8 +20,7 @@ fn sketch() -> error::Result<()> { transform_set_position(graphics, Vec3::new(200.0, -150.0, 350.0))?; transform_look_at(graphics, Vec3::new(0.0, 0.0, 0.0))?; - let light = - light_create_directional(graphics, bevy::color::Color::srgb(0.9, 0.85, 0.8), 800.0)?; + let light = light_create_directional(graphics, bevy::color::Color::srgb(0.9, 0.85, 0.8), 0.25)?; let mut angle: f32 = 0.0; diff --git a/examples/text_3d.rs b/examples/text_3d.rs index b4c82f25..bb79eea3 100644 --- a/examples/text_3d.rs +++ b/examples/text_3d.rs @@ -23,7 +23,7 @@ fn sketch() -> error::Result<()> { transform_look_at(graphics, Vec3::new(0.0, 0.0, 0.0))?; let dir_light = - light_create_directional(graphics, bevy::color::Color::srgb(0.3, 0.3, 0.4), 2000.0)?; + light_create_directional(graphics, bevy::color::Color::srgb(0.3, 0.3, 0.4), 0.65)?; transform_set_position(dir_light, Vec3::new(200.0, -300.0, 500.0))?; transform_look_at(dir_light, Vec3::new(0.0, 0.0, 0.0))?;