Esempio n. 1
0
void CNodeDefManager::updateTextures(IGameDef *gamedef,
	void (*progress_callback)(void *progress_args, u32 progress, u32 max_progress),
	void *progress_callback_args)
{
#ifndef SERVER
	infostream << "CNodeDefManager::updateTextures(): Updating "
		"textures in node definitions" << std::endl;

	Client *client = (Client *)gamedef;
	ITextureSource *tsrc = client->tsrc();
	IShaderSource *shdsrc = client->getShaderSource();
	scene::IMeshManipulator *meshmanip =
		RenderingEngine::get_scene_manager()->getMeshManipulator();
	TextureSettings tsettings;
	tsettings.readSettings();

	u32 size = m_content_features.size();

	for (u32 i = 0; i < size; i++) {
		ContentFeatures *f = &(m_content_features[i]);
		f->updateTextures(tsrc, shdsrc, meshmanip, client, tsettings);
		progress_callback(progress_callback_args, i, size);
	}
#endif
}
Esempio n. 2
0
void CNodeDefManager::updateTextures(IGameDef *gamedef,
	void (*progress_callback)(void *progress_args, u32 progress, u32 max_progress),
	void *progress_callback_args)
{
#ifndef SERVER
	infostream << "CNodeDefManager::updateTextures(): Updating "
		"textures in node definitions" << std::endl;
	ITextureSource *tsrc = gamedef->tsrc();
	IShaderSource *shdsrc = gamedef->getShaderSource();
	scene::ISceneManager* smgr = gamedef->getSceneManager();
	scene::IMeshManipulator* meshmanip = smgr->getMeshManipulator();
	TextureSettings tsettings;
	tsettings.readSettings();

	u32 size = m_content_features.size();

	for (u32 i = 0; i < size; i++) {
		m_content_features[i].updateTextures(tsrc, shdsrc, smgr, meshmanip, gamedef, tsettings);
		progress_callback(progress_callback_args, i, size);
	}
#endif
}
Esempio n. 3
0
RenderShader* RBShaderLoader::ParseFile( const tchar* fname, ShaderManager* db )
{
    Asset::ShaderAssetPtr shaderClass = Asset::AssetClass::LoadAssetClass< Asset::ShaderAsset >( fname );
    if ( !shaderClass.ReferencesObject() )
    {
        Log::Warning( TXT( "Could not load shader '%s'.\n" ), fname );
        return NULL;
    }

    // this seems like a valid shader, allocate a shader
    RenderShader* sh = new RenderShader(db,fname);

    tstring texturePath;
    bool hadError = false;

    SetShaderClassAlpha( sh, shaderClass->m_AlphaMode );

    if (shaderClass->m_DoubleSided)
        sh->m_flags|=SHDR_FLAG_TWO_SIDED;

    TextureSettings settings;
    settings.Clear();
    settings.m_WrapU = TextureAddressModes( shaderClass->m_WrapModeU );
    settings.m_WrapV = TextureAddressModes( shaderClass->m_WrapModeV );

    Asset::TexturePtr textureClass = Asset::AssetClass::LoadAssetClass< Asset::Texture >( shaderClass->m_ColorMapPath );
    if( textureClass.ReferencesObject() )
    {
        settings.m_Path = textureClass->GetPath().Get();
        settings.m_Anisotropy = 0;
        settings.m_Filter = TextureFilterMode( textureClass->GetFilter() );
        settings.m_Format = GetD3DColorFormat( textureClass->GetFormat() );
        settings.m_MipBias = 0.0f;
    }
    else
    {
        settings.m_Format = D3DFMT_UNKNOWN;
        settings.m_Path = TXT( "@@base" );
    }

    UpdateShader(sh, shaderClass);

    if( !db->LoadTextureWithSettings( settings, sh, Texture::SAMPLER_BASE_MAP ) )
    {
        if ( settings.m_Path != TXT( "@@base" ) )
        {
            Log::Warning( TXT( "Could not load base map '%s', loading default.\n" ), settings.m_Path.c_str() );
            settings.Clear();
            settings.m_Format = D3DFMT_UNKNOWN;
            settings.m_Path = TXT( "@@base" );

            if ( !db->LoadTextureWithSettings( settings, sh, Texture::SAMPLER_BASE_MAP ) )
            {
                Log::Error( TXT( "Could not load default base map.\n" ) );
                hadError = true;
            }
        }
    }

    settings.Clear();
    settings.m_WrapU = TextureAddressModes( shaderClass->m_WrapModeU );
    settings.m_WrapV = TextureAddressModes( shaderClass->m_WrapModeV );

    if ( shaderClass->m_NormalMapScaling > 0.0f )
    {
        Asset::TexturePtr normalMap = Asset::AssetClass::LoadAssetClass< Asset::Texture >( shaderClass->m_NormalMapPath );

        if ( normalMap.ReferencesObject() )
        {
            settings.m_Path = normalMap->GetPath().Get();
            settings.m_Anisotropy = 0;
            settings.m_Filter = TextureFilterMode( normalMap->GetFilter() );
            settings.m_Format = GetD3DColorFormat( normalMap->GetFormat() );
            settings.m_MipBias = 0.0f;
        }
        else
        {
            settings.m_Format = D3DFMT_UNKNOWN;
            settings.m_Path = TXT( "@@normal" );
        }
    }

    UpdateShader(sh, shaderClass);

    if( !db->LoadTextureWithSettings( settings, sh, Texture::SAMPLER_NORMAL_MAP ) )
    {
        if ( settings.m_Path != TXT( "@@normal" ) )
        {
            Log::Warning( TXT( "Could not load normal map '%s', loading default.\n" ), settings.m_Path.c_str() );
            settings.Clear();
            settings.m_Format = D3DFMT_UNKNOWN;
            settings.m_Path = TXT( "@@normal" );

            if ( !db->LoadTextureWithSettings( settings, sh, Texture::SAMPLER_NORMAL_MAP ) )
            {
                Log::Error( TXT( "Could not load default normal map.\n" ) );
                hadError = true;
            }
        }
    }

    settings.Clear();
    settings.m_WrapU = TextureAddressModes( shaderClass->m_WrapModeU );
    settings.m_WrapV = TextureAddressModes( shaderClass->m_WrapModeV );

    Asset::TexturePtr gpiMap = Asset::AssetClass::LoadAssetClass< Asset::Texture >( shaderClass->m_GPIMapPath );
    if( gpiMap.ReferencesObject() )
    {
        settings.m_Path = gpiMap->GetPath().Get();
        settings.m_Anisotropy = 0;
        settings.m_Filter = TextureFilterMode( gpiMap->GetFilter() );
        settings.m_Format = GetD3DColorFormat( gpiMap->GetFormat() );
        settings.m_MipBias = 0.0f;

        if( db->LoadTextureWithSettings( settings, sh, Texture::SAMPLER_GPI_MAP ) )
        {
            sh->m_textures[ Texture::SAMPLER_INCAN_MAP ] = 0xffffffff;
            sh->m_textures[ Texture::SAMPLER_PARALLAX_MAP ] = 0xffffffff;

            sh->m_flags |= SHDR_FLAG_GPI_MAP;

            UpdateShader( sh, shaderClass );
        }
        else
        {
            UpdateShader( sh, 0 );
            Log::Warning( TXT( "Could not load expensive map '%s', loading defaults.\n" ), settings.m_Path.c_str() );
            settings.Clear();
            settings.m_Format = D3DFMT_UNKNOWN;

            settings.m_Path = TXT( "@@gloss" );
            if ( !db->LoadTextureWithSettings( settings, sh, Texture::SAMPLER_GLOSS_MAP ) )
            {
                Log::Error( TXT( "Could not load default gloss map.\n" ) );
                hadError = true;
            }
            settings.m_Path = TXT( "@@parallax" );
            if ( !db->LoadTextureWithSettings( settings, sh, Texture::SAMPLER_PARALLAX_MAP ) )
            {
                Log::Error( TXT( "Could not load default parallax map.\n" ) );
                hadError = true;
            }
            settings.m_Path = TXT( "@@incan" );
            if ( !db->LoadTextureWithSettings( settings, sh, Texture::SAMPLER_INCAN_MAP ) )
            {
                Log::Error( TXT( "Could not load default incan map.\n" ) );
                hadError = true;
            }
        }
    }
    else
    {
        UpdateShader( sh, 0 );

        settings.Clear();
        settings.m_Format = D3DFMT_UNKNOWN;

        settings.m_Path = TXT( "@@gloss" );
        if ( !db->LoadTextureWithSettings( settings, sh, Texture::SAMPLER_GLOSS_MAP ) )
        {
            Log::Error( TXT( "Could not load default gloss map.\n" ) );
            hadError = true;
        }
        settings.m_Path = TXT( "@@parallax" );
        if ( !db->LoadTextureWithSettings( settings, sh, Texture::SAMPLER_PARALLAX_MAP ) )
        {
            Log::Error( TXT( "Could not load default parallax map.\n" ) );
            hadError = true;
        }
        settings.m_Path = TXT( "@@incan" );
        if ( !db->LoadTextureWithSettings( settings, sh, Texture::SAMPLER_INCAN_MAP ) )
        {
            Log::Error( TXT( "Could not load default incan map.\n" ) );
            hadError = true;
        }
    }

    if ( hadError )
    {
        delete sh;
        return NULL;
    }

    return sh;
}