Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements, GPU integration and prootype for Makie integration #33

Open
wants to merge 42 commits into
base: master
Choose a base branch
from

Conversation

SimonDanisch
Copy link
Collaborator

@SimonDanisch SimonDanisch commented Oct 14, 2024

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

@lazarusA
Copy link
Collaborator

+378,980 −1,668

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants