90 likes | 285 Views
CPSC 453 Tutorials. Xin Liu Oct 21, 2013. Intrinsic rotation. The angles are measured w.r.t the ref-frame of the object, not the world reference frame. m3dRotationMatrix44(M3DMatrix44f m, float angle, float x, float y, float z);. Stock Shaders. Identity shader Flat shader
E N D
CPSC 453 Tutorials Xin Liu Oct 21, 2013
Intrinsic rotation • The angles are measured w.r.t the ref-frame of the object, not the world reference frame m3dRotationMatrix44(M3DMatrix44f m, float angle, float x, float y, float z);
Stock Shaders • Identity shader • Flat shader • Shaded shader • Default light shader GLShaderManager::UseStockShader(GLT_SHADER_IDENTITY, GLfloatvColor[4]); GLShaderManager::UseStockShader(GLT_SHADER_FLAT, M3DMatrix44f m, GLfloatvColor[4]); GLShaderManager::UseStockShader(GLT_SHADER_SHADED, GLfloatmvp[16]); GLShaderManager::UseStockShader(GLT_SHADER_DEFAULT_LIGHT, GLfloatmvMatrix[16], GLfloatpMatrix[16], GLfloatvColor[4]);
Stock shaders • Point light shader • Texture replace shader • Texture modulate shader • Textured point light shader GLShaderManager::UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, GLfloatmvMatrix[16], GLfloatpMatrix[16], GLfloatvLightPos[3], GLfloatvColor[4]); GLShaderManager::UseStockShader(GLT_SHADER_TEXTURE_REPLACE, GLfloatmvpMatrix[16], GLintnTextureUnit); GLShaderManager::UseStockShader(GLT_SHADER_TEXTURE_MODULATE, GLfloatmvpMatrix[16], GLfloatvColor, GLintnTextureUnit); GLShaderManager::UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, GLfloatmvMatrix, GLfloatpMatrix[16], GLfloatvLightPos[3], GLfloatvBaseColor[4], GLintnTextureUnit);
Projective/Orthographic projections • Determined by the projection matrix • P. 151 Super Bible GLFrustum::SetPerspective(float fFov, float fAspect, float fNear, float fFar); GLFrustum:: SetOrthographic(GLfloatxMin, GLfloatxMax, GLfloatyMin, GLfloatyMax, GLfloatzMin, GLfloatzMax);
Customized shaders • Three shaders for HW2 available on tutorial website • ADSFlat.vp/fp • ADSGouraud.vp/fp • ADSPhong.vp/fp
Manage shaders with GLTools • Step 1: Load shaders upon initialization • Step 2: Locate uniforms (prep for uploading) ADSLightShader = g_shaderManager.LoadShaderPairWithAttributes("../ADSFlat.vp", "../ADSFlat.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); locAmbient = glGetUniformLocation(g_ADSLightShaders[g_shaderSelect], "ambientColor"); locDiffuse = glGetUniformLocation(g_ADSLightShaders[g_shaderSelect], "diffuseColor"); locSpecular = glGetUniformLocation(g_ADSLightShaders[g_shaderSelect], "specularColor"); locLight = glGetUniformLocation(g_ADSLightShaders[g_shaderSelect], "vLightPosition"); locMVP = glGetUniformLocation(g_ADSLightShaders[g_shaderSelect], "mvpMatrix"); locMV = glGetUniformLocation(g_ADSLightShaders[g_shaderSelect], "mvMatrix"); locNM = glGetUniformLocation(g_ADSLightShaders[g_shaderSelect], "normalMatrix");
Manage shaders with GLTools • Step 3: Upload uniforms (to GPU) GLfloatvEyeLight[] = { 100.0f, 100.0f, 100.0f }; GLfloatvAmbientColor[] = { 0.1f, 0.1f, 0.1f, 1.0f }; GLfloatvDiffuseColor[] = { 0.0f, 0.0f, 1.0f, 1.0f }; GLfloatvSpecularColor[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glUseProgram(g_ADSLightShaders[g_shaderSelect]); glUniform4fv(locAmbient, 1, vAmbientColor); glUniform4fv(locDiffuse, 1, vDiffuseColor); glUniform4fv(locSpecular, 1, vSpecularColor); glUniform3fv(locLight, 1, vEyeLight); glUniformMatrix4fv(locMVP, 1, GL_FALSE, g_transformPipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(locMV, 1, GL_FALSE, g_transformPipeline.GetModelViewMatrix()); glUniformMatrix3fv(locNM, 1, GL_FALSE, g_transformPipeline.GetNormalMatrix());
Manage shaders with GLTools • Step 4: Render models g_triangleBatch.Draw();