# 3D Primer

## Author information

 Author: Jeroen Ruigrok van der Werven Revision: $Revision: 231$ Date Revision: $Date: 2012-07-27 13:05:44 +0200 (vr, 27 jul 2012)$

## Introduction

I started this document because I like the subject of computer graphics and see a lot of ties with previous work I did on toolchains.

A lot of this right now is really unstructured. Basically a sort of brain dump, it will get fixed in the end.

This document uses MathML for rendering formulae as they were intended to be shown. In order to render these formulae on non-MathML compliant browsers this page uses MathJax.

The default font support on Windows 7 and MacOS X is good enough to display many formulae. You might want to install Stix Fonts to get even better coverage.

# 3D Basics

## Basic Terminology & Glossary

For non-native English speakers some geometric and mathematical terms might be radically different than those in their own language. My own native language, Dutch, is a good example of this knowing ‘loodrecht’ as the word that is known as ‘perpendicular’ in English.

The world of 3D graphics relies heavily upon mathematical concepts, so any affinity or rudimentary experience with geometry and set theory makes things a lot easier to understand.

• blitter - in the earlier years of personal computing a co-processor dedicated to memory data transfers
• pixel - contraction of picture element, the smallest unit of digital images
• PSU - pixel shader unit
• ROP - render output
• texel - contraction of texture element, the smallest unit of a texture, the texture map equivalent to a pixel
• texture - the feel of a surface or fabric, in the 3D world
• TMU - texture mapping unit, also known as the graphical pipeline

## Background on 3D

Phong reflection model.

$S p = C p cos ⁡ i 1 - d + d + W ⁡ i cos⁡ s n$
Formula: the Phong reflection model
$I p = k a i a + ∑ lights k d L · N i d + k s R · V α i s$

Rendering.

Formula: Kijiya's rendering equation
$I⁡ x x ′ = g⁡ x x ′ ε⁡ x x ′ + ∫ S ρ⁡ x x ′ x ″ I⁡ x ′ x ″ d x ″$
Formula: the rendering equation
$L o x w → = L e x w → + ∫ Ω f r x w → ′ L i x w → ′ ( w → ′ · n → ) d ⁢ w → ′$
Formula: the bidirectional reflectance distribution function
$f r x w → ′ w → = d ⁢ L r x w → L i x w → ′ ( w ′ → · n → ) d ⁢ w → ′$

# Typical 3D Features

• alpha blending
• alpha compositing
• anti-aliasing
• BSP trees
• filtering:
• anisotropic
• bilinear
• percentage closer filtering (PCF)
• trilinear
• fog?
• High Dynamic Range Rendering (HDRR)/High Dynamic Range Lighting (HDR lighting)
• light source tracing
• MIP mapping
• n-patches
• octree ray tracing
• photon mapping
• polygon offset
• pixel shader (DirectX term)/program fragments (OpenGL term)
• rasterization
• ray tracing
• rendering equation
• reyes algorithm
• scan-line algorithm
• skinning
• subsurface scattering
• texture mapping:
• bump mapping
• displacement mapping
• environment mapping
• luminance mapping
• reflection mapping
• specular mapping
• tone mapping
• tweening
• vertices
• z-buffering

URL dump:

### Alpha blending

Alpha blending is a very simple technique to create the effect of transparency. It accomplishes this by using a variable factor to determine the amount of blending between the foreground colour and the background colour.

In mathematics this is written as such:

Formula: alpha blending
$r g b blended = α r g b foreground + 1 - α × r g b background ∧ 0 ≤ α ≤ 1$

So an α value of 0 results in an RGB value that is totally transparent, in other words it allows the background to show through. If the α value is 1, however, the foreground is totally opaque and obscures the entire background. Any α value in-between 0 and 1 will balance the foreground and background colour appropriately. Of course, the caveat here is that the α value applies equally to the individual RGB values. For appropriately filtered alpha blending see

TODO:

DirectX functions: OpenGL functions:

### Anisotropic Filtering

When one take a certain image of a specific size and scale it in a different X and Y

TODO:

### Anti-Aliasing

