.:: Jasa Membuat Aplikasi Website,Desktop,Android Order Now..!! | | Order Now..!! Jasa Membuat Project Arduino,Robotic,Print 3D ::.

Away3d alphaBlending and alphaThreshold

0 komentar


بِسْــــــــــــــــمِ اﷲِالرَّحْمَنِ اارَّحِيم
bismillaahirrahmaanirrahiim

السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
Assalamu'alaikum warahmatullahi wabarakatuh

Away3d alphaBlending and alphaThreshold

I'd like to made a forest scene. My tree has a branches with transparent materials. I try to use alphaBlending option as true, it's look OK, but unfortunately z-sort is broken.
branchMat = new TextureMaterial(new BitmapTexture(pngBmd), true, true, true);
branchMat.alphaBlending = true;


So I read topic about AlphaBlending and Z-Sorting problem, and I try issue set the threshold at something like 0.01
Video away3d alphaBlending and alphaThreshold.
branchMat = new TextureMaterial(new BitmapTexture(pngBmd), true, true, true);
//branchMat.alphaBlending = true;
branchMat.alphaThreshold = 0.01;


This picture has z-sort is OK, but not so good SHADOW troubles from tree and huge black edges from leaves. So I thought about AlphaMaskMethod, but it's not work and last one can make the same z-sort problem. And I made from AlphaMaskMethod my own LexAlphaThresholdMethod.
package 
{
import away3d.arcane;
import away3d.core.managers.*;
import away3d.materials.compilation.*;
import away3d.textures.*;
import away3d.materials.methods.*;
import flash.display.*;

use namespace arcane;

/**
* AlphaMaskMethod allows the use of an additional texture to specify the alpha value of the material. When used
* with the secondary uv set, it allows for a tiled main texture with independently varying alpha (useful for water
* etc).
*/

public class LexAlphaThresholdMethod extends EffectMethodBase
{
private var _texture:Texture2DBase;
private var _useSecondaryUV:Boolean;

/**
* Creates a new AlphaMaskMethod object
* @param texture The texture to use as the alpha mask.
* @param useSecondaryUV Indicated whether or not the secondary uv set for the mask. This allows mapping alpha independently.
*/

public function LexAlphaThresholdMethod(texture:Texture2DBase, useSecondaryUV:Boolean = false)
{
super();
_texture = texture;
_useSecondaryUV = useSecondaryUV;
}

/**
* @inheritDoc
*/

override arcane function initVO(vo:MethodVO):void
{
vo.needsSecondaryUV = _useSecondaryUV;
vo.needsUV = !_useSecondaryUV;
}

/**
* Indicated whether or not the secondary uv set for the mask. This allows mapping alpha independently, for
* instance to tile the main texture and normal map while providing untiled alpha, for example to define the
* transparency over a tiled water surface.
*/

public function get useSecondaryUV():Boolean
{
return _useSecondaryUV;
}

public function set useSecondaryUV(value:Boolean):void
{
if (_useSecondaryUV == value)
return;
_useSecondaryUV = value;
invalidateShaderProgram();
}

/**
* The texture to use as the alpha mask.
*/

public function get texture():Texture2DBase
{
return _texture;
}

public function set texture(value:Texture2DBase):void
{
_texture = value;
}

/**
* @inheritDoc
*/

arcane override function activate(vo:MethodVO, stage3DProxy:Stage3DProxy):void
{
stage3DProxy._context3D.setTextureAt(vo.texturesIndex, _texture.getTextureForStage3D(stage3DProxy));
}

/**
* @inheritDoc
*/

arcane override function getFragmentCode(vo:MethodVO, regCache:ShaderRegisterCache, targetReg:ShaderRegisterElement):String
{
var textureReg:ShaderRegisterElement = regCache.getFreeTextureReg();
var temp:ShaderRegisterElement = regCache.getFreeFragmentVectorTemp();
var uvReg:ShaderRegisterElement = _useSecondaryUV? _sharedRegisters.secondaryUVVarying : _sharedRegisters.uvVarying;
vo.texturesIndex = textureReg.index;


return getTex2DSampleCode(vo, temp, textureReg, _texture, uvReg) +
"sub " + temp + ".z, " + temp + ".x, " + temp + ".y\n" + //store alpha - threshold (fc0.x) in temp ft.x
"kil " + temp + ".z\n";
//"mul " + targetReg + ", " + targetReg + ", " + temp + ".x\n";

}

public static function getBmdWithoutAlpha(bmd:BitmapData,defaultColor:uint):BitmapData {
var outBmd:BitmapData = new BitmapData(bmd.width, bmd.height, false, defaultColor);
var bm:Bitmap = new Bitmap(bmd);
outBmd.draw(bm);
return outBmd;
}

public static function getOnlyAlphaBmd(bmd:BitmapData,alphaThreshold:Number):BitmapData {
var outBmd:BitmapData = new BitmapData(bmd.width, bmd.height, false, 0x000000);
var i:int;
var j:int;
for (i = 0; i < bmd.width; i++) {
for (j = 0; j < bmd.height; j++) {
var color:uint = bmd.getPixel32(i, j);
var a:uint = color >>> 24;
//var r:uint = color >>> 16 & 0xFF;
//var g:uint = color >>> 8 & 0xFF;
//var b:uint = color & 0xFF;
var g:uint = 0xFF*alphaThreshold-a;
var r:uint = 0;
var b:uint = 0;
color = r << 16 | g << 8 | b;
outBmd.setPixel(i, j,color);
}
}
return outBmd;
}

}
}

