https://github.com/lisyarus/webgpu-raytracer Skip to content Navigation Menu Toggle navigation Sign in * Product + GitHub Copilot Write better code with AI + Security Find and fix vulnerabilities + Actions Automate any workflow + Codespaces Instant dev environments + Issues Plan and track work + Code Review Manage code changes + Discussions Collaborate outside of code + Code Search Find more, search less Explore + All features + Documentation + GitHub Skills + Blog * Solutions By company size + Enterprises + Small and medium teams + Startups By use case + DevSecOps + DevOps + CI/CD + View all use cases By industry + Healthcare + Financial services + Manufacturing + Government + View all industries View all solutions * Resources Topics + AI + DevOps + Security + Software Development + View all Explore + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners + Executive Insights * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Enterprise + Enterprise platform AI-powered developer platform Available add-ons + Advanced Security Enterprise-grade security features + GitHub Copilot Enterprise-grade AI features + Premium Support Enterprise-grade 24/7 support * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up Reseting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} lisyarus / webgpu-raytracer Public * Notifications You must be signed in to change notification settings * Fork 2 * Star 170 A software raytracing engine written in WebGPU 170 stars 2 forks Branches Tags Activity Star Notifications You must be signed in to change notification settings * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Security * Insights Additional navigation options * Code * Issues * Pull requests * Actions * Projects * Security * Insights lisyarus/webgpu-raytracer trunk BranchesTags [ ] Go to file Code Folders and files Name Name Last commit Last commit message date Latest commit History 81 Commits MikkTSpace @ MikkTSpace @ 3e895b4 3e895b4 cmake cmake env_maps env_maps glm @ 45008b2 glm @ 45008b2 include/ include/ webgpu-raytracer webgpu-raytracer rapidjson @ ab1842a rapidjson @ ab1842a screenshots screenshots shaders shaders source source stb @ ae721c5 stb @ ae721c5 test_scenes test_scenes .gitmodules .gitmodules CMakeLists.txt CMakeLists.txt readme.md readme.md stats.sh stats.sh View all files Repository files navigation * README [combined] See more screenshots in the screenshots directory. About This is a GPU "software" raytracer (i.e. using manual ray-scene intersections and not RTX) written using the WebGPU API. It expects a single glTF scene as input. It supports flat-colored and textured materials with albedo, normal, and material maps. It doesn't support refraction (yet). There are a bunch of test scenes in the test_scenes directory. It uses wgpu-native WebGPU implementation, and SDL2 to create a window to render to. Usage To run the program, first build it (see instructions below), then run it with a single glTF scene in the command arguments. For example, if you've built the project in a build directory inside the project root, then you can run ./webgpu-raytracer ../test_scenes/bunny/ bunny_100k.gltf. An optional second command-line parameter defines the background of the scene. It can either be an RGB comma-separated triple like 1,0.5,0.25, or path to an HDRI environment map. The env_maps directory contains some sample enrivonment maps. By default, a simple preview of the scene is rendered. Press [SPACE] to activate raytracing. Here are all the controls: * Mouse (while pressing left mouse button): rotate the camera * [Q][E]: roll the camera * [W][A][S][D]: move the camera * [LSHIFT][LCTRL]: speed up / slow down camera controls * [SPACE]: activate raytracing If the camera changes in raytracing mode, the raytracing result is discarded and the preview mode is activated again (i.e. there's no temporal reprojection in this case). Raytracer * The raytracer uses standard Monte-Carlo integration with multiple importance sampling, see the corresponding shader. * Fast ray-scene intersections are done using a BVH built with a simple surface-area heuristic at program start (see Jacco Bikker's amazing article series about this). * Raytracing uses multiple importance sampling (MIS) between several direction sampling strategies: cosine-weighted (good for diffuse materials), direct light sampling (good for rough materials), VNDF sampling (good for smooth materials), and transmission sampling (good for transparent materials). See also my article explaining how MIS works. * The material used is the standard glTF Cook-Torrance GGX with a thin-walled transmission as described by KHR_materials_transmission. * VNDF normals distribution is used to improve convergence. * Refractive materials are not supported. I tried to incorporate refractions into VNDF sampling but never managed to figure it out; this work resides in a separate vndf-refraction-wip branch. * NB: the use camera.wgsl; construct in the shaders is not standard WGSL, - instead, a rudimentary shader importing mechanism is implemented in this project. To-do list With no promises of implementing any of this, in no particular order: * Support environment maps & a fixed-color environment * Sample emissive triangles in proportion to area & intensity (probably using Vose alias method) * Support albedo, material & normal maps * Sample environment map pixels in proportion to intensity (using the same alias method) * Implement refraction + VNDF * Incorporate tinybvh and test different BVH variants for performance * Implement wavefront path-tracing * Support GLB input scenes Building To build this project, you need * CMake * SDL2 (you can probably install it via your system's package manager) * wgpu-native To install wgpu-native, download some release archive for your platform, and unpack it somewhere. This project was built with the v0.19.4.1 release, and might not work with older versions. Don't forget to check out submodules: * glm for vector & matrix maths * rapidjson for parsing glTF scenes * stb for loading images You can do this at clone time, using git clone --recurse-submodules. Add --shallow-submodules to prevent loading the whole commit history of those submodules. Otherwise, you can checkout submodules at any time after cloning the repo with git submodule update --init --recursive. Then, follow the usual steps for building something with CMake: * Create a build directory * In the build directory, run cmake -DWGPU_NATIVE_ROOT= * Build the project: cmake --build . SDL2-wgpu The include/webgpu-demo/sdl2_wgpu.h and source/sdl2_wgpu.c files implement a function WGPUSurface SDL_WGPU_CreateSurface(WGPUInstance, SDL_Window *) which creates a WebGPU surface from an SDL2 window, and should work on Linux (X11 and Wayland), Windows and MacOS. It is mostly based on glfw3webgpu. These files are almost standalone, and can be copied directly into your project, if you want to use WebGPU with SDL2. Note that the sdl2_wgpu.c file needs to be compiled as Objective-C for MacOS (add -x objective-c to compile flags for this file), and the QuartzCore framework needs to be linked with your application (add -framework QuartzCore to your linker flags). wgpu-native cmake find script The cmake/Findwgpu-native.cmake find script is also useful on its own, and can be used in other CMake-based projects. Simply add its location to CMAKE_MODULE_PATH, and call find_package(wgpu-native). It creates a wgpu-native imported library that can be simply linked to your executable via target_link_libraries (it sets up include directories automatically). About A software raytracing engine written in WebGPU Resources Readme Activity Stars 170 stars Watchers 4 watching Forks 2 forks Report repository Releases No releases published Packages 0 No packages published Languages * C++ 82.6% * WGSL 14.4% * C 1.9% * Other 1.1% Footer (c) 2024 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact * Manage cookies * Do not share my personal information You can't perform that action at this time.