Чтобы сделать частицы круглыми и светящимися, вы можете использовать текстуры для материала частиц и настроить параметры, такие как прозрачность и насыщенность. Вот как это сделать:
- Загрузить текстуру круглой частицы с радиальным градиентом для эффекта свечения.
- Установить эту текстуру для материала частиц, включить прозрачность и настроить насыщенность.
Пример кода с круглыми и светящимися частицами:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Круглые и светящиеся частицы с помощью Three.js</title>
<style>
body {
margin: 0;
}
canvas {
display: block;
}
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
// Создаем сцену, камеру и рендерер
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000
);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Загружаем текстуру для светящихся частиц
const loader = new THREE.TextureLoader();
loader.load("https://threejs.org/examples/textures/particle2.png", (texture) => {
createParticles(texture);
animate();
});
// Создаем геометрию частиц, материал частиц и систему частиц
function createParticles(texture) {
const particleCount = 1000;
const geometry = new THREE.BufferGeometry();
const positions = new Float32Array(particleCount * 3);
const velocities = new Float32Array(particleCount * 3);
for (let i = 0; i < particleCount * 3; i++) {
positions[i] = (Math.random() - 0.5) * 10;
velocities[i] = (Math.random() - 0.5) * 0.1;
}
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
const material = new THREE.PointsMaterial({
size: 0.5,
color: 0xffffff,
map: texture,
transparent: true,
blending: THREE.AdditiveBlending,
});
const particles = new THREE.Points(geometry, material);
// Добавляем систему частиц на сцену
scene.add(particles);
camera.position.z = 5;
}
// Анимационный цикл
function animate() {
requestAnimationFrame(animate);
// Обновляем положение частиц
const positions = scene.children[0].geometry.attributes.position.array;
const velocities = new Float32Array(positions.length);
for (let i = 0; i < positions.length; i++) {
positions[i] += velocities[i];
if (
positions[i] > 5 ||
positions[i] < -5
)
velocities[i] = -velocities[i];
}
scene.children[0].geometry.attributes.position.needsUpdate = true;
renderer.render(scene, camera);
}
</script>
</body>
</html>
Обратите внимание, что вам потребуется загрузить и использовать текстуру круглой частицы с радиальным градиентом для эффекта свечения. В этом примере мы загружаем текстуру из примеров Three.js, но вы можете использовать свою собственную текстуру, если предпочитаете.