I'm having some issue changing a basic lighting shader to take a normal texture and a diffuse texture for a model and then using the normal texture for lighting. The code is very simple and i can't see where i have gone wrong at all, am i not allowed to sample two textures with the same sampler? This is the output i am getting:
Using the two textures:
THe basic shader code is:
Texture2D shaderTexture : register(t0);
Texture2D heightNormalTexture : register(t1);
float4 PS(VOUT pIn) : SV_Target
{
float4 diffuseColour = shaderTexture.Sample(SampleType, pIn.texCoord);
float4 normal = heightNormalTexture.Sample(SampleType, pIn.texCoord);
float3 litColour = float3(0.0f, 0.0f, 0.0f);
for(int i = 0; i < 3; i++)
{
SurfaceInfo sInfo = {pIn.posW, normal.xyz, diffuseColour, pIn.spec};
[branch] switch(gLight[i].type)
{
case 0: //Parallel
{
litColour += ParallelLight(sInfo, gLight[i], gEyePosW);//
break;
}
case 1: //Point
{
litColour += PointLight(sInfo, gLight[i], gEyePosW);
break;
}
case 2: //Spotlight
{
//litColour += SpotLight(sInfo, gLight[i], gEyePosW);
break;
}
}
}
return float4(litColour, diffuseColour.a);
}
The lighting code seems to work just fine when i pass in the normals as part of the vertex buffer, but goes this odd mash-up of diffuse and normal when i try to use the normals from a texture. From what i can tell i am setting the texture right in C++.
ID3D11ShaderResourceView *pixelShaderTextures[2];
pixelShaderTextures[0] = m_textureManager.GetTextureResourceView(std::string("TestHeightMapNormal"));
pixelShaderTextures[1] = m_textureManager.GetTextureResourceView(std::string("TestTexture"));
context->PSSetShaderResources(0, 2, pixelShaderTextures);
If you guys have any help/advice for me to resolve this, that would be great.