7 week 5, Excerciese 1/1: Splines in a geometry shader O A geometry shader is an...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
7 week 5, Excerciese 1/1: Splines in a geometry shader O A geometry shader is an optional shader stage between the vertex and the fragment shader. The geometry shader takes a geometric primitive, consisting of a number of vertices, as input. The shader can then transform the input into a new primitive, consisting of dif- ferent vertices. A good example for using a geometry shader is the interpolation of curves, like Bzier curves. In this exercise you implement a GLSL effect that constructs a cubic Bzier curve when given four control points - the vertices of a quad. After this, you write a vertex shader to animate a cube moving along a "path" constructed using splines. See video and figure 3. You are given a skeleton project that displays a quad. In the geom- etry shader, vertices are generated using GLSL function EmitVertex(), see function genVertex(). First, implement the functions evalBezier(float t) and evalBezier Tan( float t) to return a point on the cubic curve6 at parameter t and its tangent, respectively. Next, make the shader emit vertices along the curve. The amount of segments per curve is defined by the variable uNum. The end results should look similar to the curve in the middle image of figure 3. In the next step we give the curve some some thickness. Generate7 a triangle strip8 of thickness 9 d, instead of a line strip. Implement the vertex shader of shader pass Anim to move the cube along the curve. (1) Activate the Anim shader pass by clicking eye icon next to it. (2) Implement 20 the evalBezier and evalBezierTan func- tions. (3) Implement the translation and scaling transformation functions, T(vec3 t) and S(vec3 s). (4) Construct matrix mr to move the cube according to variablet along the curve, making it face the tangent direction of the center curve. Figure 3: Some control points (vertices of a quad) being trans- formed into a curve and a sur- face, using geometry shaders. Figure 4: Construction of a triangle strip. Each generated vertex (blue) forms a triangle with the last two vertices. The four control points are available as gl_in[i].gl Position with i = 0,1,2,3. 7 In the layout of the geometry shader use triangle-strip instead of line-strip. The construction of the triangle strip is as shown in figure 4- "Hint: Use tangent function to con- struct normal vector n in point p assuming that the curve lies in the z = 0 plane. Generate points p + dn of the triangle strip centered around the curve. *Reuse code from the geometry shader, but modify to use the control points P0, P1, P2, P3 as parameters. Simple (VS) File Code Simple (GS) Simple (PS) #version 330 3 layout (location = 0) in vec3 pos; 4 layout (location = 1) in vec3 normal; 5 6 gout VertexData { vec4 color; vec4 pos; [} OutData; 11 @void main() { 12 OutData.color = vec4(sign (pos.xy), 1.0, 1.0); OutData.pos - vec4 (pos, 1.0); gl_Position = vec4 (pos, 1); X Preview Simple (VS) Simple (GS) File Code #version 330 corel 2 3 layout( lines_adjacency ) in; 4 layout(line_strip, max_vertices=200) out; 5 //layout(triangle_strip, max_vertices=200) out; 6 7pin VertexData{ 8 9 10 } VertexIn[4]; 11 12 13 gout VertexData { 14 vec4 color; 15 ) VertexOut; 16 17 uniform mat4 matP; 18 uniform mat4 matV; 19 uniform mat4 matGeo; 20 21 //uniform int uNum; 22 const int uNum = 10; 23 const float d = 0.07; 24 25 vec4 evalBezier(in float t) 26 ( 27 28 29 } 30 31 vec4 evalBezier Tan (in float t) 32 Q{ 33 34 35 [} 36 vec4 color; vec4 pos; 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 37 //first transforms a vertex, then emits it 38 void genVertex(in vec4 v, in mat4 matMVP) 39 { 40 41 42 L} 43 62 63 64 //TODO return vec4(0); 44 void main() 45 { 46 65 > } Simple (PS) //TODO return vec4(0); gl_Position = matMVP v; EmitVertex(); VertexOut.color=vec4(0.2); mat4 matMVP = matP * matV * matGeo; //TODO //generate the vertices on the control points VertexOut.color = VertexIn[0].color; genVertex(gl_in[0].gl_Position, matMVP); VertexOut.color = VertexIn[1]. color; genVertex(gl_in[1].gl_Position, matMVP); VertexOut.color = VertexIn[2].color; genVertex (gl_in[2].gl_Position, matMVP); VertexOut.color = Vertex In[3].color; genVertex (gl_in[3].gl_Position, matMVP); EndPrimitive(); Simple (VS) File Code Simple (GS) 1 #version 330 2 3 gin VertexData { 4 vec4 color; 5 [} VertexIn; 6 7 8 9 avoid main() { 10 11 L} out vec4 outColor; Simple (PS) out Color = VertexIn.color; 7 week 5, Excerciese 1/1: Splines in a geometry shader O A geometry shader is an optional shader stage between the vertex and the fragment shader. The geometry shader takes a geometric primitive, consisting of a number of vertices, as input. The shader can then transform the input into a new primitive, consisting of dif- ferent vertices. A good example for using a geometry shader is the interpolation of curves, like Bzier curves. In this exercise you implement a GLSL effect that constructs a cubic Bzier curve when given four control points - the vertices of a quad. After this, you write a vertex shader to animate a cube moving along a "path" constructed using splines. See video and figure 3. You are given a skeleton project that displays a quad. In the geom- etry shader, vertices are generated using GLSL function EmitVertex(), see function genVertex(). First, implement the functions evalBezier(float t) and evalBezier Tan( float t) to return a point on the cubic curve6 at parameter t and its tangent, respectively. Next, make the shader emit vertices along the curve. The amount of segments per curve is defined by the variable uNum. The end results should look similar to the curve in the middle image of figure 3. In the next step we give the curve some some thickness. Generate7 a triangle strip8 of thickness 9 d, instead of a line strip. Implement the vertex shader of shader pass Anim to move the cube along the curve. (1) Activate the Anim shader pass by clicking eye icon next to it. (2) Implement 20 the evalBezier and evalBezierTan func- tions. (3) Implement the translation and scaling transformation functions, T(vec3 t) and S(vec3 s). (4) Construct matrix mr to move the cube according to variablet along the curve, making it face the tangent direction of the center curve. Figure 3: Some control points (vertices of a quad) being trans- formed into a curve and a sur- face, using geometry shaders. Figure 4: Construction of a triangle strip. Each generated vertex (blue) forms a triangle with the last two vertices. The four control points are available as gl_in[i].gl Position with i = 0,1,2,3. 7 In the layout of the geometry shader use triangle-strip instead of line-strip. The construction of the triangle strip is as shown in figure 4- "Hint: Use tangent function to con- struct normal vector n in point p assuming that the curve lies in the z = 0 plane. Generate points p + dn of the triangle strip centered around the curve. *Reuse code from the geometry shader, but modify to use the control points P0, P1, P2, P3 as parameters. Simple (VS) File Code Simple (GS) Simple (PS) #version 330 3 layout (location = 0) in vec3 pos; 4 layout (location = 1) in vec3 normal; 5 6 gout VertexData { vec4 color; vec4 pos; [} OutData; 11 @void main() { 12 OutData.color = vec4(sign (pos.xy), 1.0, 1.0); OutData.pos - vec4 (pos, 1.0); gl_Position = vec4 (pos, 1); X Preview Simple (VS) Simple (GS) File Code #version 330 corel 2 3 layout( lines_adjacency ) in; 4 layout(line_strip, max_vertices=200) out; 5 //layout(triangle_strip, max_vertices=200) out; 6 7pin VertexData{ 8 9 10 } VertexIn[4]; 11 12 13 gout VertexData { 14 vec4 color; 15 ) VertexOut; 16 17 uniform mat4 matP; 18 uniform mat4 matV; 19 uniform mat4 matGeo; 20 21 //uniform int uNum; 22 const int uNum = 10; 23 const float d = 0.07; 24 25 vec4 evalBezier(in float t) 26 ( 27 28 29 } 30 31 vec4 evalBezier Tan (in float t) 32 Q{ 33 34 35 [} 36 vec4 color; vec4 pos; 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 37 //first transforms a vertex, then emits it 38 void genVertex(in vec4 v, in mat4 matMVP) 39 { 40 41 42 L} 43 62 63 64 //TODO return vec4(0); 44 void main() 45 { 46 65 > } Simple (PS) //TODO return vec4(0); gl_Position = matMVP v; EmitVertex(); VertexOut.color=vec4(0.2); mat4 matMVP = matP * matV * matGeo; //TODO //generate the vertices on the control points VertexOut.color = VertexIn[0].color; genVertex(gl_in[0].gl_Position, matMVP); VertexOut.color = VertexIn[1]. color; genVertex(gl_in[1].gl_Position, matMVP); VertexOut.color = VertexIn[2].color; genVertex (gl_in[2].gl_Position, matMVP); VertexOut.color = Vertex In[3].color; genVertex (gl_in[3].gl_Position, matMVP); EndPrimitive(); Simple (VS) File Code Simple (GS) 1 #version 330 2 3 gin VertexData { 4 vec4 color; 5 [} VertexIn; 6 7 8 9 avoid main() { 10 11 L} out vec4 outColor; Simple (PS) out Color = VertexIn.color;
Expert Answer:
Answer rating: 100% (QA)
cpp include GL glewh include GLFW glfw3h include iostream const char vertexShad... View the full answer
Related Book For
Computer Graphics Programming In OpenGL With JAVA
ISBN: 9781683922193
2nd Edition
Authors: V. Scott Gordon PhD, John L. Clevenger PhD
Posted Date:
Students also viewed these programming questions
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Use the correlation matrix from Problem 1 to answer the following questions. a. Compute the semipartial rSBP(SMK|AGE). b. Compute the semipartial rSMK(SBP|AGE). c. Compare these correlations to the...
-
Senford PLC entered into a contract to sell 3,000 telephones each with a two-year provider contract. The total cost of the contract was 120 per month payable at the end of the month. The phones were...
-
Cooper Industries Inc. began 2019 with retained earnings of $25.32 million. During the year, it paid four quarterly dividends of $0.35 per share to 2.75 million common stockholders. Preferred...
-
Respondents Varsity Brands, Inc., Varsity Spirit Corporation, and Varsity Spirit Fashions & Supplies, Inc., design, make, and sell cheerleading uniforms. Respondents have obtained or acquired more...
-
Class Printing Supply of Baltimore has applied for a loan. Bank of America has requested a budgeted balance sheet at April 30, 2012, and a budgeted statement of cash flows for April. The March 31,...
-
Part E Constants A rigid, uniform, horizontal bar of mass m and length is supported by two identical massless strings. (Figure 1)Both strings are vertical. String A is attached at a distance d < L/2...
-
1. Purchased $87,360 in materials on account. 2. Issued $3,730 in supplies from the materials inventory to the production department. 3. Issued $43,760 in direct materials to the production...
-
Ted contributed $25,000 in cash for a 25% interest in a partnership. His share of the partnership income for the year was $20,000. In addition, the partnership reported on his Schedule K-1 for the...
-
Total number of shares in Dhofar steel company are 10000 and each one is sold for RO 10. Mr. Ahmed invested RO 10000 in purchasing shares of the above company. Based on one share one vote, how much %...
-
Selling price for 100. Cash flows over 10 years 1 $12 2 $11 3 $13 4 $14.1 5 $12. 6 $13.3 7 $12 8 $13 9 $11 10 $10 The cash flow yield is closest to what percent?
-
Suppose a different company offers Ludo Corporation a "Loss Control" service which costs S (in dollars) and which cuts the probability of all losses in half (such that the probability of both the...
-
How much equity would Phil have in his home based on the following information: Purchased price of $425,000 Fair market value of $432,000 20% down payment Has made $15,000 in principal payments
-
Should civility be a criterion for job performance? Discuss the implications of leaders and managers who lack appropriate leadership skills.
-
Your firm, Auditors-R-Us, has audited the financial statements of ABC company for the year 2020. You were assigned the wages and salaries expenses of $15,000,000 in 2020. It had 300 employees....
-
Why should you not model a decision variable as a random variable with a probability distribution?
-
Repeat Exercise 7.1, but applied to Program 7.2. This should only require substituting the shaders for Phong shading into your solution to Exercise 7.1. The improvement from Gouraud to Phong shading...
-
Modify Program 7.1 so that the light can be positioned by moving the mouse. After doing this, move the mouse around and note the movement of the specular highlight and the appearance of the Gouraud...
-
Modify Program 4.1 to replace the cube with some other simple 3D shape of your own design. Be sure to properly specify the number of vertices in the glDrawArrays() command. Program 4.1 Java/JOGL...
-
At January 1, 2015, Cheng Company reported retained earnings of 20,000,000. In 2015, Cheng discovered that 2014 depreciation expense was understated by 4,000,000. In 2015, net income was 9,000,000...
-
Cherokee Construction Company changed from the cost-recovery to the percentage-of-completion method of accounting for long-term construction contracts during 2015. For tax purposes, the company...
-
In 2015, Bailey Corporation discovered that equipment purchased on January 1, 2013, for 50,000 was expensed at that time. The equipment should have been depreciated over 5 years, with no residual...
Study smarter with the SolutionInn App