JSFiddle - React, Tailwind, and code Playground
HTML
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three/build/three.module.js"
}
}
</script>
JavaScript
import * as THREE from 'three';
THREE.ShaderChunk.fog_pars_fragment += `
uniform vec3 poo;
`;
THREE.ShaderChunk.fog_fragment = `#ifdef USE_FOG
gl_FragColor.rgb = fract(poo);
#endif
`;
const poo = new THREE.Color( 'brown' );
poo.clone = function() {
return this;
};
for(let i in THREE.ShaderLib) {
THREE.ShaderLib[i].uniforms.poo = {
value: poo
};
}
// init
const camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
camera.position.z = 1;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog();
const geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
const material = new THREE.MeshBasicMaterial();
const mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
const renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animation );
document.body.appendChild( renderer.domElement );
// animation
function animation( time ) {
poo.g = time / 123;
poo.g -= Math.floor( poo.g );
poo.b = 1 - poo.g; poo.r = 1 - poo.g * poo.b;
mesh.scale.setScalar( 1 + 0.456 * ( poo.g ** 2 ) );
mesh.rotation.x = time / 2000;
mesh.rotation.y = time / 1000;
renderer.render( scene, camera );
}