当前位置: 首页 > 工具软件 > Ogre-Next > 使用案例 >

ogre-next 学习笔记 - Day 5

马权
2023-12-01

ogre-next 学习笔记 - Day 5

回过头,想起在pbsmaterial的描述里好像有说有文档。

// Also see the Hlms section of the porting guide in\n"
//        "the Docs/2.0 folder.

打开 Docs/2.0/Ogre 2.0 Porting Manual DRAFT.odt

工具 OpenOffice

打开发现,这就是一本书啊,100+页。直接找需要的东西吧。

第八章 : HLMS: High Level Material System
大致浏览了一遍,说的都是技术相关的东西,很细节,明显不是入门级的东西。
稍微看一看,没有需要的东西。回头再仔细的看。

还是只能从代码入手。

回想ogre的操作,既然它是script,每个script都有一个translator,找找hlms相关的hlms。

HlmsTranslator

void HlmsTranslator::translate()
{
    // ...
    const IdString idType( type );
    for( size_t i=0; i<HLMS_MAX && !hlms; ++i )
    {
        hlms = hlmsManager->getHlms( static_cast<HlmsTypes>( i ) );

        if( hlms && idType != hlms->getTypeName() )
            hlms = 0; //This one isn't, keep looking
    }
}

调试一下,发现,hlms Rocks pbs 中的pbs被称为type,它的type会转为 IdString.

    enum HlmsTypes
    {
        HLMS_LOW_LEVEL, /// Proxy that redirects to a regular Material
        HLMS_PBS,       /// Physically Based Shader Generator
        HLMS_TOON,      /// Toon shading / Cel shading
        HLMS_UNLIT,     /// Made for GUIs, overlays, particle FXs, self-iluminating billboards

        HLMS_USER0,
        HLMS_USER1,
        HLMS_USER2,
        HLMS_USER3,

        HLMS_MAX = 8,

        HLMS_COMPUTE,
    };

通过不同的type找到对应的hlms,然后解析script,创建对应的datablock

hlms->createDatablock( obj->name, obj->name, macroblock, blendblock, paramVec, true, obj->file, compiler->getResourceGroup() );

所以,该找的不是datablock,而是hlms。

class _OgreHlmsCommonExport HlmsBufferManager : public Hlms
class _OgreHlmsPbsExport HlmsPbs : public HlmsBufferManager, public ConstBufferPool
class _OgreHlmsUnlitExport HlmsUnlit : public HlmsBufferManager, public ConstBufferPool
class _OgreHlmsPbsMobileExport HlmsPbsMobile : public Hlms
class _OgreHlmsUnlitMobileExport HlmsUnlitMobile : public Hlms
class _OgreExport HlmsCompute : public Hlms
class _OgreExport HlmsLowLevel : public Hlms
class HlmsTerra : public HlmsBufferManager, public ConstBufferPool

  • HlmsPbs / HlmsPbsMobile => HlmsTypes : HLMS_PBS, typeName : “pbs”
  • HlmsUnlit / HlmsUnlitMobile => HlmsTypes : HLMS_UNLIT, typeName : “unlit”
  • HlmsLowLevel => HlmsTypes : HLMS_LOW_LEVEL, typeName : “”
  • HlmsCompute => HlmsTypes : HLMS_COMPUTE, typeName : “compute”
  • HlmsTerra => HlmsTypes : HLMS_USER3, typeName : “Terra”

所以,之前的猜测是对的。

hlms::createDatablock不是虚函数,hlms::createDatablockImpl是虚函数,
所以最终创建datablock在createDatablockImpl函数里。

    HlmsDatablock* HlmsCompute::createDatablockImpl( IdString datablockName,
                                                     const HlmsMacroblock *macroblock,
                                                     const HlmsBlendblock *blendblock,
                                                     const HlmsParamVec &paramVec )
    {
        return 0;
    }
    HlmsDatablock* HlmsLowLevel::createDatablockImpl( IdString datablockName,
                                                      const HlmsMacroblock *macroblock,
                                                      const HlmsBlendblock *blendblock,
                                                      const HlmsParamVec &paramVec )
    {
        return OGRE_NEW HlmsLowLevelDatablock( datablockName, this, macroblock, blendblock, paramVec );
    }
    HlmsDatablock* HlmsPbs::createDatablockImpl( IdString datablockName,
                                                       const HlmsMacroblock *macroblock,
                                                       const HlmsBlendblock *blendblock,
                                                       const HlmsParamVec &paramVec )
    {
        return OGRE_NEW HlmsPbsDatablock( datablockName, this, macroblock, blendblock, paramVec );
    }
    HlmsDatablock* HlmsPbsMobile::createDatablockImpl( IdString datablockName,
                                                       const HlmsMacroblock *macroblock,
                                                       const HlmsBlendblock *blendblock,
                                                       const HlmsParamVec &paramVec )
    {
        return OGRE_NEW HlmsPbsMobileDatablock( datablockName, this, macroblock, blendblock, paramVec );
    }
    HlmsDatablock* HlmsUnlit::createDatablockImpl( IdString datablockName,
                                                       const HlmsMacroblock *macroblock,
                                                       const HlmsBlendblock *blendblock,
                                                       const HlmsParamVec &paramVec )
    {
        return OGRE_NEW HlmsUnlitDatablock( datablockName, this, macroblock, blendblock, paramVec );
    }
    HlmsDatablock* HlmsUnlitMobile::createDatablockImpl( IdString datablockName,
                                                         const HlmsMacroblock *macroblock,
                                                         const HlmsBlendblock *blendblock,
                                                         const HlmsParamVec &paramVec )
    {
        return OGRE_NEW HlmsUnlitMobileDatablock( datablockName, this, macroblock, blendblock, paramVec );
    }
    HlmsDatablock* HlmsTerra::createDatablockImpl( IdString datablockName,
                                                       const HlmsMacroblock *macroblock,
                                                       const HlmsBlendblock *blendblock,
                                                       const HlmsParamVec &paramVec )
    {
        return OGRE_NEW HlmsTerraDatablock( datablockName, this, macroblock, blendblock, paramVec );
    }

从实现上看,compute没有对应的datablock。


直接看代码很快就找到了,其他方法找了那么久,一点可用信息都没有。

入门不易是真的


说点其他的,文档上对HLMS的描述,第一段

The HLMS (often stylized Hlms) is the new material system used in Ogre 2.0. It's more user friendly and performs faster.
HLMS stands for “High Level Material System”, because for the user, the HLMS means just define the material and start looking at it (no need for coding or shader knowledge!). But on retrospective, tweaking the shader code for an HLMS is much low level than the old Materials have ever been (and that makes them very powerful).

hlms更加友好,更加快速。用户只需要定义以及找到它就可以了,不需要代码与shader的相关知识。
hlms需要调整的代码/shader远低于旧的材质系统,这使得hlms非常强大。

 类似资料: