renderman (shading language: concepts)

28
RenderMan (Shading Language: Concepts)

Upload: meda

Post on 19-Jan-2016

161 views

Category:

Documents


3 download

DESCRIPTION

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. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: RenderMan (Shading Language: Concepts)

RenderMan(Shading Language: Concepts)

Page 2: RenderMan (Shading Language: Concepts)

RenderMan Interface

Page 3: 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

Page 4: RenderMan (Shading Language: Concepts)

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

Page 5: RenderMan (Shading Language: Concepts)

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

Page 6: RenderMan (Shading Language: Concepts)

Diffuse Reflection

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

Page 7: RenderMan (Shading Language: Concepts)

Diffuse Reflection

Lambertian model Cosine law (dot product)

Page 8: RenderMan (Shading Language: Concepts)

Specular Reflection

Reflection is strongest near mirror angle Examples: mirrors, metals

Page 9: RenderMan (Shading Language: Concepts)

Specular Reflection

Phong Model cos (n : This is a physically-motivated hack!

Page 10: RenderMan (Shading Language: Concepts)

Ambient Term

Represents reflection of all indirect illumination This is a total hack

• Avoid complexity of global illumination

ALAA IKI

Page 11: RenderMan (Shading Language: Concepts)

Surface Illumination Calculation

))()((1

nispecs

nlights

iiidiffdambaoutput RVCKClLNCKCKC

Page 12: RenderMan (Shading Language: Concepts)

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

Page 13: RenderMan (Shading Language: Concepts)

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

Page 14: RenderMan (Shading Language: Concepts)

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];

Page 15: RenderMan (Shading Language: Concepts)

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

Page 16: RenderMan (Shading Language: Concepts)

Geometry at the Surface

Page 17: RenderMan (Shading Language: Concepts)

Surface shader, Light shader

Page 18: RenderMan (Shading Language: Concepts)

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

Page 19: RenderMan (Shading Language: Concepts)

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

Page 20: RenderMan (Shading Language: Concepts)

Built-in functions

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

Page 21: RenderMan (Shading Language: Concepts)

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

Page 22: RenderMan (Shading Language: Concepts)

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

Page 23: RenderMan (Shading Language: Concepts)

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;

)

Page 24: RenderMan (Shading Language: Concepts)

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

Page 25: RenderMan (Shading Language: Concepts)

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

Page 26: RenderMan (Shading Language: Concepts)

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

Page 27: RenderMan (Shading Language: Concepts)

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;

}

Page 28: RenderMan (Shading Language: Concepts)