[2.1] Hlms ignores vertex colors?

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

[2.1] Hlms ignores vertex colors?

Post by chchwy » Wed May 15, 2019 7:38 am

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.
Image

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

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?
0 x

User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 147
Joined: Wed Apr 23, 2014 3:49 pm
x 11

Re: [2.1] Hlms ignores vertex colors?

Post by TaaTT4 » Thu May 16, 2019 11:04 am

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).
1 x
Senior game programmer at Vae Victis
Working on Racecraft

xrgo
OGRE Expert User
OGRE Expert User
Posts: 1023
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 65

Re: [2.1] Hlms ignores vertex colors?

Post by xrgo » Thu May 16, 2019 3:22 pm

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;
@end
create a file named CustomVS_piece_vs.glsl with this content:

Code: Select all

@piece( custom_vs_attributes )
	in vec4 colour;
@end
@piece( custom_vs_preExecution )
	outVs.colour = colour;
@end
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
@end
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 );
            ++libraryFolderPathIt;
        }
        //ADD CUSTOM FOLDER
        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.

cheers!
3 x

Post Reply