lecture - computer graphics
TRANSCRIPT
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 1/21
Visualization of Fluid Flows andFlow Diagnostics
Sourabh Bhat
University of Petroleum & Energy Studies
Computer Graphics
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 2/21
Computer Graphics
Computer Graphics Programming Evolution
1) Hardware – Direct register / video buffer
programming
2) OS (Win32, X, MacOS)
3) Graphics Standard (GKS, PHIGS, OpenGL)
4) Platform independent (Python, Java)
Evolution
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 3/21
Contents
• Example: Make a 2D Gaussian Plot
• Data Sampling
•
Graphic rendering – Light rendering model
• Texture mapping
•Transparency and blending
• Visualization pipeline
What are we going to study today?
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 4/21
Example2D Gaussian Function
3
1111
1111where
,22
RS
,- ,- D
,- y; ,- x ,
e y x f y x
Compact domain,
Continuous data
Continuous 3D surface in 3D space
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 5/21
Example
• Sampling:
– Nx = 30
– Ny = 30
– Uniform grid
in domain space
• Mapping:
– 3D surface is
mapped to set
of 4 vertex polygon
2D Gaussian Function
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 6/21
Example
• In 3D the quadriletral (3D polygon) is given by:
– V1 = <x, y, f(x, y)>
– V2 = <x + dx, y, f(x + dx, y)>
– V3 = <x + dx, y + dy, f(x + dx, y + dy)>
– V4 = <x, y + dy, f(x, y + dy)>
• These graphics primitives are rendered fast by
computers• The quad has uniform illumination or lighting
on its surface, so called flat shading
Quadrilateral in 3D space
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 7/21
Example
float X_min, X_max;
float Y_min, Y_max;
int N_x, N_y;
float dx = (X_max-X_min)/N_x;
float dy = (Y_max-Y_min)/N_y;
float f(float,float);
for (float x=X_min;x<=X_max-dy;x+=dx)
for (float y=Y_min;y<=Y_max-dy;y+=dy)
{
Quad q;
q.addPoint (x,y, f(x,y));q.addPoint (x+dx,y, f(x+dx,y));
q.addPoint (x+dx,y+dy, f(x+dx,y+dy));
q.addPoint (x,y+dy, f(x,y+dy));
}
Implementation
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 8/21
Rendering
• Computer graphic rendering generate a image
from 3D Scene, for a given data set
• Ingredients:
– A 3D scene
– A set of lights
– A viewpoint
• Determination of illumination of primitive
shapes?
Basics
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 9/21
Rendering
• Rendering methods decide the approximationof light effects
– Global illumination – Ray tracing (Accurate but
computationally expensive) – Local illumination – Relate illumination of a scene
point directly to the light-set and not any otherscene points (Phong Model)
• Phong local lighting model (OpenGL): Assumethat scene consist of opaque objects in voidspace, illuminate by point-like light source
Equations
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 10/21
Phong Local Lighting ModelEquation
))0,max()0,max((),,( V specdiff ambl C C C I p I
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 11/21
Phong Local Lighting Model
I(p,v,L): intensity of the scene point
Il: Intensity of the light
p: location of the scene point
V: direction vector from p to the viewpoint
L: direction vector from the light to p
n: surface normal at p
r: direction of the reflecting light
α: specular power α
Three components:
Camb: ambient lighting, overall effect of other objects, assuming to be constant
Cdiff : diffuse lighting, scattering of the surface, equal in all direction; plastic surface
Cspec: specular lighting, mirror-like surface
Equation
))0,max()0,max((),,( V specdiff ambl C C C I p I
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 12/21
Shading (Coloring)
• Flat shading:• Given a polygon surface (e.g., quadrilateral), flat shading
applies the lightening model once for the completepolygon, e.g., for the center point
•The whole polygon surface has the same light intensity
• The least expensive
• But visual artifact of the “faceted” surface
• Gouraud shading (or smooth shading):• Apply lightening model at every vertex of the polygon
• The intensity between the vertices are calculated usinginterpolation, thus yielding smooth variation
Primitive Shape
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 13/21
Shading (Coloring)Primitive Shape
Flat Shading Gouraud Shading
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 14/21
Shading (Coloring)
• Needs color definition
• Shading type (Flat or Gouraud)
•
Color distribution (Centroid color for Flat,vertex color for Gouraud)
Programming Example
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 15/21
Surface Normals
• Using gradient:
• Using normal averaging:
Formulae
)1,,
y
f
x
f (-n
N
pn j p j
)(
in
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 16/21
Texture
• Effectively simulate a wide range of appearance on the
surface of a rendered object
• Improve the realism of visualization
• Method: pre-define a texture image, mapping the polygon
vertex coordinates to texture coordinates, and then combine
the texture color with the polygon color
Mapping
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 17/21
Transparency & Blending
• Rendering translucent (or half-transparent) shape
• See multiple shapes at the same time
• e.g., the Gaussian surface and the underlying gridded
domain
Overlap objects in scene
• Blending method (rendering the transparent effect)
•
Source: the shape is being drawn• Destination: the frame buffer (currently displayed image)
• Source + Destination
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 18/21
Transparency & BlendingExample
The Gaussian Surface
The Grid
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 19/21
Transparency & Blending
• The blending output is a weighted
combination of the source and the destination• sf: source weight factor, [0,1]
• Also called alpha component
•df: destination weight factor, [0,1]
• sf and df: also called blending factors
Formulae
ndestinatiodf source sf dst **'
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 20/21
The Visualization Pipeline
float data[N_x,N_y]
Class Quad
)( 22
),f( y xe y x Continuous data
Discrete dataset
Geometric object
Displayed image
Data Acquisition
Data Mapping
Rendering
7/29/2019 Lecture - Computer Graphics
http://slidepdf.com/reader/full/lecture-computer-graphics 21/21
Quick Recap
• Data Sampling & Mapping
• Graphic rendering
– Light rendering model
• Texture mapping
• Transparency and blending
•
Visualization pipeline