@mesmotronic/three-retropass
Version:
RetroPass applies a retro aesthetic to your Three.js project, emulating the visual style of classic 8-bit and 16-bit games
20 lines (19 loc) • 698 B
JavaScript
import * as THREE from 'three';
/**
* Convert THREE.Color[] to DataTexture
*/
export function createColorTexture(colors) {
const width = colors.length;
const height = 1;
const data = new Uint8Array(width * 4); // RGBA
for (let i = 0; i < colors.length; i++) {
const color = colors[i];
data[i * 4] = Math.floor(color.r * 255); // R
data[i * 4 + 1] = Math.floor(color.g * 255); // G
data[i * 4 + 2] = Math.floor(color.b * 255); // B
data[i * 4 + 3] = 255; // A (fully opaque)
}
const texture = new THREE.DataTexture(data, width, height, THREE.RGBAFormat, THREE.UnsignedByteType);
texture.needsUpdate = true;
return texture;
}