Surface Rendering Methods -...

24
Surface Rendering Methods 6 th Week, 2008 Sun-Jeong Kim Polygon Rendering Methods Polygon Rendering Methods Determining the surface intensity at every Determining the surface intensity at every projected pixel position using an illumination model model Light-material interactions Polygonal shading Fl t h di Flat shading Gouraud shading Phong shading Computer Graphics Applications 2

Transcript of Surface Rendering Methods -...

Page 1: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Surface Rendering Methods

6th Week, 2008

Sun-Jeong Kim

Polygon Rendering MethodsPolygon Rendering Methods

Determining the surface intensity at everyDetermining the surface intensity at every projected pixel position using an illumination modelmodel

Light-material interactions

Polygonal shadingFl t h diFlat shading

Gouraud shading

Phong shading

Computer Graphics Applications2

Page 2: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Flat Shading (1)Flat Shading (1)

Constant-intensity surface renderingConstant-intensity surface renderingAssigning the same color to all projected surface positionspositions

Determining the intensity (RGB color) at a single surface position (ex. a vertex or the polygon centroid)

Fast and simple method

One rendering calculationOne rendering calculationfor each for each polygonpolygon

One rendering calculationOne rendering calculationfor each for each polygonpolygon

Computer Graphics Applications3

Flat Shading (2)Flat Shading (2)

Assumptions:Assumptions:The polygon is one face of a polyhedron (not a section of curved surface)section of curved surface)

All light sources are sufficiently far from the surfaceN⋅L and attenuation constantN L and attenuation constant

Viewing position is sufficiently far from the polygonV⋅R constant

Computer Graphics Applications4

Flat Shading Smooth Shading

Page 3: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Gouraud Shading (1)Gouraud Shading (1)

Intensity-interpolation surface renderingIntensity-interpolation surface renderingLinearly interpolating vertex intensity values across the polygon facesthe polygon faces

One rendering calculationOne rendering calculationfor eachfor each vertexvertex

One rendering calculationOne rendering calculationfor eachfor each vertexvertex

Vertex normal vectorA i th f l t f ll l

for each for each vertexvertexfor each for each vertexvertex

Averaging the surface normal vectors of all polygons sharing that vertex

∑n

kN

∑∑

=

==n

k k

k kV

1

1

N

NN

Computer Graphics Applications5 4321

4321

NNNN

NNNNN

++++++

=V

Gouraud Shading (2)Gouraud Shading (2)

Procedures:Procedures:Determine the average unit normal vector at each vertex of the polygonvertex of the polygon

Apply an illumination model at each polygon vertex to obtain the light intensityg y

Linearly interpolate the vertex intensity over the projected area of the polygonp j p yg

221

411

21

244 I

yy

yyI

yy

yyI

−−

+−−

=2121 yyyy

54

45 I

xx

xxI

xx

xxI pp

p

−+

−=

Computer Graphics Applications6

4545 xxxx −−

Page 4: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Gouraud Shading (3)Gouraud Shading (3)

Wireframe Flat Shading Gouraud Shading

Computer Graphics Applications7

Phong Shading (1)Phong Shading (1)

Normal-vector interpolation renderingNormal-vector interpolation renderingMore accurate interpolation method more realistic

One rendering calculationOne rendering calculationOne rendering calculationOne rendering calculation

More computation than Gouraud method

One rendering calculationOne rendering calculationfor each for each pixelpixel

One rendering calculationOne rendering calculationfor each for each pixelpixel

More computation than Gouraud method

Procedures:Determine the average unit normal vector at each vertex of the polygon

Li l i t l t th t l thLinearly interpolate the vertex normals over the projected area of the polygon

Apply an illumination model at positions along scan

Computer Graphics Applications8

Apply an illumination model at positions along scan lines to calculate pixel intensities

Page 5: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Phong Shading (2)Phong Shading (2)

Wireframe Flat

Computer Graphics Applications9

Gouraud Phong

Local vs Global RenderingLocal vs. Global Rendering

Local lighting model cannot handle:Local lighting model cannot handle:Blocking some of the light source from reaching the other spheresother spheres

Scattering some light among spheres

Global Lighting Model Local Lighting Model

Computer Graphics Applications10

Page 6: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Global EffectsGlobal Effects

Shadow

Translucent Surface

Multiple Reflection

Translucent Surface

Computer Graphics Applications11

Ray TracingRay Tracing

Continuing to bounce the pixel ray around in theContinuing to bounce the pixel ray around in the scene to collect the various intensity contribution

Generalization of the basic ray casting procedureGeneralization of the basic ray casting procedure

Global refection and transmission effectsHi hl li ti d h t li ti di lHighly realistic and photo-realistic display

Computer Graphics Applications12

Page 7: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Basic Ray Tracing Algorithm (1)Basic Ray Tracing Algorithm (1)

The coordinate system for ray tracingThe coordinate system for ray tracingCollecting the intensity contributions for a particular pixel by tracing a light path backward from the pixelpixel by tracing a light path backward from the pixel position into the scene

