Directx 9法线贴图Pixelshader

问题描述

我对Directx9着色器中的法线贴图有疑问。 目前,我的“法线贴图+漫反射色”的地形着色器输出仅导致此图像。 这对我来说很好。

Normal Map + Diffuse Color

如果我使用像这样的空的法线贴图图像。

enter image description here

我的法线扩散和颜色贴图的着色器输出如下所示。

enter image description here

但是,如果我使用1包括ColorMap),则会得到非常稳定的结果。

enter image description here

有人知道什么可能导致此问题吗?

这里有一些片段。

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;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)