gpt4 book ai didi

Three.js PointsMaterial AdditiveBlending 神器

转载 作者:行者123 更新时间:2023-12-01 12:19:41 31 4
gpt4 key购买 nike

为什么 Points AdditiveBlending 只在从右看而不是从左看时有效?设置 depthTest:false 会解决问题,但会引发另一个问题,即点覆盖其他网格。

<html>
<head>
<title>My first three.js app</title>
<style>
html
,body
{height: 100%;}
body { margin: 0; }
canvas { width: 100%; height: 100% }
</style>
</head>
<body>

<script src="/lib/threejs/three.js-master/build/three.js"></script>
<script src="/lib/threejs/three.js-master/examples/js/controls/OrbitControls.js"></script>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );

var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );


var buffer_geometry=new THREE.BufferGeometry();
var vertices=new Float32Array([
-1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
])
buffer_geometry.addAttribute('position',new THREE.BufferAttribute(vertices,3));


var controls=new THREE.OrbitControls(camera, renderer.domElement);

var material = new THREE.PointsMaterial({
color:0x330000,
transparent:true,
// depthTest:false,
blending:THREE.AdditiveBlending,
size:.3,
})

var mesh = new THREE.Points( buffer_geometry, material );
scene.add( mesh );

camera.position.z = 5;

var animate = function () {
requestAnimationFrame( animate );

renderer.render(scene, camera);
};

animate();
</script>
</body>
</html>

最佳答案

使用 Three.Points,点按照它们在缓冲区中出现的顺序呈现。如果启用深度测试,您可能会看到不同的结果,具体取决于相机位置和观察方向。

由于您使用的是加法混合,解决方法是最后渲染点,并禁用深度写入。

var material = new THREE.PointsMaterial( {
depthWrite: false,
blending: THREE.AdditiveBlending
} )

mesh.renderOrder = 999;

three.js r.86

关于Three.js PointsMaterial AdditiveBlending 神器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45408136/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com