Three.js - deepWrite против deepTest для карты текстур с прозрачным холстом на THREE.Points

Вопрос

Есть ли существенная разница междуdepthWrite: false а такжеdepthTest: false? Использует лиdepthTest предложить преимущество в производительности? Есть ли жертва в функциональности, выбирая один или другой?

Оригинальная проблема

Я хотел сделатьTHREE.Points объект с полупрозрачными кругами в качестве каждой точки. Я использовалTHREE.Texture загружен изcanvas элемент и передал егоmap собственность наTHREE.PointsMaterial.

Прозрачность не работала полностью, некоторые круги хорошо перекрывались, а другие вели себя так, как будто они были сплошными.

Я исправил это, узнав оdepthWrite: false а такжеdepthTest: false наTHREE.PointsMaterial.

Где я нахожусь

У меня есть пример кода (встроенный внизу), который показывает ошибку наложения точек и может использоватьdepthTest или жеdepthWrite починить это:

var points = new THREE.Points(
    new THREE.Geometry(),
    new THREE.PointsMaterial({
        //depthTest: false,
        //depthWrite: false,
        map: circleTexture,
        size: circleDiameter,
        transparent: true
    })
);

Я новичок во всем этом, но я попытался прочитать тему, и из того, что я могу сказать (поправьте меня, если я ошибаюсь), буфер глубины используется, чтобы определить, какие фрагменты закрыты и не нуждаются в рендеринге. Выключение либоdepthWrite или жеdepthTest освободит объект от этого процесса. Они отличаются тем, что:

depthWrite: false по-прежнему вычисляет глубину, но отображает весь объект независимо

depthTest: false даже не рассчитывает глубину

Похоже, я бы потерял некоторые качества объекта, отключивdepthTest вместоdepthWrite, но, возможно, получить повышение производительности, пропустив расчет в целом? Но какие качества я бы потерял? И есть ли разница в производительности? Здесь мое невежество просвечивает.

// Sizes
var sceneWidth = 200;
var sceneHeight = 200;
var lineLength = 50;
var circleRadius = 32;
var circleDiameter = circleRadius * 2;

// Renderer
var renderer = new THREE.WebGLRenderer({
    antialias: true,
    alpha: true
});
renderer.setSize(sceneWidth, sceneHeight);
document.body.appendChild(renderer.domElement);

// Scene
var scene = new THREE.Scene();

// Camera
var d = 100;
var aspect = sceneWidth / sceneHeight;
var camera = new THREE.OrthographicCamera(
    -d * aspect,
    d * aspect,
    d,
    -d,
    1,
    12000
);
camera.position.set(140, 140, 140);
scene.add(camera);

// Controls
var controls = new THREE.OrthographicTrackballControls(
    camera,
    renderer.domElement
);
controls.rotateSpeed = 0.2;
controls.addEventListener('change', function () {
    renderer.render(scene, camera);
});
window.addEventListener('resize', function() {
    controls.handleResize();
});

// Circle texture
var canvasEl = document.createElement('canvas');
var context = canvasEl.getContext('2d');
canvasEl.width = circleDiameter;
canvasEl.height = circleDiameter;
context.fillStyle = 'rgba(255, 255, 255, 0.5)';
context.beginPath();
context.arc(circleRadius, circleRadius, circleRadius, 0, Math.PI * 2);
context.fill();
var circleTexture = new THREE.Texture(canvasEl);
circleTexture.needsUpdate = true;

// Points
var points = new THREE.Points(
    new THREE.Geometry(),
    new THREE.PointsMaterial({
        //depthTest: false,
        //depthWrite: false,
        map: circleTexture,
        size: circleDiameter,
        transparent: true
    })
);
points.geometry.vertices.push(new THREE.Vector3(0, 0, 0));
points.geometry.vertices.push(new THREE.Vector3(0, lineLength, 0));
points.geometry.vertices.push(new THREE.Vector3(0, lineLength, lineLength));
points.geometry.vertices.push(new THREE.Vector3(0, 0, lineLength));
scene.add(points);

// Lines
var lines = new THREE.Line(
    new THREE.Geometry(),
    new THREE.LineBasicMaterial({
        linewidth: 1.2,
        color: 0xffffff,
        transparent: true,
        opacity: 0.25
    })
);
lines.geometry.vertices.push(new THREE.Vector3(0, 0, 0));
lines.geometry.vertices.push(new THREE.Vector3(0, lineLength, 0));
lines.geometry.vertices.push(new THREE.Vector3(0, lineLength, 0));
lines.geometry.vertices.push(new THREE.Vector3(0, lineLength, lineLength));
lines.geometry.vertices.push(new THREE.Vector3(0, lineLength, lineLength));
lines.geometry.vertices.push(new THREE.Vector3(0, 0, lineLength));
lines.geometry.vertices.push(new THREE.Vector3(0, 0, lineLength));
lines.geometry.vertices.push(new THREE.Vector3(0, 0, 0));
scene.add(lines);

// Render
function render() {
    window.requestAnimationFrame(render);
    renderer.render(scene, camera);
    controls.update();
}

render();
* { margin: 0; padding: 0; }
body { background-color: #333; }
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Document</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r76/three.min.js"></script>
<script src="http://threejs.org/examples/js/controls/OrthographicTrackballControls.js"></script>
</body>
</html>

Ответы на вопрос(1)

Ваш ответ на вопрос