Skip to content

Commit 6b30d04

Browse files
leifericfclaude
andcommitted
Add lighting gallery examples and update docs
Gallery: colored point lights scene, spotlight scene with hotspot/falloff. CHANGES.md: document all light types, multi-light, decay, spot cone. Docs: expand 3D Materials section with light types, multi-light examples. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 430e523 commit 6b30d04

3 files changed

Lines changed: 114 additions & 5 deletions

File tree

CHANGES.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,19 @@
3636
- Add `eido.ir.vary` with override descriptors (by-index, by-position, by-noise, by-gradient)
3737
- Generators accept vary descriptors in `:generator/overrides`
3838

39-
### 3D materials
39+
### 3D materials and lighting
4040

4141
- Add `eido.ir.material` with Blinn-Phong material descriptors (ambient, diffuse, specular, shininess)
42-
- Extend `scene3d/shade-face-style` to support `:material` key with specular highlights
43-
- Backward compatible — existing scenes without `:material` unchanged
42+
- Add four light types inspired by 3ds Max: directional, omni (point), spot, hemisphere (sky)
43+
- Light constructors: `material/directional`, `material/omni`, `material/spot`, `material/hemisphere`
44+
- Multi-light support: `:lights` vector on render-mesh opts, contributions sum per-channel
45+
- Light color tinting: each light's color modulates its diffuse and specular contribution
46+
- Distance decay: `:none`, `:inverse`, `:inverse-square` with configurable `:light/decay-start`
47+
- Spot light cone: `:light/hotspot` (inner angle) and `:light/falloff` (outer angle) with smoothstep
48+
- Hemisphere light: sky/ground color blended by surface normal direction
49+
- `smoothstep` added to `eido.math3d`
50+
- Extend `scene3d/shade-face-style` to support materials and multi-light
51+
- Backward compatible — existing scenes without `:material` or `:lights` unchanged
4452

4553
### Multi-pass rendering
4654

examples/gallery/scenes_3d.clj

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,75 @@
436436
:material (material/phong :specular 0.9 :shininess 256.0)}
437437
:light light})]}))
438438

