JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdn.jsdelivr.net/npm/three@0.144/build/three.min.js"></script>
JavaScript
const w = document.documentElement.clientWidth;
const h = document.documentElement.clientHeight;
const scene = new THREE.Scene();
//RENDERER
const renderer = new THREE.WebGL1Renderer();
renderer.powerPreference = "high-performance";
renderer.setSize(w, h);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setClearColor(0x000000, 1);
document.body.appendChild(renderer.domElement);
//CAMERA
const camera = new THREE.PerspectiveCamera(45, 1, 1, 1000);
camera.position.set(0, 0, 2);
camera.lookAt(new THREE.Vector3(0, 0, 0));
camera.fov = 2 * (180/Math.PI) * Math.atan(1 / 4);
camera.aspect = w / h;
camera.updateProjectionMatrix();
scene.add(camera);
// const mat = new THREE.MeshBasicMaterial({color: 0xff0000});
// const geo = new THREE.PlaneGeometry(camera.aspect, 1);
// const mesh = new THREE.Mesh(geo, mat);
// scene.add(mesh);
//SHADER
const shaderVert = `
precision mediump float;
uniform float time;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
attribute vec3 position;
attribute vec4 offset;
attribute vec2 uv;
varying vec3 vPosition;
varying float vTime;
void main ()
{
vPosition = offset.xyz;
vTime = sin(time + offset.w);
float scale = 0.001;
//BILLBOARD
gl_Position = projectionMatrix * (modelViewMatrix * vec4(vPosition, 1.0) + vec4(position.xy * scale, 0.0, 0.0));
}
`;
const shaderFrag = `
precision mediump float;
varying float vTime;
void main ()
{
vec4 color = vec4(vTime, vTime, vTime, 1.0);
gl_FragColor = color;
}
`;
//BUFFERGEOMETRY
const COUNT = 1000 * 1000;
const TAU = Math.PI * 2;
let step = 0;
const positions = [];
const uvs = [];
const offsets = [];
positions.push( 0.5, -0.5, 0.0);
positions.push( 0.5, 0.5, 0.0);
positions.push(-0.5, 0.5, 0.0);
positions.push( 0.5, -0.5, 0.0);
positions.push(-0.5, 0.5, 0.0);
positions.push(-0.5, -0.5, 0.0);
uvs.push(1.0, 0.0);
uvs.push(1.0, 1.0);
uvs.push(0.0, 1.0);
uvs.push(1.0, 0.0);
uvs.push(0.0, 1.0);
uvs.push(0.0, 0.0);
for (let i = 0; i < COUNT;...