INTRODUCTION TO RENDERING TECHNIQUES

Transcription

INTRODUCTION TORENDERING TECHNIQUES22 Mar. 2012Yanir Kleiman

What is 3D Graphics? Why 3D? Draw one frame at a time Model only once X 24 frames per second Color / texture only once 150,000 frames for a feature film Realism / hyper realism Realistic rendering is hard A lot of reuse Camera movement is hard Computer time instead of artists time Interactive animation is hard Can be interactive (games)

What is 3D Graphics? Artists workflow – in a nutshell3D ModelCreate ModelTexture (Color)Rig (Bones)LightingAnimationBonesControlsTexture FilesCameraLightsRenderingKeyframesPost Processing

What is Rendering?BonesControls3D ModelTexture FilesLightsCamera?ImageKeyframes

What is Rendering?3D Model BonesControls Keyframes GeometryGeometryTexture FilesLightsCamera?Image

What is Rendering?Lights Consider: PerspectiveOcclusionColor / TextureLightingShadowsReflections / RefractionsIndirect illuminationSampling / AntialiasingTexture Files?ImageGeometryCamera

Two Approaches Start from geometry Foreach polygon / triangle: Is itvisible? Where is it? What color is it? RasterizationStart from pixels Foreach pixel in the final image: Which objectis visible at this pixel? What color is it?Ray Tracing

RASTERIZATION22 Mar. 2012Introduction to Rendering Techniques

Rasterization Basic idea: Calculate projection of eachtriangle onto the 2D image spaceExtensively used and researchedOptimized by GPUStrongly parallelizedOpenGLDirectX

Rasterization – Graphics PipelineModel TransformationLightingProjectionClippingScan ConversionImage

Rasterization – Graphics PipelineModel Transformation Lighting ProjectionClippingScan ConversionImageTransform each triangle fromobject space to world spaceLocal space - Global space

Rasterization – Graphics PipelineModel Transformation Computation is based on anglesbetween light source, object andcamera (details later) Backface cullingLightingProjectionClippingScan ConversionImage

Rasterization – Graphics PipelineModel TransformationLightingProjectionClippingScan ConversionImage Step 1: Transform triangles fromworld space to camera space(orthogonal transformation)

Rasterization – Graphics PipelineModel Transformation LightingProjection Clipping Scan ConversionImageStep 1: Transform triangles fromworld space to camera space(orthogonal transformation)Camera is at (0, 0, 0)X axis is right vectorY axis is up vectorZ axis is “back vector”(away from camera)

Rasterization – Graphics PipelineModel TransformationLighting Step 2: Perspective ProjectionDepends on focal length (D) Calculate Z-Buffer ProjectionClippingScan ConversionImage

Rasterization – Graphics PipelineModel Transformation Lighting ProjectionClippingScan ConversionImageRemove triangles that fall outsidethe clipping planeDetermine boundaries of trianglespartially within the clipping plane

Rasterization – Graphics PipelineModel TransformationLightingProjectionClippingScan ConversionImage Drawing the triangles in 2DScanning horizontal scan lines foreach triangle

Rasterization – Graphics PipelineModel TransformationLighting ProjectionClipping Scan Conversion ImageCheck z-buffer for intersectionsUse precalculated vertex lightingInterpolate lighting at each pixel(smooth shading)Texture: Every vertex has a texturecoordinate (u, v)Interpolate texture coordinates tofind pixel color

Rasterization – Parallel Processing Triangles are independent except for z-bufferEvery step is calculated by a different part in the gScan Scan Scan Conversion

Rasterization – Parallel Processing Modern GPUs can draw 600M polygons per secondSuitable for real time applications (gaming, medical)But what about ect illumination?

Rasterization – Antialiasing Aliasing examples

Rasterization – Antialiasing Aliasing examplesAliasingAnti-aliased

Rasterization – Antialiasing Antialiasing: Trying to reduce aliasing effectsSimple solution: MultisamplingOnly the last step changes!During scan conversion,sample subpixels and averageThis is equivalent to rendering a larger imageObservation: Rendering twice larger resolution costsless then rendering twice – since scanline is efficientand the rest doesn’t change!

