Join the discussion
Write your take first — we'll ask for email only when you're ready to publish.
- Hacker News
- https://www.jsweet.org/examples/#Ray_tracer
Written in Java then transpiled to JavaScript, been around for years.
by knowhistory - The OP is real time ray tracing which is running between 30-60FPS on my macbook air while moving the camera and objects around.
Your link appears to be a basic ray tracer which anyone who has taken an intro to computer graphics course in college is likely required to implement and would only need a javascript canvas. To be honest I have no idea how much OPs real-time ray tracing differs in complexity from traditional ray tracing.
by nogridbag - runs on any GPU – even in the browser
Seems pretty clickbaity and dishonest when that's just what webgl and webgpu means. Just say webgpu.
Also the roughness doesn't apply to the environment map.
- I think you're getting lost in the weeds there. I do not see malice in the claim.
The irony is that it does not actually run on my GPU, nor much of other people's, judging by the comments. I don't know where people get this idea that WASM and WebGPU are the holy grail of portability; they are the opposite and the whole ecosystem is a fucking disaster. No offense to OP, though; I can understand the temptation to target that platform.
Anyway, I left more positive feedback in another comment.
by yunnpp - If you click into the code you can see that it depends on `wgpu`, which is a wrapper that uses whichever native API would be appropriate for the platform you're working with. If you run the native compiled version you won't be using WebGPU.by cptroot
- Dosent work in firefox, because of missing webgpu.by gunalx
- Works on mobile Firefox Nightlyby tormeh
- It does not run: "unreachable executed"by goodpoint
- Maybe your browser do not support webgpu. Try using Chrome.by tchauffi
- It looks cool, nice project.
Recommend taking a few minutes to make the web page work on mobile.
For example on iPhone the actual webgpu/ray tracing seems to work fine but html formatting is shoving things over to be barely visible.
by WhitneyLand - Thanks! It should work on mobile, you can hide the right panel using the button at the bottom of the screen. That said, performance on mobile is pretty limited because of hardware limitations.by tchauffi
- What feedback are you looking for here specifically?
I cannot run the demo on Firefox, but you might get better performance with an 8x4 thread group.
Also, mega-kernels of this sort are generally bad for occupancy. Wavefront path tracing improves this at the expense of additional IO and a more involved implementation. https://research.nvidia.com/publication/2013-07_megakernels-...
Overall your code looks easy to read. Too bad I couldn't run it.
by yunnpp - Very cool. Enjoyed playing with the "bounces" slider - it's fascinating how little improvement each additional bounce contributes after about 3 bounces. Severely diminishing returns in terms of the final image quality.by swiftcoder
- That's why virtually every renderer stochastically discards indirect paths with low contribution. Looking at the source code, this one computes every subsequent bounce, even those hitting the perfectly blue sphere after hitting the perfectly green one.by Maken
- Demonstrates how important it is to match the scenes with the rendering techniques. You can easily create a corridor with a light at one end that requires lots of bounces for the light to get to the end. But in a game you can just decide to not create that kind of scene. Cyberpunk 2077 basically has no rooms without direct light in them, which makes the game look good even without ray tracing.by tormeh
- In Safari 26 on an M1 with WebGPU enabled I get "InvalidStateError: GPUCommandEncoder.beginComputePass: Unable to begin compute pass."
In Chrome I get "Failed to start: Failed to create State. Caused by: failed to find GPU adapter."
So I guess it runs on "some" GPUs, in "some" browsers!
by skrrtww - Works fine on M4. M1 didn't have mesh shaders, maybe that's why?by iknowstuff
- works for me just fine on 26; i get
```
live_raytracer-bffaca82311af1dd.js:1484 Uncaught Error: Using exceptions for control flow, don't mind me. This isn't actually an error! at imports.wbg.__wbg_wbindgenthrow_451ec1a8469d7eb6 (
```
but everything else is fine
- And on M5 Safari 26, jacking the samples/pixel setting up high seems to trigger a system reboot, which is most curiousby pnm45678
- Why did you call the project rasterizer when it is not using rasterization but raytracing?by _bent
- Rasterization is just the process of converting an image to a raster, which you also have to do in raytracing. It does sound strange though.by SR2Z
- In Firefox, open about:config and set this to true: `dom.webgpu.enabled`.by eek2121
- In Safari < 26:
Settings... -> Advanced -> tick Show features for web developers
Settings... -> Feature Flags -> tick WebGPU*
by nomel