Fog Causing Opaque Blendfuncs to be Transparent


(obsidian) #1

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:

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

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


// 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:

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

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.


(boddo) #2

i think its your blendfunc’s
kinda strange that it changes opacity in the fog.
both blendfuncs render the shader transparent, so I would think it would be slightly transparent either way with fog or without fog.
i think you need a TGA with its own alpha channel, and then put your first blendfunc under that stage.

maybe try this;

// 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 blend
// if the above looks weird try change blendfunc blend to blendfunc add
}
{
map textures/obsidian/window_frame.tga
alphaFunc GE128
blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
depthWrite
}
{
map $lightmap
rgbGen identity
blendFunc GL_DST_COLOR GL_ZERO
depthFunc equal
}
}

the second shader stage calls for window_frame.tga instead of window_factory.tga.
window frame should be a tga with its own alpha channel, and completely transparent where the glass is and full opacity where the window-frames/iron is.

idk if this is what you had in mind but i did a window frame similar before;
http://screenshots.filesnetwork.com/38/files2/87356_7.jpg
(shader;
textures/boddos_naboo/windows
{
surfaceparm nonopaque
surfaceparm trans
surfaceparm alphashadow
{
map textures/boddos_naboo/windows
alphaFunc GE128
blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
depthWrite
}
{
map $lightmap
rgbGen identity
blendFunc GL_DST_COLOR GL_ZERO
depthFunc equal
}
}
)


(zenith-ply) #3

Don’t mean to intrude on the question with a question but this confuses me as to the use of q3map_noFog command. Volumes marked with a shader containing this keyword will not be affected by fog.

I didn’t see it used anywhere here, so I was wondering about that.


(carnage) #4

just a thought but could it be something to do with the draw order of transparent textures and their effect on the depth buffer

unlike normal faces transparent faces requir any faces behind them to be drawn before they can calculate how to draw themselves. IIRC transparent faces dont by default draw values to the depth buffer and im not sure how enviroment fog calculates its values in the engine but that since the depth buffer stores the distance of each pixel to the camera origin it might have something to do with it

maby experiment by adding a command to the shader to force depth buffer drawing


(lalitearns) #5

Hello,

i dont understand?
it simply display HTML.

why?