Skip to content

Commit 06cf619

Browse files
committed
docs: clarify combineColors and getPointSize documentation per maintainer feedback
1 parent c9d07c1 commit 06cf619

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

src/webgl/ShaderGenerator.js

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,18 @@ if (typeof p5 !== 'undefined') {
16891689
* @function combineColors
16901690
* @experimental
16911691
* @description
1692-
* Registers a callback to customize how color components are combined in the fragment shader. This hook can be used inside <a href="#/p5/baseMaterialShader">baseMaterialShader()</a>.modify() and similar shader modify calls to control the final color output of a material. The callback receives color components (baseColor, diffuse, ambientColor, ambient, specularColor, specular, emissive, opacity) and returns a vec4 for the final color.
1692+
* Registers a callback to customize how color components are combined in the fragment shader. This hook can be used inside <a href="#/p5/baseMaterialShader">baseMaterialShader()</a>.modify() and similar shader modify calls to control the final color output of a material. The callback receives an object with the following properties:
1693+
*
1694+
* - `baseColor`: a vector with three components representing the base color (red, green, blue)
1695+
* - `diffuse`: a single number representing the diffuse reflection
1696+
* - `ambientColor`: a vector with three components representing the ambient color
1697+
* - `ambient`: a single number representing the ambient reflection
1698+
* - `specularColor`: a vector with three components representing the specular color
1699+
* - `specular`: a single number representing the specular reflection
1700+
* - `emissive`: a vector with three components representing the emissive color
1701+
* - `opacity`: a single number representing the opacity
1702+
*
1703+
* The callback should return a vector with four components (red, green, blue, alpha) for the final color.
16931704
*
16941705
* This hook is available in:
16951706
* - <a href="#/p5/baseMaterialShader">baseMaterialShader()</a>
@@ -1698,7 +1709,7 @@ if (typeof p5 !== 'undefined') {
16981709
* - <a href="#/p5/baseStrokeShader">baseStrokeShader()</a>
16991710
*
17001711
* @param {function} callback
1701-
* A callback function which receives color components (baseColor, diffuse, ambientColor, ambient, specularColor, specular, emissive, opacity) and returns a vec4 for the final color.
1712+
* A callback function which receives the object described above and returns a vector with four components for the final color.
17021713
*
17031714
* @example
17041715
* <div modernizr='webgl'>
@@ -1709,20 +1720,19 @@ if (typeof p5 !== 'undefined') {
17091720
* myShader = baseMaterialShader().modify(() => {
17101721
* combineColors(components => {
17111722
* // Custom color combination: add a red tint
1712-
* let r = components.baseColor.r * components.diffuse.r +
1713-
* components.ambientColor.r * components.ambient.r +
1714-
* components.specularColor.r * components.specular.r +
1715-
* components.emissive.r + 0.2;
1716-
* let g = components.baseColor.g * components.diffuse.g +
1717-
* components.ambientColor.g * components.ambient.g +
1718-
* components.specularColor.g * components.specular.g +
1719-
* components.emissive.g;
1720-
* let b = components.baseColor.b * components.diffuse.b +
1721-
* components.ambientColor.b * components.ambient.b +
1722-
* components.specularColor.b * components.specular.b +
1723-
* components.emissive.b;
1724-
* let a = components.opacity;
1725-
* return vec4(r, g, b, a);
1723+
* let r = components.baseColor[0] * components.diffuse +
1724+
* components.ambientColor[0] * components.ambient +
1725+
* components.specularColor[0] * components.specular +
1726+
* components.emissive[0] + 0.2;
1727+
* let g = components.baseColor[1] * components.diffuse +
1728+
* components.ambientColor[1] * components.ambient +
1729+
* components.specularColor[1] * components.specular +
1730+
* components.emissive[1];
1731+
* let b = components.baseColor[2] * components.diffuse +
1732+
* components.ambientColor[2] * components.ambient +
1733+
* components.specularColor[2] * components.specular +
1734+
* components.emissive[2];
1735+
* return [r, g, b, components.opacity];
17261736
* });
17271737
* });
17281738
* }
@@ -1742,13 +1752,24 @@ if (typeof p5 !== 'undefined') {
17421752
* @function getPointSize
17431753
* @experimental
17441754
* @description
1745-
* Registers a callback to modify the size of points when rendering with a shader. This hook can be used inside <a href="#/p5/baseMaterialShader">baseMaterialShader()</a>.modify() or similar, when drawing points (e.g., with the point() function in WEBGL mode). The callback receives the current point size (number) and should return the new size (number).
1755+
* Registers a callback to modify the size of points when rendering with a shader.
1756+
*
1757+
* This hook can be used inside the following shader modify functions:
1758+
* - <a href="#/p5/baseMaterialShader">baseMaterialShader()</a>.modify()
1759+
* - <a href="#/p5/baseNormalShader">baseNormalShader()</a>.modify()
1760+
* - <a href="#/p5/baseColorShader">baseColorShader()</a>.modify()
1761+
* - <a href="#/p5/baseStrokeShader">baseStrokeShader()</a>.modify()
1762+
* - <a href="#/p5/baseFilterShader">baseFilterShader()</a>.modify()
1763+
*
1764+
* Use this hook when drawing points (for example, with the point() function in WEBGL mode).
1765+
* The callback receives the current point size (number) and should return the new size (number).
17461766
*
17471767
* This hook is available in:
17481768
* - <a href="#/p5/baseMaterialShader">baseMaterialShader()</a>
17491769
* - <a href="#/p5/baseNormalShader">baseNormalShader()</a>
17501770
* - <a href="#/p5/baseColorShader">baseColorShader()</a>
17511771
* - <a href="#/p5/baseStrokeShader">baseStrokeShader()</a>
1772+
* - <a href="#/p5/baseFilterShader">baseFilterShader()</a>
17521773
*
17531774
* @param {function} callback
17541775
* A callback function which receives and returns the point size.

0 commit comments

Comments
 (0)