Presentation is loading. Please wait.

Presentation is loading. Please wait.

RenderMan (Shading Language: Concepts)

Similar presentations


Presentation on theme: "RenderMan (Shading Language: Concepts)"— Presentation transcript:

1 RenderMan (Shading Language: Concepts)

2 RenderMan Interface

3 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

4 New Shading System Turner Whitted & David M. Weimer Robert Cook
1980, Shading dispatch table Robert Cook 1984, Shade Trees Ken Perlin 1985, Pixel Stream Pat Hanrahan & Jim Lawson 1990, Shading Language

5 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” Cdiff: texture mapping N: bump mapping

6 Diffuse Reflection Assume surface reflects equally in all directions
Example: chalk, clay

7 Diffuse Reflection Lambertian model Cosine law (dot product)

8 Specular Reflection Reflection is strongest near mirror angle
Examples: mirrors, metals

9 Specular Reflection Phong Model
cos (a)n : This is a physically-motivated hack!

10 Ambient Term Represents reflection of all indirect illumination
This is a total hack Avoid complexity of global illumination

11 Surface Illumination Calculation

12 Types of shaders Surface shaders Displacement shaders Light 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 Programmable imager shaders are supported by BMRT; but not by PRMan.

13 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 Names of color spaces “rgb”, “hsv”, “hsl”, “YIQ”, “xyz”, “xyY” Names of predeclared geometric spaces “current”, “object”, “shader”, “world”, “camera”, “screen”, “raster”, “NDC”

14 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]; Class: uniform | varying(default)

15 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

16 Geometry at the Surface

17 Surface shader, Light shader

18 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" [ ] Sphere

19 expressions Unary – Binary + * - / ^ . ^ and . * and / for matrix type
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

20 Built-in functions Angles & Trigonometry Exponentials, etc.
Miscellaneous simple scalar functions Color operations Geometric functions Strings Matrix functions

21 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

22 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

23 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; )

24 My First Shader Surface Shader Cs, Os: input color and opacity
surface first() { Oi=Os; Ci=Cs*Oi; } Surface Shader Cs, Os: input color and opacity Ci, Oi: output color and opacity Compile: slc first.sl Display "first.tiff" "file" "rgb" Projection "perspective" "fov" [45] LightSource "ambientlight" 1 "intensity" [0.2] LightSource "spotlight" 2 "from" [ ] "to" [0 0 3] "intensity" [3] Translate 0 0 3 WorldBegin Color [1 0 0] Surface "first" Sphere WorldEnd

25 My Second Shader faceforward(N,I) diffuse(N)
surface second ( float Ka = 1; float Kd = 1; ) { normal Nf = faceforward (normalize(N),I); Oi = Os; Ci = Cs * diffuse(Nf) * Oi; } 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) Display “second.tiff" "tiff" "rgba" Format Projection "perspective" "fov" [45] LightSource "ambientlight" 1 "intensity" [0.2] LightSource "spotlight" 2 "from" [ ] "to" [0 0 3] "intensity" [3] Translate 0 0 3 WorldBegin Color [1 0 0] Surface “second" Sphere WorldEnd

26 My Third Shader specular(N,V,0.1) Dot product: R, V V: invert I
surface third () { normal Nf = faceforward (normalize(N),I); vector V = -normalize(I); Oi = Os; Ci = Oi * Cs * specular(Nf,V,0.1); } My Third Shader specular(N,V,0.1) Dot product: R, V V: invert I R: Reflection vectorLight(L) and Normal(N) 0.1: roughness Display “third.tiff" "tiff" "rgba" Format Projection "perspective" "fov" [45] LightSource "ambientlight" 1 "intensity" [0.2] LightSource "spotlight" 2 "from" [ ] "to" [0 0 3] "intensity" [3] Translate 0 0 3 WorldBegin Color [1 0 0] Surface “third" Sphere WorldEnd

27 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; }

28


Download ppt "RenderMan (Shading Language: Concepts)"

Similar presentations


Ads by Google