Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.Rendering;
- //Script requires Stylized Water 2 version 1.1.2+
- //This only applies to third-party fog effects. For the built-in Unity fog, simply toggle RenderSettings.fog
- [ExecuteInEditMode]
- public class DisableWaterFogForCamera : MonoBehaviour
- {
- public Camera targetCamera;
- private int _WaterFogDisabled = Shader.PropertyToID("_WaterFogDisabled");
- void Reset()
- {
- targetCamera = GetComponent<Camera>();
- }
- void OnEnable()
- {
- RenderPipelineManager.beginCameraRendering += onRenderCamera;
- RenderPipelineManager.endCameraRendering += onFinishRenderCamera;
- }
- private void onRenderCamera(ScriptableRenderContext context, Camera currentCamera)
- {
- if(currentCamera == targetCamera) Shader.SetGlobalFloat(_WaterFogDisabled, 1);
- }
- private void onFinishRenderCamera(ScriptableRenderContext context, Camera currentCamera)
- {
- //Restore so that it still renders for whatever camera comes next (unless it also has this component on it)
- if(currentCamera == targetCamera) Shader.SetGlobalFloat(_WaterFogDisabled, 0);
- }
- void OnDisable()
- {
- RenderPipelineManager.beginCameraRendering -= onRenderCamera;
- RenderPipelineManager.endCameraRendering -= onFinishRenderCamera;
- Shader.SetGlobalFloat(_WaterFogDisabled, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement