Programming techniques for First Person Shooters in DirectX 9

80
Programming techniques for First Person Shooters in DirectX 9 Introduction Getting started .map format and visibility test func plat meshes A bit on materials Parallax mapping with multiple point lights Bibliography Programming techniques for First Person Shooters in DirectX 9 Alejandro Cosin Ayerbe August 2012

description

This presentation is an abstract of my final project in Computer Engineering,presented in September of 2006.

Transcript of Programming techniques for First Person Shooters in DirectX 9

Page 1: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Programming techniques for First Person Shooters inDirectX 9

Alejandro Cosin Ayerbe

August 2012

Page 2: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Introduction

This presentation is an abstract of my final project in Computer Engineering,presented in September of 2006. There were several goals in this project, themain ones are the following:

Understand how first person shooter video games work: level meshmanagement, BSP trees, inter-area portals, visibility tests, static simpleand complex meshes, mesh rendering, skeletal animation, lightpositioning, materials....

Develop programming techniques centered in performance (particularlyfor visibility tests).

Learn differences between the graphics programming APIs OpenGL andDirectX.

Perform per-pixel lighting effects like specular and parallax mapping.

Page 3: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Introduction

This presentation is an abstract of my final project in Computer Engineering,presented in September of 2006. There were several goals in this project, themain ones are the following:

Understand how first person shooter video games work: level meshmanagement, BSP trees, inter-area portals, visibility tests, static simpleand complex meshes, mesh rendering, skeletal animation, lightpositioning, materials....

Develop programming techniques centered in performance (particularlyfor visibility tests).

Learn differences between the graphics programming APIs OpenGL andDirectX.

Perform per-pixel lighting effects like specular and parallax mapping.

Page 4: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Introduction

This presentation is an abstract of my final project in Computer Engineering,presented in September of 2006. There were several goals in this project, themain ones are the following:

Understand how first person shooter video games work: level meshmanagement, BSP trees, inter-area portals, visibility tests, static simpleand complex meshes, mesh rendering, skeletal animation, lightpositioning, materials....

Develop programming techniques centered in performance (particularlyfor visibility tests).

Learn differences between the graphics programming APIs OpenGL andDirectX.

Perform per-pixel lighting effects like specular and parallax mapping.

Page 5: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Introduction

This presentation is an abstract of my final project in Computer Engineering,presented in September of 2006. There were several goals in this project, themain ones are the following:

Understand how first person shooter video games work: level meshmanagement, BSP trees, inter-area portals, visibility tests, static simpleand complex meshes, mesh rendering, skeletal animation, lightpositioning, materials....

Develop programming techniques centered in performance (particularlyfor visibility tests).

Learn differences between the graphics programming APIs OpenGL andDirectX.

Perform per-pixel lighting effects like specular and parallax mapping.

Page 6: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Introduction

This presentation is an abstract of my final project in Computer Engineering,presented in September of 2006. There were several goals in this project, themain ones are the following:

Understand how first person shooter video games work: level meshmanagement, BSP trees, inter-area portals, visibility tests, static simpleand complex meshes, mesh rendering, skeletal animation, lightpositioning, materials....

Develop programming techniques centered in performance (particularlyfor visibility tests).

Learn differences between the graphics programming APIs OpenGL andDirectX.

Perform per-pixel lighting effects like specular and parallax mapping.

Page 7: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

In an attempt to know in depth the performance of the current FPS games,level, mesh and geometric model loaders were looked for.

In general in the game industry, the formats are proprietary, so usually there isno access to this type of information.

Luckily, a Doom3 level viewer and a Doom 3 model viewer and skeletalanimation player were found in Internet. Both of them were programmed inOpenGL, so there was no problem to use the data structures generated bythem, but the rendering process in DirectX had to be programmed.

The level viewer works with .map format, was developed by Miguel AngelPastor, aka Garrofi. His old homepage is all that can be found today. If youwant the source code of the level viewer, contact me [email protected] and i will send it to you, as there are no active linksfor download. The mesh viewer and animator player works with .md5 format(md5mesh for meshes and md5anim for animations), and can be downloadedhere.

Information about .map file format and .md5 file format can be read here andhere respectively.

Page 8: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

In an attempt to know in depth the performance of the current FPS games,level, mesh and geometric model loaders were looked for.

In general in the game industry, the formats are proprietary, so usually there isno access to this type of information.

Luckily, a Doom3 level viewer and a Doom 3 model viewer and skeletalanimation player were found in Internet. Both of them were programmed inOpenGL, so there was no problem to use the data structures generated bythem, but the rendering process in DirectX had to be programmed.

The level viewer works with .map format, was developed by Miguel AngelPastor, aka Garrofi. His old homepage is all that can be found today. If youwant the source code of the level viewer, contact me [email protected] and i will send it to you, as there are no active linksfor download. The mesh viewer and animator player works with .md5 format(md5mesh for meshes and md5anim for animations), and can be downloadedhere.

Information about .map file format and .md5 file format can be read here andhere respectively.

Page 9: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

In an attempt to know in depth the performance of the current FPS games,level, mesh and geometric model loaders were looked for.

In general in the game industry, the formats are proprietary, so usually there isno access to this type of information.

Luckily, a Doom3 level viewer and a Doom 3 model viewer and skeletalanimation player were found in Internet. Both of them were programmed inOpenGL, so there was no problem to use the data structures generated bythem, but the rendering process in DirectX had to be programmed.

The level viewer works with .map format, was developed by Miguel AngelPastor, aka Garrofi. His old homepage is all that can be found today. If youwant the source code of the level viewer, contact me [email protected] and i will send it to you, as there are no active linksfor download. The mesh viewer and animator player works with .md5 format(md5mesh for meshes and md5anim for animations), and can be downloadedhere.

Information about .map file format and .md5 file format can be read here andhere respectively.

Page 10: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

In an attempt to know in depth the performance of the current FPS games,level, mesh and geometric model loaders were looked for.

In general in the game industry, the formats are proprietary, so usually there isno access to this type of information.

Luckily, a Doom3 level viewer and a Doom 3 model viewer and skeletalanimation player were found in Internet. Both of them were programmed inOpenGL, so there was no problem to use the data structures generated bythem, but the rendering process in DirectX had to be programmed.

The level viewer works with .map format, was developed by Miguel AngelPastor, aka Garrofi. His old homepage is all that can be found today. If youwant the source code of the level viewer, contact me [email protected] and i will send it to you, as there are no active linksfor download. The mesh viewer and animator player works with .md5 format(md5mesh for meshes and md5anim for animations), and can be downloadedhere.

Information about .map file format and .md5 file format can be read here andhere respectively.

Page 11: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

In an attempt to know in depth the performance of the current FPS games,level, mesh and geometric model loaders were looked for.

In general in the game industry, the formats are proprietary, so usually there isno access to this type of information.

Luckily, a Doom3 level viewer and a Doom 3 model viewer and skeletalanimation player were found in Internet. Both of them were programmed inOpenGL, so there was no problem to use the data structures generated bythem, but the rendering process in DirectX had to be programmed.

The level viewer works with .map format, was developed by Miguel AngelPastor, aka Garrofi. His old homepage is all that can be found today. If youwant the source code of the level viewer, contact me [email protected] and i will send it to you, as there are no active linksfor download. The mesh viewer and animator player works with .md5 format(md5mesh for meshes and md5anim for animations), and can be downloadedhere.

Information about .map file format and .md5 file format can be read here andhere respectively.

Page 12: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Getting started

Doom 3 was programmed in OpenGL, so a rendering process in DirectXrequired some changes, like texture coordinates, which are different in eachAPI, or the coordinate systems used.

Starting from an empty demo from the DirectX 9 SDK, the meshes of themodels where correctly rendered through index buffers and texturized.

These meshes are very optimized, for example, weapon meshes exclude thosepolygons from the mesh that never are viewed:

Page 13: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Getting started

Doom 3 was programmed in OpenGL, so a rendering process in DirectXrequired some changes, like texture coordinates, which are different in eachAPI, or the coordinate systems used.

Starting from an empty demo from the DirectX 9 SDK, the meshes of themodels where correctly rendered through index buffers and texturized.

These meshes are very optimized, for example, weapon meshes exclude thosepolygons from the mesh that never are viewed:

Page 14: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Getting started

Doom 3 was programmed in OpenGL, so a rendering process in DirectXrequired some changes, like texture coordinates, which are different in eachAPI, or the coordinate systems used.

Starting from an empty demo from the DirectX 9 SDK, the meshes of themodels where correctly rendered through index buffers and texturized.

These meshes are very optimized, for example, weapon meshes exclude thosepolygons from the mesh that never are viewed:

Page 15: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

md5 meshes include the weapons carried by the player, so a first personshooter needs to render correctly those meshes when the camera moves. Theproblem was to make these meshes rotate correctly:

The solution was to decompose the view matrix in its scaling, rotation andtranslation factors when rendering each frame. The rotation factor, given by aquaternion, was then used to rotate correctly the weapon mesh and thereforegive the appearance that the weapon follows the camera.

Page 16: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

md5 meshes include the weapons carried by the player, so a first personshooter needs to render correctly those meshes when the camera moves. Theproblem was to make these meshes rotate correctly:

The solution was to decompose the view matrix in its scaling, rotation andtranslation factors when rendering each frame. The rotation factor, given by aquaternion, was then used to rotate correctly the weapon mesh and thereforegive the appearance that the weapon follows the camera.

Page 17: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

md5 meshes include the weapons carried by the player, so a first personshooter needs to render correctly those meshes when the camera moves. Theproblem was to make these meshes rotate correctly:

The solution was to decompose the view matrix in its scaling, rotation andtranslation factors when rendering each frame. The rotation factor, given by aquaternion, was then used to rotate correctly the weapon mesh and thereforegive the appearance that the weapon follows the camera.

Page 18: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Also a head up display was made, enabling alpha blending and disabling depthtesting in order to keep the HUD visible even if the camera walks through amesh. The number textures were taken from the Doom 3 textures, while somesimple symbols were made with Photoshop:

Page 19: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Also a head up display was made, enabling alpha blending and disabling depthtesting in order to keep the HUD visible even if the camera walks through amesh. The number textures were taken from the Doom 3 textures, while somesimple symbols were made with Photoshop:

Page 20: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Also a head up display was made, enabling alpha blending and disabling depthtesting in order to keep the HUD visible even if the camera walks through amesh. The number textures were taken from the Doom 3 textures, while somesimple symbols were made with Photoshop:

Page 21: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

In FPS games, weapons have some typical animations associated: firing,reloading, idle, raise, lower... For the case of the shotgun in Doom 3, theanimations available are the following:empty.md5anim, fire1.md5anim, fire2.md5anim, fire3.md5anim,

idle.md5anim, lower.md5anim, raise.md5anim, reload_end.md5anim,

reload_loop.md5anim, reload_loop2.md5anim, reload_loop3.md5anim,

and reload_start.md5anim.

Page 22: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

In FPS games, weapons have some typical animations associated: firing,reloading, idle, raise, lower... For the case of the shotgun in Doom 3, theanimations available are the following:empty.md5anim, fire1.md5anim, fire2.md5anim, fire3.md5anim,

idle.md5anim, lower.md5anim, raise.md5anim, reload_end.md5anim,

reload_loop.md5anim, reload_loop2.md5anim, reload_loop3.md5anim,

and reload_start.md5anim.

Page 23: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

If a realistic behaviour is wanted, a logical coordination of the animations isneeded, so for the case of the shotgun, the first step is to play the raiseanimation, and when it ends, play the idle animation until player presses thereload or fire buttons, playing the corresponding animations and usingrandomness if more than one animation is available for the current action, andtaking into account the ammo.

The fire effect in the barrel of the weapon is achieved using a texture like thefollowing:

This texture consists in a series of sprites that must be shown correctly,averaging the number of frames of the fire animation and showing theappropriate portion of sprite in the correct interval. The sprites are displayedin a plane mesh available in every weapon:

Page 24: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

If a realistic behaviour is wanted, a logical coordination of the animations isneeded, so for the case of the shotgun, the first step is to play the raiseanimation, and when it ends, play the idle animation until player presses thereload or fire buttons, playing the corresponding animations and usingrandomness if more than one animation is available for the current action, andtaking into account the ammo.

The fire effect in the barrel of the weapon is achieved using a texture like thefollowing:

This texture consists in a series of sprites that must be shown correctly,averaging the number of frames of the fire animation and showing theappropriate portion of sprite in the correct interval. The sprites are displayedin a plane mesh available in every weapon:

Page 25: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

If a realistic behaviour is wanted, a logical coordination of the animations isneeded, so for the case of the shotgun, the first step is to play the raiseanimation, and when it ends, play the idle animation until player presses thereload or fire buttons, playing the corresponding animations and usingrandomness if more than one animation is available for the current action, andtaking into account the ammo.

The fire effect in the barrel of the weapon is achieved using a texture like thefollowing:

This texture consists in a series of sprites that must be shown correctly,averaging the number of frames of the fire animation and showing theappropriate portion of sprite in the correct interval. The sprites are displayedin a plane mesh available in every weapon:

Page 26: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

If a realistic behaviour is wanted, a logical coordination of the animations isneeded, so for the case of the shotgun, the first step is to play the raiseanimation, and when it ends, play the idle animation until player presses thereload or fire buttons, playing the corresponding animations and usingrandomness if more than one animation is available for the current action, andtaking into account the ammo.

The fire effect in the barrel of the weapon is achieved using a texture like thefollowing:

This texture consists in a series of sprites that must be shown correctly,averaging the number of frames of the fire animation and showing theappropriate portion of sprite in the correct interval. The sprites are displayedin a plane mesh available in every weapon:

Page 27: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Page 28: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

.map format and visibility test

The Doom 3 level viewer developed by Miguel Angel Pastor in OpenGL loadsmost of the objects and entities of the level. Consists of more than 12000lines of source code, and generates a data structure somewhat complex, as theamount and diversity of data is high.

Doom 3 levels consist in four file formats:

The MAP file, an ASCII text file with all the static geometry and entities,such as lights, patches (Bezier surfaces), brushes (simple geometricmeshes) and the location of complex meshes whose geometry is loadedfrom files in a more general format (LWO for example).

The CM file, which stores the collision model data.

The PROC file, with all the preprocessed geometry in the map, portalinformation (Doom 3 operates with BSP-trees) and pre-calculatedshadow volumes (for static lights in static geometry).

The AAS files, used by the AI to move the monsters in the scenario.

Page 29: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

.map format and visibility test

The Doom 3 level viewer developed by Miguel Angel Pastor in OpenGL loadsmost of the objects and entities of the level. Consists of more than 12000lines of source code, and generates a data structure somewhat complex, as theamount and diversity of data is high.

Doom 3 levels consist in four file formats:

The MAP file, an ASCII text file with all the static geometry and entities,such as lights, patches (Bezier surfaces), brushes (simple geometricmeshes) and the location of complex meshes whose geometry is loadedfrom files in a more general format (LWO for example).

The CM file, which stores the collision model data.

