Transparency with lightmap

Discussion for Level editing, modeling, programming, or any of the other technical aspects of Quake
Post Reply
User avatar
Eraser
Posts: 19174
Joined: Fri Dec 01, 2000 8:00 am

Transparency with lightmap

Post 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.
kaffee
Posts: 15
Joined: Fri Jul 31, 2009 9:15 am

Re: Transparency with lightmap

Post 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
kaustic
Posts: 184
Joined: Wed Mar 09, 2011 5:10 pm

Re: Transparency with lightmap

Post 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.
User avatar
Eraser
Posts: 19174
Joined: Fri Dec 01, 2000 8:00 am

Re: Transparency with lightmap

Post 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 :)
User avatar
Eraser
Posts: 19174
Joined: Fri Dec 01, 2000 8:00 am

Re: Transparency with lightmap

Post 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.
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Re: Transparency with lightmap

Post 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?
[size=85][url=http://gtkradiant.com]GtkRadiant[/url] | [url=http://q3map2.robotrenegade.com]Q3Map2[/url] | [url=http://q3map2.robotrenegade.com/docs/shader_manual/]Shader Manual[/url][/size]
User avatar
Eraser
Posts: 19174
Joined: Fri Dec 01, 2000 8:00 am

Re: Transparency with lightmap

Post 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.
User avatar
MKJ
Posts: 32581
Joined: Fri Nov 24, 2000 8:00 am

Re: Transparency with lightmap

Post by MKJ »

frofl, is that the sample flower from adobe?
User avatar
Eraser
Posts: 19174
Joined: Fri Dec 01, 2000 8:00 am

Re: Transparency with lightmap

Post by Eraser »

I dunno. Don't think so. It's a texture I found over at cgtextures.com
Bliccer
Posts: 341
Joined: Thu Nov 26, 2009 4:27 pm

Re: Transparency with lightmap

Post 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
User avatar
CZghost
Posts: 1943
Joined: Wed Jun 22, 2011 1:45 pm
Location: Czechia
Contact:

Re: Transparency with lightmap

Post 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...
Last edited by CZghost on Mon May 13, 2013 3:21 pm, edited 1 time in total.
[ Linktree | Twitch | YouTube | Instagram | Websites ]
When you feel the worst, turn to the sun and all the shadows will fall behind you.” - John Lennon
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Re: Transparency with lightmap

Post 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.
[size=85][url=http://gtkradiant.com]GtkRadiant[/url] | [url=http://q3map2.robotrenegade.com]Q3Map2[/url] | [url=http://q3map2.robotrenegade.com/docs/shader_manual/]Shader Manual[/url][/size]
User avatar
CZghost
Posts: 1943
Joined: Wed Jun 22, 2011 1:45 pm
Location: Czechia
Contact:

Re: Transparency with lightmap

Post 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...
[ Linktree | Twitch | YouTube | Instagram | Websites ]
When you feel the worst, turn to the sun and all the shadows will fall behind you.” - John Lennon
Post Reply