TheBasheR
24-07-2009 11:11:56
Hi all,
I would like to change the opacity of a texture applied to a ManualObject but I don't know how to do that. I tried this:
manualObject.GetSection(0).GetMaterial().GetTechnique(0).GetPass(0).SetAmbient(l_fadeFactor, l_fadeFactor, l_fadeFactor);
With l_fadeFactor between 0 and 1 but it does not work, the texture opacity doesn't change.
Did I do something wrong? Is there another way to change the opacity of a texture?
Thanks a lot for your help.
TheBasheR
28-07-2009 14:38:34
Nobody has an idea? I just would like to change the alpha channel of a texture.
smiley80
28-07-2009 15:00:01
Pass p = manualObject.GetSection(0).GetMaterial().GetTechnique(0).GetPass(0);
p.SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA);
for (int i = 0; i < p.NumTextureUnitStates; i++)
{
p.GetTextureUnitState(i).SetAlphaOperation(LayerBlendOperationEx.LBX_MODULATE, LayerBlendSource.LBS_MANUAL, LayerBlendSource.LBS_TEXTURE, l_fadeFactor);
}
SetAmbient sets the ambient colour (hence the name). You can use that for tinting a texture.
TheBasheR
28-07-2009 16:36:52
Thank you it's better. Now I have my fade effect

But there is now another problem, the texture seems cut in 2 parts, maybe because a rectangle is cut in 2 triangles, but when i change the alpha channel of my textureunit the transparency is different for the 2 parts, so we can see the cut line
Do you know why? and how i can solve this problem?
Thanks a lot.
smiley80
29-07-2009 21:13:42
Can you post the code you use to create the ManualObject?
TheBasheR
29-07-2009 22:29:36
This is the code to create the ManualObject:
string l_matName = "QuadMaterial";
ManualObject l_obj = m_sceneManager.CreateManualObject(name);
l_obj.Begin(l_matName, RenderOperation.OperationTypes.OT_TRIANGLE_STRIP);
l_obj.Position(-.5f, .5f, 1.0f);
l_obj.TextureCoord(1, 0);
l_obj.Position(-.5f, -.5f, 1.0f);
l_obj.TextureCoord(1, 1);
l_obj.Position(.5f, -.5f, 1.0f);
l_obj.TextureCoord(0, 1);
l_obj.Position(.5f, .5f, 1.0f);
l_obj.TextureCoord(0, 0);
l_obj.Index(0);
l_obj.Index(1);
l_obj.Index(2);
l_obj.Index(3);
l_obj.Index(0);
l_obj.End();
l_obj.UseIdentityProjection = false;
l_obj.UseIdentityView = false;
l_obj.RenderQueueGroup = (byte)RenderQueueGroupID.RENDER_QUEUE_MAIN;
And this is the code to apply the texture:
MaterialPtr l_mat = manualObject.GetSection(0).GetMaterial();
Technique l_tech = l_mat.GetTechnique(0);
Pass l_pass = l_tech.GetPass(0);
l_pass.GetTextureUnitState(0).SetTextureName(l_texFilename);
Thank you for your help
smiley80
29-07-2009 23:17:09
It looks fine from the front (I'm using a texture and material script from the SDK), but the back is cut in half, which can be fixed with:
l_mat.SetCullingMode(CullingMode.CULL_NONE);
If that doesn't fix it, post the 'QuadMaterial' script.
TheBasheR
30-07-2009 22:46:44
It changes nothing
This is the code I use now with your solution:
string l_matName = "QuadMaterial";
ManualObject l_obj = m_sceneManager.CreateManualObject(name);
l_obj.Begin(l_matName, RenderOperation.OperationTypes.OT_TRIANGLE_STRIP);
l_obj.Position(-.5f, .5f, 1.0f);
l_obj.TextureCoord(1, 0);
l_obj.Position(-.5f, -.5f, 1.0f);
l_obj.TextureCoord(1, 1);
l_obj.Position(.5f, -.5f, 1.0f);
l_obj.TextureCoord(0, 1);
l_obj.Position(.5f, .5f, 1.0f);
l_obj.TextureCoord(0, 0);
l_obj.Index(0);
l_obj.Index(1);
l_obj.Index(2);
l_obj.Index(3);
l_obj.Index(0);
l_obj.End();
l_obj.UseIdentityProjection = false;
l_obj.UseIdentityView = false;
l_obj.RenderQueueGroup = (byte)RenderQueueGroupID.RENDER_QUEUE_MAIN;
l_obj.GetSection(0).GetMaterial().SetCullingMode(CullingMode.CULL_NONE);
I have no material script, i just create my ManualObject with the code above but i don't specify any material script. Or maybe i missed something?
TheBasheR
31-07-2009 18:24:42
Sorry actually i have the material script, but the material is initialized in the code.
This is the code that creates the material:
string l_matName = "QuadMaterial";
MaterialPtr l_mat = (MaterialPtr)MaterialManager.Singleton.Create(l_matName, "General");
l_mat.SetCullingMode(CullingMode.CULL_NONE);
l_mat.SetAmbient(1.0f, 1.0f, 1.0f);
l_mat.SetLightingEnabled(false);
Technique l_tech = l_mat.GetTechnique(0);
Pass l_pass = l_tech.GetPass(0);
l_pass.CreateTextureUnitState();
if (!l_mat.IsLoaded)
{
MaterialManager.Singleton.Load(l_matName, "General");
}
Thank you for your help.
TheBasheR
31-07-2009 18:57:48
I searched a bit, trying to change some parts of the code i see the result, and finally I've just solved my bug.
The order when creating the ManualObject was wrong, so I changed it and now it works.
This is the working code:
string l_matName = "QuadMaterial";
ManualObject l_obj = m_sceneManager.CreateManualObject(name);
l_obj.Begin(l_matName, RenderOperation.OperationTypes.OT_TRIANGLE_STRIP);
l_obj.Position(-.5f, .5f, 1.0f);
l_obj.TextureCoord(1, 0);
l_obj.Position(-.5f, -.5f, 1.0f);
l_obj.TextureCoord(1, 1);
l_obj.Position(.5f, .5f, 1.0f);
l_obj.TextureCoord(0, 0);
l_obj.Position(.5f, -.5f, 1.0f);
l_obj.TextureCoord(0, 1);
l_obj.End();
l_obj.UseIdentityProjection = false;
l_obj.UseIdentityView = false;
l_obj.RenderQueueGroup = (byte)RenderQueueGroupID.RENDER_QUEUE_MAIN;
l_obj.GetSection(0).GetMaterial().SetCullingMode(CullingMode.CULL_NONE);
Thank you for your help