Jump to content
  • Advertisement
Sign in to follow this  

Fading out an impostor

This topic is 4733 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by baldurk
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.


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 this post


Link to post
Share on other sites
Quote:
Original post by Ilici
Quote:
Original post by baldurk
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.


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 this post


Link to post
Share on other sites
Quote:
Original post by baldurk
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.

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

John B

Share this post


Link to post
Share on other sites
Quote:
Original post by JohnBSmall
I 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 this post


Link to post
Share on other sites
Quote:
Original post by baldurk
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.


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 this post


Link to post
Share on other sites
Quote:
Original post by Ilici
Quote:
Original post by baldurk
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.


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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!