0

この質問に関連: ParticleSystem の BufferGeometry での Z バッファの問題

サイズと UV のカスタム属性を追加したため、レンダリング用に独自のシェーダーを作成しました。Everythinf は、透明度のためのパーティクルの順序付けを除いて、バッファ ジオメトリで問題なく動作します。

アクティベート > 正方形のテクスチャの場合、他のパーティクルが部分的に隠れています。

Deactivated (depthTest : false) の場合 > 粒子は正常に見えますが、順序付けられていません。

回答ありがとうございます。この件は何度か提起されましたが、まだ何もうまくいきませんでした。

Three.js の使用 61

            particleMaterial = new THREE.ShaderMaterial({
                    fragmentShader    : document.getElementById("sectorPointFragment").textContent,
                    vertexShader  : document.getElementById("sectorPointVertex").textContent,
                    uniforms  : uniforms,
                    attributes : attributes,
                    transparent : true,
                    alphaTest : 0.5
                });         


            _this.particles = new THREE.ParticleSystem(geometry, particleMaterial);

            _this.particles.sortParticles = true;   
4

1 に答える 1

0

そこで、毎回値を持つ新しい配列を作成して、私が取った解決策を次に示します。動作するようで、1000 個の粒子でテスト済み

this.updateShaders = function() {
    if(clock.getElapsedTime() - _lastZOrdering <= 0.2) {
        return;
    }
    // z-ordering
    var distances = [],
        attributes = this.particles.geometry.attributes,
        nbParticle = attributes.position.numItems / 3,
        tmpPos = new THREE.Vector3(0, 0, 0);

    for (var i = 0; i < nbParticle; ++i) {
        tmpPos.set(
            attributes.position.array[i * 3],
            attributes.position.array[i * 3 + 1],
            attributes.position.array[i * 3 + 2]
        );
        distances[i] = [this.controls.object.position.distanceTo(tmpPos), i];
    }
    distances.sort(function(a, b){ 
        return b[0] - a[0];
    });

    var index, indexSrc, indexDst, tmpTab;
    for (var val in attributes) {
        tmpTab = new Float32Array(attributes[val].itemSize * nbParticle);
        for(i = 0; i < nbParticle; ++i){
            index = distances[i][1];
            for(j = 0; j < attributes[val].itemSize; ++j){
                indexSrc = index * attributes[val].itemSize + j;
                indexDst = i * attributes[val].itemSize + j;
                tmpTab[indexDst] = attributes[val].array[indexSrc];
            }
        }
        attributes[val].array = tmpTab;
        attributes[val].needsUpdate = true;
    }
    _lastZOrdering = clock.getElapsedTime();
}
于 2013-09-19T18:00:14.197 に答える