117
Chap 10. Discrete Techniques 한한한한한 한한한한한한한 한 한한

Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Embed Size (px)

Citation preview

Page 1: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Chap 10. Discrete Techniques

한림대학교 정보통신공학부송 창근

Page 2: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

이산적 기법들• Until recently, application programmers had n

o functions in the API that allow them to read/write individual pixels.

• Frame Buffer 나 이산적 버퍼에 직접 작용하는 방법들– Texture Mapping ( 무늬사상 )– Compositing ( 합성 )– Alpa Blending– Antialiasing( 앤티엘리어징 )

Page 3: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Mapping Method

• Mapping method– Rendering Process : The illusion of surface of great

complexity– Examine how we can modify the individual pixels in a

buffer– Define multiple ways of writing into a buffer– Look at what buffers are supported by the OpenGL

API, how an application program can modify these buffers, and how these buffers can be used for new applications.

Page 4: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.1 Buffers and Mapping

그림 10.1 Buffer

Bitplane

Page 5: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.1 Buffers and Mapping• Buffer : inherently discrete.

- Frame buffer and Depth buffer are already introduced.

- A block of memory with a spatial resolution of

n m k bit elements

- Frame buffer

n,m match the resolution of the screen

k is determined by how many colors the system display

- Depth buffer

k is determined by the depth resolution

Page 6: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

• Bitplane ( 비트평면 )

- Any of the k n m planes in a buffer

• Pixel

- All k of the elements at a particular spatial resolution

- A pixel can be a byte, an integer, or even a floating point number

Terminology

Page 7: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

• Use of Buffer

- Surface Rendering : The process of modeling an object by a set of geometric primitives and then rendering these primitives has its limitations.

• Virtual Orange 의 예

(1) Start with a sphere : sphere.exe. We can build an approximate sphere out of triangles, and can render these triangles that match those of a real orange.

(2) Try to model the orange with some sort of parametric surface and to render the surface by subdivision. Although it might have the correct overall properties such as shape and color, it would lack the fine surface detail of the real orange.

(3) Procedural methods of Chapter 8 (modeling). At the cost of generating as model with more polygons than we would like to render

Page 8: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

• Alternatives

-Build a simple model and to add detail as part of the rendering process

- As implementation renders a surface, be it a polygon or a curved surface, it breaks the surface up into small pieces called fragments.

- Each of fragment, when projected, is at most the size of one pixel.

• Mapping Algorithm

- As part of the rendering process, we must assign a shade or color to each fragment.

- Either modify the shading algorithm based on the map (2 dimensional array)

- Or modify the shading by using the map to alter surface parameters, such as material properties and normals.

Page 9: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

• Mapping : 3 major approaches

(1) Texture mapping

(2) Bump mapping

(3) Environment mapping

Mappings

Page 10: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Texture Mapping (1/3)

Texture image

Flat Mapping Cylindrical/Spherical mapping

• 2D texture image =>3D object : mapping method

Page 11: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

• Texture Mapping

- Use a pattern (or texture) to determine the color of a fragment.

- How to get the pattern

(1) A fixed pattern (often used to fill polygons)

(2) By a procedural texture-generation method

(3) Through a digitized image

- The image produced by a mapping of a texture to the surface as part of the rendering of the surface; 그림 10.2

Texture Mapping

Page 12: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

그림 10.2 Texture Mapping

Page 13: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

• Bump mapping

- Distort the shape of the surface to create variations such as the bumps on a real orange

• Reflection or environment maps

- Allows us to create images with the appearance of ray-traced images without having to trace reflected rays.

- An image of the environment is painted onto the surface as the surface is being rendered.

Bump and Environment Mapping

Page 14: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Mapping

Bump Mapping Chrome/Reflection Mapping

Page 15: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Mapping

Refraction Mapping Environment Mapping

From Advanced animation and Rendering techniquesAlan watt, Mark watt

시선광선

Mipmap cube

교점

1 2 3 4

5

6

Page 16: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

• 3 methods in common

- All three alter the shading of individual pixels and are implemented as part of the shading process

- All rely on the map being stored as a one-, two-, or three dimensional digital image

- All are also subject to aliasing errors

Commons

Page 17: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.2 Texture Mapping• Textures are patterns : from regular patterns, such as

stripes, checkerboards, to the complex patterns that characterize natural materials

• We can distinguish among objects of similar size and shape by their textures. Thus, we can extend our present capabilities by placing or mapping a texture to the objects.

• We shall consider only two-dimensional textures.• Examples

– Color plate 6, Color plate 23 : the surface of the table, etc.

• With hardware texture mapping, it allows the detail to be added without degrading the rendering time

Page 18: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.2.1 Two-Dimensional Texture mapping

그림 10.3 Texture maps for a parametric surface

Page 19: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

• A sequence of steps involved in texture mapping

(1) Associate a point of T with each point on a geometric object.

(2) Each point on a geometric object is mapped to screen coordinates for display.

• Texture Pattern

- Two dimensional texture pattern T(s,t),

- s and t are texture coordinates, 0 ≤ s,t ≤ 1

- It will be stored in texture memory as an nm array of texture elements, texels

- Scale our texture coordinates to vary over the interval (0,1)

Page 20: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

- maps from texture coordinates, (s,t) to geometric coordinates, (x,y,z,w).

- maps from geometric coordinates, (x,y,z,w) to screen coordinates, (xs, ys).

- If we define the geometric object using parametric (u,v) surfaces, there is additional mapping function: maps from parametric coordinates, (u,v) to geometric coordinates, (x,y,z,w). ( 그림 10.3 참조 )

Texture map

Page 21: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

• Texture mapping process is simple.

- A small area of the texture pattern maps to the area of the geometric surface, corresponding to a pixel in the final image.

- If we assume that the values of T are RGB color values, we use these values to modify the color of the surface. ( part of the shading calculation)

Texture Mapping Process

Page 22: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

(1) Text 는 2 차원 사각형이다 . 이러한 사각형을 3 차원 공간에 사상하게 되면 왜곡현상 ( 모양이나 거리상 ) 이 발생한다 . 예를 들어서 , 구 (sphere) 에 사상하는 경우 .

(2) Rendering 과정이 pixel by pixel 기초로 동작되므로 , pixel을 색깔을 정할 때 , texture image 의 어느 점이 사용될 것인지를 알아야 한다 . 따라서 , screen coordinates 에서 texture coordinates 로의 inverse map 이 종종 필요하다 .

(3) 점들간의 사상이 아니라 면적간의 사상이므로 자연스럽게 aliasing 문제가 발생된다 . ( 그림 10.4 를 참조 ).

Difficulties

Page 23: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

그림 10.4 Preimages of pixel

Suppose that we are computing a color for square pixel centered at screen coordinates (xs, ys). The center (xs, ys). corresponds to a point (x,y,z) in object space, but, if the object is curved, the projection of the corners of the pixel backward into object space yields a curved preimage.

Page 24: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

그림 10.4 Preimages of pixel

In terms of the texture image T(s,t), projecting the pixel back a preimage in the texture space that is the area of the texture that should contribute the shading of the pixel

Page 25: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

그림 10.5 Aliasing in texture generation

• Serious Aliasing 문제-그림 10.5 의 경우에 줄무늬가 나타나는 것이 아니라 밝은 면만 나타난다 .

• One simple method is to use the point that we get by back projection of the pixel center to find texture value.

A Simple method

Page 26: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

• A better strategy is to assign a texture value based on averaging of the texture map over the preimage.

• This method is imperfect.

-For the example in Figure 10.5, we would assign an average shade, but we would still not get the striped pattern of the texture.

- We still have aliasing defects due to the limited resolution of both the frame buffer and the texture map.

A better method but not enough

