## Recommended Posts

Ilici    862
Ok I've got a problem with fading out an impostor billboard using some kind of alpha value. The problem is that I need (must) use the blending factors GL_ONE and GL_ONE_MINUS_SRC_ALPHA for the texture to blend correctly. This is because of the texture which is created by splatting a special texture for creating clouds (see Harris' cloud rendering articles). I can't use a different texture. Setting the blend factors to GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA will result in the billboard showing some nasty transparency effects. So is there a way to get my texture to blend with the framebuffer behind to fade from fully transparent to fully opaque? Simply setting alpha will whiten the billboard when alpha is anything less than one because of the blend factors. Is there some trick I can pull? I thought that the blending does Cr = Cs + Cd * (1 - As), but I need Cr now to fade out using As too. This is how it looks with SRC_ALPHA, ONE_MINUS_SRC_ALPHA: That's not very nice ! And how it looks good with ONE, ONE_MINUS_SRC_ALPHA: Much better but no fading possible: [Edited by - Ilici on June 5, 2005 4:40:32 AM]

##### Share on other sites
OrangyTang    1298
What artifacts are you seeing with SRC_ALPHA? It depends on your actual texture, but perhaps GL_EXT_blend_equation_separate might be suitable?

##### Share on other sites
Ilici    862
Quote:
 Original post by OrangyTangWhat artifacts are you seeing with SRC_ALPHA? It depends on your actual texture, but perhaps GL_EXT_blend_equation_separate might be suitable?

My card doesn't support that extension :(

Also see above pictures.

##### Share on other sites
baldurk    1028
It looks like the filtering on the texture is blending the opaque part of the texture (the cloud) with the transparent background (black)?

If that's the case you should try creating the transparent background with a colour similar to the rest of the image, like a light grey. Otherwise, try using linear filtering.

Just a couple of suggestions.

##### Share on other sites
Ilici    862
Quote:
 Original post by baldurkIt looks like the filtering on the texture is blending the opaque part of the texture (the cloud) with the transparent background (black)?If that's the case you should try creating the transparent background with a colour similar to the rest of the image, like a light grey. Otherwise, try using linear filtering.Just a couple of suggestions.

Nope, it's not a filtering problem, the impostor texture isn't color keyed, but has an alpha channel. Basically it is created by splatting rgba splat textures (linear falloff from the middle) onto the framebuffer cleared with 0, 0, 0, 0. One thing would be to change the splat texture so it works with src_alpha, 1 - src_alpha blending but I don't think that's possible.

##### Share on other sites
baldurk    1028
Quote:
Original post by Ilici
Quote:
 Original post by baldurkIt looks like the filtering on the texture is blending the opaque part of the texture (the cloud) with the transparent background (black)?If that's the case you should try creating the transparent background with a colour similar to the rest of the image, like a light grey. Otherwise, try using linear filtering.Just a couple of suggestions.

Nope, it's not a filtering problem, the impostor texture isn't color keyed, but has an alpha channel. Basically it is created by splatting rgba splat textures (linear falloff from the middle) onto the framebuffer cleared with 0, 0, 0, 0. One thing would be to change the splat texture so it works with src_alpha, 1 - src_alpha blending but I don't think that's possible.

AFAIK, mipmapping will still "bleed" the background colour into the image, even if it's 0 alpha.

I'm actually doing something similar myself - rendering a 3D image, then using readpixels to get the image into a 2D texture which I can use for an impostor at long range.

Not meaning to derail the thread but does anyone know how to get that 2D image to have a transparent background? I have clearcolor 0,0,0,0 the same as Ilici, but the data I get from readpixels has alpha 255 over the whole image. It's not a problem because I can run through and set all black pixels to 0 alpha, but it's a hassle if I want to use glcopyteximage2D.

##### Share on other sites
JohnBSmall    881
Quote:
 Original post by baldurkNot meaning to derail the thread but does anyone know how to get that 2D image to have a transparent background? I have clearcolor 0,0,0,0 the same as Ilici, but the data I get from readpixels has alpha 255 over the whole image. It's not a problem because I can run through and set all black pixels to 0 alpha, but it's a hassle if I want to use glcopyteximage2D.

I suspect that you could do it by setting up the pixel transfer modes correctly, although I'm not sure.

John B

##### Share on other sites
baldurk    1028
Quote:
 Original post by JohnBSmallI suspect that you could do it by setting up the pixel transfer modes correctly, although I'm not sure.John B

Hmm I looked at the relevant manpages, and it seems the values I'm looking at are GL_ALPHA_SCALE and GL_ALPHA_BIAS. Where read_alpha = actual_alpha * alpha_scale + alpha_bias. Unfortunately the scale is 1 and the bias is 0, so I should be reading the actual alpha value.

##### Share on other sites
Ilici    862
Quote:
 Original post by baldurkI'm actually doing something similar myself - rendering a 3D image, then using readpixels to get the image into a 2D texture which I can use for an impostor at long range.Not meaning to derail the thread but does anyone know how to get that 2D image to have a transparent background? I have clearcolor 0,0,0,0 the same as Ilici, but the data I get from readpixels has alpha 255 over the whole image. It's not a problem because I can run through and set all black pixels to 0 alpha, but it's a hassle if I want to use glcopyteximage2D.

Why glReadPixels? This is done with glCopyTexSubImage2D.. Make sure that the texture and framebuffer are RGBA.

	if (glIsTexture(Cloud->ImpostorTex) == GL_FALSE)	{		glGenTextures(1, &Cloud->ImpostorTex);		glBindTexture(GL_TEXTURE_2D, Cloud->ImpostorTex);		glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, ViewportSize, ViewportSize, 0);				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);		}	else	{		glBindTexture(GL_TEXTURE_2D, Cloud->ImpostorTex);		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, ViewportSize, ViewportSize);	}

