Vertex Colour Tracking with Shadows Problem

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
Kaylx
Greenskin
Posts: 123
Joined: Sun May 22, 2011 10:45 pm
Location: Scotland
x 7

Vertex Colour Tracking with Shadows Problem

Post by Kaylx »

Hey all,

I'm trying to use vertex colour tracking to define the colours on my objects instead of specifically setting them in the pass information and everything works fine except when I enable (additive stencil) shadows. Using Ogre 1.7.2 GL.
See below:

Images - Left: No Shadows, Right: With Shadows

Coloured Mode (Old Way - No Vertex Colour Tracking) - i.e. using pass->setAmbient(colour) and pass->setDiffuse(colour)
ImageImage
- No shadows. Works as expected. :)
- With Shadows. Works as expected. :)

Coloured Mode (New Way - Vertex Colour Tracking) - i.e. using manual->colour(colour) and pass->setVertexColourTracking(TVC_AMBIENT|TVC_DIFFUSE)
ImageImage
- No shadows. Works as expected. :)
- With Shadows. Everything looks over exposed. Doesn't work as expected... :(

Textured Mode (No Vertex Colour Tracking)
ImageImage
- No shadows. Works as expected. :)
- With Shadows. Applies vertex colour when it shouldn't. Doesn't work as expected... :cry:

FYI - I switch between Coloured and Textured modes using Material Schemes.
Here's what my material definitions look like (i've clumped the techniques together just for posting on the forum):

Code: Select all

material Material_Base
{
	// Coloured Mode (No Vertex Colour Tracking) - What i was doing before
	technique 
	{
		scheme ViewMode_Coloured
		pass
		{
			lighting on
			shading phong
			ambient 0.7 0.7 0.7 1.0     // set in code, but set these defaults anyway
			diffuse 0.7 0.7 0.7 1.0     // set in code, but set these defaults anyway
			// scene_blend alpha_blend	// set in code, but only for transparent materials
			// depth_write off          // set in code, but only for transparent materials
		}
	}
	// Coloured Mode (Vertex Colour Tracking) - What i'm trying to use now
	technique
	{
		scheme ViewMode_Coloured
		pass
		{
			lighting on
			shading phong
			ambient vertexcolour		// disabled tracking in code for transparent materials, they have specific colours to use
			diffuse vertexcolour		// disabled tracking in code for transparent materials, they have specific colours to use
			// scene_blend alpha_blend	// set in code, but only for transparent materials
			// depth_write off          // set in code, but only for transparent materials
		}
	}
	
	// Textured Mode - This mode hasn't changed
	technique 
	{
		scheme ViewMode_Textured
		pass
		{
			lighting on
			shading phong
			ambient 0.7 0.7 0.7 1.0
			diffuse 0.7 0.7 0.7 1.0
			texture_unit DiffuseMap
			{
				texture_alias DiffuseMap  // set in code
			}
		}
	}
}
I programmatically clone the material then set the texture_alias as well as the ambient/diffuse colours.

So does anyone have ideas on what's going wrong? Is this a bug or limitation in Ogre? Or am i doing something wrong? Seems like it's a bug to me...
EDIT: Do i have to do something with the material pass 'illumination_stage' parameter?

Any help appreciated!

Regards,
Kaylx
Last edited by Kaylx on Tue Sep 20, 2011 8:59 am, edited 1 time in total.
User avatar
Kaylx
Greenskin
Posts: 123
Joined: Sun May 22, 2011 10:45 pm
Location: Scotland
x 7

Re: Vertex Colour Tracking with Shadows Problem

Post by Kaylx »

I thought i'd modify my materials (see bottom of post) to use the material pass 'illumination_stage' parameter after reading this in the Ogre Manual:
When using an additive lighting mode (SHADOWTYPE_STENCIL_ADDITIVE or SHADOWTYPE_TEXTURE_ADDITIVE), the scene is rendered in 3 discrete stages, ambient (or pre-lighting), per-light (once per light, with shadowing) and decal (or post-lighting). Usually OGRE figures out how to categorise your passes automatically, but there are some effects you cannot achieve without manually controlling the illumination.
However this still doesn't output the required results...

Coloured Mode (New Way - Vertex Colour Tracking w/ Illumination Passes)
ImageImage
- No shadows. Works as expected. :)
- With Shadows. Some surfaces look over exposed, other surfaces look fine. Doesn't work as expected... :(

Material comparison:

Code: Select all

material Material_Base
{
	// Coloured Mode (No Vertex Colour Tracking w/ Illumination Stage)
	// What i created manually and What Ogre generates automatically
	technique
	{
		scheme ViewMode_Coloured
		pass
		{
			illumination_stage ambient
			lighting on
			shading phong
			ambient 0 0.501961 1 1
			diffuse 0 0 0 1
		}
		pass
		{
			illumination_stage per_light
			lighting on
			shading phong
			ambient 0 0 0 1
			diffuse 0 0.501961 1 1
			scene_blend add
		}
	}
	// Coloured Mode (Vertex Colour Tracking w/ Illumination Stage)
	// What i created manually
	technique
	{
		scheme ViewMode_Coloured
		pass
		{
			illumination_stage ambient
			lighting on
			shading phong
			ambient vertexcolour
			diffuse 0 0 0 1
		}
		pass
		{
			illumination_stage per_light
			lighting on
			shading phong
			ambient 0 0 0 1
			diffuse vertexcolour
			scene_blend add
		}
	}
	// Coloured Mode (Vertex Colour Tracking w/ Illumination Stage)
	// What Ogre generates automatically
	technique
	{
		scheme ViewMode_Coloured
		pass
		{
			illumination_stage ambient
			lighting on
			shading phong
			ambient vertexcolour
			diffuse vertexcolour
		}
		pass
		{
			illumination_stage per_light
			lighting on
			shading phong
			ambient vertexcolour
			diffuse vertexcolour
			scene_blend add
		}
	}
}
As you can see what i created manually and what ogre automatically generates is different:
colours_illumstage_diff.png
FYI: I patched the MaterialSerializer so i could have the option of exporting the illumination derived passes instead of the normal passes. Handy for debugging. :)

[s]So another dead end. :([/s] EDIT: Think i'm onto something. Investigating further, will let everyone know.

Really need help with this one guys!
Last edited by Kaylx on Tue Sep 20, 2011 10:32 am, edited 1 time in total.
User avatar
Kaylx
Greenskin
Posts: 123
Joined: Sun May 22, 2011 10:45 pm
Location: Scotland
x 7

Re: Vertex Colour Tracking with Shadows Problem

Post by Kaylx »

UPDATE: So after investigating further it turns out when Ogre creates the 3 passes automatically it doesn't take into account vertex colour tracking, by which i mean it doesn't turn off the relevant tracking for each pass it creates. Hence we see the difference in materials (see my previous post).

So after patching Ogre::Technique::_compileIlluminationPasses to disable vertex colour tracking for the lighting parameters (ambient/diffuse/specular/emissive) that were being disabled (set to black) in each pass I get the desired behaviour of 'Coloured Mode (New Way - Vertex Colour Tracking)' giving the same output as 'Coloured Mode (Old Way - No Vertex Colour Tracking)'.

However i still have the problem with 'Textured Mode (No Vertex Colour Tracking)' picking up the vertex colours when shadows are applied. :(

I thought i had to create a material like the one below to get the texture and vertex colours blending...

Code: Select all

material TextureWithVertexColour
{
   technique
   {
      pass
      {
         diffuse vertexcolour
         texture_unit
         {
            texture debug.bmp
         }
      }
   }
}
So why is it happening with no vertex colour tracking enabled...? :?

HELP!
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 66
Contact:

Re: Vertex Colour Tracking with Shadows Problem

Post by sinbad »

Use a shader. Seriously.

But otherwise, all your passes are specifically referencing 'vertexcolour' - the ambient, the per-light and the decal. So of course your vertex colours are getting picked up in all passes.
User avatar
Kaylx
Greenskin
Posts: 123
Joined: Sun May 22, 2011 10:45 pm
Location: Scotland
x 7

Re: Vertex Colour Tracking with Shadows Problem

Post by Kaylx »

This is the technique i'm using for textured mode:

Code: Select all

   // Textured Mode - This mode hasn't changed
   technique 
   {
      scheme ViewMode_Textured
      pass
      {
         lighting on
         shading phong
         ambient 0.7 0.7 0.7 1.0
         diffuse 0.7 0.7 0.7 1.0
         texture_unit DiffuseMap
         {
            texture_alias DiffuseMap  // set in code
         }
      }
   }
I don't use the 'vertexcolour' parameter and this is the output i get:
Textured Mode (No Vertex Colour Tracking)
ImageImage
- No shadows. Works as expected. :)
- With Shadows. Applies vertex colour when it shouldn't. Doesn't work as expected... :cry:
Modulative Stencil Shadows don't effect the colour of the model but Additive Stencil Shadows do. Currently i need to do things without shaders.

Am i missing something?

EDIT: Panic over. Solved it (by patching Ogre). :)
Post Reply