The PROC file, with all the preprocessed geometry in the map, portalinformation (Doom 3 operates with BSP-trees) and pre-calculatedshadow volumes (for static lights in static geometry).

The AAS files, used by the AI to move the monsters in the scenario.

Page 30: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

.map format and visibility test

The Doom 3 level viewer developed by Miguel Angel Pastor in OpenGL loadsmost of the objects and entities of the level. Consists of more than 12000lines of source code, and generates a data structure somewhat complex, as theamount and diversity of data is high.

Doom 3 levels consist in four file formats:

The MAP file, an ASCII text file with all the static geometry and entities,such as lights, patches (Bezier surfaces), brushes (simple geometricmeshes) and the location of complex meshes whose geometry is loadedfrom files in a more general format (LWO for example).

The CM file, which stores the collision model data.

The PROC file, with all the preprocessed geometry in the map, portalinformation (Doom 3 operates with BSP-trees) and pre-calculatedshadow volumes (for static lights in static geometry).

The AAS files, used by the AI to move the monsters in the scenario.

Page 31: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

.map format and visibility test

The Doom 3 level viewer developed by Miguel Angel Pastor in OpenGL loadsmost of the objects and entities of the level. Consists of more than 12000lines of source code, and generates a data structure somewhat complex, as theamount and diversity of data is high.

Doom 3 levels consist in four file formats:

The MAP file, an ASCII text file with all the static geometry and entities,such as lights, patches (Bezier surfaces), brushes (simple geometricmeshes) and the location of complex meshes whose geometry is loadedfrom files in a more general format (LWO for example).

The CM file, which stores the collision model data.

The PROC file, with all the preprocessed geometry in the map, portalinformation (Doom 3 operates with BSP-trees) and pre-calculatedshadow volumes (for static lights in static geometry).

The AAS files, used by the AI to move the monsters in the scenario.

Page 32: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

.map format and visibility test

The Doom 3 level viewer developed by Miguel Angel Pastor in OpenGL loadsmost of the objects and entities of the level. Consists of more than 12000lines of source code, and generates a data structure somewhat complex, as theamount and diversity of data is high.

Doom 3 levels consist in four file formats:

The MAP file, an ASCII text file with all the static geometry and entities,such as lights, patches (Bezier surfaces), brushes (simple geometricmeshes) and the location of complex meshes whose geometry is loadedfrom files in a more general format (LWO for example).

The CM file, which stores the collision model data.

The PROC file, with all the preprocessed geometry in the map, portalinformation (Doom 3 operates with BSP-trees) and pre-calculatedshadow volumes (for static lights in static geometry).

The AAS files, used by the AI to move the monsters in the scenario.

Page 33: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

.map format and visibility test

The Doom 3 level viewer developed by Miguel Angel Pastor in OpenGL loadsmost of the objects and entities of the level. Consists of more than 12000lines of source code, and generates a data structure somewhat complex, as theamount and diversity of data is high.

Doom 3 levels consist in four file formats:

The MAP file, an ASCII text file with all the static geometry and entities,such as lights, patches (Bezier surfaces), brushes (simple geometricmeshes) and the location of complex meshes whose geometry is loadedfrom files in a more general format (LWO for example).

The CM file, which stores the collision model data.

The PROC file, with all the preprocessed geometry in the map, portalinformation (Doom 3 operates with BSP-trees) and pre-calculatedshadow volumes (for static lights in static geometry).

The AAS files, used by the AI to move the monsters in the scenario.

Page 34: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Developing an efficient visibility test

Once all the level geometry is loaded, and in order to optimize performance, acriteria must be followed to know what meshes must be rendered (amongthose visible for the camera, i.e., inside the view frustum), and what must not.

Doom 3 levels use the BSP-tree system which divides a space into convexsets. Each convex set is called in this case an area, and two areas areconnected through an IAP or Inter Area Portal. An example of the IAPspresent in a Doom 3 level can be seen below:

Page 35: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Developing an efficient visibility test

Once all the level geometry is loaded, and in order to optimize performance, acriteria must be followed to know what meshes must be rendered (amongthose visible for the camera, i.e., inside the view frustum), and what must not.

Doom 3 levels use the BSP-tree system which divides a space into convexsets. Each convex set is called in this case an area, and two areas areconnected through an IAP or Inter Area Portal. An example of the IAPspresent in a Doom 3 level can be seen below:

Page 36: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Developing an efficient visibility test

Once all the level geometry is loaded, and in order to optimize performance, acriteria must be followed to know what meshes must be rendered (amongthose visible for the camera, i.e., inside the view frustum), and what must not.

Doom 3 levels use the BSP-tree system which divides a space into convexsets. Each convex set is called in this case an area, and two areas areconnected through an IAP or Inter Area Portal. An example of the IAPspresent in a Doom 3 level can be seen below:

Page 37: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Those IAP (seen from above) have different sizes and not always consist offour vertices. Thinking of IAPs as if they were windows, candidate meshes tobe rendered will be those in the areas whose IAPs can be seen from thecamera position and orientation. Also, BSP-trees allow to determine easilywhich area a given point belongs to, so finding the area in which the camera islocated is simple.

