/* ================ 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; }
/* ** RB_DrawSun */ void RB_DrawSun( float scale, shader_t *shader ) { float size; float dist; vec3_t origin, vec1, vec2; if ( !backEnd.skyRenderedThisView ) { return; } //qglLoadMatrixf( backEnd.viewParms.world.modelMatrix ); //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 translation, modelview; Mat4Translation( backEnd.viewParms.or.origin, translation ); Mat4Multiply( backEnd.viewParms.world.modelMatrix, translation, modelview ); GL_SetModelviewMatrix( modelview ); } dist = backEnd.viewParms.zFar / 1.75; // div sqrt(3) size = dist * scale; VectorScale( tr.sunDirection, dist, origin ); PerpendicularVector( vec1, tr.sunDirection ); CrossProduct( tr.sunDirection, vec1, vec2 ); VectorScale( vec1, size, vec1 ); VectorScale( vec2, size, vec2 ); // farthest depth range qglDepthRange( 1.0, 1.0 ); RB_BeginSurface( shader, 0, 0 ); RB_AddQuadStamp(origin, vec1, vec2, colorWhite); RB_EndSurface(); // back to normal depth range qglDepthRange( 0.0, 1.0 ); }
void GL_SetModelviewMatrix(mat4_t matrix) { Mat4Copy(matrix, glState.modelview); Mat4Multiply(glState.projection, glState.modelview, glState.modelviewProjection); }
/* ============== RB_DrawSun (SA) FIXME: sun should render behind clouds, so passing dark areas cover it up ============== */ void RB_DrawSun( float scale, shader_t *shader ) { float size; float dist; vec3_t origin, vec1, vec2; vec3_t temp; // vec4_t color; if ( !shader ) { return; } if ( !backEnd.skyRenderedThisView ) { return; } //qglLoadMatrixf( backEnd.viewParms.world.modelMatrix ); //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 translation, modelview; Mat4Translation( backEnd.viewParms.or.origin, translation ); Mat4Multiply( backEnd.viewParms.world.modelMatrix, translation, modelview ); GL_SetModelviewMatrix( modelview ); } dist = backEnd.viewParms.zFar / 1.75; // div sqrt(3) // (SA) shrunk the size of the sun size = dist * scale; VectorScale( tr.sunDirection, dist, origin ); PerpendicularVector( vec1, tr.sunDirection ); CrossProduct( tr.sunDirection, vec1, vec2 ); VectorScale( vec1, size, vec1 ); VectorScale( vec2, size, vec2 ); // farthest depth range qglDepthRange( 1.0, 1.0 ); RB_BeginSurface( shader, 0, 0 ); // color[0] = color[1] = color[2] = color[3] = 1; RB_AddQuadStamp(origin, vec1, vec2, colorWhite); RB_EndSurface(); if ( r_drawSun->integer > 1 ) { // draw flare effect // (SA) FYI: This is cheezy and was only a test so far. // If we decide to use the flare business I will /definatly/ improve all this // get a point a little closer dist = dist * 0.7; VectorScale( tr.sunDirection, dist, origin ); // and make the flare a little smaller VectorScale( vec1, 0.5f, vec1 ); VectorScale( vec2, 0.5f, vec2 ); // add the vectors to give an 'off angle' result VectorAdd( tr.sunDirection, backEnd.viewParms.or.axis[0], temp ); VectorNormalize( temp ); // amplify the result origin[0] += temp[0] * 500.0; origin[1] += temp[1] * 500.0; origin[2] += temp[2] * 500.0; // (SA) FIXME: todo: flare effect should render last (on top of everything else) and only when sun is in view (sun moving out of camera past degree n should start to cause flare dimming until view angle to sun is off by angle n + x. // draw the flare RB_BeginSurface( tr.sunflareShader_old[0], 0, 0 ); RB_AddQuadStamp( origin, vec1, vec2, colorWhite ); RB_EndSurface(); } // back to normal depth range qglDepthRange( 0.0, 1.0 ); }
/* ================ 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; }