Skip to content

Commit

Permalink
Merge pull request #58 from quephird/experimental_multiple_lights
Browse files Browse the repository at this point in the history
Support for multiple lights, including ones with a fade distance
  • Loading branch information
quephird committed Nov 29, 2023
2 parents 9da9c78 + ab271c0 commit 0f6717a
Show file tree
Hide file tree
Showing 34 changed files with 382 additions and 148 deletions.
10 changes: 5 additions & 5 deletions Examples/BallWithAreaLight/BallWithAreaLight.swift
Expand Up @@ -11,17 +11,17 @@ import ScintillaLib
@main
struct BallWithAreaLight: ScintillaApp {
var world: World = World {
AreaLight(corner: Point(-5, 5, -5),
uVec: Vector(2, 0, 0),
uSteps: 10,
vVec: Vector(0, 2, 0),
vSteps: 10)
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 2, -5),
to: Point(0, 1, 0),
up: Vector(0, 1, 0))
AreaLight(corner: Point(-5, 5, -5),
uVec: Vector(2, 0, 0),
uSteps: 10,
vVec: Vector(0, 2, 0),
vSteps: 10)
Sphere()
.translate(0, 1, 0)
.material(.solidColor(1, 0, 0))
Expand Down
2 changes: 1 addition & 1 deletion Examples/BarthSextic/BarthSextic.swift
Expand Up @@ -14,13 +14,13 @@ let φ: Double = 1.61833987
@main
struct BarthSextic: ScintillaApp {
var world: World = World {
PointLight(position: Point(-5, 5, -5))
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 0, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-5, 5, -5))
ImplicitSurface(center: (0.0, 0.0, 0.0), radius: 2.0) { x, y, z in
4.0*(φ*φ*x*x-y*y)*(φ*φ*y*y-z*z)*(φ*φ*z*z-x*x) - (1.0+2.0*φ)*(x*x+y*y+z*z-1.0)*(x*x+y*y+z*z-1.0)
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/Blob/Blob.swift
Expand Up @@ -12,13 +12,13 @@ import ScintillaLib
@main
struct Blob: ScintillaApp {
var world = World {
PointLight(position: Point(-10, 10, -10))
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 0, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
ImplicitSurface(bottomFrontLeft: (-2, -2, -2),
topBackRight: (2, 2, 2), { x, y, z in
x*x + y*y + z*z + sin(4*x) + sin(4*y) + sin(4*z) - 1.0
Expand Down
2 changes: 1 addition & 1 deletion Examples/Breather/Breather.swift
Expand Up @@ -26,13 +26,13 @@ func z(u: Double, v: Double) -> Double {
@main
struct Breather: ScintillaApp {
var world = World {
PointLight(position: Point(-10, 10, -10))
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 0, -15),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
ParametricSurface(bottomFrontLeft: (-8, -5, -5),
topBackRight: (8, 5, 5),
uRange: (-15, 15),
Expand Down
3 changes: 2 additions & 1 deletion Examples/Cavatappi/Cavatappi.swift
Expand Up @@ -12,13 +12,14 @@ import ScintillaLib
@main
struct Cavatappi: ScintillaApp {
var world = World {
PointLight(position: Point(-10, 10, -10))
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 7, -15),
to: Point(0, 7, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
PointLight(position: Point(10, 10, -10))
ParametricSurface(bottomFrontLeft: (-3.5, 0, -3.5),
topBackRight: (3.5, 15.0, 3.5),
uRange: (0, 2*PI),
Expand Down
2 changes: 1 addition & 1 deletion Examples/DecoCube/DecoCube.swift
Expand Up @@ -23,13 +23,13 @@ func decoCubeColor(_ x: Double, _ y: Double, _ z: Double) -> (Double, Double, Do
@main
struct DecoCube: ScintillaApp {
var world = World {
PointLight(position: Point(-10, 10, -10))
Camera(width: 600,
height: 600,
viewAngle: PI/3,
from: Point(2, 1, -6),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
ImplicitSurface(bottomFrontLeft: (-2.5, -2.5, -2.5),
topBackRight: (2.5, 2.5, 2.5), { x, y, z in
decoCubeShape(x, y, z)
Expand Down
2 changes: 1 addition & 1 deletion Examples/Die/Die.swift
Expand Up @@ -15,13 +15,13 @@ struct Die: ScintillaApp {
.reflective(0.2)

return World {
PointLight(position: Point(-10, 10, -10))
Camera(width: 800,
height: 600,
viewAngle: PI/3,
from: Point(0, 5, -10),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
Cube()
.material(orange)
.intersection {
Expand Down
27 changes: 27 additions & 0 deletions Examples/DimlyLitScene/DimlyLitScene.swift
@@ -0,0 +1,27 @@
//
// DimlyLitScene.swift
//
//
// Created by Danielle Kefford on 11/28/23.
//

import ScintillaLib

@available(macOS 12.0, *)
@main
struct DimlyLitScene: ScintillaApp {
var world = World {
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 0, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, 0),
fadeDistance: 10)
Sphere()
.material(.solidColor(1, 0.5, 0))
Plane()
.translate(0, -1, 0)
}
}
2 changes: 1 addition & 1 deletion Examples/HappyHalloween/HappyHalloween.swift
Expand Up @@ -24,13 +24,13 @@ func stem(x: Double, y: Double, z: Double) -> Double {
@main
struct HappyHalloween: ScintillaApp {
var world: World = World {
PointLight(position: Point(-2, 5, -5))
Camera(width: 600,
height: 600,
viewAngle: PI/3,
from: Point(0, 2, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-2, 5, -5))
ImplicitSurface(center: (0.0, 0.0, 0.0), radius: 2.0) { x, y, z in
pumpkin(x: x, y: y, z: z)
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/HollowedSphere/HollowedSphere.swift
Expand Up @@ -11,13 +11,13 @@ import ScintillaLib
@main
struct HollowedSphere: ScintillaApp {
var world = World {
PointLight(position: Point(-10, 10, -10))
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 1.5, -2),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
Sphere()
.material(.solidColor(0, 0, 1))
.intersection {
Expand Down
2 changes: 1 addition & 1 deletion Examples/Hourglass/Hourglass.swift
Expand Up @@ -12,13 +12,13 @@ import ScintillaLib
@main
struct Hourglass: ScintillaApp {
var world = World {
PointLight(position: Point(-10, 10, -10))
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 1, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
ParametricSurface(bottomFrontLeft: (-1.0, -1.0, -1.0),
topBackRight: (1.0, 1.0, 1.0),
uRange: (0, 2*PI),
Expand Down
2 changes: 1 addition & 1 deletion Examples/QuickStart/QuickStart.swift
Expand Up @@ -11,13 +11,13 @@ import ScintillaLib
@main
struct QuickStart: ScintillaApp {
var world = World {
PointLight(position: Point(-10, 10, -10))
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 2, -2),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
Sphere()
.material(.solidColor(1, 0, 0))
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/RainbowBall/RainbowBall.swift
Expand Up @@ -12,13 +12,13 @@ import ScintillaLib
@main
struct RainbowBall: ScintillaApp {
var world = World {
PointLight(position: Point(-10, 10, -10))
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 2, -2),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
Sphere()
.material(.colorFunction(.hsl) { x, y, z in
((atan2(z, x)+PI)/PI/2.0, 1.0, 0.5)
Expand Down
2 changes: 1 addition & 1 deletion Examples/Rings/Rings.swift
Expand Up @@ -12,13 +12,13 @@ import ScintillaLib
@main
struct Rings: ScintillaApp {
var world = World {
PointLight(position: Point(-10, 10, -10))
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(-10, 7, -10),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
ParametricSurface(bottomFrontLeft: (-6, -3, -6),
topBackRight: (6, 3, 6),
uRange: (0, 2*PI),
Expand Down
2 changes: 1 addition & 1 deletion Examples/StarPrism/StarPrism.swift
Expand Up @@ -11,13 +11,13 @@ import ScintillaLib
@main
struct StarPrism: ScintillaApp {
var world = World {
PointLight(position: Point(-5, 5, -5))
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 5, -5),
to: Point(0, 1, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-5, 5, -5))
Prism(bottomY: 0.0,
topY: 2.0,
xzPoints: [
Expand Down
2 changes: 1 addition & 1 deletion Examples/Superellipsoids/Superellipsoids.swift
Expand Up @@ -11,13 +11,13 @@ import ScintillaLib
@main
struct Superellipsoids: ScintillaApp {
var world: World = World {
PointLight(position: Point(0, 5, -5))
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 0, -12),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(0, 5, -5))
for (i, e) in [0.25, 0.5, 1.0, 2.0, 2.5].enumerated() {
for (j, n) in [0.25, 0.5, 1.0, 2.0, 2.5].enumerated() {
Superellipsoid(e: e, n: n)
Expand Down
2 changes: 1 addition & 1 deletion Examples/TDOR/TDOR.swift
Expand Up @@ -12,13 +12,13 @@ import ScintillaLib
@main
struct TDOR: ScintillaApp {
var world = World {
PointLight(position: Point(-10, 10, -10))
Camera(width: 600,
height: 600,
viewAngle: PI/3,
from: Point(0, 0, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
ImplicitSurface(bottomFrontLeft: (-0.5, 0.0, -0.5),
topBackRight: (0.5, 1.0, 0.5), { x, y, z in
pow(x, 2.0) + pow(z, 2.0) - pow(y, 3.0) + pow(y, 4.0)
Expand Down
2 changes: 1 addition & 1 deletion Examples/Vase/Vase.swift
Expand Up @@ -11,13 +11,13 @@ import ScintillaLib
@main
struct Vase: ScintillaApp {
var world = World {
PointLight(position: Point(-5, 5, -5))
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 7, -10),
to: Point(0, 2, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-5, 5, -5))
SurfaceOfRevolution(yzPoints: [(0.0, 2.0), (1.0, 2.0), (2.0, 1.0), (3.0, 0.5), (6.0, 0.5)])
.material(.solidColor(0.5, 0.6, 0.8))
Plane()
Expand Down
4 changes: 4 additions & 0 deletions Package.swift
Expand Up @@ -95,5 +95,9 @@ let package = Package(
name: "DecoCube",
dependencies: ["ScintillaLib"],
path: "Examples/DecoCube"),
.executableTarget(
name: "DimlyLitScene",
dependencies: ["ScintillaLib"],
path: "Examples/DimlyLitScene"),
]
)

0 comments on commit 0f6717a

Please sign in to comment.