Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

three.js transparent png texture strange border webgl

I am having a strange problem when using pngs as a texture in three.js. The pngs get strange borders at the area between visible and transparent. I allready tried to play around with alphatest value but then sometimes the image disapears completly in areas where are really thin 1px lines. Is there a solution how to solve this?

var explosionTexture = new THREE.ImageUtils.loadTexture( 'explosion.png' );
        boomer = new TextureAnimator( explosionTexture, 4, 4, 16, 55 ); // texture, #horiz, #vert, #total, duration.
        var explosionMaterial = new THREE.MeshBasicMaterial( { map: explosionTexture } );
        explosionMaterial.transparent = true;
        var cube2Geometry = new THREE.PlaneGeometry( 64, 64, 1, 1 );
        cube2 = new THREE.Mesh( cube2Geometry, explosionMaterial );
        cube2.position.set(100,26,0);
        scene.add(cube2);


        // renderer

        //renderer = new THREE.WebGLRenderer( { antialias: false, premultipliedAlpha: true  } );
        renderer = new THREE.WebGLRenderer( { antialias: false } );
like image 686
mixed_farmer Avatar asked Jul 02 '13 09:07

mixed_farmer


2 Answers

Just try this:

explosionTexture.anisotropy = 0;
explosionTexture.magFilter = THREE.NearestFilter;
explosionTexture.minFilter = THREE.NearestFilter;

Also you should not use antialaising when constructing the renderer:

renderer = new THREE.WebGLRenderer({antialias: false});

Did this to preview minecraft texture packs, works great :-)

like image 197
Pius Raeder Avatar answered Sep 20 '22 10:09

Pius Raeder


Use material blending, the following configuration worked for me:

material.blending = THREE.CustomBlending
material.blendSrc = THREE.OneFactor
material.blendDst = THREE.OneMinusSrcAlphaFactor

See this example: http://threejs.org/examples/#webgl_materials_blending_custom

like image 28
glued Avatar answered Sep 20 '22 10:09

glued