Compute normal vectors once in compute shader rather than every frame.Use a Z-fill pre-pass to reduce fragment shader work load.Use a floating point texture for more vertical resolution. ![]() Use a compute shader to generate terrain on demand as we move around the world.There are a number of improvements that could quite easily be made: Requirements for this example are Qt 5.1 alpha (or a recent build from the stable branch of git) and an OpenGL 4.0 capable system. The complete source code for this example is available at: Most of the rendering function is just setting uniform variables and could be replaced with the use of a uniform buffer. GlDrawArrays( GL_PATCHES, 0, m_patchCount ) Shader->setUniformValue( " material.shininess", 10.0f ) Shader->setUniformValue( " material.Ks" , Shader->setUniformValue( " material.Kd" , Shader->setUniformValue( " material.Ka" , Shader->setUniformValue( " light.intensity" , Shader->setUniformValue( " light.position", lightDirection ) QVector4D lightDirection = worldToEyeNormal * worldLightDirection QMatrix4x4 worldToEyeNormal( normalMatrix ) QVector4D worldLightDirection( sinf( m_sunTheta * degToRad ), Shader->setUniformValue( " mvp", mvp ) Shader->setUniformValue( " normalMatrix", normalMatrix ) Shader->setUniformValue( " worldNormalMatrix", worldNormalMatrix ) Shader->setUniformValue( " modelViewMatrix", modelViewMatrix ) ![]() Shader->setUniformValue( " modelMatrix", m_modelMatrix ) QMatrix4x4 mvp = m_camera->projectionMatrix() * modelViewMatrix QMatrix3x3 normalMatrix = modelViewMatrix.normalMatrix() QMatrix3x3 worldNormalMatrix = m_modelMatrix.normalMatrix() QMatrix4x4 modelViewMatrix = viewMatrix * m_modelMatrix QMatrix4x4 viewMatrix = m_camera->viewMatrix() Pass in the usual transformation matrices Shader->setUniformValue( " verticalScale", m_verticalScale ) Shader->setUniformValue( " horizontalScale", m_horizontalScale ) Set the horizontal and vertical scales applied Set the fragment shader display mode subroutine QOpenGLShaderProgramPtr shader = m_material->shader() GlClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) In fact the entire rendering function for this example is: void TerrainTessellationScene::render()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |