void SDRender::UpdateFogColor(double sol_angle) { double rotation; // first determine the difference between our view angle and local // direction to the sun rotation = -(thesky->getSR() + SD_PI); while ( rotation < 0 ) { rotation += SD_2PI; } while ( rotation > SD_2PI ) { rotation -= SD_2PI; } // revert to unmodified values before usign them. // osg::Vec4f sun_color = thesky->get_sun_color(); sd_gamma_correct_rgb( BaseFogColor._v ); // Calculate the fog color in the direction of the sun for // sunrise/sunset effects. float s_red = (BaseFogColor._v[0] + 2 * sun_color._v[0] * sun_color._v[0]) / 3; float s_green = (BaseFogColor._v[1] + 2 * sun_color._v[1] * sun_color._v[1]) / 3; float s_blue = (BaseFogColor._v[2] + 2 * sun_color._v[2] * sun_color._v[2]) / 3; // interpolate beween the sunrise/sunset color and the color // at the opposite direction of this effect. Take in account // the current visibility. float av = thesky->get_visibility(); if (av > 45000) av = 45000; float avf = 0.87 - (45000 - av) / 83333.33; float sif = 0.5 - cos( sol_angle * 2)/2; if (sif < 1e-4) sif = 1e-4; float rf1 = fabs((rotation - SD_PI) / SD_PI); // 0.0 .. 1.0 float rf2 = avf * pow(rf1 * rf1, 1 /sif); float rf3 = 0.94 - rf2; FogColor._v[0] = rf3 * BaseFogColor._v[0] + rf2 * s_red; FogColor._v[1] = rf3 * BaseFogColor._v[1] + rf2 * s_green; FogColor._v[2] = rf3 * BaseFogColor._v[2] + rf2 * s_blue; sd_gamma_correct_rgb( FogColor._v ); // make sure the colors have their original value before they are being // used by the rest of the program. sd_gamma_correct_rgb( BaseFogColor._v ); }
bool SDMoon::repaint( double moon_angle ) { if (prev_moon_angle == moon_angle) return true; prev_moon_angle = moon_angle; float moon_factor = 4*cos(moon_angle); if (moon_factor > 1) moon_factor = 1.0; if (moon_factor < -1) moon_factor = -1.0; moon_factor = (moon_factor/2) + 0.5f; osg::Vec4 color; color[1] = sqrt(moon_factor); color[0] = sqrt(color[1]); color[2] = moon_factor * moon_factor; color[2] *= color[2]; color[3] = 1.0; sd_gamma_correct_rgb( color._v ); orb_material->setDiffuse(osg::Material::FRONT_AND_BACK, color); return true; }
void SDRender::UpdateLight( void ) { sol_angle = (float)thesky->getSA(); moon_angle = (float)thesky->getMA(); sky_brightness = (float)(1.0 + cos(sol_angle)) / 2.0f; if (SDTrack->local.rain > 0) { BaseFogColor = osg::Vec3f(0.42f, 0.44f, 0.50f); sky_brightness = (float)pow(sky_brightness, 0.5f); } else { BaseFogColor = osg::Vec3f(0.84f, 0.87f, 1.00f); } SkyColor = BaseSkyColor * sky_brightness; UpdateFogColor(sol_angle); sd_gamma_correct_rgb( SkyColor._v ); // 3a)cloud and fog color CloudsColor = FogColor = BaseFogColor * sky_brightness; //UpdateFogColor(sol_angle); sd_gamma_correct_rgb( CloudsColor._v ); osg::Vec4f suncolor = thesky->get_sun_color(); osg::Vec3f sun_color = osg::Vec3f(suncolor._v[0], suncolor._v[1], suncolor._v[2]); if (sol_angle > 1.0) { if (SDVisibility > 1000 /*&& cloudsTextureIndex < 8*/) { CloudsColor = osg::componentMultiply(CloudsColor, sun_color); } else { CloudsColor = CloudsColor * sun_color[0]; } } sd_gamma_correct_rgb( CloudsColor._v ); // 3b) repaint the sky (simply update geometrical, color, ... state, no actual redraw) thesky->repaint(SkyColor, FogColor, CloudsColor, sol_angle, moon_angle, NPlanets, APlanetsData, NStars, AStarsData); // 3c) update scene colors. if (SDVisibility > 1000 /*&& cloudsTextureIndex < 8*/) { SceneAmbiant = osg::Vec4f((sun_color * 0.25f) + (CloudsColor * 0.75f) * sky_brightness, 1.0f); SceneDiffuse = osg::Vec4f((sun_color * 0.25f) + (FogColor * 0.75f) * sky_brightness, 1.0f); SceneSpecular = osg::Vec4f(sun_color * sky_brightness, 1.0f); } else { SceneAmbiant = osg::Vec4f(((CloudsColor._v[0] * 0.75f) + (sun_color._v[0] * 0.25f)) * sky_brightness, ((CloudsColor._v[1] * 0.75f) + (sun_color._v[0] * 0.25f)) * sky_brightness, ((CloudsColor._v[2] * 0.75f) + (sun_color._v[0] * 0.25f)) * sky_brightness, 1.0f); SceneDiffuse = osg::Vec4f(((FogColor._v[0] * 0.75f) + (sun_color._v[0] * 0.25f)) * sky_brightness, ((FogColor._v[1] * 0.75f) + (sun_color._v[0] * 0.25f)) * sky_brightness, ((FogColor._v[2] * 0.75f) + (sun_color._v[0] * 0.25f)) * sky_brightness, 1.0f); SceneSpecular = osg::Vec4f(sun_color._v[0] * sky_brightness, sun_color._v[0] * sky_brightness, sun_color._v[0] * sky_brightness, 1.0f); } }//grUpdateLight