advanced rendering techniques 4/2/02. rendering for animation the big difference: real time vs....

38
Advanced rendering techniques 4/2/02

Upload: alfred-mcdowell

Post on 17-Jan-2018

232 views

Category:

Documents


0 download

DESCRIPTION

Off-line rendering Primary goal: get the “right” appearance Less concern about time Done in software – great flexibility Not only triangles Not only Phong Can use different rendering techniques Raytracing Radiosity REYES

TRANSCRIPT

Page 1: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Advanced rendering techniques4/2/02

Page 2: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Rendering for animationThe big difference: real time vs. off-lineReal time: sacrifice quality for performanceHardware support necessary Use polygons and scanline rendering Use simple lighting models

Phong+diffuse+ambient New hardware might change this

Applications: interactive systems Games Walkthroughs

Page 3: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Off-line renderingPrimary goal: get the “right” appearance Less concern about time

Done in software – great flexibility Not only triangles Not only Phong

Can use different rendering techniques Raytracing Radiosity REYES

Page 4: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Ray tracingThe idea: follow light propagation through the sceneAlgorithm: Shoot a ray through eye position and pixel center Determine the first surface it intersects with Compute surface color: Shoot new rays to light sources (shadow rays)

If blocked, no contribution Account for surface reflection, light and viewing

direction

Page 5: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Recursive ray tracingIf surface is a mirror: Shoot new ray in mirror direction Repeat the process

If surface is diffuse: Terminate Alternative: shoot a ray in random direction Called pathtracing – very slow

Always terminate once contribution is small Rays carry light energy

Page 6: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Stochastic supersamplingRay through the pixel center – aliasing artifactsIncrease number of rays per pixel, average results supersamplingBetter if point is chosen randomly Stochastic sampling

Turn regular artifacts into noise

Page 7: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Advantages / disadvantages

Mirror reflections / refractions are easyArbitrary surface reflectance properties BRDFs

Diffuse interreflections are difficultCan be very slow Need extra acceleration datastructures

Grids, octrees, etc. With these, speed is ok on modern machines

Scanline performance: number of objectsRaytracing performance: image resolution

Page 8: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

RadiosityAssumption: all surfaces are Lambertian Uniformly diffuse

Split all surfaces into patches Chose a point on each patch

Light reflected from a patch at a point = linear combination of light from other pointsCoefficients depends on mutual arrangement

Page 9: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

RadiosityWrite equations of light transferCompute patch-to-patch transfer coefficients Form factorsSolve this system Get patch color at one pointInterpolate to get color everywhere on the patch

Page 10: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

RadiosityLots of different algorithms to: Split surfaces into patches

Respecting shadow boundaries, etc. Compute form factors Solve radiosity system of equations

Efficient methods for special “sparse” systems

Take into account only significant energy exchanges

Some form is implemented in Blender

Page 11: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Advantages / disadvantages

Very nice images of diffuse environmentsA rather complex algorithm Form factor computation is slowDoes not handle mirrors Some form of raytracing is neededCurrently somewhat decreasing in popularity

Page 12: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

REYES systemChampion in longevity Created in mid-80s by what now Pixar Basis for RenderMan – standard

rendering tool for movie industry1993 Academy award (“Oscar”)Major ideas: Splitting and dicing of primitives Surface shaders

Page 13: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Splitting and dicingDetermine if a primitive is on the screenCompute primitive size on the screen Use bounding boxesSplit if the size is “too large”Dicing – conversion to a “grid” Tesselation into mycropolygons

Size is about 1 pixel Their vertices are shaded

Page 14: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Shader conceptPrimitives have shaders attached to itShader – program which determines relevant parametersNot only surface color (surface shaders) Displacement shaders Light shaders Volume shaders Imager shaders (BMRT only)

Page 15: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Visible surface determination

Determine which pixels are affected by micropol.Each pixel has list of sample positions Stochastic point samples

Test which are covered by a micropol.Each sample has associated visible point list Includes depth and transparency

Once done, determine pixel color

Page 16: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Enhanced REYESMemory usage problem Visible point lists are hugeUse buckets – small pixel regions Sort primitives into buckets Process one bucket at a timeOcclusion culling Sort primitives by depth in each bucket Process close objects first

Page 17: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

RenderMan / BMRT4/4/02

Page 18: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

RenderMan rendering interface

RenderMan also specifies a rendering interfaceIndependent of implementation REYES system in Pixar’s RenderMan Raytracing in BMRT Mostly transparent for the user

Analog: OpenGL is an interface Hardware support – driver hides the details Software implementation (Mesa)

Page 19: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

RenderMan interfaceScene description file .rib (RenderMan interface bytestream)Compiled shaders .slc – used by RenderMan directlyShading language High level C-like language .sl – run a compiler to convert into .slc

Page 20: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Using RenderManIt is run from a command lineRun “setenv” first to set up pathsrgl – fast OpenGL previewer Good for geometry/lights/camera positioning Usage: rgl ribname.rib

slc - shader language compiler: slc shadername.sl Produces shadername.slc Need to do this for all shaders used

