CS 455 Computer Graphics

birdsowlΛογισμικό & κατασκευή λογ/κού

2 Δεκ 2013 (πριν από 4 χρόνια και 29 μέρες)

131 εμφανίσεις

CS 455


Computer Graphics


GPUs


Graphics Processing Units

GPUs


Graphic Processing Units


Specialized hardware that takes graphics processing off
of the CPU and performs the graphics processing itself.


Can be present on a video card,



or on the motherboard


Intel integrates a GPU into its


motherboard


Nvidia

and ATI control almost



all of the non
-
integrated video card market


GPU processing
power is growing
dramatically

Progression of GPUs

From Dave Luebke, SIGGRAPH 2008

Graphics Pipeline

Transformation

Per
-
vertex lighting

Viewing Transform

Viewport Transform

Clipping

Projection

Primitive Generation

Display

Texturing, fragment shading

Scan conversion

Translate, rotate, scale

Lighting at each vertex

Camera, etc.

Geometry shader


tesselation, mesh reduction

Perspective, orthographic

Against view frustum

Scale, translate to viewport

Rasterization

Fragment or pixel shading

Final colored pixels

Graphics Pipeline

Transformation

Per
-
vertex lighting

Viewing Transform

Viewport Transform

Clipping

Projection

Primitive Generation

Display

Texturing, fragment shading

Scan conversion

Easy to create
specialized
hardware for
these

Can extend the
specialized
hardware to deal
with these

GPU Evolution


Early GPUs implemented the graphic pipeline in
hardware


Each stage did one fixed task


Not very flexible


As GPUs became more popular, there was a surge to
improve them


Faster

-
More, smaller hardware

-
SIMD


More flexible

-
Programmable

Graphics Pipeline

Transformation

Per
-
vertex lighting

Viewing Transform

Viewport Transform

Clipping

Projection

Primitive Generation

Display

Texturing, fragment shading

Scan conversion

Fragment (or pixel) Shaders

Vertex Shaders

Geometry Shaders

Vertex Shaders


The GPU takes vertices as input


A “vertex shader” is run once for each vertex


Vertex shaders manipulate position, color, and texture
coordinates of vertices, but do not add new vertices


Output from the vertex shaders goes to the geometry
shader (if present) or to rasterization


Shader languages include Direct X’s HLSL, OpenGL’s
GLSL, and Cg

Vertex Shaders

3D position

Normal

Tex Coords

Color

3D position

Normal

Tex Coords

Color

Screen Position

Light,

Transform,
Project

A sample trivial GLSL vertex shader


This
transforms the input vertex the same way the
fixed
-
function pipeline would.



uniform Transformation {


mat4
projection_matrix
;


mat4
modelview_matrix
;

};



in vec3 vertex;



void main() {


gl_Position

=
projection_matrix

*






modelview_matrix

*





vec4
(vertex, 1.0);

}


Vertex Shader Cg Code

void
phongShadeVertexProgram
(




float4
iCol

: COLOR,




float4
iPos

: POSITION,




float4
iNorm

: NORMAL,





float2 iTex0 : TEXCOORD0,




out float4
oColor

: COLOR,



out float4
oScreenPos

: POSITION,




out float2
oTex

: TEXCOORD0,



out float3
oPos

: TEXCOORD1,



out float3
oNormal

: TEXCOORD2

)

{


oScreenPos

=
mul
(
glstate.matrix.mvp,iPos
);


oPos

=
mul
(
glstate.matrix.modelview
[0],
iPos
).xyz;


oN

= normalize(
mul
(
glstate.matrix.invtrans.modelview
[0],
iNorm
).xyz);


oTex

= iTex0;


oColor

=
iCol
;



return;

} // main


Geometry Shaders


Takes the initial geometry sent to the pipeline, and can
generate new primitives from that data.


Can be used to simplify or tessellate geometry.


Used for:


Point sprite generation


Geometry tessellation


Shadow volume extrusion


Single pass rendering to a cube map


A sample trivial GLSL geometry shader


This
is a simple pass
-
through
shader

for the color and
position
.




layout(triangles) in;

layout(
triangle_strip
,
max_vertices

= 3) out;



void main() {


for(
int

i

= 0;
i

<
gl_in.length
();
i
++) {


gl_Position

=
gl_in
[
i
].
gl_Position
;


EmitVertex
();


}


EndPrimitive
();

}

Fragment or Pixel Shaders


Operations performed on each pixel


Generally compute the color and other attributes of
each pixel.


Can later use the depth of the pixel for Z
-
buffering


Used for:


Bump mapping


Shadows


Specular highlights


Translucency


Fragment Shaders


One fragment in, 0
-
1 fragments out

3D position

Normal

Tex Coords

Color

Screen Position, Depth

Color

Depth

Texture and Light

Texture

Maps

A sample trivial GLSL fragment shader


This produces a red fragment.



glBindFragDataLocation
(Program, 0, "
MyFragColor
")
;

out vec4
MyFragColor
;

void main(void)

{


MyFragColor = vec4(1.0, 0.0, 0.0, 1.0);

}

Example Cg Fragment Shader Code

void
phongShadeFragmentProgram
(



float2

tex0

: TEXCOORD0,



float3

P

: TEXCOORD1,



float3

N

: TEXCOORD2,



uniform sampler2D

textureMap
,



uniform float3

Ka,Ks,Kd,LP
,



uniform float

Kp
,



out float4


oColor

: COLOR)

{


N = normalize( N ); // Compute the diffuse term


float3 L = normalize(LP
-

P);


float
diffuseLight

= max(dot(L, N), 0);


float4 Td = tex2D(textureMap,tex0.xy);


float3 diffuse = float3(1.0,1.0,1.0) *
Kd

*
diffuseLight
;


// Compute the specular term


float3 V = normalize(
-
P);


float3 H = normalize(L + V);


float
specularLight

=
pow
(max(dot(H, N), 0),
Kp
);


if (
diffuseLight

<= 0)



specularLight

= 0;


float3 specular =
Ks.xyz

*
specularLight
;


oColor.xyz

= (
Ka
*float3(1.0,1.0,1.0) + diffuse + specular);


oColor.w

= 1;


return;

} // main


GPUs

CPU

GPU

Memory

Shared, or

integrated



architecture.

CPU

GPU

Memory

Dedicated memory.

GPUs

CPU

GPU

Memory

Shared, or

integrated



architecture.


12.8 GB/s

Intel GMA X3100

CPU

GPU

Memory

Dedicated memory.


103.7 GB/s

vNidia GeForce 8800 Ultra

Integrated vs. Dedicated


Integrated


384 MB (max)


12.8 GB/s


8 pipelines


Not clear


Intel GM995 chip set.




Dedicated


768 MB


103.7 GB/s


128 pipelines


$669


vNidia GeForce 8800
Ultra


Programming the GPU

User Program

Geometry Processing

Pixel
Shader

Screen

Triangle_strip

Vertex
shader

Visible?

Framebuffer

Includes lighting

Programming the GPU

User Program

Geometry Processing

Pixel
Shader

Screen

Triangle_strip

Vertex
shader

Visible?

Framebuffer

SIMD model, so assume

all of your data gets processed

simultaneously.

Programming the GPU

User Program

Geometry Processing

Pixel
Shader

Screen

Triangle_strip

Vertex
shader

Visible?

Framebuffer

Vertex shader program

Set the color at the vertex.

Transform to screen coordinates.

Ex: simulate ocean waves on GPU

Programming the GPU

User Program

Geometry Processing

Pixel
Shader

Screen

Triangle_strip

Vertex
shader

Visible?

Framebuffer

Vertex shader program

Pixel or Fragment Shader Program

Fragment = pixel + data

Per
-
pixel functions

Ex: Phong shading.

Shortcomings in GPU


Shadows


Poor soft shadows


Sharp accurate shadows still expensive


Reflections and Refractions


Still a cheat


Caustics


Soft Diffuse Illumination


Some success using spherical harmonics


Still hard to do


especially in dynamic scenes

General Purpose Computing (GPGPU)


Can we use the GPU for things other than graphics?


Yes


knowing the GPU architecture, you can use it for
other purposes.


Physics


Collision Detection


AI


Simulations


Robot motion planning


The computation of Voronoi diagrams


Password encryption cracking

Grid based simulations on GPGPU

GPGPU Collision Detection


Cullide
: Naga
Govindaraju

et. al