CS560/460 Spring 2019


CS560/460 Spring 2019
Programming Assignment 5
(Due on April 20, 2019 by 11:59pm)
Part 1: (20%)

Theory questions:

(1) (6%) By using the curve interpolation method, we use a cubic parametric polynomial () to fit four control points P0, P1, P2, and P3. This cubic polynomial curve passes through the four control points P0, P1, P2 and P3 when parameter u=0, 1/3, 2/3, 1 respectively. Find a matrix M which satisfies the condition f(u) = UMP
(where U= , P=, f(u) is a vector which has three components (x(u), y(u), z(u)); Each control point is a vector representing x, y, z coordinate as ).

(2) (6%) The uniform B-spline curves can be used to approximate the curve segments which are determined by a number of control points. Given six control points as shown below, use the B-spline curves to approximate the six control points in the following case: the degree of the B-spline polynomial is 2.

Indicate how many curve segments there are in this case;
Sketch the B-Spline curves on the following graph and label the curve segments.
(3) (8%) If the control point P5 is repeated as shown below. P5 will be used more than once in the evaluation for one curve segment. If we use the uniform cubic B-spline curves to fit the control points: p0, p1, p2, p3, p4, p5, p5, p5.

(a) (2%) Indicate the range of the knot values (i.e., 0, … ,m).
(b) (3%) Plot the blending functions within the knot value range (0, … ,m).
(c) (3%) Sketch the uniform cubic B-spline curves to fit the control points: p0, p1, p2, p3, p4, p5, p5, p5. Label all the curve segments explicitly.

Part 2: Programming Part (80%)

Description:

Surface rendering is achieved by applying natural lighting effects to the visible surfaces.
In this assignment, you are to implement the visible surface detection algorithm (i.e., back-surface removal) to display a Bezier surface patch. The illumination models, including the ambient light, diffuse reflection and specular reflection, are used for the surface shading. Two shading methods (flat shading and Gouraud shading) are applied. Surface details can also be added to the patch by using the texture mapping method. Through this assignment, you will practice the basic methods in surface rendering and display (back-face removal, shading and texture mapping), and simulate the lighting effect by using OpenGL.

Part A: Bezier surface deformation
Create a 3D surface patch using cubic Bezier surface representation:
In order to represent a Bezier surface patch, 16 control points are defined. Modifying any control point will change the shape of the surface. In this assignment, four control points are allowed to change through the menu click. The coordinate values of the control points can be modified in X, Y, and Z axes separately. This implementation will give you an intuitive view of how the control points affect the shape of Bezier surface patch.
In order to display the surface efficiently, you are required to implement the back-face removal algorithm such that only the visible surfaces are displayed.

(Extra Points (Optional): In the setting of perspective projection, select any of 16 control points to change the shape of Bezier surface. The control points can be determined by mouse click and gluUnproject(…)).

CS560/460作业代做、代写Programming留学生作业、代写Java/Python,c/c++程序设计作业

Part B: Surface Shading Generation
Define a point light source, generate the shading effects including ambient reflection,
diffuse reflection and specular reflection (phone model) on the Bezier surface patch.
You are to set a light source, surface material parameters and viewing position by using OpenGL. The illumination effects are adjustable (i.e., diffuse reflection, shininess and the lighting position) through the surface material definition. Both the flat shading mode and the smooth shading mode are applied.

(Optional extra points): using the ray-tracing for Bezier surface rendering.

Part C (Optional Extra Points): “S” Character Creation Using Uniform B-Spline Surface
Design a set of control points to create: (1) 2D character “S” using B-spline curve; (2) 3D character “S” using B-spline surface.

Part D (Optional Extra Points): Geometric Model Loading and Drawing using Shaders


Modern OpenGL programming is now done entirely on the GPU. This is accomplished by using the GLSL (GL Shading Language). This language makes use of shaders, which are programs that run on the GPU. A common task in graphics programming is creating a model viewer (i.e. MeshLab, Blender, etc.). You will be creating a bare bones version of these viewers. In this assignment you are required to load a 3D model from a file and render it to the screen using only shaders that run on the GPU.

Your implementation: In this assignment you will implement a model viewer that runs on the GPU. For example:

Your program will implement

1.Load a 3D model from file (.OBJ format). File name can be hardcoded.
2.Load the model onto the buffers (GLSL).
3.Render the model to the screen (GLSL).
4.Load the model texture onto the GPU and render it on the model.
5.Set up lighting on the GPU and show the model with it.

NOTE
1.To help make things a little easier it is recommended to use the libraries GLEW, and GLM. These are included in the skeleton and linked to the Visual Studio Solution.
2.For loading an image look into the MFC class CImage.

Your implementation:

(1)Set one viewport as a full screen window size
(2)Set the projection as a perspective projection.
(3)Set the initial viewpoint at (45, 45, 45), looking toward the origin (0, 0, 0).
The viewing point is changeable along the Z direction, the viewing direction is
always toward the origin (0, 0, 0). The view position can be relocated by the menu
click, each click moves the view position by +5 or –5 units along the Z direction.
(4)Set an initial directional light source at (50, 50, 50, 0), where the light source is infinitely far away from the scene, with the lighting direction (x, y, z) = (50, 50, 50). The lighting direction is adjustable through a menu click. Each click
moves light source by +5 or –5 units along the Y direction.
Part A, B, C, and D are implemented under the perspective projection.

1.Part A: Display the visible surface of a Bezier surface patch
1.1. In order to create a cubic Bezier surface patch, you need to:

Define initial 16 control points as 4*4 grids with the interval 20 in X direction and interval 20 in Z direction. Y values are set to zero.
Set the viewpoint at the position (x, y, z) = (45, 45, 45), looking toward the origin. View-up vector is along the positive Y direction (0, 1, 0)
Plot the 16 control points.
Plot three lines to represent X, Y, Z axis (right-handed coordinate system)
(you may translate them by a certain distance to make the whole control points visible in the viewport.)

Use cubic Bezier surface equation to calculate the surface points P(u, v):
u : 0 1 with the inctrement 0.05
v: 0 1 with the inctrement 0.05

?Plot the P(u, v) in the viewport.
?Four internal control points are allowed to change. You can select one of the four internal control points (not boundary control points) by menu click, and change the coordinate along X, Y, Z directions separately (only one component value of X, Y or Z is allowed to change at one time).
Redraw the control points and the changed Bezier surface patch if any of the internal control points is modified.

1.2 In order to remove the back surface, you need to:

Split each polygon (i.e., each grid mesh) into two triangles, such that the whole surface patch is composed of small triangle faces.

Calculate the normal of each triangle face, and based on the viewing direction and the normal value of each face, determine the visibility of each surface. (You can take one viewing direction for all the triangle faces).

Plot the visible triangle faces only. The wire-frame model is displayed.

Redraw the visible surface of the changed Bezier surface patch if any of the internal control points is modified, or the viewpoint is changed.
2.Part B: Bezier surface rendering

2.1 Surface shading:

In Part A, the Bezier surface is displayed in the wire-frame form. In part B, the shading effects can be added on the surface. The wire-frame mode and the surface rendering mode can be switched by your menu definition.

Two rendering modes applied: Flat shading and Smooth shading. Select one of the modes to render the surface at one time (through a menu selection).

Set the ambient, diffuse and specular light with the initial parameters:
LightAmbient[] = { 0.1, 0.1, 0.1, 1.0};
LightDiffuse[] = { 0.7, 0.7, 0.7, 1.0};
LightSpecular[] = { 0.4, 0.4, 0.4, 1.0};

The surface material is set for ambient reflection, diffuse reflection and specular reflecton. Both ambient and diffuse reflections reflect the green color
and the specular reflection reflects the white (e.g., RGBA = 1.0, 1.0, 1.0, 1.0).

Increase/decrease the shininess of the highlight by changing the specular exponent value. (the incremental step of the exponent value change is +5 or –5, the initial exponent value is set as 50).

Increase/decrease the diffuse reflection (incremental step is +0.1 or –0.1). You can set the initial material parameters for the diffuse reflection (e.g., RGBA = 0.0, 0.7, 0.0, 1.0)

Define menu to adjust the specular shininess and diffuse reflection as described above.

