Skip to content

Commit 5af4635

Browse files
committed
Use tables for all hooks
1 parent db29371 commit 5af4635

File tree

1 file changed

+279
-61
lines changed

1 file changed

+279
-61
lines changed

src/webgl/material.js

Lines changed: 279 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -887,38 +887,145 @@ p5.prototype.shader = function (s) {
887887
*
888888
* You can call <a href="#/p5.Shader/modify">`materialShader().modify()`</a>
889889
* and change any of the following hooks:
890-
* - `void beforeVertex`: Called at the start of the vertex shader.
891-
* - `vec3 getLocalPosition`: Update the position of vertices before transforms are applied. It takes in `vec3 position` and must return a modified version.
892-
* - `vec3 getWorldPosition`: Update the position of vertices after transforms are applied. It takes in `vec3 position` and pust return a modified version.
893-
* - `vec3 getLocalNormal`: Update the normal before transforms are applied. It takes in `vec3 normal` and must return a modified version.
894-
* - `vec3 getWorldNormal`: Update the normal after transforms are applied. It takes in `vec3 normal` and must return a modified version.
895-
* - `vec2 getUV`: Update the texture coordinates. It takes in `vec2 uv` and must return a modified version.
896-
* - `vec4 getVertexColor`: Update the color of each vertex. It takes in a `vec4 color` and must return a modified version.
897-
* - `void afterVertex`: Called at the end of the vertex shader.
898-
* - `void beforeFragment`: Called at the start of the fragment shader.
899-
* - `Inputs getPixelInputs`: Update the per-pixel inputs of the material. It takes in an `Inputs` struct, which includes:
900-
* - `vec3 normal`, the direction pointing out of the surface
901-
* - `vec2 texCoord`, a vector where `x` and `y` are between 0 and 1 describing the spot on a texture the pixel is mapped to, as a fraction of the texture size
902-
* - `vec3 ambientLight`, the ambient light color on the vertex
903-
* - `vec4 color`, the base material color of the pixel
904-
* - `vec3 ambientMaterial`, the color of the pixel when affected by ambient light
905-
* - `vec3 specularMaterial`, the color of the pixel when reflecting specular highlights
906-
* - `vec3 emissiveMaterial`, the light color emitted by the pixel
907-
* - `float shininess`, a number representing how sharp specular reflections should be, from 1 to infinity
908-
* - `float metalness`, a number representing how mirrorlike the material should be, between 0 and 1
909-
The struct can be modified and returned.
910-
* - `vec4 combineColors`: Take in a `ColorComponents` struct containing all the different components of light, and combining them into
911-
* a single final color. The struct contains:
912-
* - `vec3 baseColor`, the base color of the pixel
913-
* - `float opacity`, the opacity between 0 and 1 that it should be drawn at
914-
* - `vec3 ambientColor`, the color of the pixel when affected by ambient light
915-
* - `vec3 specularColor`, the color of the pixel when affected by specular reflections
916-
* - `vec3 diffuse`, the amount of diffused light hitting the pixel
917-
* - `vec3 ambient`, the amount of ambient light hitting the pixel
918-
* - `vec3 specular`, the amount of specular reflection hitting the pixel
919-
* - `vec3 emissive`, the amount of light emitted by the pixel
920-
* - `vec4 getFinalColor`: Update the final color after mixing. It takes in a `vec4 color` and must return a modified version.
921-
* - `void afterFragment`: Called at the end of the fragment shader.
890+
*
891+
* <table>
892+
* <tr><th>Hook</th><th>Description</th></tr>
893+
* <tr><td>
894+
*
895+
* `void beforeVertex`
896+
*
897+
* </td><td>
898+
*
899+
* Called at the start of the vertex shader.
900+
*
901+
* </td></tr>
902+
* <tr><td>
903+
*
904+
* `vec3 getLocalPosition`
905+
*
906+
* </td><td>
907+
*
908+
* Update the position of vertices before transforms are applied. It takes in `vec3 position` and must return a modified version.
909+
*
910+
* </td></tr>
911+
* <tr><td>
912+
*
913+
* `vec3 getWorldPosition`
914+
*
915+
* </td><td>
916+
*
917+
* Update the position of vertices after transforms are applied. It takes in `vec3 position` and pust return a modified version.
918+
*
919+
* </td></tr>
920+
* <tr><td>
921+
*
922+
* `vec3 getLocalNormal`
923+
*
924+
* </td><td>
925+
*
926+
* Update the normal before transforms are applied. It takes in `vec3 normal` and must return a modified version.
927+
*
928+
* </td></tr>
929+
* <tr><td>
930+
*
931+
* `vec3 getWorldNormal`
932+
*
933+
* </td><td>
934+
*
935+
* Update the normal after transforms are applied. It takes in `vec3 normal` and must return a modified version.
936+
*
937+
* </td></tr>
938+
* <tr><td>
939+
*
940+
* `vec2 getUV`
941+
*
942+
* </td><td>
943+
*
944+
* Update the texture coordinates. It takes in `vec2 uv` and must return a modified version.
945+
*
946+
* </td></tr>
947+
* <tr><td>
948+
*
949+
* `vec4 getVertexColor`
950+
*
951+
* </td><td>
952+
*
953+
* Update the color of each vertex. It takes in a `vec4 color` and must return a modified version.
954+
*
955+
* </td></tr>
956+
* <tr><td>
957+
*
958+
* `void afterVertex`
959+
*
960+
* </td><td>
961+
*
962+
* Called at the end of the vertex shader.
963+
*
964+
* </td></tr>
965+
* <tr><td>
966+
*
967+
* `void beforeFragment`
968+
*
969+
* </td><td>
970+
*
971+
* Called at the start of the fragment shader.
972+
*
973+
* </td></tr>
974+
* <tr><td>
975+
*
976+
* `Inputs getPixelInputs`
977+
*
978+
* </td><td>
979+
*
980+
* Update the per-pixel inputs of the material. It takes in an `Inputs` struct, which includes:
981+
* - `vec3 normal`, the direction pointing out of the surface
982+
* - `vec2 texCoord`, a vector where `x` and `y` are between 0 and 1 describing the spot on a texture the pixel is mapped to, as a fraction of the texture size
983+
* - `vec3 ambientLight`, the ambient light color on the vertex
984+
* - `vec4 color`, the base material color of the pixel
985+
* - `vec3 ambientMaterial`, the color of the pixel when affected by ambient light
986+
* - `vec3 specularMaterial`, the color of the pixel when reflecting specular highlights
987+
* - `vec3 emissiveMaterial`, the light color emitted by the pixel
988+
* - `float shininess`, a number representing how sharp specular reflections should be, from 1 to infinity
989+
* - `float metalness`, a number representing how mirrorlike the material should be, between 0 and 1
990+
* The struct can be modified and returned.
991+
* </td></tr>
992+
* <tr><td>
993+
*
994+
* `vec4 combineColors`
995+
*
996+
* </td><td>
997+
*
998+
* Take in a `ColorComponents` struct containing all the different components of light, and combining them into
999+
* a single final color. The struct contains:
1000+
* - `vec3 baseColor`, the base color of the pixel
1001+
* - `float opacity`, the opacity between 0 and 1 that it should be drawn at
1002+
* - `vec3 ambientColor`, the color of the pixel when affected by ambient light
1003+
* - `vec3 specularColor`, the color of the pixel when affected by specular reflections
1004+
* - `vec3 diffuse`, the amount of diffused light hitting the pixel
1005+
* - `vec3 ambient`, the amount of ambient light hitting the pixel
1006+
* - `vec3 specular`, the amount of specular reflection hitting the pixel
1007+
* - `vec3 emissive`, the amount of light emitted by the pixel
1008+
*
1009+
* </td></tr>
1010+
* <tr><td>
1011+
*
1012+
* `vec4 getFinalColor`
1013+
*
1014+
* </td><td>
1015+
*
1016+
* Update the final color after mixing. It takes in a `vec4 color` and must return a modified version.
1017+
*
1018+
* </td></tr>
1019+
* <tr><td>
1020+
*
1021+
* `void afterFragment`
1022+
*
1023+
* </td><td>
1024+
*
1025+
* Called at the end of the fragment shader.
1026+
*
1027+
* </td></tr>
1028+
* </table>
9221029
*
9231030
* Most of the time, you will need to write your hooks in GLSL ES version 300. If you
9241031
* are using WebGL 1 instead of 2, write your hooks in GLSL ES 100 instead.
@@ -1088,17 +1195,20 @@ p5.prototype.materialShader = function() {
10881195
*
10891196
* You can call <a href="#/p5.Shader/modify">`normalShader().modify()`</a>
10901197
* and change any of the following hooks:
1091-
* - `void beforeVertex`: Called at the start of the vertex shader.
1092-
* - `vec3 getLocalPosition`: Update the position of vertices before transforms are applied. It takes in `vec3 position` and must return a modified version.
1093-
* - `vec3 getWorldPosition`: Update the position of vertices after transforms are applied. It takes in `vec3 position` and pust return a modified version.
1094-
* - `vec3 getLocalNormal`: Update the normal before transforms are applied. It takes in `vec3 normal` and must return a modified version.
1095-
* - `vec3 getWorldNormal`: Update the normal after transforms are applied. It takes in `vec3 normal` and must return a modified version.
1096-
* - `vec2 getUV`: Update the texture coordinates. It takes in `vec2 uv` and must return a modified version.
1097-
* - `vec4 getVertexColor`: Update the color of each vertex. It takes in a `vec4 color` and must return a modified version.
1098-
* - `void afterVertex`: Called at the end of the vertex shader.
1099-
* - `void beforeFragment`: Called at the start of the fragment shader.
1100-
* - `vec4 getFinalColor`: Update the final color after mixing. It takes in a `vec4 color` and must return a modified version.
1101-
* - `void afterFragment`: Called at the end of the fragment shader.
1198+
*
1199+
* Hook | Description
1200+
* -----|------------
1201+
* `void beforeVertex` | Called at the start of the vertex shader.
1202+
* `vec3 getLocalPosition` | Update the position of vertices before transforms are applied. It takes in `vec3 position` and must return a modified version.
1203+
* `vec3 getWorldPosition` | Update the position of vertices after transforms are applied. It takes in `vec3 position` and pust return a modified version.
1204+
* `vec3 getLocalNormal` | Update the normal before transforms are applied. It takes in `vec3 normal` and must return a modified version.
1205+
* `vec3 getWorldNormal` | Update the normal after transforms are applied. It takes in `vec3 normal` and must return a modified version.
1206+
* `vec2 getUV` | Update the texture coordinates. It takes in `vec2 uv` and must return a modified version.
1207+
* `vec4 getVertexColor` | Update the color of each vertex. It takes in a `vec4 color` and must return a modified version.
1208+
* `void afterVertex` | Called at the end of the vertex shader.
1209+
* `void beforeFragment` | Called at the start of the fragment shader.
1210+
* `vec4 getFinalColor` | Update the final color after mixing. It takes in a `vec4 color` and must return a modified version.
1211+
* `void afterFragment` | Called at the end of the fragment shader.
11021212
*
11031213
* Most of the time, you will need to write your hooks in GLSL ES version 300. If you
11041214
* are using WebGL 1 instead of 2, write your hooks in GLSL ES 100 instead.
@@ -1239,24 +1349,132 @@ p5.prototype.colorShader = function() {
12391349
*
12401350
* You can call <a href="#/p5.Shader/modify">`strokeShader().modify()`</a>
12411351
* and change any of the following hooks:
1242-
* - `void beforeVertex`: Called at the start of the vertex shader.
1243-
* - `vec3 getLocalPosition`: Update the position of vertices before transforms are applied. It takes in `vec3 position` and must return a modified version.
1244-
* - `vec3 getWorldPosition`: Update the position of vertices after transforms are applied. It takes in `vec3 position` and pust return a modified version.
1245-
* - `float getStrokeWeight`: Update the stroke weight. It takes in `float weight` and pust return a modified version.
1246-
* - `vec2 getLineCenter`: Update the center of the line. It takes in `vec2 center` and must return a modified version.
1247-
* - `vec2 getLinePosition`: Update the position of each vertex on the edge of the line. It takes in `vec2 position` and must return a modified version.
1248-
* - `vec4 getVertexColor`: Update the color of each vertex. It takes in a `vec4 color` and must return a modified version.
1249-
* - `void afterVertex`: Called at the end of the vertex shader.
1250-
* - `void beforeFragment`: Called at the start of the fragment shader.
1251-
* - `Inputs getPixelInputs`: Update the inputs to the shader. It takes in a struct `Inputs inputs`, which includes:
1252-
* - `vec4 color`, the color of the stroke
1253-
* - `vec2 tangent`, the direction of the stroke in screen space
1254-
* - `vec2 center`, the coordinate of the center of the stroke in screen space p5.js pixels
1255-
* - `vec2 position`, the coordinate of the current pixel in screen space p5.js pixels
1256-
* - `float strokeWeight`, the thickness of the stroke in p5.js pixels
1257-
* - `bool shouldDiscard`: Caps and joins are made by discarded pixels in the fragment shader to carve away unwanted areas. Use this to change this logic. It takes in a `bool willDiscard` and must return a modified version.
1258-
* - `vec4 getFinalColor`: Update the final color after mixing. It takes in a `vec4 color` and must return a modified version.
1259-
* - `void afterFragment`: Called at the end of the fragment shader.
1352+
*
1353+
* <table>
1354+
* <tr><th>Hook</th><th>Description</th></tr>
1355+
* <tr><td>
1356+
*
1357+
* `void beforeVertex`
1358+
*
1359+
* </td><td>
1360+
*
1361+
* Called at the start of the vertex shader.
1362+
*
1363+
* </td></tr>
1364+
* <tr><td>
1365+
*
1366+
* `vec3 getLocalPosition`
1367+
*
1368+
* </td><td>
1369+
*
1370+
* Update the position of vertices before transforms are applied. It takes in `vec3 position` and must return a modified version.
1371+
*
1372+
* </td></tr>
1373+
* <tr><td>
1374+
*
1375+
* `vec3 getWorldPosition`
1376+
*
1377+
* </td><td>
1378+
*
1379+
* Update the position of vertices after transforms are applied. It takes in `vec3 position` and pust return a modified version.
1380+
*
1381+
* </td></tr>
1382+
* <tr><td>
1383+
*
1384+
* `float getStrokeWeight`
1385+
*
1386+
* </td><td>
1387+
*
1388+
* Update the stroke weight. It takes in `float weight` and pust return a modified version.
1389+
*
1390+
* </td></tr>
1391+
* <tr><td>
1392+
*
1393+
* `vec2 getLineCenter`
1394+
*
1395+
* </td><td>
1396+
*
1397+
* Update the center of the line. It takes in `vec2 center` and must return a modified version.
1398+
*
1399+
* </td></tr>
1400+
* <tr><td>
1401+
*
1402+
* `vec2 getLinePosition`
1403+
*
1404+
* </td><td>
1405+
*
1406+
* Update the position of each vertex on the edge of the line. It takes in `vec2 position` and must return a modified version.
1407+
*
1408+
* </td></tr>
1409+
* <tr><td>
1410+
*
1411+
* `vec4 getVertexColor`
1412+
*
1413+
* </td><td>
1414+
*
1415+
* Update the color of each vertex. It takes in a `vec4 color` and must return a modified version.
1416+
*
1417+
* </td></tr>
1418+
* <tr><td>
1419+
*
1420+
* `void afterVertex`
1421+
*
1422+
* </td><td>
1423+
*
1424+
* Called at the end of the vertex shader.
1425+
*
1426+
* </td></tr>
1427+
* <tr><td>
1428+
*
1429+
* `void beforeFragment`
1430+
*
1431+
* </td><td>
1432+
*
1433+
* Called at the start of the fragment shader.
1434+
*
1435+
* </td></tr>
1436+
* <tr><td>
1437+
*
1438+
* `Inputs getPixelInputs`
1439+
*
1440+
* </td><td>
1441+
*
1442+
* Update the inputs to the shader. It takes in a struct `Inputs inputs`, which includes:
1443+
* - `vec4 color`, the color of the stroke
1444+
* - `vec2 tangent`, the direction of the stroke in screen space
1445+
* - `vec2 center`, the coordinate of the center of the stroke in screen space p5.js pixels
1446+
* - `vec2 position`, the coordinate of the current pixel in screen space p5.js pixels
1447+
* - `float strokeWeight`, the thickness of the stroke in p5.js pixels
1448+
*
1449+
* </td></tr>
1450+
* <tr><td>
1451+
*
1452+
* `bool shouldDiscard`
1453+
*
1454+
* </td><td>
1455+
*
1456+
* Caps and joins are made by discarded pixels in the fragment shader to carve away unwanted areas. Use this to change this logic. It takes in a `bool willDiscard` and must return a modified version.
1457+
*
1458+
* </td></tr>
1459+
* <tr><td>
1460+
*
1461+
* `vec4 getFinalColor`
1462+
*
1463+
* </td><td>
1464+
*
1465+
* Update the final color after mixing. It takes in a `vec4 color` and must return a modified version.
1466+
*
1467+
* </td></tr>
1468+
* <tr><td>
1469+
*
1470+
* `void afterFragment`
1471+
*
1472+
* </td><td>
1473+
*
1474+
* Called at the end of the fragment shader.
1475+
*
1476+
* </td></tr>
1477+
* </table>
12601478
*
12611479
* Most of the time, you will need to write your hooks in GLSL ES version 300. If you
12621480
* are using WebGL 1 instead of 2, write your hooks in GLSL ES 100 instead.

0 commit comments

Comments
 (0)