Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
44e250f
a few small improvements
SimonDanisch Aug 14, 2024
e2d9df8
use structarrays
SimonDanisch Aug 14, 2024
2edc348
switch to memory pool
SimonDanisch Aug 15, 2024
9583282
switch to ubershader
SimonDanisch Aug 15, 2024
107d30c
small performance improvements
SimonDanisch Aug 15, 2024
018ffe8
fix bugs + perf improvements
SimonDanisch Aug 17, 2024
2ea38b3
make BSDFVector immutable
SimonDanisch Aug 17, 2024
f9baae3
fix sppm
SimonDanisch Aug 17, 2024
e22a231
remove atomics and switch to StructArrays for SPPM
SimonDanisch Aug 17, 2024
c7cd082
get rid of offset allocation
SimonDanisch Aug 18, 2024
57f7818
almost 0 allocations
SimonDanisch Aug 18, 2024
2711fdb
use immutables for SurfaceInteraction
SimonDanisch Aug 18, 2024
a153620
remove pool
SimonDanisch Aug 18, 2024
8f7032c
fix bugs and reclaim performance
SimonDanisch Aug 19, 2024
334c03d
fix camera, break examples, add TraceMakie prototype, add light types
SimonDanisch Aug 20, 2024
16e6c3e
clean up
SimonDanisch Aug 21, 2024
a82630e
small corrections
SimonDanisch Aug 21, 2024
2db9419
add tonemapping and scene
SimonDanisch Aug 21, 2024
a175b15
cleanup
SimonDanisch Aug 21, 2024
d760f40
make intersect!(bvh, ray) work on the GPU
SimonDanisch Aug 22, 2024
afef8f2
fix TraceMakie
SimonDanisch Aug 22, 2024
4c5d2a8
performance improvements
SimonDanisch Aug 23, 2024
7ff9fe3
fix more problematic gpu code
SimonDanisch Aug 23, 2024
eafbffe
some more fixes
SimonDanisch Aug 23, 2024
5fd24cb
add new test
SimonDanisch Aug 23, 2024
17b19ab
some f0
lazarusA Aug 24, 2024
a7dbff6
more f0, but splitting cos4 solves the pow metal issue
lazarusA Aug 24, 2024
2241e61
small improvements
SimonDanisch Aug 24, 2024
a2d6332
Merge branch 'sd/more-improvements' into la/pow_issue
SimonDanisch Aug 24, 2024
b935524
Merge pull request #30 from pxl-th/la/pow_issue
SimonDanisch Aug 24, 2024
f41cf0e
merge stashed changes
SimonDanisch Aug 24, 2024
4cdcce2
more fixes
SimonDanisch Aug 24, 2024
60ef870
better mapreduce
SimonDanisch Aug 24, 2024
c113489
make li(...) iterative (normal raytracing broken)
SimonDanisch Aug 24, 2024
4d78f46
fix iterative version
SimonDanisch Aug 25, 2024
89d6db7
merge
SimonDanisch Aug 25, 2024
2e06678
fix missaligned pointer
SimonDanisch Aug 25, 2024
ecb3f2d
integrate GPU version into Trace
SimonDanisch Aug 25, 2024
a164916
get film tile to work with KernelAbstraction
SimonDanisch Aug 30, 2024
faf5ad1
small improvements
SimonDanisch Aug 30, 2024
aeaa63c
a few improvements
SimonDanisch Sep 1, 2024
ba362c6
integrate film refactor + kernelabstractions
SimonDanisch Sep 13, 2024
876d9c8
changes for new GeometryBasics
SimonDanisch Mar 24, 2025
41cb00a
switch to RayCaster.jl
SimonDanisch Oct 22, 2025
fa8f2b6
try to get back performance
SimonDanisch Oct 22, 2025
710be08
more perf
SimonDanisch Oct 22, 2025
d4660e2
is it working
SimonDanisch Oct 27, 2025
3c82a16
clean up
SimonDanisch Oct 27, 2025
fe67d5b
fix sppm
SimonDanisch Oct 27, 2025
62b6727
fixes for Raycore
SimonDanisch Oct 30, 2025
6940f3e
gpu improvements and get things working again
SimonDanisch Dec 4, 2025
40fca57
improve performance a bit
SimonDanisch Dec 5, 2025
35c17fa
rename to hikari
SimonDanisch Dec 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
name = "Trace"
name = "Hikari"
uuid = "afc56b53-c9a9-482a-a956-d1d800e05558"
authors = ["Anton Smirnov <tonysmn97@gmail.com>"]
authors = ["Anton Smirnov <tonysmn97@gmail.com>", "Simon Danisch <sdanisch@proton.me>"]
version = "0.1.0"

