[2.1] Hlms ignores vertex colors?

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
Posts: 29
Joined: Fri Feb 10, 2017 1:40 am
x 9

[2.1] Hlms ignores vertex colors?

Post by chchwy »

Hey guys,

I have a 3d model which comes with vertex color. No textures.

The model in another 3d viewer (babylon.js sandbox)
The vertex color shows correctly.

And the same model in my Ogre 2.1 application. All vertex colors are gone.

I am pretty sure the .mesh file contains vertex colors.

This is the link to the tree mesh if someone want to check.
https://www.dropbox.com/s/zqdccw41bvvcb ... .mesh?dl=0

So my question is, is Hlms supposed to ignore vertex colors?

User avatar
OGRE Contributor
OGRE Contributor
Posts: 241
Joined: Wed Apr 23, 2014 3:49 pm
x 45

Re: [2.1] Hlms ignores vertex colors?

Post by TaaTT4 »

chchwy wrote:
Wed May 15, 2019 7:38 am
So my question is, is Hlms supposed to ignore vertex colors?
I believe that vertex colors probably works just in Unlit materials. To let them work in PBS too, you have to at least change its shaders (and/or customize its HLMS implementation).
Senior game programmer at Vae Victis
Working on Racecraft

OGRE Expert User
OGRE Expert User
Posts: 1147
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 166

Re: [2.1] Hlms ignores vertex colors?

Post by xrgo »

TaaTT4 is right, you need to customize the hlmsPbs implementation. Try this:
create a file named CustomPassBuffer_piece_vs_piece_ps.glsl with this content:

Code: Select all

@piece( custom_VStoPS )
  vec4 colour;
create a file named CustomVS_piece_vs.glsl with this content:

Code: Select all

@piece( custom_vs_attributes )
	in vec4 colour;
@piece( custom_vs_preExecution )
	outVs.colour = colour;
create a file named CustomPS_piece_ps.glsl with this content:

Code: Select all

@piece( custom_ps_posExecution )
	 outColour.xyz	*= inPs.colour.xyz; //you could also use this data in previous parts of the shader to multiply just the diffuser part for example
put those files in a folder, and when registering the HlmsPbs add the folder as library:

Code: Select all

        //Create & Register HlmsPbs
        //Do the same for HlmsPbs:
        Ogre::HlmsPbs::getDefaultPaths( mainFolderPath, libraryFoldersPaths );
        Ogre::Archive *archivePbs = archiveManager.load( rootHlmsFolder + mainFolderPath,
                                                         "FileSystem", true );

        //Get the library archive(s)
        Ogre::ArchiveVec archivePbsLibraryFolders;
        libraryFolderPathIt = libraryFoldersPaths.begin();
        libraryFolderPathEn = libraryFoldersPaths.end();
        while( libraryFolderPathIt != libraryFolderPathEn )
            Ogre::Archive *archiveLibrary =
                    archiveManager.load( rootHlmsFolder + *libraryFolderPathIt, "FileSystem", true );
            archivePbsLibraryFolders.push_back( archiveLibrary );
        Ogre::Archive *archiveLibraryCustom = archiveManager.load( rootHlmsFolder+"Hlms/Pbs/MySuperDuperCustomFolder", "FileSystem", true );
        archivePbsLibraryFolders.push_back( archiveLibraryCustom );

        //Create and register
        mHlmsPbs = OGRE_NEW Ogre::HlmsPbs( archivePbs, &archivePbsLibraryFolders );
        Ogre::Root::getSingleton().getHlmsManager()->registerHlms( mHlmsPbs );
note: this is for glsl, I guess if you change vec4 for float4 and .glsl for .any should work for d3d and metal too

The next problem would be to identify which meshes have vertex color and which doesn't, so you don't do the outColour multiplication when inPs.colour is probably black. but tell me if this works first.


Post Reply