Microsoft DirectX 8.1 (Visual Basic) |
Materials describe how polygons reflect light or appear to emit light in a 3-D scene. Essentially, a material is a set of properties that tell Microsoft® Direct3D® the following things about the polygons it is rendering.
Direct3D applications written in Microsoft® Visual Basic® use the D3DMATERIAL8 type to describe material properties. For more information, see Material Properties.
Microsoft® Direct3D® rendering devices can render with one set of material properties at a time.
In a Microsoft® Visual Basic® application, set the material properties that the system uses by preparing a D3DMATERIAL8 type, then calling the Direct3DDevice8.SetMaterial method.
To prepare the D3DMATERIAL8 type for use, set the property information in the structure to create the desired effect during rendering. The following code example sets up the D3DMATERIAL8 type for a purple material with sharp white specular highlights.
Dim mat As D3DMATERIAL8 ' Set the RGBA for diffuse reflection. mat.diffuse.r = 0.5 mat.diffuse.g = 0# mat.diffuse.b = 0.5 mat.diffuse.a = 1# ' Set the RGBA for ambient reflection. mat.ambient.r = 0.5 mat.ambient.g = 0# mat.ambient.b = 0.5 mat.ambient.a = 1# ' Set the color and sharpness of specular highlights. mat.specular.r = 1# mat.specular.g = 1# mat.specular.b = 1# mat.specular.a = 1# mat.power = 50# ' Set the RGBA for emissive color. mat.Emissive.r = 0# mat.Emissive.g = 0# mat.Emissive.b = 0# mat.Emissive.a = 0#
After preparing the D3DMATERIAL8 type, apply the properties by calling the SetMaterial method of the rendering device. This method accepts the address of a prepared D3DMATERIAL8 type as its only parameter. You can call SetMaterial with new information as needed to update the material properties for the device. The following code example shows how this might look in code.
' This code example uses the material properties defined for ' the mat variable earlier in this topic. The d3dDevice is ' assumed to contain a valid reference to a Direct3DDevice8 ' object. On Local Error Resume Next Call d3dDevice.SetMaterial(mat) If Err.Number <> D3D_OK Then ' Code to handle the error goes here. End If
When you create a Direct3D device, the current material is automatically set to the default shown in the following table.
Member | Value |
---|---|
Diffuse | (R:1, G:1, B:1, A:0) |
Specular | (R:0, G:0, B:0, A:0) |
Ambient | (R:0, G:0, B:0, A:0) |
Emissive | (R:0, G:0, B:0, A:0) |
Power | (0.0) |
You retrieve the material properties that the rendering device is currently using by calling the Direct3DDevice8.GetMaterial method for the device. Unlike the Direct3DDevice8.SetMaterial method, GetMaterial doesn't require preparation. The GetMaterial method accepts a variable of type D3DMATERIAL8, and fills it with information describing the current material properties before returning.
' For this example, the d3dDevice variable is assumed to ' contain a valid reference to a Direct3DDevice8 object. On Local Error Resume Next Dim mat As D3DMATERIAL8 Call d3dDevice.GetMaterial(mat) If Err.Number <> D3D_OK Then ' Code to handle the error goes here. End If
For more information about material properties see:
Default Material Properties Note If your application does not specify material properties for rendering, the system uses a default material. The default material reflects all diffuse light—white, for example—with no ambient or specular reflection, and no emissive color.