RenderMan For Artists #03
Wanho Choi
(wanochoi.com)RenderMan for Artists wanochoi.com
(Review) RIB Generation from Maya (Method#1)
RenderMan for Artists wanochoi.com
(Review) RIB Generation from Maya (Method#1)
Display "result.jpg" "file" "rgb" Projection "perspective" "fov" 30 WorldBegin
ReadArchive "./sphere.rib" WorldEnd
•
rman genrib perspShape_Final.0001.rib
RenderMan for Artists wanochoi.com
Sine & Cosine Function
30
60
1
3
2 3 3 ) 30 tan( 2 1 ) 30 sin( 2 3 ) 30 cos( 3 ) 60 tan( 2 3 ) 60 sin( 2 1 ) 60 cos( 45
45
1
1
2
1 ) 45 tan( 2 2 ) 45 sin( 2 2 ) 45 cos( cos sin cos sin tan RenderMan for Artists wanochoi.com
Scalar vs Vector
•
Scalar
–
Only has magnitude
–
Ex. Mass: 1Kg, Temperature: 25 ºC, Speed: 100 km/h
•
Vector (2D, 3D, 4D, …)
–
Has magnitude & direction (=arrow, ≠point)
•
Addition
•
Subtraction
•
Multiplication with scalar
–
Resultant vector is
a
times as long.
Basic Operations of Vectors
-A
B
=
C
A
×
2
=
C
+
A
B
=
C
C
) , , ( ) , , ( ) , , (Ax Ay Az Bx By Bz AxBx AyBy Az Bz A B C ) , , ( ) , , ( ) , , (Ax Ay Az Bx By Bz AxBx AyBy Az Bz A B C
ABBA
ABBA
) 1 , 1 ( ) 1 , 0 ( ) 0 , 1 ( A B C ) 0 , 1 ( ) 1 , 0 ( (1,1) ) 1 , 1 ( ) 1 , 0 ( ) 0 , 1 ( A B C ) 0 , 1 ( ) 1 , 0 ( ) 1 , 1 ( ) 1 , 1 ( ) 1 , 1 ( 1 1 ) 5 . 0 , 5 . 0 ( ) 1 , 1 ( ) 5 . 0 ( ) 5 . 0 ( ) 2 , 2 ( ) 1 , 1 ( 2 2 A D A D A C ) 0 , 1 ( ) 1 , 0 ( ) 1 , 1 ( ) 2 , 2 ( ) 1 , 1 ( ) 5 . 0 , 5 . 0 ( ) , , (Ax Ay Az A CRenderMan for Artists wanochoi.com
Example – Vector Subtraction
3,1,0
1,3,0
5,1,0
3,3,0
2,2,0
x y 0
2,2,0
2,2,0
Length & Normal of Vectors
2 2 2 2 / 1 2 2 2 ) (Ax AyAz Ax Ay Az A 2 2 2 2 2 2 2 2 2 , , / z y x z z y x y z y x x n A A A A A A A A A A A A A A A•
Length (=magnitude)
–
•
Normal
–
※ normalize, normalization
2 1 1 ) 1 , 1 ( 2 2 A ) 0 , 1 ( ) 1 , 0 ( (1,1) 2 2 1 , 2 1 / A A An ) 0 , 1 ( ) 1 , 0 ( (1,1) 2 1 , 2 1RenderMan for Artists wanochoi.com
Dot Product (=Inner Product, 내적)
cos
B
A
B
A
)
(
2
1
2 2 2C
B
A
)
(
2
1
2 2 2B
A
B
A
2 2 2 2 2 2 2 2 2
)
(
)
(
)
(
)
(
)
(
2
1
z z y y x x z y x z y xa
a
b
b
b
b
a
b
a
b
a
a
z z y y x xb
a
b
a
b
a
B
A
C
B
A
B
A
2
2 2 2Dot Product (=Inner Product, 내적)
•
Result: scalar
•
When A & B are unit vector, .
•
When A & B are orthogonal, .
•
When A & B are in same direction, .
•
When A & B are in opposite direction, .
•
“Dot Product” is useful for the shading, collision detection, etc.
cos
B
A
B
A
z z y y x xb
a
b
a
b
a
cos
B
A
A
B
A
B
arccos
cos
1
0
B
A
0
90
cos
cos
0
B
A
0
B
A
RenderMan for Artists wanochoi.com
Shader
•
A small program to be used to determine the final surface properties.
•
shader
myShader.sl
myShader.slo
•
prman
test.rib
result.jpg
Display "result.jpg" "file" "rgb" Projection "perspective" "fov" 30 Translate 0 0 5
WorldBegin
LightSource "ambientlight" 1 "intensity" [0.1]
LightSource "pointlight" 2 "from" [-2 2 -2] "intensity" [7] Color [1 1 1] Surface "myShader" Sphere 1 -1 1 360 WorldEnd surface myShader() { Oi = Os; Ci = Oi * Cs; }
2-01_sphere_basic
test.rib myShader.slRenderMan for Artists wanochoi.com
.rib File Structure (Example #1)
Display “sphere.tiff” “file” “rgb” Projection “perspective”
WorldBegin Translate 0 0 2
Surface “myShader” “color surfaceColor” [1 0 0] Sphere 1 -1 1 360
WorldEnd
.rib
surface myShader(
color surfaceColor = color(1,1,1); color surfaceOpacity = color(1,1,1); ) { Oi = surfaceOpacity; Ci = Oi * surfaceColor; } .sl
Setup Part
Drawing Part
RenderMan for Artists wanochoi.com
Surface Shader – Basic Structure
•
O
is for opacity
–
Os
: opacity input provided by the RIB stream
–
Oi
: opacity output, which are then used by the renderer in the rest of its processing
•
C
is for color
–
Cs
: color input provided by the RIB stream
–
Ci
: opacity output, which are then used by the renderer in the rest of its processing
•
Globals
–
Predefined shader variables
–
Os, Oi, Cs, Ci, ….
myBasic.slo
Os
Cs
Oi
Ci
RenderMan for Artists wanochoi.com
Display "result.jpg" "file" "rgb" Projection "perspective" "fov" 30 Translate 0 0 5
WorldBegin
LightSource "ambientlight" 1 "intensity" [0.1]
LightSource "pointlight" 2 "from" [-2 2 -2] "intensity" [7] Color [1 1 1]
Surface "myShader" "color surfaceColor" [1 0 0]
Sphere 1 -1 1 360 WorldEnd
surface myShader( color surfaceColor = color(1,1,1);
color surfaceOpacity = color(1,1,1); ) { Oi = surfaceOpacity; Ci = Oi * surfaceColor; }
2-02_sphere_constant
.rib .slRenderMan for Artists wanochoi.com
Illumination
•
Global illumination
–
Considers the interaction of light
between all surfaces
in a scene
•
Local illumination
–
Considers the interaction of light between
one light source
and
one object surface
.
–
Usually, it is approximated as the summation of three components.
:
Ambient, Diffuse, Specular
•
Ambient reflection
–
Crude approximation to global effects of light
–
Accounts for the general brightness from light scattering in all directions from all surfaces.
•
Diffuse reflection
–
Due to the „roughness‟ of a surface at the microscopic level
–
Accounts for the light hitting a surface and then scattering evenly in all directions
–
Depends on “surface normal”
•
Specular reflection
–
Due to the „shininess‟ of a material
–
Accounts for the highlights
RenderMan for Artists wanochoi.com
•
Ideal diffuse reflection
–
An
ideal diffuse reflector
, at the microscopic level, is a very rough surface.
(real-world example: chalk)
–
Because of these microscopic variations, an incoming ray of light is equally likely to be
reflected in any direction over the hemisphere.
•
What does the reflected intensity depend on?
(Lambert‟s cosine law)
–
The energy reflected by a small portion of a surface from a light source in a given direction
is proportional to the cosine of the angle between that direction and the surface normal.
•
These are often called
Lambertian surfaces
•
Note that the reflected intensity is independent of the viewing direction, but does
depend on the surface orientation with regard to the light source.
I
diffuse= k
dI
lightcos
= k
dI
light(n • l)
Phong Shading Model
= Phong reflection model = Phong illumination model = Phong Ligting model
•
An empirical model of local illumination
•
K
a: ambient reflection constant
•
K
d: diffuse reflection constant
•
K
s: specular reflection constant
•
α : shininess constant for this material (=1/roughness)
lights
i
s
s
d
d
a
a
p
k
I
k
I
N
L
k
I
R
V
I
RenderMan for Artists wanochoi.com
Specular Shiness
lights
i
s
s
d
d
a
a
p
k
I
k
I
N
L
k
I
R
V
I
Blinn-Phong Shading Model
RenderMan for Artists wanochoi.com
surface myShader( uniform float Ka = 1.00;
color surfaceColor = color(1,1,1); color surfaceOpacity = color(1,1,1); ) { Oi = surfaceOpacity; Ci = Oi * surfaceColor * ( Ka * ambient() ); }
2-03_sphere_ambient
.slRenderMan for Artists wanochoi.com
surface myShader( uniform float Kd = 1.00;
color surfaceColor = color(1,1,1); color surfaceOpacity = color(1,1,1); ) { normal Nn = normalize(N); color Cdiff = 0; illuminance( P, Nn, PI/2 ) { vector Ln = normalize(L); Cdiff += Cl * max( 0, Nn.Ln ); } Oi = surfaceOpacity; Ci = Oi * surfaceColor * ( Kd * Cdiff ); }
2-04_sphere_diffuse
.slRenderMan for Artists wanochoi.com
surface myShader( uniform float Kd = 1.00;
color surfaceColor = color(1,1,1); color surfaceOpacity = color(1,1,1); ) { normal Nn = normalize(N); Oi = surfaceOpacity; Ci = Oi * surfaceColor * ( Kd * diffuse(Nn) ); }
2-05_sphere_diffuse
.slRenderMan for Artists wanochoi.com
surface myShader( uniform float Ks = 1.00; uniform float roughness = 0.20;
color surfaceColor = color(1,1,1); color surfaceOpacity = color(1,1,1); color specularColor = color(1,1,1); ) { normal Nn = normalize(N); vector V = -normalize(I); color Cspec = 0; illuminance( P, Nn, PI/2 ) { vector Ln = normalize(L); vector H = normalize( Ln + V );
Cspec += Cl * pow( max( 0, Nn.H ), 1/roughness ); } Oi = surfaceOpacity; Ci = Oi * specularColor * ( Ks * Cspec ); }
2-06_sphere_specular
.slRenderMan for Artists wanochoi.com
surface myShader( uniform float Ks = 1.00; uniform float roughness = 0.20;
color surfaceColor = color(1,1,1); color surfaceOpacity = color(1,1,1); color specularColor = color(1,1,1); ) { normal Nn = normalize(N); vector V = -normalize(I); Oi = surfaceOpacity; Ci = Oi * specularColor * ( Ks * specular(Nn,V,roughness) ); }
2-07_sphere_specular
.slRenderMan for Artists wanochoi.com
surface myShader( uniform float Ka = 1.00; uniform float Kd = 0.85;
color surfaceColor = color(1,1,1); color surfaceOpacity = color(1,1,1); ) {
normal Nn = normalize(N); Oi = surfaceOpacity;
Ci = Oi * surfaceColor * ( Ka * ambient() + Kd * diffuse(Nn) ); }
2-08_sphere_lambert
RenderMan for Artists wanochoi.com
surface myShader( uniform float Ka = 1.00; uniform float Ks = 1.00; uniform float roughness = 0.20;
color surfaceColor = color(1,1,1); color surfaceOpacity = color(1,1,1); color specularColor = color(1,1,1); ) { normal Nn = normalize(N); vector V = -normalize(I); Oi = surfaceOpacity; Ci = Oi * ( surfaceColor * ( Ka * ambient() ) + specularColor * ( Ks * specular(Nn,V,roughness) ) ); }
2-09_sphere_metal
.slRenderMan for Artists wanochoi.com
surface myShader( uniform float Ka = 1.00; uniform float Kd = 1.00; uniform float Ks = 1.00; uniform float roughness = 0.20;
color surfaceColor = color(1,1,1); color surfaceOpacity = color(1,1,1); color specularColor = color(1,1,1); ) {
normal Nn = normalize(N); vector V = -normalize(I); Oi = surfaceOpacity;
Ci = Oi * ( surfaceColor * ( Ka * ambient() + Kd * diffuse(Nn) ) + specularColor * ( Ks * specular(Nn,V,roughness) ) ); }
2-10_sphere_plastic
RenderMan for Artists wanochoi.com
Surface Shader – Surface Normal (N vs Ng)
•
N
: surface shading normal
•
Ng
: Surface geometric normal
•
Surface shaders are evaluated after the displacement shaders.
•
This means that if the displacement shader altered the position of P and the direction
of N, then those values will be used by the surface shader.
References
• Cook, Robert L., Loren Carpenter, Edwin Catmull, The Reyes Image Rendering Architecture, SIGGRAPH 87.
• Saty Raghavachary, Rendering for Beginners: Image synthesis using RenderMan, Focal Press, 2004
• Rudy Cortes, Saty Raghavachary, The RenderMan Shading Language Guide, Thomson Course Technology, 2007 • Ian Stephenson, Essential RenderMan Fast, Springer, 2003
• Anthony A. Apodaca, Larry Gritz, Advanced RenderMan: Creating CGI for Motion Pictures, Morgan Kaufmann, 1999
• http://en.wikipedia.org/wiki/Phong_shading