6.1 vis_04 data visualization lecture 6 - a rough guide to rendering
Post on 21-Dec-2015
226 views
TRANSCRIPT
6.2Vis_04
Rendering of TrianglesRendering of Triangles
Surface views for 2D scalar visualization, and isosurfaces for 3D scalar visualization both generate a triangular mesh surface
Techniques for rendering these meshes rely on :– an understanding of how light is
reflected from surfaces - to define the colour of points within each triangle
– generating a 2D image representation of the 3D scene
Just a simplified view here...
6.3Vis_04
Reflection ModelReflection Model
There are two major components to consider in modelling reflection of light from a surface– diffuse reflection: this gives a dull
effect; light is scattered evenly and gives the colour of the surface
– specular reflection: this gives shininess of surface; light is reflected at angle of perfect reflection and has colour of incoming light
– total effect is sum of both (plus ambient light)
6.4Vis_04
* intensity of reflected lightdepends on angle of light to surface
Reflection Model - Diffuse Reflection
Reflection Model - Diffuse Reflection
lightsourceN
L
I* = Intensity of light sourceN = Surface normalL = Direction of light sourceKd = Diffuse-reflectioncoefficient (gives colour)I = Reflected intensity
surface
I = Kd (cos ) I*
* equal reflection in all directions
I, I*, Kd have R, G, B components
6.5Vis_04
I* = Intensity of light sourceV = View directionR = Direction of perfect
reflected lightKs = Specular-reflection
coefficientI = Reflected intensity
I = Ks( cos )n I*
n varies with materiallarge n : shinysmall n : dull
Intensity depends on angle between eye and reflected light ray - and type of material
V
lightsourceN
LR
eye
surface
Reflection Model - Specular ReflectionReflection Model -
Specular Reflection
6.6Vis_04
Effect of Diffuse ReflectionSlide from Alan Watt, University of Sheffield
Effect of Diffuse ReflectionSlide from Alan Watt, University of Sheffield
6.7Vis_04
Effect of Diffuse plus Specular Reflection
Slide from Alan Watt, University of Sheffield
Effect of Diffuse plus Specular Reflection
Slide from Alan Watt, University of Sheffield
6.8Vis_04
RenderingRendering
To render a scene composed of a number of surfaces (here triangles):
We can project the surfaces on to a viewing plane, determining which are visible to the eye, and assigning the colour as given by the lighting model
6.11Vis_04
Triangle RenderingTriangle Rendering
Thus, by projecting the triangle vertices, we get position of triangle in image - how can we get the colour of pixels within the triangle?
There are three techniques of increasing complexity - and increasing realism– Flat shading– Gouraud shading– Phong shading
6.12Vis_04
Flat Shading of Triangular Mesh
Flat Shading of Triangular Mesh
Each point in a triangle given the same intensity
N1N2
N3
N4
Fast and simple- but intensitydiscontinuities at edges
Calculate intensityfor each trianglefrom reflection modelequations
6.13Vis_04
Gouraud Shading of Triangular Mesh
Gouraud Shading of Triangular Mesh
Aim is to shade mesh as though it were curved surface
Step 1: Approximate normal at each vertex in some way -
one possibility is to average the normals of surrounding triangles
6.14Vis_04
Gouraud Shading of Triangular Mesh
Gouraud Shading of Triangular Mesh
Step 2: Calculate the intensityat each vertex using the lightingmodel
I1
I2
I3
I1
I2
I3
Step 3: Calculate the intensityat any interior point by linearinterpolation in triangle
6.15Vis_04
Phong Shading of Triangular Mesh
Phong Shading of Triangular Mesh
N1
N2
N3
Step 1: As for Gouraud, estimatenormals at vertices
N1
N2
N3
Step 2: Estimate normal at aninterior point by linear interpolation
Step 3: Calculate intensity byapplying lighting model
6.16Vis_04
Comparison of TechniquesComparison of Techniques
Flat shading:– fast and simple, 1 lighting calc’n done per
triangle, all pixels given same intensity– discontinuity in intensity across edges
Gouraud shading– relatively fast, 1 lighting calc’n per vertex,
intensity linearly interpolated from vertex intensities - giving smooth appearance – now industry standard
Phong shading– slower, lighting calc’n for each pixel - giving
very smooth appearance – not supported in OpenGL
6.17Vis_04
Constant or Flat Shading -Each Polygon has Constant
Shade
Constant or Flat Shading -Each Polygon has Constant
Shade
6.20Vis_04
Flat, Gouraud and Phong Shading
Slides from Alan Watt, University of Sheffield
Flat, Gouraud and Phong Shading
Slides from Alan Watt, University of Sheffield
6.21Vis_04
Rendering by Ray TracingRendering by Ray Tracing
An alternative to polygon projection is the concept of ray tracing
Very high quality rendering with global inter-reflections
6.22Vis_04
Rendering of IsosurfacesRendering of Isosurfaces
Isosurface algorithms generate triangular meshes which can be rendered as just described
Key is the estimation of vertex normals for Gouraud and Phong shading
One possibility is to construct the entire surface, then assign vertex normals as average of normals of surrounding triangles
6.23Vis_04
Rendering of IsosurfacesRendering of Isosurfaces
An alternative - generally preferred - is based on fact that surface normal is equal to the gradient vector of f
At (xi,yj,zk), df/dx = 0.5*(f i+1,j,k - f i-1,j,k) df/dy = 0.5*(f i,j+1,k - f i,j-1,k) df/dz = 0.5*(f i,j,k+1 - f i,j,k-1)
This gives us normals at all grid points,and then trilinear interpolation will givenormals at the triangle vertices