Page 21: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Using RenderManrendrib is the renderer rendrib ribname.ribCreates output according to rib specs Use –d to get display output directly -d 16 to get multiresolution

approximationRaytracing complex scenes can be slow Debug shaders on simple geometry

Page 22: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

.rib file anatomyGlobal options

Frame block

Next frame blockAnother world block

World block Attributes, lights, primitives

Changed options

Image optionsCamera options

Page 23: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Parameter declarationsCan declare parameters with Declare “name” “declaration” declaration is an analog of type

class type actuallyType = float, color, vertex, vector, normal, point, string, matrixThis is globalIn-line decraration – only in particular command “class type name”

Page 24: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Attribute blocksEverything between AttributeBegin and AttributeEndInherits attribute state of the parentManipulates it, assigns to geometric primitivesAttribute state: color/shaders attached Transformation matricesTransformBegin / TransformEnd push/pop transform matrices

Page 25: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

TransformationsApplies to local coord systemRotate angle vx vy vzScale sx sy szSkew angle vx vy vz ax ay azConcatTransform matrixIdentityTransform matrix

Page 26: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Special coord systemsCamera space Origin at the camera, Z+ in front, Y+ is up Left-handed !!! Created with

Projection type parameterlist

Everything else is relative to itBefore WorldBegin – form world-to-camera matrixEach object/shader created according to current transform matrix Coord system is stored as “object” / “shader” space

Page 27: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

GeometryQuadrics: Sphere, cylinder, cone, paraboloid, hyperboloid,

disk, torusPolygons and meshes: Polygon, GeneralPolygon, PointsPolygon,

PointsGeneralPolygonParametric patches and NURBS: Basis, Patch, PatchMesh, NuPatchOther: trim curves, subdivision meshes, CSG

Page 28: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Primitive variablesAttached to geometric primitivesCan be referred to directly: “P”, “Pw”, “N”, “Cs”, “Os”, “st”These are: Position in 3D (P), and in hc (Pw) Normal (N) Surface color (Cs) and opacity (Os) Texture coords (st)

Page 29: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

ShadersIn .rib file, created by: Surface “shadername” parameterlist Displacement “shadername” parameterlist

Parameters are passed to the shader program Written in special shading language

Has access to some global variablesSets some global variables Final surface color Ci and opacity Oi Can also modify position P and normal N

Displacement shader

Page 30: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

A simple shaderSurface metal (float Ka = 1, Ks = 1; float roughness = .1;)

{ normal Nf = faceforward (normalize(N),I);

vector V = -normalize(I); Ci = Cs * (Ka*ambient() + Ks*specular(Nf,V,roughness));

Oi = Os; Ci *= Oi;}

Page 31: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Simple shader usageIn .rib file the usage will be:

AttributeBeginTranslate 0 0 0Color 1 .3 .05Surface "metal" "roughness" [0.3] "Ks" [1.5]

ReadArchive "vase.rib"AttributeEnd

Page 32: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Simple shader notesGlobal variables: N, I, Oi, Os, Ci, Cs Sets final surface color Ci Cs is from .rib file Parameters Ka, Ks, roughness are from

shader parameterlist in .ribShader language functions: Uses default ambient() and specular(…) to

do actual computation There is also diffuse(…)

Normalize(), faceforward()

Page 33: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Lights and illuminationCan access light information in illumination loops

color diffuse (normal Nn){ extern point P; color C=0; illuminance(P,Nn,PI/2){ C+=Cl*(Nn . Normalize(L)) } return C; }

Loops over all visible lights from P which are within PI/2 from Nn

Page 34: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

BMRTBMRT implements RenderMan interfaceBut it is a raytracer Extra features availablecolor trace(point from; vector dir) returns incoming light from dirAlso Fulltrace, rayhittest, visibility, etc. RayTrace(…) – stochastic supersamplingEasy to do reflections

Page 35: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Simple shader using raytracingcolor MaterialShinyMetal (normal Nf; color basecolor; float Ka, Kd, Ks, roughness, Kr, blur; uniform float twosided; DECLARE_ENVPARAMS;)

{ extern point P; extern vector I; extern normal N; float kr = Kr;

Page 36: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

…continuedif (twosided == 0 && N.I > 0)kr = 0;

vector IN = normalize(I), V = -IN; vector R = reflect (IN, Nf); return basecolor * (Ka*ambient() + Kd*diffuse(Nf) + Ks*specular(Nf,V,roughness) +

SampleEnvironment (P, R, kr, blur, ENVPARAMS));

}

Page 37: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Notes on raytracing shader

Mostly as beforeSampleEnvironment calls RayTrace Also includes environment mapping See reflections.hENVPARAMS is a bunch of stuff controlling ray tracing / env. mapping Number of samples, env.map name, etc.

Page 38: Advanced rendering techniques 4/2/02. Rendering for animation The big difference: real time vs. off-line Real time: sacrifice quality for performance

Concluding notesReal power of RenderMan is in its flexibilityWant complex appearance – just write a shader function Hundreds of parameters for complex shaders

Will see more on procedural techniques later in the course Including possibilities for some interesting shaders

Assignment 5 asks you to play with shaders And write a few of your own…