Microsoft DirectX 8.1 (Visual Basic)

MultiTexture Shader

This topic shows the steps necessary to initialize and use a simple vertex shader that uses a position and multiple texture coordinates for multiple textures.

The first step is to declare the structures that holds the position and color as shown in the code example below.

Private Type XYZBuffer
    x As Single
    y As Single
    z As Single
End Type

Private Type Tex0Buffer
    tu As Single
    tv As Single
End Type

Private Type Tex1Buffer
    tu2 As Single
    tv2 As Single
End Type

The next step is to create a vertex shader declaration as shown in the code below.

Dim decl(7) As Long

decl(0) = D3DVSD_STREAM(0)
decl(1) = D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3)
decl(2) = D3DVSD_STREAM(1)
decl(3) = D3DVSD_REG(D3DVSDE_TEXCOORD0, D3DVSDT_FLOAT2)
decl(4) = D3DVSD_STREAM(2)
decl(5) = D3DVSD_REG(D3DVSDE_TEXCOORD1, D3DVSDT_FLOAT2)
decl(6) = D3DVSD_END()

The next step is to call the Direct3DDevice8.CreateVertexShader method to create the vertex shader.

Call m_D3DDevice.CreateVertexShader( decl, ByVal 0, vShader, 0)

Passing ByVal 0 to the second parameter of CreateVertexShader tells Direct3D that this vertex shader will use a fixed function pipeline.

After creating the vertex buffer and vertex shader, they are ready to use. The code example below shows how to set the vertex shader, set the stream source, and then draw a triangle list that uses the new vertex shader.

Call m_D3DDevice.SetVertexShader(vShader)
Call m_D3DDevice.SetStreamSource(0, xyzbuf, len(XYZBuffer))
Call m_D3DDevice.SetStreamSource(1, tex0buf, len(Tex0Buffer))
Call m_D3DDevice.SetStreamSource(2, tex0buf, len(Tex1Buffer))
Call m_D3DDevice.SetIndices(IB, 0)
Call m_D3DDevice.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, max - min + 1, 0, count / 3)