如何将两个纹理采样到同一个对象上?

How to sample two textures onto the same object?

我必须重现一种效果,该效果包括组合两个纹理(瓷砖 + 硬币)以实现以下效果:

迄今为止我取得的最好成绩:

Visual Studio Solution to reproduce the problem

上面的 link 将带您进入项目,这里是我尝试在像素着色器中执行的操作:

float4 PS(PS_INPUT input) : SV_Target
{
    float4 color1;
    float4 color2;
    float4 blendColor;


    // Get the pixel color from the first texture.
    color1 = texTile.Sample(samLinear, input.Tex) * vMeshColor;

    // Get the pixel color from the second texture.
    color2 = texCoin.Sample(samLinear, input.Tex) * vMeshColor;

    // Blend the two pixels together and multiply by the gamma value.
    blendColor = color1 * color2;

    // Saturate the final color.
    blendColor = saturate(blendColor);

    return blendColor;
}

但这似乎不是正确的做法。
我应该采取哪种方法才能获得预期的结果?

好吧,首先你混合它们而不是使用 alpha-mask 混合,当示例图像似乎已经与 alpha-mask.

混合时

示例可能如下所示;前提是硬币有 alpha-channel.
(否则您将不得不计算一个 alpha 或在图像编辑软件中添加一个。

    float3 blend(float4 CoinTex, float3 GridTex)
    {
         // Inverse of alpha, to get the area around the coin
         // Alpha spans from [0,1] so the expression below would suffice
         float1 inverseAlpha = (1 - CoinTex.a);

         float3 blendedTex = 0;
         
         // If-else that is evaluated to decide how they'll be overlayed
         if (inverseAlpha > 0.0 ){
             blendedTex = GridTex.rgb;
         } else {blendedTex = CoinTex.rgb;}

         return blendedTex;
    }