Rasterization – Shadow Maps Render an image from the light’s point of viewShadow map(the light is the camera)Keep “depth” from light of every pixel in the mapDuring image render:Calculate position and depth on theshadow map for each pixel in thefinal image (not vertex!)If pixel depth shadow map depththe pixel will not receive light fromthis source

Rasterization – Shadow Maps This solution is not optimalShadow map resolution is not correlated to renderresolution – one shadow map pixel can span a lot ofrendered pixels!Shadow aliasingVarious hacks andOnly allows sharp shadowscomplex solutionsSemi-transparent objectsBlurred hardshadows(shadow map)True softshadows(ray tracing)

Rasterization – Reflection Maps Not a true reflection – a “cheat”Precalculate reflection map from a point in the center(can be replaced by an existing image)The reflection map is mapped to asphere or cube surrounding the sceneEach direction (vector) is mapped toa specific color according to where ithits the sphere / cubeDuring render, find the reflection coloraccording to the reflection vectorof each pixel (not vertex!)

Rasterization – Reflection Maps Can produce fake reflections (no geometry needed)Works well for: Environment reflection (landscape, outdoors, big halls)Distorted reflectionsWeak reflections (wood, plastic)Static scenesNot so good for: Reflections of near objectsMoving scenesMirror like objectsOptical effects

Rasterization – Reflection Maps Examples: Reflection mapsUsed to create the map

Rasterization – Reflection Maps Examples: Ray traced reflections

Rasterization – Reflection Maps Examples:Reflection MapRay Traced Reflection

Rasterization – Refractions There is no real solutionRefraction maps: same as reflectionmaps but the angle is computed usingrefractive indexOnly simulates the first directionchange, not the second (that wouldrequire ray tracing)Refraction is complex so fake refractionsare hard to noticeDoesn’t consider near objects, onlystatic background

Rasterization – Refractions Other “fake” solutions:Distort the background according to a precomputed map“Bake” ray traced refractions into a texture file(for static scenes)Refraction MapDistort Background

Rasterization – Indirect Illumination Indirect / global illumination means taking into account lightbouncing off other objects in the scene

Rasterization – Indirect Illumination Surprisingly, there are methods to approximateglobal illumination using only rasterization,without ray tracing“High-Quality Global Illumination RenderingUsing Rasterization”, Toshiya Hachisuka,The University of TokyoMain idea: Use a lot of fast rasterized“renders” from differentangles to compute indirectillumination at each pointRasterization is super quickon GPU

Rasterization – Indirect Illumination Results:Results of equal render timePhoton mapping(ray tracing)Rasterizer (GPU)

TRANSFORMATIONS22 Mar. 2012Introduction to Rendering Techniques

Transformations We saw 2 types of transformationsViewing transformation: Can move, rotate and scale theobject but does not skew or distort objectsPerspective projection: This special transformationprojects the 3D space onto the image planeHow do we represent such transformations?Homogeneous coordinates: Adding a 4th dimension to the3D space x' ? y ' ? z ' ? w' ? ? ? x ? ? ? y ? ? ? z ? ? ? 1

Viewing Transformations Types of transformationsScale x' a y' 0 z ' 0 w' 00 0 0 x b 0 0 y 0 c 0 z 0 0 1 1 Translate (move) x' 1 y ' 0 z ' 0 w' 00 01 00 10 0x0 x y0 y z0 z 1 1 Rotations x' cos y ' sin z' 0 w' 0 sin 0 0 x 0 0 y 1 0 z 0 1 1 cos x' cos y' 0 z ' sin w' 00 x' 1 y ' 0 cos z ' 0 sin 0 w' 0000 sin 100 cos 000 sin cos 00 x 0 y 0 z 1 1 0 x 0 y 0 z 1 1

Viewing Transformations Any combination of these matrices is a viewingtransformation matrixLast coordinate is only for moving the pivot,w’ is always 1 and will not be usedHow to find the transformation to a certain view(could be camera, light, etc)?

Viewing Transformations After the transformation:Eye position should be at (0, 0, 0)X axis right vectorY axis up vectorZ axis back vector

Viewing Transformations It is easy to construct the invert transformation,from camera coordinates to worldRightUpBackEyeVector Vector Vector Position

Viewing Transformations Examples:(0, 0, 0) - Eye Position Camera X Axis - Origin Right vectorNow all we have to do is invert T (always invertible),and we have our view transformation

