   Normal mapping and standard lighting model
  Hi everybody! I have an answer on the rendering process in DirectX 9 without using shaders. I'm using the following code to perform the so called Dot3 normal mapping. Note that standard DirectX lighting is off.d3dDevice->SetTexture(0, normal);d3dDevice->SetTexture(1, texture);d3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR, factor);d3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3);d3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);d3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TFACTOR);d3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);d3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);d3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);d3dDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);d3dDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_TEXTURE);d3dDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);d3dDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);d3dDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);d3dDevice->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);It works fine, however I would like a bit more flexibility; in particular when the vector set in the render state D3DRS_TEXTUREFACTOR is orthogonal to the surface normal I simply get a black pixel, even if I turn the lighting on. In addition, there is no simple way to produce specular highlights.Now, the question: WITHOUT SHADERS is it possible to tell DirectX to perform per-pixel lighting using the normals stored in the normal maps in the same way it would use vertex normals? In other words, can I turn on lighting and ask DirectX to apply the standard light model (ambient, diffuse, specular) to every pixel? Ideally in this case I wouldn't need to set D3DRS_TEXTUREFACTOR, because the set lights would be used for the computation. I don't need a detailed explanation, just to know wether is it possible and some hints about what I should look at.Thanks to everybody! :-)[Edited by - damix911 on January 22, 2008 1:53:00 PM]
  Look up the old D3D6 'Environment Mapped Bump Mapping' (aka 'EMBM') - thats pretty much the only other per-pixel mode supported by the fixed function pipeline. Here is a good starting point.Ultimately, if you want flexibility you want shaders [wink]hthJack   ;  Thank you jollyjeffers for this info on the fixed function pipeline! Perhaps I should really start looking at shader programming! Some techniques are possible only through shaders right? Maybe this is one of those. Obviously with multi-passing multi-texturing and a good amount of good will it is possible to achieve something like specular highlights on a normal map, but perhaps it doesn't worth.Thank you again :-)   ;  I would definitely suggest that you give shaders a try, even if its just in a limited context.  They're most definitely here to stay (in fact fixed-function is removed completely from D3D10!), and they ultimately offer you much more power and flexibility.  In fact for something like normal mapping, I think it will be easier for you to get things working with shaders than it would be for using FFP.  If you do decide to start using shaders, I suggest you have a look at Riemer's D3D9 tutorial.  It has some great explanations and diagrams that can help you learn how the programmable pipeline works, although the application code is in C# (translating to C++ is a piece of cake though, most functions either have the same name or have similar names). Pieter Germishuys also has some simple HLSL tutorials, including one that shows you how to perform simple normal mapping.  If those seem confusing or you have any further questions, feel free to ask and myself or someone else can help you out or give you some code snippets if necessary.   ;  Thanks MJP! I would say I'm still learning DirectX, even if I have already tried all the basic techniques; part of my problem with shaders was that I wanted to know how it worked before shaders, and eventually understand what can be done without them and when on the contrary they are fundamental. I'll look for sure on Riemer's tutorials, I actually started with Managed DirectX a few months ago, so it shouldn't be difficult. Also the Pieter's tutorial look nice, and the one on normal mapping is exactly what I want to do! Thanks!Bye :-)   ;  If you also have interests in learning general purpose graphics you'll be best off learning in the context of shaders.Yes, the maths can be a bit of a steep learning curve in places but ultimately you'll learn more from that than any Device->SetFunkyCoolNormalMapWithSpecularLighting(true) type code [smile]Be careful learning via Managed DirectX as it's a bit old now and is being phased out by MS. They won't be developing it any further. For official .NET integration you have to use XNA, otherwise look up SlimDX.hthJack   