0

I am working a game engine with DirectX9. This is my first time working with DirectX9.

I am able to obtain following results: SpiderRender

std::vector<std::string> tex_keys = {
    mesh + "_Diffuse",
    mesh + "_Ambient",
    mesh + "_Specular",
    mesh + "_Dissolve",
    mesh + "_Bump",
    mesh + "_Sharpness"
};
auto device = GetDevice();
// Diffuse Map _ Base Texture
if (TextureMap[tex_keys[0]])
{
    device->SetTextureStageState(TextureMap[tex_keys[0]]->GetSlot(), D3DTSS_COLOROP, D3DTOP_MODULATE);
    device->SetTextureStageState(TextureMap[tex_keys[0]]->GetSlot(), D3DTSS_COLORARG1, D3DTA_TEXTURE);
    device->SetTextureStageState(TextureMap[tex_keys[0]]->GetSlot(), D3DTSS_COLORARG2, D3DTA_DIFFUSE);

    device->SetTextureStageState(TextureMap[tex_keys[0]]->GetSlot(), D3DTSS_ALPHAOP, D3DTOP_MODULATE);
    device->SetTextureStageState(TextureMap[tex_keys[0]]->GetSlot(), D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
    device->SetTextureStageState(TextureMap[tex_keys[0]]->GetSlot(), D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
    TextureMap[tex_keys[0]]->Bind();
}
// Specular Map
if (TextureMap[tex_keys[2]])
{
    device->SetTextureStageState(TextureMap[tex_keys[2]]->GetSlot(), D3DTSS_COLOROP, D3DTOP_ADD);
    device->SetTextureStageState(TextureMap[tex_keys[2]]->GetSlot(), D3DTSS_COLORARG1, D3DTA_TEXTURE);
    device->SetTextureStageState(TextureMap[tex_keys[2]]->GetSlot(), D3DTSS_COLORARG2, D3DTA_CURRENT);
    TextureMap[tex_keys[2]]->Bind();
}

I would like to know how to apply bump map texture to the mesh by extending the above code.

  • Looks like you're [skipping a few steps](https://learn.microsoft.com/en-us/windows/win32/direct3d9/using-bump-mapping) – Mgetz Nov 03 '21 at 13:33
  • @Mgetz Its not possible to post all my code here. Other part of the code takes care of setting the texture to a particular slot when Bind is called. I tried following the Microsoft Doc on Bump mapping but it didn't work. – sparkskapil Nov 03 '21 at 16:56
  • I can't say for sure I've used D3D11 and 12. So I grabbed the documentation. It appears from the docs that order matters and the way you're ordering things skips "Stage 1" in that documentation and also omits a call in "stage 0" setting `D3DTSS_TEXCOORDINDEX` – Mgetz Nov 03 '21 at 16:59
  • @Megtz As far as I know order of the state doesn't matter and if texcoordindex is not set it takes default 0,0 as start of u,v. – sparkskapil Nov 04 '21 at 05:12
  • Note you should strongly consider using DirectX 11. DirectX 9 is extremely old at this point, and there's plenty of [open source utilities](https://walbourn.github.io/living-without-d3dx/) and [samples](https://github.com/walbourn/directx-sdk-samples) for DirectX 11 without all the legacy issues of using the 11 year old legacy, end-of-life DirectX SDK. Unless you are targeting Windows XP, there's no point in using DX9. Even with DX9, you are using the even more legacy fixed-function rendering pipeline instead of HLSL shaders. – Chuck Walbourn Nov 20 '21 at 21:13
  • Also, 'bump mapping' is an extremely old technique. It was introduced back in Direct3D 8. The modern equivalent is 'normal mapping' and specifically 'tangent-space normal-mapping'. There are a number of tutorials on the internet for this technique such as [this one](https://github.com/microsoft/DirectXTK/wiki/Using-advanced-shaders) for *DirectX Tool Kit*. – Chuck Walbourn Nov 20 '21 at 21:16

1 Answers1

0

As far as I'm concerned, you should try to use D3DXLoadMeshFromX functionto load a mesh. And then you could try to use D3DXCreateTextureFromFileto load a texture to a mesh.

For more details, I suggest you could refer to the thread:c++ directx 9 mesh texture

Jeaninez - MSFT
  • 3,210
  • 1
  • 5
  • 20
  • Note if you must use legacy DirectX 9, you can avoid all the mess of the legacy DirectX SDK and the legacy DirectX End User Runtime REDIST by using the [Microsoft.DXSDK.D3DX](https://www.nuget.org/packages/Microsoft.DXSDK.D3DX) NuGet package. See [this blog post](https://walbourn.github.io/legacy-d3dx-on-nuget/) for details. – Chuck Walbourn Nov 20 '21 at 21:18
  • @sparkskapil Have you got any updates? If your case has been solved, please help to mark answers. If not, just feel free to contact us. Your understanding and cooperation will be grateful. – Jeaninez - MSFT Nov 25 '21 at 07:24