1

I have a question about normal mapping in directx9 shader. Currently my Terrain shader Output for Normal Map + Diffuse Color only result into this Image. Which looks good to me.

Normal Map + Diffuse Color

If i use an empty Normal map image like this one.

enter image description here

My shader output for normal diffuse and color map looks like this. enter image description here

But if i use 1 including a ColorMap i get a really stange result.

enter image description here

Does anyone have an idea what could cause this issue?

Here is some snippets.

float4 PS_TERRAIN(VSTERRAIN_OUTPUT In) : COLOR0
{
    float4 fDiffuseColor;
    float lightIntensity;
    
    float3 bumpMap = 2.0f * tex2D( Samp_Bump, In.Tex.xy ).xyz-1.0f;
    float3 bumpNormal = (bumpMap.x * In.Tangent) + (bumpMap.y * In.Bitangent) + (bumpMap.z * In.Normal);
    bumpNormal = normalize(bumpNormal);

    // Direction Light Test ( Test hardcoded )
    float3 lightDirection = float3(0.0f, -0.5f, -0.2f);
    float3 lightDir = -lightDirection;

    // Bump
    lightIntensity = saturate(dot( bumpNormal, lightDir)); 

    // We are using a lightmap to do our alpha calculation for given pixel
    float4 LightMaptest = tex2D( Samp_Lightmap, In.Tex.zw ) * 2.0f;
    fDiffuseColor.a = LightMaptest.a;
    if( !bAlpha )
        fDiffuseColor.a = 1.0;
    
    // Sample the pixel color from the texture using the sampler at this texture coordinate location.
    float4 textureColor = tex2D( Samp_Diffuse, In.Tex.xy );

    // Combine the color map value into the texture color.
    textureColor = saturate(textureColor * LightMaptest);
    textureColor.a = LightMaptest.a;
    
    fDiffuseColor.rgb = saturate(lightIntensity * I_d).rgb;
    fDiffuseColor = fDiffuseColor * textureColor; // If i enable this line it goes crazy
    return fDiffuseColor;
}
Daros
  • 43
  • 3

0 Answers0