In the editor, fog works as I want it to on Play. I add choose the color I want in the editor and use this simple code to change it per level:
public Color color;
public Color color2;
public Color color3;
public Color color4;
Scene currentScene = SceneManager.GetActiveScene();
string sceneName = currentScene.name;
Debug.Log("sceneName: " + sceneName);
if (sceneName == "lvl1")
{
Cursor.visible = false;
RenderSettings.fogColor = color;
RenderSettings.fogDensity = 0.02F;
}
if (sceneName == "lvl2")
{
Cursor.visible = false;
RenderSettings.fogColor = color2;
RenderSettings.fogDensity = 0.02F;
}
if (sceneName == "lvl3")
{
Cursor.visible = false;
//RenderSettings.fogColor = Camera.main.backgroundColor;
RenderSettings.fogColor = color3;
RenderSettings.fogDensity = 0.02F;
}
if (sceneName == "lvl4")
{
Cursor.visible = false;
RenderSettings.fogColor = color4;
RenderSettings.fogDensity = 0.015F;
}
Int he build however, it doesn’t work at all!!! WHY?? And how do I fix this horribly annoying issue?
I’ve tried changing the graphics - fog settings to custom and select Linear, or Exponential or Exponential square or all three at once. NOTHING works. This is so frustrating, it does not make any sense.
Plenty of people have had the same issue, but is there even a fix for this?
Check that you’re not stripping fog modes from shaders in the Graphics settings. If the fog modes are stripped (because materials aren’t using them) then you won’t be able to change them at runtime.
Thank you for your reply. If I choose “Keep all” in the Graphics Settings - Shader stripping - Instancing variants, and set the fog modes to Linear (Because the exponential ones don’t update the fog in each scene) I get this error :
Shader error in ‘Particles/Standard Surface’: invalid subscript ‘instanceID’ ‘UnitySetupInstanceID’: no matching 1 parameter function at line 142 (on d3d11)
Compiling Vertex program with DIRECTIONAL SHADOWS_SCREEN INSTANCING_ON _NORMALMAP _ALPHABLEND_ON _FADING_ON
Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_FULL_HDR
-When I open the code I cant edit it, and there’s a commented text at the top of the script stating:
//////////////////////////////////////////////////////////////////////////
//
// NOTE: This is not a valid shader file, the contents are provided just
// for information and for debugging purposes only.
//
//////////////////////////////////////////////////////////////////////////
How do I remove it? I’m assuming it would work if it’s not there at all?
Not sure I can help with your problem with the standard particle shader - perhaps ask @richardkettlewell . We’ve had problems with Unity 2019.2.x and shader stripping, shader preloading/warming, and shaders that use instancing (INSTANCING_ON) on Metal (complains about instance stuff and buffer bindings) but we couldn’t fix it so just worked around it by not preloading some shaders that had problems.
Maybe reset some of those other settings you changed and try setting fog modes to ‘custom’ and enable the modes you need (or all three modes) to at least test if your fog works at runtime. We are currently using these settings ourselves to enable different fog settings at runtime within scenes. Without it, the fog modes are stripped from shaders and changing things (linear/expo) at runtime doesn’t work or fog disappears.
Thanks, I’m making a but report. I already tried all combinations you suggest with the result that the build crashes because of the above mentioned error. Hopefully the bug report will clear this up. Thank you for your help
I just made a bug report. I haven’t made one in years: It uploaded and then the upload percentage window disappeared when it finished and everything in the bug reporter was grayed out which seems right, but I didn’t get a confirmation that it had successfully made the bug report. Can you confirm that you have it? Thank you
If you haven’t received a reply with the case number, then we probably don’t have it. You would have to give me some information for me to have any hope of finding it. eg bug title, or, DM me with the email address you used to submit it.