-1

So far I've found out that you need to create a ID3D10BlendState object, call CreateBlendState() with a D3D10_BLEND_DESC struct, and call OMSetBlendState(). But I don't know how to call the Draw() functions and how to Apply() the textures. I have lightmap textures that I need to be blended with normal textures. Do I need multiple texture coordinates for the vertices? Do I need to draw each poly twice, once for the texture and once for the lightmap? I also don't really want to use texture arrays.

Thanks in advance.

Hermetix
  • 141
  • 2
  • 8
  • OK, why the downvote? :/ – Hermetix May 30 '17 at 21:13
  • Welcome to SO! I haven't downvoted, but here are possible reasons one could: (1) You don't ask a question that is answerable in SO format (i.e. a short post). (2) The only exact problem you state is "I don't know how to...", for which solution is "To learn and to try". (3) One could help you to learn one simple thing at a time, but you basically require an explanation of the entire pipeline (buffers, shaders etc.) (4) Lightmaps are probably not the best things to start with if don't know how to draw. (5) There is no code and no effort is shown to research and to solve the problem – Ivan Aksamentov - Drop May 30 '17 at 21:38
  • Here is what you can do now: Try to split the problem into smaller, simpler subproblems that you can address one at a time. Look for an online tutorial that would help you to draw a triangle or a quad, with shaders, but no textures or blending. e.g. directxtutorial, rastertek or braynzarsoft. Gradually, add textures, try to play with colors inside pixel shader, e.g. invert them. Add blending, check that e.g. two transparent quads blend correctly when overlapped. Then check the theory about lightmaps. On this stage it will be trivial for you to implement them. – Ivan Aksamentov - Drop May 30 '17 at 21:41
  • On every stage feel free to come back to SO or to gamedev.stackexchange and to ask about *exact* problems that you've encountered, with minimal code examples that reproduce the problem – Ivan Aksamentov - Drop May 30 '17 at 21:41
  • I do know how to draw, but only a single texture at a time. – Hermetix May 30 '17 at 21:46
  • OK, I will reformat my question and ask it on the gamedev site. Thanks for taking the time to answer. – Hermetix May 30 '17 at 21:48
  • http://www.rastertek.com/dx10tut18.html – James Poag May 30 '17 at 23:50
  • @James Poag, I am aware of that tutorial but unfortunately it uses texture arrays - something that I want to avoid for now. – Hermetix May 31 '17 at 04:45

1 Answers1

0

There's no reason to use DirectX 10. DirectX 11 fully supplants it on all the same platforms (Windows Vista SP2 or later all support DirectX 11), and supports a wider range of video hardware. In addition, the only place to find DirectX 10 samples and utility code is in the legacy DirectX SDK. For DirectX 11, there are numerous open-source replacements for the old deprecated D3DX library, as well as samples.

Direct3D 10 and later all use programmable shaders rather than the legacy 'fixed function' pipeline. Therefore, the way you'd implement light mapping is in a pixel shader written in HLSL:

Texture2D<float4> Texture  : register(t0);
Texture2D<float4> Texture2 : register(t1);

sampler Sampler  : register(s0);
sampler Sampler2 : register(s1);

float4 PSDualTextureNoFog(PSInputTx2NoFog pin) : SV_Target0
{
    float4 color = Texture.Sample(Sampler, pin.TexCoord);
    float4 overlay = Texture2.Sample(Sampler2, pin.TexCoord2);

    color.rgb *= 2; 
    color *= overlay * pin.Diffuse;

    return color;
}

You'd build this offline with FXC and then bind it at run-time along with a vertex shader. Typically for light-maps you'd use two texture coordinate sets in the input layout:

const D3D11_INPUT_ELEMENT_DESC VertexPositionDualTexture::InputElements[] =
{
    { "SV_Position", 0, DXGI_FORMAT_R32G32B32_FLOAT,    0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "TEXCOORD",    0, DXGI_FORMAT_R32G32_FLOAT,       0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "TEXCOORD",    1, DXGI_FORMAT_R32G32_FLOAT,       0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};

A good place to start with C++ coding for DirectX 11 is the DirectX Tool Kit. It includes the DualTextureEffect which uses the shader above.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • OK that is one thing that I wanted to know, the use of multiple texture coordinates. Because the lightmaps have different coordinates. I'm using DX10 because my video card does not support DX11. (I know it is pretty old) – Hermetix May 31 '17 at 07:07
  • You are conflating "DirectX API version" and "Direct3D hardware feature level". You can and should use the Direct3D 11 API which supports a range of hardware including ``D3D_FEATURE_LEVEL_10_0`` which is in fact "a video card that supports all the features required by the Direct3D 10 API". As I said, there's no reason to use the DirectX 10 API at all. See [this blog post](https://blogs.msdn.microsoft.com/chuckw/2012/06/20/direct3d-feature-levels/) – Chuck Walbourn Jun 01 '17 at 07:11