Question: 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

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 shading artifacts. You may find it convenient to render a point (or small object) at the location of the light source.

Program 7.1public class Code extends JFrame implements GLEventListener { private GLCanvas myCanvas; // declarations forprivate Vector3f currentLightPos = new Vector3f(); private float[] lightPos = new float[3]; // current light// This function is unchanged from the previous chapter. // The following portion is repeated for clarity,// set up lights currentLightPos.set(initialLightLoc); install Lights();// build the inverse-transpose of the MV matrix, for transforming normal vectors mMat.invert(inv TrMat);gl.glEnable(GL_CULL_FACE); gl.glFrontFace(GL_CCW); gl.glEnable(GL_DEPTH_TEST); gl.glDepthFunc(GL_LEQUAL);// get the locations of the light and material fields in the shader globalAmbLoc = gl.glGetUniform Location// set the uniform light and material values in the shader gl.glProgramUniform4fv(renderingVertex Shader #version 430 layout (location=0) in vec3 vertPos; layout (location=1) in vec3 vertNormal; outuniform vec4 globalAmbient; uniform PositionalLight light; uniform Material material; uniform mat4 m_matrix;// ambient, diffuse, and specular contributions vec3 ambient = ((globalAmbient * material.ambient) +} vec3 diffuse = light.diffuse.xyz * material.diffuse.xyz*max(dot(N,L), 0.0); vec3 specular =Fragment Shader #version 430 in vec4 varying Color; out vec4 fragColor; // uniforms match those in the vertexuniform vec4 globalAmbient; uniform PositionalLight light; uniform Material material; uniform mat4 m_matrix;

public class Code extends JFrame implements GLEventListener { private GLCanvas myCanvas; // declarations for building shaders and rendering program, as before. // declaration of one VAO, two VBOS, Torus object, and Torus and camera location as before. // Utils.java class now has gold, silver, and bronze material accessors added. // allocate variables for display() function private FloatBuffer vals = Buffers.newDirectFloatBuffer(16); private Matrix4f pMat = new Matrix4f(); private Matrix4f vMat = new Matrix4f(); private Matrix4f mMat = new Matrix4f(); private Matrix4f invTrMat = new Matrix4f(); // perspective matrix // view matrix // model matrix // inverse-transpose matrix for converting normals private int mLoc, vLoc, pLoc, nLoc; private int globalAmbLoc, ambLoc, diffLoc, specLoc, posLoc, mAmbLoc, mDiffLoc, mSpecLoc, mShiLoc; // locations of shader uniform variables

Step by Step Solution

3.41 Rating (148 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Graphics Programming Questions!