Quote:
 AFAIK, mipmapping will still "bleed" the background colour into the image, even if it's 0 alpha.

No mipmapping is used :D I switch impostor resolution manually when creating the impostor so mipmapping wouldn't even help and would cost a lot to generate on the fly (maybe the specialized extension could help you if you really need them).

##### Share on other sites
baldurk    1028
Quote:
Original post by Ilici
Quote:
 Original post by baldurkI'm actually doing something similar myself - rendering a 3D image, then using readpixels to get the image into a 2D texture which I can use for an impostor at long range.Not meaning to derail the thread but does anyone know how to get that 2D image to have a transparent background? I have clearcolor 0,0,0,0 the same as Ilici, but the data I get from readpixels has alpha 255 over the whole image. It's not a problem because I can run through and set all black pixels to 0 alpha, but it's a hassle if I want to use glcopyteximage2D.

Why glReadPixels? This is done with glCopyTexSubImage2D.. Make sure that the texture and framebuffer are RGBA.

*** Source Snippet Removed ***

Haha, after a day or two tearing my hair out it turns out that when I got my window the default alpha size was 0. I've set it to 8 and it's working perfectly now. The reason I wasn't using glCopyTexSubImage2D is because I couldn't :D. Thanks a lot

Quote:

Quote:
 AFAIK, mipmapping will still "bleed" the background colour into the image, even if it's 0 alpha.

No mipmapping is used :D I switch impostor resolution manually when creating the impostor so mipmapping wouldn't even help and would cost a lot to generate on the fly (maybe the specialized extension could help you if you really need them).

What filtering method are you using? is it just linear? See if setting the background to white before rendering the cloud makes any difference at all anyway. Sometimes weird things work :).

##### Share on other sites
Ilici    862
Quote:
 Original post by baldurkWhat filtering method are you using? is it just linear? See if setting the background to white before rendering the cloud makes any difference at all anyway. Sometimes weird things work :).

I tried setting the background clear color to white when rendering the impostor and tried both ONE and SRC_ALPHA for the source factor, they don't work. My hat is all out of weird things to pull out [sad]

Here's the impostor texture with alpha, maybe someone can figure out how to fade it nicely:

##### Share on other sites
baldurk    1028
Looks like the problem lies in your texture generation. Here's a blown up view of it in the gimp on my system:

I did a real quick erase of the black semi-transparent haze and whipped up an app to show the difference:

So it seems that black is creeping in there. I assume there's no black in your rendering of the cloud. I'm guessing here, but maybe when blending the rendered cloud with the 0,0,0,0 frame buffer created it? I don't know why it would still do that if you set the framebuffer to 1,1,1,0 though.

One solution I guess would be what I did and make it so that you get the texture data and loop through it going a=(r+g+b)/3 on it, but that's a lot slower.

##### Share on other sites
Ilici    862
Well the edge is, though a little less visible, still present. The cloud must be blended with 1, 1 - SRC_ALPHA and I have no idea how to make it fade then. My simulation will have to do without switching from the impostor billboard to the 3d particles :(.

Maybe something could be done with the combiner but I'm not sure the combiner does it's thing after blending, otherwise it wouldn't work. I'm guessing what I want is this:

Result = (Incoming + Destination * (1 - IncomingAlpha)) * IncomingAlpha;

##### Share on other sites
baldurk    1028
Quote:
 Original post by IliciWell the edge is, though a little less visible, still present. The cloud must be blended with 1, 1 - SRC_ALPHA and I have no idea how to make it fade then. My simulation will have to do without switching from the impostor billboard to the 3d particles :(.Maybe something could be done with the combiner but I'm not sure the combiner does it's thing after blending, otherwise it wouldn't work. I'm guessing what I want is this:Result = (Incoming + Destination * (1 - IncomingAlpha)) * IncomingAlpha;

Well the edge is still visible because I did a quick erase to remove the worst of it. If you removed all the black, then I'd think that it would disappear entirely.

##### Share on other sites
hplus0603    11356
This is the difference between images generated for alpha (which would be mostly white), and images generated with pre-multiplied alpha (which is what you have). GL_ONE, GL_ONE_MINUS_SRC_ALPHA is the pre-multiplied alpha blending function. Just learn to love it and live with it -- it's the least incorrect options.

It's somewhat un-clear what you mean by wanting to "fade out" with pre-multiplied alpha. If you want to make some parts fade towards black, then just put black into the rendered image, but make the alpha strong.

##### Share on other sites
OrangyTang    1298
I may be being stupidly obtuse here, but couldn't you just use ONE,ONE_MINUS as you are doing, then fade the vertex colours to black to fade out?

##### Share on other sites
Ilici    862
I mean I want it to fade from opaque to completely transparent.

Thanks to hplus0603 for sorting me out.

##### Share on other sites
zedzeek    529
try this
fade the color out as well

draw cloud

##### Share on other sites
Ilici    862
Quote:
 Original post by OrangyTangI may be being stupidly obtuse here, but couldn't you just use ONE,ONE_MINUS as you are doing, then fade the vertex colours to black to fade out?

Quote:

Omg, that works! Seriously, I thought I tried that but it seems I did something wrong the previous time. Thanks to the both of you, 10x!

Shots:
Full Impostor:

Approx half half:

Full 3D:

[Edited by - Ilici on June 5, 2005 4:33:34 PM]

##### Share on other sites
Guest Anonymous Poster
Quote:

## Create an account

Register a new account