Microsoft DirectX 8.1 (Visual Basic) |
Full-scene antialiasing refers to blurring the edges of each polygon in the scene as it is rasterized in a single pass—no second pass is required. Full-scene antialiasing, when supported, only affects triangles and groups of triangles; lines cannot be antialiased by using Microsoft® Direct3D® services. Full-scene antialiasing is done in Direct3D by using multisampling on each pixel. When multisampling is enabled all subsamples of a pixel are updated in one pass, but when used for other effects that involve multiple rendering passes, the application can specify that only some subsamples are to be affected by a given rendering pass. This latter approach enables simulation of motion blur, depth of field focus effects, reflection blur, and so on.
In both cases, the various samples recorded for each pixel are blended together and output to the screen. This enables the improved image quality of antialiasing or other effects.
Before creating a device with the Direct3D8.CreateDevice method, you must determine if full-scene antialiasing is supported. Do this by calling the Direct3D8.CheckDeviceMultiSampleType method as shown in the code example below.
' ' The code below assumes that D3D is a valid pointer ' to a Direct3D8 object. ' Call D3D.CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_R8G8B8, 0, D3DMULTISAMPLE_2_SAMPLES )
The first parameter that CheckDeviceMultiSampleType accepts is an ordinal number that denotes the display adapter to query. This sample uses D3DADAPTER_DEFAULT to specify the primary display adapter. The second parameter is a value from the CONST_D3DDEVTYPE enumerated type, specifying the device type. The third parameter specifies the format of the surface. The fourth parameter tells Direct3D whether to inquire about full-windowed multisampling (1) or full-scene antialiasing (0). This sample uses 0 to tell Direct3D that it is inquiring about full-scene antialiasing. The last parameter specifies the multisampling technique to test. Use a value from the CONST_D3DMULTISAMPLE_TYPE enumerated type. This sample tests to see if two levels of multisampling are supported.
If the device supports the level of multisampling that you want to use, the next step is to set the presentation parameters by filling in the appropriate members of the D3DPRESENT_PARAMETERS structure to create a multisample rendering surface. After that, you can create the device. The sample code below shows how to set up a device with a multisampling render surface.
' ' The example below assumes that D3D is a valid Direct3D8 ' object and D3DDevice is a valid Direct3DDevice8 object. ' Dim d3dpp As D3DPRESENT_PARAMETER d3dpp.Windowed = FALSE d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD d3dpp.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES Set D3DDevice = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, d3dpp )
Note To use multisampling, the SwapEffect member of D3DPRESENT_PARAMETER must be set to D3DSWAPEFFECT_DISCARD.
The last step is to enable multisampling antialiasing by calling the Direct3DDevice8.SetRenderState method and setting the D3DRS_MULTISAMPLEANTIALIAS to 1. After setting this value to 1, any rendering that you do has multisampling applied to it. You might want to enable and disable multisampling depending on what you are rendering to the scene.