1 / 9

CPSC 453 Tutorials

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

plato
Download Presentation

CPSC 453 Tutorials

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CPSC 453 Tutorials Xin Liu Oct 21, 2013

  2. 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);

  3. 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]);

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

  5. 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);

  6. Customized shaders • Three shaders for HW2 available on tutorial website • ADSFlat.vp/fp • ADSGouraud.vp/fp • ADSPhong.vp/fp

  7. 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");

  8. 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());

  9. Manage shaders with GLTools • Step 4: Render models g_triangleBatch.Draw();

More Related