Material.diffuse and setParameter ('material_diffuse') work in different ways?

Hello everybody, just trying to set the color of mesh instance via setParameter('material_diffuse', [0, 0, 0] and is produces quite different results comparing to meshInstance.material.diffuse = new pc.Color(); meshInstance.material.update():

image
image

Am I doing it wrong? What may affect the colors here (checked the scene lighting, skybox, emissive)?

Also an interesting observation: they look the same for pure red, green, yellow and blue colors :thinking:

image
image
image

but once I start playing with colors in-between ( like [0.75, 0.5, 0.25] or [0.15, 0.6, 0.33]) everything breaks :slight_smile:

The colors are specified in gamma space, and internally for rendering using uniforms, those are converted to linear space by the standard material.

But this does not happen when setting on MeshInstance, and you are responsible for setting a uniform values directly. And so you need to do a gamma correction yourself.

Internally this happens, so use a similar code:

uniform[0] = Math.pow(color.r, 2.2);
uniform[1] = Math.pow(color.g, 2.2);
uniform[2] = Math.pow(color.b, 2.2);
1 Like

that worked, many thanks Martin!

Just in case, is there a way to extract the gamma correction power factor (defaulting to 2.2) from the engine instead of hardcoding? Get a value based on app.scene.gammaCorrection ?
I see there are different presets for the gamma value in the engine ( pc.GAMMA_SRGB, pc.GAMMA_SRGBFAST, pc.GAMMA_SRGBHDR etc), where can I check the actual gamma power values?

EDIT: ah, I see now it’s hardcoded to 2.2 in the standard-material.js :smiley:

Ah and this is pretty recent change, huh? I didn’t notice that behavior before :thinking:

I believe it’s been like this from the beginning.