Modify Program 7.1 so that the light can be positioned by moving the mouse. After doing this,

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 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;

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Computer Graphics Programming In OpenGL With JAVA

ISBN: 9781683922193

2nd Edition

Authors: V. Scott Gordon PhD, John L. Clevenger PhD

Question Posted: