Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
139 lines (110 sloc) 3.44 KB
import THREE from '../third_party/three.js';
import { renderer, getOrthoCamera } from '../modules/three.js';
import Maf from '../modules/maf.js';
import OrbitControls from '../third_party/THREE.OrbitControls.js';
import easings from '../modules/easings.js';
import { Post } from '../modules/lines-glow.js';
import { Curves } from '../third_party/THREE.CurveExtras.js';
import { TubeBufferGeometry } from '../modules/three-tube-geometry.js';
import { parabola } from '../shaders/functions.js';
const vertexShader = `
precision highp float;
attribute vec3 position;
attribute vec2 uv;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform vec3 cameraPosition;
uniform float time;
uniform float offset;
varying vec3 vPosition;
varying vec2 vUv;
varying float vDepth;
#define PI 3.1415926535897932384626433832795
#define TAU (2.*PI)
${parabola}
void main() {
vUv = uv;
vec3 p = position;
vec4 mvPosition = modelViewMatrix * vec4( p, 1. );
gl_Position = projectionMatrix * mvPosition;
vDepth = 1.5-20.*abs(gl_Position.z);
}
`;
const fragmentShader = `
precision highp float;
uniform float time;
uniform float offset;
uniform vec3 color;
uniform float speed;
varying vec2 vUv;
varying float vDepth;
#define PI 3.1415926535897932384626433832795
#define TAU (2.*PI)
${parabola}
float v(vec2 uv, float offset, float t){
float l = 20.;
float o = .05 + .95*parabola(mod(1.*uv.x+1.*t+offset,1.),l);
return o;
}
vec3 color1 = vec3(69.,91.,105.)/255.;
vec3 color2 = vec3(249.,122.,77.)/255.;
vec3 color3 = vec3(195.,58.,78.)/255.;
void main(){
vec2 s = 1.*vec2(480.,40.);
vec2 uv = floor(vUv * s)/s;
vec2 uv2 = mod(vUv*s*vec2(1.,3.),1.);
float i = floor(mod(vUv.y*s.y*3.,3.));
float e = 1./3.;
float t = -2.* time/3.;
float o1 = v(uv, 0., t);
float o2 = v(uv, e, t);
float o3 = v(uv, -e, t);
float stripe = .5 +.5 * sin(3.*(1.*uv.y+3.*uv.x)*TAU-3.*3.*t*TAU);
float v = 1.-.95*smoothstep(.25,.75,stripe);
vec3 color = v*vDepth*(o1*color1+o2*color2+o3*color3)/1.;
if(i==0.) color.yz *= 0.;
if(i==1.) color.xz *= 0.;
if(i==2.) color.xy *= 0.;
float d = smoothstep(.25,.75,1.-1.*length(uv2-.5));
gl_FragColor = vec4(color*d,1.);
}
`;
const canvas = renderer.domElement;
const camera = getOrthoCamera(2.25, 2.25);
const controls = new OrbitControls(camera, canvas);
controls.screenSpacePanning = true;
const scene = new THREE.Scene();
const group = new THREE.Group();
const post = new Post(renderer, { minLeveL: .25, maxLevel: .5, gamma: 1. });
const r = .2;
const curve = new THREE.Curves.TrefoilKnot();
const geo = new THREE.TorusKnotBufferGeometry(1, .5, 200, 36, 1, 3);
const mat = new THREE.RawShaderMaterial({
uniforms: {
time: { value: 0 },
speed: { value: 1 },
offset: { value: 0 },
color: { value: new THREE.Color(0x455b69) }
},
vertexShader,
fragmentShader,
wireframe: false,
side: THREE.DoubleSide
})
const mesh = new THREE.Mesh(geo, mat);
group.add(mesh);
scene.add(group);
camera.position.set(0, 0, 1);
camera.lookAt(new THREE.Vector3(0, 0, 0));
camera.rotation.z -= Maf.PI / 2;
renderer.setClearColor(0x010203, 1);
const loopDuration = 4;
function draw(startTime) {
const time = (.001 * (performance.now() - startTime)) % loopDuration;
const t = Maf.mod(time / loopDuration - .5, 1);
mesh.material.uniforms.time.value = t;
//mesh.scale.setScalar(1. - .5 * Maf.parabola(t, 10.));
group.rotation.z = 1 * t * Maf.TAU / 3;
post.render(scene, camera);
}
export { renderer, draw, loopDuration, canvas };
You can’t perform that action at this time.