Anti-aliasing is a technique goes against a phenomenon called edge-aliasing. But that still does not mean anything. In short: edge-aliasing is the effect that causes the so-called staircase (jaggies) effect in an image. In a drawing program when you have a white background and a black foreground colour and you draw a diagonal line you will see the pixels on-screen display a staircase effect. A pixel tends to be a cube form and thus a resulting image will have noticeable edges. Just like when you would recreate that line as a mosaic. Anti-aliasing is the process of applying a filter over the image to counter the effect of edge-aliasing.

Types of Antialiasing Methods:

• Supersampling schemes:
• Ordered Grid Super-Sampling [OGSS]: Basically OGSS renders the image at a higher resolution than it needs to output, takes colour samples, averages these and scales the image down to the intended resolution. Typical scaling factors used are: 2X, 4X, 9X, 16X. 2X means the scaling takes place on only one axis (either X or Y) and thus only two colour samples are taken on the scaled axis to make up the final colour for the pixel. A 4X factor means that the total image is rendered twice as large on both the X and Y axis and thus four samples are taken (2x2 grid) and averaged to produce the final colour for the pixel. A 9X factor scales three times on each axis and thus takes nine samples (3x3 grid). A 16X factor scales four times on each axis and thus takes sixteen samples (4x4 grid).
• Rotated Grid Super-Sampling [RGSS]: RGSS was already in use by the, now extinct, 3Dfx Voodoo 5 card. RGSS is a variantion of the OGSS method. Instead of using a basic square grid pattern for sampling, RGSS thus uses a sort of diamond shaped pattern. The advantage of this method is that the human eye gets tricked because the regularities, which still exist with a regular grid-based approach, are nullified with this method.
• Multisampling schemes:
• MultiSampling AntiAliasing [MSAA]
• Quincunx AntiAliasing [MSAA + Blur Filter]

TODO:

FSAA - Full Screen Anti-Aliasing

TODO:

TODO:

### MIP mapping

Multum In Parvo (MIP; Latin for 'much in little') mapping is a texturing technique to improve the visual quality of computer graphics. In drawing 3D scenery objects that approach the horizon are drawn proportionally smaller in size. On the computer drawing like this will result in the objects in the distance losing their details due to their size. This leads to edge-aliasing, which leads to interference patterns forming commonly known as moiré.

To counter this MIP mapping, as stated above, uses a variety of scaled down objects. The normal texture might be drawn/rendered at 512x512 pixels and is what you see when you are very close up to a surface with that texture. For displaying surfaces with the texture in the distance it has pre-rendered and filtered textures in, typically, powers of two resolutions. So the GPU might have already pre-rendered 256x256, 128x128, 64x64, perhaps all the way down to 8x8, or even 2x2 resolutions.

MIP mapping scales and filters a texture map into multiple versions before applying it to the wire frame model. These versions are of varying resolution and details. At close distances to the camera viewpoint, the texture map appears in its original full detail. For medium distances, a smaller texture that is half the resolution of the original is used. Even further distances display texture maps that are a quarter the resolution and so on. Each of these stages is known as a MIP map level.

By choosing the appropriate texture map resolution and detail, MIP mapping ensures that pixels do not get lost at further distances. Instead, properly averaged smaller versions of the original texture map are used. Since low resolution textures are used for further distances, other benefits of MIP mapping include reduced memory bandwidth requirements.

TODO:

### Polygon offset

Adds an appropriate offset to force coincident z-values apart to cleanly separate a polygon edge from its highlighting line

Fill in.

TODO:

TODO:

TODO:

# 3D Software Development Kits

Right now the two major Software Development Kits (SDKs) are:

• OpenGL, by the OpenGL Architecture Review Board (ARB)

As of this writing DirectX has version 11 out and OpenGL has specification 4.2 out.

Both specifications are quite powerful in their own right. The choice for selecting one of the other is a choice you make based on your requirements (which you do have, right?).

TODO:

## DirectX

Since DirectX is build up from multiple sub-parts this document will only highlight the graphics parts in order to cut back on the size of the total document.

DirectX Programming Documentation

DirectX has had the following releases:

• 1.0 (1995) - supported with this version were:
• Control of the graphics card's blitter.
• Double-buffered and page flipping graphics.
• Hardware-assisted overlays with z-ordering.
• Texture maps with/without palettes.
• Z-buffers.
• 2.0 (1996) - supported with this version were:
• DirectDraw extended with MIPmaps.
• The Direct3D architecture introduced is built up from three modules that form a virtual 3D rendering engine:
• Transformation module
• Lighting module
• Rasterisation module
• 3.0 (1996) - supported with this version were:
• something
• 4.0 - this version has never been released to public.
• 5.0 (1997) - supported with this version were:
• 5.1 (199?) - supported with this version were:
• 5.2 (1998) - supported with this version were:
• 6.0 (1998) - supported with this version were:

