Platform SDK: DirectX |
To alleviate fog-related graphic artifacts caused by uneven distribution of z-values within a depth buffer, most hardware devices use eye-relative depth instead of z-based depth values for pixel fog. Eye-relative depth is essentially the w element from a homogenous coordinate set. (Direct3D takes the reciprocal of the RHW element from a device space coordinate set to reproduce true w.) If a device supports eye-relative fog, it sets the D3DPRASTERCAPS_WFOG flag in the dwRasterCaps member of the D3DPRIMCAPS when you call IDirect3DDevice7::GetCaps method. (The D3DDEVICEDESC7 structure you pass to GetCaps contains multiple D3DPRIMCAPS structures that describe capabilities for various types of primitives.)
Note With the exception of the reference rasterizer, software devices always use z to calculate pixel fog effects.
When eye-relative fog is supported, the system will automatically use eye-relative depth in favor of z-based depth if the provided projection matrix produces z-values in world space that are equivalent to w-values in device space. (You set the projection matrix by calling the IDirect3DDevice7::SetTransform method, using the D3DTRANSFORMSTATE_PROJECTION value and passing a D3DMATRIX structure that represents the desired matrix.) If the projection matrix isn't compliant with this requirement, fog effects will not be applied properly. For details about producing a compliant matrix, see A W-Friendly Projection Matrix. (The perspective projection matrix provided in What Is the Projection Transformation? produces a compliant projection matrix.)
Usage Notes Direct3D uses the currently set projection matrix in its w-based depth calculations. As a result, applications must set a compliant projection matrix to receive the desired w-based features, even if they do not use the Direct3D transformation pipeline.
Direct3D checks the fourth column of the projection matrix, and if the coefficients are [0,0,0,1] (for an affine projection) the system will use z-based depth values for fog. In this case, you must also specify the start and end distances for linear fog effects in device space, which ranges from 0.0 at the nearest point to the user, and 1.0 at the farthest point.
To alleviate fog-related graphic artifacts caused by uneven distribution of z-values within a depth buffer, most hardware devices use eye-relative depth instead of z-based depth values for pixel fog. Eye-relative depth is essentially the w element from a homogenous coordinate set. (Direct3D takes the reciprocal of the RHW element from a device space coordinate set to reproduce true w.) If a device supports eye-relative fog, it sets the D3DPRASTERCAPS_WFOG flag in the lRasterCaps member of the D3DPRIMCAPS type when you call Direct3DDevice7.GetCaps method. (The D3DDEVICEDESC7 type you pass to GetCaps contains multiple D3DPRIMCAPS type that describe capabilities for various types of primitives.)
Note With the exception of the reference rasterizer, software devices always use z to calculate pixel fog effects.
When eye-relative fog is supported, the system will automatically use eye-relative depth in favor of z-based depth if the provided projection matrix produces z-values in world space that are equivalent to w-values in device space. (You set the projection matrix by calling the Direct3DDevice7.SetTransform method, using the D3DTRANSFORMSTATE_PROJECTION value from CONST_D3DTRANSFORMSTATETYPE and passing a D3DMATRIX type that represents the desired matrix.) If the projection matrix isn't compliant with this requirement, fog effects will not be applied properly. For details about producing a compliant matrix, see A W-Friendly Projection Matrix. (The perspective projection matrix provided in What Is the Projection Transformation? produces a compliant projection matrix.)
Usage Notes Direct3D uses the currently set projection matrix in its w-based depth calculations. As a result, applications must set a compliant projection matrix to receive the desired w-based features, even if they do not use the Direct3D transformation pipeline.
Direct3D checks the fourth column of the projection matrix, and if the coefficients are [0,0,0,1] (for an affine projection) the system will use z-based depth values for fog. In this case, you must also specify the start and end distances for linear fog effects in device space, which ranges from 0.0 at the nearest point to the user, and 1.0 at the farthest point.