Microsoft DirectX 8.0 (Visual Basic)

Using Volume Textures

The code examples below show the steps required to use a volume texture.

First, specify a custom vertex type that has three texture coordinates for each vertex, as shown in this code example.

Private Type VOLUMEVERTEX
    Dim x As Single
    Dim y As Single
    Dim z As Single
    Dim color As Long
    Dim tu As Single
    Dim tv As Single
    Dim tw As Single
};

Const D3DFVF_VOLUMEVERTEX = (D3DFVF_XYZ Or D3DFVF_DIFFUSE Or _
                             D3DFVF_TEX1 Or D3DFVF_TEXCOORDSIZE3_0)

Next, fill the vertices with data.

Dim Vertices(3) As VOLUMEVERTEX

With Vertices(0):
    .x = 1.0: .y = 1.0: .z = 0.0: .color = &HFFFFFFFF .tu = 1.0: .tv = 1.0: .tw = 0.0
End With

With Vertices(1):
    .x = -1.0: .y = 1.0: .z = 0.0: .color = &HFFFFFFFF .tu = 0.0: .tv = 1.0: .tw = 0.0
End With

With Vertices(2):
    .x = 1.0: .y = -1.0: .z = 0.0: .color = &HFFFFFFFF .tu = 1.0: .tv = 0.0: .tw = 0.0
End With

With Vertices(3):
    .x = -1.0: .y = -1.0: .z = 0.0: .color = &HFFFFFFFF .tu = 0.0: .tv = 0.0: .tw = 0.0
End With

Now, create a vertex buffer and fill it with data from the vertices.

The next step is to use the Direct3DDevice8.CreateVolumeTexture method to create a volume texture, as shown in the code example below.

Dim volTexture As Direct3DVolumeTexture8

Set volTexture = m_D3DDevice.CreateVolumeTexture(8, 4, 4, 1, 0, _
                                                 D3DFMT_R8G8B8, _
                                                 D3DPOOL_MANAGED)

Before rendering the primitive, set the current texture to the volume texture created above. The code example below shows the entire rendering process for a strip of triangles.

d3dDevice.BeginScene

// Draw the quad, with the volume texture.
Call d3dDevice.SetTexture(0, volTexture)
Call d3dDevice.SetVertexShader(D3DFVF_VOLUMEVERTEX)
Call d3dDevice.SetStreamSource(0, VB, len(Vertices(0))
Call d3dDevice.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2)

// End the scene.
d3dDevice->EndScene