/* ================ RB_StageIteratorSky All of the visible sky triangles are in tess Other things could be stuck in here, like birds in the sky, etc ================ */ void RB_StageIteratorSky( void ) { if ( r_fastsky->integer ) { return; } // go through all the polygons and project them onto // the sky box to see which blocks on each side need // to be drawn RB_ClipSkyPolygons( &tess ); // r_showsky will let all the sky blocks be drawn in // front of everything to allow developers to see how // much sky is getting sucked in if ( r_showsky->integer ) { qglDepthRange( 0.0, 0.0 ); } else { qglDepthRange( 1.0, 1.0 ); } // draw the outer skybox if ( tess.shader->sky.outerbox[0] && tess.shader->sky.outerbox[0] != tr.defaultImage ) { mat4_t oldmodelview; GL_State( 0 ); //qglTranslatef (backEnd.viewParms.or.origin[0], backEnd.viewParms.or.origin[1], backEnd.viewParms.or.origin[2]); { // FIXME: this could be a lot cleaner mat4_t trans, product; Mat4Copy( glState.modelview, oldmodelview ); Mat4Translation( backEnd.viewParms.or.origin, trans ); Mat4Multiply( glState.modelview, trans, product ); GL_SetModelviewMatrix( product ); } DrawSkyBox( tess.shader ); GL_SetModelviewMatrix( oldmodelview ); } // generate the vertexes for all the clouds, which will be drawn // by the generic shader routine R_BuildCloudData( &tess ); RB_StageIteratorGeneric(); // draw the inner skybox // back to normal depth range qglDepthRange( 0.0, 1.0 ); // note that sky was drawn so we will draw a sun later backEnd.skyRenderedThisView = qtrue; }
void GLSL_SetUniformMat4(shaderProgram_t *program, int uniformNum, const mat4_t matrix) { GLint *uniforms = program->uniforms; vec_t *compare = (float *)(program->uniformBuffer + program->uniformBufferOffsets[uniformNum]); if (uniforms[uniformNum] == -1) return; if (uniformsInfo[uniformNum].type != GLSL_MAT16) { ri.Printf( PRINT_WARNING, "GLSL_SetUniformMat4: wrong type for uniform %i in program %s\n", uniformNum, program->name); return; } if (Mat4Compare(matrix, compare)) { return; } Mat4Copy(matrix, compare); qglUniformMatrix4fvARB(uniforms[uniformNum], 1, GL_FALSE, matrix); }
/* ================== RB_RenderFlares Because flares are simulating an occular effect, they should be drawn after everything (all views) in the entire frame has been drawn. Because of the way portals use the depth buffer to mark off areas, the needed information would be lost after each view, so we are forced to draw flares after each view. The resulting artifact is that flares in mirrors or portals don't dim properly when occluded by something in the main view, and portal flares that should extend past the portal edge will be overwritten. ================== */ void RB_RenderFlares (void) { flare_t *f; flare_t **prev; qboolean draw; mat4_t oldmodelview, oldprojection, matrix; if ( !r_flares->integer ) { return; } if(r_flareCoeff->modified) { R_SetFlareCoeff(); r_flareCoeff->modified = qfalse; } // Reset currentEntity to world so that any previously referenced entities // don't have influence on the rendering of these flares (i.e. RF_ renderer flags). backEnd.currentEntity = &tr.worldEntity; backEnd.or = backEnd.viewParms.world; // (SA) turned light flares back on. must evaluate problem id had with this RB_AddDlightFlares(); RB_AddCoronaFlares(); // perform z buffer readback on each flare in this view draw = qfalse; prev = &r_activeFlares; while ( ( f = *prev ) != NULL ) { // throw out any flares that weren't added last frame if ( f->addedFrame < backEnd.viewParms.frameCount - 1 ) { *prev = f->next; f->next = r_inactiveFlares; r_inactiveFlares = f; continue; } // don't draw any here that aren't from this scene / portal f->drawIntensity = 0; if ( f->frameSceneNum == backEnd.viewParms.frameSceneNum && f->inPortal == backEnd.viewParms.isPortal ) { RB_TestFlare( f ); if ( f->drawIntensity ) { draw = qtrue; } else { // this flare has completely faded out, so remove it from the chain *prev = f->next; f->next = r_inactiveFlares; r_inactiveFlares = f; continue; } } prev = &f->next; } if ( !draw ) { return; // none visible } if ( backEnd.viewParms.isPortal ) { qglDisable (GL_CLIP_PLANE0); } Mat4Copy(glState.projection, oldprojection); Mat4Copy(glState.modelview, oldmodelview); Mat4Identity(matrix); GL_SetModelviewMatrix(matrix); Mat4Ortho( backEnd.viewParms.viewportX, backEnd.viewParms.viewportX + backEnd.viewParms.viewportWidth, backEnd.viewParms.viewportY, backEnd.viewParms.viewportY + backEnd.viewParms.viewportHeight, -99999, 99999, matrix ); GL_SetProjectionMatrix(matrix); for ( f = r_activeFlares ; f ; f = f->next ) { if ( f->frameSceneNum == backEnd.viewParms.frameSceneNum && f->inPortal == backEnd.viewParms.isPortal && f->drawIntensity ) { RB_RenderFlare( f ); } } GL_SetProjectionMatrix(oldprojection); GL_SetModelviewMatrix(oldmodelview); }
void GL_SetModelviewMatrix(mat4_t matrix) { Mat4Copy(matrix, glState.modelview); Mat4Multiply(glState.projection, glState.modelview, glState.modelviewProjection); }
/* @@@@@@@@@@@@@@@@@@@@@ RE_RenderScene Draw a 3D view into a part of the window, then return to 2D drawing. Rendering a scene may require multiple views to be rendered to handle mirrors, @@@@@@@@@@@@@@@@@@@@@ */ void RE_RenderScene( const refdef_t *fd ) { viewParms_t parms; int startTime; if ( !tr.registered ) { return; } GLimp_LogComment( "====== RE_RenderScene =====\n" ); if ( r_norefresh->integer ) { return; } startTime = ri.RealMilliseconds(); if (!tr.world && !( fd->rdflags & RDF_NOWORLDMODEL ) ) { ri.Error (ERR_DROP, "R_RenderScene: NULL worldmodel"); } RE_BeginScene(fd); // SmileTheory: playing with shadow mapping if (!( fd->rdflags & RDF_NOWORLDMODEL ) && tr.refdef.num_dlights && r_dlightMode->integer >= 2) { R_RenderDlightCubemaps(fd); } /* playing with more shadows */ if(glRefConfig.framebufferObject && !( fd->rdflags & RDF_NOWORLDMODEL ) && r_shadows->integer == 4) { R_RenderPshadowMaps(fd); } // playing with even more shadows if(glRefConfig.framebufferObject && r_sunlightMode->integer && !( fd->rdflags & RDF_NOWORLDMODEL ) && (r_forceSun->integer || tr.sunShadows)) { if (r_shadowCascadeZFar->integer != 0) { R_RenderSunShadowMaps(fd, 0); R_RenderSunShadowMaps(fd, 1); R_RenderSunShadowMaps(fd, 2); } else { Mat4Zero(tr.refdef.sunShadowMvp[0]); Mat4Zero(tr.refdef.sunShadowMvp[1]); Mat4Zero(tr.refdef.sunShadowMvp[2]); } // only rerender last cascade if sun has changed position if (r_forceSun->integer == 2 || !VectorCompare(tr.refdef.sunDir, tr.lastCascadeSunDirection)) { VectorCopy(tr.refdef.sunDir, tr.lastCascadeSunDirection); R_RenderSunShadowMaps(fd, 3); Mat4Copy(tr.refdef.sunShadowMvp[3], tr.lastCascadeSunMvp); } else { Mat4Copy(tr.lastCascadeSunMvp, tr.refdef.sunShadowMvp[3]); } } // playing with cube maps // this is where dynamic cubemaps would be rendered if (0) //(glRefConfig.framebufferObject && !( fd->rdflags & RDF_NOWORLDMODEL )) { int i, j; for (i = 0; i < tr.numCubemaps; i++) { for (j = 0; j < 6; j++) { R_RenderCubemapSide(i, j, qtrue); } } } // setup view parms for the initial view // // set up viewport // The refdef takes 0-at-the-top y coordinates, so // convert to GL's 0-at-the-bottom space // Com_Memset( &parms, 0, sizeof( parms ) ); parms.viewportX = tr.refdef.x; parms.viewportY = glConfig.vidHeight - ( tr.refdef.y + tr.refdef.height ); parms.viewportWidth = tr.refdef.width; parms.viewportHeight = tr.refdef.height; parms.isPortal = qfalse; parms.fovX = tr.refdef.fov_x; parms.fovY = tr.refdef.fov_y; parms.stereoFrame = tr.refdef.stereoFrame; VectorCopy( fd->vieworg, parms.or.origin ); VectorCopy( fd->viewaxis[0], parms.or.axis[0] ); VectorCopy( fd->viewaxis[1], parms.or.axis[1] ); VectorCopy( fd->viewaxis[2], parms.or.axis[2] ); VectorCopy( fd->vieworg, parms.pvsOrigin ); if(!( fd->rdflags & RDF_NOWORLDMODEL ) && r_depthPrepass->value && ((r_forceSun->integer) || tr.sunShadows)) { parms.flags = VPF_USESUNLIGHT; } R_RenderView( &parms ); if(!( fd->rdflags & RDF_NOWORLDMODEL )) R_AddPostProcessCmd(); RE_EndScene(); tr.frontEndMsec += ri.RealMilliseconds() - startTime; }
/* ================ RB_StageIteratorSky All of the visible sky triangles are in tess Other things could be stuck in here, like birds in the sky, etc ================ */ void RB_StageIteratorSky( void ) { if ( r_fastsky->integer ) { return; } // when portal sky exists, only render skybox for the portal sky scene if ( skyboxportal && !( backEnd.refdef.rdflags & RDF_SKYBOXPORTAL ) ) { return; } // does the current fog require fastsky? if ( backEnd.viewParms.glFog.registered ) { if ( !backEnd.viewParms.glFog.drawsky ) { return; } } else if ( glfogNum > FOG_NONE ) { if ( !glfogsettings[FOG_CURRENT].drawsky ) { return; } } backEnd.refdef.rdflags |= RDF_DRAWINGSKY; // go through all the polygons and project them onto // the sky box to see which blocks on each side need // to be drawn RB_ClipSkyPolygons( &tess ); // r_showsky will let all the sky blocks be drawn in // front of everything to allow developers to see how // much sky is getting sucked in if ( r_showsky->integer ) { qglDepthRange( 0.0, 0.0 ); } else { qglDepthRange( 1.0, 1.0 ); } // draw the outer skybox if ( tess.shader->sky.outerbox[0] && tess.shader->sky.outerbox[0] != tr.defaultImage ) { mat4_t oldmodelview; GL_State( 0 ); //qglTranslatef( backEnd.viewParms.or.origin[0], backEnd.viewParms.or.origin[1], backEnd.viewParms.or.origin[2] ); { // FIXME: this could be a lot cleaner mat4_t trans, product; Mat4Copy( glState.modelview, oldmodelview ); Mat4Translation( backEnd.viewParms.or.origin, trans ); Mat4Multiply( glState.modelview, trans, product ); GL_SetModelviewMatrix( product ); } DrawSkyBox( tess.shader ); GL_SetModelviewMatrix( oldmodelview ); } // generate the vertexes for all the clouds, which will be drawn // by the generic shader routine R_BuildCloudData( &tess ); RB_StageIteratorGeneric(); // draw the inner skybox // Rafael - drawing inner skybox if ( tess.shader->sky.innerbox[0] && tess.shader->sky.innerbox[0] != tr.defaultImage ) { mat4_t oldmodelview; GL_State( 0 ); //qglTranslatef( backEnd.viewParms.or.origin[0], backEnd.viewParms.or.origin[1], backEnd.viewParms.or.origin[2] ); { // FIXME: this could be a lot cleaner mat4_t trans, product; Mat4Copy( glState.modelview, oldmodelview ); Mat4Translation( backEnd.viewParms.or.origin, trans ); Mat4Multiply( glState.modelview, trans, product ); GL_SetModelviewMatrix( product ); } DrawSkyBoxInner( tess.shader ); GL_SetModelviewMatrix( oldmodelview ); } // Rafael - end // back to normal depth range qglDepthRange( 0.0, 1.0 ); backEnd.refdef.rdflags &= ~RDF_DRAWINGSKY; // note that sky was drawn so we will draw a sun later backEnd.skyRenderedThisView = qtrue; }