[deps]
Atomix = "a9b6321e-bd34-4604-b9c9-b65b8de01458"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RandomNumbers = "e6cf234a-135c-5ec9-84dd-332b85af5143"
Raycore = "afc56b53-c9a9-482a-a956-d1d800e05559"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"

[compat]
#Atomix = "0.1.0"
FileIO = "1.16"
GeometryBasics = "0.4"
GeometryBasics = "0.4, 0.5"
ImageCore = "0.10"
ImageIO = "0.6"
#KernelAbstractions = "0.9.24"
ProgressMeter = "1.10"
StaticArrays = "1.9"
RandomNumbers = "1.6.0"
StaticArrays = "1.9.7"
StructArrays = "0.6.18"

[extras]
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "JET"]
7 changes: 6 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterVitepress = "4710194d-e776-4893-9690-8d956a29c365"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
ImageShow = "4e3cecfd-b093-5904-9786-8bbb286a6a31"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
Trace = "afc56b53-c9a9-482a-a956-d1d800e05558"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Metal = "dde4c033-4e86-420c-a63e-0dd931031962"
Hikari = "afc56b53-c9a9-482a-a956-d1d800e05558"

[compat]
Documenter = "1.5"
Expand Down
128 changes: 128 additions & 0 deletions docs/code/basic-scene.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using GeometryBasics
using Hikari
using FileIO
using ImageCore
using Raycore

# using BenchmarkTools
# using FileIO, ImageShow

function tmesh(prim, material)
prim = prim isa Sphere ? Tesselation(prim, 64) : prim
mesh = normal_mesh(prim)
m = Raycore.TriangleMesh(mesh)
return Hikari.GeometricPrimitive(m, material)
end

LowSphere(radius, contact=Point3f(0)) = Sphere(contact .+ Point3f(0, 0, radius), radius)

begin

material_red = Hikari.MatteMaterial(
Hikari.ConstantTexture(Hikari.RGBSpectrum(0.796f0, 0.235f0, 0.2f0)),
Hikari.ConstantTexture(0.0f0),
)
material_blue = Hikari.MatteMaterial(
Hikari.ConstantTexture(Hikari.RGBSpectrum(0.251f0, 0.388f0, 0.847f0)),
Hikari.ConstantTexture(0.0f0),
)
material_white = Hikari.MatteMaterial(
Hikari.ConstantTexture(Hikari.RGBSpectrum(1.0f0)),
Hikari.ConstantTexture(0.0f0),
)
mirror = Hikari.MirrorMaterial(Hikari.ConstantTexture(Hikari.RGBSpectrum(1.0f0)))
glass = Hikari.GlassMaterial(
Hikari.ConstantTexture(Hikari.RGBSpectrum(1.0f0)),
Hikari.ConstantTexture(Hikari.RGBSpectrum(1.0f0)),
Hikari.ConstantTexture(0.0f0),
Hikari.ConstantTexture(0.0f0),
Hikari.ConstantTexture(1.5f0),
true,
)

s1 = tmesh(LowSphere(0.5f0), material_white)
s2 = tmesh(LowSphere(0.3f0, Point3f(0.5, 0.5, 0)), material_white)
s3 = tmesh(LowSphere(0.3f0, Point3f(-0.5, 0.5, 0)), material_white)
s4 = tmesh(LowSphere(0.4f0, Point3f(0, 1.0, 0)), material_white)

ground = tmesh(Rect3f(Vec3f(-5, -5, 0), Vec3f(10, 10, 0.01)), material_white)
back = tmesh(Rect3f(Vec3f(-5, -3, 0), Vec3f(10, 0.01, 10)), material_white)
l = tmesh(Rect3f(Vec3f(-2, -5, 0), Vec3f(0.01, 10, 10)), material_white)
r = tmesh(Rect3f(Vec3f(2, -5, 0), Vec3f(0.01, 10, 10)), material_white)

bvh = Hikari.no_material_bvh([s1, s2, s3, s4, ground, back, l, r]);

lights = (
# Hikari.PointLight(Vec3f(0, -1, 2), Hikari.RGBSpectrum(22.0f0)),
Hikari.PointLight(Vec3f(0, 0, 2), Hikari.RGBSpectrum(10.0f0)),
# Hikari.PointLight(Vec3f(0, 3, 3), Hikari.RGBSpectrum(25.0f0)),
)
scene = Hikari.Scene([lights...], bvh);
resolution = Point2f(1024)
f = Hikari.LanczosSincFilter(Point2f(1.0f0), 3.0f0)