Projections A projection transform points from higher dimension to alower dimension, in this case 3D - 2DThe most simple projection is orthographicSimply remove the Z axis afterthe viewing transformation

Perspective Projections Perspective projections map points onto the view planetoward the center of projection (the viewer)Since the viewer is at (0, 0, 0) the math is very simpleD is called the focal lengthx’ x*(D/z)y‘ y*(D/z)

Perspective Projections Matrix form of the perspective projection usinghomogeneous coordinates d 0 0 00d0000d10 x d 0 y dxy d z [dx dy dz z] z 0 z Divide by 4th coordinate0 1 (the “w” coordinate) Singular matrix – projection is many to oneD infinity gives an orthographic projectionPoints on the viewing plane z D do not movePoints at z 0 are not allowed – usually by using a clippingplane at z ε

LIGHTING22 Mar. 2012Introduction to Rendering Techniques

RAY TRACING22 Mar. 2012Introduction to Rendering Techniques

Ray Tracing Basic idea: Shoot a “visibility ray” from center ofprojection (camera) through each pixel in theimage and find out where it hitsThis is actually backward tracing– instead of tracing rays fromthe light source, we trace therays from the viewer back tothe light source

Ray Tracing Backward tracing is called Ray CastingSimple to implementFor each ray find intersectionswith every polygon – slow Easy to implement realisticlighting, shadows, reflectionsand refractions, and indirectillumination

Ray Tracing For each sample (pixel or subpixel):Construct a ray from eye position through viewingplane

Ray Tracing For each sample (pixel or subpixel):Construct a ray from eye position through viewingplaneFind first (closest) surface that intersects the ray

Ray Tracing For each sample (pixel or subpixel):Construct a ray from eye position through viewingplaneFind first (closest) surface that intersects the rayCompute color based on surface radiance

Ray Tracing For each sample (pixel or subpixel):Construct a ray from eye position through viewingplaneFind first (closest) surface that intersects the rayCompute color based on surface radianceComputing radiance requires casting rays towardthe light source, reflected and refracted objectsand recursive illumination rays from reflected andrefracted objects

Ray Tracing – Casting Rays Construct a ray through viewing plane:

Ray Tracing – Casting Rays Construct a ray through viewing plane:2D Example:For every i between (–width/2) and (width/2)

Ray Tracing - Intersections Finding intersections Intersecting spheres Intersecting triangles(polygons) Intersecting other primitives Finding the closest intersection in a groupof objects / all scene

Ray Tracing - Intersections Finding intersections with a sphere:Algebraic methodSolve for t

Ray Tracing - Intersections Finding intersections with a sphere:Geometric methodSolve for t

Ray Tracing - Intersections Finding intersections with a sphere:Calculating normalWe will need the normal to compute lighting,reflection and refractions

Ray Tracing - Intersections Finding intersections with a triangle:Step 1: find intersection with the planeStep 2: check if point on plane is inside triangleMany ways to solve

Ray Tracing - Intersections Step 1: find intersection with the plane:Algebraic methodNot necessaryparallel to ray

Ray Tracing - Intersections Step 2: Check if point is inside triangleAlgebraic methodIf all 3 succeed the pointis inside the triangle

Ray Tracing - Intersections Step 2: Check if point is inside triangleParamteric methodUsing dot products(P-T1) (T2-T1) and (P-T1) (T3-T1)

Ray Tracing - Intersections Ray tracing can support other primitivesCone, Cylinder, Ellipsoid: similar to sphere Convex Polygon:Point in Polygon is a basic problem in computationalgeometry and has algebraic solutions Concave Polygon:Same plane intersectionMore complex point-in-polygon test Alternatively, divide the polygon to triangles and checkeach triangle

Ray Tracing - Intersections Find closest intersection:Simple solution is go over each polygon in thescene and test for intersectionsWe will see optimizations for this later (maybe) We have an intersection – what now?

Ray Tracing – Computing Color Computing lighting can be similar to the processwhen rasterizing (using normals)This is not for a vertex but for the intersection pointFor better accuracy: ray trace lightingAt each intersection point casta ray to

This is equivalent to rendering a larger image Observation: Rendering twice larger resolution costs less then rendering twice – since scanline is efficient and the rest doesn’t change! Rasterization –