Game Programm Notes
Game Programm Notes
In Computer graphics,
In Computer graphics,3D Translation is a process of moving an object from one position to another
in a three dimensional plane.
Consider a point object O has to be moved from one position to another in a 3D plane.
Let-
This translation is achieved by adding the translation coordinates to the old coordinates of the object
as-
QUATERNIONS
In mathematics, the quaternions are a number system that extends the complex numbers. They
were first described by Irish mathematician William Rowan Hamilton in 1843[1][2] and applied to
mechanics in three-dimensional space. A feature of quaternions is that multiplication of two
quaternions is noncommutative. Hamilton defined a quaternion as the quotient of two directed lines
in a three-dimensional space[3] or equivalently as the quotient of two vectors.[4]
Quaternions are generally represented in the form:
where a, b, c, and d are real numbers, and i, j, and k are the fundamental quaternion units.
Quaternions are used in pure mathematics, and also have practical uses in applied mathematics—in
particular for calculations involving three-dimensional rotations such as in three-dimensional
computer graphics, computer vision, and crystallographic texture analysis.[5] In practical
applications, they can be used alongside other methods, such as Euler angles and rotation matrices,
or as an alternative to them, depending on the application.
In modern mathematical language, quaternions form a four-dimensional associative normed
division algebra over the real numbers, and therefore also a domain. In fact, the quaternions were
the first noncommutative division algebra to be discovered. The algebra of quaternions is often
denoted by H (for Hamilton), or in blackboard bold by (Unicode U+210D, ℍ). It can also be given
by the Clifford algebra classifications Cℓ0,2(ℝ) ≅ Cℓ03,0(ℝ). The algebra H holds a special place in
analysis since, according to the Frobenius theorem, it is one of only two finite-dimensional division
rings containing the real numbers as a proper subring, the other being the complex numbers. These
rings are also Euclidean Hurwitz algebras, of which quaternions are the largest associative algebra.
Further extending the quaternions yields the non-associative octonions, which is the last normed
division algebra over the reals (the extension of the octonions, sedenions, has zero divisors and so
cannot be a normed division algebra).[6]
The unit quaternions can be thought of as a choice of a group structure on the 3-sphere S 3 that gives
the group Spin(3), which is isomorphic to SU(2) and also to the universal cover of
SO(3).
Definition
A quaternion is an expression of the form
where a, b, c, d, are real numbers, and i, j, k, are symbols that can be interpreted as unit-vectors
pointing along the three spatial axes. In practice, if one of a, b, c, d is 0, the corresponding term is
omitted; if a, b, c, d are all zero, the quaternion is the zero quaternion, denoted 0; if one of b, c, d
equals 1, the corresponding term is written simply i, j, or k.
Hamilton describes a quaternion , as consisting of a scalar part and a vector part. The quaternion is
called the vector part (sometimes imaginary part) of q, and a is the scalar part (sometimes real
part) of q. A quaternion that equals its real part (that is, its vector part is zero) is called a scalar, and
is identified with the corresponding real number. That is, the real numbers are a subset of the
quaternions. A quaternion that equals its vector part is called a vector quaternion.
The set of quaternions is made a 4 dimensional vector space over the real numbers, with as a basis,
by the componentwise addition and the componentwise scalar multiplication
A multiplicative group structure, called the Hamilton product, denoted by juxtaposition, can be
defined on the quaternions in the following way:
3D Modeling
3D modeling is utilized as a part of a wide range of ventures, including virtual reality, computer
games, 3D printing, showcasing, TV and movies, logical and medicinal imaging and CAD process
and assembling CAD/CAM.
3D modeling is a way of making 3-dimensional objects. 3D modeling is frequently done through
3D files that can be influenced to the desired measurements of the print.
Without a 3D model, a 3D print is incomprehensible. Subsequently, a 3D visualization is impossible
without a 3D model. Thus, Modeling is the pre-production stage and Rendering is the post-
production stage.
SketchUp, Blender, 3DS Max, Revit, Maya are some of the software used for creating 3D models.
3DRendering
3D Modeling 3D Rendering
Cyberpunk 2077
Call of Duty: Modern Warfare– Ray traced shadows and ambient occlusion
Control– Ray traced reflections, ray traced global illumination and ray traced shadows
Enlisted
Justice Online
MechWarrior V
Wolfenstein Youngblood – Ray traced reflections
Vampire: The Masquerade – Bloodlines 2– Ray traced reflections
Watch Dogs: Legion– Ray traced reflections
Minecraft – Fully path-traced lighting
Synched: Off Planet – Ray traced reflections, ray traced shadows
Either way, we’re sure many more developers are willing to jump on the ray-traced bandwagon, and
we’ll update this page just as soon as we hear of any others.
Shader Model
In the field of 3D computer graphics, the Unified Shader Model (known in Direct3D 10 as "Shader
Model 4.0") refers to a form of shader hardware in a graphical processing unit (GPU) where all of
the shader stages in the rendering pipeline (geometry, vertex, pixel, etc.) have the same capabilities.
They can all read textures and buffers, and they use instruction sets that are almost identica
Earlier GPUs generally included two types of shader hardware, with the vertex shaders having
considerably more instructions than the simpler pixel shaders. This lowered the cost of
implementation of the GPU as a whole, and allowed more shaders in total on a single unit. This was
at the cost of making the system less flexible, and sometimes leaving one set of shaders idle if the
workload used one more than the other. As improvements in fabrication continued, this distinction
became less useful. ATI Technologies introduced a unified architecture on the hardware they
developed for the Xbox 360, and then introduced this in card form in the TeraScale line. Nvidia
quickly followed with their Tesla design. The concept has been universal since then.
Early shader abstractions (such as Shader Model 1.x) used very different instruction sets for vertex
and pixel shaders, with vertex shaders having much more flexible instruction set. Later shader
models (such as Shader Model 2.x and 3.0) reduced the differences, approaching Unified Shader
Model. Even in the Unified model the instruction set may not be completely the same between
different shader types; different shader stages may have a few distinctions. Fragment/pixel shaders
can compute implicit texture coordinate gradients, while geometry shaders can emit rendering
primitives.
Shader Models are components used to help render graphics sent from the CPU to the graphic
card. The version of shader model your computer can support is based in the combination
between your DirectX version and the version your graphics card can support.
DirectX 10.0 and higher will not run in Windows XP.
Lighting
Lighting or illumination is the deliberate use of light to achieve practical or aesthetic effects.
Lighting includes the use of both artificial light sources like lamps and light fixtures, as well as
natural illumination by capturing daylight. Daylighting (using windows, skylights, or light shelves)
is sometimes used as the main source of light during daytime in buildings. This can save energy in
place of using artificial lighting, which represents a major component of energy consumption in
buildings. Proper lighting can enhance task performance, improve the appearance of an area, or
have positive psychological effects on occupants.
Indoor lighting is usually accomplished using light fixtures, and is a key part of interior design.
Lighting can also be an intrinsic component of landscape projects.
Types
List of types of lighting
Task lighting is mainly functional and is usually the most concentrated, for purposes such as
reading or inspection of materials. For example, reading poor-quality reproductions may
require task lighting levels up to 1500 lux (150 footcandles), and some inspection tasks or
surgical procedures require even higher levels.
Accent lighting is mainly decorative, intended to highlight pictures, plants, or other elements
of interior design or landscaping.
General lighting (sometimes referred to as ambient light) fills in between the two and is
intended for general illumination of an area. Indoors, this would be a basic lamp on a table
or floor, or a fixture on the ceiling. Outdoors, general lighting for a parking lot may be as
low as 10-20 lux (1-2 footcandles) since pedestrians and motorists already used to the dark
will need little light for crossing the area.
Methods
Downlighting is most common, with fixtures on or recessed in the ceiling casting light
downward. This tends to be the most used method, used in both offices and homes. Although
it is easy to design it has dramatic problems with glare and excess energy consumption due
to large number of fittings.[9] The introduction of LED lighting has greatly improved this by
approx. 90% when compared to a halogen downlight or spotlight. LED lamps or bulbs are
now available to retro fit in place of high energy consumption lamps.
Uplighting is less common, often used to bounce indirect light off the ceiling and back
down. It is commonly used in lighting applications that require minimal glare and uniform
general illuminance levels. Uplighting (indirect) uses a diffuse surface to reflect light in a
space and can minimize disabling glare on computer displays and other dark glossy surfaces.
It gives a more uniform presentation of the light output in operation. However indirect
lighting is completely reliant upon the reflectance value of the surface. While indirect
lighting can create a diffused and shadow free light effect it can be regarded as an
uneconomical lighting principle.[10][11]
Front lighting is also quite common, but tends to make the subject look flat as its casts
almost no visible shadows. Lighting from the side is the less common, as it tends to produce
glare near eye level.
Backlighting either around or through an object is mainly for accent. Backlighting is used to
illuminate a background or backdrop. This adds depth to an image or scene. Others use it to
achieve a more dramatic effect.
The Game Loop
The game loop is the overall flow control for the entire game program. It’s a loop because the game
keeps doing a series of actions over and over again until the user quits. Each iteration of the game
loop is known as a frame. Most real-time games update several times per second: 30 and 60 are the
two most common intervals. If a game runs at 60 FPS (frames per second), this means that the
game loop completes 60 iterations every second.
There can be many variations of the game loop, depending on a number of factors, most notably the
target hardware. Let’s first discuss the traditional game loop before exploring a more advanced
formulation that’s designed for more modern hardware.
Each of these three phases has more depth than might be apparent at first glance. For instance,
processing inputs clearly involves detecting any inputs from devices such as a keyboard, mouse, or
controller. But those aren’t the only inputs to be considered; any external input must be processed
during this phase of the game loop.
As one example, consider a game that supports online multiplayer. An important input for such a
game is any data received over the Internet, because the state of the game world will directly be
affected by this information. Or take the case of a sports game that supports instant replay. When a
previous play is being viewed in replay mode, one of the inputs is the saved replay information. In
certain types of mobile games, another input might be what’s visible by the camera, or perhaps GPS
information. So there are quite a few potential input options, depending on the particular game and
hardware it’s running on.
Updating the game world involves going through everything that is active in the game and updating
it as appropriate. This could be hundreds or even thousands of objects. Later in this chapter, we will
cover exactly how we might represent said game objects.
As for generating outputs, the most computationally expensive output is typically the graphics,
which may be 2D or 3D. But there are other outputs as well—for example, audio, including sound
effects, music, and dialogue, is just as important as visual outputs. Furthermore, most console
games have “rumble” effects, where the controller begins to shake when something exciting
happens in the game. The technical term for this is force feedback, and it, too, is another output
that must be generated. And, of course, for an online multiplayer game, an additional output would
be data sent to the other players over the Internet.
We’ll fill in these main parts of the game loop further as this chapter continues. But first, let’s look
at how this style of game loop applies to the classic Namco arcade game Pac-Man.
The primary input device in the arcade version of Pac-Man is a quad-directional joystick, which
enables the player to control Pac-Man’s movement. However, there are other inputs to consider: the
coin slot that accepts quarters and the Start button. When a Pac-Man arcade cabinet is not being
played, it simply loops in a demo mode that tries to attract potential players. Once a quarter is
inserted into the machine, it then asks the user to press Start to commence the actual game.
When in a maze level, there are only a handful of objects to update in Pac-Man—the main character
and the four ghosts. Pac-Man’s position gets updated based on the processed joystick input. The
game then needs to check if Pac-Man has run into any ghosts, which could either kill him or the
ghosts, depending on whether or not Pac-Man has eaten a power pellet. The other thing Pac-Man
can do is eat any pellets or fruits he moves over, so the update portion of the loop also needs to
check for this. Because the ghosts are fully AI controlled, they also must update their logic.
Finally, in classic Pac-Man the only outputs are the audio and video. There isn’t any force feedback,
networking, or anything else necessary to output. A high-level version of the Pac-Man game loop
during the gameplay state would look something like what is shown in Listing 1.1.
// Generate Outputs
draw graphics
update audio
loop
Note that the actual code for Pac-Man does have several different states, including the
aforementioned attract mode, so these states would have to be accounted for in the full game’s code.
However, for simplicity the preceding pseudo-code gives a representation of what the main game
loop might look like if there were only one state.
Figure 1.1 The jump is delayed a couple of frames due to input lag.
If a particular game relies on extremely quick response time, including fighting games such as
Street Fighter, this increased input lag may be deemed unacceptable. But for most other genres, the
increased lag may not be particularly noticeable. Several other factors increase input lag. The game
loop can be one of these factors, and some, like the display lag most LCD panels have, might be out
of the programmer’s control. For more information on this topic, check the references at the end of
this chapter, which includes an interesting set of articles on the topic of measuring and solving input
lag in games.
COLOR
Color (American English), or colour (Commonwealth English), is the characteristic of visual
perception described through color categories, with names such as red, orange, yellow, green, blue,
or purple. This perception of color derives from the stimulation of photoreceptor cells (in particular
cone cells in the human eye and other vertebrate eyes) by electromagnetic radiation (in the visible
spectrum in the case of humans). Color categories and physical specifications of color are
associated with objects through the wavelength of the light that is reflected from them. This
reflection is governed by the object's physical properties such as light absorption, emission spectra,
etc.
By defining a color space, colors can be identified numerically by coordinates, which in 1931 were
also named in global agreement with internationally agreed color names like mentioned above (red,
orange, etc.) by the International Commission on Illumination. The RGB color space for instance is
a color space corresponding to human trichromacy and to the three cone cell types that respond to
three bands of light: long wavelengths, peaking near 564–580 nm (red); medium-wavelength,
peaking near 534–545 nm (green); and short-wavelength light, near 420–440 nm (blue).[1][2] There
may also be more than three color dimensions in other color spaces, such as in the CMYK color
model, wherein one of the dimensions relates to a color's colorfulness).
The photo-receptivity of the "eyes" of other species also varies considerably from that of humans
and so results in correspondingly different color perceptions that cannot readily be compared to one
another. Honeybees and bumblebees for instance have trichromatic color vision sensitive to
ultraviolet but is insensitive to red. Papilio butterflies possess six types of photoreceptors and may
have pentachromatic vision.[3] The most complex color vision system in the animal kingdom has
been found in stomatopods (such as the mantis shrimp) with up to 12 spectral receptor types thought
to work as multiple dichromatic units.[4]
The science of color is sometimes called chromatics, colorimetry, or simply color science. It
includes the study of the perception of color by the human eye and brain, the origin of color in
materials, color theory in art, and the physics of electromagnetic radiation in the visible range (that
is, what is commonly referred to simply as light).
Physics of Color
Electromagnetic radiation is characterized by its wavelength (or frequency) and its intensity. When
the wavelength is within the visible spectrum (the range of wavelengths humans can perceive,
approximately from 390 nm to 700 nm), it is known as "visible light".
Most light sources emit light at many different wavelengths; a source's spectrum is a distribution
giving its intensity at each wavelength. Although the spectrum of light arriving at the eye from a
given direction determines the color sensation in that direction, there are many more possible
spectral combinations than color sensations. In fact, one may formally define a color as a class of
spectra that give rise to the same color sensation, although such classes would vary widely among
different species, and to a lesser extent among individuals within the same species. In each such
class the members are called metamers of the color in question.
Texturing
Texture mapping[1][2][3] is a method for defining high frequency detail, surface texture, or color
information on a computer-generated graphic or 3D model. The original technique was pioneered
by Edwin Catmull in 1974.[4]
Texture mapping originally referred to diffuse mapping, a method that simply mapped pixels from
a texture to a 3D surface ("wrapping" the image around the object). In recent decades, the advent of
multi-pass rendering, multitexturing, mipmaps, and more complex mappings such as height
mapping, bump mapping, normal mapping, displacement mapping, reflection mapping, specular
mapping, occlusion mapping, and many other variations on the technique (controlled by a materials
system) have made it possible to simulate near-photorealism in real time by vastly reducing the
number of polygons and lighting calculations needed to construct a realistic and functional 3D
scene.
Texture Map
A texture map[5][6] is an image applied (mapped) to the surface of a shape or polygon.[7] This
may be a bitmap image or a procedural texture. They may be stored in common image file formats,
referenced by 3d model formats or material definitions, and assembled into resource bundles.
They may have 1-3 dimensions, although 2 dimensions are most common for visible surfaces. For
use with modern hardware, texture map data may be stored in swizzled or tiled orderings to
improve cache coherency. Rendering APIs typically manage texture map resources (which may be
located in device memory) as buffers or surfaces, and may allow 'render to texture' for additional
effects such as post processing or environment mapping.
They usually contain RGB color data (either stored as direct color, compressed formats, or indexed
color), and sometimes an additional channel for alpha blending (RGBA) especially for billboards
and decal overlay textures. It is possible to use the alpha channel (which may be convenient to store
in formats parsed by hardware) for other uses such as specularity.
Multiple texture maps (or channels) may be combined for control over specularity, normals,
displacement, or subsurface scattering e.g. for skin rendering.
Multiple texture images may be combined in texture atlases or array textures to reduce state
changes for modern hardware. (They may be considered a modern evolution of tile map graphics).
Modern hardware often supports cube map textures with multiple faces for environment mapping.
Texture application
This process is akin to applying patterned paper to a plain white box. Every vertex in a polygon is
assigned a texture coordinate (which in the 2d case is also known as UV coordinates). This may be
done through explicit assignment of vertex attributes, manually edited in a 3D modelling package
through UV unwrapping tools. It is also possible to associate a procedural transformation from 3d
space to texture space with the material. This might be accomplished via planar projection or,
alternatively, cylindrical or spherical mapping. More complex mappings may consider the distance
along a surface to minimize distortion. These coordinates are interpolated across the faces of
polygons to sample the texture map during rendering. Textures may be repeated or mirrored to
extend a finite rectangular bitmap over a larger area, or they may have a one-to-one unique
"injective" mapping from every piece of a surface (which is important for render mapping and light
mapping, also known as baking).
Texture space
Texture mapping maps the model surface (or screen space during rasterization) into texture space;
in this space, the texture map is visible in its undistorted form. UV unwrapping tools typically
provide a view in texture space for manual editing of texture coordinates. Some rendering
techniques such as subsurface scattering may be performed approximately by texture-space
operations.
Multitexturing
Multitexturing is the use of more than one texture at a time on a polygon.[8] For instance, a light
map texture may be used to light a surface as an alternative to recalculating that lighting every time
the surface is rendered. Microtextures or detail textures are used to add higher frequency details,
and dirt maps may add weathering and variation; this can greatly reduce the apparent periodicity of
repeating textures. Modern graphics may use more than 10 layers, which are combined using
shaders, for greater fidelity. Another multitexture technique is bump mapping, which allows a
texture to directly control the facing direction of a surface for the purposes of its lighting
calculations; it can give a very good appearance of a complex surface (such as tree bark or rough
concrete) that takes on lighting detail in addition to the usual detailed coloring. Bump mapping has
become popular in recent video games, as graphics hardware has become powerful enough to
accommodate it in real-time.[9]
Texture filtering
The way that samples (e.g. when viewed as pixels on the screen) are calculated from the texels
(texture pixels) is governed by texture filtering. The cheapest method is to use the nearest-
neighbour interpolation, but bilinear interpolation or trilinear interpolation between mipmaps are
two commonly used alternatives which reduce aliasing or jaggies. In the event of a texture
coordinate being outside the texture, it is either clamped or wrapped. Anisotropic filtering better
eliminates directional artefacts when viewing textures from oblique viewing angles.
Baking
As an optimization, it is possible to render detail from a complex, high-resolution model or
expensive process (such as global illumination) into a surface texture (possibly on a low-resolution
model). Baking is also known as render mapping. This technique is most commonly used for light
maps, but may also be used to generate normal maps and displacement maps. Some computer
games (e.g. Messiah) have used this technique. The original Quake software engine used on-the-fly
baking to combine light maps and colour maps ("surface caching").
Baking can be used as a form of level of detail generation, where a complex scene with many
different elements and materials may be approximated by a single element with a single texture,
which is then algorithmically reduced for lower rendering cost and fewer drawcalls. It is also used
to take high-detail models from 3D sculpting software and point cloud scanning and approximate
them with meshes more suitable for realtime rendering.
Rasterisation algorithms
Various techniques have evolved in software and hardware implementations. Each offers different
trade-offs in precision, versatility and performance.
Standards
PHIGS
PHIGS was the first commercial scene graph specification, and became an ANSI standard in 1988.
Disparate implementations were provided by Unix hardware vendors. The HOOPS 3D Graphics
System appears to have been the first commercial scene graph library provided by a single software
vendor. It was designed to run on disparate lower-level 2D and 3D interfaces, with the first major
production version (v3.0) completed in 1991. Shortly thereafter, Silicon Graphics released IRIS
Inventor 1.0 (1992), which was a scene graph built on top of the IRIS GL 3D API. It was followed
up with Open Inventor in 1994, a portable scene graph built on top of OpenGL. More 3D scene
graph libraries can be found in Category:3D scenegraph APIs.
X3D
X3D is a royalty-free open standards file format and run-time architecture to represent and
communicate 3D scenes and objects using XML. It is an ISO-ra
tified standard that provides a system for the storage, retrieval and playback of real-time graphics
content embedded in applications, all within an open architecture to support a wide array of
domains and user scenarios.