You see kill opcode and how to use LexAlphaThresholdMethod from action script:
   var pngBmd:BitmapData = new branchClass().bitmapData;
var noAlphaBmd:BitmapData = LexAlphaThresholdMethod.getBmdWithoutAlpha(pngBmd, 0x00CC00);

branchMat = new TextureMaterial(new BitmapTexture(noAlphaBmd), true, true, true);
//branchMat = new TextureMaterial(new BitmapTexture(pngBmd), true, true, true);
//branchMat.alphaBlending = true;
//branchMat.alphaThreshold = 0.01;

var alphaBitmap:BitmapData = LexAlphaThresholdMethod.getOnlyAlphaBmd(pngBmd,0.05);

var lexAlphaThresholdMethod:LexAlphaThresholdMethod = new LexAlphaThresholdMethod(new BitmapTexture(alphaBitmap));
branchMat.addMethod(lexAlphaThresholdMethod);


How to export multiply texture mesh from blender to away.

The grass ring and fence on this demo it is a single mesh in blender, and it has a two texture.
 private function multiTextureObject():ObjectContainer3D {
var lobj:LObjData = new LObjData()
with (lobj) {include '\\blender\\MultiTextureMesh.txt';}
var materialArr:Array = [various0712_1_S$pngMat,grassMat];
var mesh:LMeshData = lobj.meshArr[0];
trace('mesh.textureArr ' + mesh.textureArr);
var lObj:LObjData = mesh.multiTextureMeshToObj(materialArr);

return Blender3DMesh.makeAwayObjFromLObjData(lObj);
}

To away3d it's goes as object3dContainer with two meshes, in blender3d it's run python script exportObjectsAsMultiTextureMesh.py you can find it in zip.
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
NB :: Bila Sobat tertarik Ingin membuat software, membeli software, membeli source code, membeli hardware elektronika untuk kepentingan Perusahaan maupun Tugas Akhir (TA/SKRIPSI), Insyaallah Saya siap membantu, untuk Respon Cepat dapat menghubungi kami, melalui :

No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com


atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :

ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِين
Alhamdulilah hirobil alamin

وَ السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
wassalamualaikum warahmatullahi wabarakatuh


Artikel Away3d alphaBlending and alphaThreshold, Diterbitkan oleh scodeaplikasi pada Rabu, 09 Oktober 2013. Semoga artikel ini dapat menambah wawasan Anda. Website ini dipost dari beberapa sumber, bisa cek disini sumber, Sobat diperbolehkan mengcopy paste / menyebar luaskan artikel ini, karena segala yang dipost di public adalah milik public. Bila Sobat tertarik Ingin membuat software, membeli software, membeli source code ,Dengan Cara menghubungi saya Ke Email: Fajarudinsidik@gmail.com, atau No Hp/WA : (fajar) : 085369237896, (puat) : 085267792168.

Tawk.to