film = Hikari.Film(
resolution,
Hikari.Bounds2(Point2f(0.0f0), Point2f(1.0f0)),
f, 1.0f0, 1.0f0,
)
screen_window = Hikari.Bounds2(Point2f(-1), Point2f(1))
cam = Hikari.PerspectiveCamera(
Hikari.look_at(Point3f(0, 4, 2), Point3f(0, -4, -1), Vec3f(0, 0, 1)),
screen_window, 0.0f0, 1.0f0, 0.0f0, 1.0f6, 45.0f0, film,
)
end


# begin
# Hikari.clear!(film)
# integrator = Hikari.WhittedIntegrator(cam, Hikari.UniformSampler(8), 5)
# @time integrator(scene, film, cam)
# end
pres = []
using AMDGPU
g_scene = Hikari.to_gpu(ROCArray, scene; preserve=pres);
g_film = Hikari.to_gpu(ROCArray, film; preserve=pres);
integrator = Hikari.WhittedIntegrator(cam, Hikari.UniformSampler(8), 5)
integrator(g_scene, g_film, cam);
AMDGPU.@device_code_warntype interactive = true integrator(g_scene, g_film, cam);
@time integrator(scene, film, cam);
@time Hikari.integrator_threaded(integrator, scene, film, cam);


image = @btime (Hikari.integrator_threaded(integrator, scene, film, camera))

@code_warntype Hikari.integrator_threaded(integrator, scene, film, cam)
using OpenCL

cl_scene = Hikari.to_gpu(CLArray, scene)
cl_film = Hikari.to_gpu(CLArray, film);

@time integrator(cl_scene, cl_film, cam);
OpenCL.@device_code_warntype interactive = true integrator(cl_scene, cl_film, cam)
# Setup for profiling sample_kernel_inner!


# begin
# resolution = Point2f(1024)
# Hikari.clear!(film)
# @time render_scene(scene, film, cam)
# Hikari.to_framebuffer!(film, 1.0f0)
# film.framebuffer
# end


# 6.296157 seconds (17.64 k allocations: 19.796 MiB, 0.13% gc time, 45 lock conflicts)
# After more GPU optimizations
# 4.169616 seconds (17.37 k allocations: 19.777 MiB, 0.14% gc time, 20 lock conflicts)
# After first shading running on GPU
# 3.835527 seconds (17.36 k allocations: 19.779 MiB, 0.16% gc time, 41 lock conflicts)
# 4.191 s (4710 allocations: 18.36 MiB)
# iterative_li: 5.2s -.-


# begin
# integrator = Hikari.SPPMIntegrator(cam, 0.075f0, 5, 1)
# integrator(scene)
# img = reverse(film.framebuffer, dims=1)
# end
140 changes: 43 additions & 97 deletions docs/code/caustic_glass.jl
Original file line number Diff line number Diff line change
@@ -1,98 +1,44 @@
using GeometryBasics
using GeometryBasics, ImageShow
using LinearAlgebra
using Trace

function render()
glass = Trace.GlassMaterial(
Trace.ConstantTexture(Trace.RGBSpectrum(1f0)),
Trace.ConstantTexture(Trace.RGBSpectrum(1f0)),
Trace.ConstantTexture(0f0),
Trace.ConstantTexture(0f0),
Trace.ConstantTexture(1.25f0),
true,
)
plastic = Trace.PlasticMaterial(
Trace.ConstantTexture(Trace.RGBSpectrum(0.6399999857f0, 0.6399999857f0, 0.6399999857f0)),
Trace.ConstantTexture(Trace.RGBSpectrum(0.1000000015f0, 0.1000000015f0, 0.1000000015f0)),
Trace.ConstantTexture(0.010408001f0),
true,
)

model = "./scenes/models/caustic-glass.ply"
triangle_meshes, triangles = Trace.load_triangle_mesh(
model, Trace.ShapeCore(Trace.translate(Vec3f(5, -1.49, -100)), false),
)
floor_triangles = Trace.create_triangle_mesh(
Trace.ShapeCore(Trace.translate(Vec3f(-10, 0, -87)), false),
2, UInt32[1, 2, 3, 1, 4, 3],
4,
[
Point3f(0, 0, 0), Point3f(0, 0, -30),
Point3f(30, 0, -30), Point3f(30, 0, 0),
],
[
Trace.Normal3f(0, 1, 0), Trace.Normal3f(0, 1, 0),
Trace.Normal3f(0, 1, 0), Trace.Normal3f(0, 1, 0),
],
)

