void SceneTerrain::Init()
{
	ResourceManager& res = ResourceManager::getInstance();
	VarManager& var = VarManager::getInstance();

	m_vSunAngle = vec2(0.0f, RADIANS(45.0f));

	m_pSkybox = (TextureCubemap*)res.LoadResource(ResourceManager::TEXTURECUBEMAP, "sand_up.jpg sand_dn.jpg sand_tp.jpg sand_bm.jpg sand_lt.jpg sand_rt.jpg");

	m_pShaderLighting	= (Shader*)res.LoadResource(ResourceManager::SHADER, "lighting");
	m_pShaderTerrain	= (Shader*)res.LoadResource(ResourceManager::SHADER, "terrain_ground");
	m_pShaderWater		= (Shader*)res.LoadResource(ResourceManager::SHADER, "terrain_water");
	m_pShaderGrass		= (Shader*)res.LoadResource(ResourceManager::SHADER, "terrain_grass");
	m_pShaderTree		= (Shader*)res.LoadResource(ResourceManager::SHADER, "terrain_tree");

	res.LoadResource(ResourceManager::MESH, "terrain_house.obj");

	res.LoadResource(ResourceManager::TEXTURE2D, "wall_diffuse.jpg");
	res.LoadResource(ResourceManager::TEXTURE2D, "wall_NM_height.tga");

	m_tTextures.push_back( (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "terrain_detail_NM.tga") );
	m_tTextures.push_back( (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "sandfloor009a.jpg") );
	m_tTextures.push_back( (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "terrain_rocky_map_1024.png") );
	m_tTextures.push_back( (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "terrain_grass_map_1024.png") );
	m_tTextures.push_back( (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "terrain_water_caustics.jpg") );
	
	
	res.LoadResource(ResourceManager::TEXTURE2D, "grass_billboards.tga");
	res.LoadResource(ResourceManager::TEXTURE2D, "palm_texture.tga");


	m_pTexWaterNoiseNM = (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "terrain_water_NM.jpg");
	m_pTerrainDiffuseMap = (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "test_heightmap512_2_diffusemap.jpg");

	var.set("water_height", 4.2f);

	m_pTerrain = new Terrain();
	assert(m_pTerrain != NULL);
	//BoundingBox bbox( vec3(-300.0f, 0.0f, -300.0f), vec3(300.0f, 50.0f, 300.0f) );
	BoundingBox bbox( vec3(-300.0f, 0.0f, -300.0f), vec3(300.0f, 40.0f, 300.0f) );
//	m_pTerrain->Load("test_heightmap1024_2.jpg", bbox, 32);
	m_pTerrain->Load("test_heightmap512_2.jpg", bbox, 16);

	ImageTools::ImageData img;
	ImageTools::OpenImage("test_heightmap512_2_diffusemap.jpg", img);
	m_pTerrain->GenerateGrass(img, 200000);
	m_pTerrain->GenerateVegetation(img, 100);
	m_pTerrain->ComputeBoundingBox();
	img.Destroy();

	Reload(); // set shader constants

	m_fboWaterReflection.Create(FrameBufferObject::FBO_2D_COLOR, 512, 512);
	m_fboDepthMapFromLight[0].Create(FrameBufferObject::FBO_2D_DEPTH, 2048, 2048);
	m_fboDepthMapFromLight[1].Create(FrameBufferObject::FBO_2D_DEPTH, 2048, 2048);

	LoadCameraTrajFromFile("terrain.txt");
}
Exemple #2
0
bool Texture::loadFile(const TextureLoadInfo& info, const stringImpl& name, ImageTools::ImageData& fileData) {
    // If we haven't already loaded this file, do so
    if (!fileData.data()) {
        // Flip image if needed
        fileData.flip(_flipped);
        fileData.set16Bit(_descriptor.dataType() == GFXDataFormat::FLOAT_16 ||
                          _descriptor.dataType() == GFXDataFormat::SIGNED_SHORT ||
                          _descriptor.dataType() == GFXDataFormat::UNSIGNED_SHORT);
        
        // Save file contents in  the "img" object
        ImageTools::ImageDataInterface::CreateImageData(name, fileData);

        
        bufferPtr data = fileData.is16Bit() ? fileData.data16() : fileData.isHDR() ? fileData.dataf() : fileData.data();
        // Validate data
        if (data == nullptr) {
            if (info._layerIndex > 0) {
                Console::errorfn(Locale::get(_ID("ERROR_TEXTURE_LAYER_LOAD")), name.c_str());
                return false;
            }
            Console::errorfn(Locale::get(_ID("ERROR_TEXTURE_LOAD")), name.c_str());
            // Missing texture fallback.
            fileData.flip(false);
            // missing_texture.jpg must be something that really stands out
            ImageTools::ImageDataInterface::CreateImageData(Paths::g_assetsLocation + Paths::g_texturesLocation + s_missingTextureFileName, fileData);

        }

        // Extract width, height and bitdepth
        U16 width = fileData.dimensions().width;
        U16 height = fileData.dimensions().height;
        // If we have an alpha channel, we must check for translucency/transparency

        FileWithPath fwp = splitPathToNameAndLocation(name);
        Util::ReplaceStringInPlace(fwp._path, "/", "_");
        const stringImpl cachePath = Paths::g_cacheLocation + Paths::Textures::g_metadataLocation;
        const stringImpl cacheName = fwp._path + "_" + fwp._fileName + ".cache";
        ByteBuffer metadataCache;
        if (metadataCache.loadFromFile(cachePath, cacheName)) {
            metadataCache >> _hasTransparency;
            metadataCache >> _hasTranslucency;
        } else {
void SceneTerrain::Init()
{
	SINGLETON_GET( ResourceManager, res )
	SINGLETON_GET( VarManager, var )

	m_vSunAngle = vec2(0.0f, RADIANS(45.0f));

	m_pSkybox   = (TextureCubemap*)res.LoadResource(ResourceManager::TEXTURECUBEMAP, "xposD.jpg xnegD.jpg yposD.jpg ynegD.jpg zposD.jpg znegD.jpg");
	m_pNightbox = (TextureCubemap*)res.LoadResource(ResourceManager::TEXTURECUBEMAP, "xposN.jpg xnegN.jpg yposN.jpg ynegN.jpg zposN.jpg znegN.jpg");


	m_pShaderLighting	= (Shader*)res.LoadResource(ResourceManager::SHADER, "lighting");
	m_pShaderTerrain	= (Shader*)res.LoadResource(ResourceManager::SHADER, "terrain_ground");
	m_pShaderWater		= (Shader*)res.LoadResource(ResourceManager::SHADER, "terrain_water");
	m_pShaderGrass		= (Shader*)res.LoadResource(ResourceManager::SHADER, "terrain_grass");
	m_pShaderTree		= (Shader*)res.LoadResource(ResourceManager::SHADER, "terrain_tree");

	res.LoadResource(ResourceManager::MESH, "terrain_house.3d");

	res.LoadResource(ResourceManager::TEXTURE2D, "wall_diffuse.jpg");
	res.LoadResource(ResourceManager::TEXTURE2D, "wall_NM_height.tga");

	// These are textures used to render the final terrain
	m_tTextures.push_back( (Texture2D*)res.LoadResource( ResourceManager::TEXTURE2D, "terrain_detail_NM.tga") );
	m_tTextures.push_back( (Texture2D*)res.LoadResource( ResourceManager::TEXTURE2D, "terrain_sand_512.jpg") );
	m_tTextures.push_back( (Texture2D*)res.LoadResource( ResourceManager::TEXTURE2D, "terrain_rocky_1024.png") );
	m_tTextures.push_back( (Texture2D*)res.LoadResource( ResourceManager::TEXTURE2D, "terrain_grass_1024.png") );
	m_tTextures.push_back( (Texture2D*)res.LoadResource( ResourceManager::TEXTURE2D, "terrain_water_caustics.jpg") );	
	
	
	res.LoadResource(ResourceManager::TEXTURE2D, "grass_billboards.tga");
	res.LoadResource(ResourceManager::TEXTURE2D, "palm_texture.tga");

	m_pTexWaterNoiseNM = (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "terrain_water_NM.jpg");
	m_pTerrainDiffuseMap = (Texture2D*)res.LoadResource(ResourceManager::TEXTURE2D, "heightmap_1024_diffusemap.jpg");

	m_pTerrain = new Terrain();
	assert(m_pTerrain != NULL);
	BoundingBox bbox( vec3(.0f, .0f, .0f), vec3(1025.0f, 255.0f, 1025.0f) );	// TODO : Calculate this so can be modified in game.
	m_pTerrain->Load("heightmap_1024.jpg", bbox, 32);	// 16

	ImageTools::ImageData img;
	ImageTools::OpenImage("heightmap_1024.jpg", img);
	std::cout << "   HeightMap D: " << img.d << " Size: " << img.w << "x" << img.h << std::endl;
	m_pTerrain->GenerateGrass(img, 200);				// 200000 GRASS AMOUNT
	m_pTerrain->GenerateVegetation(img, 25);
	m_pTerrain->ComputeBoundingBox();
	img.Destroy();

	vec3 fogColor(0.7f, 0.7f, 0.9f);
	m_pShaderTerrain->Activate();
		m_pShaderTerrain->Uniform("bbox_min", m_pTerrain->getBoundingBox().min);
		m_pShaderTerrain->Uniform("bbox_max", m_pTerrain->getBoundingBox().max);
		m_pShaderTerrain->Uniform("fog_color", fogColor);
	m_pShaderTerrain->Deactivate();

	m_pShaderWater->Activate();
		m_pShaderWater->Uniform("bbox_min", m_pTerrain->getBoundingBox().min);
		m_pShaderWater->Uniform("bbox_max", m_pTerrain->getBoundingBox().max);
		m_pShaderWater->Uniform("fog_color", fogColor);
	m_pShaderWater->Deactivate();


	m_fboWaterReflection.Create(FrameBufferObject::FBO_2D_COLOR, 512, 512);
	m_fboDepthMapFromLight[0].Create(FrameBufferObject::FBO_2D_DEPTH, 2048, 2048);
	m_fboDepthMapFromLight[1].Create(FrameBufferObject::FBO_2D_DEPTH, 2048, 2048);

	Camera::GetSingleton().setEye( ( m_pTerrain->getBoundingBox().min + (m_pTerrain->getBoundingBox().max * 0.5) ) );
	//Camera::GetSingleton().setAngle( 45.0f, 45.0f );

	// Player set up. TODO : Need to add multiple players and networking.
	Mark.m_szName = "Mark";
	Mark.m_pointer.MoveTo( ( m_pTerrain->getBoundingBox().min + (m_pTerrain->getBoundingBox().max * 0.5) ));
	res.LoadResource(ResourceManager::MESH, "pointy.3d");
	m_pGui = new GUI();
	m_pGui->init();
}