git ssb

0+

substack / °ŗÅñġ€Ŧəá



Commit 00ce6a804f0b0eea3a8a7afe54a09ac71163c479

¡mi teapot es fuego!

substack committed on 5/16/2017, 12:32:54 PM
Parent: cf2cf2ffcdd1c1043fccc11c88b6c7845a2467cc

Files changed

main.jschanged
package.jsonchanged
main.jsView
@@ -5,13 +5,16 @@
55 var grid = require('grid-mesh')
66 var wireframe = require('screen-projected-lines')
77 var feedback = require('regl-feedback')
88 var mat4 = require('gl-mat4')
9 +var teapot = require('teapot')
10 +var anormals = require('angle-normals')
911
1012 var fbtex = regl.texture()
1113 var draw = {
1214 grid: createGrid(regl,30),
1315 gridbg: createGridBg(regl,30),
16 + orbit: orbit(regl),
1417 bg: createBg(regl),
1518 fb: feedback(regl, `
1619 vec3 sample (vec2 uv, sampler2D tex) {
1720 float px = 256.0;
@@ -22,8 +25,12 @@
2225 }
2326 `)
2427 }
2528 var rmat = [], last = 0
29 +var orbits = []
30 +for (var i = 0; i < 20; i++) {
31 + orbits.push({ offset: i/20*100 })
32 +}
2633 regl.frame(function (context) {
2734 regl.clear({ color: [0,0,0,1], depth: true })
2835 draw.fb({ texture: fbtex })
2936 draw.bg()
@@ -31,12 +38,66 @@
3138 mat4.rotateY(rmat,rmat,context.time*0.05)
3239 camera(function () {
3340 draw.grid({ rmat: rmat })
3441 draw.gridbg({ rmat: rmat })
42 + draw.orbit(orbits)
3543 fbtex({ copy: true, mag: 'linear', min: 'linear' })
3644 })
3745 })
3846
47 +function orbit (regl) {
48 + var model = [], offset = []
49 + var mesh = teapot
50 + return regl({
51 + frag: glsl`
52 + precision highp float;
53 + #pragma glslify: snoise = require('glsl-noise/simplex/4d')
54 + #pragma glslify: hsl2rgb = require('glsl-hsl2rgb')
55 + #pragma glslify: dither = require('glsl-dither/8x8')
56 + uniform float time;
57 + varying vec3 vpos;
58 + void main () {
59 + float h = snoise(vec4(vpos*0.2,time*2.0))*0.5+0.5;
60 + vec3 c = hsl2rgb(vec3(h*0.2,1,0.5));
61 + gl_FragColor = vec4(dither(gl_FragCoord.xy,c) ,1);
62 + }
63 + `,
64 + vert: glsl`
65 + precision highp float;
66 + uniform mat4 projection, view, model;
67 + uniform float offset;
68 + attribute vec3 position, normal;
69 + varying vec3 vpos;
70 + uniform float time;
71 + void main () {
72 + float x = sin(time*0.4);
73 + float d = 4.0 + (1.0+sin(x))*0.5*8.0;
74 + float t = (time*1.0 + offset) / ${100/(Math.PI*2)};
75 + vec3 op = vec3(sin(t)*140.0, -30.0, cos(t)*90.0);
76 + vec3 pos = (model * vec4(position,1)).xyz;
77 + vpos = floor((pos*0.5+op)*d)/d+0.5/d
78 + + normal*x*0.1;
79 + gl_Position = projection * view * vec4(vpos,1);
80 + }
81 + `,
82 + uniforms: {
83 + offset: regl.prop('offset'),
84 + time: regl.context('time'),
85 + model: function (context) {
86 + mat4.identity(model)
87 + mat4.rotateX(model,model,Math.sin(context.time*0.01)*0.1)
88 + mat4.rotateY(model,model,context.time)
89 + return model
90 + }
91 + },
92 + attributes: {
93 + position: mesh.positions,
94 + normal: anormals(mesh.cells, mesh.positions)
95 + },
96 + elements: mesh.cells
97 + })
98 +}
99 +
39100 function createBg (regl) {
40101 return regl({
41102 frag: glsl`
42103 precision highp float;
package.jsonView
@@ -1,6 +1,7 @@
11 {
22 "dependencies": {
3 + "angle-normals": "^1.0.0",
34 "conway-hart": "^0.1.0",
45 "gl-mat4": "^1.1.4",
56 "glsl-dither": "^1.0.1",
67 "glsl-hsl2rgb": "^1.1.0",
@@ -11,9 +12,10 @@
1112 "icosphere": "^1.0.0",
1213 "regl": "^1.3.0",
1314 "regl-camera": "^1.1.2",
1415 "regl-feedback": "^1.0.0",
15- "screen-projected-lines": "^1.2.0"
16 + "screen-projected-lines": "^1.2.0",
17 + "teapot": "^1.0.0"
1618 },
1719 "browserify": {
1820 "transform": [
1921 "glslify"

Built with git-ssb-web