C++ 如何在同一对象上采样两个纹理?
我必须复制一种效果,它由两种纹理(瓷砖+硬币)组合而成,以实现以下效果: 到目前为止,我取得的最好成绩是: 上面的链接将带您进入项目,这里是我在像素着色器中尝试执行的操作:C++ 如何在同一对象上采样两个纹理?,c++,graphics,directx-11,C++,Graphics,Directx 11,我必须复制一种效果,它由两种纹理(瓷砖+硬币)组合而成,以实现以下效果: 到目前为止,我取得的最好成绩是: 上面的链接将带您进入项目,这里是我在像素着色器中尝试执行的操作: float4 PS(PS_INPUT input) : SV_Target { float4 color1; float4 color2; float4 blendColor; // Get the pixel color from the first texture. co
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遮罩混合时,您正在混合它们,但没有使用alpha遮罩进行混合 下面是一个例子:;如果硬币有阿尔法通道。
(否则,您必须计算alpha或在图像编辑软件中添加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;
}
谢谢,@Ario Amin!我应用了你的建议,效果很好。很高兴能帮上忙!我建议你去看看:这是一个很好的W.I.P.资源,github必须至少在第15章中说明。克隆repo并为离线访问安装它的步骤: