Shaders, Fog and Multipasses rendering

I am making a terrain demo.
I render the terrain in 6 passes (for 6 textures).
The first pass draw texture 1.
The other passes draw texture 2-6 over the previous one using blend func (one, one).

I use a vertex and a pixel shader to blend my terrain textures…

But my problem is that I dont know how make the fog working when there are multiple rendering pass and blend (one, one).

Please help if you have any idea ?? may be adding a 7th pass for the fog but I dont know how it is possible…

(PS: My fog work well when I render all the 6 textures in one pass in a vertex/pixel shader)

You’ll have to use a pass just to do fog.

Have you tried just enabling Fog for your first pass (or perhaps for your last pass)?

It works now.
I used glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA) and I write the fog color and alpha in the pixelshader.

I cant enable for just for the first or last patch since the passes are blended together.

The point is you add an extra pass at the end. With GL_ONE, GL_ONE blend fog cannot work unless your fog color is black.