primitives = Vector{Trace.GeometricPrimitive}(undef, 0)
for t in triangles
push!(primitives, Trace.GeometricPrimitive(t, glass))
end
for t in floor_triangles
push!(primitives, Trace.GeometricPrimitive(t, plastic))
end

bvh = Trace.BVHAccel(primitives, 1)

from, to = Point3f(0, 2, 0), Point3f(-5, 0, 5)
cone_angle, cone_δ_angle = 30f0, 10f0
dir = normalize(Vec3f(to - from))
dir, du, dv = Trace.coordinate_system(dir)

dir_to_z = Trace.Transformation(transpose(Mat4f(
du[1], du[2], du[3], 0f0,
dv[1], dv[2], dv[3], 0f0,
dir[1], dir[2], dir[3], 0f0,
0f0, 0f0, 0f0, 1f0,
)))
light_to_world = (
Trace.translate(Vec3f(4.5, 0, -101))
* Trace.translate(Vec3f(from))
* inv(dir_to_z)
)

lights = [
Trace.SpotLight(
light_to_world, Trace.RGBSpectrum(60f0),
cone_angle, cone_angle - cone_δ_angle,
),
]

scene = Trace.Scene(lights, bvh)

resolution = Point2f(256)
n_samples = 8
ray_depth = 5

look_point = Point3f(-3, 0, -91)
screen = Trace.Bounds2(Point2f(-1f0), Point2f(1f0))
filter = Trace.LanczosSincFilter(Point2f(1f0), 3f0)

ir = Int64.(resolution)
film = Trace.Film(
resolution, Trace.Bounds2(Point2f(0), Point2f(1)),
filter, 1f0, 1f0,
"./scenes/caustics-sppm-$(ir[1])x$(ir[2]).png",
)
camera = Trace.PerspectiveCamera(
Trace.look_at(Point3f(0, 150, 150), look_point, Vec3f(0, 1, 0)),
screen, 0f0, 1f0, 0f0, 1f6, 90f0, film,
)

integrator = Trace.SPPMIntegrator(camera, 0.075f0, ray_depth, 100, -1)
integrator(scene)
end

render()
using Hikari, FileIO, MeshIO
using TraceMakie, GLMakie

model = load(joinpath(@__DIR__, "..", "..", "src", "assets", "models", "caustic-glass.ply"))

glass = Hikari.GlassMaterial(
Hikari.ConstantTexture(Hikari.RGBSpectrum(1f0)),
Hikari.ConstantTexture(Hikari.RGBSpectrum(1f0)),
Hikari.ConstantTexture(0f0),
Hikari.ConstantTexture(0f0),
Hikari.ConstantTexture(1.25f0),
true,
)
plastic = Hikari.PlasticMaterial(
Hikari.ConstantTexture(Hikari.RGBSpectrum(0.6399999857f0, 0.6399999857f0, 0.6399999857f0)),
Hikari.ConstantTexture(Hikari.RGBSpectrum(0.1000000015f0, 0.1000000015f0, 0.1000000015f0)),
Hikari.ConstantTexture(0.010408001f0),
true,
)

scene = Scene(size=(1024, 1024); lights=[
AmbientLight(RGBf(1, 1, 1)),
PointLight(Vec3f(4, 4, 10), RGBf(150, 150, 150)),
PointLight(Vec3f(-3, 10, 2.5), RGBf(60, 60, 60)),
PointLight(Vec3f(0, 3, 0.5), RGBf(40, 40, 40))
])

cam3d!(scene)
mesh!(scene, model, material=glass)
mini, maxi = extrema(Rect3f(decompose(Point, model)))
floorrect = Rect3f(Vec3f(-10, mini[2], -10), Vec3f(20, -1, 20))
mesh!(scene, floorrect, material=plastic)
center!(scene)
update_cam!(scene, Vec3f(-1.6, 6.2, 0.2), Vec3f(-3.6, 2.5, 2.4), Vec3f(0, 1, 0))

# Render with SPPM
img = TraceMakie.render_sppm(scene; search_radius=0.075f0, max_depth=5, iterations=100)

# Save the result
using Colors
image_01 = map(c -> mapc(x -> clamp(x, 0f0, 1f0), c), img)
save(joinpath(@__DIR__, "caustic_glass.png"), image_01)
Loading
Loading