The main feature of DirectX 6 is the support for environment mapped bump mapping

• 6.1 (1999) - supported with this version were:
• 7.0 (1999) - supported with this version were:
• Direct3D now supports device-state blocks, geometry blending, cubic environment mapping, user-defined clipping planes.
• DirectInput now supports up to eight mouse buttons, exclusive keyboard access and delayed force-feedback effect start. Also reading and writing of force-feedback effect files.
• DirectSound features improved hardware voice management as well as new 3D audio processing algorithms (for better CPU utilisation).
• DirectPlay supports 'ripple launching'. A ripple launch is where one application is required to launch another application.
• DirectDraw stereo support for active devices.
• 7.0a (2000-02):
• DirectInput provided improved force-feedback performance.
• 7.1 (2000):
• 8.0 (2000):
• DirectShow added to the DirectX software collection.
• DirectInput now support action mapping.
• DirectX Audio is the name for the integrated DirectMusic and DirectSound components, allowing DirectMusic to control wave files or other resources.
• DirectX Graphics is the name for the integrated Direct3D and DirectDraw components. Added support for programmable shaders.
• DirectPlay now supports voice communication between players.
• 8.0a (2001)
• DirectInput fix for disabled buttons which worked on previous of DirectX.
• 8.0b (2001):
• D3DX library bug fix release
• 8.1 (2001):
• New pixel shader models 1.2, 1.3, and 1.4.
• New high precision texture formats.
• New n-Patch quadratic interpolation order.
• New dynamic texture support.
• New D3DX methods.
• 8.1b (2002):
• 9.0 (2002):
• Introduction of shader model 2.0
• 9.0a (2003):
• 9.0b (2003):
• MIDI security fix release.
• 9.0c (2004):
• Introduction of shader model 3.0
• 10 (2007-02):
• http://www.beyond3d.com/content/articles/14/
• 10.1 (2008-03):
• 11 (2009-??):

DirectX was introduced by Microsoft in 1995. It is based on their Component Object Model (COM) technology. Thus DirectX has been object oriented from the start. Prior to version 8.0 DirectX was rather cumbersome to program, since it required a lot of complex operations. Version 4 was never released and was solely known/used in-house

DirectX specifics:

• Limited to Windows only
• basically aimed at game development
• build up from multiple subcomponents:
• Direct3D: Direct3D provides for drawing of 3D primitives.
• data formats:
• Floating point z buffer formats
• 16-bit floating point vertex and texture formats
• 64-bit integer and 32-bit floating point texture formats
• 10:10:10:2 pixel formats
• Discardable depth and stencil buffers
• Light-weight mipmap
• two-sided stencils
• Support for 2D/video/GDI features, including:
• Support for video hardware acceleration
• D operations, e.g., stretch, BLT, scissoring
• GDI interoperability with GetDC method
• New 3D rendering features, including:
• Displacement maps
• Depth biasing
• Antialiased lines
• Constant blend factor
• Separate alpha channel blending
• Multisampling quality control parameter
• Tesselation
• Multi-Element Texture support
• Multiple render targets
• Autogenerated mipmaps
• Spherical TexGen mode
• Miscellaneous:
• New vertex stream declarations
• Cleaned up interfaces to Swap Effects and Presentation Rates
• Improved monitor refresh rate heuristics
• Gamma correction
• Color-converting windowed presentation
• New vertex and pixel shader models for current and future hardware
• Pixel shader models 2.0 and 3.0
• Vertex shader models 2.0 and 3.0

D3DX New features:

DirectX 9 introduces a new high level shading language for shader programming. This language provides the ability to more easily write shaders with functions, arbitrary variable names, conditionals, and loops.

The shader compiler now supports the following profiles: vs_1_1, vs_2_0, ps_1_1, ps_1_2, ps_1_3, ps_1_4, ps_2_0, ps_2_sw.

