RenderMan - Shading Language: Concepts
Download
Report
Transcript RenderMan - Shading Language: Concepts
RenderMan
- Shading Language: Concepts -
Conventional Shading
System
• Fixed parameter shading system
• Disadvantages
– Built-in shading model is NOT enough
– New shading model
• Realistic shading model
• NPR
– Can be inefficient
• Flexible, extensible system is needed
New Shading System
• Turner Whitted & David M. Weimer
– 1980, Shading dispatch table
• Robert Cook
– 1984, Shade Trees
• Ken Perlin
– 1985, Pixel Stream
• Pat Hanrahan & Jim Lawson
– 1990, Shading Language
Parameterized shading
model
• Phong illumination model
Coutput K aCamb
nlights
n
(
K
C
(
N
L
)
Cl
K
C
(
R
L
)
)
d diff
i
i
s spec
i
i 1
• Does not change the fundamental
form of the shading equation
– Narrow range of appearances
Quick tour of a Shader
surface
plastic(float Ka = 1, Kd = 1, Ks = 0.5, roughness = 0.1;
color specularcolor = 1;)
{
/* simple plastic-like reflection model */
normal Nf = faceforward(normalize(N), I);
vector V = -normalize(I);
Ci = Cs * (Ka*ambient() + Kd*diffuse(Nf))
+ Ks*specularcolor*specular(Nf, V, roughness);
Oi = Os;
Ci *= Oi;
}
Types of shaders
• Surface shaders
– Appearance of surface
– How they react to the lights
• Displacement shaders
– How wrinkle or bump
• Light shaders
– Directions, amounts, and colors of illumination
• Volume shaders
– How light is affected as it passes through a participating
medium
• Imager shaders
– Describe color transformation make to final pixel values
before the are output
Shading Language data type
• Built-in types
–
–
–
–
–
Floats
Colors
Points, Vectors, Normals
Matrices
Strings
• SL has no double or int types
• SL does not support user-defined
structures or pointer of any kind
Shading Language Variables
• Global variables
– graphics state variables
• [class] type variablename [=initializer]
– Static 1D arrays are allowed
• e.g.)
–
–
–
–
–
float a;
uniform float b;
float c = 1;
float d = b*a;
float e[10];
Surface Graphics State Variables
•
•
•
•
•
•
P
N
Ng
I
E
Cs
Surface position
Shading normal
Geometric normal
Incident vector
Vantage(eye) point
Surface color
•
•
•
•
•
•
Os Surface Opacity
s,t Texture coordinates
L,Cl Light vector and color
u,v Parametric coordinates
du,dv Change in coordinates
dPdu,dPdv Surface tangents
Geometry at the Surface
Surface shader, Light shader
Shader Parameters
surface pitted (float Ka = 1, Kd = 1, Ks = 0.5;
float angle = radiances(30);
color spotcolor = 0;
color strpicolor = color (.5, .5, .75);
string texturename = "";
string dispmapname = "mydisp.tx";
vector up = vector "shader" (0, 0, 1);
varying point Pref = point (0, 0, 0);
)
{
...
}
Decalre "Kd" "float"
Declare "stripecolor" "color"
Surface "pitted" "Kd" [0.8] "stripecolor" [.2 .3 .8]
Sphere 1 -1 1 360
expressions
• Unary –
• Binary + * - / ^ .
• ^ and .
– Operators only work for vectors and normals
– ^ (vector cross product)
– . (vector dot product)
• * and / for matrix type
– * (matrix multiplication)
– / (matrix multiplication by the inverse)
• Type casts
• Ternary operator
• Function calls
?:
Built-in functions
•
•
•
•
•
•
•
Angles & Trigonometry
Exponentials, etc.
Miscellaneous simple scalar functions
Color operations
Geometric functions
Strings
Matrix functions
Built-in functions
• 수학함수
– PI, radians, degree, sin, asin, cos, acos, tan, atan, pow,
exp, sqrt, inversesqrt, log, mod, abs, sign, min, max,
clamp, mix, floor, ceil, round, step, smoothstep,
filterstep, spline, Du, Dv, Deriv, random, noise, pnoise,
cellnoise,
• 기하함수
– xcomp, ycomp, zcomp, setxcomp, setycomp, setzcomp,
length, normalize, distance, ptlined, rotate, area,
faceforward, reflect, refract, fresnel, transform,
vtransform, ntransform, depth, calculatenormal
• 색함수
– comp, setcomp, mix, ctransform
• 행렬함수
– comp, setcomp, determinant
Built-in functions
• 문자열함수
– concat, printf, format, match,
• 쉐이딩과 라이팅 함수
– ambient, diffuse, specular, specularbrdf, phong, trace,
• 텍스쳐 매핑함수
– texture, environment, shadow, textureinfo
• 메시지 전달 및 정보함수
– atmosphere, displacement, lightsource, surface, incident,
opposite, attribute, option, rendererinfo, shadername
• 추가된 함수
– gather, occlusion, indirectdiffuse, photonmap,
iradiancecache, caustic, transmission, gridpattern,
ambience, trace
Writing SL functions
• Only one return statement is allowed per
function
• Call by reference mechanism
• You may not compile functions separately
from the body of your shader
returntype functionname(params)
{
do some computations;
...
return return_value;
}
float myfunc (
float f;
output float g;
)
Homework
• 1. Polygons
–
–
–
–
• 2.
–
–
–
–
–
A.
B.
C.
D.
Polygon
GeneralPolygon
PointsPolygons
• 4.
PointsGeneralPolygons
Patches
A.
B.
C.
D.
E.
• 3. Subdivision Surfaces
– A. SubdivisionMesh
Basis
Patch
PatchMesh
NuPatch
TrimCurve
–
–
–
–
–
–
–
Quadrics
A. Sphere
B. Cone
C. Cylinder
D. Hyperboloid
E. Paraboloid
F. Disk
G. Torus