[Solved][Material] Vertexcolour and transparent texture

Problems building or running the engine, queries about how to use features etc.
Post Reply
vimes
Gnoblar
Posts: 15
Joined: Fri May 19, 2006 5:00 am

[Solved][Material] Vertexcolour and transparent texture

Post by vimes »

Hi,
I've been trying to achieve this effect
Image
and to do that I created a quad to which I apply a material which is supposed to attach a ring texture (i.e. a transparent texture containing a ring which fades on the inside and the outside) and color the non transparent area (i.e. pixel of the texture with a not nil alpha value) thanks to the color values attached to each vertex of the quad.
In the end it should a ring of gradient.

Here is the code for the material, which is supposed to achieve this but is only making the quad completely transparent.

Code: Select all

material Sun/Test
{
	technique
	{
		pass 3
		{
			texture_unit
			{
				texture ring.png
			}
			scene_blend alpha_blend
			ambient vertexcolour
			depth_write off
			depth_check on
		}
	}
}
Here is the code for the quad

Code: Select all

atmosphereEffectNode = static_cast<SceneNode*>(sceneManager->getRootSceneNode()->createChild());
  	ManualObject* atmosphereQuad = sceneManager->createManualObject("AtmosphereEffect");	atmosphereQuad->begin("Sun/Test",RenderOperation::OT_TRIANGLE_STRIP);
	atmosphereQuad->position(Vector3(-2,-2,-1.1));
	atmosphereQuad->colour(Ogre::ColourValue::Red);
	atmosphereQuad->position(Vector3(-2,2,-1.1));
	atmosphereQuad->colour(Ogre::ColourValue::Red);
	atmosphereQuad->position(Vector3(2,-2,-1.1));
	atmosphereQuad->colour(Ogre::ColourValue::Blue);
	atmosphereQuad->position(Vector3(2,2,-1.1));
	atmosphereQuad->colour(Ogre::ColourValue::Black);
	atmosphereQuad->setVisible(true);
	atmosphereQuad->end();
	atmosphereEffectNode->attachObject(atmosphereQuad);
and here is the ring texture.
Image

Having studied the manual concerning the texture and the pass options I thought I knew how the material scripts worked but I must admit that I'm totally confused now :lol:
Could someone help me on this one, please?
Last edited by vimes on Thu Jun 15, 2006 10:30 am, edited 1 time in total.
PatrickB3
Greenskin
Posts: 101
Joined: Mon May 09, 2005 3:37 am
Location: California, USA

Post by PatrickB3 »

It is hard to see the ring texture on the site as it depends greatly on the file format. Using a texture for translucency only uses the alpha channel of the texture. For example Bitmaps do not have alpha channels so they don't work.

I have found .tga files from Photoshop work the best. .png files are iffy, sometimes they work from Paint Shop Pro other times no.

If you have access to PhotoShop, open up your ring texture. Add a alpha channel ( second button from the left I believe in the layer window, note sometimes you have to copy it to a new layer for the button to work ) and you should get a result. Also note that alphas should be grey scale. If you make a .tga in Photoshop it will make no difference what is in the RGB layer so you can leave that as is.
vimes
Gnoblar
Posts: 15
Joined: Fri May 19, 2006 5:00 am

Post by vimes »

Sooo, I modified several things which all together solved my problem
1- Use grayscale for the transparency levels (thx PatrickB3)
2 - Modified the material script

Code: Select all

material Sun/Test
{
	technique
	{
		
		pass 1 
		{
			scene_blend alpha_blend
			ambient vertexcolour
			depth_write off
			depth_check on
			texture_unit
			{
			
				colour_op alpha_blend 
				texture ring.png
			}
		}
	}
}
anc add texture coordinates to the manual object (I suspect the solid part of the texture to have been out of the quad for most of my test :roll: )
Post Reply