Matrix4D Matrix4D::transpose( const Matrix4D& A ) { return Matrix4D( A[0][0], A[0][1], A[0][2], A[0][3], A[1][0], A[1][1], A[1][2], A[1][3], A[2][0], A[2][1], A[2][2], A[2][3], A[3][0], A[3][1], A[3][2], A[3][3] ); }
Matrix4D Matrix4D::matrixCompMult( const Matrix4D& A, const Matrix4D& B ) { return Matrix4D( A[0][0]*B[0][0], A[0][1]*B[0][1], A[0][2]*B[0][2], A[0][3]*B[0][3], A[1][0]*B[1][0], A[1][1]*B[1][1], A[1][2]*B[1][2], A[1][3]*B[1][3], A[2][0]*B[2][0], A[2][1]*B[2][1], A[2][2]*B[2][2], A[2][3]*B[2][3], A[3][0]*B[3][0], A[3][1]*B[3][1], A[3][2]*B[3][2], A[3][3]*B[3][3] ); }
Matrix4D ParametrizedEulerAnglesAndTranslation::getMatrix(void) { Point3D angles = value->eulerAngles; Point3D trans = value->translate; Matrix3D rotate = Matrix3D(angles); return Matrix4D(rotate, trans); }
Matrix4D ParametrizedQuaternionAndTranslation::getMatrix(void) { Quaternion q = value->quaternion; Point3D trans = value->translate; Matrix3D closestRot = Matrix3D(q); return Matrix4D(closestRot, trans); }
Matrix4D ParametrizedRotationLogarithmAndTranslation::getMatrix(void) { Matrix3D m = value->skewSymmetric; Point3D trans = value->translate; Matrix3D exp = Matrix3D::Exp(m, 100); //exponential return Matrix4D(exp, trans); }
Matrix4D ParametrizedClosestRotationAndTranslation::getMatrix(void) { Matrix3D notRotation = value->rotation; Point3D trans = value->translate; Matrix3D closestRotate = notRotation.closestRotation(); return Matrix4D(closestRotate, trans); }
void ScreenSpaceAmbientOcclusionManager::generate_ssao_texture(Scene * scene) { //Render scene normals and depth to a texture glViewport(0, 0, viewport_width, viewport_height); Matrix4D view = scene->set_view(); Matrix4D projection = scene->set_projection(); Matrix3D normal = glm::inverseTranspose(glm::mat3(view)); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frame_buffer_object); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, normal_depth_texture, 0); check_frame_buffer(); glClearColor(0.f, 0.f, 0.f, 0.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaders.select_shader(NORMAL_DEPTH_TEXTURE); uint program = shaders.get_program_id(NORMAL_DEPTH_TEXTURE); GLint projection_location = glGetUniformLocation(program, "projection"); glUniformMatrix4fv(projection_location, 1, GL_FALSE, &projection[0][0]); GLint view_location = glGetUniformLocation(program, "view"); glUniformMatrix4fv(view_location, 1, GL_FALSE, &view[0][0]); GLint normal_matrix_location = glGetUniformLocation(program, "normal_matrix"); glUniformMatrix3fv(normal_matrix_location, 1, GL_FALSE, &normal[0][0]); scene->plain_render(view, program); scene->render_floor(view, program); shaders.select_shader(-1); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindTexture(GL_TEXTURE_2D, normal_depth_texture); glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); //Render SSAO to a texture glViewport(0, 0, viewport_width, viewport_height); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); view = Matrix4D(1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); projection = glm::ortho(-1.0, 1.0, -1.0, 1.0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frame_buffer_object); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ssao_texture, 0); check_frame_buffer(); glClearColor(0.f, 0.f, 0.f, 0.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaders.select_shader(separable ? SEPARABLE_SSAO : SSAO_TEXTURE); glActiveTexture(GL_TEXTURE0); bind_normal_depth_texture(); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures.getID(noise)); program = shaders.get_program_id(separable ? SEPARABLE_SSAO : SSAO_TEXTURE); GLint sampler_reference = glGetUniformLocation(program, "sampler"); glUniform1i(sampler_reference, 0); GLint noise_reference = glGetUniformLocation(program, "noise"); glUniform1i(noise_reference, 1); GLint viewport_width_reference = glGetUniformLocation(program, "viewport_width"); glUniform1f(viewport_width_reference, viewport_width); GLint viewport_height_reference = glGetUniformLocation(program, "viewport_height"); glUniform1f(viewport_height_reference, viewport_height); GLint radius_reference = glGetUniformLocation(program, "radius_modifier"); glUniform1f(radius_reference, radius); projection_location = glGetUniformLocation(program, "projection"); glUniformMatrix4fv(projection_location, 1, GL_FALSE, &projection[0][0]); view_location = glGetUniformLocation(program, "view"); glUniformMatrix4fv(view_location, 1, GL_FALSE, &view[0][0]); glColor3f(1.0, 1.0, 1.0); glBegin(GL_QUADS); glVertex3f(-1, -1, -0.5); glVertex3f(1, -1, -0.5); glVertex3f(1, 1, -0.5); glVertex3f(-1, 1, -0.5); glEnd(); shaders.select_shader(-1); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindTexture(GL_TEXTURE_2D, ssao_texture); glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); //Blur the SSAO texture in X direction glViewport(0, 0, viewport_width, viewport_height); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frame_buffer_object); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, blurred_ssao_texture_x, 0); check_frame_buffer(); glClearColor(0.f, 0.f, 0.f, 0.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaders.select_shader(GAUSSIAN_X); glActiveTexture(GL_TEXTURE0); bind_ssao_texture(); program = shaders.get_program_id(GAUSSIAN_X); sampler_reference = glGetUniformLocation(program, "sampler"); glUniform1i(sampler_reference, 0); viewport_width_reference = glGetUniformLocation(program, "viewport_width"); glUniform1f(viewport_width_reference, viewport_width); viewport_height_reference = glGetUniformLocation(program, "viewport_height"); glUniform1f(viewport_height_reference, viewport_height); projection_location = glGetUniformLocation(program, "projection"); glUniformMatrix4fv(projection_location, 1, GL_FALSE, &projection[0][0]); view_location = glGetUniformLocation(program, "view"); glUniformMatrix4fv(view_location, 1, GL_FALSE, &view[0][0]); glColor3f(1.0, 1.0, 1.0); glBegin(GL_QUADS); glVertex3f(-1, -1, -0.5); glVertex3f(1, -1, -0.5); glVertex3f(1, 1, -0.5); glVertex3f(-1, 1, -0.5); glEnd(); shaders.select_shader(-1); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindTexture(GL_TEXTURE_2D, blurred_ssao_texture_x); glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); //Blur the SSAO texture in Y direction glViewport(0, 0, viewport_width, viewport_height); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frame_buffer_object); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, blurred_ssao_texture_xy, 0); check_frame_buffer(); glClearColor(0.f, 0.f, 0.f, 0.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaders.select_shader(GAUSSIAN_Y); glActiveTexture(GL_TEXTURE0); bind_blurred_ssao_texture_x(); program = shaders.get_program_id(GAUSSIAN_Y); sampler_reference = glGetUniformLocation(program, "sampler"); glUniform1i(sampler_reference, 0); viewport_width_reference = glGetUniformLocation(program, "viewport_width"); glUniform1f(viewport_width_reference, viewport_width); viewport_height_reference = glGetUniformLocation(program, "viewport_height"); glUniform1f(viewport_height_reference, viewport_height); projection_location = glGetUniformLocation(program, "projection"); glUniformMatrix4fv(projection_location, 1, GL_FALSE, &projection[0][0]); view_location = glGetUniformLocation(program, "view"); glUniformMatrix4fv(view_location, 1, GL_FALSE, &view[0][0]); glColor3f(1.0, 1.0, 1.0); glBegin(GL_QUADS); glVertex3f(-1, -1, -0.5); glVertex3f(1, -1, -0.5); glVertex3f(1, 1, -0.5); glVertex3f(-1, 1, -0.5); glEnd(); shaders.select_shader(-1); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindTexture(GL_TEXTURE_2D, blurred_ssao_texture_xy); glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); }
Matrix4D Matrix4D::operator * ( const float s ) const { return Matrix4D( s*m[0], s*m[1], s*m[2], s*m[3] ); }
Matrix4D Matrix4D::operator - ( const Matrix4D& n ) const { return Matrix4D( m[0]-n[0], m[1]-n[1], m[2]-n[2], m[3]-n[3] ); }
Matrix4D Matrix4D::operator + ( const Matrix4D& n ) const { return Matrix4D( m[0]+n[0], m[1]+n[1], m[2]+n[2], m[3]+n[3] ); }