0% found this document useful (0 votes)
15 views

Computer Graphics - Jaish Khan

Uploaded by

Alex bhai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Computer Graphics - Jaish Khan

Uploaded by

Alex bhai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Computer Graphics - Jaish Khan

It is the branch of science and technology concerned with methods and techniques
for
converting data to or from visual presentation using computers.

It is used in many different areas like CAD, Education and Entertainment and creating
things like GUIs, Art, Simulations/VR and Visualization.

A Graphics API is used for creating/interacting with graphics without having to deal
with low level system system stuff like window handling.

There are 6 components in a Computer Graphics system.

CPU, GPU, Input, Output, Memory, Frame Buffer

Graphics/Display Controller -> Translator between the computer and the the display.

Graphics Pipeline
The processes it takes to render graphics on the screen. It can generally be divided
into 3 parts.

1. Application Step
This stage happens entirely on the CPU and is controlled by your application.

This is where you define the scene data

3D Models making up the scene.


Materials applied to those models.
Lights illuminating the scene.
Camera position/orientation.

Animation, Collision detection and Scene management also happen here.

2. Geometry Step
This is where all the objects are prepared for rendering.

This prepares the 3D models for the rasterization step.

Vertices are transformed (by model, view or projection).


Shaders are used (like Vertex Shader, Geometry Shader etc.).
Clipping (The process of removing geometry that is not in view) also happens here.

3. Rasterization Step
This is where primitives (usually triangles) are converted into fragments.

This bridges the gap between 3D and 2D.

Checks which triangles are visible from the Camera.


Things like Culling are used to removing triangles that are not seen by the
Camera.
Lighting, Texture, Blending and Shading calculations are done.

At the end Fragment Shaders are used to determine the final pixel (color) that is to be
shown based on the calculations done.

Displaying Images
Display Attributes
Refresh Rate -> The redrawing of image on a screen.
It is measured in Hertz.
Higher refresh rate results in smoother motion and better for eye comfort.

Contrast Ratio -> The difference between the brightest and the darkest colors that a
display is able to produce.
It is shown using a ratio.
Higher contrast ratio results in darker blacks and brighter whites.

Response Time -> The time it takes for a monitor to change from one color to another.
It is measured in milliseconds.
Higher response time results in reduced ghosting (images leaving a trail behind).

Display Resolution -> The total amount of pixels used in the screen.
It is shown using width x height.
Higher resolution results in sharper/clearer images.

Pixel Density -> The average amount of pixels per an inch of screen.
It is measured in PPI (pixels per inch)
Higher pixel density results in sharper/clearer images.
To calculate -> √ (W idth
2 2
+ H eight )/DiagonalI nches

Aspect Ratio -> The width divided by the height of a display.


It is shown using a ratio.
Common aspect ratios include 16:9 (Wide), 4:3 (Standard) and 21:9 (Ultra Wide).
To calculate -> Reduce W idth/H eight into the simplest form.
Frame Buffer -> The area where image information of next frame is temporarily stored.
It is calculated in terms of Bytes but can be converted to KBs.
Higher resolutions and require bigger frame buffer.
Video Controller -> Used to control the operation of the display device by accessing
the frame buffer to refresh the screen.
To calculate -> (Resolution×BitsP erP ixel)/8

Bit Depth -> No of bits per pixel.


Bitmap -> Frame buffer with 1 bit depth.
Pixmap -> Frame buffer with 1+ bit depth.
High Color -> 16 bit depth
True Color -> 32 bit depth

Pixel Access Rate -> Resolution×F ramerate


Access Time per Pixel -> 1/AccessRate

Resolution Name Dimensions Aspect


(pixels) Ratio
Ultra High-Definition 8K (8K UHD) 7680 x 4320 16:9
Ultra-Wide High-Definition 5K (5K UHD) 5120 x 2160 21:9
Ultra High-Definition 4K (4K UHD) 3840 x 2160 16:9
Ultra-Wide Quad High-Definition 2K (UWQHD) 3440 x 1440 21:9
Quad High-Definition 2K (QHD) 2160 x 1440 16:9
Ultra-Wide Full High-Definition 1080p 2560 x 1080 21:9
(UWFHD)
Full High-Definition 1080p (FHD) 1920 x 1080 16:9
High-Definition 720p (HD) 1080 x 720 16:9
Standard-Definition 480p (SD) 640 x 480 16:9

Types of Displays
CRT (Cathode Ray Tube)
Uses an electron gun on a phosphorus film to create images.

A focusing system and a deflection system are used to aim the light exactly where
we want.