2.2.Surface Shading Generation Using Ray-Tracing (optional)
Define a point light source, generate the shading effects on the surface of Bezier patch and a sphere above the Bezier patch using the ray-casting based ray-tracing algorithm. The rendering includes the shadows of spheres on the Bezier patch.
2.3 Surface texture mapping (Optional)

The texture mapping is enabled in this part (similar to the assignment 4)
Load an image (.bmp) to an image array as a texture-map (see sample code). Define the texture coordinates based on the Bezier patch grids.

Map the loaded texture onto the Bezier surface patch using OpenGL.The patch shape is changeable through the adjustment of the four internal control points as described in Part A.

The lighting effect must be effective on the mapped texture, including the diffuse reflection, specular highlight and the change of the light source position as used in the Part B.

3.Part C: B-Spline Surface Creation (Optional)

Design a set of control points in the 2D plane, using cubic B-spline curve to create a character “S”. Note that the control points are adjustable, so that the shape of “S” can be changed interactively.
Design a set of control points in the 3D space, using cubic B-spline surface to create a 3D character “S”. Note that the 3D surface is also allowed to deform through the modification of any of the control points.

4.Part D: Geometric model loading and drawing using Shaders (Optional)

Your program will load a 3D model from file (.OBJ format), render it with texture (GLSL) with GPU.

(See reference “GL Shading Language_SupplementalMaterial.ppt” and a sample template program “GLSL_SKELETON_VS2012.rar”)

Tips on how to complete the assignment:

Part A:
(1)For each triangle, define the vertices in a counterclockwise order.
(2)The surface normal of each triangle face must be normalized
(3)The normal of a vertex (v) is the average of the normals of all the triangle faces
which share the vertex (v). The vertex normal must be normalized.
(4)The view vector is the viewpoint to the origin (0, 0, 0). You can take this
view vector for all the triangle faces for simple implementation.

Part B:
(5)Use glShadeMode() to define the flat shading or smooth shading (Read OpenGL red book (Ch.5, p170)
(6)Use glNormal3f, glVertex3f to render a polygon (Read OpenGL red book Ch.2 P65) (p87-88 shows one example for your reference)
(7)Use glLightf, glMaterialf to set the lighting parameters and the material reflection parameters (OpenGL red book Ch.5 p177-187)
(8)Make the depth buffer be active (e.g., glEnable(GL_DEPTH_TEST)
(9)Enable the lighting.

(10)Using OpenGL commands for texture mapping: glTexCoord2f, glBindTexture, glGenTextures, glTexEnvf, glTexParameteri, glTexImage2D, gluBuild2Dmipmaps,
glEnable(GL_TEXTURE_2D) (red-book Ch. 9, P356-361, P394-396, P385-386)
(11)Use the modulate mode to set the texture environment in order to make the lighting be effective.

Hand-in

Code package: Your program package and the assignment report must be compressed in a ZIP file, and submit it through the blackboard digital drop-box.

Mark distribution (100%)

Theory Part: (20%) Each question has 5 points.

Programming Part: (80%)

Part A:
(5%) Show the initial control points and XYZ axes.
(10%) Show the cubic Bezier surface patch
(8%) Show the updated surface patch after each modification of the control points.
(15%) Show the visible Bezier surface when its shape is changed along with the control point modification.
(Extra points (5%) : arbitrary control points are selected for shape modification)

Part B:
(12%) Show the shaded surface (both flat mode and smooth mode) with green color

Show the lighting effect on the shaded surface:
(5%) Change of the diffuse reflection,
(5%) Change of the specular highlight,
(5%) Change of the lighting direction
(5%) Change of the viewing direction and view position

(Extra 5%) Show the effect of the texture mapping on the Bezier surface with lighting effect
(Extra 5%) Show the effect of ray-tracing on the Bezier surface and a sphere

Part C (Extra points):
(10%) Show the 2D “S”.
(10%) Show the 3D “S”

Part D (Extra points):
(10%) Show 3D teapot model using shaders.

Write-up:
(10%) Clearly explain your code design, and the solution to the problem you solved

因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com 

微信:codinghelp

上一篇:Unity3D Shaderlab 学习记录


下一篇:IDirect3DDevice9 StretchRect