p5.js | emissiveMaterial() Function

The emissiveMaterial() function in p5.js is used to create a emissive material for a geometry with the given color. The emissivity of an object gives it the appearance that the object is glowing. An emissive material would still display in full strength even if no light exists in the scene, unlike ambient or specular materials.


emissiveMaterial( v1, [v2], [v3], [a] )


emissiveMaterial( color )

Parameters: This function accept four parameters as mentioned above and described below:

  • v1: It is a number which determines the gray value, or the red or hue value relative to the current color range.
  • v2: It is a number which determines the green or saturation value relative to the current color range. It is an optional parameter.
  • v3: It is a number which determines the blue or brightness value relative to the current color range. It is an optional parameter.
  • a: It is a number which denotes the opacity of the material. It is an optional parameter.
  • color: It is a p5.Color or color string which defines the color of the material.

The example below illustrates the emissiveMaterial() function in p5.js:

Example: The example below shows that the emissive material always shows regardless of the ambient light present.





let newFont;
let hasAmbientLight = true;
let currentEmissiveColor = "red";
function preload() {
  newFont = loadFont('fonts/Montserrat.otf');
function setup() {
  createCanvas(600, 300, WEBGL);
  textFont(newFont, 16);
  // Create checkbox to enable/disable ambient light
  redCheckbox = createCheckbox('Enable Ambient Light', true);
  redCheckbox.position(30, 250);
  redCheckbox.changed(() => hasAmbientLight = !hasAmbientLight);
  // Create a selector for selecting the directional light color
  lightColorSel = createSelect();
  lightColorSel.position(30, 80);
  lightColorSel.changed(() => {
    currentEmissiveColor = lightColorSel.value();
function draw() {
  text("Select an option below to set the emissive material color",
                                                        -285, -125);
  text("Select emissive material color", -285, -100);
  // Enable ambient light if the checkbox is enabled
  if (hasAmbientLight)
    ambientLight(0, 0, 255);
  // Draw sphere which uses emissive material
  translate(-100, 0, 0);
  translate(100, 0, 0);
  // Draw sphere which uses ambient material
  translate(100, 0, 0);
  translate(-100, 0, 0);



Online editor: https://editor.p5js.org/

Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/

Reference: https://p5js.org/reference/#/p5/emissiveMaterial


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.