The Effect framework has undergone some exciting changes for DirectX9, specifically the addition of the ID3DXEffectCompiler interface. The Effect compiler interface can be used for shader specialization. i.e. marking a global variable as literal for a specific compile of the shader.

Added variable sharing between effects. Variables in effects files declared with the keyword "share" will be shared across all effects created with a given effect pool.

A new animation subsystem and mesh hierarchy loader are now included.

The mesh library now supports arbitrary vertex declarations (single stream only).

CloneMesh handles all data type conversions. i.e. FLOAT2 to FLOAT16_2, D3DDECLTYPE_DEC3N...

Patch support is included in the mesh library, including Adaptive tessellation.

• DirectDraw: DirectDraw provides for drawing raster graphics.
• DirectInput: DirectInput provides the developer with an interface to myriad input devices, including support for force feedback.
• DirectMusic: DirectMusic provides for playback of soundtracks. It also allows the composer to dictate what events will trigger transitions in the music to blend from one piece to another or to simply add more tempo, decrease tempo, increase volume or the intensity, all in order to supplement the gameplay. In other words it provides movie-like music control. It is based on MIDI with the Downloadable Sounds (DLS) feature to use custom sounds in combination with the MIDI power.
• DirectPlay: DirectPlay is a set of tools that simplify communications across networks, the Internet, or modems. The tools allow game players to find game sessions easily to help manage the flow between hosts and players.
• DirectSetup: DirectSetup provides a simple API for installing DirectX from your customized application. With DirectX being a complex product, this component greatly simplifies the process of installation.
• DirectShow: DirectShow provides multimedia support for video files such as AVIs and MPGs. This component of DirectX that was once an outside API is integrated with the release DirectX 8.
• DirectSound: DirectSound provides for playback and recording of waveform sound.

## OpenGL

### OpenGL background

OpenGL specifics:

OpenGL was begun by Silicon Graphics, Incorporated (SGI). The name is a short form for 'Open Graphics Library'.

OpenGL, through its extension feature, allows vendors to more easily export their own API to provide functionality. Until the ARB standardises on a specific API it means you may encounter vendors offering the same functionality through widely different APIs. This, of course, has both its advantages as disadvantages.

OpenGL is based on a state machine accessed through a C API.

### OpenGL features

OpenGL has the following versions defined:

• 1.0 - January, 1992
• 1.1 - January, 1997
• Introduction of vertex arrays,
• Introduction of polygon offset, a way to remedy stitching and z-fighting,
• Logic ops
• Textures
• 1.2 - March, 1998
• 1.2.1 - October, 1998
• 1.3 - August, 2001
• 1.4 - July, 2002
• 1.5 - July, 2003
• 2.0 - September, 2004
• 2.1 - July, 2006
• 3.0 - July, 2008
• 3.1 - May, 2009
• 3.2 - August, 2009
• 3.3 - March, 2010
• 4.0 - March, 2010
• 4.1 - July, 2010
• 4.2 - August, 2011

OpenGL 2.0 provides the following:

• Programmable shading: - Shader Objects - Shared Programs - OpenGL Shading Language is a core feature now,
• Multiple Render Targets
• Non-Power-Of-Two Textures
• Point Sprites
• Separate Stencil

# Hardware

Documenting how 3d hardware generally is built up and how it progressed through history.

Blah.

Blah.

Blah.

## NVIDIA®

NVIDIA generally uses the identifier NVnn to label their computer chip products. In the past a Cnn identifier has been used for a few products, all of them based on HyperTransport. More recently they seem to have started using the identifier Gnn.

