1 .有點類似于圖層的概念
2 .混合操作實際上是對像素值的RGB分量分別進行簡單的數(shù)學運算知残,每個分量都介于0-1之間
3 .僅當渲染的物體是網(wǎng)格時alpha混合時题山,才能使用此屬性煌妈。因為alphaMode屬性對不透明網(wǎng)格物體絕對沒有沒有影響
mesh.visibility=0.99
//使不透明的物體變得透明
material.opacityTexture = material.diffuseTexture;
//或者為材質(zhì)指定透明紋理杰扫,都可以實現(xiàn)效果
4 .混合模式的類型
1 BABYLON.Engine.ALPHA_COMBINE:默認的網(wǎng)格混合模式刀诬,混合是通過繪制像素的alpha值來調(diào)制的究抓,默認的混合模式
2 BABYLON.ENGINE.ALPHA_ADD:看實際效果就是給了點透明度
3 BABYLON.Engine.ALPHA_SUBTRACT:從現(xiàn)有像素減去新的像素值蜘欲,從而實現(xiàn)“反轉顏色”效果
4 BABYLON.Engine.ALPHA_MULTIPLY:新像素和現(xiàn)有像素值相乘益眉,因此渲染的網(wǎng)格后面的顏色變暗。和add模式相反
5 BABYLON.Engine.ALPHA_MAXIMIZED:此混合模式類似于ALPHA_ADD姥份,但散發(fā)出不那么活躍和飽和的效果
6 BABYLON.Engine.ALPHA_ONEONE:此混合模式與ALPHA_ADD非常相似郭脂,除了它不受alpha值調(diào)制。內(nèi)部用于各種視覺效果
5 代碼
var material_base = new BABYLON.StandardMaterial("mat", scene);
material_base.diffuseTexture = new BABYLON.Texture("textures/misc.jpg", scene);
material_base.alpha = 0.9999; // artificially set the material as alpha blended
// material_base.ambientColor = BABYLON.Color3.White();
var alphamodes = [
BABYLON.Engine.ALPHA_COMBINE,
BABYLON.Engine.ALPHA_ADD,
BABYLON.Engine.ALPHA_SUBTRACT,
BABYLON.Engine.ALPHA_MULTIPLY,
BABYLON.Engine.ALPHA_ONEONE
];
// cubes
var count = 5;
var mesh;
var mat;
var angle;
for (var i = 0; i < count; i++) {
//angle = Math.PI * 2 * i / count;
//mesh = BABYLON.Mesh.CreateBox("cube" + i, 12, scene);
mesh = BABYLON.Mesh.CreateCylinder("aaa", 12, 8, 8, 12, 1, scene);
mesh.position.x = -17 * (i +0.5 - count/2);
//mesh.rotation.y = Math.PI * 2 - angle;
mesh.rotation.y = 8;
mat = material_base.clone(null);
mat.alphaMode = alphamodes[i];
mesh.material = mat;
}