|
1 | 1 | let myShader;
|
| 2 | +let myShader2; |
2 | 3 | p5.disableFriendlyErrors = true;
|
3 |
| - |
| 4 | +function windowResized() { |
| 5 | + resizeCanvas(windowWidth, windowHeight); |
| 6 | +} |
4 | 7 | function calculateOffset() {
|
5 | 8 | return 30;
|
6 | 9 | }
|
7 | 10 |
|
8 | 11 | function setup(){
|
9 | 12 | createCanvas(windowWidth, windowHeight, WEBGL);
|
10 |
| - |
11 | 13 | // // Raw example
|
12 | 14 | myShader = baseMaterialShader().modify(() => {
|
13 |
| - |
14 |
| - const offset = uniformFloat(1); |
15 |
| - |
| 15 | + const uCol = uniformVector4(0.1,0.1,0.1,1); |
| 16 | + const time = uniformFloat(()=>millis); |
16 | 17 | getFinalColor((col) => {
|
17 |
| - let a = createVector4(1, 2, 3, 4); |
18 |
| - let b = createVector4(3, 4, 5, 6); |
19 |
| - a = (a * b + offset) / 10; |
20 |
| - col += a; |
| 18 | + let x = createFloat(0.5); |
| 19 | + col.x = createFloat(time); |
| 20 | + col.w = 1; |
| 21 | + col /= uCol; |
21 | 22 | return col;
|
22 | 23 | });
|
23 |
| - }); |
24 |
| - |
| 24 | + }, { parser: true, srcLocations: true }); |
25 | 25 |
|
| 26 | + console.log(myShader) |
26 | 27 | // Create and use the custom shader.
|
27 |
| - // myShader = baseMaterialShader().modify( |
| 28 | + // myShader2 = baseMaterialShader().modify( |
28 | 29 | // () => {
|
29 |
| - // const offset = uniformFloat('offset', () => calculateOffset) |
| 30 | + // // const offset = uniformFloat('offset', 1) |
30 | 31 |
|
31 |
| - // getWorldPosition((pos) => { |
32 |
| - // let a = createVector3(1, 2, 3); |
33 |
| - // let b = createVector3(3, 4, 5); |
| 32 | + // getFinalColor((pos) => { |
| 33 | + // let a = createVector4(1, 2, 3); |
| 34 | + // let b = createVector4(3, 4, 5); |
34 | 35 | // a = a.add(b);
|
35 | 36 |
|
36 | 37 | // let c = a.add(b);
|
37 |
| - // c += c.add(offset); |
38 |
| - // c.x = b.x.add(1); |
39 |
| - |
| 38 | + // // c += c.add(offset); |
| 39 | + // // c.x = b.x.add(1); |
40 | 40 |
|
41 | 41 | // pos = pos.add(c);
|
42 | 42 |
|
43 | 43 | // return pos;
|
44 | 44 | // })
|
45 |
| - // } |
46 |
| - // ); |
| 45 | + // }, { parser: false, srcLocations: true }); |
47 | 46 | }
|
48 | 47 |
|
49 | 48 | function draw(){
|
50 | 49 | // Set the styles
|
51 |
| - background(0) |
| 50 | + background(0); |
| 51 | + // fill(0) |
| 52 | + shader(myShader); |
| 53 | + stroke('red') |
| 54 | + fill(255,0,0) |
| 55 | + // myShader.setUniform('uCol', [0.1,2,0,1]) |
| 56 | + sphere(100); |
52 | 57 | }
|
0 commit comments