439+
;; --- 17. Colored Point Lights ---
440+
441+
(defn ^{:example {:output "3d-colored-lights.png"
442+
:title "Colored Point Lights"
443+
:desc "A sphere lit by warm and cool omni lights with hemisphere ambient."}}
444+
colored-point-lights []
445+
(let [mesh (s3d/sphere-mesh 1.5 24 16)
446+
proj (s3d/perspective {:scale 120 :origin [200 200]
447+
:yaw 0.3 :pitch -0.25 :distance 6})]
448+
{:image/size [400 400]
449+
:image/background [:color/rgb 15 15 20]
450+
:image/nodes
451+
[(s3d/render-mesh proj mesh
452+
{:style {:style/fill [:color/rgb 200 200 200]
453+
:material (material/phong :ambient 0.05 :diffuse 0.8
454+
:specular 0.5 :shininess 48.0)}
455+
:lights [(material/omni [3 2 2]
456+
:color [:color/rgb 255 180 100]
457+
:multiplier 1.5
458+
:decay :inverse :decay-start 2.0)
459+
(material/omni [-3 1 -1]
460+
:color [:color/rgb 80 130 255]
461+
:multiplier 1.2
462+
:decay :inverse :decay-start 2.0)
463+
(material/hemisphere
464+
[:color/rgb 40 50 80]
465+
[:color/rgb 15 10 5]
466+
:multiplier 0.15)]})]}))
467+
468+
;; --- 18. Spotlight Scene ---
469+
470+
(defn ^{:example {:output "3d-spotlight.png"
471+
:title "Spotlight"
472+
:desc "A spot light with visible hotspot and falloff on a sphere and floor."}}
473+
spotlight-scene []
474+
(let [sphere (s3d/sphere-mesh 1.0 20 12)
475+
floor (s3d/cube-mesh [-3 -1.5 -3] 6)
476+
proj (s3d/perspective {:scale 80 :origin [200 220]
477+
:yaw 0.4 :pitch -0.35 :distance 8})]
478+
{:image/size [400 400]
479+
:image/background [:color/rgb 10 10 15]
480+
:image/nodes
481+
[(s3d/render-mesh proj
482+
(s3d/scale-mesh floor [1.0 0.05 1.0])
483+
{:style {:style/fill [:color/rgb 180 180 180]
484+
:material (material/phong :ambient 0.02 :diffuse 0.8 :specular 0.1)}
485+
:lights [(material/spot [0 8 0] [0 -1 0]
486+
:color [:color/rgb 255 240 200]
487+
:multiplier 2.0
488+
:hotspot 20 :falloff 30
489+
:decay :inverse :decay-start 3.0)
490+
(material/hemisphere
491+
[:color/rgb 20 25 40]
492+
[:color/rgb 5 5 5]
493+
:multiplier 0.1)]})
494+
(s3d/render-mesh proj sphere
495+
{:style {:style/fill [:color/rgb 200 60 60]
496+
:material (material/phong :ambient 0.02 :diffuse 0.7
497+
:specular 0.6 :shininess 64.0)}
498+
:lights [(material/spot [0 8 0] [0 -1 0]
499+
:color [:color/rgb 255 240 200]
500+
:multiplier 2.0
501+
:hotspot 20 :falloff 30
502+
:decay :inverse :decay-start 3.0)
503+
(material/hemisphere
504+
[:color/rgb 20 25 40]
505+
[:color/rgb 5 5 5]
506+
:multiplier 0.1)]})]}))
507+
439508
(comment
440509
;; Evaluate individual examples at the REPL:
441510
(utah-teapot)
@@ -453,4 +522,6 @@
453522
(wireframe-overlay)
454523
(specular-spheres)
455524
(glossy-torus)
456-
(material-showcase))
525+
(material-showcase)
526+
(colored-point-lights)
527+
(spotlight-scene))

examples/site/pages.clj

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,37 @@
727727
:shininess 32.0)}
728728
:light {:light/direction [1 2 1]
729729
:light/ambient 0.2
730-
:light/intensity 0.8}})"]]]}
730+
:light/intensity 0.8}})"]]
731+
[:h4 "Light Types"]
732+
[:pre [:code
733+
";; Directional — parallel rays (like the sun)
734+
(material/directional [1 2 1] :multiplier 0.8 :ambient 0.2)
735+
736+
;; Omni — point light radiating in all directions
737+
(material/omni [100 50 200]
738+
:color [:color/rgb 255 200 150]
739+
:decay :inverse-square :decay-start 10.0)
740+
741+
;; Spot — cone with hotspot/falloff angles
742+
(material/spot [0 200 0] [0 -1 0]
743+
:hotspot 25 :falloff 35 :decay :inverse)
744+
745+
;; Hemisphere — sky/ground ambient
746+
(material/hemisphere
747+
[:color/rgb 135 180 220] [:color/rgb 40 30 20]
748+
:multiplier 0.3)"]]
749+
[:h4 "Multi-Light"]
750+
[:p "Use " [:code ":lights"] " to combine multiple lights. Each light's color tints its contribution."]
751+
[:pre [:code
752+
"(s3d/render-mesh proj mesh
753+
{:style {:style/fill [:color/rgb 200 200 200]
754+
:material (material/phong :specular 0.5)}
755+
:lights [(material/omni [3 2 2]
756+
:color [:color/rgb 255 180 100]
757+
:multiplier 1.5 :decay :inverse)
758+
(material/hemisphere
759+
[:color/rgb 40 50 80] [:color/rgb 15 10 5]
760+
:multiplier 0.2)]})"]]]}
731761

732762
{:id "multi-pass"
733763
:title "Multi-Pass Rendering"

0 commit comments

Comments
 (0)