p5.js emissiveMaterial() Function
Last Updated :
23 Aug, 2023
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.
Syntax:
emissiveMaterial( v1, [v2], [v3], [a] )
OR
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);
redCheckbox = createCheckbox( 'Enable Ambient Light' , true );
redCheckbox.position(30, 250);
redCheckbox.changed(() => hasAmbientLight = !hasAmbientLight);
lightColorSel = createSelect();
lightColorSel.position(30, 80);
lightColorSel.option( 'red' );
lightColorSel.option( 'green' );
lightColorSel.option( 'blue' );
lightColorSel.changed(() => {
currentEmissiveColor = lightColorSel.value();
});
}
function draw() {
background( 'white' );
fill( 'black' );
text( "Select an option below to set the emissive material color" ,
-285, -125);
text( "Select emissive material color" , -285, -100);
noStroke();
if (hasAmbientLight)
ambientLight(0, 0, 255);
emissiveMaterial(currentEmissiveColor);
translate(-100, 0, 0);
sphere(50);
translate(100, 0, 0);
ambientMaterial(255);
translate(100, 0, 0);
sphere(50);
translate(-100, 0, 0);
}
|
Output:
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...