fog with pixel shaders < 3.0
der.fabe at gmx.net
Mon Mar 12 04:35:14 CDT 2007
I'd like to get fog working in conjunction with pixel shaders 2.0 or earlier.
The problem is that said shaders don't replace the fog stage in Direct3D.
Adding the necessary fog calculations to a GLSL fragment shader is trivial,
however, this results in a dependency of the shader on the current fog state.
Now, I have thought up three solutions for this problem:
1) Compile two versions of every fragment shader (one with fog and one
without) and choose the appropriate one according to the state.
Pro: Probably performance wise the cheapest solution
Con: Generates more shaders, however, as shader are only compiled on demand,
this shouldn't be too bad.
2) Rebuild the shader whenever it is bound in conjunction with a changed fog
Con: This would be a performance killer as it would potentially cause multiple
calls of IWineD3DPixelShaderImpl_CompileShader per frame, as some Programs
use the same fragment shader for rendering with and without fog. (ok, I only
know this of source based games, but imo that's bad enough)
3) Add Fog calculation to every shader, enabling or disabling it at runtime
via a constant factor of 1.0 or 0.0 depending on the fog state which is
supplied as a shader constant.
Pro: cpu-load wise cheap
Con: Adds some more instructions to fragment shader code.
Now, I don't particularly like any of these solutions, so I'd welcome other
ideas, comments or suggestions.
P.S: I noticed that fog-state management is not yet included in the state
table. Should a patch that fixes fog with pixel shaders wait until this is
done, or is this of no importance?
More information about the wine-devel