Monochrome CRT (Black and White) -> Used a single white colored electron gun.
Color CRT (Full Color)
Beam Penetration Method -> Uses 2 color films of phosphor. Color depends
on how far the beam penerates in the layers.
Shadow Masking Method -> Uses 3 color dots of phosphor and 3 electron
guns of each color. Color depends on which gun is used.

Raster Scan

The electron beam is swept across the screen, one row at a time from top to bottom.

Each row that is scanned is called a Scan Line. These scan lines can be scanned one-
by-one in order (Progressive) or in odd-even pairs (Interlacing).

Horizontal Retrace -> When it scans an entire row it goes to the start of the next row.
Vertical Retrace -> When it scans an entire screen (all rows) it goes to the start of the
screen.

Random Scan (Vector Scan)

The electron beam is directed to the parts of the screen where a picture is to be
drawn.

Flat Panel Displays


Non-Emissive Displays

They borrow light from an external light source (usually a backlight).

Transmissive Displays (backlight as a light source)

LCD (Liquid Crystal Display) -> Uses an RGB filter with a CCFL backlight to create
images.

TN (Twisted Nematic) -> Uses liquid crystals that twist to pass light through.
Best refresh rate and response time.
IPS (In-Plane Switching) -> Uses liquid crystals that are fixed and aligned with the
glass.
Best color and viewing angle.
VA (Vertical Alignment) -> Mix of TN and IPS.
Average for everything.

Reflective Displays -> (reflections as a light source)

Transflective Displays -> (both Transmissive and Reflective)

Emissive Displays

They create their own light and each pixel is capable of individually switching on/off
which results in pure blacks (high contrast ratios).
LED (Light Emitting Diode) -> Uses a layer of pixels infront of an LED backlight.

OLED (Organic LED) -> Uses a layer of pixels which have their own light.
AMOLED (Active Matrix OLED)

PDP (Plasma Display) -> Uses small pockets of gas/plasma. Very expensive and not
much used.
FED (Field Emission Display) -> Uses a field of electron to target a phosphorus film to
create color. Not used these days.

Touch Enabled Displays


Displays that can also be provided input by using a conductive surface like a finger or
a pen.

They have a digitizer layer which creates an electric field, which when disturbed
catches touch inputs.

Image Formats
Raster Image Formats
Raster Image Storage -> Stored in individual points to display.

1. JPEG (Joint Photographic Experts Group) -> Lossy Format, uses an algorithm to
remove excess information that human eyes cannot see.
8 bits per channel for R, G, B each -> 24 bits total.
2. PNG (Portable Network Group) -> Lossless Format, allows for transparency.
PNG-32 -> 8 bits, 4 channels (R, G, B, A).
PNG-24 -> 8 bits, 3 channels (R, G, B).
PNG-8 -> 8 bits, single chanel.
3. GIF (Graphics Interchange Format) ->
4. TIFF (Tagged Image File Format) ->
16 bits per channel for R, G, B

Vector Image Formats


Vector Image Storage -> Stored in instructions to draw with.

1. SVG (Scalable Vector Graphics) -> Used for drawings/icons/shapes.


2. PDF (Portable Document Format) -> Used for finalized documents.

Degrees of Freedom (DOF)


Number of ways that something can move/rotate in.
1D Objects only have 1 DOF
Moving (in x-axis)
2D Objects have 3 DOF
Moving (in x-axis)
Moving (in y-axis)
Rotating (between x-y)
3D Objects have 6 DOF
Moving (in x-axis) -> Sway
Moving (in y-axis) -> Heave
Moving (in z-axis) -> Surge
Rotating (between x-y) -> Roll
Rotating (between y-z) -> Pitch
Rotating (between x-z) -> Yaw

2D Image Transformations
Changing the image in one way or another.
Rigid Transformation -> If a transformation preserves the points. Translation, Rotation,
Reflection but not Scale or Shear.

Translation
Moving the object from one point to another.

1 0
⎡ ⎤

0 1
⎣ ⎦
Tx Ty

Rotation
Turning the object on its axis.

Rotate based on the angle given.

cosx −sinx
[ ]
sinx cosx

Scale
Changing the size of the object.

Increase/Decrease in size based on Sx and Sy.

Sx 0
[ ]
0 Sy
Shear/Skew
Translating the individual pixel of the image based on an angle.

Shear in both direction based on Shx and Shy.

1 Shy
[ ]
Shx 1

Reflection
Mirroring the object in one or both axes.

1. Flip horizontally.

1 0
[ ]
0 −1

2. Flip vertically.

−1 0
[ ]
0 1

3. Flip both.

−1 0
[ ]
0 −1

Color Representation
Human Vision is more suited to Brightness/Darkness compared to it being suited to
Hue(Color).

