I'm trying to port some antiquated D3D8 Dot3 bumpmapping code from fixed function calls to an HLSL shader. The original code looks like the following:
dev->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3);
dev->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE); // normal map
dev->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
dev->SetTextureStageState (1, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
dev->SetTextureStageState (1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
dev->SetTextureStageState (1, D3DTSS_COLORARG2, D3DTA_CURRENT);
The texture in stage 0 is the normal map, 1 is the texture that it's applied to (in this case it's a terrain texture). I'm assuming this is fairly simple to replicate in an HLSL shader, but my limited knowledge of HLSL has prevented me from making much progress.
I think I have the vertex shader right, but my pixel shader isn't working. From the (limited) DX8 documentation on this, it seems like this would be the literal translation of the FFP code above:
float4 RenderScenePS(VS_OUTPUT input) : COLOR0
{
float4 normalMap = mul(tex2D(g_LandBumpTextureSampler, input.LandBumpTextureUV), input.LandDiffuse);
float4 color = 2 * (tex2D(g_LandTextureSampler, input.LandTextureUV) * normalMap);
return color;
}
This just causes the original landscape texture to be rendered, but a bit brighter/strangely colored.
The examples of bump/normal map shaders I've found on Google assume either that tangents and binormals are being passed in the vertex data (not the case here), or that diffuse/specular need to be calculated (this uses pre-lit color per vertex). What exactly am I missing?