Quake 2 Realtime GPU Pathtracing

Raylgun

Supports all static and dynamic light types that were used in the original game, for which illumination was originally baked into static lightmaps.

All objects can cast shadows.

In terms of graphics API support, only OpenGL 3.3 is required.

Requires no offline pre-processing of input data, so any mod or level which works with Yamagi Quake 2 (which is a no-frills port) should work.

Still uses the rasterisation capabilities of the GPU anywhere that it makes sense.

All code modifications reside within the refresher (Quake 2's rendering subsystem) and the pathtracing codepath can be averted entirely at runtime without qualitative detriment to the original renderer's results.

Update Log



May 2020

Fixed a random number sampling precision bug.

June 2019

Fixed a bug which prevented correct random number sampling on AMD GPUs.

Fixed a couple of minor bugs.

August 2017

Improved sampling with blue noise dithering and Halton sequence sample points.

Added TAA (temporal anti-aliasing) using raytracing to detect disocclusions, rather than colour history or G-buffer data.

Added support for moving lightsources attached to level objects such as elevators.

Added bump mapping, with bumpmaps generated on start-up from diffuse texture brightness.

Added Simple Reinhard tonemapping with exposure control, and a gamma correction parameter.

Added specular reflections of light sources and indirect lighting.

The player's own weapon no longer casts shadows on the level geometry (it can still receive shadows, and it still casts shadows on itself).

Fixed a significant slowdown caused by GL buffer usage flags, in relation to dynamic entity lights.

Added more console variables.

Fixed numerous minor bugs.

August 2016

Initial release.

AMD FirePro W8100 49.3 fps NVIDIA Quadro K6000 32.8 fps GeForce GTX 960 31.1 fps AMD FirePro W7100 29.3 fps GeForce GTX 680 22.1 fps



Links



Out-dated Links



Console Commands



gl_pt_recompile_shaders Forces the shader programs to be recompiled. This is usually necessary after altering some aspect of the pathtracer via the console because some parameters are inserted into the shader source code itself. gl_pt_print_static_info Prints some pathtracing-related information about the current map. This information only pertains to things which are processed at map loading time.

Console Variables



Name Purpose Requires vid_restart Requires gl_pt_recompile_shaders gl_pt_enable Enables the pathtracing codepath. When this is set to zero, the original Quake 2 rendering is used and all other pathtracer settings are ignored. No No gl_pt_stats_enable Enables a continuous display of per-frame information. This is useful for finding out how well the pathtracer is performing. No No gl_pt_bounces The number of secondary bounces of light. A value of 0 means all illumination is direct. Note: The sky is not sampled by secondary bounces. No Yes gl_pt_shadow_samples The number of shadow rays to cast towards an individual lightsource. A higher number of shadow samples means less noise in shadows. Zero shadow samples means no shadows at all. No Yes gl_pt_light_samples The number of light samples to make. A higher number of light samples means less noise overall, but the shader must re-compute importance sampling weights for each light sample (since storing them in registers is prohibitively slow). Zero light samples means no light from explicitly-sampled lightsources. No Yes gl_pt_sky_enable Enables light emission from the sky. If this is disabled then the sky itself is still drawn, it just won't emit any light. No Yes gl_pt_sky_samples The number of BRDF-sampled rays to trace and test against skyportals. No Yes gl_pt_ao_enable Enables ambient occlusion No Yes gl_pt_ao_radius The ambient occlusion radius. No No gl_pt_ao_color The color of the ambient occlusion contribution. Note: This is a scalar value because Quake 2's console doesn't allow vector-valued variables. No No gl_pt_ao_samples The number of BRDF-sampled rays to trace for ambient occlusion. No Yes gl_pt_translucent_surfaces_enable Currently not used, but will be used to enable the application of pathtracing to translucent surfaces. No No gl_pt_lightstyles_enable Enables the use of lightstyles (animated colour and intensity of static entity lightsources). No No gl_pt_dlights_enable Enables the use of dlights (dynamic lightsources created at runtime by entities). No No gl_pt_brushmodel_shadows_enable Enables the casting of shadows by brushmodels (entities with rigid polygonal geometry defined by the BSP). No Yes gl_pt_aliasmodel_shadows_enable Enables the casting of shadows by aliasmodels (entities with deforming triangle mesh geometry defined by separate MD2 files). No Yes gl_pt_bounce_factor The scalar amount of absorption simulated at each surface-light interaction in secondary bounces. Has no effect if the number of bounces is zero. No No gl_pt_diffuse_map_enable Enables the modulation of light by the surface albedo maps (the original textures of Quake 2). No Yes gl_pt_static_entity_lights_enable Enables the creation of static entity lights when the map is loaded. These lights can be quite costly as for each one 4 triangular lightsources are created, arranged in a tetrahedron. Yes No gl_pt_depth_prepass_enable Enables a depth pre-pass which draws all entities into the depth buffer before pathtracing is performed. This eliminates overdraw (except for translucent surfaces) with minimal drawcall overhead so is recommended for improving performance. No No gl_pt_taa_enable Enables temporal anti-aliasing, which is a form of anti-aliasing which re-uses the previously-rendered frame and blends between them in a smart way. No Yes gl_pt_exposure Sets the exposure parameter for tone-mapping. Currently the tonemapping is Simple Reinhard only. No No gl_pt_gamma Sets the gamma exponent of the display. Gamma is applied after tonemapping but before TAA, due to engine limitations. No No gl_pt_bump_factor Sets strength of the bumpmapping effect. A higher value means more pronounced bumps. No No gl_pt_bump_enable Enables the bumpmapping effect. Bump maps are generated automatically from diffuse maps by interpreting diffuse pixel brightness as bump height. No Yes gl_pt_brushlights_enable Enables the casting of light from brushlights, which are those lights attached to moving level objects such as elevators and platforms. No No gl_pt_specular_factor Sets a factor adjusting the blending between pure diffuse and pure specular reflection. No No

This is a from-scratch GPU-based pathtracer created specifically for Quake 2. It has several optimisations which are only viable due to the typical characteristics of Quake 2 such as support for parallogram-shaped lightsources, BSP ray traversal, and special handling of sky 'surfaces' (portals). It doesn't officially have a name, but you can call itSam Lapere (of Ray Tracey fame) made a great post putting together a lot of my answers to his questions about this project, and also provided some useful tips on getting it running yourself. Sam is quite passionate about raytracing in videogames, be sure to check out his other posts and past projects.In 2019, a Vulkan-based renderer using NVIDIA RTX for hardware-accelerated raytracing was created for Quake 2 with a similar goal to this project. You can find out all about that project here . Judging by the About section of that page, my project which began in 2016 served as something of an inspiration for Q2VKPT.Here are some average framerate measurements as measured by Quake 2 itself along with the graphics hardware that was used: