[Solved] Change the fogColor with script

Hello, i was looking all around forum and answers but didn’t find any example to change the fogColor i have tried app.scene.fogColor(0,0,0) but don’t work. Thanks.

The fogColor property is a pc.Color, so you’d want to do something like:

app.scene.fogColor = new pc.Color (1, 0, 0);

I’d recommend checking the PlayCanvas API, rather than just forum/answers. :slight_smile:

I have checked the api but was not clear the use :slight_smile: al least for me…thanks @Ben

Uhm the problem is when i need to change it back to the original fogColor, in the editor i have those values
55,76,92 that are also 374c5c but when i assign the values to fogColor the effect is totally different also using 5,7,9 or 3,4,5

What colour are you are aiming for and how are you using pc.Color to get that colour? You may want to recheck the API to see what values you should be using :wink:

Ok found it in pc.Color instead fogColor reference the value is between 0 and 1 so 0.3,0.4,0.5 thanks

Err… not quite right.

With colour, we represent it in our UI in two ways, RGB and the hex representation.

RGB is represented as values between 0 and 255 (8 bit per component).

The colour can also be represented as hex (base 16) which uses characters 0-9 and A-F, 2 characters per component therefore, 8-bits.

So #374c5c is actually, #37 for R, #4c for G and #5c for B.

Using a hex to decimal convertor like this one: http://www.binaryhexconverter.com/hex-to-decimal-converter

#37 is 55 ®
#4c is 76 (G)
#5c is 92 (B)

To normalise a component value so it’s between 0-1, you divide the value by the component’s max value, 255 in this case.

i.e.

var color = pc.Color(55/255, 76/255, 92/255);
// which comes out to roughly as pc.Color(0.2156, 0.2980, 0.3607);
1 Like

Thanks for the detailed explanation :slight_smile: i will correct it, anyway the values i used are close enough so for now noone will notice the difference :smiley: