Colors missing from meshes.

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
Darkness
Greenskin
Posts: 121
Joined: Sat Mar 19, 2005 3:32 am
Location: Austin, Texas

Colors missing from meshes.

Post by Darkness »

Well, I finally got my internet back, so I've been converting my objects into meshes. The problem I have is some of them have no color. The objects themselves have no textures, they were supposed to be simply shaded, but when I load them in as entities they are without the color I gave them. In the XML file they have color, but there are none when I bring them into the scene. Anyone know how why this is or how I can fix it?


-Darkness
User avatar
johnhpus
Platinum Sponsor
Platinum Sponsor
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am
x 3

Post by johnhpus »

Did you set an ambient light? I'm not sure but I think that you might need one for vertex colors to show.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

Specifically you need to use the 'vertexcolour' option of at least one of the colour components in the pass (ambient, diffuse etc), see the manual for details.
Darkness
Greenskin
Posts: 121
Joined: Sat Mar 19, 2005 3:32 am
Location: Austin, Texas

Post by Darkness »

sinbad wrote:Specifically you need to use the 'vertexcolour' option of at least one of the colour components in the pass (ambient, diffuse etc), see the manual for details.
Hmmm...when I search the Ogre API reference for "vertexcolour", I don't find anything. The other thing is, just for the sake of testing, I made another object and gave it an actual texture. When I ran the "ogreXMLconverter" on it, it did not generate a material file. I load it up and it's just white. Just like the other objects. Oh, and I do have the ambient light turned on, so I don't think that's the problem. Is the ogreXMLconverter supposed to generate a material file? Do I need to set an option when I run the program on an object?

I apologize if I seem a little snippy, but I've been messing with this for many hours and I'm just frustrated at this point. I'm sure I'm doin' something wrong, but I don't know what or where.


-Darkness
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8
Contact:

Post by haffax »

Don't look for it in the API docs, but in the manual. Section 3.1.2 has it.
instead of something like

Code: Select all

ambient 0.8 0.8 0.8
write

Code: Select all

ambient vertexcolour
This uses the vertex colour as ambient component. this works likewise with diffuse and specular
team-pantheon programmer
creators of Rastullahs Lockenpracht
Darkness
Greenskin
Posts: 121
Joined: Sat Mar 19, 2005 3:32 am
Location: Austin, Texas

Post by Darkness »

What file is that in? When I look in the XML files for "ambient", I don't see anything. There wasn't a material file generated, so I don't have that to look into.


-Darkness
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8
Contact:

Post by haffax »

yes this is done in the material file. You need to give them a material or else they get the default one assigned. You can do this programatically too. Look up the API docs for details here, but just defning everything in a material file is easier.
team-pantheon programmer
creators of Rastullahs Lockenpracht
Darkness
Greenskin
Posts: 121
Joined: Sat Mar 19, 2005 3:32 am
Location: Austin, Texas

Post by Darkness »

Hmmm...when I run "ogreXMLconverter" it doesn't generate a material file automatically? I have no idea how to make a material script let alone how to make it work with my objects. Don't get me wrong, I've looked at the material scripts that came with ogre, but there are numbers in there I have no idea what they are. And how do I tell it what material goes on what face? I just assumed the converter created a material script when it did the conversion. Is there a converter that I can get that will automatically generate a material script off of the XML file?


-Darkness
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8
Contact:

Post by haffax »

The converter does what the name suggests it only converts between xml and binary meshes/skeletons. It can't create material files, as it doesn't know how you want the material.

This material should work for you:

Code: Select all

material mymaterial
{
    technique
    {
        pass
        {
            ambient vertexcolour
            diffuse vertexcolour
			
            texture_unit 
            {
                 colour_op_ex source1 src_diffuse src_diffuse
            }
        }
    }
}
team-pantheon programmer
creators of Rastullahs Lockenpracht
Darkness
Greenskin
Posts: 121
Joined: Sat Mar 19, 2005 3:32 am
Location: Austin, Texas

Post by Darkness »

Sinbad, here's the code I use:

Code: Select all

//Load the main background
		MaterialPtr		bgmaterial = MaterialManager::getSingleton().create("Background", "General");
		bgmaterial->getTechnique(0)->getPass(0)->createTextureUnitState("../Graphics/city.png");
		bgmaterial->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
		bgmaterial->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);

		//Disable lighting on background
		bgmaterial->getTechnique(0)->getPass(0)->setLightingEnabled(false);

		//Create background rectangle
		Rectangle2D*	bgrect = new Rectangle2D(true);

		//Cover whole screen
		bgrect->setCorners(-1.0,1.0,1.0,-1.0);

		//Kludge: set bounding box to a large size.
		bgrect->setBoundingBox(AxisAlignedBox(-10000.0*Vector3::UNIT_SCALE, 100000.0*Vector3::UNIT_SCALE));
		bgrect->setMaterial("Background");

		//Render background before everything else
		bgrect->setRenderQueueGroup(RENDER_QUEUE_BACKGROUND);

		//Attach background to the scene
		SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Background");
		node->attachObject(bgrect);
I hope this works.


-Darkness
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8
Contact:

Post by haffax »

Darkness, a follow-up from the discussion on IRC.
This material is a semi-transparent light purple and it works, I have tested it using both OpenGL and dx9.

Code: Select all

material alpha_purple
{
   technique
   {
      pass
      {
         depth_write off
         scene_blend alpha_blend

         texture_unit
         {
            colour_op_ex source1 src_manual src_manual 1.0 0.5 1.0 1.0 0.5 1.0
            alpha_op_ex source1 src_manual src_manual 0.5 0.5
         }
      }
   }
}
If your mesh is not transparent purple afterwards you need to post the material application code, as the error is most likely in it then.
team-pantheon programmer
creators of Rastullahs Lockenpracht
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8
Contact:

Post by haffax »

Darkness, got your mesh working at last. Actually without changing the mesh, really. The two white faces in the image where because they are seperate submeshes and I forgot to rename the materials for them. (from Purple to alpha_purple)

So, your mesh is fine, the material is fine too. The problem lies in some other place then. But don't know where. :?
team-pantheon programmer
creators of Rastullahs Lockenpracht
Darkness
Greenskin
Posts: 121
Joined: Sat Mar 19, 2005 3:32 am
Location: Austin, Texas

Post by Darkness »

Haff, I'm not sure what's goin' on either. If the meshes are good, then something must be wrong in the code somewhere. Based on my code for loading them in, is everything okay? Is there a step I need to do before I load them? I need to figure out what's goin' on, otherwise I can't get anywhere. Can't load models...can't finish project. :(


-Darkness
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

I've put this on my TODO, I'll look at it as soon as I can.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

Ok, I've looked. I don't have a mesh with vertex colours to hand, so I had to change your material a bit to this:

Code: Select all

material mymaterial
{
    technique
    {
        pass
        {
        	lighting off
			
            texture_unit
            {
                 colour_op_ex source1 src_manual src_current 1 0 0 
            }
        }
    }
} 
I then took the code above (changing the image to ogrelogo.png), and added:

Code: Select all

		Entity* e = mSceneMgr->createEntity("2", "knot.mesh");
		e->setMaterialName("mymaterial");
		mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
and the result was
Image

ie normal.

This thread is somewhat disjointed since conversations have happened on IRC - if this doesn't satisfy you need to sum up what your current problem is, and provide code, screenshots and media links, since it's difficult to derive here.
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8
Contact:

Post by haffax »

Sinbad, I don't believe this is a problem in Ogre. I tested the mesh and it worked just fine here. And there actually were no vertex colours in it. You are right, this discussion in the forum is a bit misleading, as it doesn't reflect everything, that has been said on IRC.
team-pantheon programmer
creators of Rastullahs Lockenpracht
Darkness
Greenskin
Posts: 121
Joined: Sat Mar 19, 2005 3:32 am
Location: Austin, Texas

Post by Darkness »

Yeah. I wish I had saved the links to the pics and everything we had when talking on IRC so you could see what was goin' on. If the problem is in the code, then I need to find where the problem is. I posted all of the code I use to pull up the images and I cannot get the meshes to work properly. They show up, but with no materials on them. In OpenGL they absorb the background material. It's real strange.

I'm not sure what to do right now. I can't get any of the models to display correctly. Even got some models from Lightwave and converted them and they don't work either. So I'm just lost.


-Darkness
Darkness
Greenskin
Posts: 121
Joined: Sat Mar 19, 2005 3:32 am
Location: Austin, Texas

Post by Darkness »

Just as a heads up...I got some meshes from someone that I'm going to try. I'll post my results of this when I get home, but I'm hoping this will work. If they do, then perhaps there was a problem when exporting in Max.

-Darkness
Post Reply