



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Real-Time Rendering &
Graphics Hardware
Pradeep Sen Advanced Graphics Lab
Class 9 February 14, 2007
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Pop quiz! ^
This quiz will test you on your knowledge ofARB fragment programs
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Announcements ^
New homework available (due Wednesday) ^
GFX Café series starting March 23 ^
I won’t be here on Wednesday (substitute:Joe Kniss)
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Last time ^
DirectX ^
Started talking about high-level shadinglanguages
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Today ^
More on high-level shading languages ^
Specific kinds of shaders
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Motivation
curly maple
padauk
walnut
^
We want the shader to do several things:– Model the surface color f(s,t) (albedo)– Deform the surface– Model how the light interacts with the surface
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Real-time shading languages ^
SGI Interactive Shading Language (SGI, 2000) ^
Real-time Shading Language (Stanford, 2001) ^
Cg (NVIDIA, 2003) ^
HLSL (Microsoft, 2003)– very similar to Cg ^
GLSL (3DLabs, 2003)– Included in OpenGL2.0 spec ^
Brook, Sh (2005)– GPGPU
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
High-end shading languages ^
For high-end rendering, shading languageshave been around for 20 years:– Shade Trees (Cook 84)
final color
copper color
specular
ambient
ambientweight
viewer normal
surfaceroughness
specularweight
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
High-end shading languages ^
For high-end rendering, shading languageshave been around for 20 years:– Shade Trees (Cook 84)
+^
=
From Cook 84
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
High-end shading languages ^
For high-end rendering, shading languageshave been around for 20 years:– Shade Trees (Cook 84)– Pixel stream programs (Perlin 85)
from Perlin 85
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
High-end shading languages ^
For high-end rendering, shading languageshave been around for 20 years:– Shade Trees (Cook 84)– Pixel stream programs (Perlin 85)– RenderMan Shading Language (Hanrahan and
Lawson 90)
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Renderman Examples^ Terminator 2: Judgement Day
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Renderman Examples^ Terminator 2: Judgement Day
Jurassic Park
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Renderman Examples^ Terminator 2: Judgement Day
Jurassic Park
Monsters, Inc.
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Renderman Examples^ Terminator 2: Judgement Day
Jurassic Park
Monsters, Inc.
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
RTSL ^
Inspired by the RenderMan shadinglanguage ^
First shading language to expose capabilityat both the vertex and fragment levels ^
Single program model– User does not specify what is a vertex program
and what is a fragment program– Automatically evaluated computation frequency:constant, per-primitive, per-vertex, per-fragment
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Computation Frequencies
Courtesy Kekoa Proudfoot
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
RTSL shader example surface shader float4anisotropic_ball (texref anisotex, texref star){
// generate texture coordinatesperlight float4 uv = {center(dot(B, E)), center(dot(B, L)),
// compute reflection coefficientperlight float4 fd = max(dot(N, L), 0);perlight float4 fr = fd * texture(anisotex, uv);// compute amount of reflected lightfloat4 lightcolor = 0.2 * Ca + integrate(Cl * fr);// modulate reflected light colorfloat4 uv_base = {center(Pobj[2]), center(Pobj[0]),
return lightcolor * texture(star, uv_base); }^
Courtesy Kekoa Proudfoot
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Shaders as DAGs
Assumptions:• 8 instructions max per pass• 1 output per pass E
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Shaders as DAGs
Assumptions:• 8 instructions max per pass• 1 output per pass E
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Shaders as DAGs
Assumptions:• 8 instructions max per pass• 1 output per pass E
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Things that make the search complicated… ^
Computation can be duplicated ^
The number of graph cuts is variable ^
Limited number of outputs per pass
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Dominator tree
Original DAG
Dominator tree
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Cg ^
Not an application-specific shading language– Does not explicitly define “surface” or “light” shaders
Based on syntax and philosophy of C– Data types and operators have a direct mapping to the
Departs from the single program model: usersrequired to write vertex and fragment programsseparately
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Cg ^
Compilation target controlled by user-specifiedprofiles ^
Compilation of Cg happens at run-time in thedriver
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Interpolants ^
How do you pass interpolants betweenvertex/fragment programs?
Vertex program Fragment program rasterizer pos
color
normal
coord 0
coord 1
pos
color
normal
coord 0
coord 1
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Interpolant binding ^
Bind by position– The interpolant’s position is consistent from vertex to
Bind by name– The vertex program identifies the output interpolant by
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Important differences from C ^
No pointers!– Current graphics hardware have very limited indirect
^
No bitwise operations! ^
First class support for vector data types: float4,float4x ^
Swizzling and masking (var.xy) ^
Design paradigm: expose what the hardware doesbest
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Comparison with C++ ^
Some notion of constructors, but not user-defined: ^
No support for “programming in the large.”Missing classes, templates, namespaces,etc. ^
No support for file I/O
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Cg runtime ^
Is composed of two parts:
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Simple vertex program in Cg void
simpleTransform(
float
objectPosition :
float
color :
float
decalCoord :
float
lightMapCoord :
out float
clipPosition :
out float
oColor :
out float
oDecalCoord :
out float
oLightMapCoord :
uniform float
brightness,
uniform float4x
modelViewProjection) {
clipPosition =
mul
(modelViewProjection, objectPosition);
oColor = brightness * color;oDecalCoord = decalCoord;oLightMapCoord = lightMapCoord; }
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Compiled version ^
When compiled with a
vs_1_
profile
(DirectX 8 vertex program)
vs.1.1mov
oT0, v mov
oT1, v dp
oPos.x,
c1, v
dp
oPos.y,
c2, v
dp
oPos.z,
c3, v
dp
oPos.w,
c4, v
mul
oD0, c0.x, v END
Real-time Rendering & Graphics Hardware Pradeep Sen
Class 9 – February 14, 2007
Simple fragment program in Cg
float
brightLightMapDecal(
float
color :
float
decalCoord :
float
lightMapCoord :
uniform sampler2D
decal,
uniform sampler2D
lightMap) :
float4 d =
tex2Dproj
(decal, decalCoord);
float4 lm =
tex2Dproj
(lightMap, lightMapCoord);
return
2.0 * color * d * lm;