|
| 1 | +var regl = require('regl')() |
| 2 | +var camera = require('regl-camera')(regl, |
| 3 | + { distance: 5 }) |
| 4 | +var icosphere = require('icosphere') |
| 5 | +var mesh = icosphere(5) |
| 6 | +var glsl = require('glslify') |
| 7 | +var anormals = require('angle-normals') |
| 8 | + |
| 9 | +var draw = regl({ |
| 10 | + frag: glsl` |
| 11 | + precision highp float; |
| 12 | + #pragma glslify: snoise = require('glsl-noise/simplex/4d') |
| 13 | + #pragma glslify: hsl2rgb = require('glsl-hsl2rgb') |
| 14 | + uniform float time; |
| 15 | + varying vec3 vpos; |
| 16 | + void main () { |
| 17 | + float h = (snoise(vec4(vpos,time))*0.5+0.5)*0.4+0.5; |
| 18 | + float s = 0.5; |
| 19 | + float l = 0.5; |
| 20 | + gl_FragColor = vec4(hsl2rgb(h,s,l),1); |
| 21 | + } |
| 22 | + `, |
| 23 | + vert: glsl` |
| 24 | + precision highp float; |
| 25 | + #pragma glslify: snoise = require('glsl-noise/simplex/4d') |
| 26 | + attribute vec3 position, normal; |
| 27 | + uniform mat4 projection, view; |
| 28 | + uniform float time; |
| 29 | + varying vec3 vpos; |
| 30 | + void main () { |
| 31 | + float n = snoise(vec4(position,time*0.2)); |
| 32 | + vpos = position + normal * n * 0.8; |
| 33 | + gl_Position = projection * view * vec4(vpos,1); |
| 34 | + } |
| 35 | + `, |
| 36 | + uniforms: { |
| 37 | + time: regl.context('time') |
| 38 | + }, |
| 39 | + attributes: { |
| 40 | + position: mesh.positions, |
| 41 | + normal: anormals(mesh.cells, mesh.positions) |
| 42 | + }, |
| 43 | + elements: mesh.cells |
| 44 | +}) |
| 45 | +regl.frame(function () { |
| 46 | + regl.clear({ color: [0,0,0,1], depth: true }) |
| 47 | + camera(function () { |
| 48 | + draw() |
| 49 | + }) |
| 50 | +}) |
0 commit comments