Google

Setting alpha colour value of ambient texture?? [solved]

Problems building or running the engine, queries about how to use features etc.

Moderators: Moderators, OGRE Team

Setting alpha colour value of ambient texture?? [solved]

Postby gerds » Wed Sep 06, 2006 10:04 am

I want to implement an effect that uses the 'alpha' colour value of a material. In the old engine we use the following code to do the effect:

// calc the alpha value
float alpha = "some code"

// set the color
glColor4f(1.0f, 1.0f, 1.0f, alpha)

// render the polys
glBegin(GL_TRIANGLES)
"etc...etc..."
glEnd()

I've porting the engine to use ogre and I need to do something like this:

(given Ogre::MaterialPtr m_pmaterial)

// calc the alpha value
float alpha = "some code"

// set the materials colour
m_pmaterial->setAmbient(1.0f, 1.0f, 1.0f, alpha)

however the Ogre::Material classes setAmbient only takes 3 parameters (red, green, and blue), - no alpha?

How can I do this in ogre? hm....
Last edited by gerds on Fri Sep 08, 2006 5:33 am, edited 1 time in total.
User avatar
gerds
Veteran
 
Posts: 288
Joined: Mon Sep 01, 2003 3:59 am
Location: London, United Kingdom

Postby haffax » Wed Sep 06, 2006 10:10 am

Use the setAmbient overload, that takes a ColourValue as input parameter.
team-pantheon programmer
creators of Rastullahs Lockenpracht
User avatar
haffax
OGRE Moderator
OGRE Moderator
 
Posts: 5069
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany

Postby gerds » Thu Sep 07, 2006 2:29 am

Thanks, now I have the problem that no matter what values I put in the setAmbient parameters it has no effect on the output what-so-ever. There must be a problem with referencing the wrong material??

Here's the code used to create the object and get a reference to the material

Code: Select all
static const char* SUNGLARE_MATERIAL = "material Sydac/Sunglare";

// create the 'sunglare plane' 3dmodel in ogre
    Ogre::Plane sunglare_plane;
    sunglare_plane.normal = Ogre::Vector3::UNIT_Z;
   sunglare_plane.d = 0.0f;
    try
    {
        Ogre::MeshPtr pmesh = Ogre::MeshManager::getSingleton().createPlane("SunglarePlane",
            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, sunglare_plane,
            12.0f, 12.0f, 1, 1, false, 1, 1.0f, 1.0f, Ogre::Vector3::UNIT_Y);
        if (pmesh.isNull())
        {
            LOG_ERROR << "Failed to build the SunglarePlane 3dModel" << ENDLOG;
            return (false);
        }
    }
    catch(...)
    {
        LOG_ERROR << "Exception raised building the SunglarePlane 3dModel" << ENDLOG;
        return (false);
    }
   
    // create the entity using the SunglarePlane 3dmodel
    try
    {
        m_pogre_entity = OgreScene()->createEntity("Effect_SunglarePlane", "SunglarePlane");
        if (NULL == m_pogre_entity)
        {
            LOG_ERROR << "Failed to create sunglare entity" << ENDLOG;
            return (false);
        }
    }
    catch(...)
    {
        LOG_ERROR << "Exception raised creating sunglare entity" << ENDLOG;
        return (false);
    }

    // set the material name
    try
    {
       m_pogre_entity->setMaterialName(SUNGLARE_MATERIAL);
    }
    catch(...)
    {
        LOG_ERROR << "Exception raised setting sunglare model material: " << SUNGLARE_MATERIAL << ENDLOG;
        return (false);
    }

    // get a reference to the material   
    m_pmaterial = Ogre::MaterialManager::getSingleton().getByName(SUNGLARE_MATERIAL);   
    if (m_pmaterial.isNull())
    {
        LOG_ERROR << "Failed to find effect material: " << SUNGLARE_MATERIAL << ENDLOG;
        return (false);
    }
    m_pmaterial->load();


Now at runtime when I want to adjust the amount of sunglare I should be able to just change the alpha value. However, no matter what values I pass to setAmbient it has no effect.

What is going wrong?

Code: Select all
      float alpha = "something";
      m_pmaterial->setAmbient(Ogre::ColourValue(1.0f, 1.0f, 1.0f, alpha));


