Directx 如何在像素着色器中使用Direct X使法线贴图正常工作

Directx 如何在像素着色器中使用Direct X使法线贴图正常工作,directx,Directx,我有切线和双切线等,我想我的数学正确了,直到像素着色器中的最后一个东西 我一直在看教程,但似乎无法在我自己的课程中使用 到目前为止,我的法线贴图代码如下所示: float3 normalMap = (nTex.Sample(mySampler, input.UV).rgb); normalMap = (normalMap * 2) - 1.0f; input.tangents = normalize(input.tangents - dot(input.tangents, input

我有切线和双切线等,我想我的数学正确了,直到像素着色器中的最后一个东西

我一直在看教程,但似乎无法在我自己的课程中使用

到目前为止,我的法线贴图代码如下所示:

   float3 normalMap = (nTex.Sample(mySampler, input.UV).rgb);


normalMap = (normalMap * 2) - 1.0f;

input.tangents = normalize(input.tangents - dot(input.tangents, input.normal) * input.normal);

float3 biTang = cross(input.normal, input.tangents);

float3x3 texSpace = float3x3(input.tangents, biTang, input.normal);

//float3 normalWW = float3(normalMap.r, normalMap.g, normalMap.b);

input.normal = normalize(mul(normalMap, texSpace));

float3 plDir = float3(pointLightDir.rgb);

//float final = saturate(dot(-plDir, input.normal));


//float4 finalW = saturate(float4(combined * final));

output.Color = color * combined;

output.Color+= saturate((dot(-plDir, input.normal)*combined)*color);


output.Color.a = 1;
我还没有给东西起个好名字。 “组合”是我的phong着色,我将漫反射、镜面反射和环境光添加在一起。“颜色”只是采样的漫反射纹理

结果与我只有第一个纹理没有什么不同。如果我只使用法线贴图,它会显示出来,以便正常工作


<>我在C++中使用DirectX。< /P>你使用对象空间还是切线空间法线贴图?您可能会发现该代码非常有用。请仅尝试此操作,而不要添加:output.Color=saturate((dot(-plDir,input.normal)*combined)*Color);感谢您的回复,我正在使用切线空间法线贴图,我尝试了很多组合,但都不起作用。我认为您应该使用
mul(texSpace,normalMap)
而不是
mul(normalMap,textSpace)