//---------------------------------------------------------------------------- void VolumeFog::CreateScene () { // Create a screen-space camera for the background image. mScreenCamera = ScreenTarget::CreateCamera(); // Create a screen polygon for the background image. VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0); mScreenPolygon = ScreenTarget::CreateRectangle(vformat, GetWidth(), GetHeight(), 0.0f, 1.0f, 0.0f, 1.0f, 1.0f); std::string skyName = Environment::GetPathR("BlueSky.wmtf"); Texture2D* skyTexture = Texture2D::LoadWMTF(skyName); Texture2DEffect* skyEffect = new0 Texture2DEffect(); mScreenPolygon->SetEffectInstance(skyEffect->CreateInstance(skyTexture)); // Create the scene graph for the terrain. mScene = new0 Node(); // Begin with a flat height field. vformat = VertexFormat::Create(3, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT4, 0, VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0); mMesh = StandardMesh(vformat).Rectangle(64, 64, 8.0f, 8.0f); mScene->AttachChild(mMesh); // Set the heights based on a precomputed height field. Also create a // texture image to go with the height field. std::string heightFieldName = Environment::GetPathR("HeightField.wmtf"); Texture2D* heightTexture = Texture2D::LoadWMTF(heightFieldName); unsigned char* data = (unsigned char*)heightTexture->GetData(0); Float4 white(1.0f, 1.0f, 1.0f, 0.0f); VertexBufferAccessor vba(mMesh); for (int i = 0; i < vba.GetNumVertices(); ++i) { unsigned char value = *data; float height = 3.0f*value/255.0f + 0.05f*Mathf::SymmetricRandom(); *data++ = (unsigned char)Mathf::IntervalRandom(32.0f, 64.0f); *data++ = 3*(128 - value/2)/4; *data++ = 0; *data++ = 255; vba.Position<Float3>(i)[2] = height; // The fog color is white. The alpha channel is filled in by the // function UpdateFog(). vba.Color<Float4>(0, i) = white; } UpdateFog(); std::string effectFile = Environment::GetPathR("VolumeFog.wmfx"); VolumeFogEffect* effect = new0 VolumeFogEffect(effectFile); mMesh->SetEffectInstance(effect->CreateInstance(heightTexture)); }
//---------------------------------------------------------------------------- void VolumeFog::OnIdle () { MeasureTime(); bool fogNeedsUpdate = false; if (MoveCamera()) { mCuller.ComputeVisibleSet(mScene); fogNeedsUpdate = true; } if (MoveObject()) { mScene->Update(); mCuller.ComputeVisibleSet(mScene); fogNeedsUpdate = true; } if (fogNeedsUpdate) { UpdateFog(); } if (mRenderer->PreDraw()) { mRenderer->ClearDepthBuffer(); // Draw fogged terrain. mRenderer->SetCamera(mCamera); mRenderer->Draw(mCuller.GetVisibleSet()); // Draw background image. mRenderer->SetCamera(mScreenCamera); mRenderer->Draw(mScreenPolygon); DrawFrameRate(8, GetHeight()-8, mTextColor); mRenderer->PostDraw(); mRenderer->DisplayColorBuffer(); } UpdateFrameCount(); }
void World::SetFarPlane_Fog( Event *ev ) { farplane_fog = ev->GetBoolean( 1 ); UpdateFog(); }
void World::SetFarPlane_Cull( Event *ev ) { farplane_cull = ev->GetBoolean( 1 ); UpdateFog(); }
void World::SetFarPlane_Color( Event *ev ) { farplane_color = ev->GetVector( 1 ); UpdateFog(); }
void World::SetFarPlane( Event *ev ) { farplane_distance = ev->GetFloat( 1 ); UpdateFog(); }
World::World() { const char *text; str mapname; int i; assert( this->entnum == ENTITYNUM_WORLD ); world = this; world_dying = false; setMoveType( MOVETYPE_NONE ); setSolidType( SOLID_BSP ); // world model is always index 1 edict->s.modelindex = 1; model = "*1"; turnThinkOn(); UpdateConfigStrings(); groupcoordinator = NULL; // Anything that modifies configstrings, or spawns things is ignored when loading savegames if ( LoadingSavegame ) { return; } // clear out the soundtrack from the last level ChangeSoundtrack( "" ); // set the default farplane parameters farplane_distance = 0; farplane_color = Vector(0, 0, 0); farplane_cull = true; farplane_fog = true; UpdateFog(); terrain_global = false; terrain_global_min = MIN_WORLD_COORD; UpdateTerrain(); entity_fade_dist = DEFAULT_ENTITY_FADE_DIST; UpdateEntityFadeDist(); UpdateDynamicLights(); UpdateWeather(); time_scale = 1.0f; sky_alpha = 1.0f; sky_portal = true; UpdateSky(); // // see if this is a cinematic level // level.cinematic = ( spawnflags & CINEMATIC ) ? true : false; if ( level.cinematic ) gi.cvar_set( "sv_cinematic", "1" ); else gi.cvar_set( "sv_cinematic", "0" ); level.nextmap = ""; level.level_name = level.mapname; // Set up the mapname as the default script mapname = "maps/"; mapname += level.mapname; for( i = mapname.length() - 1; i >= 0; i-- ) { if ( mapname[ i ] == '.' ) { mapname[ i ] = 0; break; } } mapname += ".scr"; text = &mapname[ 5 ]; // If there isn't a script with the same name as the map, then don't try to load script if ( gi.FS_ReadFile( mapname.c_str(), NULL, true ) != -1 ) { gi.DPrintf( "Adding script: '%s'\n", text ); // just set the script, we will start it in G_Spawn level.SetGameScript( mapname.c_str() ); } else { level.SetGameScript( "" ); } level.consoleThread = Director.CreateThread(); SoundMan.Init(); SoundMan.Load(); // Set the color for the blends. level.water_color = Vector( 0.0f, 0.0f, 0.5f ); level.water_alpha = 0.4f; level.slime_color = Vector( 0.2f, 0.4f, 0.2f ); level.slime_alpha = 0.6f; level.lava_color = Vector( 0.5f, 0.15f, 0.0f ); level.lava_alpha = 0.6f; // // set the targetname of the world // SetTargetName( "world" ); groupcoordinator = new GroupCoordinator; // Initialize movement info for ( i = 0 ; i < WORLD_PHYSICS_TOTAL_NUMBER ; i++ ) { _physicsInfo[ i ] = -1.0f; } _canShakeCamera = false; }
void World::Archive( Archiver &arc ) { int i; int num; TargetList *tempTargetList; Entity::Archive( arc ); if ( arc.Loading() ) { FreeTargetList(); } if ( arc.Saving() ) num = targetList.NumObjects(); arc.ArchiveInteger( &num ); for ( i = 1; i <= num; i++ ) { if ( arc.Saving() ) { tempTargetList = targetList.ObjectAt( i ); } else { tempTargetList = new TargetList; targetList.AddObject( tempTargetList ); } arc.ArchiveObject( ( Class * )tempTargetList ); } _brokenThings.Archive( arc ); _availableViewModes.Archive( arc ); arc.ArchiveBoolean( &world_dying ); arc.ArchiveString( &skipthread ); arc.ArchiveFloat( &farplane_distance ); arc.ArchiveVector( &farplane_color ); arc.ArchiveBoolean( &farplane_cull ); arc.ArchiveBoolean( &farplane_fog ); arc.ArchiveBoolean( &terrain_global ); arc.ArchiveFloat( &terrain_global_min ); arc.ArchiveFloat( &entity_fade_dist ); for( i = 0 ; i < MAX_LIGHTING_GROUPS ; i++ ) dynamic_lights[ i ].Archive( arc ); wind.Archive( arc ); weather.Archive( arc ); arc.ArchiveFloat( &time_scale ); arc.ArchiveFloat( &sky_alpha ); arc.ArchiveBoolean( &sky_portal ); for ( i = 0 ; i < WORLD_PHYSICS_TOTAL_NUMBER ; i++ ) { arc.ArchiveFloat( &_physicsInfo[ i ] ); } arc.ArchiveBool( &_canShakeCamera ); if ( arc.Loading() ) { UpdateConfigStrings(); UpdateFog(); UpdateTerrain(); UpdateSky(); UpdateDynamicLights(); UpdateWindDirection(); UpdateWindIntensity(); UpdateWeather(); UpdateTimeScale(); } // Archive groupcoordinator (not part of world but this is a good place) if ( arc.Loading() ) { if ( groupcoordinator ) delete groupcoordinator; groupcoordinator = new GroupCoordinator; } groupcoordinator->Archive( arc ); }
void CRenderPipeline::EnableFog( bool bEnable ) { m_FogEnable = bEnable; UpdateFog(); }