Lecture 7 Notes: Models and Polygon Meshes
Week 4 & 5
New lecturer from week 7 to 10.
Models
Outline:
Polygon Mesh
Triangle Mesh
OpenGL Functions
Polygon Mesh
Continuous objects are modeled using polygon approximations.
Object surfaces are approximated using attached polygons.
Referred to as "mesh" because of its appearance.
Opaque objects: Surface is crucial for light interaction.
More polygons lead to more detailed surface modeling but are computationally expensive.
Meshes are named as such due to their resemblance to meshes when polygons are viewed without color or shading.
Types of Polygons:
Triangle mesh (3 vertices).
Quadrilateral mesh (4 vertices).
Larger polygons.
This module primarily deals with triangle meshes.
Defining a Polygon Mesh:
Each polygon requires a certain number of points (vertices).
Each vertex in 3D space is defined by three coordinates: X, Y, and Z.
A set of vertices is needed to create an object.
Edges are line segments connecting two vertices.
Chained edges share at least one vertex.
Faces (polygons) are formed by connecting all vertices with edges.
Simple polygons are made of three or four vertices forming triangle or quadrangle meshes.
Normals:
A normal is a direction perpendicular to the surface at a point and defined for each vertex.
For a face, the normal can be averaged from the normals of its vertices.
Normals are essential for rendering to determine light interaction with the surface.
Light interaction depends on the angles between the normal, the light direction, and the view direction.
Properties of Polygon Meshes:
Any two faces of the mesh either don't share any nodes, or share one vertex, or share one edge.
Manifold meshes: Every edge is shared by exactly two faces, except for border edges.
Normals must be consistent in direction (either facing outwards or inwards).
Mobius strip is an example that doesn't satisfy normals as they are non consistant.
Approximating Curves with Line Segments (2D Example):
Curves can be approximated using line segments.
Increasing the number of vertices improves the approximation of the curve.
As the number of segments approaches infinity, the approximation gets closer to the true curve.
Mathematical Explanation:
Approximating the area of a circle with radius 1.
Divide the circle into segments.
Angle of each segment:
Area of each segment:
Total area using segments:
As approaches infinity, approaches 0.
Therefore,
This proves that increasing the number of vertices to infinity results in the true approximation of the circle.
Approximating Spheres with Polygons (3D Example):
Smaller number of polygons results in a rough approximation of the sphere.
Increasing the number of polygons gets closer to a true sphere.
Complex objects require more polygons for detailed representation.
Adapt the number of polygons based on the complexity of different parts of the object.
Use a moderate number of polygons for less complex parts and more polygons for more complex parts.
Approximating a Circle in OpenGL (Older Version):
Origin at , radius is 1.
Angle of each slice:
Use
GLLineLoopto create a loop of line segments.The X and Y coordinates for each point are:
Where is the radius and is the angle of the slice.
Increasing gets closer to the true approximation.
Triangle Mesh in OpenGL:
GL_BEGINandGL_ENDdefine the start and end of drawing.GL_VERTEXinputs the vertex values.GL_TRIANGLES: Draws individual triangles.GL_TRIANGLE_STRIP: Creates a strip of triangles by reusing the last two vertices of the previous triangle.GL_TRIANGLE_FAN: Shares the first vertex among all triangles.
Redundant vs. Shared Representation:
Redundant method: Uses
GL_TRIANGLESand inputs all vertices for each face, even if they are repeated.Shared method: Uses strips or fans to reuse vertices.
Explicit Representation (Redundant):
Each triangle requires three vertices.
For faces, requires floats (3 values for each vertex).
Vertices are defined as
Example:
Triangle 1:
Triangle 2:
Vertex Array Capability:
Enable with
GL_ENABLE_CLIENT_STATE.Draw arrays using
glDrawArrays.Define the primitive type (
GL_TRIANGLES).Specify the starting vertex and the number of vertices to use.
Vertex Buffer Objects (VBOs):
Objects created to store arrays in memory for drawing.
Used in both explicit and shared representation.
Initializing VBOs:
glGenBuffers: Generate the buffer.glBindBuffer: Bind the buffer with an array (GL_ARRAY_BUFFER).glBufferData: Input data into the buffer (vertex array).GL_STATIC_DRAW: Argument when the data is not dynamic.To draw the explicit representation, input triangles as such.
Function :
glDrawArrays
Shared Representation (Non-Redundant):
Assigns an index to each vertex.
Refers to the index when defining triangles rather than repeating vertex values.
Example:
Vertex gets index 0.
Vertex gets index 1.
Triangle 1: Use indices 0, 1, and 2.
Triangle 2: Use indices 1, 2, and 3.
Number of floats required becomes much less than explicit representation.
With vertices, each having 3 numbers, requires floats.
With triangles, requires integers for indices.
Shared Representation in OpenGL:
For explicit representation:
Generate buffer using
glGenBuffers.Bind buffer using
glBindBuffer.Input using
glBufferData.
For shared representation:
Create an index buffer.
Bind buffer with
GL_ELEMENT_ARRAY_BUFFER.Input data using
glBufferDatawith the array of indices.
To Draw function :
glDrawElements
Information for each Vertex:
Vertex position (X, Y, Z values).
Color information (RGB values).
Normal (NX, NY, NZ values) for light interactions, texture mapping, etc.
Light source information (type, position).
Surface material (reflectivity, absorption).
Connectivity.
Transparency (alpha channel).
Shading Methods:
Flat shading: Fill each face with a single color, leading to visible boundaries and contrast.
Interpolated shading: Interpolate values from one edge to another for a smoother color transition across the face.
Different shading methods have varying complexity based on the scene and objects.
Treats the object in different ways.