Skip to content

[p5.strands] Significant refactor for p5.strands #8009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 55 commits into
base: dev-2.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
23ff7e6
syntax/ remove unneccessary
lukeplowden Jun 24, 2025
1511ffb
blocking out new modular strands structure
lukeplowden Jun 27, 2025
604c2dd
chipping away at DOD approach.
lukeplowden Jul 1, 2025
8950817
nested ifs
lukeplowden Jul 5, 2025
f6369e7
if/else semi working
lukeplowden Jul 7, 2025
a355416
change if/elseif/else api to be chainable and functional (return assi…
lukeplowden Jul 9, 2025
3e1e149
binary ops and contructors prototyped
lukeplowden Jul 16, 2025
f718717
simplify type system
lukeplowden Jul 16, 2025
24f0c46
SSA
lukeplowden Jul 16, 2025
0851285
Return type checking for hooks with native types reimplemented (i.e. …
lukeplowden Jul 23, 2025
9b84f6f
declarations moved to backend, hook arguments fixed
lukeplowden Jul 23, 2025
8509231
rename file
lukeplowden Jul 24, 2025
47eda1a
update api imports for new filename
lukeplowden Jul 24, 2025
1088b4d
move extractTypeInfo and rename to extractNodeTypeInfo
lukeplowden Jul 24, 2025
87e8a99
rename files for clarity
lukeplowden Jul 24, 2025
e32fd47
builtin function overloads type checking
lukeplowden Jul 24, 2025
11a1610
function calls partially reimplemented. Still needs more error checking.
lukeplowden Jul 24, 2025
e8f03d6
update function calls to conform parameters when raw numbers are handed
lukeplowden Jul 25, 2025
1ddd9a2
adding struct types
lukeplowden Jul 25, 2025
f3155e6
adding struct types
lukeplowden Jul 25, 2025
babedfd
Merge branch 'strands-refactor' of github.com:lukeplowden/p5.js into …
lukeplowden Jul 25, 2025
afff707
struct types working
lukeplowden Jul 26, 2025
2e70e0e
comment old line. Should revisit structs if needs optimisation.
lukeplowden Jul 26, 2025
6d5913a
fix wrong ID in binary op node
lukeplowden Jul 26, 2025
2745bda
fix bug with binary op, and make strandsNode return node if arg is al…
lukeplowden Jul 26, 2025
4133fae
fix function call bugs
lukeplowden Jul 29, 2025
b3ce3ec
remove dag sort, use basic block instructions instead. Also start wor…
lukeplowden Jul 30, 2025
9ebf77e
syntax/ remove unneccessary
lukeplowden Jun 24, 2025
faae3aa
blocking out new modular strands structure
lukeplowden Jun 27, 2025
f6783d2
chipping away at DOD approach.
lukeplowden Jul 1, 2025
06faa2c
nested ifs
lukeplowden Jul 5, 2025
5d32089
if/else semi working
lukeplowden Jul 7, 2025
95fa410
change if/elseif/else api to be chainable and functional (return assi…
lukeplowden Jul 9, 2025
627b7a3
binary ops and contructors prototyped
lukeplowden Jul 16, 2025
7899f0d
simplify type system
lukeplowden Jul 16, 2025
b731c15
SSA
lukeplowden Jul 16, 2025
7166f35
Return type checking for hooks with native types reimplemented (i.e. …
lukeplowden Jul 23, 2025
e4e54ac
declarations moved to backend, hook arguments fixed
lukeplowden Jul 23, 2025
51e8ddd
rename file
lukeplowden Jul 24, 2025
79c2f8d
update api imports for new filename
lukeplowden Jul 24, 2025
18dc1d3
move extractTypeInfo and rename to extractNodeTypeInfo
lukeplowden Jul 24, 2025
eb5f1bf
rename files for clarity
lukeplowden Jul 24, 2025
446d3ec
builtin function overloads type checking
lukeplowden Jul 24, 2025
83b4cf4
function calls partially reimplemented. Still needs more error checking.
lukeplowden Jul 24, 2025
a743c68
update function calls to conform parameters when raw numbers are handed
lukeplowden Jul 25, 2025
295c140
adding struct types
lukeplowden Jul 25, 2025
7cd3d42
adding struct types
lukeplowden Jul 25, 2025
f7b1339
struct types working
lukeplowden Jul 26, 2025
ba4be8b
comment old line. Should revisit structs if needs optimisation.
lukeplowden Jul 26, 2025
4fe4aaf
fix wrong ID in binary op node
lukeplowden Jul 26, 2025
0908e43
fix bug with binary op, and make strandsNode return node if arg is al…
lukeplowden Jul 26, 2025
5ce9451
fix function call bugs
lukeplowden Jul 29, 2025
54851ba
remove dag sort, use basic block instructions instead. Also start wor…
lukeplowden Jul 30, 2025
2b681b8
Merge branch 'strands-refactor' of github.com:lukeplowden/p5.js into …
lukeplowden Jul 30, 2025
ebaaa08
change example
lukeplowden Jul 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 20 additions & 112 deletions preview/global/sketch.js
Original file line number Diff line number Diff line change
@@ -1,124 +1,32 @@
p5.disableFriendlyErrors = true;

function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}

let starShader;
let starStrokeShader;
let stars;
let originalFrameBuffer;
let pixellizeShader;
let fresnelShader;
let bloomShader;

function fresnelShaderCallback() {
const fresnelPower = uniformFloat(2);
const fresnelBias = uniformFloat(-0.1);
const fresnelScale = uniformFloat(2);
getCameraInputs((inputs) => {
let n = normalize(inputs.normal);
let v = normalize(-inputs.position);
let base = 1.0 - dot(n, v);
let fresnel = fresnelScale * pow(base, fresnelPower) + fresnelBias;
let col = mix([0, 0, 0], [1, .5, .7], fresnel);
inputs.color = [col, 1];
return inputs;
});
}

function starShaderCallback() {
const time = uniformFloat(() => millis());
const skyRadius = uniformFloat(1000);

function rand2(st) {
return fract(sin(dot(st, [12.9898, 78.233])) * 43758.5453123);
}

function semiSphere() {
let id = instanceID();
let theta = rand2([id, 0.1234]) * TWO_PI;
let phi = rand2([id, 3.321]) * PI+time/10000;
let r = skyRadius;
r *= 1.5 * sin(phi);
let x = r * sin(phi) * cos(theta);
let y = r * 1.5 * cos(phi);
let z = r * sin(phi) * sin(theta);
return [x, y, z];
}

getWorldInputs((inputs) => {
inputs.position += semiSphere();
return inputs;
});

getObjectInputs((inputs) => {
let scale = 1 + 0.1 * sin(time * 0.002 + instanceID());
inputs.position *= scale;
function callback() {
const time = uniformFloat(() =>millis()*0.001)
// getFinalColor((col) => {
// return vec4(1,0,0,1).rgba;
// });

getWorldInputs(inputs => {
// strandsIf(inputs.position === vec3(1), () => 0).Else()
inputs.color = vec4(inputs.position, 1);
inputs.position = inputs.position + sin(time) * 100;
return inputs;
});
}

function pixellizeShaderCallback() {
const pixelSize = uniformFloat(()=> width*.75);
getColor((input, canvasContent) => {
let coord = input.texCoord;
coord = floor(coord * pixelSize) / pixelSize;
let col = texture(canvasContent, coord);
return col;
});
}

function bloomShaderCallback() {
const preBlur = uniformTexture(() => originalFrameBuffer);
getColor((input, canvasContent) => {
const blurredCol = texture(canvasContent, input.texCoord);
const originalCol = texture(preBlur, input.texCoord);
const brightPass = max(originalCol, 0.3) * 1.5;
const bloom = originalCol + blurredCol * brightPass;
return bloom;
});
}

async function setup(){
createCanvas(windowWidth, windowHeight, WEBGL);
stars = buildGeometry(() => sphere(30, 4, 2))
originalFrameBuffer = createFramebuffer();
createCanvas(windowWidth,windowHeight, WEBGL)
bloomShader = baseColorShader().newModify(callback);
}

starShader = baseMaterialShader().modify(starShaderCallback);
starStrokeShader = baseStrokeShader().modify(starShaderCallback)
fresnelShader = baseColorShader().modify(fresnelShaderCallback);
bloomShader = baseFilterShader().modify(bloomShaderCallback);
pixellizeShader = baseFilterShader().modify(pixellizeShaderCallback);
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}

function draw(){
originalFrameBuffer.begin();
background(0);
function draw() {
orbitControl();

push()
strokeWeight(4)
stroke(255,0,0)
rotateX(PI/2 + millis() * 0.0005);
fill(255,100, 150)
strokeShader(starStrokeShader)
shader(starShader);
model(stars, 2000);
pop()

push()
shader(fresnelShader)
noStroke()
sphere(500);
pop()
filter(pixellizeShader);

originalFrameBuffer.end();

imageMode(CENTER)
image(originalFrameBuffer, 0, 0)

filter(BLUR, 20)
filter(bloomShader);
background(0);
shader(bloomShader);
noStroke();
sphere(300)
}
Loading
Loading