This is my experiment on raytracing based on GPU.
It should obey the basic rules of raytracing, but is probably not the common practice, so be cautious when reading my codes.
- Install
pnpm - Run
pnpm i - Run
pnpm run dev
In the future, this part can be configured with JSON.
config_max_bounce: the max bounce time (recursion depth) of rays
gen_ray: prepare initial primary rays; for each pixel, generate one random rayhit_test: hit test for existing rays, calculate color contribution and new raysfilter: filter based on previous outputs to reduce noisesfilter: additional filter to reduce noises- to be added..
blit: blit result to screen
In one frame:
- gen ray for each pixel
- hit test for
config_max_bouncetimes - filter using previous frame's output (running average)
- blit to screen
-
NEVER use non-null assertion (!)
- If you are querying sth that may not exist, return
undefined. Callers should check the results properly. - If you are querying sth that must exist, throw an error. Do not let error propagate.
- If you are querying sth that may not exist, return
-
NEVER use
arrayLengthfunction in WGSL but explicitly pass length in or calculate on the fly, since array length is not necessarily equal to actual element count
Run pnpm run deploy.
- Add new changes on dev branch. Test whenever I can.
- When these changes are ready (a complete new feature / fix, etc.), switch to main branch and run
git merge --squash dev. - Deploy to github pages.
- Switch back to dev branch, run
git merge main. - Continue to add new things!
Do not need to write CHANGELOG, I will keep commit log of main branch clean. Sufficient for this personal project.