The faster the method, the better the performance, because the visibility testmust be done every frame before the rendering process. There are severalways to test what surfaces are visible in a scenario based on BSP-trees,currently there are several efficient methods, but new ways can be thought of?

The main task is to determine which IAPs of the current area are visible fromthe position and orientation of the camera, the meshes in those areas are thecandidate meshes to be rendered. The hardware technique occlusion cullingcan be used (a detailed explanation can be found here), in oder to know whatIAPs are visible.

Page 38: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Those IAP (seen from above) have different sizes and not always consist offour vertices. Thinking of IAPs as if they were windows, candidate meshes tobe rendered will be those in the areas whose IAPs can be seen from thecamera position and orientation. Also, BSP-trees allow to determine easilywhich area a given point belongs to, so finding the area in which the camera islocated is simple.

The faster the method, the better the performance, because the visibility testmust be done every frame before the rendering process. There are severalways to test what surfaces are visible in a scenario based on BSP-trees,currently there are several efficient methods, but new ways can be thought of?

The main task is to determine which IAPs of the current area are visible fromthe position and orientation of the camera, the meshes in those areas are thecandidate meshes to be rendered. The hardware technique occlusion cullingcan be used (a detailed explanation can be found here), in oder to know whatIAPs are visible.

Page 39: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Those IAP (seen from above) have different sizes and not always consist offour vertices. Thinking of IAPs as if they were windows, candidate meshes tobe rendered will be those in the areas whose IAPs can be seen from thecamera position and orientation. Also, BSP-trees allow to determine easilywhich area a given point belongs to, so finding the area in which the camera islocated is simple.

The faster the method, the better the performance, because the visibility testmust be done every frame before the rendering process. There are severalways to test what surfaces are visible in a scenario based on BSP-trees,currently there are several efficient methods, but new ways can be thought of?

The main task is to determine which IAPs of the current area are visible fromthe position and orientation of the camera, the meshes in those areas are thecandidate meshes to be rendered. The hardware technique occlusion cullingcan be used (a detailed explanation can be found here), in oder to know whatIAPs are visible.

Page 40: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

The concept is very simple:

Render to a small buffer the meshes being tested (or a bunding box forperformance).

For each mesh:Start the query.Render again the mesh to the small buffer (or bounding box).Finish the queryRetrieve information from the test: if the number of visible pixels is greaterthan cero, the mesh is visible from the camera position and orientation.

The following is an example of the method. On the left several IAPs can beseen in green color. On the right, the content of the small buffer afterperforming the visibility test to one of the IAPs in the left:

Page 41: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

The concept is very simple:

Render to a small buffer the meshes being tested (or a bunding box forperformance).For each mesh:

Start the query.Render again the mesh to the small buffer (or bounding box).Finish the queryRetrieve information from the test: if the number of visible pixels is greaterthan cero, the mesh is visible from the camera position and orientation.

The following is an example of the method. On the left several IAPs can beseen in green color. On the right, the content of the small buffer afterperforming the visibility test to one of the IAPs in the left:

Page 42: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

The concept is very simple:

Render to a small buffer the meshes being tested (or a bunding box forperformance).For each mesh:

Start the query.

Render again the mesh to the small buffer (or bounding box).Finish the queryRetrieve information from the test: if the number of visible pixels is greaterthan cero, the mesh is visible from the camera position and orientation.

The following is an example of the method. On the left several IAPs can beseen in green color. On the right, the content of the small buffer afterperforming the visibility test to one of the IAPs in the left:

Page 43: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

The concept is very simple:

Render to a small buffer the meshes being tested (or a bunding box forperformance).For each mesh:

Start the query.Render again the mesh to the small buffer (or bounding box).

Finish the queryRetrieve information from the test: if the number of visible pixels is greaterthan cero, the mesh is visible from the camera position and orientation.

The following is an example of the method. On the left several IAPs can beseen in green color. On the right, the content of the small buffer afterperforming the visibility test to one of the IAPs in the left:

Page 44: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

The concept is very simple:

Render to a small buffer the meshes being tested (or a bunding box forperformance).For each mesh:

Start the query.Render again the mesh to the small buffer (or bounding box).Finish the query

Retrieve information from the test: if the number of visible pixels is greaterthan cero, the mesh is visible from the camera position and orientation.

The following is an example of the method. On the left several IAPs can beseen in green color. On the right, the content of the small buffer afterperforming the visibility test to one of the IAPs in the left:

Page 45: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

The concept is very simple:

Render to a small buffer the meshes being tested (or a bunding box forperformance).For each mesh:

Start the query.Render again the mesh to the small buffer (or bounding box).Finish the queryRetrieve information from the test: if the number of visible pixels is greaterthan cero, the mesh is visible from the camera position and orientation.

The following is an example of the method. On the left several IAPs can beseen in green color. On the right, the content of the small buffer afterperforming the visibility test to one of the IAPs in the left:

Page 46: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

The concept is very simple:

Render to a small buffer the meshes being tested (or a bunding box forperformance).For each mesh:

Start the query.Render again the mesh to the small buffer (or bounding box).Finish the queryRetrieve information from the test: if the number of visible pixels is greaterthan cero, the mesh is visible from the camera position and orientation.