Computer Graphics Applications13

Basic Ray Tracing Algorithm (2)Basic Ray Tracing Algorithm (2)

Primary raysPrimary rays – ray castingPrimary raysPrimary rays – ray castingVisible surface detection

Secondary raysSecondary rays reflection and refraction raysSecondary raysSecondary rays – reflection and refraction raysRepeating the ray-processing procedures for the secondary rayssecondary rays

Computer Graphics Applications14

Page 8: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Basic Ray Tracing Algorithm (3)Basic Ray Tracing Algorithm (3)

Ray tracing treeRay tracing treeRay tracing treeRay tracing treeThe list of surfaces intersecting ray for each pixel

Left reflection right refractionLeft – reflection, right – refraction

Maximum depth – a user option

Terminating a path in the binary tree for a pixel if anyTerminating a path in the binary tree for a pixel if any one of the following conditions is satisfied:

The ray intersects no surfacesThe ray intersects no surfaces

The ray intersects a light source

The tree has been generated to its maximum allowable depth

Computer Graphics Applications15

Basic Ray Tracing Algorithm (4)Basic Ray Tracing Algorithm (4)

ReflectionReflection

Refraction (transparency)

( )NNuuR ⋅−= 2

Refraction (transparency)

NuT⎞

⎜⎜⎛

−−= ii

ri θηθη

coscosSnell’s law:

θηθη sinsin⎠

⎜⎝

ir

rr ηη iirr θηθη sinsin =

η ηrη iη

Computer Graphics Applications16

Page 9: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Basic Ray Tracing Algorithm (5)Basic Ray Tracing Algorithm (5)

Computer Graphics Applications17

RadiosityRadiosity

More precisely lighting effectsMore precisely lighting effectsConsidering the physical laws governing the radiant-energy transfersenergy transfers

Accurately describing diffuse reflections from a surfacesurface

RadiosityRadiosityThe quantity of radiant flux per unit area that is leaving a surface

R diR diRadianceRadianceThe radiant flux or the radiosity per unit solid angle ( t di )

Computer Graphics Applications18

(steradian)

Page 10: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Basic Radiosity ModelBasic Radiosity Model

Computing radiant-energy intersections betweenComputing radiant-energy intersections between all surfaces in a scene

Radiosity equationRadiosity equationRadiosity equationRadiosity equation

∑+=n

jkjkkk FBEB ρ

Bk: radisoity of surface k

∑=j

jkjkkk1

Ek: emission of surface k

ρk: reflectivity of surface k ∫ ∫=j ksurf surf jk

kj

jjk dAdA

rAF

2

coscos1

πφφ

Fjk: form factor for surfaces j and kThe fractional amount of radiant energy from surface j that reaches surface k

Computer Graphics Applications19

reaches surface k

Progressive Refinement Radiosity (1)Progressive Refinement Radiosity (1)

Disadvantage of radiosity methodDisadvantage of radiosity methodConsiderable processing time to calculate the form factorsfactors

Tremendous storage requirements

