Material file question about alphas

Problems building or running the engine, queries about how to use features etc.
Bill
Gremlin
Posts: 167
Joined: Sun Sep 26, 2004 11:50 pm
Location: Arkansas

Material file question about alphas

Post by Bill »

I notice that the color entries use only red, green, and blue. For example:

diffuse 0.95 0.34 0.34

So it would seem that Ogre is not set up to use transparent textures as there is no alpha specified.

However, there are scene_blend and colour_op_ex operations that use alpha such as:

alpha_blend
one_minus_dest_alpha
blend_current_alpha
blend_diffuse_alpha

Now that suggests that there is the possibilty of using an alpha in your colors. I don't see how though. I would have thought that the color operations would be more like:

diffuse <red> <green> <blue> <alpha>

And since they are not, I am missing something. What am I missing?




Sinbad: On another note, I have found that there are realtime shader operations in XSI that closely match those in the material file.
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2

Post by Kencho »

It's done through the alpha_blend function. Using the manual alpha blend you can specify a certain alpha value :)
Image
User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

You *can* provide an alpha component for the diffuse color; this will be multiplied with the texture alpha to yield the final alpha of your object.

Of course, without alpha_blend, this alpha isn't used. Also, you need to set depth_write to off for transparant objects.
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2

Post by Kencho »

Is there an optional "alpha" parameter for diffuse? Great news! :D
Image
Bill
Gremlin
Posts: 167
Joined: Sun Sep 26, 2004 11:50 pm
Location: Arkansas

Post by Bill »

hmm OK. Is the manual out of date? Do the other colors have alphas? Is it like this:

ambient <red> <green> <blue> <alpha>
diffuse <red> <green> <blue> <alpha>
emissive <red> <green> <blue> <alpha>

Not sure how specular would be done. Maybe like this:

specular <red> <green> <blue> <alpha> <shininess>

Or for backwards compatability maybe this:

specular <red> <green> <blue> <shininess> <alpha>



I also don't see how to specify an alpha with the scene_blend alpha_blend operation. The manual doesn't say it takes a parameter, it just says the command is:

scene_blend alpha_blend

Which is equivalent to:

scene_blend src_alpha one_minus_src_alpha



fyi
The openGL real time shader in XSI sets things up like this (in a GUI though):

Ambient = <red> <green> <blue> <alpha>
Diffuse = <red> <green> <blue> <alpha>
Specular = <red> <green> <blue> <alpha>
Emissive = <red> <green> <blue> <alpha>
Shininess = <shininess factor>

e.g.

Ambient = 0.3 0.3 0.3 1
Diffuse = 0.5 0.5 0.5 1
Specular = 0.7 0.7 0.7 1
Emissive = 0 0 0 1
Shininess = 10

So each color has an alpha. And shininess is seperate from specular.
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

Post by sinbad »

All 4 pass colours can take an alpha, including specular. Ogre simply works out whether you supplied it based on the number of parameters. In all cases it follows the 'blue' value (so before the shininess value in specular). The manual doesn't mention this, so I'll update it for next time.

As for supplying an alpha value for scene_blend, you have to understand how GPUs work to realise why this isn't done.

GPUs have a vertex processing stage, a fragment processing stage, and then a final compositing stage with the contents of the frame buffer.

1. The diffuse, ambient, emissive and specular values affect the colour generated at the vertex processing stage.
2. The fragment processing stage then pulls in the vertex inputs interpolated over the face, and adds to it 2 calculations each texture unit - a colour operation and an alpha operation. (If you use pixel shaders this can be a lot more complex, but the principle is similar - there is some pretty flexible processing going on inside the fragment processor). The result of all these texture unit (or pixel shader) operations is a single colour in RGBA format.
3. The GPU then decides what to do with this final colour - it can just write it to the frame buffer (if the depth check passes), or it can perform a combination with the existing contents of the frame buffer. The operations available to composite the result with the frame buffer are much simpler than those available in the fragment processor. You only have 2 factors, a source and a destination factor, and the calculation is always srcColour * srcFactor + dstColour * dstFactor. The available factors are enumerated in the manual - those are the only ones the GPU allows, period. So you have to design the output colour of your more flexible fragment operations (in texture unit colour / alpha operations, or pixel shaders) to give you the values you need to perform a calculation against the frame buffer which the GPU will allow. Typically that means calculating alpha in the fragment processor (getting it from textures, or using manual parameters to alpha_operation_ex) and passing it down so that it comes out in the final colour.

As for shininess being separate from specular, that's fair enough but we combine it with specular since it's irrelevant to everything except specular colour.
Bill
Gremlin
Posts: 167
Joined: Sun Sep 26, 2004 11:50 pm
Location: Arkansas

Post by Bill »

ah excellent

Thanks
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2

Post by Kencho »

I mispelled. O wanted to use alpha_operation_ex instead of alpha_blend. My fault
Image
Bill
Gremlin
Posts: 167
Joined: Sun Sep 26, 2004 11:50 pm
Location: Arkansas

Post by Bill »

What are the default alphas for ambient, diffuse, specular, and emissive?


Also, is the default RGB for emissive 1 0 0 as per the manual?

Thanks
User avatar
monster
OGRE Community Helper
OGRE Community Helper
Posts: 1098
Joined: Mon Sep 22, 2003 2:40 am
Location: Melbourne, Australia

Post by monster »

What are the default alphas for ambient, diffuse, specular, and emissive?

Judging by _parseColourValue in OgreMaterialSerializer.cpp, it's 1.0 for all of them;

Code: Select all

ColourValue _parseColourValue(StringVector& vecparams)
{
    return ColourValue(
        StringConverter::parseReal(vecparams[0]) ,
        StringConverter::parseReal(vecparams[1]) ,
        StringConverter::parseReal(vecparams[2]) ,
        (vecparams.size()==4) ? StringConverter::parseReal(vecparams[3]) : 1.0f ) ;
}
Also, is the default RGB for emissive 1 0 0 as per the manual?
No, it's 0 0 0 as per the manual;
http://www.ogre3d.org/docs/manual/manual_18.html#SEC40
Bill
Gremlin
Posts: 167
Joined: Sun Sep 26, 2004 11:50 pm
Location: Arkansas

Post by Bill »

monster wrote:
Oops. I must have looked at the example.