Unit 4
Unit 4
be displayed on a screen. This process includes several steps: modeling, lighting, shading,
projection, and rasterization. Here's an overview of each step:
1. Modeling
Modeling is the process of creating the geometric representation of objects within a scene. This
typically involves defining objects using vertices, edges, and faces to form meshes. Models can be
created using various techniques and tools such as:
• Vertices and Polygons: The most common method, where objects are represented by a
collection of vertices connected by edges to form polygons (usually triangles or quads).
• Procedural Generation: Automatically generating complex structures and textures
algorithmically.
• Surface Representations: Using curves and surfaces (e.g., NURBS) for smoother and
more flexible object representations.
• 3D Scanning: Capturing real-world objects into digital 3D models using scanning
technology.
2. Lighting
Lighting simulates how light interacts with objects in the scene, significantly affecting the
appearance of the rendered image. Key components include:
• Light Sources: Different types of light sources include point lights, directional lights,
spotlights, and area lights.
• Illumination Models: Algorithms to compute the effect of light on surfaces, such as the
Phong reflection model or more complex models like physically based rendering (PBR).
• Shadows: Determining which parts of the scene are in shadow, often using techniques
like shadow mapping or shadow volumes.
3. Shading
Shading determines the color and brightness of surfaces in the scene based on lighting and material
properties.
• Flat Shading: Applies a single color to each polygon, computed using the polygon's
normal vector.
• Gouraud Shading: Computes lighting at vertices and interpolates the colors across the
polygon's surface.
• Phong Shading: Interpolates surface normals across the polygon and computes lighting
per pixel, resulting in smoother shading.
• Physically Based Shading: Uses realistic material properties and lighting models to
produce more accurate and lifelike images.
4. Projection
Projection transforms 3D coordinates into 2D coordinates for display. There are two main types
of projection:
• Orthographic Projection: Parallel projection where objects are the same size regardless
of depth. Useful for technical and engineering drawings.
• Perspective Projection: Mimics human vision by making distant objects appear smaller
than closer ones. This involves a viewpoint and a view frustum to create a more realistic
image.
5. Rasterization
Rasterization converts the 2D representation of objects into pixels on the screen. This process
includes:
• Scan Conversion: Determining which pixels on the screen correspond to the vertices and
edges of polygons.
• Depth Buffering (Z-buffering): Managing depth information to handle visibility and
occlusion, ensuring that only the closest objects are visible.
• Fragment Shading: Applying textures and shading calculations to fragments (potential
pixels) before finalizing their colors in the frame buffer.
In the case of 3D graphics, scenes can be pre-rendered or generated in real time. Pre-rendering is
a slow, computationally intensive process that is typically used for movie creation, where scenes
can be generated ahead of time, while real-time rendering is often done for 3D video games and
other applications that must dynamically create scenes. 3D hardware accelerators can improve real
time rendering performance.
In the sketch, rendering is used, which adds in bitmap textures or procedural textures, lights, bump
mapping and relative position to other objects. Several images (frames) must be rendered and
stitched together to making an video animation.
In rendering techniques, for tracing every particle of light in a scene is almost impractical and
spend amount of time. Therefore, more efficient modeling techniques have emerged:
For the older form of rasterization, entire face (primitive) is rendered by a single colour. It’s more
complicated, because we must render the vertices of a face by first and then rendering the pixels
of that face as a blending of the vertex colors.
Ray Casting
Geometry model in ray casting is parsed pixel by pixel, line by line, from the point of view
outward, as if casting rays out from the point of view. the color value of the object at the point of
intersection may be evaluated using several methods. the simplest method, its color value becomes
the value of that pixel. The color may be determined from a texture-map. The more sophisticated
method is to modify the colour value by an illumination factor. To reduce artifacts, a number of
rays in slightly different directions may be averaged.
This technique is considered quite faster than ray tracing, because geometric rays are traced from
the eye of the observer, then tracing is carried out from the object where the light originated from
and the object is looking for the light source.
However compared to ray tracing, the images generated with ray casting are not very realistic. Due
to the geometric constraints involved in the process, not all shapes can be rendered by ray casting.
Ray Tracing
Rendering technique by tracing the path of light as pixels in an image plane and reproduces the
path that each light ray follows in reverse direction from the eye back to its point of origin. The
process will continue to repeat until all pixels are formed. This technique involves reflection,
refraction, or shadow effects from points within the scene. Ray tracing also accumulate the color
value of the light and the value of the reflection coefficient of the object in determining the color
of the depiction on the screen. By using this ray tracing technique, effects such as reflection,
refraction, scattering, and chromatic aberration can be obtained.
Often, ray tracing methods are utilized to approximate the solution to the rendering equation by
applying Monte Carlo methods to it. Some of the most used methods are path tracing, bidirectional
path tracing, or Metropolis light transport, but also semi realistic methods are in use, like Whitted
Style Ray Tracing, or hybrids.
Radiosity
This technique is not usually implemented as a rendering technique, but instead calculates the
passage of light as it leaves the light source and illuminates’ surfaces that usually rendered to the
display using one of the other three techniques.
This technique is a rendering technique based on detailed analysis of light reflection from diffusion
surfaces. These techniques divide field into smaller field to find color details so that the process is
slow, but the resulting visualization is neat and smooth. Radiosity is more precisely used for the
final result of an object.
Rendering Method
Hidden Line Rendering
This method is used to represent objects whose surface is covered or blocked by other objects with
lines representing the sides of the object, but some lines are not visible because of the surface that
blocks them.
Shaded Rendering
In this method, the computer is required to perform various calculations both lighting, surface
characteristics, shadow casting, etc. This method produces a very realistic image, but the
disadvantage is the long rendering time required.
Wireframe Rendering
In wireframe rendering, an object is formed only visible lines that describe the edges of an object.
This method can be done by a computer very quickly, the only drawback is the absence of a surface,
so that an object looks transparent. So, there is often a misunderstanding between the front and
back side of an object.
Polygon-Rendering Methods in Computer Graphics
Polygon rendering is a fundamental technique in computer graphics used to represent three-
dimensional objects in a two-dimensional space. It involves providing appropriate shading at
each point of a polygon to create the illusion of a real object. This technique is essential for
creating realistic images and animations in various applications, including video games, movies,
and simulations.
Definition:
Polygon rendering is the process of determining the color and intensity of each pixel on the
surface of a polygon in a 3D space to create a 2D image. It involves applying various shading
models, such as constant intensity shading, Gouraud shading, and Phong shading, to produce a
realistic representation of a three-dimensional object on a two-dimensional screen. The goal is
to simulate the appearance of real-world objects by accurately representing the way they reflect
light and cast shadows.
It is a simple method of polygon rendering. It is also called Flat shading. In this method every
point has constant intensity. All point of polygon has same intensity value. It is fast rendering
method. It is useful for displaying simple curved surface appearances.
Gouraud Shading
It is developed by Gouraud. This rendering is done by intensity interpolation. At each point the
intensity value is calculated. It interpolates linearly in the surface of the polygon. It eliminates
intensity discontinuity. It has match bands.
Phong Shading
It is more accurate method of polygon rendering. At each point of the surface, it interpolates the
normal vector and applies the illumination model. It is also called as normal vector interpolation
shading. It gives more real highlights of the surface. It reduces match bands.
Affine transformation is a linear mapping method that preserves points, straight lines, and planes.
Sets of parallel lines remain parallel after an affine transformation.
The affine transformation technique is typically used to correct for geometric distortions or
deformations that occur with non-ideal camera angles. For example, satellite imagery uses affine
transformations to correct for wide angle lens distortion, panorama stitching, and image
registration. Transforming and fusing the images to a large, flat coordinate system is desirable to
eliminate distortion. This enables easier interactions and calculations that don’t require accounting
for image distortion.
• Scaling
• Translation
• Shear
• Rotation
Note: A combination of these transformations is also an affine transformation.
The following table illustrates the different affine transformations: translation, scale, shear, and
rotation.
Scaling
image = cv2.imread("Detective.png")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
transformation = tf.keras.preprocessing.image.apply_affine_transform(
image, # input image
zx=0.5,
zy=0.5,
row_axis=0,
col_axis=1,
channel_axis=2
)
• Line 2: We use the OpenCV library to read the input image, so the image read would be
in BGR, which we need to convert into RGB.
• Lines 6 and 7: We have zx and zy as the scaling parameters.
• Lines 8 to 10: We tell the order of RGB channels. We may not need this if we use some
other library to read the image.
Translation
transformation = tf.keras.preprocessing.image.apply_affine_transform(
image,
tx=-400,
ty=400,
row_axis=0,
col_axis=1,
channel_axis=2
)
Rotation
transformation = tf.keras.preprocessing.image.apply_affine_transform(
image,
theta=90,
row_axis=0,
col_axis=1,
channel_axis=2
Visibility and occlusion are crucial concepts in computer graphics, as they determine which parts
of a scene are visible to the camera (or viewer) and which are hidden by other objects.
Understanding and efficiently handling these aspects are essential for rendering realistic and
performant scenes. Here's a breakdown of these concepts:
Visibility
Visibility refers to the determination of which parts of the scene are visible from a particular
viewpoint. This involves figuring out what can be seen directly by the camera and what is
obscured.
1. Ray Casting: Tracing rays from the camera to each pixel in the image plane to determine
which objects are hit first. This is computationally intensive and typically used in ray
tracing rendering techniques.
2. Z-buffering (Depth Buffering): Used in rasterization to keep track of the depth of every
pixel on the screen. When a new pixel is drawn, its depth is compared to the current value
in the Z-buffer, and only the closest (smallest depth) pixel is rendered.
3. Occlusion Culling: This process skips rendering objects or parts of objects that are not
visible because they are blocked by other objects. Techniques include:
Occlusion
Occlusion refers to the phenomenon where certain objects in a scene block other objects from
view. Properly handling occlusion is essential for realistic rendering.
1. Z-buffering: As mentioned, this keeps track of the depth of pixels and ensures that only
the closest objects are rendered, effectively handling occlusions.
2. Shadow Mapping: A technique to determine which areas are occluded from light
sources. A depth map is created from the light's perspective, and during rendering, it is
used to determine if a pixel is in shadow (occluded by other objects).
3. Ambient Occlusion: This technique approximates how much ambient light (light
scattered from the environment) reaches a point. Areas occluded by surrounding geometry
receive less ambient light and appear darker.
Applications
• A depth buffer (Z-buffer) is initialized along with the frame buffer. The depth
buffer has the same resolution as the frame buffer and is used to store depth
information for each pixel.
• Each entry in the depth buffer is initially set to a maximum value (typically
representing the farthest possible depth).
2. Rendering Process:
• For each pixel in a polygon being rendered, the depth of the pixel is calculated
based on the geometry of the scene and the camera's position.
• The calculated depth value is compared to the current value stored in the depth
buffer at the corresponding pixel location.
• If the calculated depth is less than the current value in the depth buffer (meaning
the pixel is closer to the camera than what is currently recorded), the depth buffer
is updated with the new depth value, and the pixel color is written to the frame
buffer.
• If the calculated depth is greater than or equal to the current value in the depth
buffer, the pixel is occluded by a closer object and is therefore not rendered.
Key Concepts
Advantages
1. Simplicity: Depth buffering integrates seamlessly with the rasterization pipeline and is
straightforward to implement in hardware and software.
2. Efficiency: It allows for fast, real-time hidden surface removal, essential for interactive
applications like video games and simulations.
3. Generality: Works with arbitrary scenes and does not require preprocessing or special
data structures for the scene geometry.
Limitations
1. Z-fighting: Occurs when two surfaces are very close together, and the limited precision
of the depth buffer causes them to compete for the same pixel.
2. Memory Usage: Depth buffers require additional memory, which scales with the
resolution of the frame buffer.
3. Perspective Artifacts: Depth precision is non-linear in perspective projections, leading
to higher precision close to the camera and lower precision at greater distances.
Optimization Techniques
Applications
1. Real-time Rendering: Used extensively in video games, virtual reality, and simulations
to manage visibility efficiently.
2. Shadow Mapping: Depth buffers are used to create shadow maps from the light source's
perspective, determining which areas are in shadow.
3. Post-processing Effects: Techniques like screen-space ambient occlusion (SSAO) and
depth-of-field effects use depth buffers to determine spatial relationships between objects.
Painter Algorithm
It came under the category of list priority algorithm. It is also called a depth-sort algorithm. In
this algorithm ordering of visibility of an object is done. If objects are reversed in a particular
order, then correct picture results.
Objects are arranged in increasing order to z coordinate. Rendering is done in order of z coordinate.
Further objects will obscure near one. Pixels of rear one will overwrite pixels of farther objects. If
z values of two overlaps, we can determine the correct order from Z value as shown in fig (a).
If z objects overlap each other as in fig (b) this correct order can be maintained by splitting of
objects.
The concept has taken color from a painter or artist. When the painter makes a painting, first of
all, he will paint the entire canvas with the background color. Then more distance objects like
mountains, trees are added. Then rear or foreground objects are added to picture. Similar approach
we will use. We will sort surfaces according to z values. The z values are stored in the refresh
buffer.
Painter Algorithm
Step2: Sort all polygons by z value keep the largest value of z first.
The success of any test with single overlapping polygon allows F to be painted.
Ray Tracing
Ray tracing is a rendering technique that can realistically simulate the lighting of a scene and its
objects by rendering physically accurate reflections, refractions, shadows, and indirect lighting.
Ray tracing generates computer graphics images by tracing the path of light from the view camera
(which determines your view into the scene), through the 2D viewing plane (pixel plane), out into
the 3D scene, and back to the light sources. As it traverses the scene, the light may reflect from
one object to another (causing reflections), be blocked by objects (causing shadows), or pass
through transparent or semi-transparent objects (causing refractions). All of these interactions are
combined to produce the final color and illumination of a pixel that is then displayed on the screen.
This reverse tracing process of eye/camera to light source is chosen because it is far more efficient
than tracing all light rays emitted from light sources in multiple directions.
Another way to think of ray tracing is to look around you, right now. The objects you’re seeing
are illuminated by beams of light. Now turn that around and follow the path of those beams
backwards from your eye to the objects that light interacts with. That’s ray tracing.
The primary application of ray tracing is in computer graphics, both non-real-time (film and
television) and real-time (video games). Other applications include those in architecture,
engineering, and lighting design.
The following section introduces rendering and ray tracing basics along with commonly used
terminology.
• Ray casting is the process in a ray tracing algorithm that shoots one or more rays from the
camera (eye position) through each pixel in an image plane, and then tests to see if the rays
intersect any primitives (triangles) in the scene. If a ray passing through a pixel and out
into the 3D scene hits a primitive, then the distance along the ray from the origin (camera
or eye point) to the primitive is determined, and the color data from the primitive
contributes to the final color of the pixel. The ray may also bounce and hit other objects
and pick up color and lighting information from them.
• Path Tracing is a more intensive form of ray tracing that traces hundreds or thousands of
rays through each pixel and follows the rays through numerous bounces off or through
objects before reaching the light source in order to collect color and lighting information.
• Bounding Volume Hierarchy (BVH) is a popular ray tracing acceleration technique that
uses a tree-based “acceleration structure” that contains multiple hierarchically-arranged
bounding boxes (bounding volumes) that encompass or surround different amounts of
scene geometry or primitives. Testing each ray against every primitive intersection in the
scene is inefficient and computationally expensive, and BVH is one of many techniques
and optimizations that can be used to accelerate it. The BVH can be organized in different
types of tree structures and each ray only needs to be tested against the BVH using a depth-
first tree traversal process instead of against every primitive in the scene. Prior to rendering
a scene for the first time, a BVH structure must be created (called BVH building) from
source geometry. The next frame will require either a new BVH build operation or a BVH
refitting based on scene changes.
• Denoising Filtering is an advanced filtering techniques that can improve performance and
image quality without requiring additional rays to be cast. Denoising can significantly
improve the visual quality of noisy images that might be constructed of sparse data, have
random artifacts, visible quantization noise, or other types of noise. Denoising filtering is
especially effective at reducing the time ray traced images take to render, and can produce
high fidelity images from ray tracers that appear visually noiseless. Applications of
denoising include real-time ray tracing and interactive rendering. Interactive rendering
allows a user to dynamically interact with scene properties and instantly see the results of
their changes updated in the rendered image.
Rendering fundamentals
Forward rendering, also known as the direct rendering equation, traces light from the light sources
to the camera (or viewer). This approach is natural for simulating how light physically behaves in
the real world, but it can be computationally intensive due to the complexity of light interactions.
The forward rendering equation is expressed as:
Backward rendering, also known as the inverse rendering equation, traces light from the camera
to the light sources. This approach aligns more naturally with how images are captured in cameras,
making it more suitable for techniques like ray tracing. Backward rendering is often more efficient
for image synthesis because it directly computes the light that contributes to each pixel.