Progressive refinementProgressive refinementFi t li ht h (th hi h t di tFirst, light sources are chosen (the highest radient energy)

Other patches are selected based on the amount ofOther patches are selected based on the amount of light received from the light sources

Computer Graphics Applications20

Page 11: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Progressive Refinement Radiosity (2)Progressive Refinement Radiosity (2)

1 iteration

2 iterations2 iterations

24 iterations

100 iterations

Computer Graphics Applications21

Progressive Refinement Radiosity (3)Progressive Refinement Radiosity (3)

Computer Graphics Applications22

Page 12: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

OpenGL Surface-Property FunctionOpenGL Surface Property Function

Material – reflectivity properties of a surfaceMaterial – reflectivity properties of a surfaceglMaterial{if}(GLenum face, GLenum name, TYPE value);glMaterial{if}v(GLenum face, GLenum name, TYPE *value);glMaterial{if}(GLenum face, GLenum name, TYPE value);glMaterial{if}v(GLenum face, GLenum name, TYPE *value);

face

GL FRONT GL BACK GL FRONT AND BACK

glMaterial{if}v(GLenum face, GLenum name, TYPE value);glMaterial{if}v(GLenum face, GLenum name, TYPE value);

GL_FRONT, GL_BACK, GL_FRONT_AND_BACK

name

GL DIFFUSE GL SPECLAR GL AMBIENTGL_DIFFUSE, GL_SPECLAR, GL_AMBIENT, GL_AMBIENT_AND_DIFFUSE, GL_EMISSION, GL SHININESSGL_SHININESS

Computer Graphics Applications23

Default Light & MaterialDefault Light & Material

Computer Graphics Applications24

Page 13: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Result – Default Light & MaterialResult Default Light & Material

Computer Graphics Applications25

Specifying Material (1)Specifying Material (1)

Computer Graphics Applications26

Page 14: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Result – Specifying Material (1)Result Specifying Material (1)

Computer Graphics Applications27

Specifying Material (2)Specifying Material (2)

Computer Graphics Applications28

Page 15: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Result – Specifying Material (2)Result Specifying Material (2)

Computer Graphics Applications29

Specifying Material (3)Specifying Material (3)

Computer Graphics Applications30

Page 16: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Result – Specifying Material (3)Result Specifying Material (3)

Computer Graphics Applications31

Exercises (1)Exercises (1)

새로운 Material 값들을 설정하시오새로운 Material 값들을 설정하시오.각 Parameter의 의미를 파악하시오.

자신이 만든 조명과 함께 Rendering 하시오.떻 보 는 ?어떻게 보이는가?

Computer Graphics Applications32

Page 17: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Specifying Material (4)Specifying Material (4)

Computer Graphics Applications33

Specifying Material (5)Specifying Material (5)

Computer Graphics Applications34

Page 18: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Specifying Material (6)Specifying Material (6)

Computer Graphics Applications35

Specifying Material (7)Specifying Material (7)

Computer Graphics Applications36

Page 19: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

What’s Happening?What s Happening?

Computer Graphics Applications37

Exercises (2)Exercises (2)

Cone에 자신이 만든 Material을 지정해보시오Cone에 자신이 만든 Material을 지정해보시오.반드시 4개 Object가 다른 Material을 가지고 있어야 함

Computer Graphics Applications38

Page 20: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Color Material (1)Color Material (1)

Specifying a material by the color referred to bySpecifying a material by the color referred to by all following calls to glColor*( )

l bl ( )l bl ( )glEnable(GL_COLOR_MATERIAL);glEnable(GL_COLOR_MATERIAL);

glColorMaterial(GLenum face, GLenum name);glColorMaterial(GLenum face, GLenum name);

face

GL FRONT GL BACK GL FRONT AND BACKGL_FRONT, GL_BACK, GL_FRONT_AND_BACK

name

GL DIFFUSE GL SPECLAR GL AMBIENTGL_DIFFUSE, GL_SPECLAR, GL_AMBIENT, GL_AMBIENT_AND_DIFFUSE, GL_EMISSION

Computer Graphics Applications39

Color Material (2)Color Material (2)

Computer Graphics Applications40

Page 21: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Color Material (3)Color Material (3)

Computer Graphics Applications41

Result – Color MaterialResult Color Material

Computer Graphics Applications42

Page 22: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Shading Model in OpenGLShading Model in OpenGL

Computing a color for only the first vertex in aComputing a color for only the first vertex in a polygon

glShadeModel( GL FLAT );glShadeModel( GL FLAT );

Performing the lighting calculation at each vertex d h i l i l h

glShadeModel( GL_FLAT );glShadeModel( GL_FLAT );

and then interpolating vertex colors across the polygon ( default)

Enabling automatic normalization

glShadeModel( GL_SMOOTH );glShadeModel( GL_SMOOTH );

gIncurring a performance penalty

glEnable( GL NORMALIZE );glEnable( GL NORMALIZE );

Computer Graphics Applications43

glEnable( GL_NORMALIZE );glEnable( GL_NORMALIZE );

Flat Shading in OpenGLFlat Shading in OpenGL

Constant shadingConstant shading

glShadeModel(GL_FLAT);glShadeModel(GL_FLAT); pp1

n_

glBegin(GL_TRIANGLES);glNormal3fv(n);

_

glBegin(GL_TRIANGLES);glNormal3fv(n);

p0

pg ( );glVertex3fv(P1);glVertex3fv(P2);glVertex3fv(P3);

g ( );glVertex3fv(P1);glVertex3fv(P2);glVertex3fv(P3); ( ) ( )0201 ppppn −×−=

p2

glVertex3fv(P3);glEnd();

glVertex3fv(P3);glEnd();

( ) ( )0201 pppp

Computer Graphics Applications44

Page 23: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Smooth Shading in OpenGLSmooth Shading in OpenGL

Gouraud shading defaultGouraud shading default

glShadeModel(GL_SMOOTH);glShadeModel(GL_SMOOTH);

glBegin(GL_TRIANGLES);glNormal3fv(n1);

glBegin(GL_TRIANGLES);glNormal3fv(n1);glVertex3fv(P1);glNormal3fv(n2);glVertex3fv(P2);

glVertex3fv(P1);glNormal3fv(n2);glVertex3fv(P2); 4321 nnnn

n++++++

=glNormal3fv(n3);glVertex3fv(P3);

glEnd();

glNormal3fv(n3);glVertex3fv(P3);

glEnd();

4321 nnnn +++

g ();g ();

Computer Graphics Applications45Note silhouette edge

Flat ShadingFlat Shading

Computer Graphics Applications46

Page 24: Surface Rendering Methods - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cga/src/06render.pdf · Surface Rendering Methods 6th Week, 2008 Sun-Jeong Kim Polygon Rendering

Result – Flat ShadingResult Flat Shading

Computer Graphics Applications47

Exercises (3)Exercises (3)

서로 다른 재질을 사용하여 모델링 하시오서로 다른 재질을 사용하여 모델링 하시오.

Computer Graphics Applications48