2
votes

Using the Fixed Function rendering pipeline in DirectX 9, it's quite easy to set a texture and render vertices by doing the following:

struct vert { float x, y, z, u, v; };

device->SetFVF(D3DFVF_XYZ | D3DFVF_TEX1);
device->SetTexture(0, MyTexture);

//Draw vertices here

However, I'd like to add an additional float value to each vertex, which is then multiplied by the resulting colour output from the texture. (So the value would be between 0 and 1)

EG (psuedocode) Colour = TextureColour(u, v) * CustomFloat

I think there is a way using device->SetTextureStageState, but I am unsure of how to do it... Can anyone help me?

2
strongly related to Per vertex pre-computated lighting in DirectX9 using fixed function rendering pipeline. -while not exactly a duplicate, an answer to that would answer this as well.Suma

2 Answers

2
votes

You could set a 1D linear grayscale texture as a second texture, configured to modulate the first. Then send a single texture coordinate for the second texture (by specifying D3DFVF_TEXCOORDSIZE1 for it, I think). Speculating here -- haven't tried it myself.

To paraphrase your pseudocode: Colour = Texture0Colour(u0, v0) * Texture1Colour(u1)

Edit I think you need:

device->SetFVF(D3DFVF_XYZ | D3DFVF_TEX2 | D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE1(1)) 

MSDN also has a similar example.

0
votes

This could hopefully get you started: Per-Vertex Color State (Direct3D 9).

You need to use FVF like this:

D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_DIFFUSE

and to enable using the vertex color by:

m_pDevice9->SetRenderState(D3DRS_COLORVERTEX, TRUE);

m_pDevice9->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1);

This is another link, showing more details about how to set the texture combiners. The example uses alpha combine, but it should be trivial to modify it to use color combiners instead.