void GLWidget::paintGL() { //Clear the buffers gbuffer.startFrame(); //Draw the sky drawSkyBox(); //Render the Textures for DeferredShading DSGeometryPass(); //Shadow map pass. Render them and blur shadowMapsPass(); //Use of the Textures to Render to the Magic Quad DSLightPass(); getSceneIntensity(); blurIntensity(); paintSceneToCanvas(); }
void ParticleRenderer::display() { if (b_renderSkyBox){ drawSkyBox(); } if (b_renderFloor){ drawFloor(); } switch (_displayMode) { case PARTICLE_POINTS: { glColor3f(1, 1, 1); glPointSize(1.0f); _drawPoints(); } break; case PARTICLE_FIRE: { glPointSize(4.0f); float m_baseColor[4] = { 0.6f, 0.1f, 0.0f, 0.95f}; glColor4f(m_baseColor[0],m_baseColor[1],m_baseColor[2],m_baseColor[3]); glEnable (GL_POINT_SMOOTH); glHint (GL_POINT_SMOOTH_HINT, GL_NICEST); glAlphaFunc(GL_GREATER, 0.1); glEnable(GL_ALPHA_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_BLEND); glDepthMask(GL_FALSE); // Disable depth buffer updating! (Integral to transparency!) _drawPoints(false); glDepthMask(GL_TRUE); glDisable(GL_BLEND); glDisable(GL_ALPHA_TEST); } break; case SPRITE_COSMOS: { glEnable(GL_POINT_SPRITE_ARB); // setup point sprites glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_NV); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_BLEND); glDepthMask(GL_FALSE); glUseProgram(m_program_cosmos); GLuint texLoc = glGetUniformLocation(m_program_cosmos, "splatTexture"); glUniform1i(texLoc, 0); glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, m_texture); glColor3f(1, 1, 1); glPointSize(m_particleRadius*2.0f); //float m_baseColor[4] = {0.6f, 0.1f, 0.0f, 0.95f}; float m_baseColor[4] = { 1.0f, 0.6f, 0.3f, 0.20f}; // nbody fp32 color (yellow) //float m_baseColor[4] = { 0.4f, 0.8f, 0.1f, 1.0f}; // nbody fp64 color (green) glSecondaryColor3fv(m_baseColor); _drawPoints(); glUseProgram(0); glDisable(GL_POINT_SPRITE_ARB); glDisable(GL_BLEND); glDepthMask(GL_TRUE); } break; default: case PARTICLE_SPHERES: { glEnable(GL_POINT_SPRITE_ARB); glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_NV); glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); glUseProgram(m_program_sphere); glUniform1f( glGetUniformLocation(m_program_sphere, "pointScale"), m_window_h / tanf(m_fov*0.5f*(float)M_PI/180.0f) ); glUniform1f( glGetUniformLocation(m_program_sphere, "pointRadius"), m_particleRadius ); glColor3f(1, 1, 1); _drawPoints(); glUseProgram(0); glDisable(GL_POINT_SPRITE_ARB); } break; } }
// Draws the map void BSPMap::draw( LPDIRECT3DDEVICE9 device, Camera *camera, DrawingInfo *drawInfo ) { /** * Here's how the data is laid out of rendering: * FaceInfo has a vertex buffer that is a set of polygons. * A bsp face has an index into the vertex buffer. * A bsp leaf has a set of bsp faces that it draws. A leaf also has data for * determining whether or not its faces are visible within a viewing * frustum. If not visible, then none of the faces are drawn. * Leaves are grouped into clusters. Clusters control which of the other * clusters should be drawn based on which cluster the camera is in. * Clusters are the final tier of drawing information. */ // The array of clusters vector< BSP::Cluster > *clusters = bspTree->getClusters(); // This array is for determining which leaf to use for frustum culling vector< vector< BSP::Leaf * > > *clusterLeaves = bspTree->getClusterLeaves(); // The visibility state of each cluster, found by traversing the BSP Tree // with the camera's position. BitVector *visState = bspTree->getVisState( camera ); // Set the Fixed Vertex Format (FVF) to the BSP FVF device->SetFVF( BSP_FVF ); // Set the vertex buffer used by Direct3D to the vertex buffer with all of // the map vertex information in it. device->SetStreamSource( 0, faceInfo->getVertexBuffer(), 0, sizeof( D3D::Vertex ) ); // Special variables for using the map's pixel shader UINT Pass, Passes; // Setup backface culling (so polygons that are facing away from you aren't drawn) device->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW ); // Set the useLightMap variable in the Pixel Shader mapShader->getEffect()->SetInt( "useLightMap", lMap ); // The variables for how many polgons were drawn or culled. int totalPolygons = faceInfo->getNumVertices() / 3; int polygonsDrawn = 0; int numPVSCulled = 0; int numFrustumCulled = 0; D3DXMATRIX world; D3DXMATRIX view; D3DXMATRIX proj; device->GetTransform( D3DTS_WORLD, &world ); device->GetTransform( D3DTS_VIEW, &view ); device->GetTransform( D3DTS_PROJECTION, &proj ); mapShader->getEffect()->SetMatrix( "worldViewProj", &( world * view * proj ) ); mapShader->getEffect()->SetMatrix( "world", &( world ) ); mapShader->getEffect()->SetMatrix( "view", &( view ) ); mapShader->getEffect()->SetMatrix( "proj", &( proj ) ); mapShader->getEffect()->SetFloat( "camPosX", -camera->pos->x ); mapShader->getEffect()->SetFloat( "camPosY", -camera->pos->y ); mapShader->getEffect()->SetFloat( "camPosZ", -camera->pos->z ); vsTest += 0.1; mapShader->getEffect()->SetFloat( "vsTest", vsTest ); mapShader->getEffect()->SetTexture( "modelTexture", ddsTexture ); mapShader->getEffect()->SetTexture( "modelTexture", texInfo->getMegaTexture() ); // draw the map with the pixel shader /*mapShader->getEffect()->Begin( &Passes, 0 ); for ( Pass = 0; Pass < Passes; Pass++ ) { mapShader->getEffect()->BeginPass( Pass ); mapShader->getEffect()->SetInt( "useLightMap", 1 ); device->DrawPrimitive( D3DPT_TRIANGLELIST, 0, faceInfo->getNumVertices() / 3 ); mapShader->getEffect()->EndPass(); } mapShader->getEffect()->End(); */ // make sure lightmaps are enabled //mapShader->getEffect()->SetInt( "useLightMap", lMap ); // Add in the number of polygons drawn //polygonsDrawn += ( faceInfo->getFaceStartIndex( i + 1 ) - faceInfo->getFaceStartIndex( i ) ) / 3; /** * This block is simply for drawing the map's polygons, while making sure no * polygons are drawn when they don't need to be drawn. */ // For each cluster, for ( unsigned int c = 0; c < clusters->size(); ++c ) { // If the cluster is visible, if ( visState->getData( c ) ) { // If it is, for each leaf in that cluster, for ( unsigned int l = 0; l < ( *clusters )[ c ].size(); ++l ) { // Is that leaf within the viewing frustum? if ( camera->leafInFrustum( ( *clusterLeaves )[ c ][ l ] ) ) { // If it is, then draw the faces in that leaf // For each face in that leaf for ( unsigned int f = 0; f < ( *clusters )[ c ][ l ].size(); ++f ) { int i = ( *clusters )[ c ][ l ][ f ]; // If it's not a skybox, then draw it. if ( !texInfo->getTexture( faceInfo->getTextureNum( i ) )->isSkyBox ) { // Setup the lightmap and texture for the pixel shader mapShader->getEffect()->SetTexture( "modelTexture", texInfo->getTexture( faceInfo->getTextureNum( i ) )->getTexture() ); //mapShader->getEffect()->SetTexture( "modelTexture", texInfo->getMegaTexture() ); //mapShader->getEffect()->SetTexture( "modelTexture", ddsTexture ); mapShader->getEffect()->SetTexture( "lightMap", lightMaps->getTexture( i ) ); //mapShader->getEffect()->SetTexture( "normalMap", normalMap );