Page 27: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

)(

),(

minmaxminmax

minmin

minmaxminmax

minmin

vvtt

ttvv

uuss

ssuu

• 구현하기는 쉬우나 , 대상물의 곡면을 고려할 수 없음

그림 10.6 Linear texture mapping

Page 28: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Another approach using a two-part mapping

1st step : Maps the texture to a simple 3-dimensional intermediate surface such as sphere, cylinder or cube.

2nd step : the intermediate surface containing the mapped process can be applied to surface being rendered

This method can be applied to surfaces defined in either geometric or parametric coordinates.

Another approach

Page 29: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

그림 10.7 Texture mapping with a cylinder

1,0 ts

1,0 ts

실린더의 밑면과 윗면은 제외하면 모양의 왜곡 없이 mapping 이 가능하나 , 패쇄된 공간에 mapping 은 왜곡을 필연적으로 발생시킴 . 예 ) 세계 지도 (Mercator projection)

Page 30: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

그림 10.7 Texture mapping with a cylinder

hvz

ury

urx

/

)2sin(

),2cos(

Points on the cylinder are given by the parametric equations as u and v vary over (0,1):

We can use the mapping

vt

us

Page 31: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

• If we use a sphere of radius r as the intermediate surface, a possible mapping is

)2sin()2sin(

),2cos()2sin(

),2cos(

vurz

vury

urx

Texture mapping with sphere

Page 32: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

그림 10.8 Texture mapping with box

We map the texture to a box that can be unraveled, like a cardboard packing box.

Page 33: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

The Second Step

• Map the texture values on the intermediate object to the desired surface (object)

• Figure 10.9 shows 3 possible different mapping strategies.

Page 34: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

(a) Using the normal from the intermediate surface (b) Using the normal from the object surface (c ) Using the center of the object.

그림 10.9 Second mappingobject

Page 35: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.2.2 Texture Mapping in OpenGL

glTexImage2D(GL_TEXTURE_2D, level, components, width, height, border, format, type, image);– The texture pattern is stored in the widthheight array

image– The value components is the number 1 to 4 of color

components (RGBA).– The parameter level and border gives us fine control over

how texture is handled; multiple texture maps (multiple resolutions)

– glTexImage2D(GL_TEXTURE_2D, 0,3, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, image);

Page 36: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

• Assign texture coordinates to each vertex, just as we assign colors and normal vectors.– Texture coordinates are then mapped to fragm

ents by interpolation– The function glTexCoord is used.– 2 Dim & floating point : glTexCoord2f(s,t);

Page 37: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.2.3 Texture Generation

• Provide detail without generating numerous geometric objects

-If we want to simulate grass in a scene, we can texture map an image of grass (obtained by scanning a photograph) faster than we can generate two- or three-dimensional objects that look like grass.

-Rather than generating realistic surface detail for terrain, we can digitize a real map, and can paint it on a three-dimensional surface model by texture mapping.

Page 38: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.2.3 Texture Generation

• Procedural methods for determining texture patterns

-Such as the texture of sand, grass, or minerals

-These textures show both structure (regular pattern) and randomness.

-An ideal random number generator produces a sequence of values (white noise). Statistically uncorrelated.

- The filter correlate successive noise values, and by controlling the filter, we can simulate various patterns.

Page 39: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

3D Texture

• Three dimension texture• By associating each (s,t,r) value directly

with an (x,y,z) point, we can avoid the mapping problem entirely.

• Conceptually, this process is similar to sculpting the three-dimensional object from a solid block whose volume is colored by the specified texture.

Page 40: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.3 Environmental Maps• Consider a shiny metal ball that is in the middle of a room. We can see the contents of the room, in a distorted form on the surface of the ball

-Ray-tracing, Too time-consuming to be practical

- Environmental or reflection mapping. We can extend our mapping techniques to obtain an image that approximates the desired reflection by extending texture map to an environmental mapping

Page 41: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.3 Environmental Maps• Two step procedure for mapping environments to the surface

of the objects.

(1) Obtain an image of the environment on an intermediate projection surface. The center of projection is located at the center of the reflective object, but the projections are computed with the object removed from the scene. Refer to Figure 10.11.

(2) Treat the environmental map as a texture map. Place the object back in the scene, and transfer the texture map to its surface. Figure 10.12

Page 42: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Figure 10.11 Mapping of the environment

10.3 Environmental Maps

Page 43: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Figure 10.12 Mapping from the intermediate surface

Page 44: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Ray Tracing(1/4)– Suggested by Appel in 1968 : called by ray casting

process• 관찰자의 눈에 들어오는 광선을 추적하여 광선의 색을

화면에 표시해 주는 방법• ray 의 방향 : eye light source• 각 ray 를 추적하면서 simulation 많은 시간 소모• 정반사에 중점을 둠 , 난반사 표현에는 한계

eyeray

screenrefraction

reflection

Page 45: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Ray Tracing(2/4)

• Reflection/Refraction

Page 46: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Ray Tracing(3/4)• Backward Ray Tracing

Page 47: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Ray Tracing(4/4)

• DOF, Motion Blur(Distributed Ray Tracing)

Page 48: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.4 Bump Maps• 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 color that are generated by shading then show a variation in the surface properties.

Page 49: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.4 Bump Maps

vu

vu

PP

PPn

v

zv

yv

x

p

u

zu

yu

x

p vu

• Let P(u,v) be a point on a parametric surface. The unit normal is :

where

Page 50: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

.),(' nvudpp

''' vu ppn

vvv

uuu

nvudnv

dpp

nvudnu

dpp

),(

,),(

'

'

• Suppose that we displace the surface in the normal direction by a function called the bump function, d(u,v), that is assumed known and small.

•We alter the normal n, instead of p. The normal at the perturbed point p’ is given by the cross product .

• We can compute the two partial derivatives by differentiating the equation for p’, obtaining

Page 51: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

uv pnv

dpn

u

dnn

'

•If d is small, we can neglect the terms on the right of these equations to obtain the perturbed normal:

•To apply the bump map we need two arrays that contain the values and . These arrays can be precomputed.

• The normal can then be perturbed during the shading process.u

d

v

d

Page 52: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.5 Writes into Buffers

Figure 10.13 Writing of a block

Page 53: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Figure 10.14 Writing modes

Page 54: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Figure 10.15 Logical operation between 2 bits

Page 55: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Figure 10.16 Writing in modes 3 and 7

Page 56: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.6 Bit and Pixel Operations in OpenGL

• Bitmap and images of multibit Pixels • Concentrate on how the buffers are see

n from the application program.

Page 57: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.6.1 OpenGL Buffers

• Color buffer– Frame buffer– Double buffering : the front and back buffer– Stereo pairs of images

• Depth buffer– Used for hidden-surface removal

• Accumulation buffer– Used for a variety of operations including motion

blur

• Stencil buffer– Masking operation

Page 58: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Raster operation

• We can think of this operation as defining a cursor in window coordinates.

• glRasterPos– glRasterPos3f(x,y,z);

Page 59: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.6.2 Use of Bitmaps for Fonts

Page 60: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Fig.10.18 Outputting of a bitmap

Page 61: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Glubyte my_font[128][13];

glBitmap(width, height, x0, y0, xi, yi, bitmap);

Base=glGenLists(128)

For (I=0, I<127, I++)

{

glNewList(base+I, GL_COMPLIE);

glBitMap(8, 13, 0.0, 2.0, 10.0, 0.0, my_font[I]);

glEndList();

}

Page 62: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.6.3 Pixels and Images

• There are 3 functions for moving images in OpenGLglReadPixels(x,y,width,height,format,type,image);glDrawPixels(width, heighr, format, type, image);glCopyPixels(x,y,width,height,type);

Page 63: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.6.4 Lookup Table

Page 64: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Figure 10.20 Thermal color map

Pseudocolor : converting gray levels to colors.

Page 65: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Figure 10.21& 10.22

Brightness Adjustments

Page 66: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Color Conversion

• CRT and Photographic print• Color Balancing

Page 67: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.6.5 Buffers for Picking

• Return the identifier of an object to the user program

• As we render primitives, we place the identifier of the fragment being rendered an extra buffer : the “colors” in this buffer are identifiers of objects located at corresponding pixels in the frame buffer.

Page 68: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.7 The Mandelbrot Set

Figure 10.23 Complex plane

Page 69: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

W=F(z)

)(1 kk zFz

)(1 kk zFz

Figure 10.24 Path from complex recurrence

Page 70: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Figure 10.25 Mandelbrot set (a) Black and white coloring (b) detail along edges

Page 71: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

21 kk zz cz 0

czz kk 2

1iz 0

Page 72: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.8 Compositing Techniques

• Alpha (α) blending

- Transparent object with ray tracing techniques – time consuming

- alpha channel is the fourth color in RGBA color mode

- By default, not blending. Need to be enabled

- blended or composite

Page 73: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.8.1 Opacity and Blending

Figure 10.26 Translucent and opaque polygon

Page 74: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

• Opacity (α)– α =1 : completely opaque surface– α = 0 : transparent

• Transparnecy or translucency of a surface with opacity α is 1- α

• Figure 10.26– the middle polygon is opaque– If the front polygon is transparent, the viewer woul

d see only back polygon– If the front is partially opaque (similar to colored gl

ass), the color we see is a blending of the colors of the front and middle polygon

– For example, the front is red and the middle is blue, we will see magenta

Page 75: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

][

][

ddddd

sssss

bgr

bgr

dcsbdcsbdcsbdcsbd bbbbggggrrrr '

Source and Destination pixel : If we regard the fragment as the source pixel and the frame buffer pixel as destination, we can combine these values in various ways. (Combining the colors of polygon is similar to joining two pieces of colored glass into a single piece of glass that will have a higher opacity and a color different from either of the original pieces

The arrays of constants b and c are the source and destination blending factors.

Page 76: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.8.2 Image Compositing

• To combine and display a number of images that exist as pixmap, or as sets of data that have been rendered independently

• We wish to keep our RGB colors between 0 and 1 in the final images– Suppose that we have n images– At a given pixel, image i has components Ciα i. If we

replace Ci by 1/n Ci and α i by 1/n α i, .We can simply add each image into the frame buffer.

Page 77: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Figure 10.27 Raster Line

Page 78: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.8.3 Antialiasing

1

1101)1(

d

d CCC

• One of the major uses of the α channel is for antialiasing.

• Set α value that is the amount of that pixel covered by the fragment.

• Suppose that we start with an opaque background, and the frame buffer starts with the background color C0. α0=0

• The first polygon is rendered. The color of the destination pixel is set to

Page 79: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.8.3 Antialiasing

1

1101)1(

d

d CCC

• A fragment that covers the entire pixel α1 = 1

- Its color is assigned to the destination pixel

- The destination pixel will be opaque

Page 80: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Figure 10.28 Fragments

(a) Nonoverlapping (b) Overlapping

21

2211012 ))1)((1(

d

d CCCC

Page 81: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Figure 10.29 Average Overlap

2121 d

•The more difficult problems if the fragments overlap and

Page 82: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

glEnable(GL_POINT_SMOOTH);glEnable(GL_LINE_SMOOTH);glEnable(GL_SMOOTHING);glBlendFunc(GL_SRC_ALPHA, GL_ONE_MI

NUS_SRC_ALPHA);

Page 83: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.8.4 Back-to-Front and Front-to-Back Rendering

Figure 10.30 Scene with translucent objects

Page 84: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.8.5 Splatting

Figure 10.31 Volume of voxels

Page 85: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

• Volume rendering : Marching Cubes in Chapter 8

• Direct Method : Computed Tomography(CT)• Splatting

– Simple way to generate an image– Footprint. Each voxel is projected onto the image pl

ane. Footprint is saved as a bitmap that can be bitblt into the frame buffer

– Color plate 26 and 27, and 28– How each splat is composited into the image.

Page 86: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Figure 10.32 Splat, or Footprint of voxel

Page 87: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

sdsd

ssdsd CCC

)1(

)1(

'

'

• We can go through the data back to front, adding the contributions of each voxel through its splat.

• We start with a background image, and blend in successive splat. We modify slightly our usual way of blending colors and opacities.

• If we are compositing back to front, and if the source is opaque (s=1), then so is d’ and the new destination color is the same as the source color.

• If the source is transparent, we retain the original destination color and opacity.

Back to front

Page 88: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

• Not need to keep the entire data set in memory to do rendering

• We can not speed up due to data dependancies.

- For example, if front of the volume is opaque, a back to front renderer nevertheless will process all voxels, even though we shall see only the front voxels in the final image.

Back to front

Page 89: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

• Front to back rendering by ray casting

• We determine when an opaque voxel is reached, and we stop tracing this ray immediately.

• Difficulties:

- A given ray passes through many slices of the data, and thus we need to keep all the data available.

Front to Back

Page 90: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Figure 10.33

(a) Ray casting for a volume (b) Top view

Page 91: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.8.6 Depth Cueing and Fog

fss CffCC )1('

• Depth cueing

-The oldest techniques in 3 D graphics

- Create illusion of depth by drawing lines father from the viewer dimmer than lines closer to the viewer.

• Fog

-Extension of depth cueing idea to create the illusion of partially translucent space between the object and the viewer

- Let f denote a fog factor. And let z be the distance between a fragment and the viewer. Cs and Cf are colors of the fragment, and the fog.

Page 92: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.8.6 Depth Cueing and Fog

• If f varies linearly, we have a depth-cueing effect.

• If f varies exponentially, we get effects that look more like fog.

Page 93: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

For example, in RGBA mode, we can set up a fog-density function by using the function calls

Glfloat fcolor[4]={…}glEnable(GL_FOG);glFogf(GL_FOG_MODE,GL_EXP);glFogf(GL_FOG_DENSITY, 0.5);glFogfv(GL_FOG_COLOR, fcolor);

25.0 zef

Page 94: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.9 Use of the Accumulation Buffer

• We can use the additional resolution to render successive images into one location while retaining numerical accuracy.

• The function glAccum– Add or multiply values from the frame buffer into the accumulation

buffer– Copy the contents of the accumulation buffer back to the frame b

uffer

Page 95: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

10.9 Use of the Accumulation Buffer

glClear(GL_ACUM_BUFFER_BIT);For (i=0; i< num_images; i++){

glClear(GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT);display_image(i);glAccum(GL_ACCUM, 1.0/(float) num_images);

}glAccum(GL_RETURN, 1.0)

Page 96: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Antialiasing using the accumulation buffer

• Antialiasing using the accumulation buffer

- Rather than antialiasing individual points and lines, we can antialias an entire scene into the accumulation buffer

- Regenerate the same scene with all objects or the viewer shifted slightly (less than one pixel). Average together the resulting images, the aliasing effects will be smoothed out.

- It is easier to shift (or jitter) the viewer, as we have to change only the parameters in glPerspective or glOrth.

Page 97: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

m

mk

n

nlljkiklij

ij

hab

aA

,

][

• A linear filter H produces a filtered matrix B.

• We can represent the image with NM matrix A.

• B is the result of convolving A with a filter matrix H.

Page 98: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

010

111

010

5

1H

121

242

120

16

1H

010

141

010

H

Used for Antialising

Use more points and weigh the center more heavily

Page 99: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Figure 10.35 Filtering and Convolution

Page 100: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Motion Blur

• If we jitter an object and render it multiple times, leaving the positions of the other objects unchanged, we get dimmer copies of the jitter object in the final images.

• If the object is moved along a path, rather than randomly jittered, we see the trail of the object.

• Similar to the result of tacking a photograph of a moving object using a long exposure time.

Page 101: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Motion Blur

Page 102: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Depth of field

• A real camera : depth of field

• Computer Graphics : an infinite depth of field

• Occasionally, we want to create an image that looks as though it were produced by a real camera.

Page 103: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them

Figure 10.36 Depth-of-field jitter

)(min'min nearf

f

zzz

xxx

• If we move the viewer from the origin in the x direction by x, we must change xmin to

• As we increase x and y, we create a narrower depth of field.

Page 104: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them
Page 105: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them
Page 106: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them
Page 107: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them
Page 108: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them
Page 109: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them
Page 110: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them
Page 111: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them
Page 112: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them
Page 113: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them
Page 114: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them
Page 115: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them
Page 116: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them
Page 117: Chap 10. Discrete Techniques 한림대학교 정보통신공학부 송 창근. 이산적 기법들 Until recently, application programmers had no functions in the API that allow them