所以,我在世界空间中有一个光的方向,我计算了每个顶点的法线......然而,我对我的法线贴图实现有点困惑。现在我正在做这个。
// Normal Map
const float3 normalmap = (2.0f*gTextures1024.Sample(gLinearSam, float3(_in.Tex, gNormalMapIndex)).rgb) - 1.0f;
const float3 NormalW = _in.Norm;
const float3 TangentW = normalize(_in.TangentW.xyz - dot(_in.TangentW.xyz, _in.Norm)* _in.Norm);
const float3 BitangentW = cross(NormalW, TangentW) * _in.TangentW.w;
const float3x3 TBN = float3x3(TangentW, BitangentW, NormalW);
float3 normal = normalize(mul(TBN, normalmap));
// Lighting Calculations
//float4 normal = normalize(float4(_in.Norm, 0.0f));
float3 hvector = normalize(mul(-gDirLight.Direction.xyz, TBN) + gEyePos).xyz;
//hvector = mul(hvector.xyz, TBN);
float4 ambient = gDirLight.Ambient * gMaterial.Ambient;
float4 diffuse = float4(0.0f, 0.0f, 0.0f, 0.0f);
float4 specular = float4(0.0f, 0.0f, 0.0f, 0.0f);
float4 texColor = float4(1.0f, 1.0f, 1.0f, 1.0f);
[branch]
if(gUseTextures)
texColor = gTextures1024.Sample(gLinearSam, float3(_in.Tex, gDiffuseMapIndex));
// diffuse factor
float diffuseFactor = saturate(dot(normal, -gDirLight.Direction.xyz));
[branch]
if(diffuseFactor > 0.0f)
{
diffuse = diffuseFactor * gDirLight.Diffuse * gMaterial.Diffuse;
// Specular facttor & color
float HdotN = saturate(dot(hvector, normal));
specular = gDirLight.Specular * pow(HdotN, gMaterial.Specular.w);
}
// Modulate with late add
return (texColor * (ambient + diffuse)) + specular;
我在这里做错了吗?据我说,我正在世界空间中实现法线贴图计算,一切都应该工作得很好......我在这里错过了什么吗?