glClearColor( 0.75f, 0.75f, 1.0f, 1.0f );
glClearDepth( 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
MatrixStack modelMatrix = new MatrixStack();
modelMatrix.setMatrix( viewPole.calcMatrix() );
final Mat4 worldToCamMat = modelMatrix.top();
LightBlock lightData = new LightBlock();
lightData.ambientIntensity = new Vec4( 0.2f, 0.2f, 0.2f, 1.0f );
float halfLightDistance = 25.0f;
float lightAttenuation = 1.0f / (halfLightDistance * halfLightDistance);
lightData.lightAttenuation = lightAttenuation;
Vec3 globalLightDirection = new Vec3( 0.707f, 0.707f, 0.0f );
lightData.lights[0] = new PerLight();
lightData.lights[0].cameraSpaceLightPos = Mat4.mul( worldToCamMat, new Vec4( globalLightDirection, 0.0f ) );
lightData.lights[0].lightIntensity = new Vec4( 0.6f, 0.6f, 0.6f, 1.0f );
lightData.lights[1] = new PerLight();
lightData.lights[1].cameraSpaceLightPos = Mat4.mul( worldToCamMat, calcLightPosition() );
lightData.lights[1].lightIntensity = new Vec4( 0.4f, 0.4f, 0.4f, 1.0f );
glBindBuffer( GL_UNIFORM_BUFFER, lightUniformBuffer );
glBufferSubData( GL_UNIFORM_BUFFER, 0, lightData.fillAndFlipBuffer( lightBlockBuffer ) );
glBindBuffer( GL_UNIFORM_BUFFER, 0 );
{
Mesh pMesh = useInfinity ? objectMesh : planeMesh;
glBindBufferRange( GL_UNIFORM_BUFFER, materialBlockIndex, materialUniformBuffer,
currMaterial * materialOffset, MaterialBlock.SIZE );
modelMatrix.push();
modelMatrix.applyMatrix( objtPole.calcMatrix() );
modelMatrix.scale( useInfinity ? 2.0f : 4.0f );
Mat3 normMatrix = new Mat3( modelMatrix.top() );
normMatrix = Glm.transpose( Glm.inverse( normMatrix ) );
ProgramData prog = programs[shaderMode.ordinal()];
glUseProgram( prog.theProgram );
glUniformMatrix4( prog.modelToCameraMatrixUnif, false, modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
glUniformMatrix3( prog.normalModelToCameraMatrixUnif, false, normMatrix.fillAndFlipBuffer( mat3Buffer ) );
glActiveTexture( GL_TEXTURE0 + gaussTexUnit );
glBindTexture( GL_TEXTURE_2D, gaussTextures[currTexture] );
glBindSampler( gaussTexUnit, textureSampler );
glActiveTexture( GL_TEXTURE0 + shineTexUnit );
glBindTexture( GL_TEXTURE_2D, shineTexture );
glBindSampler( shineTexUnit, textureSampler );
if ( shaderMode != ShaderMode.FIXED ) {
pMesh.render( "lit-tex" );
} else {
pMesh.render( "lit" );
}
glBindSampler( gaussTexUnit, 0 );
glBindTexture( GL_TEXTURE_2D, 0 );
glUseProgram( 0 );
glBindBufferBase( GL_UNIFORM_BUFFER, materialBlockIndex, 0 );
modelMatrix.pop();
}
if ( drawLights ) {
modelMatrix.push();
modelMatrix.translate( new Vec3( calcLightPosition() ) );
modelMatrix.scale( 0.25f );
glUseProgram( unlit.theProgram );
glUniformMatrix4( unlit.modelToCameraMatrixUnif, false, modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
Vec4 lightColor = new Vec4( 1.0f );
glUniform4( unlit.objectColorUnif, lightColor.fillAndFlipBuffer( vec4Buffer ) );
cubeMesh.render( "flat" );
modelMatrix.pop();
modelMatrix.translate( globalLightDirection.scale( 100.0f ) );
modelMatrix.scale( 5.0f );
glUniformMatrix4( unlit.modelToCameraMatrixUnif, false, modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
cubeMesh.render( "flat" );
glUseProgram( 0 );
}
if ( drawCameraPos ) {
modelMatrix.push();
modelMatrix.setIdentity();
modelMatrix.translate( new Vec3( 0.0f, 0.0f, -viewPole.getView().radius ) );
modelMatrix.scale( 0.25f );
glDisable( GL_DEPTH_TEST );
glDepthMask( false );
glUseProgram( unlit.theProgram );
glUniformMatrix4( unlit.modelToCameraMatrixUnif, false, modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
glUniform4f( unlit.objectColorUnif, 0.25f, 0.25f, 0.25f, 1.0f );
cubeMesh.render( "flat" );
glDepthMask( true );
glEnable( GL_DEPTH_TEST );
glUniform4f( unlit.objectColorUnif, 1.0f, 1.0f, 1.0f, 1.0f );
cubeMesh.render( "flat" );
modelMatrix.pop();
}
}