Quake II RTX

Quake II RTX

Not enough ratings
Quake II RTX PBR Pipeline
By NV_Tim
Learn how to set Material parameters, texture overrides and our recommended substance painter workflow for Quake II RTX.
Material System
The material parameters are driven from the file materials.csv (extract it from q2rtx_media.pkz - can open in Excel or another spreadsheet).

Material parameters and flags:

CSV columns:

Kind:​ special material types; possible values include:
  • CHROME is reflective polished metal. Reflective parts of the material are identified as those having roughness lower than 0.02. Albedo color affects the reflections and can be used to create colored metals such as copper.
  • GLASS is a thin transparent glass panel with bump mapping.
  • WATER is water surface with procedural wave animation. Water volumes simulate light scatter and look blue.
  • LAVA is lava surface with emissive texture and warping texture animation, like in original Quake 2.
  • SLIME is poisonous water: looks like water but has greenish scatter.
  • SCREEN is a reflective glass panel with emissive texture behind it, used for computer screens. Glass shader is applied to parts of the material having roughness lower than 0.02.
  • CAMERA is the same as SCREEN but replaces a part of the emissive texture with a live security camera view. The part of the texture to replace is hardcoded in the shaders and matches only a few materials that are used for certain monitors in the game.
  • INVISIBLE means objects with this material should not be rendered.
  • nothing which means regular material.

"Light flag”​: set to 1 if the texture is applied to a static light fixture that emits bright light. Tells the engine to treat as a static ​analytical light source - look at overrides/baselt_1 for an idea of what those are. Materials not marked with the light flag can still emit light, but the result will be more noisy, so that should only be applied to large and/or dim emissive surfaces.

“​Correct albedo​” flag: this one is important! Albedo exported out of Substance Painter is in sRGB space. Older textures are not, and the shader applies a correction function that we made up. ​IF THIS FLAG IS SET TO 1 (ON), THE ALBEDO IN GAME WILL BE BRIGHTER THAN WHAT YOU SEE IN SUBSTANCE​. The flag is ON for most of the materials in the materials.csv table shipped with Q2RTX – make sure to turn it OFF if you want to match what you are seeing in Substance. Unknown materials (textures referenced in the level file but not listed in the table) will ​not ​have this flag set.

“​Roughness override​”​: provides a minimum roughness value for the material roughness channel (useful to test for noise or replace a texture that we do not have the time to paint)

Look at the lines under develop/objects/ShaderBallArray/ for reference:

(note: “correct albedo” flag is set to 0 !)

Material rows are dictated by unique texture paths in the game. If you are adding new materials, make sure to keep the file sorted by texture path; otherwise, the engine will complain.
Texture Overrides
The game engine uses a fairly complex system of search paths to allow mods to override textures in the game. Since we cannot modify texture file-paths in level files, the search path is resolved at run-time based on the original file names.

Vanilla Quake II supports only 2 file formats: .pcx and .wal. The TGA, JPG and PNG formats were later additions.

The engine follows the following pattern to resolve overrides:
  • Search for the file basename in the ​baseq2/overrides/<basename>.<extension>
    in the following order for extensions: .png, .jpg, .tga, .pcx, .wal

  • Search for the file basename in custom .pak and .pkz archive files (​baseq2/*.pak/overrides/<basename>.<extension>​ ) in descending order
    in the following order for extensions: .png, .jpg, .tga, .pcx, .wal
    (note : we are not altering original pak files)

  • Search for the full file-path in the ​baseq2/<file-path>/<basename>.<extension>​ folder
    in the following order for extensions: .png, .jpg, .tga, .pcx, .wal

  • Search for the full file-path in .pak and .pkz archive files (​baseq2/*.pak/<file-path>/<basename>.<extension>​ ) in descending order in the following order for extensions: .png, .jpg, .tga, .pcx, .wal
    (note: we are not altering original pak files)

You can verify texture paths & overrides with the on-screen display at run-time with some ​console commands.
Substance Painter Workflow
For more information on Substance’s BRDF & materials : https://www.substance3d.com/system/files/software/download/build/PBR_Guide_Vol.1.pdf​.

Quake II RTX baseline for material BRDF has been matched as best as possible against a test palette created with Substance Painter.

The reference palette can be spawned in the game with the following:

  • Open the console with ~
  • Type : ​cl_shaderballs 1​ (note: tab auto-completes)
  • Reload the map : ​gamemap base1​ (or any other map)
  • (shader balls will be at the world origin, wherever that is in the map)
  • You can move the shaderballs to your current location with:​ ​drop_balls (combine with ​noclip​ to move around freely)

Some materials work better than others: avoid what doesn’t work well and see the material system section for details & limitations.

Note​: the material balls are not shipped with regular builds of the game. Download the “shader_balls.pkz” package from the ​GitHub Releases​ page[github.com] and put it into the baseq2 folder for the feature to work.

Substance Export Settings

Quake 2 RTX texture naming conventions & channels:
  • <texture>.tga: albedo (rgb), roughness (a)
  • <texture>_n.tga: normal (rgb), metallic (a)
  • <texture>_light.tga: emitted light (rgb)
Global Illumination Features
Sky Clusters

The original Quake II implements a system of portal geometry as an optimization for culling & geometry rasterization: windows, open ceilings and other places that allow the player to look outside of the current “room” are generally closed off by invisible triangle geometry. Quake II RTX leverages this geometry and the original engine’s BSP/PVS system to focus sky-dome samples on windows and cull rays that would otherwise hit mostly walls around the player.

Unfortunately, these triangles must be tagged manually and stored in the file ​baseq2/sky_clusters.txt​

In order to see the sky polygons and identify clusters, set the cvar ​pt_show_sky​ to 1 (added after the 1.1.0 release).

draw cl_clusterthere 50 50​ will show the cluster you're pointing at in the top-left corner.

draw cl_lightpolys 50 60​ will show the number of direct light triangles visible from a surface.

Rule of thumb: small windows in otherwise dark rooms should be marked in the file. Large sky boxes around open areas should not, as that would create too many light triangles, and the direct lighting denoiser wouldn't be able to handle that noise. Small patches of lava in caves should also be marked in the file, which will add one extra bounce of lava illumination.

Note: the ​Light flag ​in the materials.csv table also tells the engine to convert all geometry with a given texture to analytic lights. Same rules: small and bright things should be analytic, large and dim should not.

In some cases, the skybox geometry that is used in the original maps is still inadequate for good lighting. For those maps, the engine supports custom portal lights. You can create a mesh with the portal lights in a 3D editor such as Blender, export it as .obj, and save as “baseq2/maps/sky/<name>.obj”, where <name> is the map name such as “base1”. Note that these portal lights should be as low-poly as possible.

To author the portal lights geometry, you’ll need to see the original map geometry in the editor. Map geometry can potentially be exported using some Quake 2 modding tools, or directly from the Q2RTX engine. The shipping engine doesn’t have this feature enabled though, you’ll need to build it and set the “DUMP_WORLD_MESH_TO_OBJ” constant to 1 (see the “bsp_mesh.c” file).
Console Commands Reference
● reload_materials​: reloads materials.csv and any modified textures
(note: you should ​never add or remove lines in the file, or modify the key strings (texture paths) without restarting the engine​ – only modify values & flags)

● set_material <property> <value>​: sets a property of the material pointed at.
Valid properties: bump_scale, roughness_override, specular_scale, emissive_scale, kind, invisible_flag, light_flag, correct_albedo_flag. Note that only the scales and overrides take effect immediately; things like material kind require a map reload.
ex: ​set_material bump_scale 2.0

● save_materials​: save materials CSV file
● print_material​: print properties of the material currently in the crosshair
● reload_textures​: reload modified textures, but not material definitions
●  draw cl_material 50 50
draw cl_material_override 50 70

console command that turns on the display of the original texture name (and its override) currently in your crosshair

imagelist <filename>
lists all the textures in the texture cache – when an optional file name is given, saves a CSV file with similar texture information

● pt_show_sky​ ​1​: displays ‘sky’ geometry to make sky cluster tagging easier
● draw cl_clusterthere 50 50​: display the cluster ID pointed at by the cross-hairs
● draw cl_lightpolys 50 70​: display the number of direct light triangles visible from the surface pointed at by the cross-hairs
SGC-Puffy Aug 26, 2020 @ 6:22am 
Hey guys, Is there any documentation on how to adjust the skybox setup? It seems to crash out the engine if you make any changes to the terrain_depth.dds or terrain_heightmap.dds files - thanks
Captain Dagon Jan 6, 2020 @ 1:08pm 
Thanks, we needed this guide a while ago. :47_thumb_up:
Millenia Dec 5, 2019 @ 8:43am 
Incredibly useful - thanks for taking the time to document this for us! I was wondering about the materials.csv workflow in particular - would it be possible to add support for loading multiple materials files? I'd like to distribute custom material properties with newly authored textures, without having to edit the original materials.csv which is liable to conflict with other mods or future updates to Q2RTX itself.