renderhjs/bbs/flashkit/color_dune/demo_chardesign2 / new imap

55
http://www.renderhjs.net/bbs/flashkit/c olor_dune/demo_chardesign2 / New iMap http://theamazingios6maps.tumblr.com /

Upload: tola

Post on 23-Feb-2016

78 views

Category:

Documents


2 download

DESCRIPTION

http://www.renderhjs.net/bbs/flashkit/color_dune/demo_chardesign2 / New iMap http://theamazingios6maps.tumblr.com /. Hidden Surface Removal. CS3241: Computer Graphics. Where are we?. All the objects are set up in the scene And they are polygonal models A camera (view point) is set - PowerPoint PPT Presentation

TRANSCRIPT

Slide 1

http://www.renderhjs.net/bbs/flashkit/color_dune/demo_chardesign2/New iMaphttp://theamazingios6maps.tumblr.com/

1Hidden Surface RemovalCS3241: Computer Graphics2Where are we?All the objects are set up in the sceneAnd they are polygonal modelsA camera (view point) is setAfter all the transformations (including the perspective transformation)So we now have many many polygons on the screenTransform all the polygon vertices into the screen coordinates3

Transformation/Viewing4Drawing Order??5But how do we know the order?Scan Convert Algorithm

6Keeping the z Values

After Perspective Transformation7Wrong Drawing Order

8Hidden Surface Removal (HSR)

9Two Main ApproachesControl the drawing order of objectsSort the order of polygons according to depthDraw polygons from furthest to nearestView dependentThe depth order changes when the viewpoint changesDraw objects in a random orderThen for each pixel drawn by a new objectIf there is already some object drawn, decide if the new object should overwrite it or not10Various HSR AlgorithmsType 1:Depth SortingWeiler-Atherton AlgorithmBinary Space-Partitioning (BSP) TreeType 2:Z-buffer Warnock's AlgorithmRay-casting (in the lecture of ray tracing). etc.All of them are performed after perspective transformationExcept Ray-casting

11Type I(Object-precision Algorithm)

12Type 1: Controlling Drawing OrderGoal: For a bunch of polygons, we sort them according to the depth and draw the deepest firstHowever, sometime there is no possible correct order:

So, we have to break the polygons

13Type 1a: Depth SortBreaking two polygonsPolygon APolygon BDetermine who covers who in this area14Type 1a:Depth SortWeiler-Atherton Algorithm Computing intersections of polygonsA generic polygon clipping algorithm (detail omitted)For two polygons and B, we can computethe union of A and Bthe intersection of A and BA minus BB minus A

15Set A and Set BUnionIntersectionA - B16Type 1a: Depth SortPolygon APolygon B17Type 1a: Depth SortPolygon APolygon A in BPolygon A minus B18Type 1a: Depth SortPolygon B minus APolygon B in A19Type 1a: Depth SortDrawing orderPolygons A B and B - APolygon B in APolygon A - BPolygon B -APolygon B in A20Type 1a: Depth SortingDrawing order:Determine which one to draw firstPolygon A in B or Polygon B in AIn this case, draw A in B first then draw B in A if polygon B is transparentIf B is not transparent, we can ignore or skip drawing A in B directlyDo not need to care about A-B or B-AIf they do not intersect other polygons in the screen21Type 1a: Depth SortingAdvantagesHandle transparencyEspecially good if The order is predictable and there is no need for polygon clippingDisadvantagesNeed special care for penetrating polygonsComputational expensiven polygons produce nC2 intersectionsi.e. O(n2)And for each pair of polygon, we could produce O(m2) if each polygon has m edges

22Binary Space Partitioning

23Type Ib: Binary Space PartitioningAn industrial standard for real time 3D games such as FPSDoom, Counterstrike, Quake, etcInput:An environment modeled by polygonsPreprocess the environment and produce a BSP treeOutputBase on the BSP tree, output a drawing order from the furthest away to the nearest polygon

24The First FPSThere are free versions on web and iPad/iPhoneThe iPad version is totally free on the Japanese iStore

25Recap: Binary Search Tree10203250606979102032506069791 dimensional space26Recap: Binary Search Tree10203250606979102032506069791 dimensional space2 sub-spacesInternal nodeLeaf27Type 1b: Binary Space PartitioningIdea: Subdivide the entire space by a binary treeEach internal node is a division of a partition/spaceEach leaf is a part of the space with only one polygon

Divide into two stepsPreparationRenderingABC(Use a birds eye view for illustration)28Type 1b: BSP-tree PreparationInitializationLet S = the entire spacePick any polygon, say Polygon ALet HA be the hyperplane that contains A and divides S into two subspace S1 and S2

ABCHA29Type 1b: BSP-treeBuild a node by polygon ABreak every polygon in S by HABuild the two children of A by the two subspaces S1 and S2Repeat until the subspace contains only 1 polygonAB1CHAB2AB130Type 1b: BSP-treeAB1HAB2AB1B2C2C1C1C2Prepare the BSP-tree for rendering:

31Type 1b: BSP-tree RenderingAB1HAB2AB1B2C2C1C1C2Depending on the viewpoint pStart from the rootFor each node there is one polygon and two sub-spaces in the two childrenRecursively draw the sub-tree behind the polygon from the view point pDraw the polygon of the nodeRecursively, draw the sub-tree in front of the polygon from the view point p

p= in-order traversal of a BSP tree32AB1HAB2AB1B2C2C1C1C2For example, for the following viewpoints, their drawing order will bep1 : B1, A, C1, B2 , C2p2: C1, B2, C2, A, B1

p1p2Type 1b: BSP-treeDetailed exercises in tutorials33Type 1b: BSP-treeAdvantage:Once the tree is computed, the tree can handle all viewpoints, i.e. efficientHandle transparencyIndeed, its a standard format (.BSP files) to store the environment for many gamesE.g. Quake, Half-life, Call of Duty, etcDisadvantagesCannot handle moving/changing environmentsPreprocessing time is long34Type II(Image-precision Algorithm)35Type 2a: Z-buffer AlgorithmWhen we draw a pixel on the screenIt is from a pixel by the scan conversion algorithmWe may store the color onto the color buffer (memory)The choices are:To overwrite the original values already there, orDo not write anything, i.e. ignoring the current pixelThe main idea of z-buffer algorithm:Allocate another buffer to store the z values of all the pixel drawn36Keeping the z Values2 Cases:Draw blue first, then overwritten by yellowDraw yellow first, then the blue pixel is skipped when the blue polygon is drawn

After Perspective TransformationYellow or blue?37Type 2a: Z-buffer AlgorithmFor every pixel of a polygon (during SCA) will (usually) have a different z values

38Type 2a: Z-buffer AlgorithmThe main idea of z-buffer algorithm:Allocate another buffer to store the z values of all the pixel drawn, namely z-bufferE.g. a 1024 x 768 screen has a memory size of 1024 x 768 array of double valuesBefore drawing, initialize every value to be infinityWhen we draw a pixel, we compare its z value with the one on the z-bufferIf the depth is smaller, overwriteElse, do nothing, namely, do NOT draw this pixel39999999999999999999999999999999999999999999999999999999999999999999999999555555559555555599555555999555559999555599999555999999559999999599999999555555555555555555555555555555555555+=555555559555555599555555999555559999555599999555999999559999999599999999234567823456782345678+555555559555555599234555899234557899234567899555999999559999999599999999=Initial Screen z-buffer(Let 9 be the maximum z value)40Type 2a: Z-buffer AlgorithmAdvantagesNo pre-sorting is necessary, no explicit intersection/object-object comparisons are required, i.e.Fast and simpleHandles cyclic and penetrating polygonsCan make use of z to speed up in the incremental SCADisadvantagesCan handle only opaque objects, namely, transparency is not handledWell can somehow fix it partiallyA single point sampling process, i.e. severe aliasing.E.g. two polygons on the same plane but with different shapesZ fightingProblem in a sub-pixel levelThe z-buffer's finite precision does not provide adequate resolution for scene with small objects separated far apart (in z) and for intersections of distant objects. (i.e. 2 pts close together may become touching each other due to rounding )

41Z-fightingWhen two polygons are contained in the same plane and overlapping with each otherTheoretically, their z values are exactly the same at every pixelBut, practically, numerical errors

42Type 2b: Warnock's AlgorithmSubdivide the screen untilThe area only contains one polygon, orThe area is one pixel bigFor the one pixel big areaDetermine which polygon to draw by intersecting a line to all the polygons in that pixel

43Speed-up Enhancement(Reducing the number of polygons rendered)44Speed-up EnhancementsSkipping (eliminating) objects outside the view frustumMany many methodsBack face cullingFor each polygon, define one side is outside and the other insideOnly draw the polygon if the outside face is facing the viewer

Only these three polygons are actually drawn by SCA, the rest are skipped45

Polygon Normal46Back face cullingFor each polygon, define one side is outside and the other insideOnly draw the polygon if the outside face is facing the eye by testing if the dot product of the two vectors V and N is greater than zeroV: eye position minus a point on the polygonN: normal vector of the polygonNV47Recap:Polygon OrientationsFor a triangle with three vertices v1, v2 and v3The order (v1, v3, v2) and (v3, v2, v1) are considered to be equivalent during drawing, e.g. glVertexBut the order (v1, v2, v3) is considered to be different (or opposite)(v1, v3, v2) and (v3, v2, v1) describe a facing direction of a polygon/triangleRight-hand ruleThe order (v1, v2, v3) creates an opposite facing directionSo, geometry is the same, but normal vector for that polygon will be different Usually we follow the natural order in the polygon list to define the outward direction of an object

v1v2v348Vertex List and Polygon List

123For example, if it is a solid ball, the triangle below must be stored in the order of (v1, v3, v2) or (v3,v2,v1) or (v2,v1,v3)But NOT (v1,v2,v3) or some other orders49Back Face Culling

50

51OpenGLZ-buffer (depth buffer)Setup:glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE);Every time clearing the screenglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);Back face cullingSetupglEnable(GL_CULL_FACE);glCullFace(GL_FRONT); or glCullFace(GL_BACK);Then draw all polygons in an anti-clockwise or a clockwise order52Outline EffectA polygonal modelDraw the outlineThe division between polygon being backface culled and not culled

53ConclusionThis all COMPUTATIONAL GEOMETRY!Z-buffer is not superior, but most user friendlyMost suitable for hardware implementationOther algorithms are more suitable for software implementationPerformance depends on The number of polygonsSize of the outputThose who are interested:Quakes HSR techniques:http://downloads.gamedev.net/pdf/gpbb/gpbb66.pdf54AdminHW1All marked already, just some IVLE bugs and we will upload the marks ASAPHW2 Deadline 30th Sept (delayed)Midterm next next lecture in class12th OctStart sharply at 2:00 pm1 hourOpen BookScope: everything (lecture, tutorial, hw) before 8 OctSee IVLE lesson plan for detailsMake-up lectureOct 22nd, 23rd or 25th?55

P

Q

R

Q

P

COP

Z2

Z1