Page 1 of 1

2 different mesh vertex color.

Posted: Wed Feb 22, 2023 6:35 pm
by JFM

Hi,

it is possible to set 2 different color on each vertex of a mesh ? The first one used to calculate the ambient light effect and the second used to calculate diffuse light effect ? This lead to have a different ambient light color per poly that was different of diffuse one per poly.

Thanks.


Re: 2 different mesh vertex color.

Posted: Thu Feb 23, 2023 10:07 pm
by JFM

If its possible to do that. It will appreciate if you can explain or even better, give a example with a scene of one manual mesh of one quad (or triangle), one ambient light (white) and one diffuse light (white). Probably need the material for the mesh too in the example. If you have 2 color on the vertex of mesh, say color1 (green) and color2 (blue). The expected result is the render to output the poly more green if you put more ambient light and blue if you put more diffuse light lighting it and cyan if you put both equal. Will be great if shadow work too (for diffuse light).

Thanks for your help.


Re: 2 different mesh vertex color.

Posted: Thu Feb 23, 2023 10:20 pm
by JFM

For the "said" example one poly is enough, but the finality is to have many poly (like 2 poly of different color). Then mesh can contain a second poly with 2 color, color1 (green), color2 (red). And this second poly will be green if exposed to ambient only, red to diffuse only, and yellow if exposed to both. And a mix of these 2 color in general. In fact the 2 color is blend with the texture of material first, then used for lighting.

I want something equivalent to something like this I guess. But this code below is not possible, can we make same behavior another way ?

Ogre::MaterialPtr mMat = Ogre::MaterialManager::getSingleton().create("MyMaterial", "General", true);
Ogre::Technique* mTech = mMat->getTechnique(0);
Ogre::Pass* mPass = mTech->getPass(0);
mPass->setDiffuse(Ogre::ColourValue(1, 1, 1));
--> mPass->setVertexColour1Tracking(Ogre::TVC_AMBIENT);
--> mPass->setVertexColour2Tracking(Ogre::TVC_DIFFUSE);
Ogre::Image ogreImage;
ogreImage.load("Textures.bmp", "General");
Ogre::TexturePtr mTex = Ogre::TextureManager::getSingleton().loadImage("MyTexture", "General", ogreImage);
Ogre::TextureUnitState* mTexUnitState = mPass->createTextureUnitState("MyTexture");

Ogre::ManualObject* ogreMan = scene->createManualObject("MyMan");
ogreMan->begin("MyMaterial", Ogre::RenderOperation::OT_TRIANGLE_LIST);
for (int i = 0; i < 4; ++i)
{
ogreMan->position(...);
ogreMan->normal(...);
ogreMan->textureCoord(...);
--> ogreMan->colour1(Ogre::ColourValue(0, 0.5, 0));
--> ogreMan->colour2(Ogre::ColourValue(0, 0, 0.5));
}
ogreMan->quad(0, 1, 2, 3);
ogreMan->end();
...


Re: 2 different mesh vertex color.

Posted: Fri Feb 24, 2023 1:12 pm
by paroj

you can do:

Code: Select all

ogreMan->textureCoord(...);
ogreMan->colour(0, 0.5, 0);
ogreMan->textureCoord(0, 0, 0.5);

to get the secondary colour in TEXCOORD1. When not using the ManualObject, there is also VES_COLOUR2 that you can use.

In any case, you will need to provide your own shader to make sense of the vertex attributes, as ogre only implements the simple Fixed Function mode, where only a single attribute is tracked: https://registry.khronos.org/OpenGL-Ref ... terial.xml


Re: 2 different mesh vertex color.

Posted: Fri Feb 24, 2023 4:36 pm
by JFM

ok, thanks, im ok to pass the second "color" parameter into the w of uvcoord.

Im not very confident to make a custom shader using it and consider diffuse binded to colour and ambient binded to w. Can you help me how to do that in Ogre ?

Thanks.


Re: 2 different mesh vertex color.

Posted: Fri Feb 24, 2023 7:54 pm
by JFM

ok, I understanded you don't pass color in w but pass a second uvcoord (possibly 7 can be pass ?), or in VES_COLOUR2 that look better for this use. The 2 methods is ok for me. Create a material with a custom shader in Ogre look more complicated but ok. The shader himself (.glsl file ?) is another thing. I need a vertex shader only ? Another or more ? Shadow or transparency will continue to work well without adding more complexity to custom shader ?

Thanks.