Skip to content

Commit 0995029

Browse files
committed
Convert some hooks examples to p5.strands
1 parent c14c385 commit 0995029

File tree

1 file changed

+22
-37
lines changed

1 file changed

+22
-37
lines changed

src/webgl/material.js

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,17 +1441,15 @@ function material(p5, fn){
14411441
* environment = await loadImage('assets/outdoor_spheremap.jpg');
14421442
*
14431443
* createCanvas(200, 200, WEBGL);
1444-
* myShader = baseMaterialShader().modify({
1445-
* 'Inputs getPixelInputs': `(Inputs inputs) {
1446-
* float factor =
1447-
* sin(
1448-
* inputs.texCoord.x * ${TWO_PI} +
1449-
* inputs.texCoord.y * ${TWO_PI}
1450-
* ) * 0.4 + 0.5;
1451-
* inputs.shininess = mix(1., 100., factor);
1444+
* myShader = baseMaterialShader().modify(() => {
1445+
* getPixelInputs((inputs) => {
1446+
* let factor = sin(
1447+
* TWO_PI * (inputs.texCoord.x + inputs.texCoord.y)
1448+
* );
1449+
* inputs.shininess = mix(1, 100, factor);
14521450
* inputs.metalness = factor;
14531451
* return inputs;
1454-
* }`
1452+
* })
14551453
* });
14561454
* }
14571455
*
@@ -1476,25 +1474,17 @@ function material(p5, fn){
14761474
*
14771475
* function setup() {
14781476
* createCanvas(200, 200, WEBGL);
1479-
* myShader = baseMaterialShader().modify({
1480-
* 'Inputs getPixelInputs': `(Inputs inputs) {
1481-
* vec3 newNormal = inputs.normal;
1482-
* // Simple bump mapping: adjust the normal based on position
1483-
* newNormal.x += 0.2 * sin(
1484-
* sin(
1485-
* inputs.texCoord.y * ${TWO_PI} * 10.0 +
1486-
* inputs.texCoord.x * ${TWO_PI} * 25.0
1487-
* )
1488-
* );
1489-
* newNormal.y += 0.2 * sin(
1490-
* sin(
1491-
* inputs.texCoord.x * ${TWO_PI} * 10.0 +
1492-
* inputs.texCoord.y * ${TWO_PI} * 25.0
1493-
* )
1477+
* myShader = baseMaterialShader().modify(() => {
1478+
* getPixelInputs((inputs) => {
1479+
* inputs.normal.x += 0.2 * sin(
1480+
* sin(inputs.texCoord.yx * TWO_PI * [10, 25])
14941481
* );
1495-
* inputs.normal = normalize(newNormal);
1482+
* inputs.normal.y += 0.2 * sin(
1483+
* sin(inputs.texCoord * TWO_PI * [10, 25])
1484+
* );
1485+
* inputs.normal = normalize(inputs.normal);
14961486
* return inputs;
1497-
* }`
1487+
* });
14981488
* });
14991489
* }
15001490
*
@@ -1568,18 +1558,13 @@ function material(p5, fn){
15681558
* async function setup() {
15691559
* img = await loadImage('assets/bricks.jpg');
15701560
* createCanvas(100, 100, WEBGL);
1571-
* myShader = baseFilterShader().modify({
1572-
* uniforms: {
1573-
* 'float time': () => millis()
1574-
* },
1575-
* 'vec4 getColor': `(
1576-
* FilterInputs inputs,
1577-
* in sampler2D canvasContent
1578-
* ) {
1561+
* myShader = baseFilterShader().modify(() => {
1562+
* let time = uniformFloat(() => millis());
1563+
* getColor((color, canvasContent) => {
15791564
* inputs.texCoord.y +=
1580-
* 0.01 * sin(time * 0.001 + inputs.position.x * 5.0);
1581-
* return getTexture(canvasContent, inputs.texCoord);
1582-
* }`
1565+
* 0.01 * sin(time * 0.001 + inputs.position.x * 5);
1566+
* return texture(canvasContent, inputs.texCoord);
1567+
* });
15831568
* });
15841569
* }
15851570
*

0 commit comments

Comments
 (0)