Skip to content

Instantly share code, notes, and snippets.

@robert-michels
Last active March 23, 2021 02:03
Show Gist options
  • Select an option

  • Save robert-michels/1272b6f0de41f4409cf4e61fdfbbd622 to your computer and use it in GitHub Desktop.

Select an option

Save robert-michels/1272b6f0de41f4409cf4e61fdfbbd622 to your computer and use it in GitHub Desktop.
// CODE SNIPPET, NOT THE FULL FILE //
//Sets the mood of the environment (skybox, fog, dust, water). Input a value between 0 (beginning: grim) and 1 (ending: bright).
private int startDust = 600;
private int endDust = 0;
private int startFogLimit = 300;
private int endFogLimit = 1250;
private int startFog = 0;
private int endFog = 50;
private void SetEnvironment (float lerp)
{
lerp = Util.capVal(lerp, 0, 1);
Color horizonCol = Color.Lerp(startColors[1], endColors[1], lerp);
//sky
skyBox.SetColor("_TopColor", Color.Lerp(startColors[0], endColors[0], lerp));
skyBox.SetColor("_HorizonColor", horizonCol);
skyBox.SetColor("_BottomColor", Color.Lerp(startColors[2], endColors[2], lerp));
//fog
RenderSettings.fogColor = horizonCol;
RenderSettings.fogEndDistance = Util.mapVal(lerp, 0, 1, startFogLimit, endFogLimit);
RenderSettings.fogStartDistance = Util.mapVal(lerp, 0, 1, startFog, endFog);
//dust
int dustCount = (int)Mathf.SmoothStep(startDust, endDust, lerp);
dust1.maxParticles = dustCount;
dust2.maxParticles = dustCount / 12;
//water
waterMat.SetColor("_Color", Color.Lerp(waterColors[0], waterColors[1], lerp));
//Post Processing (disabled for mobile)
ppBefore.weight = Util.mapVal(lerp, 0, 1, 1, 0);
ppAfter.weight = Util.mapVal(lerp, 0, 1, 0, .4f);
//sun
sun.intensity = Util.mapVal(lerp, 0, 1, 0.5f, 1.1f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment