Question: Define an out variable in the vertex shader that has type vec 4 and is named position. Define an in variable in the fragment shader
Define an out variable in the vertex shader that has type vec and is named position. Define an in variable in the fragment shader with the same name. Add a statement to assign the buffer position to the position variable.
In the fragment shader, change the code to compute fColor as follows.
If the x component of position is less than set the r component of the fragment color to otherwise set it to
If the y component of position is less than set the g component of the fragment color to otherwise set it to
If the z component of position is less than set the b component of the fragment color to otherwise set it to
Set the a component of the fragment color to
Multiply the fragment color by scolor.
The source code is the following :
#include
#include GLMgtctypeptrhpp
#include
#include "learnopenglshaderh
#include csartifacth
#include cswindowh
#include csbufferutilities.h
static std::vector artifactlist;
static Shader shader;
void init
shader new ShaderproblemBvertexshader.glslproblemBfragmentshader.glsl;
shaderuse;
glEnableGLDEPTHTEST;
auto shape new cs::cylinder;
Change the colorset of the shape to using two levels of gray.
This will give a darkerlighter pattern of the material color over the surface.
auto graylevel;
auto graylevel;
shapecolorset std::vectorcs::colorgraylevel graylevel graylevel
cs::colorgraylevel graylevel graylevel;
auto number ;
auto d number ;
auto radius d ;
auto base radius;
for auto x ; x number; x
for auto y ; y number; y
for auto z ; z number; z
auto artf new cs::artifactrotating;
artftheshape shape;
artfworldtransform.translate glm::vecbase x d base y d base z d;
artfworldtransform.scale glm::vecradius radius, radius;
artfanimationtransform.rotationaxis glm::vec x y z ;
artfanimationtransform.rotationcenter
artfworldtransform.matrix glm::vec;
artfrotationrate MPI powz;
artifactlist.pushbackartf;
cs::initbuffersshaderID artifactlist, bposition", bcolor";
void render
static auto lasttime ;
auto time glfwGetTime;
auto deltatime time lasttime;
lasttime time;
uncomment the following few lines to see the frame rate computed two different ways
static double arate ;
auto x arate deltatime;
arate x;
for auto artf : artifactlist
artfanimatetime deltatime;
auto modelmatrix artfanimationtransform.matrix artfworldtransform.matrix;
shadersetMatutransform", modelmatrix;
glDrawArraysGLTRIANGLES, artftheshapebufferstart, artftheshapebuffersize;
int main
glfwInit;
cs::setopenglversion;
GLFWwindow window cs::setupwindowProblem B;
gladLoadGLglfwGetProcAddress;
init;
while glfwWindowShouldClosewindow
glClearBufferfvGLCOLOR, cs::x::grayasfloatarray;
glClearGLDEPTHBUFFERBIT;
render;
glfwSwapBufferswindow;
glfwPollEvents;
glfwDestroyWindowwindow;
glfwTerminate;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
