|
1 | | -// p5.disableFriendlyErrors = true; |
| 1 | +p5.disableFriendlyErrors = true; |
2 | 2 | function windowResized() { |
3 | 3 | resizeCanvas(windowWidth, windowHeight); |
4 | 4 | } |
5 | | -let myShader; |
6 | | -let filterShader; |
7 | | -let video; |
8 | 5 |
|
| 6 | +let myModel; |
| 7 | +let starShader; |
| 8 | +let starStrokeShader; |
| 9 | +let stars; |
| 10 | + |
| 11 | +function starShaderCallback() { |
| 12 | + const time = uniformFloat(() => millis()); |
| 13 | + getWorldInputs((inputs) => { |
| 14 | + inputs.position.y += instanceID() * 20 - 1000; |
| 15 | + inputs.position.x += 40*sin(time * 0.001 + instanceID()); |
| 16 | + return inputs; |
| 17 | + }); |
| 18 | + getObjectInputs((inputs) => { |
| 19 | + inputs.position *= sin(time*0.001 + instanceID()); |
| 20 | + return inputs; |
| 21 | + }) |
| 22 | +} |
9 | 23 |
|
10 | 24 | async function setup(){ |
11 | 25 | createCanvas(windowWidth, windowHeight, WEBGL); |
12 | | - |
13 | | - // filterShader = baseFi |
14 | | - |
15 | | - filterShader = baseFilterShader().modify(() => { |
16 | | - const time = uniformFloat(() => millis()); |
17 | | - |
18 | | - getColor((input, canvasContents) => { |
19 | | - let myColor = texture(canvasContents, uvCoords()); |
20 | | - const d = distance(input.texCoord, [0.5, 0.5]); |
21 | | - myColor.x = smoothstep(0, 0.5, d); |
22 | | - myColor.y = sin(time*0.001)/2; |
23 | | - return myColor; |
24 | | - }) |
25 | | - }); |
26 | | - |
27 | | - myShader = baseMaterialShader().modify(() => { |
28 | | - const time = uniformFloat(() => millis()); |
29 | | - |
30 | | - getFinalColor((col) => { |
31 | | - col.x = uvCoords().x; |
32 | | - col.y = uvCoords().y; |
33 | | - col.z = 1; |
34 | | - return col; |
35 | | - }); |
36 | | - |
37 | | - getWorldInputs((inputs) => { |
38 | | - inputs.position.y += 20 * sin(time * 0.001 + inputs.position.x * 0.05); |
39 | | - return inputs; |
40 | | - }) |
41 | | - }); |
| 26 | + stars = buildGeometry(() => sphere(20, 7, 4)) |
| 27 | + starShader = baseMaterialShader().modify(starShaderCallback); |
| 28 | + starStrokeShader = baseStrokeShader().modify(starShaderCallback) |
42 | 29 | } |
43 | 30 |
|
44 | 31 | function draw(){ |
45 | | - // orbitControl(); |
46 | | - background(0); |
| 32 | + background(0,200,240); |
| 33 | + orbitControl(); |
| 34 | + // noStroke(); |
| 35 | + |
| 36 | + push(); |
| 37 | + stroke(255,0,255) |
| 38 | + fill(255,200,255) |
| 39 | + strokeShader(starStrokeShader) |
| 40 | + shader(starShader); |
| 41 | + model(stars, 100); |
| 42 | + pop(); |
| 43 | + push(); |
| 44 | + shader(baseMaterialShader()); |
47 | 45 | noStroke(); |
48 | | - fill('blue') |
49 | | - sphere(100) |
50 | | - shader(myShader); |
51 | | - filter(filterShader); |
52 | | - // filterShader.setUniform('time', millis()); |
| 46 | + rotateX(HALF_PI); |
| 47 | + translate(0, 0, -250); |
| 48 | + plane(10000) |
| 49 | + pop(); |
53 | 50 | } |
0 commit comments