Question: Each of the surface objects is assigned a diffuse color. The first part of the assignment is to mix the diffuse color in with the
Each of the surface objects is assigned a diffuse color. The first part of the assignment is to mix the diffuse color in with the shape color. See the example usematerial in the Module example stream to see how that is done.
Here is a guide:
Define a uniform variable in the fragment shader
Give the variable an initial value vec so that base still works properly.Mix the shape color and the diffuse color to get the fragment color
Add code to the driver to send the diffuse color value for each artifact to the fragment shader
Source code give:
#include GLMgtctypeptrhpp
#include
#include
#include "learnopenglshaderh
#include csartifacth
#include csviewh
#include cswindowh
#include csbufferutilities.h
static cs::View theview;
static Shader shader;
static std::vector artifactlist;
static auto asteroidcenter glm::vec;
static float asteroidradius ;
static float pcheight ;
static unsigned int randomseed ;
void init
theview new cs::View;
shader new Shadervertexshader.glsl"fragmentshader.glsl;
shaderuse;
glEnableGLDEPTHTEST;
position the camera
theviewcameraPosition asteroidradius pcheight glm::vec asteroidcenter;
theviewcameraUp glm::vec;
theviewcameraForward glm::vec;
theviewcameraLeft glm::crosstheviewcameraUp, theviewcameraForward;
cs::Shape b new cs::Sphere;
bcolorSet std::vectorcs::Color::colorRGBcs::Color::colorRGB;
auto transformation new cs::Transformation;
transformationmultiplyScaleasteroidradius, asteroidradius, asteroidradius;
transformationmultiplyTranslationasteroidcenter;
transformationrotationAxis glm::vec;
transformationrotationCenter asteroidcenter;
transformationrotationRate ;
auto artf new cs::Artifacttransformation;
artftheShape b;
artfsurfaceMaterial.diffuseColor cs::X::white;
artifactlist.pushbackartf;
std::srandrandomseed;
cs::Shape shapes
new cs::Block
new cs::Cylinder
new cs::Cylinder
;
int numshapes ;
shapescolorSet std::vectorcs::X::gray cs::X::gray;
shapescolorSet std::vectorcs::X::gray cs::X::gray;
shapescolorSet std::vectorcs::X::gray cs::X::gray;
forint i ; i ; i
float height glm::linearRand;
auto position glm::sphericalRandasteroidradius height asteroidcenter;
printfpos fff distance f
position.x position.y position.z
glm::lengthposition asteroidcenter;
auto cToP position asteroidcenter;
transformation new cs::Transformation;
transformationmultiplyScaleheight height, height ;
transformationmultiplyRotationglm::acospositiony glm::lengthposition
glm::veccToPzcToP.x;
transformationmultiplyTranslationposition;
artf new cs::Artifacttransformation;
artftheShape shapesi numshapes;
unsigned int r intglm::linearRand;
unsigned int g intglm::linearRand;
unsigned int b intglm::linearRand;
artfsurfaceMaterial.diffuseColor cs::Color::colorRGBrgb;
artifactlist.pushbackartf;
cs::initBuffersshaderID artifactlist, bposition", bcolor";
void render
auto viewtransform glm::lookAttheviewcameraPosition,
theviewcameraPosition theviewcameraForward,
theviewcameraUp;
auto projectiontransform glm::infinitePerspectivetheviewperspectiveFOVY,
theviewperspectiveAspect, theviewperspectiveNear;
auto vptransform projectiontransform viewtransform;
for auto artf : artifactlist
auto modeltransform artfworldTransformationgetMatrix;
auto transform vptransform modeltransform;
shadersetMatutransform", transform;
glDrawArraysGLTRIANGLES, artftheShapebufferStart, artftheShapebufferSize;
float movementspeed f;
float lrscale movementspeed;
float fbscale movementspeed;
float udscale movementspeed;
float lrpanscale f;
float udpanscale lrpanscale;
void generalkeycallbackGLFWwindow window, int key, int scancode, int action, int mods
static int oldwidth, oldheight, oldxpos, oldypos;
auto view staticcastglfwGetWindowUserPointerwindow;
if action GLFWPRESS action GLFWREPEAT
switch key
case GLFWKEYA:
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
