AlphaState on Quad - changes brightness of texture

Hi all … me again, I'm afraid.



Just wondered if any of you might have any thoughts on this.



I'm just mucking about with texturing quads in the hopes that I might be able to make some passable vegetation. I've got a GLSL shader I'm using to texture the quad (that I will animate at some stage hopefully), but that's not the issue. The issue is that when I add an AlphaState to the quad, the brightness of the texture is increased. Yeah, I know, wierd, but check it out:





AlphaState OFF AlphaState ON


If anyone has any thoughts, that would be great.

Thanks


Mak

Here's the shader:



Vertex:


varying vec2 TexCoord;

void main() {
   TexCoord = gl_MultiTexCoord0.st;
   gl_Position = ftransform();
}



Frag:

uniform sampler2D texture;

varying vec2 TexCoord;

void main() {
   vec3 tex= texture2D(texture, TexCoord).rgb;
   gl_FragColor = vec4(tex, 1.0);
}



It's pretty simple  ;) It is a placeholder while I sort out this problem.


I'm lost on this one. I can't see why it isn't working.

What's your alphastate set to?  It looks like you are using color to blend instead of purely alpha.

Sorry, should have put this in the previous post:


AlphaState alpha = display.getRenderer().createAlphaState();
alpha.setBlendEnabled(true);
alpha.setSrcFunction(AlphaState.SB_SRC_ALPHA);
alpha.setDstFunction(AlphaState.DB_ONE);
alpha.setTestEnabled(true);
alpha.setTestFunction(AlphaState.TF_GREATER);
alpha.setEnabled(true);



Thanks

Mak


Edit: ps. The texture files are PNG files with Black set as the transparent color.

You get those kind of results because the fragment color is being multiplied by a value larger than 1.0, thus resulting in higher luminance.

To get 1.0, use SRC_ALPHA as the source blend function and ONE_MINUS_SRC_ALPHA as the destination blend function (SRC_ALPHA + ONE_MINUS_SRC_ALPHA = 1.0).

More information about blend functions: http://opengl.org/sdk/docs/man/xhtml/glBlendFunc.xml

Thanks guys, but I'm still having no joy. If I set my AlphaState as Momolo suggests:


AlphaState alpha = display.getRenderer().createAlphaState();
alpha.setBlendEnabled(true);
alpha.setSrcFunction(AlphaState.SB_SRC_ALPHA);
alpha.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
alpha.setTestEnabled(true);
alpha.setTestFunction(AlphaState.TF_GREATER);
alpha.setEnabled(true);



I get no transparency at all. (Just like the AlphaState OFF image above).

Mak
Makaveli said:

If I set my AlphaState as Momolo suggests:

Ehm.. It is MOMOKO, not MOMOLO :x

Makaveli said:

I get no transparency at all. (Just like the AlphaState OFF image above).

Does your image have an alpha channel?
Ehm.. It is MOMOKO, not MOMOLO


Huge apologies !! Typo !

It's a PNG image with a palette transparency. Is that not enough ?


Mak

Hm, can you post a link to it?

I’ve actually just changed Paint Shop Pro to save the PNG’s transparency to the alpha channel, rather than the palette. But still no joy. Here’s the image:



http://www.foursidedtriangle.com/deep/grass.png



It’s pretty shoddy, but I’m just experimenting  :wink:



Thanks





Mak

Well, those settings should be ok…  We use the same settings for alpha channel blended Text (without the test enabled.)  Perhaps it is your shader you said you are using to provide texture?

So I tried this myself using TestTerrainTrees as an example and applying your texture file and your alpha state code to the trees.  Here’s what I get:







It seems fine to me…  The only way I get something like your screenshot is if I use your old alphastate code:







I would start eliminating things from the equation (shaders first) until you can get the functionality you expect, then start adding things back in.

Wow. Thanks for taking the effort to look into this for me Ren. It's much appreciated. I shall do as you say and start removing code to get down to basics. I shall report back …



Thanks





Mak