Skip to content

Commit a175b15

Browse files
committed
cleanup
1 parent 2db9419 commit a175b15

File tree

10 files changed

+375188
-61
lines changed

10 files changed

+375188
-61
lines changed

docs/code/TraceMakie.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function to_trace_primitive(plot::Makie.Surface)
7575
end
7676

7777
positions = lift(grid, x, y, z, Makie.transform_func_obs(plot))
78-
normals = Makie.surface_normals(x[], y[], z[])
78+
# normals = Makie.surface_normals(x[], y[], z[])
7979
r = Tesselation(Rect2f((0, 0), (1, 1)), size(z[]))
8080
# decomposing a rectangle into uv and triangles is what we need to map the z coordinates on
8181
# since the xyz data assumes the coordinates to have the same neighouring relations

docs/code/basic-scene.jl

Lines changed: 23 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -45,75 +45,42 @@ begin
4545
s1 = tmesh(LowSphere(0.5f0), material_white)
4646
s2 = tmesh(LowSphere(0.3f0, Point3f(0.5, 0.5, 0)), material_blue)
4747
s3 = tmesh(LowSphere(0.3f0, Point3f(-0.5, 0.5, 0)), mirror)
48-
s4 = tmesh(LowSphere(0.4f0, Point3f(0.0, 1.0, 0)), material_white)
49-
ground = tmesh(Rect3f(Vec3f(-5, -5, 0), Vec3f(10, 10, -0.1)), mirror)
50-
left = tmesh(Rect3f(Vec3f(-3, 0, 0), Vec3f(-0.1, 10, -0.1)), mirror)
48+
s4 = tmesh(LowSphere(0.4f0, Point3f(0, 1.0, 0)), glass)
5149

52-
bvh = Trace.BVHAccel([s1..., s2..., s3..., s4..., ground...], 1);
50+
ground = tmesh(Rect3f(Vec3f(-5, -5, 0), Vec3f(10, 10, 0.01)), mirror)
51+
back = tmesh(Rect3f(Vec3f(-5, -3, 0), Vec3f(10, 0.01, 10)), material_white)
52+
l = tmesh(Rect3f(Vec3f(-2, -5, 0), Vec3f(0.01, 10, 10)), material_red)
53+
r = tmesh(Rect3f(Vec3f(2, -5, 0), Vec3f(0.01, 10, 10)), material_blue)
54+
55+
bvh = Trace.BVHAccel([s1..., s2..., s3..., s4..., ground..., back..., l..., r...], 1);
5356

