【问题标题】:How do I combine the bump map normal and the real normal?如何结合凹凸贴图法线和真实法线?
【发布时间】:2013-04-06 23:13:54
【问题描述】:

我正在尝试使用凹凸贴图创建着色器。

我有对象的真实法线,我有凹凸贴图采样法线。 我想做的是旋转采样法线,以便在采样法线点上“向上”在真实法线的方向上。

我一直在研究数学,但我似乎无法正确计算... Y 在这个世界上。

// Vertex shader sends this matrix to the pixel shader
OUT.normal[0] = mul((float3x3)world, normal);
float3 temptan = cross(normal, float3(0, 0, 1));
temptan = normalize(temptan);
OUT.normal[2] = mul((float3x3)world, temptan);
OUT.normal[1] = cross(OUT.normal[0], OUT.normal[2]); calculating binormal (in world space)

// Pixel Shader:
// Get normal from bump texture
float3 normal = tex2D(normalmap, texCoord);
normal = normal * 2 - 1;
// Swap Z and Y, since Z is up on the texture, but Y is up in this world.
float temp = normal[1];
normal[1] = -normal[2];
normal[2] = temp;
// Multiply the sampled normal and the normal-basis matrix together.
normal = mul(normalMat, normal);

【问题讨论】:

    标签: shader hlsl bump-mapping


    【解决方案1】:

    当您想使用法线贴图(这实际上是“凹凸贴图”的意思)时,您需要两个额外的向量来实现您的目的:切线副法线。从几何法线和“凹凸贴图”的纹理空间计算切线和副法线。

    我确实在→my answer to StackOverflow question "How to calculate Tangent and Binormal?"中解释了如何做到这一点

    法线、切线和副法线形成一个坐标系,可以表示为 3×3 矩阵。这个矩阵实际上就是将法线贴图转换到模型局部空间所需的旋转矩阵,以便您可以将其用于光照计算。简而言之,你乘以这三个向量的三脚架形成的矩阵。

    【讨论】:

    • 谢谢!我会阅读你的文章。我想我一直在尝试按照您上面所说的进行操作,但对我来说还不是很清楚。
    • 请注意,只有当您在谈论切线空间法线贴图时才会出现这种情况,如果您在世界或对象空间中有法线,则不需要这样做。
    • @RobertJ.:世界空间法线非常不寻常,一旦您使用骨骼动画,对象空间法线就会产生大量问题。但你当然是对的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多