Shading & Texture. Shading Flat Shading The process of assigning colors to pixels. Smooth Shading Gouraud ShadingPhong Shading Shading.

Slides:



Advertisements
Similar presentations
16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.
Advertisements

Virtual Realism TEXTURE MAPPING. The Quest for Visual Realism.
1 Graphics CSCI 343, Fall 2013 Lecture 18 Lighting and Shading.
3D Graphics Rendering and Terrain Modeling
Computer Graphics Inf4/MSc Computer Graphics Lecture 13 Illumination I – Local Models.
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
1 Computer Graphics Chapter 9 Rendering. [9]-2RM Rendering Three dimensional object rendering is the set of collective processes which make the object.
Based on slides created by Edward Angel
Illumination Model & Surface-rendering Method 박 경 와.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Shading I.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Lighting/Shading III Week.
Computer Graphics - Class 10
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Lighting/Shading III Week.
IMGD 1001: Illumination by Mark Claypool
(conventional Cartesian reference system)
X86 and 3D graphics. Quick Intro to 3D Graphics Glossary: –Vertex – point in 3D space –Triangle – 3 connected vertices –Object – list of triangles that.
CS 4731: Computer Graphics Lecture 19: Shadows Emmanuel Agu.
Materials in OpenGL A material is defined by ρ a, ρ s, ρ d, and f for each of the R, G, B components. –Fig contains a table of coefficients for various.
7M836 Animation & Rendering
6.1 Vis_04 Data Visualization Lecture 6 - A Rough Guide to Rendering.
©Larry F. Hodges (modified by Amos Johnson) 1 Shading Models.
Coordinate Systems X Y Z (conventional Cartesian reference system) X Y Z.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Shading Week 5, Wed 1 Oct 2003 recap: lighting shading.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Lighting and Shading Week.
CS 480/680 Computer Graphics Shading I Dr. Frederick C Harris, Jr.
Computer Graphics An Introduction. Computer Graphics 26/9/2008Lecture 12 What’s this course all about? We will cover… Graphics programming and algorithms.
CS 445 / 645 Introduction to Computer Graphics Lecture 18 Shading Shading.
Shading (introduction to rendering). Rendering  We know how to specify the geometry but how is the color calculated.
University of Illinois at Chicago Electronic Visualization Laboratory (EVL) CS 426 Intro to 3D Computer Graphics © 2003, 2004, 2005 Jason Leigh Electronic.
COMPUTER GRAPHICS CS 482 – FALL 2014 AUGUST 27, 2014 FIXED-FUNCTION 3D GRAPHICS MESH SPECIFICATION LIGHTING SPECIFICATION REFLECTION SHADING HIERARCHICAL.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
CS 638, Fall 2001 Admin Grad student TAs may have had their accounts disabled –Please check and the lab if there is a problem If you plan on graduating.
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Textures and shadows  Generation  Mipmap  Texture coordinates,
COLLEGE OF ENGINEERING UNIVERSITY OF PORTO COMPUTER GRAPHICS AND INTERFACES / GRAPHICS SYSTEMS JGB / AAS 1 Shading (Shading) & Smooth Shading Graphics.
Computer Graphics An Introduction. What’s this course all about? 06/10/2015 Lecture 1 2 We will cover… Graphics programming and algorithms Graphics data.
Steve Sterley. Real World Lighting Physical objects tend to interact with light in three ways: Absorption (black body) Reflection (mirror) Transmission.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Basic Rendering Pipeline and Shading Spring 2012.
Illumination and Shading How to shade surfaces based on the position,orientation,characteristics of the surfaces and the light sources illuminating them.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading.
Illumination and Shading
CS 325 Introduction to Computer Graphics 03 / 29 / 2010 Instructor: Michael Eckmann.
CS 445 / 645 Introduction to Computer Graphics Lecture 15 Shading Shading.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
Local Illumination and Shading
Illumination and Shading Prof. Lizhuang Ma Shanghai Jiao Tong University.
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
Render methods. Contents Levels of rendering Wireframe Plain shadow Gouraud Phong Comparison Gouraud-Phong.
Computer Graphics One of the central components of three-dimensional graphics has been a basic system that renders objects represented by a set of polygons.
David Luebke3/16/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
Computer Graphics Ken-Yi Lee National Taiwan University (the slides are adapted from Bing-Yi Chen and Yung-Yu Chuang)
Applications and Rendering pipeline
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Illumination and Shading Prof. Lizhuang Ma Shanghai Jiao Tong University.
Computer Graphics Chapter 9 Rendering.
3D Graphics Rendering PPT By Ricardo Veguilla.
Chapter 14 Shading Models.
CSC461: Lecture 23 Shading Computation
Computer Graphics One of the central components of three-dimensional graphics has been a basic system that renders objects represented by a set of polygons.
Illumination and Shading
Texture Mapping 고려대학교 컴퓨터 그래픽스 연구실.
Computer Graphics (Fall 2003)
Chapter 14 Shading Models.
Illumination Model 고려대학교 컴퓨터 그래픽스 연구실.
Adding Surface Detail 고려대학교 컴퓨터 그래픽스 연구실.
Adding Surface Detail 고려대학교 컴퓨터 그래픽스 연구실.
Presentation transcript:

