Page 1 of 1

Transparency with lightmap

Posted: Sat May 11, 2013 2:48 pm
by Eraser
I can't figure out how to get my TGA texture with transparency to show up correctly in-game.

I've got a texture of a flower. The background is transparent (through alpha channel). I've got the following shader for it:

Code: Select all

textures/ep_survival/flower1
{
	qer_editorimage textures/ep_survival/Flowers0048_2_S.tga/
	surfaceparm trans
	{
		map textures/ep_survival/Flowers0048_2_S.tga
		blendFunc blend
	}
	{
		map $lightmap
		rgbGen identity
		blendFunc filter
	}	
}
At first I had forgotten to include the lightmap stage, but the flowers would show up in fullbright. I then included the lightmap stage, but the result is as follows:

Image

I want to get rid of the dark squares surrounding the flowers (in brighter lit areas of the map, the squares aren't visible (or less visible)). Anyone know how to do this? The flower texture is applied to a small, thin brush that's positioned right on top of the grass surface.

Re: Transparency with lightmap

Posted: Sat May 11, 2013 3:28 pm
by kaffee
Hey. pretty simple, you can delete the blendfunc and add just the "alphafunc ge128" and apply an alphachannel to the tga. everything thats black wont be drawn(you know for sure the technical background.) any other method will cause ugly results.
mfg kaffeewunder

Re: Transparency with lightmap

Posted: Sat May 11, 2013 4:40 pm
by kaustic
I don't know a whole lot about shaders but in the map I just finished I had the same problem
and what I did to fix it was to get rid of the alpha channel and make it a negative image but
the shader isn't the same so that may not work in your case.

Re: Transparency with lightmap

Posted: Sat May 11, 2013 5:16 pm
by Eraser
kaffee wrote:Hey. pretty simple, you can delete the blendfunc and add just the "alphafunc ge128" and apply an alphachannel to the tga. everything thats black wont be drawn(you know for sure the technical background.) any other method will cause ugly results.
mfg kaffeewunder
thx, will try :)

Re: Transparency with lightmap

Posted: Sat May 11, 2013 5:17 pm
by Eraser
kaustic wrote:I don't know a whole lot about shaders but in the map I just finished I had the same problem
and what I did to fix it was to get rid of the alpha channel and make it a negative image but
the shader isn't the same so that may not work in your case.
Yeah that works with decals but there the entire texture is blended which kind of makes the decal not entirely opaque. I used this shader technique for the decals in my map, like stains or patches of dirt on the grass.

Re: Transparency with lightmap

Posted: Sun May 12, 2013 12:55 am
by obsidian
kaffee wrote:Hey. pretty simple, you can delete the blendfunc and add just the "alphafunc ge128" and apply an alphachannel to the tga. everything thats black wont be drawn(you know for sure the technical background.) any other method will cause ugly results.
mfg kaffeewunder

This is correct. You need to do an alpha-test, which basically says, take the texture's alpha channel and save it to the buffer, then also apply the same alpha channel to the lightmap stage as well. All the grates and other effects in Q3 work the same. The only pitfall is that it will not work if you have a full 8-bit alpha channel, where the texture requires different levels of opacity per pixel. alphaFunc is an all or nothing test, so a alpha channel pixel is either 100% opaque or 100% transparent and otherwise rounds the value to the nearest 1 or 0 value.

Another alternative if you absolutely need a full 8-bit alpha channel is to simply vertex light the surface or set a constant vertex colour value that approximates the lighting in the area. Then you can use a normal blendFunc blend and skip the lightmap stage altogether.

Are you making a 60's themed map full of hippies?

Re: Transparency with lightmap

Posted: Sun May 12, 2013 7:12 am
by Eraser
So here's my new shader:

Code: Select all

textures/ep_survival/flower1
{
   qer_editorimage textures/ep_survival/Flowers0048_2_S.tga/
   surfaceparm trans
   {
      map textures/ep_survival/Flowers0048_2_S.tga
      alphafunc ge128
   }
   {
      map $lightmap
      rgbGen identity
      blendFunc filter
   }   
}
It works properly, but they do look a bit cardboard-cut-out-ey, but that's probably due to the everything or nothing way of how the alpha channel works. I guess it's good enough as it is now.

Re: Transparency with lightmap

Posted: Mon May 13, 2013 7:46 am
by MKJ
frofl, is that the sample flower from adobe?

Re: Transparency with lightmap

Posted: Mon May 13, 2013 7:59 am
by Eraser
I dunno. Don't think so. It's a texture I found over at cgtextures.com

Re: Transparency with lightmap

Posted: Mon May 13, 2013 8:23 am
by Bliccer
Eraser wrote:It works properly, but they do look a bit cardboard-cut-out-ey, but that's probably due to the everything or nothing way of how the alpha channel works. I guess it's good enough as it is now.
You can get rid of this effect if you color the background similiar to your object (dark green here).
Quick lookup here: http://www.cgtextures.com/content.php?a ... me=alphabg

Re: Transparency with lightmap

Posted: Mon May 13, 2013 3:17 pm
by CZghost
Bliccer wrote:You can get rid of this effect if you color the background similiar to your object (dark green here).
Quick lookup here: http://www.cgtextures.com/content.php?a ... me=alphabg
He means the black square around the flower made by lightmap. Pretty ugly, the solution is to alphatest the flower with alphaFunc GE128 in the shader without soft blending (edges will be nasty sharp, as it was a model placed on the floor... That way it should look much better than with soft transition using soft blending with use of lightmap stage it's the case now in his EntityPlus map Survivour.

@Eraser:

Code: Select all

textures/ep_survival/flower1
{
   qer_editorimage textures/ep_survival/Flowers0048_2_S.tga/
   surfaceparm trans
   {
      map textures/ep_survival/Flowers0048_2_S.tga
      alphafunc ge128
      depthWrite
   }
   {
      map $lightmap
      rgbGen identity
      blendFunc filter
      depthFunc equal
   }   
}
That will work much better...

Re: Transparency with lightmap

Posted: Mon May 13, 2013 3:19 pm
by obsidian
Yeah, what Bliccer said. I'm surprised how this isn't standard practice even among commercial game textures.

Also, if you're just placing those flowers on the ground like decals, that's not very realistic (I'm not sure if you're just testing the texture like that). Real flowers have stems and some sort of plant that it's attached to. It doesn't have to be particularly detailed, but just something to suggest that it's growing out of the ground.

Re: Transparency with lightmap

Posted: Mon May 13, 2013 3:55 pm
by CZghost
@obsidian:
An arcade styled map doesn't need to give a realistic feel to the level. Flowers also doesn't have to float in the air on stems, but can grow near the grass ground...