Here's the material script
Code: Select all
material Sydac/Sunglare
{
   technique
   {
      pass
      {
         fog_override true none
         lighting off
         scene_blend alpha_blend
         depth_write off
         depth_check off
         texture_unit
         {
            texture SydacSunglare.png
         }
      }

   }

}
User avatar
gerds
Veteran
 
Posts: 288
Joined: Mon Sep 01, 2003 3:59 am
Location: London, United Kingdom

Postby Bontakun » Thu Sep 07, 2006 4:08 am

Operate on the diffuse color, instead of the ambient.
- Bonta (eveonline:Dentad)
User avatar
Bontakun
Veteran
 
Posts: 291
Joined: Tue Dec 09, 2003 6:09 am
Location: Melbourne, Australia

Postby gerds » Thu Sep 07, 2006 4:59 am

That doesn't have any effect either.

I think it may have something to do with the "lighting off" setting in the material file.

If i delete that setting then the effect is "effected" by the current ambient light for the scene (which I dont want) but still doesnt work.

Hmm...
User avatar
gerds
Veteran
 
Posts: 288
Joined: Mon Sep 01, 2003 3:59 am
Location: London, United Kingdom

Postby gerds » Thu Sep 07, 2006 5:11 am

Ok, I've worked out that if I leave lighting on (ie: dont set "lighting off") then setDiffuse does allow me to set the diffuse color and alpha values.

However, I dont want to turn lighting on for the material.

I also want to be able to use "scene_blend src_alpha one", instead of "scene_blend alpha_blend", in which case neither setAmbient, or setDiffuse do anything regardless of the "lighting" state.

Is this some kind of internal bug/limitation inside ogre?
I've certainly had no problems in the past doing this kind of thing, however, I've usually written my special effects directly in OpenGL.
User avatar
gerds
Veteran
 
Posts: 288
Joined: Mon Sep 01, 2003 3:59 am
Location: London, United Kingdom

Postby Bontakun » Thu Sep 07, 2006 5:58 am

I was in a similar situation to you. I had to leave lighting on and use the diffuse color to be able to change alpha values.

If you don't leave lighting on for the material then you wont get the lighting effects that you want. Why is having lighting on for the material a problem?

Are you calling
Code: Select all
{scene manager}->setAmbientLight( Ogre::ColourValue::White)
?
- Bonta (eveonline:Dentad)
User avatar
Bontakun
Veteran
 
Posts: 291
Joined: Tue Dec 09, 2003 6:09 am
Location: Melbourne, Australia

Postby gerds » Thu Sep 07, 2006 7:20 am

There are a few lighting effects I need to do.

"Sun glare" which will effect the viewer between sunrise and sunset.
At sunrise the ambient light will be low, however if you look in to the sun then the "sun glare" effect needs to white out the screen. This means that the ambient lighting cannot be taken in to account for this material.

The "sun glare" also needs to have a configurable level between 0 and 1, hence I need to be able to set the "alpha" value of the materials color.

We also have a "headlight" effect which is done a similar way, and once again the headlight material must have "lighting off" because ambient light will be very low at midnight, but the light must be seen.
User avatar
gerds
Veteran
 
Posts: 288
Joined: Mon Sep 01, 2003 3:59 am
Location: London, United Kingdom

Postby M » Thu Sep 07, 2006 11:20 am

Ambient, diffuse, specular colors are used for dynamic lighting, thus they doesn't work with lighting off.

To set material transparency by multiplying both texture and manual alpha: set lighting off, scene_blend alpha_blend, depth_write off, and set texture unit alpha/color operations:
Code: Select all
TextureUnitState* texture = material->getBestTechnique()->getPass(0)->getTextureUnitState(0);
Real value = 0.5;
texture->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_TEXTURE, Ogre::LBS_MANUAL, 1, value, 1);

To apply the effect I use a fullscreen overlay panel or quad (never tried Compositor). Search about it.
M
Regular
 
Posts: 198
Joined: Mon May 23, 2005 4:40 pm
Location: Spain

Postby gerds » Fri Sep 08, 2006 5:33 am

Thanks a heap :)

I ended up using setAlphaOperation for some effects, and setColourOperationEx for others and this worked as expected :)
User avatar
gerds
Veteran
 
Posts: 288
Joined: Mon Sep 01, 2003 3:59 am
Location: London, United Kingdom


Return to Help

Who is online

Users browsing this forum: Box5, Google [Bot], lilljohan, Mako_energy, rinesh_t and 5 guests