How to avoid fogged objects with stencil?

Hello,

I’m having trouble with the fog an stencil node.

I’m programming (DX11 renderer) a first-person view on an landscape which disappears in fog. But the sky should still be visible without fog.

I learned from an older forum thread, that I should apply the fog by postprocessing and use the depthbuffer.

This works fine for the landscape, but do not get the stencil function set correctly to make the sky visible. (I put the sky texture on a sphere around the viewer).

Can anybody help me with the correct setting? I read that I may have to adjust the depthbuffer,but I cannot specify it in the render (just turn it on or off).

Thanks.

node with fog and stencil (21.6 kB)