osg::StateSet* createSpotLightDecoratorState(unsigned int lightNum, unsigned int textureUnit) { osg::StateSet* stateset = new osg::StateSet; stateset->setMode(GL_LIGHT0+lightNum, osg::StateAttribute::ON); osg::Vec4 centerColour(1.0f,1.0f,1.0f,1.0f); osg::Vec4 ambientColour(0.05f,0.05f,0.05f,1.0f); // set up spot light texture osg::Texture2D* texture = new osg::Texture2D(); texture->setImage(createSpotLightImage(centerColour, ambientColour, 64, 1.0)); texture->setBorderColor(osg::Vec4(ambientColour)); texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_BORDER); texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_BORDER); texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_BORDER); stateset->setTextureAttributeAndModes(textureUnit, texture, osg::StateAttribute::ON); // set up tex gens stateset->setTextureMode(textureUnit, GL_TEXTURE_GEN_S, osg::StateAttribute::ON); stateset->setTextureMode(textureUnit, GL_TEXTURE_GEN_T, osg::StateAttribute::ON); stateset->setTextureMode(textureUnit, GL_TEXTURE_GEN_R, osg::StateAttribute::ON); stateset->setTextureMode(textureUnit, GL_TEXTURE_GEN_Q, osg::StateAttribute::ON); return stateset; }
void ChunkPhotographer::setStates( Chunk& chunk ) { //first, setup some rendering options. //we need to draw as cheaply as possible, and //not clobber the main pipeline. Waters::simulationEnabled(false); Waters::drawReflection(false); ChunkFlare::ignore( true ); EditorChunkLink::enableDraw( false ); EditorChunkStationNode::enableDraw( false ); PySplodge::s_ignoreSplodge_ = true; Rain::disable( true ); g_disableSkyLightMap = true; //save some states we are about to change oldFOV_ = Moo::rc().camera().fov(); savedLighting_ = Moo::rc().lightContainer(); savedChunkLighting_ = &ChunkManager::instance().cameraSpace()->enviro().timeOfDay()->lighting(); oldInvView_ = Moo::rc().invView(); //create some lighting if ( !lighting_ ) { Vector4 ambientColour( 0.08f,0.02f,0.1f,1.f ); //outside lighting for chunks chunkLighting_.sunTransform.setRotateX( DEG_TO_RAD(90.f) ); chunkLighting_.sunTransform.postRotateZ( DEG_TO_RAD(20.f) ); chunkLighting_.sunColour.set( 1.f, 1.f, 1.f, 1.f ); chunkLighting_.ambientColour = ambientColour; //light container for terrain Moo::DirectionalLightPtr spDirectional = new Moo::DirectionalLight( Moo::Colour(1,1,1,1), Vector3(0,0,-1.f) ); spDirectional->worldTransform( chunkLighting_.sunTransform ); lighting_ = new Moo::LightContainer; lighting_->ambientColour( Moo::Colour( ambientColour ) ); lighting_->addDirectional( spDirectional ); } Moo::rc().lightContainer( lighting_ ); //setup the correct transform for the given chunk. //adds of .25 is for the near clipping plane. std::vector<ChunkItemPtr> items; EditorChunkCache::instance(chunk).allItems( items ); BoundingBox bb( Vector3::zero(), Vector3::zero() ); for( std::vector<ChunkItemPtr>::iterator iter = items.begin(); iter != items.end(); ++iter ) (*iter)->addYBounds( bb ); Matrix view; Vector3 lookFrom( chunk.transform().applyToOrigin() ); lookFrom.x += GRID_RESOLUTION / 2.f; lookFrom.z += GRID_RESOLUTION / 2.f; lookFrom.y = bb.maxBounds().y + 0.25f + 300.f; float chunkHeight = bb.maxBounds().y - bb.minBounds().y + 320.f; view.lookAt( lookFrom, Vector3(0,-1,0), Vector3(0,0,1) ); Moo::rc().push(); Moo::rc().world( Matrix::identity ); Matrix proj; proj.orthogonalProjection( GRID_RESOLUTION, GRID_RESOLUTION, 0.25f, chunkHeight + 0.25f ); Moo::rc().view( view ); Moo::rc().projection( proj ); Moo::rc().updateViewTransforms(); Terrain::BaseTerrainRenderer::instance()->enableSpecular( false ); //make sure there are no states set into the main part of bigbang //that could upset the rendering Moo::rc().setRenderState( D3DRS_FILLMODE, D3DFILL_SOLID ); Moo::rc().fogEnabled( false ); FogController::instance().enable( false ); }