一款用 WebGPU 编写的软件光线追踪引擎
See more screenshots in the screenshots directory.
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).
Note that if the input model has UVs, they should be non-degenerate, as they are used to reconstruct tangents used for normal mapping (even if the model doesn't have a normal map).
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.
This project is licensed under the terms of the MIT license.
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 environment maps.
By default, a simple preview of the scene is rendered. Press [SPACE] to activate raytracing.
Here are all the controls:
[Q][E]: roll the camera[W][A][S][D][Z][X]: move the camera[LSHIFT][LCTRL]: speed up / slow down camera controls[SPACE]: activate raytracing[UP][DOWN]: change exposureIf 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).
vndf-refraction-wip branch.use camera.wgsl; construct in the shaders is not standard WGSL, - instead, a rudimentary shader importing mechanism is implemented in this project.With no promises of implementing any of this, in no particular order:
To build this project, you need
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:
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:
cmake -DWGPU_NATIVE_ROOT=cmake --build .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).
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).
暂无开放 Issues,或尚未同步最近议题。