1 Rendering - III CS148, Summer 2010 Siddhartha Chaudhuri 2 Today ● Graphics Pipeline and Programmable Shaders ● Artist Workflow 3 Outline ● Intro to textures ● The fixed-function graphics pipeline ● Programmable stages ● Vertex shaders ● Fragment shaders ● OpenGL shading language (GLSL) ● A look ahead… (Adapted from Pat Hanrahan's slides) 4 Texturing: The 10,000m View + = (Globe and texture map courtesy James Hastings-Trew) 5 Texture Coordinates (0, 0) (0, 1) (1, 1) (1, 0) (0.5, 0.5) ● Texture coordinates on surface map surface points to image pixels ● Specify at vertices, interpolated within primitives 6 Specifying Texture Coordinates in GL ● Most common version: glTexCoord2f(float u, float v); ● Used just like glColor, glNormal etc., before a glVertex call ● Maps vertex to point (u, v) ∈ [0, 1] 2 on texture image ● This texture image is loaded with the functions glGenTextures, glTexImage2D and glBindTexture, look up SDK docs for syntax
5
Embed
Today Rendering - III - Computer graphicsgraphics.stanford.edu/courses/cs148-10-summer/docs/... · Graphics Pipeline and Programmable Shaders ... Interpolation (coordinates, colors,
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
Rendering - III
CS148, Summer 2010
Siddhartha Chaudhuri
2
Today
● Graphics Pipeline and Programmable Shaders
● Artist Workflow
3
Outline
● Intro to textures● The fixed-function graphics pipeline● Programmable stages
● Vertex shaders● Fragment shaders
● OpenGL shading language (GLSL)● A look ahead…
(Adapted from Pat Hanrahan's slides) 4
Texturing: The 10,000m View
+
=
(Glo
be a
nd te
xtur
e m
ap c
ourt
esy
Jam
es H
astin
gs-T
rew
)
5
Texture Coordinates
(0, 0)
(0, 1) (1, 1)
(1, 0)
(0.5, 0.5)
● Texture coordinates on surface map surface points to image pixels
● Specify at vertices, interpolated within primitives
6
Specifying Texture Coordinates in GL
● Most common version:
glTexCoord2f(float u, float v);
● Used just like glColor, glNormal etc., before a glVertex call
● Maps vertex to point (u, v) ∈ [0, 1]2 on texture image● This texture image is loaded with the functions
glGenTextures, glTexImage2D and glBindTexture, look up SDK docs for syntax
7
Basic Graphics Pipeline
Command
Vertex
Primitive Assembly
Rasterization
Fragment
Framebuffer Ops
Display
Texture
8
CommandCommand
Vertex
Primitive Assembly
Rasterization
Fragment
Framebuffer Ops
Display
● Command queue● Command interpretation● Unpacking and format conversion● Maintain graphics state
● Textures are arrays indexed by floats● “Sampler” interface for reading values
● Texture address calculation● Texture interpolation and filtering
Fragments Texture fragments
13
FragmentCommand
Vertex
Primitive Assembly
Rasterization
Fragment
Framebuffer Ops
Display
● Combine texture sampler outputs● Per-fragment lighting● Special effects
Fragments Textured fragments 14
Framebuffer OpsCommand
Vertex
Primitive Assembly
Rasterization
Fragment
Framebuffer Ops
Display
● Fragment tests:- Ownership: screen pixel owned by current window?- Scissor: pixel inside clipping rectangle?- Alpha: fragment α satisfies some condition?- Stencil: fragment within masked area?- Depth: new depth < old depth?
● Blending/compositing● Dithering and logical ops
Textured fragments Framebuffer pixels
15
DisplayCommand
Vertex
Primitive Assembly
Rasterization
Fragment
Framebuffer Ops
Display
● Gamma correction● Digital to analog conversion
Framebuffer pixels Light 16
Programmable Stages
Command
Vertex
Primitive Assembly
Rasterization
Fragment
Framebuffer Ops
Display
Texture
Texture
Programmable
17
Programmable Shaders● The code that processes a vertex is called a
vertex shader● The code that processes a fragment is called a
fragment shader● Shaders replace fixed-function stages● Can be written in
● Assembly● High-level languages (typically C-like)