简体   繁体   English

three.js透明png纹理奇怪边框webgl

[英]three.js transparent png texture strange border webgl

I am having a strange problem when using pngs as a texture in three.js. 我在使用pngs作为three.js中的纹理时遇到了一个奇怪的问题。 The pngs get strange borders at the area between visible and transparent. png在可见和透明之间的区域有奇怪的边界。 I allready tried to play around with alphatest value but then sometimes the image disapears completly in areas where are really thin 1px lines. 我已经尝试过使用alphatest值,但有时候图像会在1px线条很薄的区域中完全消失。 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 } );

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 :-) 这是预览我的世界纹理包,效果很好:-)

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 请参阅此示例: http//threejs.org/examples/#webgl_materials_blending_custom

Congratulations, you've run directly into the Texel-to-Pixel-mapping-trap. 恭喜,您已直接进入Texel-to-Pixel-mapping-trap。 :) :)

This should help you out of there, although it's not WebGL the basics still apply. 应该可以帮助你摆脱困境,虽然它不是WebGL的基础知识仍然适用。

Ok, so I tried all the solutions on this page. 好的,所以我尝试了这个页面上的所有解决方案。 They all failed. 他们都失败了。

What worked for me was to use the correct Texture.wrapS (horizontal wrapping) and Texture.wrapT (vertical wrapping) for the sprite texture. 对我有用的是为精灵纹理使用正确的Texture.wrapS (水平包装)和Texture.wrapT (垂直包装)。

I personally was finding this ugly edge on the top of my sprite. 我个人在我的精灵顶部找到了这个丑陋的边缘。 I just had to make sure my Texture.wrapT setting was THREE.ClampToEdgeWrapping instead of THREE.RepeatWrapping . 我只是要确保我的Texture.wrapT设置被THREE.ClampToEdgeWrapping代替THREE.RepeatWrapping

Solved the issue perfectly without messing with alpha test values, texture filters, vertices or antialiasing. 在不弄乱alpha测试值,纹理滤镜,顶点或抗锯齿的情况下完美解决了这个问题。

i solved it like this: 我这样解决了:

            var c2GVertices = cube2Geometry.vertices;


            for (var i = 0; i < c2GVertices.length; i++) {
              c2GVertices[i].x =  c2GVertices[i].x - 0.5;
              c2GVertices[i].y =  c2GVertices[i].y - 0.5;
            }

is there an easier way to move all vertices a half pixel? 是否有更简单的方法将所有顶点移动半个像素?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM