下面的 vertex shader 使 w 值对齐到近裁剪面,z 值变为 0。 // transform position into projection space m4x4 r0,v0,c8 max r0.z,c40.z,r0.z //clamp to 0 7 max r0.w,c12.x,r0.w mov oPos,r0 //clamp to near clip plane // Subtract the Near clipping plane add r0.w,r0.w,-c12.x // Scale to give us the far clipping plane mul r0.w,r0.w,c12.y // load depth into texture, don't care about y mov oT0.xy,r0.w 参考资料: 1、 Volumetric Rendering in Realtime By Charles Boyd and Dan Baker ; Gamasutra October 3,2001 2、 Texture-based fog By Ping-Che Chen; Game Resource 3、 Fog ; By 朝三暮四郎; Game Resource 8