Trace.jl icon indicating copy to clipboard operation
Trace.jl copied to clipboard

Performance improvements, GPU integration and prootype for Makie integration

Open SimonDanisch opened this issue 1 year ago • 1 comments

This makes Trace.jl 10-20x faster and prototypes a simple Makie integration. It also removes any allocations and dynamic dispatch to make the same code run on the GPU. Currently, the GPU version isn't much faster as the CPU though, which may require further experiments with the ray intersection implementation and removal of GPU performance traps.

using Trace, TraceMakie
begin
    model = load(joinpath(dirname(pathof(Trace)), "..", "docs", "src", "assets", "models", "caustic-glass.ply"))
    glass = Trace.GlassMaterial(
        Trace.ConstantTexture(Trace.RGBSpectrum(0.9f0)),
        Trace.ConstantTexture(Trace.RGBSpectrum(0.88f0)),
        Trace.ConstantTexture(0.0f0),
        Trace.ConstantTexture(0.0f0),
        Trace.ConstantTexture(1.4f0),
        true,
    )
    plastic = Trace.PlasticMaterial(
        Trace.ConstantTexture(Trace.RGBSpectrum(0.6399999857f0, 0.6399999857f0, 0.5399999857f0)),
        Trace.ConstantTexture(Trace.RGBSpectrum(0.1000000015f0, 0.1000000015f0, 0.1000000015f0)),
        Trace.ConstantTexture(0.010408001f0),
        true,
    )
    plastic_ceil = Trace.PlasticMaterial(
        Trace.ConstantTexture(Trace.RGBSpectrum(0.3399999857f0, 0.6399999857f0, 0.8399999857f0)),
        Trace.ConstantTexture(Trace.RGBSpectrum(1.4f0)),
        Trace.ConstantTexture(0.000408001f0),
        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)
    cm = scene.camera_controls
    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_ceil)
    ceiling = Rect3f(Vec3f(-25, 11, -25), Vec3f(50, -1, 50))
    mesh!(scene, ceiling, 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_interactive(scene, ArrayType; max_depth=5)
    TraceMakie.render_interactive(scene; backend=GLMakie, max_depth=5)
end

image

SimonDanisch avatar Oct 14 '24 11:10 SimonDanisch

+378,980 −1,668

This is one of the biggest PRs I have seen so far, 😄.

lazarusA avatar Oct 14 '24 16:10 lazarusA

Continued in https://github.com/JuliaGraphics/Trace.jl/pull/34

SimonDanisch avatar Nov 04 '25 11:11 SimonDanisch