Skip to content

Commit 29fbe52

Browse files
committed
Address Maintainer feedbacks: Update ShaderGenerator docs and examples
1 parent 483edcb commit 29fbe52

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/webgl/ShaderGenerator.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,13 @@ if (typeof p5 !== 'undefined') {
16461646
* @method getWorldInputs
16471647
* @description
16481648
* Registers a callback to modify the world-space properties of each vertex in a shader. This hook can be used inside <a href="#/p5/baseColorShader">baseColorShader()</a>.modify() and similar shader modify calls to customize vertex positions, normals, texture coordinates, and colors before rendering. "World space" refers to the coordinate system of the 3D scene, before any camera or projection transformations are applied.
1649-
*
1649+
*
1650+
* The callback receives a vertex object with the following properties:
1651+
* - `position`: a vector with three components representing the original position of the vertex
1652+
* - `normal`: a vector with three components representing the direction the surface is facing
1653+
* - `texCoord`: a vector with two components representing the texture coordinates
1654+
* - `color`: a vector with four components representing the color of the vertex (red, green, blue, alpha)
1655+
*
16501656
* This hook is available in:
16511657
* - <a href="#/p5/baseMaterialShader">baseMaterialShader()</a>
16521658
* - <a href="#/p5/baseNormalShader">baseNormalShader()</a>
@@ -1667,7 +1673,8 @@ if (typeof p5 !== 'undefined') {
16671673
* getWorldInputs(inputs => {
16681674
* // Move the vertex up and down in a wave in world space
16691675
* // In world space, moving the object (e.g., with translate()) will affect these coordinates
1670-
* inputs.position.y += 0.5 * sin(t * 0.001 + inputs.position.x * 0.05);
1676+
* // The sphere is ~50 units tall here, so 20 gives a noticeable wave
1677+
* inputs.position.y += 20 * sin(t * 0.001 + inputs.position.x * 0.05);
16711678
* return inputs;
16721679
* });
16731680
* });
@@ -1862,9 +1869,7 @@ if (typeof p5 !== 'undefined') {
18621869
* let t = uniformFloat(() => millis());
18631870
* getPixelInputs(inputs => {
18641871
* // Animate alpha (transparency) based on x position
1865-
* if (inputs.color && inputs.texCoord) {
1866-
* inputs.color.a = 0.5 + 0.5 * sin(inputs.texCoord.x * 10.0 + t * 0.002);
1867-
* }
1872+
* inputs.color.a = 0.5 + 0.5 * sin(inputs.texCoord.x * 10.0 + t * 0.002);
18681873
* return inputs;
18691874
* });
18701875
* });
@@ -1875,14 +1880,15 @@ if (typeof p5 !== 'undefined') {
18751880
* lights();
18761881
* noStroke();
18771882
* fill('purple');
1878-
* sphere(50);
1883+
* circle(0, 0, 100);
18791884
* }
18801885
* </code>
18811886
* </div>
18821887
*/
18831888

18841889
/**
18851890
* @method shouldDiscard
1891+
* @private
18861892
* @description
18871893
* Registers a callback to decide whether to discard (skip drawing) a fragment (pixel) in the fragment shader. This hook can be used inside <a href="#/p5/baseStrokeShader">baseStrokeShader()</a>.modify() and similar shader modify calls to create effects like round points or custom masking. The callback receives a boolean:
18881894
* - `willDiscard`: true if the fragment would be discarded by default
@@ -1918,8 +1924,7 @@ if (typeof p5 !== 'undefined') {
19181924
/**
19191925
* @method getFinalColor
19201926
* @description
1921-
* Registers a callback to change the final color of each pixel after all lighting and mixing is done in the fragment shader. This hook can be used inside <a href="#/p5/baseColorShader">baseColorShader()</a>.modify() and similar shader modify calls to adjust the color before it appears on the screen. The callback receives a four component vector representing red, green, blue, and alpha:
1922-
* - `[r, g, b, a]`: the current color (red, green, blue, alpha)
1927+
* Registers a callback to change the final color of each pixel after all lighting and mixing is done in the fragment shader. This hook can be used inside <a href="#/p5/baseColorShader">baseColorShader()</a>.modify() and similar shader modify calls to adjust the color before it appears on the screen. The callback receives a four component vector representing red, green, blue, and alpha.
19231928
*
19241929
* Return a new color array to change the output color.
19251930
*
@@ -2009,7 +2014,6 @@ if (typeof p5 !== 'undefined') {
20092014
* - `texCoord`: a vector with two components representing the texture coordinates (u, v)
20102015
* - `canvasSize`: a vector with two components representing the canvas size in pixels (width, height)
20112016
* - `texelSize`: a vector with two components representing the size of a single texel in texture space
2012-
* - `color`: a vector with four components representing the current pixel color (red, green, blue, alpha)
20132017
* - `canvasContent`: a texture containing the sketch's contents before the filter is applied
20142018
*
20152019
* Return a four-component vector `[r, g, b, a]` for the pixel.
@@ -2075,7 +2079,7 @@ if (typeof p5 !== 'undefined') {
20752079
* let t = uniformFloat(() => millis());
20762080
* getObjectInputs(inputs => {
20772081
* // Create a sine wave along the x axis in object space
2078-
* inputs.position.y += 0.5 * sin(inputs.position.x * 0.1 + t * 0.002);
2082+
* inputs.position.y += 20 * sin(t * 0.001 + inputs.position.x * 0.05);
20792083
* return inputs;
20802084
* });
20812085
* });
@@ -2085,7 +2089,7 @@ if (typeof p5 !== 'undefined') {
20852089
* shader(myShader);
20862090
* noStroke();
20872091
* fill('orange');
2088-
* box(100);
2092+
* sphere(100);
20892093
* }
20902094
* </code>
20912095
* </div>

0 commit comments

Comments
 (0)