微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Directx 9法线贴图Pixelshader

如何解决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 举报,一经查实,本站将立刻删除。