The following is an example of the method. On the left several IAPs can beseen in green color. On the right, the content of the small buffer afterperforming the visibility test to one of the IAPs in the left:

Page 47: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

The concept is very simple:

Render to a small buffer the meshes being tested (or a bunding box forperformance).For each mesh:

Start the query.Render again the mesh to the small buffer (or bounding box).Finish the queryRetrieve information from the test: if the number of visible pixels is greaterthan cero, the mesh is visible from the camera position and orientation.

The following is an example of the method. On the left several IAPs can beseen in green color. On the right, the content of the small buffer afterperforming the visibility test to one of the IAPs in the left:

Page 48: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

This way, starting from the area in which lies the camera, all the visible IAPsfor that area can be known. But the IAPs from other areas are visible fromthe current area sometimes, so the test must be refined, a way to improve thetest is described below.

For each visible IAP of the current area, tested with the occlusion culling test(which will be called culled IAP), do the following:

Consider all the IAPs in the area accessed through the current culled IAP,which will be called secondary IAPs.

Trace straight lines from the corners and center of each secondary IAP tothe camera, and check if any of the lines intersect with the culled IAP.If there is at least a line verifying the condition, then that secondary IAPis visible through the current culled IAP. The next image shows a scheme:

Page 49: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

This way, starting from the area in which lies the camera, all the visible IAPsfor that area can be known. But the IAPs from other areas are visible fromthe current area sometimes, so the test must be refined, a way to improve thetest is described below.

For each visible IAP of the current area, tested with the occlusion culling test(which will be called culled IAP), do the following:

Consider all the IAPs in the area accessed through the current culled IAP,which will be called secondary IAPs.Trace straight lines from the corners and center of each secondary IAP tothe camera, and check if any of the lines intersect with the culled IAP.

If there is at least a line verifying the condition, then that secondary IAPis visible through the current culled IAP. The next image shows a scheme:

Page 50: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

This way, starting from the area in which lies the camera, all the visible IAPsfor that area can be known. But the IAPs from other areas are visible fromthe current area sometimes, so the test must be refined, a way to improve thetest is described below.

For each visible IAP of the current area, tested with the occlusion culling test(which will be called culled IAP), do the following:

Consider all the IAPs in the area accessed through the current culled IAP,which will be called secondary IAPs.Trace straight lines from the corners and center of each secondary IAP tothe camera, and check if any of the lines intersect with the culled IAP.If there is at least a line verifying the condition, then that secondary IAPis visible through the current culled IAP. The next image shows a scheme:

Page 51: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

This way, starting from the area in which lies the camera, all the visible IAPsfor that area can be known. But the IAPs from other areas are visible fromthe current area sometimes, so the test must be refined, a way to improve thetest is described below.

For each visible IAP of the current area, tested with the occlusion culling test(which will be called culled IAP), do the following:

Consider all the IAPs in the area accessed through the current culled IAP,which will be called secondary IAPs.Trace straight lines from the corners and center of each secondary IAP tothe camera, and check if any of the lines intersect with the culled IAP.If there is at least a line verifying the condition, then that secondary IAPis visible through the current culled IAP. The next image shows a scheme:

Page 52: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Each time an IAP turns out to be visible, its IAP path is saved, as thisprocess iterates with tertiary and more distant IAPs. When making atertiary IAP test, for example, the straight lines from the corners andcenter of the IAP must intersect with its corresponding secondary andculled IAPs.

The test goes on with quaternary and more distant IAPs (whenever thereare remaining tests). At the end, there is a list of areas which are visiblefrom the current camera position and orientation, so the meshes presentin those areas are the candidates to be rendered.

Page 53: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Each time an IAP turns out to be visible, its IAP path is saved, as thisprocess iterates with tertiary and more distant IAPs. When making atertiary IAP test, for example, the straight lines from the corners andcenter of the IAP must intersect with its corresponding secondary andculled IAPs.

The test goes on with quaternary and more distant IAPs (whenever thereare remaining tests). At the end, there is a list of areas which are visiblefrom the current camera position and orientation, so the meshes presentin those areas are the candidates to be rendered.

Page 54: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Now its time to test the visibility of each mesh in the visible areas. The test isslightly different, as meshes are tridimensional objects: for a given area and agiven mesh in that area, straight lines from each corner and the center of thebounding box of the mesh are traced to the camera.

If any of these lines intersect with all the IAPs of the corresponding IAP pathfor the area in which the mesh lies, then that mesh is visible.

Page 55: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Now its time to test the visibility of each mesh in the visible areas. The test isslightly different, as meshes are tridimensional objects: for a given area and agiven mesh in that area, straight lines from each corner and the center of thebounding box of the mesh are traced to the camera.

If any of these lines intersect with all the IAPs of the corresponding IAP pathfor the area in which the mesh lies, then that mesh is visible.

Page 56: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Now its time to test the visibility of each mesh in the visible areas. The test isslightly different, as meshes are tridimensional objects: for a given area and agiven mesh in that area, straight lines from each corner and the center of thebounding box of the mesh are traced to the camera.