•  Name NV1 Transistors 1 million Background released in September 1995, this design was based on quadratic surfaces and the system used VRAM or Fast Page Mode (FPM) DRAM
• NV2 - abandoned design based on quadratic surfaces
• NV3 - released in April 1997, named RIVA 128, NVIDIA's first native Direct3D-supporting design, 1 PSU, 1 TMU, 1 ROP, 128-bit memory bus, typical memory bandwidth of 1.6 GiB/s, up to 8 MiB of RAM, up to an 3D resolution of 960x720, PCI and AGP 1x, 2x, DirectX 5, OpenGL 1.0, 350 nm fabrication
• NV4 - released in 1998, named RIVA TNT, first NVIDIA dual pixel pipeline (TNT stands for TwiN Texel), 2 PSU, 2 TMU, 2 ROP, 128-bit memory bus, typical memory bandwidth of 1.7 GiB/s, up to 16 MiB of RAM, DirectX 6, OpenGL 1.1, 350 nm fabrication
• NV5 - released in 1999, named RIVA TNT2, featured AGP 4x support, up to 32 MiB of RAM, and higher clock speeds, 128-bit memory bus, typical memory bandwidth of 2.4 GiB/s, 150 MHz RAMDAC, 32-bit colour for 3D, support for 2048x2048 pixel textures, 250 nm fabrication
• NV6 - released in 1999, named Vanta or TNT2 M64, 64-bit memory bus, 250 and 220 nm fabrication
• NV10 - released in August 1999, named the GeForce 256 and the first GPU for the PC market to feature a hardware transform and lighting (T&L) implementation, 220 nm fabrication
• NV11 - 2000, 180 nm fabrication
• NV15 - released in April 2000, named GeForce2 and featured a dual texture processor per pipeline (4x2) design - typical memory bandwidth of 5.3 GiB/s, 1.6 Gigatexel fill rate, 25 Million triangles/s, 8 texels/clock cycle, OpenGL 1.2 compliant, 350 MHz RAMDAC, double, triple, and quad buffering, YUV 4:2:2 and 4:2:0, Z/stencil buffer, 180 and 150 nm fabrication
• NV16 - 2000, 180 nm fabrication
• NV17 - 2002, 150 nm fabrication
• NV18 - 2002, 150 nm fabrication
• NV18B - 2002, 150 nm fabrication
• NV20 - released in February 2001, named GeForce3, 180 and 150 nm fabrication
• NV25 - released in February 2002, named GeForce4 Ti, 150 nm fabrication
• NV28 - 2003, 150 nm fabrication
• NV30 - released in November 2002, named GeForce FX, 130 nm fabrication
• NV31 - 2003, 130 nm fabrication
• NV34 - 2003, 130 nm fabrication
• NV35 - 2003, 130 nm fabrication
• NV36 - 2003, 130 nm fabrication
• NV38 - 2003, 130 nm fabrication
• NV40 - released in April 2004, named GeForce6, 130 and 110 nm fabrication
• NV41 - 2005, 130 and 110 nm fabrication
• NV42 - 2005, 110 nm fabrication
• NV43 - 2005, 110 nm fabrication
• NV44 - 2005, 110 and 90 nm fabrication
• NV44A - 2005, 110 nm fabrication
• NV45 - 2004, 130 nm fabrication
• C51G - 2005, 110 nm fabrication
• C51PV - 2005, 90 nm fabrication
• C51PVG - 2005, 110 nm fabrication
• G70/NV47 - released in June 2005, named GeForce 7, 110 nm fabrication
• G71 - 2006, 90 nm fabrication
• G72 - 2006, 90 nm fabrication
• G73 - 2006, 90 nm fabrication
• G73-B1 - 2006, 80 nm fabrication
• C86PV - 2007, ? nm fabrication
• C86S - 2007, ? nm fabrication
• G80 - released in November 2006, named GeForce 8, 90 nm fabrication, 681 million transistors
• G84 - 2007, named GeForce 8, 80 nm fabrication, 289 million transistors
• G86 - 2007, named GeForce 8, 80 nm fabrication, 210 million transistors
• G92 - 2007, 65 nm fabrication, 754 million transistors
• G92a - 2008, 65 nm fabrication, 754 million transistors
• G92b - 2008, 55 nm fabrication, 754 million transistors
• G94a - 2008, 65 nm fabrication, 505 million transistors
• G94b - 2008, 55 nm fabrication, 505 million transistors
• G96a - 2008, 65 nm fabrication, 314 million transistors
• G96b - 2008, 55 nm fabrication, 314 million transistors
• G98 - 2007, 65 nm fabrication, ? million transistors
• G200 - 2008, 65 nm fabrication, 1400 million transistors
• G200b - 2008, 55 nm fabrication, 1400 million transistors
• G215 - 2008, 40 nm fabrication, 727 million transistors
• G216 - 2008, 40 nm fabrication, 486 million transistors
• G218 - 2008, 40 nm fabrication, 260 million transistors
• Fermi - 2010, 40 nm fabrication,

Blah.

Blah.

Blah.

Blah.