Shading & Texture

Shading Flat Shading The process of assigning colors to pixels. Smooth Shading Gouraud ShadingPhong Shading Shading

Shading Model Flat Shading Compute Phong lighting once for entire polygon Gouraud Shading Compute Phong lighting at the vertices and interpolate lighting values across polygon Phong Shading Interpolate normals across polygon and perform Phong lighting across polygon

Flat Shading For each polygon – Determines a single intensity value at a chosen point on the polygon. – Uses that value to shade the entire polygon. Assumptions – Light source at infinity – Viewer at infinity – Only ambient light is present

Problems of Flat Shading Specular highlights tends to get lost If chosen point on polygon is at location of the light soure, then color of the polygon will be significantly distortes. Flat Shading

Smooth Shading Introduce vertex normals at each vertex – Usually different from facet normal – Used only for shading – Think of as a better approximation of the real surface that the polygons approximate – Finds color value for each point in the polygon individually. Two types – Gouraud Shading – Phong Shading (do not confuse with Phong Lighting Model)

Gouraud Shading This is the most common approach – Perform Phong lighting at the vertices – Linearly interpolate the resulting colors over faces Along edges Along scanline

Gouraud Shading x right ysys y top y bott x left color 1 color 2 color 3 color 4 y4y4

Gouraud Shading x right ysys y top y bott x left color 1 color 2 color 3 color 4 y4y4 Calculate the surface normals along the scan line and the edge using incremental approach Y s’

Flat vs Gouraud Shading Images in left column are shaded using Flat Shading Images in right column are shaded using Gouraud Shading

Problem of Gouraud Shading – Good for diffuse reflection – But lacks accurate specular component for bigger surface C1C1 C2C2 C3C3 Can’t shade the specular reflection

Phong Shading x ysys m1m1 m2m2 m3m3 m4m4 m left m right mxmx Interpolate normal vectors of face vertices at each pixel, then perform phong lighting at each pixel. m left = m 1 + (m 4 -m 1 ) y s - y 1 Y 4 - y 1 m right = m 1 + (m 2 -m 1 ) y s - y 1 Y 2 - y 1 m x = m left + (m right -m left ) x - x left x right - x left Calculate the surface normals along the scan line and the edge using incremental approach

If a highlight does not fall on a vertex Gouraud shading may miss it completely, but Phong shading does not. Phong vs Gouraud Shading Phong Shading is more smooth.

Texture

Texture Types – Bitmap textures: Using some image file – Procedural textures: Changing pixel intensity in some controlled fashion without using external image source Texture(s, t): produces a color or intensity value for each value of s and t between 0 and 1.

Texture Bitmap textures: Using some image file having dimension CxR presented as txtr[c][r] – 0<=c<=C-1 and 0<=r<=R-1 Example: R= 400 and C= 600 texture(0.261,0.783) evaluates to txtr[156][313] texture(1,1) evaluates to txtr[600][400]

Texture Procedural textures: Changing pixel intensity in some controlled fashion without using external image source Not used frequently (We will mostly deal with bitmap textures that is image files)

Texture Adding Texture to flat surface Texture P and Surface S has – same shape – Same number of vertices Attaching a P i to each V i P 1 =T(0,0) P 2 =T(0,1)P 3 =T(1,1) P 4 =T(1,0) T(s,t) V1V1 V2V2 V3V3 V4V4

Texture Adding Texture to flat surface Texture P and Surface S has same shape glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(1.0, 2.0, 1.5); glTexCoord2f(0.0, 1.0); glVertex3f(1.0, 3.0, 1.5); glTexCoord2f(1.0, 1.0); glVertex3f(2.0, 3.0, 1.5); glTexCoord2f(1.0, 0.0); glVertex3f(2.0, 2.0, 1.5); glEnd(); 0,0 0,11,1 1,0 = Without distortion 1,2 1,32,3 2,2

Texture Adding Texture to flat surface Texture P and Surface S has same shape glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(1.0, 2.0, 1.5); glTexCoord2f(0.0, 0.5); glVertex3f(1.0, 3.0, 1.5); glTexCoord2f(0.5, 0.5); glVertex3f(2.0, 3.0, 1.5); glTexCoord2f(0.5, 0.0); glVertex3f(2.0, 2.0, 1.5); glEnd(); 0,0 0,11,1 1,0 = stretched 1,2 1,32,3 2,2

Texture Adding Texture to flat surface Texture P and Surface S has same shape glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(1.0, 2.0, 1.5); glTexCoord2f(0.0, 2.0); glVertex3f(1.0, 3.0, 1.5); glTexCoord2f(2.0, 2.0); glVertex3f(2.0, 3.0, 1.5); glTexCoord2f(2.0, 0.0); glVertex3f(2.0, 2.0, 1.5); glEnd(); 0,0 0,11,1 1,0 = Tile

Texture Adding Texture to flat surface Texture P and Surface S has same shape Mapping is clearly affine – Scaling – Rotation – Translation.

1.Creating a glowing object I = texture(s, t) gl.glEnable(GL.GL_TEXTURE_2D); gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE); gl.glBindTexture(GL.GL_TEXTURE_2D, texName); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(1.0, 2.0, 1.5); glTexCoord2f(0.0, 1.0); glVertex3f(1.0, 3.0, 1.5); glTexCoord2f(1.0, 1.0); glVertex3f(2.0, 3.0, 1.5); glTexCoord2f(1.0, 0.0); glVertex3f(2.0, 2.0, 1.5); glEnd(); Creating Visual effect using Texture = replaces colour and alpha with that of the texture.

Creating Visual effect using Texture 2.Modulating the reflection coefficient Object is the color of – Reflected diffuse light component – Reflected ambient light component gl.glEnable(GL.GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_MODULATE); gl.glBindTexture(GL.GL_TEXTURE_2D, texName); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(1.0, 2.0, 1.5); glTexCoord2f(0.0, 1.0); glVertex3f(1.0, 3.0, 1.5); glTexCoord2f(1.0, 1.0); glVertex3f(2.0, 3.0, 1.5); glTexCoord2f(1.0, 0.0); glVertex3f(2.0, 2.0, 1.5); glEnd();

Creating Visual effect using Texture 3.Simulating Roughness by Bump Mapping – Technique to give surface wrinkled or dimpled appearance without having to model each individual dimple – Independent of the viewing angle and object orientation

Creating Visual effect using Texture 3.Simulating Roughness by Bump Mapping scalar function texture(u, v) perturb the normal vector at each spot in a controlled fashion causes perturbations in amount of diffuse and specular light. Actual Scenario Required Scenario

Creating Visual effect using Texture 3.Simulating Roughness by Bump Mapping P(u, v) is a parameterized function, representing the position vectors of points P on the surface Surface normal at any point is given by m(u,v)=N= P u × P v 3D point at (u, v) corresponds to the texture at (u, v) New normal m’(u, v) =N' can be found by: N’=N+D (D is the perturbation vector) =N+ {(N×P v ) texture u - (N×P u ) texture v } texture u, texture v = partial derivatives of the texture function with respect to u and v P u, P v = partial derivatives of P(u, v) with respect to u and v

Adding Shadows of Objects

1.Shadows as Texture 2.Shadows using a shadow buffer

Adding Shadows of Objects 1.Shadows as Texture: Paint shadows as a texture Works for flat surfaces illuminated by point light source Problem: compute shape of shadow

Adding Shadows of Objects union of projections of individual faces = projection of entire Object Algorithm: 1.First, draw plane using specular-diffuse-ambient components 2.Then, draw shadow projections (face by face) using only ambient component

Shadows using a shadow buffer Shadow Buffer: An auxiliary second depth buffer Principle: any points in the scene that are “hidden” from the light source must be in shadow. if no object lies between a point and the light source the point is not in shadow.

Shadows using a shadow buffer Shadow buffer: 1.Contains a “depth picture” of the scene from the point of view of the light source 2.Each of its index (i, j) records the distance from the source to the closest object in the associated direction.

Shadows using a shadow buffer Step 1: Loading Shadow Buffer: Initialize each index value d[i][j] to 1.0 Position a camera at light source Rasterize each face in scene updating pseudo-depth Shadow buffer tracks smallest pseudo-depth so far

Shadows using a shadow buffer Step 1: Loading Shadow Buffer: Shadow buffer calculation is independent of eye position In animations, shadow buffer loaded once If eye moves, no need for recalculation If objects move, recalculation required

Shadows using a shadow buffer Step 2: Rendering Scene: Render scene using camera as usual While rendering a pixel find: – pseudo-depth D from light source to P – Index location [i][j] in shadow buffer, to be tested – Value d[i][j] stored in shadow buffer If d[i][j] < D (other object on this path closer to light) – point P is in shadow – set lighting using only ambient Otherwise, not in shadow

Reference Hill: sec: 8.3, 8.5.1, 8.5.3, 8.6