I think the title says it all…
Does threejs have issues when handling blur-filtered html canvases?
Thanks…
<canvas id="myCanvas" width="800" height="800"></canvas>
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.163.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.163.0/examples/jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
canvas.width = 800;
canvas.height = 800;
let angleRed = 0;
let angleGreen = Math.PI / 4;
let angleBlue = Math.PI / 2;
let redSpeed = Math.random()*0.03;
let greenSpeed = Math.random()*0.03;
let blueSpeed = Math.random()*0.03;
let motionRadius = 50;
let proximity = 0;
let renderer = new THREE.WebGLRenderer( { antialias: true, alpha: true} );
renderer.setSize(800, 800);
document.body.appendChild( renderer.domElement );
let scene = new THREE.Scene();
let camera = new THREE.PerspectiveCamera( 45, 1, 0.1, 100 );
camera.position.z = 1.3;
let texture = new THREE.CanvasTexture(canvas);
const material = new THREE.MeshBasicMaterial({ map: texture });
const planeGeometry = new THREE.PlaneGeometry(1, 1);
const mesh = new THREE.Mesh(planeGeometry, material);
scene.add(mesh);
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw black background
ctx.fillStyle = 'black';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Update circle positions
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
const radius = 100;
const redX = centerX + Math.cos(-angleRed) * motionRadius;
const redY = centerY + Math.sin(angleRed) * motionRadius;
const greenX = centerX + Math.cos(angleGreen) * motionRadius;
const greenY = centerY + Math.sin(-angleGreen) * motionRadius;
const blueX = centerX + Math.cos(angleBlue) * motionRadius;
const blueY = centerY + Math.sin(angleBlue) * motionRadius;
// Draw red circle
ctx.fillStyle = '#34cceb';
ctx.beginPath();
ctx.arc(redX, redY, radius, 0, Math.PI * 2);
ctx.fill();
// Draw green circle
ctx.fillStyle = '#343aeb';
ctx.beginPath();
ctx.arc(greenX, greenY, radius, 0, Math.PI * 2);
ctx.fill();
// Draw blue circle
ctx.fillStyle = '#347deb';
ctx.beginPath();
ctx.arc(blueX, blueY, radius, 0, Math.PI * 2);
ctx.fill();
// Apply blur effect
ctx.filter = `blur(100px)`;
ctx.drawImage(canvas, 0, 0);
ctx.filter = 'none'; // Reset filter
// Increment angles for circular motion
angleRed += redSpeed;
angleGreen += greenSpeed;
angleBlue += blueSpeed;
texture.needsUpdate = true;
renderer.render(scene, camera);
requestAnimationFrame(draw);
}
draw();
</script>