Fog Causing Opaque Blendfuncs to be Transparent

Discussion for Level editing, modeling, programming, or any of the other technical aspects of Quake
Post Reply
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Fog Causing Opaque Blendfuncs to be Transparent

Post by obsidian »

I'm having difficulty with blendFuncs and fog, where a window frame that is supposed to be opaque turns transparent only when it is enveloped by fog. I'll explain...

Here is my texture:
Image

And the alpha channel for the texture (note that the frame is set to be 100% opaque):
Image

Here are the actual shaders, pretty ordinary, nothing special:

Code: Select all

// Factory Window
textures/obsidian/window_factory
{
	surfaceparm alphashadow
	surfaceparm lightfilter
	surfaceparm trans
	qer_alphaFunc gequal 0.5
	{
		map textures/obsidian/envmap/iron.tga
		tcGen environment
		blendFunc add
	}
	{
		map textures/obsidian/window_factory.tga
		blendFunc blend
	}
	{
		map $lightmap
		blendFunc filter
		tcGen lightmap
	}
}


// Global fog
textures/obsidian/fog
{
	fogparms ( 0.1314 0.1647 0.1873 ) 4096	//R:134 G:168 B:191
	surfaceparm fog
	surfaceparm nolightmap
	surfaceparm nodlight
	surfaceparm trans
	qer_editorImage textures/obsidian/white.tga
	qer_trans 0.5
}
With fog in the map, you can see the gear in the background not just where the glass is, but also through the frame. The frame becomes more transparent the further you are away from it:
Image

Removing the fog, the frame is opaque as I would expect it to be (not a good screenshot, but take my word for it):
Image




Any ideas on how to fix this? I'm sure it has something to do with the blendFunc and setting it to some other explicit blendFunc, but after a bit of trial and error my head hurts.
[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]
fKd
Posts: 2478
Joined: Sat Jun 03, 2006 2:54 am
Location: Wellington
Contact:

Re: Fog Causing Opaque Blendfuncs to be Transparent

Post by fKd »

since its a nice square frame, could you not make it out of brushes? but it does seem odd, i need to learn how to make shaders, so i cant really help sorry :/

bloody nice textures btw, hope ya release a pack for us
rgoer
Posts: 798
Joined: Sun Aug 17, 2003 7:00 am

Re: Fog Causing Opaque Blendfuncs to be Transparent

Post by rgoer »

you should do the frame and the glass in separate passes in your shader

blendfunc for the glass

alphafunc for the frame

blendfunc means no z-write, which confuses fog (or maybe fog confuses it?)

alphafunc writes z so fog should be perfectly happy
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Re: Fog Causing Opaque Blendfuncs to be Transparent

Post by obsidian »

Not quite there... here's the shader:

Code: Select all

textures/obsidian/window_factory
{
	surfaceparm alphashadow
	surfaceparm lightfilter
	surfaceparm trans
	qer_alphaFunc gequal 0.5
	{
		map textures/obsidian_steampunk/envmap/iron.tga
		blendFunc add
		tcGen environment
	}
	{
		map textures/obsidian/blends/window_factory_glass.tga
		blendFunc blend
	}
	{
		map textures/obsidian/window_factory.tga
		alphaFunc GE128
		depthWrite
	}
	{
		map $lightmap
		blendFunc filter
		tcGen lightmap
	}
}
Now the surface is not affected by fog at all, so at a distance, everything else is occluded by the fog except the window and frame. Placing any stage before the alphaFunc stage causes the entire shader to be unaffected by fog. I tried reordering the shader like so...

Code: Select all

textures/obsidian/window_factory
{
	surfaceparm alphashadow
	surfaceparm lightfilter
	surfaceparm trans
	qer_alphaFunc gequal 0.5
	{
		map textures/obsidian/window_factory.tga
		alphaFunc GE128
		depthWrite
	}
	{
		map textures/obsidian_steampunk/envmap/iron.tga
		blendFunc add
		tcGen environment
	}
	{
		map textures/obsidian/blends/window_factory_glass.tga
		blendFunc blend
	}
	{
		map $lightmap
		blendFunc filter
		tcGen lightmap
	}
}
... so now fog works as you would expect it to but (I think) the environment map stage causes some pretty strange artifacts that's I'm not sure about the cause of. It seems to pick random surfaces behind the glass and paints them that light blue tinge from the envmap. That trapezoid brush in the middle is textured entirely with the same texture, so it's not a sorting issue. :dork:

Image

I can put together a zip file with the contents of the stuff in question if anyone wants to have a go at it.
[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]
rgoer
Posts: 798
Joined: Sun Aug 17, 2003 7:00 am

Re: Fog Causing Opaque Blendfuncs to be Transparent

Post by rgoer »

try adding a sort opaque keyword to your shader... from the q3 source tr_shader.c:

Code: Select all

	// there are times when you will need to manually apply a sort to
	// opaque alpha tested shaders that have later blend passes
	if ( !shader.sort ) {
		shader.sort = SS_OPAQUE;
	}
[/color]
Post Reply