1. Homepage
  2. Programming
  3. COMPSCI 3GC3 Computer Graphics Fall 2023 - Assignment 2: Blendshapes for Face Expressions

COMPSCI 3GC3 Computer Graphics Fall 2023 - Assignment 2: Blendshapes for Face Expressions

Engage in a Conversation
McMasterCOMPSCI 3GC3Computer GraphicsBlendshapes for Face ExpressionsOpenGLC++

3GC3 Fall 2023 - Assignment 2 Blendshapes for Face Expressions CourseNana.COM

In assignment 2, we will load meshes described in obj file format, render them in OpenGL and use blendshapes for creating various facial expressions. CourseNana.COM

Figure 1. Facial Expression Rendered in Wireframe and Solid Mode Using OpenGL. CourseNana.COM

Task 1: Load and Render Mesh Using Tinyobj CourseNana.COM

1.1 Understanding Obj File Format CourseNana.COM

Obj is a very popular file format for describing meshes. Information stored in obj format is similar to the Indexed Triangle Mesh structure that we introduced in class. In the file, v indicates vertex position, vt indicates texture coordinate, vn indicates normal direction, and f indicates face construction with vertices, texture coord and normals, using format f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 .... For example, the cube we rendered in Assignment 1 in obj file format can be described as follows: CourseNana.COM

v -1.00000 -1.00000 1.00000
v 1.00000 -1.00000 1.00000
v -1.00000 1.00000 1.00000
v 1.00000 1.00000 1.00000
v -1.00000 1.00000 -1.00000
v 1.00000 1.00000 -1.00000
v -1.00000 -1.00000 -1.00000
v 1.00000 -1.00000 -1.00000
vt 1.000000 0.000000
vt 0.000000 1.000000
vt 1.000000 1.000000
vn 0.000000 0.000000 1.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 -1.000000 0.000000
vn 1.000000 0.000000 0.000000
vn -1.000000 0.000000 0.000000
f 1/1/1 2/2/1 3/3/1
f 3/3/1 2/2/1 4/4/1
f 3/1/2 4/2/2 5/3/2
f 5/3/2 4/2/2 6/4/2
f 5/4/3 6/3/3 7/2/3
f 7/2/3 6/3/3 8/1/3
f 7/1/4 8/2/4 1/3/4
f 1/3/4 8/2/4 2/4/4
f 2/1/5 8/2/5 4/3/5
f 4/3/5 8/2/5 6/4/5
f 7/1/6 1/2/6 5/3/6
f 5/3/6 1/2/6 3/4/6

In the cube mesh, there are 8 unique vertices (defined by lines starting with v) and 6 unique face normals (defined by lines starting with vn). Ignore texture coordinate for this assignment. There are 12 triangle faces constructing the cube mesh (defined by lines starting with f). For example, based on f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3, line f 1/1/1 2/2/1 3/3/1 means this face is a triangle face. It has three vertices with index 1, 2 and 3, and the normals associated with the vertices are with index 1, 1, 1. CourseNana.COM

For more details of obj file format you can check with https://en.wikipedia.org/wiki/Wavefront_.obj_file. The cube.obj file is provided for the assignment. CourseNana.COM

1.2 tinyobj loader CourseNana.COM

After understanding the obj file format, we will load meshes described in obj format to our OpenGL program and render them. Given the obj files, you don’t need to implement CourseNana.COM

the obj file parser, but you can include the tinyobjloader library for loading obj meshes https://github.com/tinyobjloader/tinyobjloader. CourseNana.COM

Here is some example code: CourseNana.COM

tinyobj::attrib_t attrib;
std::vector<tinyobj::shape_t> shapes;
std::vector<tinyobj::material_t> materials;
// tinyobj load obj
CourseNana.COM

The above code loads an obj file from obj_path. After loading the obj file into the program, you can access the faces, vertices and normals from shapes and attrib. The example code is listed below. CourseNana.COM

for(auto face : shapes[0].mesh.indices) { CourseNana.COM

int vid = face.vertex_index; int nid = face.normal_index; CourseNana.COM

//fill in vertex buffer with vertex positions CourseNana.COM

vbuffer.push_back(attrib.vertices[vid*3]);//vertex vid’s x vbuffer.push_back(attrib.vertices[vid*3+1]);//vertex vid’s y vbuffer.push_back(attrib.vertices[vid*3+2]);//vertex vid’s z CourseNana.COM

//fill in normal buffer with normal directions CourseNana.COM

nbuffer.push_back(attrib.normals[nid*3]); nbuffer.push_back(attrib.normals[nid*3+1]); nbuffer.push_back(attrib.normals[nid*3+2]); CourseNana.COM

} CourseNana.COM

You need to get the vertex position and normal information and pass them to the OpenGL shaders to render them. You can choose to reuse the provided code or implement your own as you see fit. CourseNana.COM

1.3 Your Task to Render Meshes CourseNana.COM

Now you know the obj file format and how to load it to program using tinyobjloader. For all the rendering tasks, here are the common configurations: CourseNana.COM

Background color CourseNana.COM

(0.3f, 0.4f, 0.5f, 1.0f) CourseNana.COM

Window Size CourseNana.COM

Window Width = 1024; Window Height = 768; CourseNana.COM

Model Matrix CourseNana.COM

Identity CourseNana.COM

Projection Matrix CourseNana.COM

glm::mat4 proj = glm::perspective(glm::radians(60.0f), 4.0f / 3.0f, 0.1f, 1000.0f); CourseNana.COM

Fragment Shader CourseNana.COM

#version 330 core in vec3 Normal;
out vec3 FragColor; void main()
CourseNana.COM

{
float c = dot(Normal, vec3(0.8,0.7,0.6)); FragColor = vec3(c,c,c);
CourseNana.COM

} CourseNana.COM

Cull backface + Depth Test with GL_LESS CourseNana.COM

Table 1. Face Mesh Rendering Configuration CourseNana.COM

1.3.1 Render cube.obj CourseNana.COM

Load the provided cube.obj and render it in your OpenGL code. Set the view matrix as CourseNana.COM

glm::mat4 view = glm::lookAt(glm::vec3(-2,6,5), glm::vec3(0,1,0), glm::vec3(0,1,0)); Press p to capture ppm and rename the ppm image to “cube_solid.ppm”. CourseNana.COM

Render the cube in wireframe mode by adding code CourseNana.COM

glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); CourseNana.COM

Press p to capture ppm and rename the ppm image to “cube_wire.ppm”. CourseNana.COM

1.3.2 Load and Render obj files for faces CourseNana.COM

You have a folder “faces”, containing obj files base.obj, 0~34.obj, totalling 36 obj files. They form the blendshapes for the face. Set the view matrix as
glm::mat4 view = glm::lookAt(glm::vec3(20,50,200), glm::vec3(0,90,0), glm::vec3(0,1,0)); CourseNana.COM

Load and render base.obj in both solid and wireframe mode, and rename captured ppm images to “base_solid.ppm” and “base_wire.ppm” respectively. CourseNana.COM

Figure 2. Example result of 14.obj rendered and captured with a different view matrix. CourseNana.COM

Task 2: Render Blendshapes for Facial Expressions CourseNana.COM

For Task 2, first you need to load all the obj files under the “faces” folder, i.e. base.obj, 0.obj ~ 34.obj, store them in the program without rendering them. Then in the code we will apply blendshape operations on the provided meshes to generate new facial expression shapes and render the generated shapes. CourseNana.COM

2.1 Blendshape Operations CourseNana.COM

New facial expression shape can be computed by the following formula: CourseNana.COM

Shapenew expression = Shapebase + 𝝨 wi * (Shapei - Shapebase) CourseNana.COM

Note, you load shapes from base.obj and 0.obj ~ 34.obj, under the “faces” folder, and they all have the same number of vertices, the same order in the vertex list, and the same way how faces are constructed by vertices. The shape subtraction, summation and multiplication involved in the above formula is vertex-wise. For example, the following code is subtracting two shapes. (Let’s simplify the computation, and ignore normals and texture coordinates. During rendering, you can reuse base.obj’s normal for the generated facial expression) CourseNana.COM

