예제 #1
0
	void Material::update() {
		if(!baseMaterial.isNull()) {
			Ogre::ColourValue ambient = baseMaterial->getTechnique(0)->getPass(0)->getAmbient();
			Ogre::ColourValue diffuse = baseMaterial->getTechnique(0)->getPass(0)->getDiffuse();
			Ogre::ColourValue specular = baseMaterial->getTechnique(0)->getPass(0)->getSpecular();
			Ogre::ColourValue emissive = baseMaterial->getTechnique(0)->getPass(0)->getEmissive();
			float shininess = baseMaterial->getTechnique(0)->getPass(0)->getShininess();
			GLuint tex = 0;
			if(baseMaterial->getNumTechniques()!=0 && baseMaterial->getTechnique(0)->getNumPasses()!=0 && baseMaterial->getTechnique(0)->getPass(0)->getNumTextureUnitStates()!=0) {
				Ogre::String texName = baseMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName();
				if(Ogre::TextureManager::getSingleton().resourceExists(texName)) {
					Ogre::TexturePtr texPtr = Ogre::TextureManager::getSingleton().getByName(texName);
					Ogre::Image img;
					texPtr->convertToImage(img);
					Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual(texPtr->getName()+"_optixformat", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, texPtr->getWidth(), texPtr->getHeight(), 0, Ogre::PF_FLOAT32_RGBA, Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
					texture->loadImage(img);
					tex = ((Ogre::GLTexturePtr)texture)->getGLID();
				}
			}
			prepareMaterial(glm::vec3(ambient.r,ambient.g,ambient.b),
							glm::vec3(diffuse.r,diffuse.g,diffuse.b),
							glm::vec3(specular.r,specular.g,specular.b),
							glm::vec3(emissive.r,emissive.g,emissive.b),
							shininess,tex);
		}
	}
예제 #2
0
 void ReliefApp::GenerateRelief()
 {
     //Get depth data
     Ogre::TexturePtr depthTex = Ogre::TextureManager::getSingleton().createManual(  
         "DepthTexture",      // name   
         Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,  
         Ogre::TEX_TYPE_2D,   // type   
         512,  // width   
         512,  // height   
         0,                   // number of mipmaps   
         //Ogre::PF_B8G8R8A8,   // pixel format
         Ogre::PF_FLOAT32_R,
         Ogre::TU_RENDERTARGET
         ); 
     Ogre::RenderTarget* pTarget = depthTex->getBuffer()->getRenderTarget();
     Ogre::Camera* pOrthCam = MagicCore::RenderSystem::GetSingleton()->GetMainCamera();
     pOrthCam->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
     pOrthCam->setOrthoWindow(3, 3);
     pOrthCam->setPosition(0, 0, 3);
     pOrthCam->lookAt(0, 0, 0);
     pOrthCam->setAspectRatio(1.0);
     pOrthCam->setNearClipDistance(0.5);
     pOrthCam->setFarClipDistance(5);
     Ogre::Viewport* pViewport = pTarget->addViewport(pOrthCam);
     pViewport->setDimensions(0, 0, 1, 1);
     MagicCore::RenderSystem::GetSingleton()->RenderLightMesh3D("RenderMesh", "Depth", mpLightMesh);
     MagicCore::RenderSystem::GetSingleton()->Update();
     Ogre::Image img;
     depthTex->convertToImage(img);
     std::vector<double> heightField(512 * 512);
     for(int x = 0; x < 512; x++)  
     {  
         for(int y = 0; y < 512; y++)  
         {
             heightField.at(x * 512 + y) = (img.getColourAt(x, 511 - y, 0))[1];
         }
     }
     Ogre::TextureManager::getSingleton().remove("DepthTexture");
     //
     MagicDGP::LightMesh3D* pReliefMesh = MagicDGP::ReliefGeneration::PlaneReliefFromHeightField(heightField, 511, 511);
     //MagicDGP::LightMesh3D* pReliefMesh = MagicDGP::ReliefGeneration::CylinderReliefFromHeightField(heightField, 511, 511);
     if (pReliefMesh != NULL)
     {
         delete mpLightMesh;
         mpLightMesh = pReliefMesh;
         mpLightMesh->UnifyPosition(2);
         mpLightMesh->UpdateNormal();
     }
     MagicCore::RenderSystem::GetSingleton()->SetupCameraDefaultParameter();
     MagicCore::RenderSystem::GetSingleton()->RenderLightMesh3D("RenderMesh", "MyCookTorrance", mpLightMesh);
 }
예제 #3
0
파일: Terrain.cpp 프로젝트: Gohla/Diversia
void Terrain::resourcesLoaded()
{
    mTerrain = OGRE_NEW Ogre::Terrain( GlobalsBase::mScene );

    Ogre::Terrain::ImportData imp;
    Ogre::Image img;

    switch( mHeightmapType )
    {
        case HEIGHTMAPTYPE_IMAGE:
        {
            Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName( 
                mHeightmapFile.string(), mResourceManager.getGroup() );
            texture->convertToImage( img );
            imp.inputImage = &img;
            imp.terrainSize = img.getWidth();
            imp.inputScale = mInputScale;
            break;
        }
        case HEIGHTMAPTYPE_RAW:
        {
            Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource( 
                mHeightmapFile.string(), mResourceManager.getGroup() );
            img.loadRawData( stream, 1025, 1025, Ogre::PF_FLOAT32_R );
            imp.inputImage = &img;
            imp.terrainSize = img.getWidth();
            imp.inputScale = 1;
            break;
        }
        case HEIGHTMAPTYPE_OGREBINARY:
            break;
    }

    if( mTerrainType != TERRAINTYPE_OGREBINARY )
    {
        // Generic import data
        imp.worldSize = 1025;
        imp.minBatchSize = 33;
        imp.maxBatchSize = 65;
        imp.pos = toVector3<Ogre::Vector3>( 
            ServerPosition( ClientPlugin::getServer().getGridPosition() ).get3DPosition() );
        mTerrain->setPosition( imp.pos );

        // Set textures
        imp.layerList.resize( mLayerInstances.size() );
        for( unsigned int i = 0; i < mLayerInstances.size(); ++i )
        {
            imp.layerList[i].worldSize = mLayerInstances[i].mWorldSize;
            for( std::vector<Path>::iterator j = mLayerInstances[i].mTextureFiles.begin(); 
                j != mLayerInstances[i].mTextureFiles.end(); ++j )
            {
                imp.layerList[i].textureNames.push_back( (*j).string() );
            }
        }

        // Load the terrain
        mTerrain->prepare( imp );
        mTerrain->load();
    }

    // Set blending
    switch( mTerrainType )
    {
        case TERRAINTYPE_AUTOBLENDMAP:
        {
            Ogre::TerrainLayerBlendMap* blendMap0 = mTerrain->getLayerBlendMap(1);
            Ogre::TerrainLayerBlendMap* blendMap1 = mTerrain->getLayerBlendMap(2);
            float* pBlend1 = blendMap1->getBlendPointer();
            for (Ogre::uint16 y = 0; y < mTerrain->getLayerBlendMapSize(); ++y)
            {
                for (Ogre::uint16 x = 0; x < mTerrain->getLayerBlendMapSize(); ++x)
                {
                    Ogre::Real tx, ty;

                    blendMap0->convertImageToTerrainSpace(x, y, &tx, &ty);
                    Ogre::Real height = mTerrain->getHeightAtTerrainPosition(tx, ty);
                    Ogre::Real val = (height - mMinHeight0) / mFadeDistance0;
                    val = Ogre::Math::Clamp(val, (Ogre::Real)0, (Ogre::Real)1);

                    val = (height - mMinHeight1) / mFadeDistance1;
                    val = Ogre::Math::Clamp(val, (Ogre::Real)0, (Ogre::Real)1);
                    *pBlend1++ = val;
                }
            }

            blendMap0->dirty();
            blendMap1->dirty();
            blendMap0->update();
            blendMap1->update();
            break;
        }
        case TERRAINTYPE_OGREBINARY:
            // Everything is embedded in the binary file.
            mTerrain->setResourceGroup( mResourceManager.getGroup() );
            mTerrain->prepare( mHeightmapFile.string() );
            mTerrain->load( mHeightmapFile.string() );
            break;
    }

    mTerrain->freeTemporaryResources();

    ClientPlugin::mLoadingCompletedSignal( *this );
}