Additive Color Model -> Based on emitted light. Combining the primary colors results
in White. Used for displays.
Subtractive Color Model -> Based on absorbed light. Combining the primary colors
results in Black. Used for pigments.

Color Models
A theoretical system used to describe colors by using numbers.

Color Model Primaries Type


RGB Red, Green, Blue Additive
CMY Cyan, Magenta, Yellow Subtractive
HSV Hue, Saturation, Value Additive
HSL Hue, Saturation, Lightness Additive
Color Model Primaries Type
LAB L*, a*, b* Additive

Color Spaces
A practical implementation based on a color models which decides how many colors
are available for use.

Color Space For Model Human Perception


sRGB Displays RGB
AdobeRGB Photography RGB 50%
ProPhoto RGB Photography RGB 76%
CMYK Printing CMY
CIELAB Human Perception LAB 100%

Drawing Graphics
Line Drawing
Drawing even a single line on the screen is a complicated process.

The general approach would be to use the line equation.


Slope-Intercept Form -> y = mx + b

def naive_line(x0, y0, x1, y1):

#Calculate the difference between x and y values.


dx = abs(x1 - x0)
dy = abs(y1 - y0)

#Calculate the slope.


m = dy / dx
c = y0 - m * x0

points = []

if dx > dy:
start, end = sorted([x0, x1])
for x in range(start, end + 1):
y = m * x + c
points.append((x, round(y)))
else:
start, end = sorted([y0, y1])
for y in range(start, end + 1):
x = (y - c) / m
points.append((round(x), y))

print(f"Points are: {points}\n")

But this approach is extremely slow and requires the floats and rounding numbers.

Digital Differential Analyser Algorithm


A line drawing algorithm that uses floating point arithmetic.

def dda(x0, y0, x1, y1):

#Calculate the difference between x and y values.


dx = abs(x1 - x0)
dy = abs(y1 - y0)

#Compare dx and dy and choose the bigger number as number of steps.


steps = max(dx,dy)

#Calculate the increment in each axis.


x_inc = dx / steps
y_inc = dy / steps

#Initialize the loop variables.


x, y = x0, y0

#Loop and append the points to a list.


points = []
for i in range(int(steps)+1):
points.append((round(x),round(y)))
x += x_inc
y += y_inc

#Printing the points list.


print(f"Points are: {points}\n")

Bresenham's Line Algorithm


A fast line drawing algorithm that only uses integer operations.

It is incremental and avoids having to round down numbers and avoids using floats.

def bresenham_line(x0, y0, x1, y1):

#Calculate the constants.


dx = x1 - x0
dy = y1 - y0
dx2, dy2 = 2*dx, 2*dy
D = dy2 - dx2

#Calculate the initial decision parameter.


P0 = dy2 - dx

#Check for slope being greater than 1.


m = dy / dx
if m < 1:

#Initialize the loop variables.


x, y = x0, y0

#Loop and append the points to a list.


points = []
for x in range(x0, x1+1):
points.append((x,y))

if P0 < 0:
P0 = P0 + dy2
else:
P0 = P0 + dy2 - dx2
y = y + 1

#Printing the points list.


print(f"Points are: {points}\n")
else:
#Printing in case slope is bigger than 1.
print(f"Slope is greater than 1: {m}\n")

Also called Mid-Point Algorithm

Circle Drawing
Equation of Circle -> x
2 2
+ y
2
= r

Tweaking this equation gets us -> y = √(r 2 2


− x )

Approach 1 -> Get every point by putting values for x in the range of [−R, R].
Approach 2 -> Use polar coordinates and then use trigonometric functions.

Both of these approaches are inefficient and we can do better using the Bresenham
Algorithm.

Bresenham's Circle Algorithm


Works by using the fact that circles have 8-way symmetry.
We can draw 8-points simultaneously because they're mirrors of each other

Initial Decision Parameter -> 1-r

(The algorithm is very complicated and I have no clue how the fuck it works)

Aliasing
A problem in graphics caused when a diagonal/curved shape is drawn.

This is due to the fact that a screen is made up of square pixels. It results in the image
having jagged edges, distortion or pixelation.

Anti Aliasing
The process of smoothing out lines by using different techniques. This can usually
done by

1. Increasing Resolution to have more pixels.


2. Super Sampling -> Rendering at a higher resolution then down-sampling to a
lower one.
3. Fast Approximate -> Looking at nearby pixels and averaging out the color. Can
cause blurry images.
4. Time Sampling -> Averaging out pixels based on previous frames.

All of these methods do impact performance a little because they all require extra
processing.

You might also like