Skip to content

Commit 661c04e

Browse files
committed
Merge remote-tracking branch 'upstream/dev-2.0' into matrix-docs
2 parents 9544f78 + 3e2d17a commit 661c04e

File tree

8 files changed

+1311
-386
lines changed

8 files changed

+1311
-386
lines changed

docs/parameterData.json

Lines changed: 71 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,6 @@
382382
]
383383
]
384384
},
385-
"sketchVerifier": {
386-
"overloads": [
387-
[]
388-
]
389-
},
390385
"setup": {
391386
"overloads": [
392387
[]
@@ -1855,6 +1850,50 @@
18551850
]
18561851
]
18571852
},
1853+
"bezierOrder": {
1854+
"overloads": [
1855+
[],
1856+
[
1857+
"Number"
1858+
]
1859+
]
1860+
},
1861+
"splineVertex": {
1862+
"overloads": [
1863+
[
1864+
"Number",
1865+
"Number",
1866+
"Number?",
1867+
"Number?"
1868+
],
1869+
[
1870+
"Number",
1871+
"Number",
1872+
"Number",
1873+
"Number?",
1874+
"Number?"
1875+
]
1876+
]
1877+
},
1878+
"splineProperty": {
1879+
"overloads": [
1880+
[
1881+
"String"
1882+
],
1883+
[
1884+
"String",
1885+
null
1886+
]
1887+
]
1888+
},
1889+
"splineProperties": {
1890+
"overloads": [
1891+
[],
1892+
[
1893+
"Object"
1894+
]
1895+
]
1896+
},
18581897
"vertex": {
18591898
"overloads": [
18601899
[
@@ -1864,12 +1903,13 @@
18641903
[
18651904
"Number",
18661905
"Number",
1906+
"Number?",
18671907
"Number?"
18681908
],
18691909
[
18701910
"Number",
18711911
"Number",
1872-
"Number?",
1912+
"Number",
18731913
"Number?",
18741914
"Number?"
18751915
]
@@ -1899,21 +1939,15 @@
18991939
[
19001940
"Number",
19011941
"Number",
1902-
"Number",
1903-
"Number",
1904-
"Number",
1905-
"Number"
1942+
"Number?",
1943+
"Number?"
19061944
],
19071945
[
19081946
"Number",
19091947
"Number",
19101948
"Number",
1911-
"Number",
1912-
"Number",
1913-
"Number",
1914-
"Number",
1915-
"Number",
1916-
"Number"
1949+
"Number?",
1950+
"Number?"
19171951
]
19181952
]
19191953
},
@@ -1955,11 +1989,6 @@
19551989
[
19561990
"String",
19571991
"Number|Number[]"
1958-
],
1959-
[
1960-
"String",
1961-
"Number|Number[]",
1962-
"Number?"
19631992
]
19641993
]
19651994
},
@@ -3090,22 +3119,6 @@
30903119
[]
30913120
]
30923121
},
3093-
"findClosestSchema": {
3094-
"overloads": [
3095-
[
3096-
"z.ZodSchema",
3097-
"Array"
3098-
]
3099-
]
3100-
},
3101-
"validate": {
3102-
"overloads": [
3103-
[
3104-
"String",
3105-
"Array"
3106-
]
3107-
]
3108-
},
31093122
"createVideo": {
31103123
"overloads": [
31113124
[
@@ -3131,31 +3144,6 @@
31313144
"Function?"
31323145
]
31333146
]
3134-
},
3135-
"bezierOrder": {
3136-
"overloads": [
3137-
[]
3138-
]
3139-
},
3140-
"splineVertex": {
3141-
"overloads": [
3142-
[]
3143-
]
3144-
},
3145-
"splineProperty": {
3146-
"overloads": [
3147-
[
3148-
"String",
3149-
null
3150-
]
3151-
]
3152-
},
3153-
"splineProperties": {
3154-
"overloads": [
3155-
[
3156-
"Object?"
3157-
]
3158-
]
31593147
}
31603148
},
31613149
"p5.Geometry": {
@@ -3201,6 +3189,15 @@
32013189
"overloads": [
32023190
[]
32033191
]
3192+
},
3193+
"vertexProperty": {
3194+
"overloads": [
3195+
[
3196+
"String",
3197+
"Number|Number[]",
3198+
"Number?"
3199+
]
3200+
]
32043201
}
32053202
},
32063203
"p5.Color": {
@@ -4505,6 +4502,18 @@
45054502
}
45064503
},
45074504
"p5.Font": {
4505+
"textToPaths": {
4506+
"overloads": [
4507+
[
4508+
"String",
4509+
"Number",
4510+
"Number",
4511+
"Number?",
4512+
"Number?",
4513+
"Object?"
4514+
]
4515+
]
4516+
},
45084517
"textToPoints": {
45094518
"overloads": [
45104519
[

preview/global/sketch.js

Lines changed: 81 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,124 @@
11
p5.disableFriendlyErrors = true;
2+
23
function windowResized() {
34
resizeCanvas(windowWidth, windowHeight);
45
}
56

6-
let myModel;
77
let starShader;
88
let starStrokeShader;
99
let stars;
10-
let ditheringShader;
1110
let originalFrameBuffer;
12-
let blurredFrameBuffer;
11+
let pixellizeShader;
12+
let fresnelShader;
13+
let bloomShader;
14+
15+
function fresnelShaderCallback() {
16+
const fresnelPower = uniformFloat(2);
17+
const fresnelBias = uniformFloat(-0.1);
18+
const fresnelScale = uniformFloat(2);
19+
getCameraInputs((inputs) => {
20+
let n = normalize(inputs.normal);
21+
let v = normalize(-inputs.position);
22+
let base = 1.0 - dot(n, v);
23+
let fresnel = fresnelScale * pow(base, fresnelPower) + fresnelBias;
24+
let col = mix([0, 0, 0], [1, .5, .7], fresnel);
25+
inputs.color = [col, 1];
26+
return inputs;
27+
});
28+
}
1329

1430
function starShaderCallback() {
1531
const time = uniformFloat(() => millis());
32+
const skyRadius = uniformFloat(1000);
33+
34+
function rand2(st) {
35+
return fract(sin(dot(st, [12.9898, 78.233])) * 43758.5453123);
36+
}
37+
38+
function semiSphere() {
39+
let id = instanceID();
40+
let theta = rand2([id, 0.1234]) * TWO_PI;
41+
let phi = rand2([id, 3.321]) * PI+time/10000;
42+
let r = skyRadius;
43+
r *= 1.5 * sin(phi);
44+
let x = r * sin(phi) * cos(theta);
45+
let y = r * 1.5 * cos(phi);
46+
let z = r * sin(phi) * sin(theta);
47+
return [x, y, z];
48+
}
49+
1650
getWorldInputs((inputs) => {
17-
inputs.position.y += instanceID() * 20 - 1000;
18-
inputs.position.x += 40 * sin(time * 0.001 + instanceID());
51+
inputs.position += semiSphere();
1952
return inputs;
2053
});
54+
2155
getObjectInputs((inputs) => {
22-
inputs.position *= sin(time*0.001 + instanceID());
56+
let scale = 1 + 0.1 * sin(time * 0.002 + instanceID());
57+
inputs.position *= scale;
2358
return inputs;
24-
})
59+
});
2560
}
2661

27-
function ditheringCallback() {
28-
const time = uniformFloat(() => millis())
29-
30-
function rand(co) {
31-
return fract(sin(dot(co, [12.9898, 78.233])) * 43758.5453);
32-
}
33-
34-
function grayscale(col) {
35-
return dot([col.x, col.y, col.z], [0.21, 0.72, 0.07])
36-
}
37-
62+
function pixellizeShaderCallback() {
63+
const pixelSize = uniformFloat(()=> width*.75);
3864
getColor((input, canvasContent) => {
39-
let col = texture(canvasContent, input.texCoord);
40-
col.z = 0.55;
41-
col += rand(input.texCoord + time/10000000000) * 0.15 - 0.05;
42-
let greyscaleValue = grayscale(col);
43-
col.x = greyscaleValue
44-
col.y = greyscaleValue
65+
let coord = input.texCoord;
66+
coord = floor(coord * pixelSize) / pixelSize;
67+
let col = texture(canvasContent, coord);
4568
return col;
4669
});
4770
}
4871

49-
function bloom() {
50-
const blurred = uniformTexture(() => blurredFrameBuffer);
51-
const original = uniformTexture(() => originalFrameBuffer);
52-
72+
function bloomShaderCallback() {
73+
const preBlur = uniformTexture(() => originalFrameBuffer);
5374
getColor((input, canvasContent) => {
54-
const blurredCol = texture(blurred, input.texCoord);
55-
const originalCol = texture(original, input.texCoord);
56-
const brightPass = max(originalCol - 0.0, 0.0) * 3.0;
57-
// const bloom = original + blurred * brightPass;
58-
// return bloom;
59-
return texture(blurred, input.texCoord) + texture(original, input.texCoord);
75+
const blurredCol = texture(canvasContent, input.texCoord);
76+
const originalCol = texture(preBlur, input.texCoord);
77+
const brightPass = max(originalCol, 0.3) * 1.5;
78+
const bloom = originalCol + blurredCol * brightPass;
79+
return bloom;
6080
});
6181
}
6282

6383
async function setup(){
6484
createCanvas(windowWidth, windowHeight, WEBGL);
65-
stars = buildGeometry(() => sphere(20, 3, 3))
85+
stars = buildGeometry(() => sphere(30, 4, 2))
86+
originalFrameBuffer = createFramebuffer();
87+
6688
starShader = baseMaterialShader().modify(starShaderCallback);
6789
starStrokeShader = baseStrokeShader().modify(starShaderCallback)
68-
ditheringShader = baseFilterShader().modify(ditheringCallback);
69-
originalFrameBuffer = createFramebuffer();
70-
blurredFrameBuffer = createFramebuffer();
71-
bloomShader = baseFilterShader().modify(bloom);
90+
fresnelShader = baseColorShader().modify(fresnelShaderCallback);
91+
bloomShader = baseFilterShader().modify(bloomShaderCallback);
92+
pixellizeShader = baseFilterShader().modify(pixellizeShaderCallback);
7293
}
7394

7495
function draw(){
7596
originalFrameBuffer.begin();
97+
background(0);
7698
orbitControl();
77-
background(0,0,0);
78-
push();
79-
stroke(255,0,255)
80-
fill(255,200,255)
99+
100+
push()
101+
strokeWeight(4)
102+
stroke(255,0,0)
103+
rotateX(PI/2 + millis() * 0.0005);
104+
fill(255,100, 150)
81105
strokeShader(starStrokeShader)
82106
shader(starShader);
83-
model(stars, 100);
84-
pop();
107+
model(stars, 2000);
108+
pop()
109+
110+
push()
111+
shader(fresnelShader)
112+
noStroke()
113+
sphere(500);
114+
pop()
115+
filter(pixellizeShader);
116+
85117
originalFrameBuffer.end();
86118

87-
blurredFrameBuffer.begin();
88-
image(originalFrameBuffer, -windowWidth/2, -windowHeight/2)
89-
filter(BLUR)
90-
blurredFrameBuffer.end();
91-
92-
// image(originalFrameBuffer, -windowWidth/2, -windowHeight/2)
119+
imageMode(CENTER)
120+
image(originalFrameBuffer, 0, 0)
121+
122+
filter(BLUR, 20)
93123
filter(bloomShader);
94124
}

0 commit comments

Comments
 (0)