[2.1] Hlms ignores vertex colors?

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


chchwy
Kobold
Posts: 30
Joined: Fri Feb 10, 2017 1:40 am
x 11

[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.
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?
User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 267
Joined: Wed Apr 23, 2014 3:49 pm
Location: Bologna, Italy
x 75

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 programmer at 505 Games; former senior engine programmer at Sandbox Games
Worked on: Racecraft EsportRacecraft Coin-Op, Victory: The Age of Racing

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

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;
@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!
jwwalker
Goblin
Posts: 297
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 21

Re: [2.1] Hlms ignores vertex colors?

Post by jwwalker »

I tried setting an unlit datablock on an item with vertex colors, and I still didn't see the colors.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5534
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1394

Re: [2.1] Hlms ignores vertex colors?

Post by dark_sylinc »

Unlit definitely supports vertex colours. Check in RenderDoc to see if you can spot something amiss.

jwwalker
Goblin
Posts: 297
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 21

Re: [2.1] Hlms ignores vertex colors?

Post by jwwalker »

I'm mostly developing on macOS, so no RenderDoc. I tried looking at the Metal debugging info in Xcode, but I don't know enough about Metal to know what to look for.

However... I had been testing in a toy program made by modifying a sample program. But when I tried using vertex colors in unlit mode in my big program, it worked. So it's a mystery, but maybe not worth spending hours to figure out.