RenderMan (Shading Language: Concepts). RenderMan Interface.
-
Upload
oliver-harrison -
Category
Documents
-
view
253 -
download
0
Transcript of RenderMan (Shading Language: Concepts). RenderMan Interface.
RenderMan(Shading Language: Concepts)
RenderMan Interface
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
Does not change the fundamental form of the shading equation Narrow range of appearances
Simple analytic model: Diffuse reflection + Specular reflection + Emission + “Ambient”
))()((1
nispecs
nlights
iiidiffdambaoutput RVCKClLNCKCKC
Diffuse Reflection
Assume surface reflects equally in all directions Example: chalk, clay
Diffuse Reflection
Lambertian model Cosine law (dot product)
Specular Reflection
Reflection is strongest near mirror angle Examples: mirrors, metals
Specular Reflection
Phong Model cos (n : This is a physically-motivated hack!
Ambient Term
Represents reflection of all indirect illumination This is a total hack
• Avoid complexity of global illumination
ALAA IKI
Surface Illumination Calculation
))()((1
nispecs
nlights
iiidiffdambaoutput RVCKClLNCKCKC
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 outp
ut
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 a
ny 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 Surface position N Shading normal Ng Geometric normal I Incident vector E Vantage(eye) point Cs 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);
)
{
...
}cd
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, inversesq
rt, 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, attribut
e, 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;
)
My First Shader
Surface Shader Cs, Os: input color and opacity Ci, Oi: output color and opacity
Compile: slc first.sl
surface first()
{
Oi=Os;
Ci=Cs*Oi;
}
Display "first.tiff" "file" "rgb"
Projection "perspective" "fov" [45]
LightSource "ambientlight" 1 "intensity" [0.2]
LightSource "spotlight" 2 "from" [-1 1 0 ]
"to" [0 0 3] "intensity" [3]
Translate 0 0 3
WorldBegin
Color [1 0 0]
Surface "first"
Sphere 1 -1 1 360
WorldEnd
My Second Shader
faceforward(N,I) Face forward surface normal Shade the back just the same as the front N : Shading normal I : Incident vector
diffuse(N) Dot Product: Nf, L (=Light vector)
surface second (float Ka = 1;float Kd = 1;)
{ normal Nf = faceforward (normalize(N),I);
Oi = Os; Ci = Cs * diffuse(Nf) * Oi;}
Display “second.tiff" "tiff" "rgba"Format 320 240 1Projection "perspective" "fov" [45]LightSource "ambientlight" 1 "intensity" [0.2]LightSource "spotlight" 2 "from" [-1 1 0 ]
"to" [0 0 3] "intensity" [3]Translate 0 0 3WorldBeginColor [1 0 0]Surface “second"Sphere 1 -1 1 360WorldEnd
My Third Shader
specular(N,V,0.1) Dot product: R, V V: invert I R: Reflection vectorLight(L) and Normal(N) 0.1: roughness
surface third (){ normal Nf = faceforward (normalize(N),I); vector V = -normalize(I);
Oi = Os; Ci = Oi * Cs * specular(Nf,V,0.1);}
Display “third.tiff" "tiff" "rgba"Format 320 240 1Projection "perspective" "fov" [45]LightSource "ambientlight" 1 "intensity" [0.2]LightSource "spotlight" 2 "from" [-1 1 0 ]
"to" [0 0 3] "intensity" [3]Translate 0 0 3WorldBeginColor [1 0 0]Surface “third"Sphere 1 -1 1 360WorldEnd
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;
}