5457
lights = [
55-
Trace.PointLight(Vec3f(0, 2.5, 4), Trace.RGBSpectrum(60.0f0)),
56-
Trace.PointLight(Vec3f(-5, 2, 0), Trace.RGBSpectrum(60.0f0)),
58+
# Trace.PointLight(Vec3f(0, -1, 2), Trace.RGBSpectrum(22.0f0)),
59+
Trace.PointLight(Vec3f(0, 0, 2), Trace.RGBSpectrum(10.0f0)),
60+
Trace.PointLight(Vec3f(0, 3, 3), Trace.RGBSpectrum(15.0f0)),
5761
]
5862
scene = Trace.Scene(lights, bvh);
59-
resolution = Point2f(1024)
63+
resolution = Point2f(10)
6064
f = Trace.LanczosSincFilter(Point2f(1.0f0), 3.0f0)
6165
film = Trace.Film(resolution,
6266
Trace.Bounds2(Point2f(0.0f0), Point2f(1.0f0)),
6367
f, 1.0f0, 1.0f0,
6468
"shadows_sppm_res.png",
6569
)
6670
screen_window = Trace.Bounds2(Point2f(-1), Point2f(1))
67-
camera = Trace.PerspectiveCamera(
68-
Trace.look_at(Point3f(0, 3, 3), Point3f(0, 0, 0), Vec3f(0, 0, 1)),
71+
cam = Trace.PerspectiveCamera(
72+
Trace.look_at(Point3f(0, 4, 2), Point3f(0, -4, -1), Vec3f(0, 0, 1)),
6973
screen_window, 0.0f0, 1.0f0, 0.0f0, 1.0f6, 45.0f0, film,
7074
)
71-
integrator = Trace.WhittedIntegrator(camera, Trace.UniformSampler(8), 1)
72-
integrator(scene)
75+
76+
end
77+
begin
78+
integrator = Trace.WhittedIntegrator(cam, Trace.UniformSampler(8), 1)
79+
@time integrator(scene)
7380
img = reverse(film.framebuffer, dims=1)
7481
end
75-
x = Trace.scale(2, 2, 2)
76-
x.inv_m == inv(x.m)
77-
GLMakie.activate!(inline=true)
78-
# Computer projective camera transformations.
79-
resolution = Point2f(1024)
80-
resolution = Trace.scale(resolution[1], resolution[2], 1)
81-
82-
window_width = screen_window.p_max .- screen_window.p_min
83-
inv_bounds = Trace.scale((1.0f0 ./ window_width)..., 1)
84-
85-
offset = Trace.translate(Vec3f(
86-
-screen_window.p_min..., 0.0f0,
87-
))
88-
89-
ray = camera.core.raster_to_camera(Point3f(1024 / 2, 1024 / 2, 0))
90-
camera.core.screen_to_raster(camera.core.camera_to_screen(ray))
91-
92-
camera.core.screen_to_raster(Point3f(-1, -1, 0))
93-
camera.core.screen_to_raster(Point3f(1, 1, 0))
94-
95-
camera.core.raster_to_screen(Point3f(1024, 1024, 0))
96-
97-
camera.core.screen_to_raster(Point3f(-1, -1, 0))# == (0, 0, 0)
98-
camera.core.screen_to_raster(Point3f(1, 1, 0))# == (1024, 1024, 0)
99-
100-
camera.core.raster_to_screen(Point3f(0, 0, 0)) # == (0, 0, 0)
101-
camera.core.screen_to_raster(Point3f(1, 1, 0)) # == (1024, 1024, 0)
102-
103-
104-
res_t = Trace.scale(resolution..., 1)
105-
window_width = screen_window.p_max .- screen_window.p_min
106-
inv_bounds = Trace.scale((1f0 ./ window_width)..., 1)
107-
108-
offset = Trace.translate(Vec3f(
109-
(-screen_window.p_min)..., 0f0,
110-
))
111-
112-
inv(res_t.m)
113-
screen_to_raster = res_t * inv_bounds * offset
114-
115-
screen_to_raster(Point3f(1, 1, 0))
116-
117-
raster_to_screen = inv(offset) * inv(inv_bounds) * inv(res_t)
118-
119-
raster_to_screen(Point3f(1024, 1024, 0))
82+
# begin
83+
# integrator = Trace.SPPMIntegrator(cam, 0.075f0, 5, 100)
84+
# integrator(scene)
85+
# img = reverse(film.framebuffer, dims=1)
86+
# end

docs/code/dragon.jl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using Makie, Trace, ImageShow, Colors, FileIO, LinearAlgebra, GeometryBasics, GLMakie
2+
3+
glass = Trace.GlassMaterial(
4+
Trace.ConstantTexture(Trace.RGBSpectrum(1.0f0)),
5+
Trace.ConstantTexture(Trace.RGBSpectrum(1.0f0)),
6+
Trace.ConstantTexture(0.0f0),
7+
Trace.ConstantTexture(0.0f0),
8+
Trace.ConstantTexture(1.25f0),
9+
true,
10+
)
11+
mirror = Trace.MirrorMaterial(Trace.ConstantTexture(Trace.RGBSpectrum(1.0f0)))
12+
plastic = Trace.PlasticMaterial(
13+
Trace.ConstantTexture(Trace.RGBSpectrum(0.6399999857f0, 0.6399999857f0, 0.6399999857f0)),
14+
Trace.ConstantTexture(Trace.RGBSpectrum(0.1000000015f0, 0.1000000015f0, 0.1000000015f0)),
15+
Trace.ConstantTexture(0.010408001f0),
16+
true,
17+
)
18+
begin
19+
dragon = load(joinpath(@__DIR__, "dragon.obj"))
20+
scene = Scene(size=(1024, 1024); lights=[
21+
AmbientLight(RGBf(1, 1, 1)),
22+
PointLight(Vec3f(4, 4, 10), RGBf(150, 150, 150)),
23+
PointLight(Vec3f(-3, 10, 2.5), RGBf(60, 60, 60)),
24+
PointLight(Vec3f(0, 3, 0.5), RGBf(40, 40, 40))
25+
])
26+
cc = cam3d!(scene)
27+
points = dragon.position
28+
mini, maxi = extrema(points)
29+
sfactor = 1.0 / maximum(maxi .- mini)
30+
normed = map(points) do p
31+
n = (p .- mini) .* sfactor
32+
Point3f(n[1], n[3], n[2])
33+
end
34+
dragon.position .= normed
35+
fs = decompose(TriangleFace{Int}, dragon)
36+
fsi = reinterpret(Int, fs)
37+
bb = Rect3f(dragon.position[fsi])
38+
xmin, ymin, zmin = minimum(bb)
39+
mesh!(scene, dragon, material=glass)
40+
mesh!(scene, Rect3f(Vec3f(-2, -2, zmin), Vec3f(4, 4, 0.01)), material=plastic)
41+
update_cam!(scene, Vec3f(1.25, 1.08, 0.44), Vec3f(0.36, -0.22, -0.52), Vec3f(-0.29, -0.42, 0.85))
42+
img = render_scene(scene) do camera
43+
Trace.SPPMIntegrator(camera, 0.075f0, 5, 500)
44+
end
45+
# img = render_scene(scene)
46+
s = Scene(size=size(img))
47+
image!(s, rotr90(img), space=:pixel)
48+
display(s; scalefactor=1, px_per_unit=2)
49+
# scene
50+
end

0 commit comments

Comments
 (0)