[英]How to sample two textures onto the same object?
我必須重現一種由組合兩種紋理(瓷磚 + 硬幣)組成的效果,以實現以下效果:
迄今為止我取得的最好成績:
上面的鏈接將帶您進入該項目以及我嘗試在像素着色器中執行的操作:
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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.