Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.Rendering;
- [ExecuteInEditMode]
- [RequireComponent(typeof(Camera))]
- public class Fog : MonoBehaviour
- {
- public Color fogColor;
- public float minDistance;
- public float maxDistance;
- Shader _shader;
- Material _material;
- static class Uniforms
- {
- internal static readonly int _FogColor = Shader.PropertyToID("_FogColor");
- internal static readonly int _MinMax = Shader.PropertyToID("_MinMax");
- }
- public enum BlendMode { Blend, Additive, Multiplicative};
- public BlendMode blendMode;
- void OnEnable()
- {
- if (_shader == null) {
- _shader = Shader.Find("Hidden/Fog");
- }
- _material = new Material(_shader);
- _material.hideFlags = HideFlags.DontSave;
- }
- void OnDisable()
- {
- DestroyImmediate(_material);
- }
- void OnRenderImage(RenderTexture source, RenderTexture destination)
- {
- _material.SetColor(Uniforms._FogColor, fogColor);
- _material.SetVector(Uniforms._MinMax, new Vector4(minDistance, maxDistance, 0, 0));
- Graphics.Blit(source, destination, _material, (int)blendMode);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement