Docsity

Real-time Rendering & Graphics Hardware: High-level Shading Languages and Shaders - Prof. , Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
1
Real-time Rendering & Graphics Hardware
PradeepSen Class 9 –February 14, 2007
ECE 595 / CS 491 / CS 591
Real-Time Rendering &
Graphics Hardware
Pradeep Sen
Advanced Graphics Lab
Class 9
February 14, 2007 Real-time Rendering & Graphics Hardware
PradeepSen Class 9 –February 14, 2007
Pop quiz!
This quiz will test you on your knowledge of
ARB fragment programs
Real-time Rendering & Graphics Hardware
PradeepSen 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
PradeepSen Class 9 –February 14, 2007
Last time
DirectX
Started talking about high-level shading
languages
Real-time Rendering & Graphics Hardware
PradeepSen Class 9 –February 14, 2007
Today
More on high-level shading languages
Specific kinds of shaders
Real-time Rendering & Graphics Hardware
PradeepSen 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
(glossiness, etc)
Real-time Rendering & Graphics Hardware
PradeepSen 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
PradeepSen Class 9 –February 14, 2007
High-end shading languages
For high-end rendering, shading languages
have been around for 20 years:
– Shade Trees (Cook 84)
final color
*
copper color
+
specular
*
ambient
*
ambient
weight
viewer
normal surface
roughness
specular
weight
Real-time Rendering & Graphics Hardware
PradeepSen Class 9 –February 14, 2007
High-end shading languages
For high-end rendering, shading languages
have been around for 20 years:
– Shade Trees (Cook 84)
+=
From Cook 84
pf3
pf4
pf5

Partial preview of the text

Download Real-time Rendering & Graphics Hardware: High-level Shading Languages and Shaders - Prof. and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

Real-time Rendering & Graphics Hardware Pradeep Sen

Class 9 – February 14, 2007

ECE 595 / CS 491 / CS 591

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

(glossiness, etc)

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

  • Carolco Pictures (1991)

Real-time Rendering & Graphics Hardware Pradeep Sen

Class 9 – February 14, 2007

Renderman Examples^ Terminator 2: Judgement Day

  • Carolco Pictures (1991)

Jurassic Park

  • Universal (1993)

Real-time Rendering & Graphics Hardware Pradeep Sen

Class 9 – February 14, 2007

Renderman Examples^ Terminator 2: Judgement Day

  • Carolco Pictures (1991)

Jurassic Park

  • Universal (1993)

Monsters, Inc.

  • Pixar (2001)

Real-time Rendering & Graphics Hardware Pradeep Sen

Class 9 – February 14, 2007

Renderman Examples^ Terminator 2: Judgement Day

  • Carolco Pictures (1991)

Jurassic Park

  • Universal (1993)

Monsters, Inc.

  • Pixar (2001)^ Finding Nemo
    • Pixar (2003)

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

A B

C

F

G^

K

I^

L

H J

D

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

A B

C

F

G^

K

I^

L

H J

D

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

A B

C

F

G^

K

I^

L

H J

D

Assumptions:• 8 instructions max per pass• 1 output per pass E

H J

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

A B

C

F

G^

K

I^

L

H J

D

E

A B

C

F

G^

K

I^

L

H J

D

E

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

(but you can implement these using interfaces)

  • Different from RenderMan or RTSL ƒ^

Based on syntax and philosophy of C– Data types and operators have a direct mapping to the

hardware

  • Low overhead, minimal management of application data ƒ^

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

fragment program

  • Supported by Cg, not HLSL ƒ^

Bind by name– The vertex program identifies the output interpolant by

name. The same name is used to identify the inputinterpolant in the fragment program.

  • Both Cg and HLSL support a more specific version of

bind-by-name where the names are pre-defined. Thisallows compatibility between different vertex andfragment programs (plug-and-play)

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

addressing capability– While C blurs the distinction between array types andpointer types, Cg is explicit about the two

ƒ^

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:

  1. Compiler which compiles the Cg programsusing the specified profiles and outputs theappropriate assembly code2) Interface to the 3D API, which load and bindsthe Cg programs, passes environment variablesin, etc.

Real-time Rendering & Graphics Hardware Pradeep Sen

Class 9 – February 14, 2007

Simple vertex program in Cg void

simpleTransform(

float

objectPosition :

POSITION

float

color :

COLOR

float

decalCoord :

TEXCOORD

float

lightMapCoord :

TEXCOORD

out float

clipPosition :

POSITION

out float

oColor :

COLOR

out float

oDecalCoord :

TEXCOORD

out float

oLightMapCoord :

TEXCOORD

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 :

COLOR

float

decalCoord :

TEXCOORD

float

lightMapCoord :

TEXCOORD

uniform sampler2D

decal,

uniform sampler2D

lightMap) :

COLOR

float4 d =

tex2Dproj

(decal, decalCoord);

float4 lm =

tex2Dproj

(lightMap, lightMapCoord);

return

2.0 * color * d * lm;