DirectX 9 Fixed Function Textures
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?
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.
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.
精彩评论