If any of these lines intersect with all the IAPs of the corresponding IAP pathfor the area in which the mesh lies, then that mesh is visible.

Page 57: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Each time a mesh passes the test, is added to a vector of meshes. Once thetest ends, the vector is sorted by the depth of the z coordinate of thebounding box.

This method can be improved: below, on the left, an IAP can be seen in darkbrown. Depending on the form of the bounding boxes of the meshes beingtested, the visibility test can fail, as can be seen in the image on the right.

Page 58: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Each time a mesh passes the test, is added to a vector of meshes. Once thetest ends, the vector is sorted by the depth of the z coordinate of thebounding box.

This method can be improved: below, on the left, an IAP can be seen in darkbrown. Depending on the form of the bounding boxes of the meshes beingtested, the visibility test can fail, as can be seen in the image on the right.

Page 59: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Each time a mesh passes the test, is added to a vector of meshes. Once thetest ends, the vector is sorted by the depth of the z coordinate of thebounding box.

This method can be improved: below, on the left, an IAP can be seen in darkbrown. Depending on the form of the bounding boxes of the meshes beingtested, the visibility test can fail, as can be seen in the image on the right.

Page 60: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

A way to fix this is to add a small error bound, to mark as visible thosemeshes which don’t pass the test for a little. Now the same mesh of theprevious image becomes visible. Small spheres corresponding with the cornersand the center point are rendered, giving an idea of the geometry of this typeof simple meshes:

Page 61: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

A way to fix this is to add a small error bound, to mark as visible thosemeshes which don’t pass the test for a little. Now the same mesh of theprevious image becomes visible. Small spheres corresponding with the cornersand the center point are rendered, giving an idea of the geometry of this typeof simple meshes:

Page 62: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Another improvement was introduced by considering the camera as atridimensional object: the camera position is a single point, but the cameraitself constitutes an area, so the test lines were aimed to the corners andcenter point of the camera.

This way, when the central point of the camera is in front of a wall, the visiblemeshes farther than the wall pass the visibility test.

Page 63: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Another improvement was introduced by considering the camera as atridimensional object: the camera position is a single point, but the cameraitself constitutes an area, so the test lines were aimed to the corners andcenter point of the camera.

This way, when the central point of the camera is in front of a wall, the visiblemeshes farther than the wall pass the visibility test.

Page 64: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Another improvement was introduced by considering the camera as atridimensional object: the camera position is a single point, but the cameraitself constitutes an area, so the test lines were aimed to the corners andcenter point of the camera.

This way, when the central point of the camera is in front of a wall, the visiblemeshes farther than the wall pass the visibility test.

Page 65: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

func plat meshes

Some meshes in the Doom 3 level viewer in OpenGL clearly did not appear.Some are complex meshes which must be loaded through an external file in.LWO or .ASE format, and others are the platforms and mobile meshes:elevators, doors...

These meshes don’t belong to a particular area, so a test to find out whichareas belong had to be done, and in the visibility test, test each of thesesurfaces only once. The results for non-specific-area meshes were satisfactory:

Page 66: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

func plat meshes

Some meshes in the Doom 3 level viewer in OpenGL clearly did not appear.Some are complex meshes which must be loaded through an external file in.LWO or .ASE format, and others are the platforms and mobile meshes:elevators, doors...

These meshes don’t belong to a particular area, so a test to find out whichareas belong had to be done, and in the visibility test, test each of thesesurfaces only once. The results for non-specific-area meshes were satisfactory:

Page 67: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

func plat meshes

Some meshes in the Doom 3 level viewer in OpenGL clearly did not appear.Some are complex meshes which must be loaded through an external file in.LWO or .ASE format, and others are the platforms and mobile meshes:elevators, doors...

These meshes don’t belong to a particular area, so a test to find out whichareas belong had to be done, and in the visibility test, test each of thesesurfaces only once. The results for non-specific-area meshes were satisfactory:

Page 68: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

A bit on materials

Doom 3 displays a wide variety of materials, defined by the .mtr files. Each ofthis materials is built with specific keywords, which are detailed here and here.

In order to perform some per-pixel effects, height, normal and specular mapsare needed for each mesh, besides the traditional diffuse map. Doom 3incorporates this textures, specified for each mesh in its definition.

By parsing all the .mtr files (Doom 3 uses more than 2600 differentmaterials), the correct textures can be assigned to each mesh, although onlysimple per-pixel effects were made, like specular and parallax mapping orper-pixel lighting (due to lack of time).

Textures were loaded from a Zip file, an article in Gamedev explains how to dothis (can be read here).

Page 69: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

A bit on materials

Doom 3 displays a wide variety of materials, defined by the .mtr files. Each ofthis materials is built with specific keywords, which are detailed here and here.

In order to perform some per-pixel effects, height, normal and specular mapsare needed for each mesh, besides the traditional diffuse map. Doom 3incorporates this textures, specified for each mesh in its definition.

By parsing all the .mtr files (Doom 3 uses more than 2600 differentmaterials), the correct textures can be assigned to each mesh, although onlysimple per-pixel effects were made, like specular and parallax mapping orper-pixel lighting (due to lack of time).