assert(obj1.m_attrib.vertices.size() == obj2.m_attrib.vertices.size()); for(unsigned i = 0; i < obj1.m_attrib.vertices.size(); ++ i)
{
CourseNana.COM

result_vertices[i] = obj1.m_attrib.vertices[i] - obj2.m_attrib.vertices[i]; } CourseNana.COM

2.2 Blendshape Weights
wi in the above formula are blending weights. Specifically, in this assignment, we need CourseNana.COM

to know the weights w0 ~ w34 for the blending shapes. Weights are provided under folder “weights”, where each file includes 35 floating numbers, in the order for w0 ~ CourseNana.COM

w34. According to the weight values described in one weight file, each file generates one facial expression shape. CourseNana.COM

2.3 Your Task to Compute Facial Expressions and Render Them CourseNana.COM

Read each weight file in, and compute the new facial expression shape according to the blending formula and the weight values, and render the resulting facial expression in OpenGL. Render configuration is the same as listed in Table 1, set view matrix as glm::mat4 view = glm::lookAt(glm::vec3(20,50,200), glm::vec3(0,90,0), glm::vec3(0,1,0)); and only render facial expression shapes in solid mode. CourseNana.COM

Specifically, follow the order, load “0.weights” in, compute the blended shape given the weight value in “0.weights”, render the result shape, press p to capture ppm image, and rename it to “blended0.ppm”. Then load “1.weights” in, compute the blended shape, render the result shape, capture ppm and rename it to “blended1.ppm”. Do this for all the provided weight files, and capture ppm from “blended0.ppm” to “blended11.ppm”. Facial expression in Figure 1 illustrates one of the results. CourseNana.COM

Submission Checklist
Submit your code together with all the captured ppm images. CourseNana.COM

CourseNana.COM

1 points - “cube_solid.ppm” 1 points - “cube_wire.ppm” 3 points - “base_solid.ppm” 1 points - “base_wire.ppm” 3 points - “0.ppm” CourseNana.COM

3 points - “1.ppm”
3 points - “7.ppm”
3 points - “8.ppm”
3 points - “13.ppm”
3 points - “14.ppm”
3 points - “23.ppm”
3 points - “24.ppm”
3 points - “27.ppm”
3 points - “28.ppm”
4 points - “blended0.ppm” 4 points - “blended1.ppm” 4 points - “blended2.ppm” 4 points - “blended3.ppm” 4 points - “blended4.ppm” 4 points - “blended5.ppm” 4 points - “blended6.ppm” 4 points - “blended7.ppm” 4 points - “blended8.ppm” 4 points - “blended9.ppm” 4 points - “blended10.ppm” 4 points - “blended11.ppm”
CourseNana.COM

17 points - source code
Submission deadline is
Nov. 14th, 2023 CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
McMaster代写,COMPSCI 3GC3代写,Computer Graphics代写,Blendshapes for Face Expressions代写,OpenGL代写,C++代写,McMaster代编,COMPSCI 3GC3代编,Computer Graphics代编,Blendshapes for Face Expressions代编,OpenGL代编,C++代编,McMaster代考,COMPSCI 3GC3代考,Computer Graphics代考,Blendshapes for Face Expressions代考,OpenGL代考,C++代考,McMasterhelp,COMPSCI 3GC3help,Computer Graphicshelp,Blendshapes for Face Expressionshelp,OpenGLhelp,C++help,McMaster作业代写,COMPSCI 3GC3作业代写,Computer Graphics作业代写,Blendshapes for Face Expressions作业代写,OpenGL作业代写,C++作业代写,McMaster编程代写,COMPSCI 3GC3编程代写,Computer Graphics编程代写,Blendshapes for Face Expressions编程代写,OpenGL编程代写,C++编程代写,McMasterprogramming help,COMPSCI 3GC3programming help,Computer Graphicsprogramming help,Blendshapes for Face Expressionsprogramming help,OpenGLprogramming help,C++programming help,McMasterassignment help,COMPSCI 3GC3assignment help,Computer Graphicsassignment help,Blendshapes for Face Expressionsassignment help,OpenGLassignment help,C++assignment help,McMastersolution,COMPSCI 3GC3solution,Computer Graphicssolution,Blendshapes for Face Expressionssolution,OpenGLsolution,C++solution,