Skip to content

Instantly share code, notes, and snippets.

@mcallegari10
Created October 20, 2020 19:54
Show Gist options
  • Save mcallegari10/1947ac928eafb23ad837b6b4653b293f to your computer and use it in GitHub Desktop.
Save mcallegari10/1947ac928eafb23ad837b6b4653b293f to your computer and use it in GitHub Desktop.
Particle Material
export function createPointMaterial(size, opacity = 1) {
const matCanvas = document.createElement('canvas')
matCanvas.width = size
matCanvas.height = size
const matContext = matCanvas.getContext('2d')
const texture = new CanvasTexture(matCanvas)
const center = size / 2
matContext.beginPath()
matContext.arc(center, center, size / 2, 0, 2 * Math.PI, false)
matContext.closePath()
matContext.fillStyle = `rgba(255, 255, 255, ${opacity})`
matContext.fill()
texture.needsUpdate = true
return texture
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment