Setting fog via code in BIRP turns everything white

Hey everyone, this is with the built-in rendering pipeline.
I’m trying to set fog via code by querying a map of colors and numbers.

private Dictionary<int, Color> fogColors = new Dictionary<int, Color>()
{
    { -4, new Color(60f, 59f, 60f, 1f) },
    { -3, new Color(82f, 81f, 82f, 1f) },
    { -2, new Color(96f, 97f, 96f, 1f) },
    { -1, new Color(126f, 125f, 126f, 1f) },
    { 0, new Color(128, 128, 128, 1f) },
    { 1, new Color(126f, 125f, 126f, 1f) },
    { 2, new Color(176f, 175f, 176f, 1f) },
    { 3, new Color(195f, 196f, 195f, 1f) },
    { 4, new Color(218f, 219f, 218f, 1f) }
};

//Later on, in Update()...
RenderSettings.fogColor = fogColors[stateObject.polarity];

Setting fog without changing it in code (i.e. in the editor before playing) works fine.


But setting the fog in code turns everything to a super strong white!
And checking the fog in debug mode even reveals it’s set to the right color. So I don’t know why I’m having this issue :frowning:

I had more pictures to post but I can’t show them here. You can see them in the Unity Discord server under Shaders posted today.

1 Answer

1

I fixed it, actually! My color values were whole numbers, but they need to be fractions of 255f, so just divide all the numbers above by 255. easy!