Skip to content

Commit e469fe2

Browse files
authored
Merge pull request #5310 from JetStarBlues/improveMaterialDocumentation
Improve documetation clarity of material methods
2 parents f66d2c5 + f08bf2c commit e469fe2

File tree

1 file changed

+120
-46
lines changed

1 file changed

+120
-46
lines changed

src/webgl/material.js

Lines changed: 120 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -657,11 +657,17 @@ p5.prototype.textureWrap = function(wrapX, wrapY = wrapX) {
657657
};
658658

659659
/**
660-
* Normal material for geometry is a material that is not affected by light.
661-
* It is not reflective and is a placeholder material often used for debugging.
662-
* Surfaces facing the X-axis, become red, those facing the Y-axis, become green and those facing the Z-axis, become blue.
663-
* You can view all possible materials in this
660+
* Sets the current material as a normal material.
661+
*
662+
* A normal material is not affected by light. It is often used as
663+
* a placeholder material when debugging.
664+
*
665+
* Surfaces facing the X-axis become red, those facing the Y-axis
666+
* become green, and those facing the Z-axis become blue.
667+
*
668+
* You can view more materials in this
664669
* <a href="https://p5js.org/examples/3d-materials.html">example</a>.
670+
*
665671
* @method normalMaterial
666672
* @chainable
667673
* @example
@@ -679,7 +685,7 @@ p5.prototype.textureWrap = function(wrapX, wrapY = wrapX) {
679685
* </code>
680686
* </div>
681687
* @alt
682-
* Red, green and blue gradient.
688+
* Sphere with normal material
683689
*/
684690
p5.prototype.normalMaterial = function(...args) {
685691
this._assert3d('normalMaterial');
@@ -695,14 +701,30 @@ p5.prototype.normalMaterial = function(...args) {
695701
};
696702

697703
/**
698-
* Ambient material for geometry with a given color. Ambient material defines the color the object reflects under any lighting.
699-
* For example, if the ambient material of an object is pure red, but the ambient lighting only contains green, the object will not reflect any light.
700-
* Here's an <a href="https://p5js.org/examples/3d-materials.html">example containing all possible materials</a>.
701-
* @method ambientMaterial
702-
* @param {Number} v1 gray value, red or hue value
703-
* (depending on the current color mode),
704-
* @param {Number} [v2] green or saturation value
705-
* @param {Number} [v3] blue or brightness value
704+
* Sets the current material as an ambient material of the given color.
705+
*
706+
* The ambientMaterial() color is the color the object will reflect
707+
* under **any** lighting.
708+
*
709+
* Consider an ambientMaterial() with the color yellow (255, 255, 0).
710+
* If the light emits the color white (255, 255, 255), then the object
711+
* will appear yellow as it will reflect the red and green components
712+
* of the light. If the light emits the color red (255, 0, 0), then
713+
* the object will appear red as it will reflect the red component
714+
* of the light. If the light emits the color blue (0, 0, 255),
715+
* then the object will appear black, as there is no component of
716+
* the light that it can reflect.
717+
*
718+
* You can view more materials in this
719+
* <a href="https://p5js.org/examples/3d-materials.html">example</a>.
720+
*
721+
* @method ambientMaterial
722+
* @param {Number} v1 red or hue value relative to the current
723+
* color range
724+
* @param {Number} v2 green or saturation value relative to the
725+
* current color range
726+
* @param {Number} v3 blue or brightness value relative to the
727+
* current color range
706728
* @chainable
707729
* @example
708730
* <div>
@@ -713,12 +735,16 @@ p5.prototype.normalMaterial = function(...args) {
713735
* function draw() {
714736
* background(0);
715737
* noStroke();
716-
* ambientLight(200);
738+
* ambientLight(255);
717739
* ambientMaterial(70, 130, 230);
718740
* sphere(40);
719741
* }
720742
* </code>
721743
* </div>
744+
* @alt
745+
* sphere reflecting red, blue, and green light
746+
*
747+
* @example
722748
* <div>
723749
* <code>
724750
* // ambientLight is both red and blue (magenta),
@@ -728,12 +754,16 @@ p5.prototype.normalMaterial = function(...args) {
728754
* }
729755
* function draw() {
730756
* background(70);
731-
* ambientLight(100); // white light
732-
* ambientMaterial(255, 0, 255); // pink material
757+
* ambientLight(255, 0, 255); // magenta light
758+
* ambientMaterial(255); // white material
733759
* box(30);
734760
* }
735761
* </code>
736762
* </div>
763+
* @alt
764+
* box reflecting only red and blue light
765+
*
766+
* @example
737767
* <div>
738768
* <code>
739769
* // ambientLight is green. Since object does not contain
@@ -744,19 +774,27 @@ p5.prototype.normalMaterial = function(...args) {
744774
* function draw() {
745775
* background(70);
746776
* ambientLight(0, 255, 0); // green light
747-
* ambientMaterial(255, 0, 255); // pink material
777+
* ambientMaterial(255, 0, 255); // magenta material
748778
* box(30);
749779
* }
750780
* </code>
751781
* </div>
752782
* @alt
753-
* radiating light source from top right of canvas
754-
* box reflecting only red and blue light
755783
* box reflecting no light
756784
*/
785+
786+
/**
787+
* @method ambientMaterial
788+
* @param {Number} gray number specifying value between
789+
* white and black
790+
* @chainable
791+
*/
792+
757793
/**
758-
* @method ambientMaterial
759-
* @param {Number[]|String|p5.Color} color color, color Array, or CSS color string
794+
* @method ambientMaterial
795+
* @param {p5.Color|Number[]|String} color
796+
* color as a <a href="#/p5.Color">p5.Color</a>,
797+
* as an array, or as a CSS string
760798
* @chainable
761799
*/
762800
p5.prototype.ambientMaterial = function(v1, v2, v3) {
@@ -775,17 +813,28 @@ p5.prototype.ambientMaterial = function(v1, v2, v3) {
775813
};
776814

777815
/**
778-
* Sets the emissive color of the material used for geometry drawn to
779-
* the screen. This is a misnomer in the sense that the material does not
780-
* actually emit light that effects surrounding polygons. Instead,
781-
* it gives the appearance that the object is glowing. An emissive material
782-
* will display at full strength even if there is no light for it to reflect.
816+
* Sets the current material as an emissive material of
817+
* the given color.
818+
*
819+
* An emissive material will display the emissive color at
820+
* full strength regardless of lighting. This can give the
821+
* appearance that the object is glowing.
822+
*
823+
* Note, "emissive" is a misnomer in the sense that the material
824+
* does not actually emit light that will affect surrounding objects.
825+
*
826+
* You can view more materials in this
827+
* <a href="https://p5js.org/examples/3d-materials.html">example</a>.
828+
*
783829
* @method emissiveMaterial
784-
* @param {Number} v1 gray value, red or hue value
785-
* (depending on the current color mode),
786-
* @param {Number} [v2] green or saturation value
787-
* @param {Number} [v3] blue or brightness value
788-
* @param {Number} [a] opacity
830+
* @param {Number} v1 red or hue value relative to the current
831+
* color range
832+
* @param {Number} v2 green or saturation value relative to the
833+
* current color range
834+
* @param {Number} v3 blue or brightness value relative to the
835+
* current color range
836+
* @param {Number} [alpha] alpha value relative to current color
837+
* range (default is 0-255)
789838
* @chainable
790839
* @example
791840
* <div>
@@ -804,11 +853,21 @@ p5.prototype.ambientMaterial = function(v1, v2, v3) {
804853
* </div>
805854
*
806855
* @alt
807-
* radiating light source from top right of canvas
856+
* sphere with green emissive material
857+
*/
858+
859+
/**
860+
* @method emissiveMaterial
861+
* @param {Number} gray number specifying value between
862+
* white and black
863+
* @chainable
808864
*/
865+
809866
/**
810-
* @method emissiveMaterial
811-
* @param {Number[]|String|p5.Color} color color, color Array, or CSS color string
867+
* @method emissiveMaterial
868+
* @param {p5.Color|Number[]|String} color
869+
* color as a <a href="#/p5.Color">p5.Color</a>,
870+
* as an array, or as a CSS string
812871
* @chainable
813872
*/
814873
p5.prototype.emissiveMaterial = function(v1, v2, v3, a) {
@@ -827,11 +886,23 @@ p5.prototype.emissiveMaterial = function(v1, v2, v3, a) {
827886
};
828887

829888
/**
830-
* Specular material for geometry with a given color. Specular material is a shiny reflective material.
831-
* Like ambient material it also defines the color the object reflects under ambient lighting.
832-
* For example, if the specular material of an object is pure red, but the ambient lighting only contains green, the object will not reflect any light.
833-
* For all other types of light like point and directional light, a specular material will reflect the color of the light source to the viewer.
834-
* Here's an <a href="https://p5js.org/examples/3d-materials.html">example containing all possible materials</a>.
889+
* Sets the current material as a specular material of the given color.
890+
*
891+
* A specular material is reflective (shiny). The shininess can be
892+
* controlled by the <a href="#/p5/shininess">shininess()</a> function.
893+
*
894+
* Like <a href="#/p5/ambientMaterial">ambientMaterial()</a>,
895+
* the specularMaterial() color is the color the object will reflect
896+
* under <a href="#/p5/ambientLight">ambientLight()</a>.
897+
* However unlike ambientMaterial(), for all other types of lights
898+
* (<a href="#/p5/directionalLight">directionalLight()</a>,
899+
* <a href="#/p5/pointLight">pointLight()</a>,
900+
* <a href="#/p5/spotLight">spotLight()</a>),
901+
* a specular material will reflect the **color of the light source**.
902+
* This is what gives it its "shiny" appearance.
903+
*
904+
* You can view more materials in this
905+
* <a href="https://p5js.org/examples/3d-materials.html">example</a>.
835906
*
836907
* @method specularMaterial
837908
* @param {Number} gray number specifying value between white and black.
@@ -881,7 +952,9 @@ p5.prototype.emissiveMaterial = function(v1, v2, v3, a) {
881952

882953
/**
883954
* @method specularMaterial
884-
* @param {Number[]|String|p5.Color} color color Array, or CSS color string
955+
* @param {p5.Color|Number[]|String} color
956+
* color as a <a href="#/p5.Color">p5.Color</a>,
957+
* as an array, or as a CSS string
885958
* @chainable
886959
*/
887960
p5.prototype.specularMaterial = function(v1, v2, v3, alpha) {
@@ -900,12 +973,13 @@ p5.prototype.specularMaterial = function(v1, v2, v3, alpha) {
900973
};
901974

902975
/**
903-
* Sets the amount of gloss in the surface of shapes.
904-
* Used in combination with specularMaterial() in setting
905-
* the material properties of shapes. The default and minimum value is 1.
976+
* Sets the amount of gloss ("shininess") of a
977+
* <a href="#/p5/specularMaterial">specularMaterial()</a>.
978+
*
979+
* The default and minimum value is 1.
980+
*
906981
* @method shininess
907-
* @param {Number} shine Degree of Shininess.
908-
* Defaults to 1.
982+
* @param {Number} shine degree of shininess
909983
* @chainable
910984
* @example
911985
* <div>
@@ -931,7 +1005,7 @@ p5.prototype.specularMaterial = function(v1, v2, v3, alpha) {
9311005
* </code>
9321006
* </div>
9331007
* @alt
934-
* Shininess on Camera changes position with mouse
1008+
* two spheres, one more shiny than the other
9351009
*/
9361010
p5.prototype.shininess = function(shine) {
9371011
this._assert3d('shininess');

0 commit comments

Comments
 (0)