HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<script async src="https://ga.jspm.io/npm:[email protected]/dist/es-module-shims.js" crossorigin="anonymous"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/[email protected]/build/three.module.js",
"three/addons/": "https://unpkg.com/[email protected]/examples/jsm/",
"three-mesh-bvh": "https://cdn.skypack.dev/[email protected]",
"simplex-noise": "https://cdn.skypack.dev/[email protected]"
}
}
</script>
<script>
let noise = `// Simplex 4D Noise
// by Ian McEwan, Ashima Arts
//
vec4 permute(vec4 x){return mod(((x*34.0)+1.0)*x, 289.0);}
float permute(float x){return floor(mod(((x*34.0)+1.0)*x, 289.0));}
vec4 taylorInvSqrt(vec4 r){return 1.79284291400159 - 0.85373472095314 * r;}
float taylorInvSqrt(float r){return 1.79284291400159 - 0.85373472095314 * r;}
vec4 grad4(float j, vec4 ip){
const vec4 ones = vec4(1.0, 1.0, 1.0, -1.0);
vec4 p,s;
p.xyz = floor( fract (vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0;
p.w = 1.5 - dot(abs(p.xyz), ones.xyz);
s = vec4(lessThan(p, vec4(0.0)));
p.xyz = p.xyz + (s.xyz*2.0 - 1.0) * s.www;
return p;
}
float snoise(vec4 v){
const vec2 C = vec2( 0.138196601125010504, // (5 - sqrt(5))/20 G4
0.309016994374947451); // (sqrt(5) - 1)/4 F4
// First corner
vec4 i = floor(v + dot(v, C.yyyy) );
vec4 x0 = v - i + dot(i, C.xxxx);
// Other corners
// Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI)
vec4 i0;
vec3 isX = step( x0.yzw, x0.xxx );
vec3 isYZ = step( x0.zww, x0.yyz );
// i0.x = dot( isX, vec3( 1.0 ) );
i0.x = isX.x + isX.y + isX.z;
i0.yzw = 1.0 - isX;
// i0.y += dot( isYZ.xy, vec2( 1.0 ) );
i0.y += isYZ.x + isYZ.y;
i0.zw += 1.0 - isYZ.xy;
i0.z += isYZ.z;
i0.w += 1.0 - isYZ.z;
// i0 now contains the unique values 0,1,2,3 in each channel
vec4 i3 = clamp( i0, 0.0, 1.0 );
vec4 i2 = clamp( i0-1.0, 0.0, 1.0 );
vec4 i1 = clamp( i0-2.0, 0.0, 1.0 );
// x0 = x0 - 0.0 + 0.0 * C
vec4 x1 = x0 - i1 + 1.0 * C.xxxx;
vec4 x2 = x0 - i2 + 2.0 * C.xxxx;
vec4 x3 = x0 - i3 + 3.0 * C.xxxx;
vec4 x4 = x0 - 1.0 + 4.0 * C.xxxx;
// Permutations
i = mod(i, 289.0);
float j0 = permute( permute( permute( permute(i.w) + i.z) + i.y) + i.x);
vec4 j1 = permute( permute( permute( permute (
i.w + vec4(i1.w, i2.w, i3.w, 1.0 ))
+ i.z + vec4(i1.z, i2.z, i3.z, 1.0 ))
+ i.y + vec4(i1.y, i2.y, i3.y, 1.0 ))
+ i.x + vec4(i1.x, i2.x, i3.x, 1.0 ));
// Gradients
// ( 7*7*6 points uniformly over a cube, mapped onto a 4-octahedron.)
// 7*7*6 = 294, which is close to the ring size 17*17 = 289.
vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ;
vec4 p0 = grad4(j0, ip);
vec4 p1 = grad4(j1.x, ip);
vec4 p2 = grad4(j1.y, ip);
vec4 p3 = grad4(j1.z, ip);
vec4 p4 = grad4(j1.w, ip);
// Normalise gradients
vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;
p4 *= taylorInvSqrt(dot(p4,p4));
// Mix contributions from the five corners
vec3 m0 = max(0.6 - vec3(dot(x0,x0), dot(x1,x1), dot(x2,x2)), 0.0);
vec2 m1 = max(0.6 - vec2(dot(x3,x3), dot(x4,x4) ), 0.0);
m0 = m0 * m0;
m1 = m1 * m1;
return 49.0 * ( dot(m0*m0, vec3( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 )))
+ dot(m1*m1, vec2( dot( p3, x3 ), dot( p4, x4 ) ) ) ) ;
}`;
</script>
body{
overflow: hidden;
margin: 0;
}
import * as THREE from "three";
import { OrbitControls } from "three/addons/controls/OrbitControls";
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader';
import * as BufferGeometryUtils from "three/addons/utils/BufferGeometryUtils";
import { RoomEnvironment } from "three/addons/environments/RoomEnvironment";
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer';
import { RenderPass } from 'three/addons/postprocessing/RenderPass';
import { ShaderPass } from "three/addons/postprocessing/ShaderPass";
import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass';
import { computeBoundsTree, disposeBoundsTree, acceleratedRaycast } from 'three-mesh-bvh';
import { createNoise3D } from "simplex-noise";
console.clear();
//console.log(CurveModifier);
class Postprocessing {
constructor(scene, camera, renderer) {
const renderScene = new RenderPass(scene, camera);
const bloomPass = new UnrealBloomPass(
new THREE.Vector2(window.innerWidth, window.innerHeight),
2,
0.25,
0
);
let samples = 4;
const target1 = new THREE.WebGLRenderTarget(
window.innerWidth,
window.innerHeight,
{
type: THREE.FloatType,
format: THREE.RGBAFormat,
encoding: THREE.sRGBEncoding,
samples: samples
}
);
this.bloomComposer = new EffectComposer(renderer, target1);
this.bloomComposer.renderToScreen = false;
this.bloomComposer.addPass(renderScene);
this.bloomComposer.addPass(bloomPass);
const finalPass = new ShaderPass(
new THREE.ShaderMaterial({
uniforms: {
baseTexture: { value: null },
bloomTexture: { value: this.bloomComposer.renderTarget2.texture }
},
vertexShader: `varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); }`,
fragmentShader: `uniform sampler2D baseTexture; uniform sampler2D bloomTexture; varying vec2 vUv; void main() { gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) ); }`,
defines: {}
}),
"baseTexture"
);
finalPass.needsSwap = true;
const target2 = new THREE.WebGLRenderTarget(
window.innerWidth,
window.innerHeight,
{
type: THREE.FloatType,
format: THREE.RGBAFormat,
encoding: THREE.sRGBEncoding,
samples: samples
}
);
this.finalComposer = new EffectComposer(renderer, target2);
this.finalComposer.addPass(renderScene);
this.finalComposer.addPass(finalPass);
this.finalComposer.setPixelRatio( window.devicePixelRatio )
renderer.setPixelRatio( window.devicePixelRatio )
}
}
class Pattern extends THREE.LineSegments {
constructor(gu) {
let _startPoint = new THREE.Vector3();
let _endPoint = new THREE.Vector3();
let allPts = [];
// <vegetation>
segmentedElement(_startPoint.set(0.1, 0, 0), _endPoint.set(0.9, 0, 0), 10);
segmentedElement(_startPoint.set(0.1, 1, 0), _endPoint.set(0.9, 1, 0), 10);
segmentate(
new THREE.Path().absarc(0.5, 0.5, 0.5, 0, Math.PI).getSpacedPoints(10)
);
let c = new THREE.Vector2(0, 0);
let c1 = new THREE.Vector2(0.25, 0);
let c2 = new THREE.Vector2(0.5, 0);
let v1 = new THREE.Vector2(),
v2 = new THREE.Vector2();
let segs = 10;
for (let i = 0; i <= segs; i++) {
v1.copy(c1).rotateAround(c, (Math.PI / segs) * i);
v2.copy(c2).rotateAround(c, (Math.PI / segs) * i);
segmentate(
new THREE.Path()
.moveTo(0.5, 0)
.quadraticCurveTo(v1.x + 0.5, v1.y + 0.5, v2.x + 0.5, v2.y + 0.5)
.getSpacedPoints(10)
);
}
let g1 = new THREE.BufferGeometry()
.setFromPoints(allPts)
.scale(0.9, 0.75, 1)
.translate(0.0, -1, 0);
setGeometryAttributes(g1, { rotDir: -1 });
// </vegetation>
// <ankh>
allPts = [];
segmentate(
new THREE.Path()
.moveTo(0.4, 0)
.lineTo(0.6, 0)
.lineTo(0.55, 0.45)
.lineTo(0.9, 0.4)
.lineTo(0.9, 0.6)
.lineTo(0.55, 0.55)
.absarc(0.5, 0.8, 0.2, 0, Math.PI)
.lineTo(0.45, 0.55)
.lineTo(0.1, 0.6)
.lineTo(0.1, 0.4)
.lineTo(0.45, 0.45)
.lineTo(0.4, 0)
.getPoints(100)
);
segmentate(
new THREE.Path()
.moveTo(0.5, 0.6)
.lineTo(0.5, 0.6)
.absarc(0.5, 0.8, 0.1, 0, Math.PI)
.lineTo(0.5, 0.6)
.getPoints(50)
);
let g2 = new THREE.BufferGeometry()
.setFromPoints(allPts)
//.translate(0, -1, 0);
setGeometryAttributes(g2, { rotDir: 1 });
// </ankh>
let g = BufferGeometryUtils.mergeBufferGeometries([g1, g2]);
let ig = new THREE.InstancedBufferGeometry().copy(g);
ig.instanceCount = 32;
let m = new THREE.LineBasicMaterial({
color: 0x442208,
onBeforeCompile: (shader) => {
shader.uniforms.time = gu.time;
shader.uniforms.globalBloom = gu.globalBloom;
shader.vertexShader = `
uniform float time;
attribute float rotDir;
mat2 rot(float a){
float c = cos(a);
float s = sin(a);
return mat2(c, -s, s, c);
}
${shader.vertexShader}
`.replace(
`#include <begin_vertex>`,
`#include <begin_vertex>
float t = time * 0.01;
float amount = ${ig.instanceCount}.;
float radiusBase = 4.;
float angleStep = PI2 / amount;
float angle = (angleStep * float(gl_InstanceID)) + angleStep * position.x;
angle = mod(angle + t * PI2 * rotDir, PI2);
transformed.xy = rot(angle) * vec2(0., radiusBase + position.y);
`
);
//console.log(shader.vertexShader);
shader.fragmentShader = `
uniform float globalBloom;
${shader.fragmentShader}
`.replace(
`#include <dithering_fragment>`,
`#include <dithering_fragment>
gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(0), globalBloom);
`
);
//console.log(shader.fragmentShader)
}
});
super(ig, m);
function segmentate(pts) {
for (let i = 0; i < pts.length - 1; i++) {
allPts.push(pts[i].clone(), pts[i + 1].clone());
}
}
function segmentedElement(start, end, division = 10) {
for (let i = 0; i < division; i++) {
allPts.push(
new THREE.Vector3().lerpVectors(
start,
end,
THREE.MathUtils.clamp(i / division, 0, 1)
)
);
allPts.push(
new THREE.Vector3().lerpVectors(
start,
end,
THREE.MathUtils.clamp((i + 1) / division, 0, 1)
)
);
}
}
function setGeometryAttributes(geometry, params) {
let rotDir = new Array(geometry.attributes.position.count).fill(
params.rotDir
);
geometry.setAttribute(
"rotDir",
new THREE.Float32BufferAttribute(rotDir, 1)
);
}
}
}
// <CurveModifier>
const CHANNELS = 4;
const TEXTURE_WIDTH = 1024;
const TEXTURE_HEIGHT = 4;
function initSplineTexture( numberOfCurves = 1 ) {
const dataArray = new Float32Array( TEXTURE_WIDTH * TEXTURE_HEIGHT * numberOfCurves * CHANNELS );
const dataTexture = new THREE.DataTexture(
dataArray,
TEXTURE_WIDTH,
TEXTURE_HEIGHT * numberOfCurves,
THREE.RGBAFormat,
THREE.FloatType
);
//dataTexture.magFilter = THREE.NearestFilter;
dataTexture.needsUpdate = true;
return dataTexture;
}
function updateSplineTexture( texture, splineCurve, offset = 0, closed ) {
const numberOfPoints = TEXTURE_WIDTH;
splineCurve.arcLengthDivisions = numberOfPoints / 2;
splineCurve.updateArcLengths();
const points = splineCurve.getSpacedPoints( numberOfPoints );
const frenetFrames = splineCurve.computeFrenetFrames( numberOfPoints, closed );
for ( let i = 0; i < numberOfPoints; i ++ ) {
const rowOffset = Math.floor( i / TEXTURE_WIDTH );
const rowIndex = i % TEXTURE_WIDTH;
let pt = points[ i ];
setTextureValue( texture, rowIndex, pt.x, pt.y, pt.z, 0 + rowOffset + ( 4 * offset ) );
pt = frenetFrames.tangents[ i ];
setTextureValue( texture, rowIndex, pt.x, pt.y, pt.z, 1 + rowOffset + ( 4 * offset ) );
pt = frenetFrames.normals[ i ];
setTextureValue( texture, rowIndex, pt.x, pt.y, pt.z, 2 + rowOffset + ( 4 * offset ) );
pt = frenetFrames.binormals[ i ];
setTextureValue( texture, rowIndex, pt.x, pt.y, pt.z, 3 + rowOffset + ( 4 * offset ) );
}
texture.needsUpdate = true;
}
function setTextureValue( texture, index, x, y, z, o ) {
const image = texture.image;
const { data } = image;
const i = 4 * texture.source.data.width * o; // Row Offset
data[ index * 4 + i + 0 ] = x;
data[ index * 4 + i + 1 ] = y;
data[ index * 4 + i + 2 ] = z;
data[ index * 4 + i + 3 ] = 1;
}
// </CurveModifier>
THREE.BufferGeometry.prototype.computeBoundsTree = computeBoundsTree;
THREE.BufferGeometry.prototype.disposeBoundsTree = disposeBoundsTree;
THREE.Mesh.prototype.raycast = acceleratedRaycast;
let noise3D = createNoise3D();
let gu = {
time: {value: 0},
globalBloom: {value: 0}
}
class Curves{
constructor(model, modelSize, curveAmount, basePointsAmount){
let raycaster = new THREE.Raycaster();
raycaster.firstHitOnly = true;
let ori = new THREE.Vector3(); // origin
let dir = new THREE.Vector3(); // direction
let v3 = new THREE.Vector3();
let found;
let angleStep = Math.PI * 2 / curveAmount;
let heightStep = modelSize.y / basePointsAmount;
model.geometry.computeBoundsTree();
this.curves = [];
for(let i = 0; i < curveAmount; i++){
let pts = [];
v3.setFromCylindricalCoords(1, angleStep * i, 0);
for(let idx = (5 + THREE.MathUtils.randInt(0, 40)); idx < (basePointsAmount - THREE.MathUtils.randInt(0, 40)); idx++){
let angleNoise = noise3D(v3.x, (heightStep * idx) / modelSize.y * 5, v3.z) * Math.PI * 0.1;
let a = angleNoise + angleStep * i;
let h = heightStep * idx;
let r = 100;
ori.setFromCylindricalCoords(r, a, h);
dir.copy(ori).setY(0).normalize().negate();
raycaster.set(ori, dir);
found = raycaster.intersectObject(model);
if (found.length > 0) pts.push(found[0].point.addScaledVector(found[0].face.normal, 0));
}
this.curves.push(new THREE.CatmullRomCurve3(pts));
}
}
}
let bgColors = {
on: new THREE.Color(1, 0.25, 0).multiplyScalar(0.25).getHex(),
off: 0x000000
}
let scene = new THREE.Scene();
scene.background = new THREE.Color(bgColors.off);
let camera = new THREE.PerspectiveCamera(30, innerWidth / innerHeight, 1, 1000);
camera.position.set(-5, 0, 13).setLength(50);
scene.add(camera);
let renderer = new THREE.WebGLRenderer({ antialias: false });
renderer.toneMapping = THREE.ReinhardToneMapping;
renderer.toneMappingExposure = Math.pow( 1.2, 4.0 );
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);
window.addEventListener("resize", (event) => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
postprocessing.bloomComposer.setSize(innerWidth, innerHeight);
postprocessing.finalComposer.setSize(innerWidth, innerHeight);
});
const pmremGenerator = new THREE.PMREMGenerator(renderer);
const bgt = pmremGenerator.fromScene(new RoomEnvironment(), 0.04).texture;
scene.environment = bgt;
//scene.background = bgt;
let controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.enablePan = false;
controls.maxDistance = 200;
let light = new THREE.DirectionalLight(0xffffff, 0.5);
light.position.set(0, 1, 2);
scene.add(light, new THREE.AmbientLight(0xffffff, 0.5));
let loader = new GLTFLoader();
let gltf = await loader.loadAsync("https://threejs.org/examples/models/gltf/Nefertiti/Nefertiti.glb");
let model = gltf.scene;
model.traverse(child => {
if(child.isMesh){
child.material.map = null;
child.material.normalMap = null;
child.material.side = THREE.DoubleSide;
}
})
let box = new THREE.Box3().setFromObject(model);
let size = new THREE.Vector3();
box.getSize(size);
camera.position.y = size.y * 0.2;
controls.target.set(0, size.y * 0.465, 0);
controls.update();
//scene.add(model);
let curveAmount = 500;
let basePointsAmount = 300;
let curves = new Curves(model.children[0], size, curveAmount, basePointsAmount);
let dataTexture = initSplineTexture(curveAmount);
console.log(dataTexture);
let instIdx = []; //index
let instDur = []; //duration
let instDel = []; //delay
curves.curves.forEach((curve, cIdx) => {
updateSplineTexture(dataTexture, curve, cIdx, false);
instIdx.push(cIdx);
instDur.push(Math.random() * 2 + 8);
instDel.push(Math.random() + 1);
})
const radialSegs = 5;
/*let g = BufferGeometryUtils.mergeBufferGeometries([
new THREE.CylinderGeometry(1, 1, 1, radialSegs, pointsAmount, true).translate(
0,
0.5,
0
),
new THREE.SphereGeometry(
1,
radialSegs,
radialSegs,
0,
Math.PI * 2,
0,
Math.PI * 0.5
).translate(0, 1, 0),
new THREE.SphereGeometry(
1,
radialSegs,
radialSegs,
0,
Math.PI * 2,
Math.PI * 0.5,
Math.PI * 0.5
)
]);
*/
let g = new THREE.CylinderGeometry(1, 1, 1, radialSegs, basePointsAmount)
.translate(0, 0.5, 0)
.rotateZ(-Math.PI * 0.5)
.setAttribute("instIdx", new THREE.InstancedBufferAttribute(new Float32Array(instIdx), 1))
.setAttribute("instDur", new THREE.InstancedBufferAttribute(new Float32Array(instDur), 1))
.setAttribute("instDel", new THREE.InstancedBufferAttribute(new Float32Array(instDel), 1));
let gi = new THREE.InstancedBufferGeometry().copy(g);
gi.instanceCount = curveAmount;
let m = new THREE.MeshStandardMaterial({
color: 0xdf6222, //0xff3030,
roughness: 0.125,
metalness: 1,
onBeforeCompile: shader => {
shader.uniforms.time = gu.time;
shader.uniforms.globalBloom = gu.globalBloom;
shader.uniforms.dataTexture = {value: dataTexture};
shader.uniforms.radius = m.userData.uniforms.radius;
shader.uniforms.eyeAppearance = m.userData.uniforms.eyeAppearance;
shader.vertexShader = `
uniform float time;
uniform sampler2D dataTexture;
uniform float radius;
attribute float instIdx;
attribute float instDur;
attribute float instDel;
varying vec3 vPos;
float textureLayers = 4. * ${curveAmount}.;
float textureStacks = 1.;
${shader.vertexShader}
`.replace(
`#include <defaultnormal_vertex>`, ``
).replace(
`#include <normal_vertex>`, ``
)
.replace(
`#include <begin_vertex>`,
`#include <begin_vertex>
float elongation = clamp((time - instDel) / instDur, 0., 1.);
float canElongate = elongation > 0. ? 1. : 0.;
float mt = position.x * elongation;
float rowOffset = instIdx * 4.;
vec3 spinePos = texture2D(dataTexture, vec2(mt, (0. + rowOffset + 0.5) / textureLayers)).xyz;
vec3 a = texture2D(dataTexture, vec2(mt, (1. + rowOffset + 0.5) / textureLayers)).xyz;
vec3 b = texture2D(dataTexture, vec2(mt, (2. + rowOffset + 0.5) / textureLayers)).xyz;
vec3 c = texture2D(dataTexture, vec2(mt, (3. + rowOffset + 0.5) / textureLayers)).xyz;
mat3 basis = mat3(a, b, c);
transformed = basis
* (position * radius * canElongate)
+ spinePos;
vec3 transformedNormal = normalMatrix * (basis * objectNormal);
vPos = transformed;
#include <normal_vertex>
`
);
//console.log(shader.vertexShader);
shader.fragmentShader = `
#define S(a, b, c) smoothstep(a, b, c)
uniform float time;
uniform float globalBloom;
uniform float eyeAppearance;
varying vec3 vPos;
${shader.fragmentShader}
`.replace(
`#include <dithering_fragment>`,
`
#include <dithering_fragment>
float appearance = 0.;
appearance = max(appearance, S(eyeAppearance, eyeAppearance + 1., time));
vec2 symmetry = vec2(abs(vPos.x - 0.1425), vPos.y);
vec2 eyePos = vec2(1.39, 18.45);
float eye = distance(symmetry, eyePos);
float f = S(0.6, 0.05, eye) * clamp(sign(vPos.z), 0., 1.) * appearance;
vec3 colShine = vec3(0.125, 0.5, 1); // eyes
vec3 ringCol1 = vec3(1, 0.25, 0.25); // ring color 1
vec3 ringCol2 = vec3(0.25, 0.5, 1); // ring color 2
// planes
vec3 planeDir = normalize(vec3(0, 1, -0.65));
float timeStep = 0.5;
float d =S(0.25, 0., abs(19.5 - dot(vPos, planeDir)));
colShine = mix(colShine, ringCol1, d);
float ring1app = S(eyeAppearance + 2.5 * timeStep, eyeAppearance + 4.5 * timeStep, time);
f = max(f, d * ring1app);
appearance = max(appearance, ring1app);
d =S(0.25, 0., abs(18. - dot(vPos, planeDir)));
colShine = mix(colShine, ringCol2, d);
float ring2app = S(eyeAppearance + 2.25 * timeStep, eyeAppearance + 4.25 * timeStep, time);
f = max(f, d * ring2app);
appearance = max(appearance, ring2app);
d =S(0.25, 0., abs(16. - dot(vPos, planeDir)));
colShine = mix(colShine, ringCol1, d);
float ring3app = S(eyeAppearance + 2.0 * timeStep, eyeAppearance + 4.0 * timeStep, time);
f = max(f, d * ring3app);
appearance = max(appearance, ring3app);
vec3 cntr = vec3(0., 8., 1.);
d = S(0.2, 0., abs(5. - distance(vPos, cntr))) * (vPos.y < 8. ? 1. : 0.);
colShine = mix(colShine, ringCol2, d);
float sphereApp = S(eyeAppearance + 4.0 * timeStep, eyeAppearance + 6.0 * timeStep, time);
f = max(f, d * sphereApp);
appearance = max(appearance, sphereApp);
f *= f * f * f * appearance;
vec3 colBloomNone = mix(gl_FragColor.rgb, colShine, f);
vec3 colBloom = mix(vec3(0), vec3(0.375), f * f * f);
gl_FragColor.rgb = mix(colBloomNone, colBloom, globalBloom);
`
);
//console.log(shader.fragmentShader)
}
});
m.userData.uniforms = {
radius: {value: 0.075},
eyeAppearance: {value: 13}
}
let o = new THREE.Mesh(gi, m);
o.frustumCulled = false;
scene.add(o);
let pattern = new Pattern(gu);
pattern.position.z = -900;
pattern.scale.setScalar(48);
camera.add(pattern);
let postprocessing = new Postprocessing(scene, camera, renderer);
let clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
let t = clock.getElapsedTime();
gu.time.value = t;
controls.update();
//renderer.render(scene, camera);
gu.globalBloom.value = 1;
scene.background.set(bgColors.off);
postprocessing.bloomComposer.render();
gu.globalBloom.value = 0;
scene.background.set(bgColors.on);
postprocessing.finalComposer.render();
});
Also see: Tab Triggers