Debian Codegraph @

docs/opengl2-readme.md

raw symbols SCIP
1 # OpenGL2
2 <insert ascii art here>
3
4 OpenGL2 is an alternate renderer for ioquake3. It aims to implement modern
5 features and technologies into the id tech 3 engine, but without sacrificing
6 compatibility with existing Quake 3 mods.
7
8
9 -------------------------------------------------------------------------------
10 FEATURES
11 -------------------------------------------------------------------------------
12
13 - Compatible with most vanilla Quake 3 mods.
14 - HDR Rendering, and support for HDR lightmaps
15 - Tone mapping and auto-exposure.
16 - Cascaded shadow maps.
17 - Multisample anti-aliasing.
18 - Texture upsampling.
19 - Advanced materials support.
20 - Advanced shading and specular methods.
21 - RGTC and BPTC texture compression support.
22 - Screen-space ambient occlusion.
23
24
25 -------------------------------------------------------------------------------
26 INSTALLATION
27 -------------------------------------------------------------------------------
28
29 For *nix:
30
31 1. This should be identical to installing ioq3. Check their README for more
32 details.
33
34
35 For Win32:
36
37 1. Have a Quake 3 install, fully patched.
38
39 2. Copy the following files into Quake 3's install directory:
40
41 ioquake3.x86.exe
42 renderer_opengl1_x86.dll
43 renderer_opengl2_x86.dll
44
45 These can be found in build/release-mingw32-x86 after compiling, or bug
46 someone to release binaries.
47
48
49 -------------------------------------------------------------------------------
50 RUNNING
51 -------------------------------------------------------------------------------
52
53 1. Start ioquake3. (ioquake3.x86.exe on Win32)
54
55 2. Open the console (the default key is tilde ~) and type
56 `/cl_renderer opengl2` and press enter
57 `/vid_restart` then press enter again.
58
59 3. Enjoy.
60
61
62 -------------------------------------------------------------------------------
63 CVARS
64 -------------------------------------------------------------------------------
65
66 Cvars for API:
67
68 * `r_preferOpenGLES` - This sets the preference for using OpenGL or OpenGL ES 2.
69 Many features are not supported when using OpenGL ES such as sun shadows and HDR.
70 1 - Prefer OpenGL ES 2+.
71 0 - Prefer desktop OpenGL.
72 -1 - Automatically pick (default).
73
74 Cvars for simple rendering features:
75
76 * `r_ext_compressed_textures` - Automatically compress textures.
77 0 - No texture compression. (default)
78 1 - DXT/RGTC texture compression if
79 supported.
80 2 - BPTC texture compression if supported.
81
82 * `r_ext_framebuffer_multisample` - Multisample Anti-aliasing.
83 0 - None. (default)
84 1-16 - Some.
85 17+ - Too much!
86
87 * `r_ssao` - Enable screen-space ambient occlusion.
88 Currently eats framerate and has some
89 visible artifacts.
90 0 - No. (default)
91 1 - Yes.
92
93 Cvars for HDR and tonemapping:
94
95 * `r_hdr` - Do scene rendering in a framebuffer with
96 high dynamic range. (Less banding, and
97 exposure changes look much better)
98 0 - No.
99 1 - Yes. (default)
100
101 * `r_cameraExposure` - Cheat. Alter brightness, in powers of two.
102 -2 - 4x as dark.
103 0 - Normal. (default)
104 0.5 - Sqrt(2)x as bright.
105 2 - 4x as bright.
106
107 * `r_postProcess` - Enable post-processing.
108 0 - No.
109 1 - Yes. (default)
110
111 * `r_toneMap` - Enable tone mapping. Requires
112 r_hdr and r_postProcess.
113 0 - No.
114 1 - Yes. (default)
115
116 * `r_forceToneMap` - Cheat. Override built-in and map tonemap settings and use cvars r_forceToneMapAvg, r_forceToneMapMin, and r_forceToneMapMax.
117 0 - No. (default)
118 1 - Yes.
119
120 * `r_forceToneMapAvg` - Cheat. Map average scene luminance to this
121 value, in powers of two. Requires
122 r_forceToneMap.
123 -2.0 - Dark.
124 -1.0 - Kinda dark. (default).
125 2.0 - Too bright.
126
127 * `r_forceToneMapMin` - Cheat. After mapping average, luminance
128 below this level is mapped to black.
129 Requires r_forceToneMap.
130 -5 - Not noticeable.
131 -3.25 - Normal. (default)
132 0.0 - Too dark.
133
134 * `r_forceToneMapMin` - Cheat. After mapping average, luminance
135 above this level is mapped to white.
136 Requires r_forceToneMap.
137 0.0 - Too bright.
138 1.0 - Normal. (default).
139 2.0 - Washed out.
140
141 * `r_autoExposure` - Do automatic exposure based on scene
142 brightness. Hardcoded to -2 to 2 on maps
143 that don't specify otherwise. Requires
144 r_hdr, r_postprocess, and r_toneMap.
145 0 - No.
146 1 - Yes. (default)
147
148 * `r_forceAutoExposure` - Cheat. Override built-in and map auto
149 exposure settings and use cvars
150 r_forceAutoExposureMin and
151 r_forceAutoExposureMax.
152 0 - No. (default)
153 1 - Yes.
154
155 * `r_forceAutoExposureMin` - Cheat. Set minimum exposure to this value,
156 in powers of two. Requires
157 r_forceAutoExpsure.
158 -3.0 - Dimmer.
159 -2.0 - Normal. (default)
160 -1.0 - Brighter.
161
162 * `r_forceAutoExposureMax` - Cheat. Set maximum exposure to this value,
163 in powers of two. Requires
164 r_forceAutoExpsure.
165 1.0 - Dimmer.
166 2.0 - Normal. (default)
167 3.0 - Brighter.
168
169 Cvars for advanced material usage:
170
171 * `r_normalMapping` - Enable normal maps for materials that
172 support it.
173 0 - No.
174 1 - Yes. (default)
175
176 * `r_specularMapping` - Enable specular maps for materials that
177 support it.
178 0 - No.
179 1 - Yes. (default)
180
181 * `r_deluxeMapping` - Enable deluxe mapping. (Map is compiled
182 with light directions.) Even if the map
183 doesn't have deluxe mapping compiled in,
184 an approximation based on the lightgrid
185 will be used.
186 0 - No.
187 1 - Yes. (default)
188
189 * `r_parallaxMapping` - Enable parallax mapping for materials that
190 support it.
191 0 - No. (default)
192 1 - Use parallax occlusion mapping.
193 2 - Use relief mapping. (slower)
194
195 * `r_parallaxMapOffset` - Set the parallax height offset.
196 0 - Values map to -255 - 0. (default)
197 0.5 - Values map to -127 - 127.
198 1.0 - Values map to 0 - 255.
199
200 * `r_parallaxMapShadows` - Enable self-shadowing on parallax map
201 supported materials.
202 0 - No. (default)
203 1 - Yes.
204
205 * `r_baseSpecular` - Set the specular reflectance of materials
206 which don't include a specular map or
207 use the specularReflectance keyword.
208 0 - No.
209 0.04 - Realistic. (default)
210 1.0 - Ack.
211
212 * `r_baseGloss` - Set the glossiness of materials which don't
213 include a specular map or use the
214 specularExponent keyword.
215 0 - Rough.
216 0.3 - Default.
217 1.0 - Shiny.
218
219 * `r_baseNormalX` - Set the scale of the X values from normal
220 maps when the normalScale keyword is not
221 used.
222 -1 - Flip X.
223 0 - Ignore X.
224 1 - Normal X. (default)
225 2 - Double X.
226
227 * `r_baseNormalY` - Set the scale of the Y values from normal
228 maps when the normalScale keyword is not
229 used.
230 -1 - Flip Y.
231 0 - Ignore Y.
232 1 - Normal Y. (default)
233 2 - Double Y.
234
235 * `r_baseParallax` - Sets the scale of the parallax effect for
236 materials when the parallaxDepth keyword
237 is not used.
238 0 - No depth.
239 0.01 - Pretty smooth.
240 0.05 - Standard depth. (default)
241 0.1 - Looks broken.
242
243 * `r_pbr` - Enable physically based rendering.
244 Experimental, will not look correct without
245 assets meant for it.
246 0 - No. (default)
247 1 - Yes.
248
249 Cvars for image interpolation and generation:
250
251 * `r_imageUpsample` - Use interpolation to artificially increase
252 the resolution of all textures. Looks good
253 in certain circumstances.
254 0 - No. (default)
255 1 - 2x size.
256 2 - 4x size.
257 3 - 8x size, etc
258
259 * `r_imageUpsampleMaxSize` - Maximum texture size when upsampling
260 textures.
261 1024 - Default.
262 2048 - Really nice.
263 4096 - Really slow.
264 8192 - Crash.
265
266 * `r_imageUpsampleType` - Type of interpolation when upsampling
267 textures.
268 0 - None. (probably broken)
269 1 - Bad but fast (default,
270 FCBI without second derivatives)
271 2 - Okay but slow (normal FCBI)
272
273 * `r_genNormalMaps` - Naively generate normal maps for all
274 textures.
275 0 - Don't. (default)
276 1 - Do.
277
278 Cvars for the sunlight and cascaded shadow maps:
279
280 * `r_forceSun` - Cheat. Force sunlight and shadows, using sun position from sky material.
281 0 - Don't. (default)
282 1 - Do.
283 2 - Sunrise, sunset.
284
285 * `r_forceSunLightScale` - Cheat. Scale sun brightness by this factor
286 when r_forceSun 1.
287 1.0 - Default
288
289 * `r_forceSunAmbientScale` - Cheat. Scale sun ambient brightness by this factor when r_forceSun 1. 0.5 - Default
290
291 * `r_sunShadows` - Enable sunlight and cascaded shadow maps for
292 it on maps that support it.
293 0 - No.
294 1 - Yes. (default)
295
296 * `r_sunlightMode` - Specify the method used to add sunlight to
297 the scene.
298 0 - No.
299 1 - Multiply lit areas by light scale, and
300 shadowed areas by ambient scale.
301 (default)
302 2 - Add light. Looks better, but is slower
303 and doesn't integrate well with existing
304 maps.
305
306 * `r_shadowFilter` - Enable filtering shadows for a smoother
307 look.
308 0 - No.
309 1 - Some. (default)
310 2 - Much.
311
312 * `r_shadowMapSize` - Size of each cascaded shadow map.
313 256 - 256x256, ugly, probably shouldn't
314 go below this.
315 512 - 512x512, passable.
316 1024 - 1024x1024, good. (default)
317 2048 - 2048x2048, extreme.
318 4096 - 4096x4096, indistinguishable from
319 2048.
320
321 Cvars that you probably don't care about or shouldn't mess with:
322
323 * `r_depthPrepass` - Do a depth-only pass before rendering.
324 Speeds up rendering in cases where advanced
325 features are used. Required for
326 r_sunShadows.
327 0 - No.
328 1 - Yes. (default)
329
330 * `r_mergeLightmaps` - Merge the small (128x128) lightmaps into
331 2 or fewer giant (4096x4096) lightmaps.
332 Easy speedup.
333 0 - Don't.
334 1 - Do. (default)
335
336 * `r_shadowCascadeZNear` - Near plane for shadow cascade frustums.
337 4 - Default.
338
339 * `r_shadowCascadeZFar` - Far plane for shadow cascade frustums.
340 3072 - Default.
341
342 * `r_shadowCascadeZBias` - Z-bias for shadow cascade frustums.
343 -256 - Default.
344
345 Cvars that have broken bits:
346
347 * `r_dlightMode` - Change how dynamic lights look.
348 0 - Quake 3 style dlights, fake
349 brightening. (default)
350 1 - Actual lighting, no shadows.
351 2 - Light and shadows. (broken)
352
353 * `r_pshadowDist` - Virtual camera distance when creating shadowmaps for projected shadows. Deprecated.
354
355 * `cg_shadows` - Old shadow code. Deprecated.
356
357
358 -------------------------------------------------------------------------------
359 MATERIALS
360 -------------------------------------------------------------------------------
361
362 OpenGL2 supports .mtr files, which are basically the same as .shader files, and
363 are located in the same place, but override existing .shader files if they
364 exist. This is to allow maps and mods to use the new material features without
365 breaking the map when using the old renderer.
366
367 Here's an example of a material stored in one, showing off some new features:
368
369 textures/abandon/grass
370 {
371 qer_editorimage textures/abandon/grass.jpg
372 {
373 map textures/abandon/grass3_256_d.jpg
374 rgbgen identity
375 }
376 {
377 stage normalparallaxmap
378 map textures/abandon/grass3_1024_n.png
379 normalScale 1 1
380 parallaxDepth 0.05
381 }
382 {
383 stage specularmap
384 map textures/abandon/grass3_256_s.png
385 specularReflectance 0.12
386 specularExponent 16
387 }
388 {
389 map $lightmap
390 blendfunc GL_DST_COLOR GL_ZERO
391 }
392 }
393
394 The first thing to notice is that this is basically the same as old Quake 3
395 shader files. The next thing to notice are the new keywords. Here is what
396 they mean:
397
398 `stage <type>`
399 - State how this imagemap will be used by OpenGL2:
400 diffuseMap - Standard, same as no stage entry
401 normalMap - Image will be used as a normal map
402 normalParallaxMap - Image will be used as a normal map with
403 alpha treated as height for parallax mapping
404 specularMap - Image will be used as a specular map with
405 alpha treated as shininess.
406
407 `specularReflectance <value>`
408 - State how metallic this material is. Metals typically have a high
409 specular and a low diffuse, so this is typically high for them, and low
410 for other materials, such as plastic. For typical values for various
411 materials, see http://refractiveindex.info , pick a material, then scroll
412 down to the reflection calculator and look up its reflectance. Default
413 is 0.04, since most materials aren't metallic.
414
415 `specularExponent <value>`
416 - State how shiny this material is. Note that this is modulated by the
417 alpha channel of the specular map, so if it were set to 16, and the alpha
418 channel of the specular map was set to 0.5, then the shininess would be
419 set to 8. Default 256.
420
421 `normalScale <x> <y>`
422 - State the X and Y scales of the normal map. This is useful for increasing
423 or decreasing the "strength" of the normal map, or entering negative values
424 to flip the X and/or Y values. Default 1 1.
425
426 `parallaxDepth <value>`
427 - State the maximum depth of the parallax map. This is a fairly sensitive
428 value, and I recommend the default or lower. Default 0.05.
429
430 An important note is that normal and specular maps influence the diffuse map
431 declared before them, so materials like this are possible:
432
433 textures/terrain/grass
434 {
435 qer_editorimage textures/terrain/grass.jpg
436
437 {
438 map textures/terrain/rock.jpg
439 }
440 {
441 stage normalparallaxmap
442 map textures/terrain/rock_n.png
443 }
444 {
445 stage specularmap
446 map textures/terrain/rock_s.jpg
447 }
448 {
449 map textures/terrain/grass.jpg
450 blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
451 alphaGen vertex
452 }
453 {
454 stage normalparallaxmap
455 map textures/terrain/grass_n.png
456 }
457 {
458 stage specularmap
459 map textures/terrain/grass_s.png
460 specularReflectance 0.12
461 }
462 {
463 map $lightmap
464 blendfunc GL_DST_COLOR GL_ZERO
465 }
466 }
467
468 Though note due to the complexity of lighting, dynamic light (including
469 sunlight with cascaded shadow maps) currently only works 100% on materials like
470 this, where the second diffuse map doesn't have its own alpha, and only
471 uses vertex alpha. YMMV.
472
473 Another addition to materials is working normal/specular maps on vertex lit
474 surfaces. To enable this, make your material look like this:
475
476 textures/vehicles/car
477 {
478 qer_editorimage textures/vehicles/car.jpg
479
480 {
481 map textures/vehicles/car.jpg
482 rgbGen vertexLit
483 }
484 {
485 stage normalparallaxmap
486 map textures/vehicles/car_n.jpg
487 }
488 {
489 stage specularmap
490 map textures/vehicles/car_s.jpg
491 }
492 }
493
494 Note the new keyword, 'vertexLit' after rgbGen. This is analogous to
495 'rgbGen vertex', except a light direction will be determined from the lightgrid
496 and used with the normal and specular maps. 'exactVertexLit' exists as well,
497 and is the equivalent for 'exactVertex'.
498
499
500 -------------------------------------------------------------------------------
501 DYNAMIC SUNLIGHT AND CASCADED SHADOW MAPS
502 -------------------------------------------------------------------------------
503
504 This adds a new keyword to sky materials, q3gl2_sun. The syntax is:
505
506 q3gl2_sun <red> <green> <blue> <intensity> <degrees> <elevation> <shadowScale>
507
508 Note the first six parameters are the same as in q3map_sun or q3map_sunExt,
509 and the last two indicate scaling factors for the map brightness and an ambient
510 light of the same color as the sun.
511
512 There are currently two ways to use this in your own (and other people's) maps.
513
514 1. Create your map as normal, set r_sunlightMode to 1, and add a
515 'q3gl2_sun' line after your 'q3map_sun' line in your sky material, like
516 so:
517
518 textures/skies/bluesky
519 {
520 qer_editorimage textures/skies/bluesky.jpg
521
522 surfaceparm nomarks
523 surfaceparm noimpact
524 surfaceparm nolightmap
525 surfaceparm sky
526 q3map_sunExt 240 238 200 100 195 35 3 16
527 q3gl2_sun 240 238 200 50 195 35 0.2
528 q3map_skylight 50 16
529 q3map_lightimage $whiteimage
530
531 skyparms env/bluesky - -
532 }
533
534 The advantages with this method are that your map will continue to work
535 with the old renderer with the sunlight baked into the lightmap, and it
536 can be used with existing maps without recompilation. The downside is
537 artifacts like doubled shadows and uneven shadow edges.
538
539 2. Set r_sunlightMode to 2 and use 'q3gl2_sun' instead of 'q3map_sun' or
540 'q3map_sunExt', like so:
541
542 textures/skies/bluesky
543 {
544 qer_editorimage textures/skies/bluesky.jpg
545
546 surfaceparm nomarks
547 surfaceparm noimpact
548 surfaceparm nolightmap
549 surfaceparm sky
550 q3gl2_sun 240 238 200 50 195 35 0.2
551 q3map_skylight 50 16
552 q3map_lightimage $whiteimage
553
554 skyparms env/bluesky - -
555 }
556
557 The advantages with this method are that you don't get the artifacts that
558 characterize the other method, and your map compiles a lot faster without
559 the sunlight bouncing calculations. The downsides are that your map will
560 not display properly with the old renderer, and you lose the bounced light
561 that compiling the map with q3map_sun* in it would have.
562
563
564 -------------------------------------------------------------------------------
565 TONE MAPPING AND AUTO EXPOSURE
566 -------------------------------------------------------------------------------
567
568 This adds a new keyword to sky materials, q3gl2_tonemap. The syntax is:
569
570 q3gl2_tonemap <toneMapMin> <toneMapAvg> <toneMapMax> <autoExposureMin> <autoExposureMax>
571
572 Each of these settings corresponds to a matching cvar, so you can view and
573 adjust the effect before settling on fixed settings.
574
575
576 -------------------------------------------------------------------------------
577 THANKS
578 -------------------------------------------------------------------------------
579
580 I'd like to take this part of the readme to thank the numerous people who
581 contributed thoughts, ideas, and whole swaths of code to this project.
582
583 - Id Software, for creating Quake 3 and releasing its source code under a
584 GPL license, without which this project would not be possible.
585
586 - Zachary 'Zakk' Slater, Thilo Schulz, Tim Angus, and the rest of the
587 ioquake3 team and contributors, for improving massively upon the raw Quake
588 3 source, and accepting my and gimhael's modular renderer patch.
589
590 - Robert 'Tr3B' Beckebans and the other contributors to XReaL, for letting me
591 liberally copy code from you. :)
592
593 - Andrew 'Black Monk' Prosnik, Andrei 'Makro' Drexler, Tomi 'T.T.I.' Isoaho,
594 Richard 'JBravo' Allen, Walter 'Johnny Rocket' Somol, and the rest of the
595 Boomstick Studios, for contributing code, feature requests, and testing.
596
597 - Yoshiharu Gotanda, Tatsuya Shoji, and the rest of tri-Ace's R&D Department,
598 for creating the tri-Ace shading equations and posting their derivations in
599 simple English.
600
601 - Matthias 'gimhael' Bentrup, for random ideas and bits of code.
602
603 - Evan 'megatog615' Goers, for testing, ideas, and bugging me just enough
604 that I'd write documentation. :)
605
606 - The folks at #ioquake3, who don't seem to mind when I suddenly drop a
607 screenshot and insist on talking about it. :)
608
609 - And lots of various other random people, who posted on forums, blogs, and
610 Wikipedia, who helped in small but numerous ways.
611
612 If I missed you in this section, feel free to drop me a line and I'll add you.
613
614
615 -------------------------------------------------------------------------------
616 CONTACT
617 -------------------------------------------------------------------------------
618
619 My name is James Canete, and I wrote most of this readme. Also, a renderer.
620
621 If you wish to get in touch with me, try my GMail at use.less01 (you should be
622 able to solve this), or look for SmileTheory in #ioquake3 on irc.freenode.net.