Discrete Techniques - WordPress.com · discrete: They have limited ... Before we look at how the...

36
DISCRETE TECHNIQUES

Transcript of Discrete Techniques - WordPress.com · discrete: They have limited ... Before we look at how the...

DISCRETE

TECHNIQUES

Buffers

We have already used two types of standard buffers: color

buffers and depth buffers.

There may be others supported by the hardware and software

for special purposes.

What all buffers have in common is that they are inherently

discrete:They have limited resolution, both spatially and in

depth.

We can define a (two-dimensional)1buffer as a block of

memory with n × m k-bit elements

Buffers con..

We have used the term frame buffer to mean the set of buffers

that the graphics system uses for rendering, including the front

and back color buffers, the depth buffer, and other buffers the

hardware may provide. These buffers generally reside on the

graphics card.

Digital images

Before we look at how the graphics system can work with

digital images through pixel and bit operations, let’s first

examine what we mean by a digital image.

Within our programs, we generally work with images that are

arrays of pixels.

These images can be of a variety of sizes and data types,

depending on the type of image with which we are working.

For example, if we are working with RGB images, we usually

represent each of the color components with 1 byte whose

values range from 0 to 255.

Image Format

We often work with images in standard format

( JPEG , TIFF ,GIF)

How do we read/write such images with openGl?

No support in openGl

OpenGl know nothing of image format

Witting into Buffer

Conceptually, we can consider all of memory as large two

dimensional array of pixels.

We read and write rectangular block of pixels known as

bitblock transfer (bitblt) operations, as efficiently as

possible.

These operations are also known as raster operations

(raster-ops)

Writing Mode

Read destination pixel before writing source

Writing Mode con..

Source and destination bits are combined bitwise

16 possible function (one per column in table)

Mapping Methods

Although graphics card can render over 10 million polygons

per second , that number is insufficient for many phenomena :

Grass

Cloud

skin

Three types of mapping

Texture mapping

Uses an image (or texture) to influence the color of a fragment.

Environmental mapping

distort the normal vectors during the shading process to make the

surface appear to have small variations in shape, such as the

bumps on a real orange

Pump mapping

allow us to create images that have the appearance of reflected

materials without our having to trace reflected rays. In this

technique, an image of the environment is painted onto the

surface as that surface is being rendered

Texture Mapping

Environmental Mapping

Texture Mapping

Textures are patterns. They can range from regular patterns,

such as stripes and checkerboards, to the complex patterns that

characterize natural materials.

Textures can be one, two, three, or four dimensional. For

example, a one dimensional texture might be used to create a

pattern for coloring a curve.

A three dimensional texture might describe a solid block of

material from which we could sculpt an object

Where does mapping take place?

OpenGL’s texture maps rely on its pipeline architecture.

We have seen that there are actually two parallel pipelines:

the geometric pipeline and the pixel pipeline.

For texture mapping, the pixel pipeline merges with fragment

processing after rasterization, as shown in Figure below.

This architecture determines the type of texture mapping that

is supported.

In particular, texture mapping is done as part of fragment

processing.

Mapping geometry

Texture mapping: rendering polygons by applying images with mapped geometry

(s,t) – texture coordinates

T(s,t) – texture

x(s,t), y(s,t), z(s,t) – texture map (a mapping of texture onto world coords)

To render, we really want the inverse map: s(x,y,z) and t(x,y,z)

Mapping geometry

Also have to map screen coordinates (xs,ys) into world

coordinates before you can map texture coordinates onto

world coordinates

Texture Mapping Coordinates

Sometimes finding the mapping is easy (rectangle onto

rectangle)

Can use some standard mappings (rectangle onto a sphere, for

example)

Otherwise, it’s generally done by hand

Automatically “unwrap” shape onto plane

Hand-paint or otherwise create custom texture map

Texture Mapping Details

Assume texture image has coordinates (s,t) from (0,0) to (1,1)

Specify texture coordinates for each vertex and interpolate

Look up color from texture

Mix texture color with object color:

Replace – just use the texture map color

Decal – apply lighting to texture mapped point

Modulate – multiply object color by texture map

Blend – alpha-blend colors

Pixel color from texture map?

How do we get the pixel’s color from the texture map?

We could map the center of the pixel to the texture map and

use the color we find there

Pixel color from texture map?

How do we get the pixel’s

color from the texture map?

We could map the center of

the pixel to the texture map

and use the color we find

But this can result in severe aliasing and flickering

Better to map the whole pixel and average. But won’t that be slow?

Aliasing and Filtering

What happens if texture is too small or too big?

What happens when you zoom way in or out on a textured object?

Interactive Computer Graphics Chapter 7 - 23

Mipmaps

Make pre-filtered

images of size 1x1,

2x2, 4x4, …, nxn

Choose the best

Examples: [1][2]

Interactive Computer Graphics Chapter 7 - 24

Handling Multiple Textures

Using multiple texture objects:

Make two texture samplers

Read the values from both

Combine however you like in fragment shader

Environment Mapping

Compute viewing direction reflection vector

See where it hits the environment map

Need:

View direction

Surface normal at every pt

Simplifications:

Assume environment is

distant (only need direction

to environment)

Use the same environment

map for all objects (no one

will notice for curved surfaces) Chapter 7 - 25

Bump mapping

Bump mapping is a texture-mapping technique that can give

the appearance of great

complexity in an image without increasing the geometric

complexity.

Bump mapping con..

If we take a photograph of a real orange, we can apply this

image as a texture map to a surface.

However, if we move the lights or rotate the object, we

immediately notice that we have the image of a model of an

orange rather than the image of a real orange.

The problem is that a real orange is characterized primarily by

small variations in its surface rather than by variations in its

color, and the former are not captured by texture mapping.

The technique of bump mapping varies the apparent

shape of the surface by perturbing the normal vectors as the

surface is rendered; the colors that are generated by shading

then show a variation in the surface properties

Opacity and blending

The opacity of a surface is a measure of how much light

penetrates through that

surface. An opacity of 1 (α = 1) corresponds to a completely

opaque surface that

blocks all light incident on it. A surface with an opacity of 0 is

transparent; all light

passes through it. The transparency or translucency of a

surface with opacity α is

given by 1− α

Opacity and blending con..

Consider the three uniformly lit polygons shown in Figure

below.

Assume that the middle polygon is opaque, and the front

polygon, nearest to the viewer, is transparent.

If the front polygon were perfectly transparent, the viewer

would see only the middle polygon.

However, if the front polygon is only partially opaque

(partially transparent), similar to colored glass, the color that

viewer sees is a blending of the colors of the front and middle

polygon.

Blending Function

Source: Rs, Gs, Bs, As

Destination: Rd, Gd, Bd, Ad

Source factor: Sr, Sg, Sb, Sa (Can have separate RGBA

components of source, destination factors)

Dest factor: Dr, Dg, Db, Da

Combining colors:

Rresult = Rs * Sr + Rd * Dr

Gresult = Gs * Sg + Gd * Dg

Bresult = Bs * Sb + Bd * Db

Aresult = As * Sa + Ad * Da

Blending Problems

What if we leave the depth test on and want to draw these

faces (back to front order):

1. (1, 0, 0, .5) [Red 50% opaque]

2. (0, 1, 0, 1) [Green 100% opaque]

3. (0, 0, 1, .5) [Blue 50% opaque]

What happens if we draw faces…

1, then 2, then 3

2, then 1, then 3

1, then 3, then 2

Interactive Computer Graphics Chapter 7 - 31

Interactive Computer Graphics Chapter 7 - 32

Screen-door Transparency

Another approach for fast transparency effects:

“Screen door” method–put a pattern with a set

percent coverage into

the stencil buffer and

render.

Even works with many

layers (but use

different patterns)

Antialiasing

Line Aliasing

Ideal raster line is one pixel wide

All line segments , other than vertical and horizontal segments

, partially cover pixels

Lead to the “ jaggies “ or aliasing

Similar issue for polygons

Antialiasing con..

Can try to color a pixel by adding a fraction of its color to the

frame buffer.

Fraction depend on percentage of pixel covered by fragment

Fraction depends on whether there is overlap

Area Averaging

Use average area α1+α2- α1α2 as blending factor

Back-to-front and front –to-Back rendering

Is this image correct?

Probably not

Polygons are rendered in the order they pass down the

pipeline

Blending functions are order dependent