Textures were loaded from a Zip file, an article in Gamedev explains how to dothis (can be read here).

Page 70: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

A bit on materials

Doom 3 displays a wide variety of materials, defined by the .mtr files. Each ofthis materials is built with specific keywords, which are detailed here and here.

In order to perform some per-pixel effects, height, normal and specular mapsare needed for each mesh, besides the traditional diffuse map. Doom 3incorporates this textures, specified for each mesh in its definition.

By parsing all the .mtr files (Doom 3 uses more than 2600 differentmaterials), the correct textures can be assigned to each mesh, although onlysimple per-pixel effects were made, like specular and parallax mapping orper-pixel lighting (due to lack of time).

Textures were loaded from a Zip file, an article in Gamedev explains how to dothis (can be read here).

Page 71: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

A bit on materials

Doom 3 displays a wide variety of materials, defined by the .mtr files. Each ofthis materials is built with specific keywords, which are detailed here and here.

In order to perform some per-pixel effects, height, normal and specular mapsare needed for each mesh, besides the traditional diffuse map. Doom 3incorporates this textures, specified for each mesh in its definition.

By parsing all the .mtr files (Doom 3 uses more than 2600 differentmaterials), the correct textures can be assigned to each mesh, although onlysimple per-pixel effects were made, like specular and parallax mapping orper-pixel lighting (due to lack of time).

Textures were loaded from a Zip file, an article in Gamedev explains how to dothis (can be read here).

Page 72: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

A bit on materials

The next image shows on the left some meshes. The same meshes, withstandard per-pixel lighting, are shown on the right (point lights are describedas entities of type light in the file .map, with color and radius assigned):

Page 73: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

A bit on materials

The next image shows on the left some meshes. The same meshes, withstandard per-pixel lighting, are shown on the right (point lights are describedas entities of type light in the file .map, with color and radius assigned):

Page 74: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Parallax mapping with multiple point lights

Parallax mapping produces a great effect of realism, and its computationalcost is not exorbitant. The effect developed is based on the Parallax mappingdemo from this web, which had in the past didactic material on DirectX(email me at [email protected] and i will send this demo to you).

This application was programmed in 2006, when the most extended ShaderModel was the 2.0. This Shader Model had a limit of 96 registers and 64instructions, so the limit for the effect was three passes (for three differentpoint lights).

If more than three point lights light a mesh, is neccessary to activate blending(which means a drop in performance) and repeat the effect until all thecontributions on all the lights have been calculated.

Page 75: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Parallax mapping with multiple point lights

Parallax mapping produces a great effect of realism, and its computationalcost is not exorbitant. The effect developed is based on the Parallax mappingdemo from this web, which had in the past didactic material on DirectX(email me at [email protected] and i will send this demo to you).

This application was programmed in 2006, when the most extended ShaderModel was the 2.0. This Shader Model had a limit of 96 registers and 64instructions, so the limit for the effect was three passes (for three differentpoint lights).

If more than three point lights light a mesh, is neccessary to activate blending(which means a drop in performance) and repeat the effect until all thecontributions on all the lights have been calculated.

Page 76: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Parallax mapping with multiple point lights

Parallax mapping produces a great effect of realism, and its computationalcost is not exorbitant. The effect developed is based on the Parallax mappingdemo from this web, which had in the past didactic material on DirectX(email me at [email protected] and i will send this demo to you).

This application was programmed in 2006, when the most extended ShaderModel was the 2.0. This Shader Model had a limit of 96 registers and 64instructions, so the limit for the effect was three passes (for three differentpoint lights).

If more than three point lights light a mesh, is neccessary to activate blending(which means a drop in performance) and repeat the effect until all thecontributions on all the lights have been calculated.

Page 77: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

The following image shows the parallax mapping effect, with a maximum ofthree point lights for each mesh on the left, and for more than three pointlights in the right:

Page 78: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

The following image shows the parallax mapping effect, with a maximum ofthree point lights for each mesh on the left, and for more than three pointlights in the right:

Page 79: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Bibliography

Ultimate Game Programming Allen Sherrod.

http://www.ultimategameprogramming.com, September 2006.

GameDev.net Developer Community.

http://www.gamedev.net, September 2006.

Md5 mesh viewer in OpenGL David Henry.

http://tfc.duke.free.fr, September 2006.

Occlusion Culling Using DirectX 9 Dustin Franklin.

http://www.gamedev.net, September 2006.

MAP file format.

http://www.modwiki.net, September 2006.

MD5 file format.

http://www.modwiki.net, September 2006.

Loading a Texture From a Zip File in DirectX 9 Greg Stewart.

http://www.gamedev.net, September 2006.

Page 80: Programming techniques for First Person Shooters in DirectX 9

Programmingtechniquesfor FirstPerson

Shooters inDirectX 9

Introduction

Gettingstarted

.mapformat andvisibilitytest

func platmeshes

A bit onmaterials

Parallaxmappingwithmultiplepoint lights

Bibliography

Global material keywords.

http://www.modwiki.net, September 2006.

Game Tutorials.

http://www.gametutorials.com, September 2006.