diff --git a/Packages/com.verasl.water-system/Scripts/Rendering/WaterSystemFeature.cs b/Packages/com.verasl.water-system/Scripts/Rendering/WaterSystemFeature.cs index c5065b99e..af5e4127f 100644 --- a/Packages/com.verasl.water-system/Scripts/Rendering/WaterSystemFeature.cs +++ b/Packages/com.verasl.water-system/Scripts/Rendering/WaterSystemFeature.cs @@ -16,11 +16,17 @@ class WaterFxPass : ScriptableRenderPass private readonly ShaderTagId m_WaterFXShaderTag = new ShaderTagId("WaterFX"); private readonly Color m_ClearColor = new Color(0.0f, 0.5f, 0.5f, 0.5f); //r = foam mask, g = normal.x, b = normal.z, a = displacement private FilteringSettings m_FilteringSettings; +#if UNITY_2022_1_OR_NEWER + private RTHandle m_WaterFX = RTHandles.Alloc(BuiltinRenderTextureType.CameraTarget,"_WaterFXMap"); +#else private RenderTargetHandle m_WaterFX = RenderTargetHandle.CameraTarget; +#endif public WaterFxPass() { +#if !UNITY_2022_1_OR_NEWER m_WaterFX.Init("_WaterFXMap"); +#endif // only wanting to render transparent objects m_FilteringSettings = new FilteringSettings(RenderQueueRange.transparent); } @@ -36,8 +42,13 @@ public override void Configure(CommandBuffer cmd, RenderTextureDescriptor camera // default format TODO research usefulness of HDR format cameraTextureDescriptor.colorFormat = RenderTextureFormat.Default; // get a temp RT for rendering into +#if UNITY_2022_1_OR_NEWER + cmd.GetTemporaryRT(Shader.PropertyToID(m_WaterFX.name), cameraTextureDescriptor, FilterMode.Bilinear); + ConfigureTarget(m_WaterFX); +#else cmd.GetTemporaryRT(m_WaterFX.id, cameraTextureDescriptor, FilterMode.Bilinear); ConfigureTarget(m_WaterFX.Identifier()); +#endif // clear the screen with a specific color for the packed data ConfigureClear(ClearFlag.Color, m_ClearColor); } @@ -55,7 +66,13 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData SortingCriteria.CommonTransparent); // draw all the renderers matching the rules we setup +#if UNITY_2022_1_OR_NEWER + var param = new RendererListParams(renderingData.cullResults,drawSettings,m_FilteringSettings); + var rendererList = context.CreateRendererList(ref param); + cmd.DrawRendererList(rendererList); +#else context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref m_FilteringSettings); +#endif } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); @@ -64,7 +81,11 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData public override void OnCameraCleanup(CommandBuffer cmd) { // since the texture is used within the single cameras use we need to cleanup the RT afterwards +#if UNITY_2022_1_OR_NEWER + cmd.ReleaseTemporaryRT(Shader.PropertyToID(m_WaterFX.name)); +#else cmd.ReleaseTemporaryRT(m_WaterFX.id); +#endif } } diff --git a/Packages/com.verasl.water-system/Scripts/Water.cs b/Packages/com.verasl.water-system/Scripts/Water.cs index 1b648e91c..8a6af9c90 100644 --- a/Packages/com.verasl.water-system/Scripts/Water.cs +++ b/Packages/com.verasl.water-system/Scripts/Water.cs @@ -7,6 +7,10 @@ using Object = UnityEngine.Object; using Random = UnityEngine.Random; +#if UNITY_EDITOR +using UnityEditor.SceneManagement; +#endif + namespace WaterSystem { [ExecuteAlways] @@ -171,7 +175,7 @@ public void Init() { resources = Resources.Load("WaterResources") as WaterResources; } - if(Application.platform != RuntimePlatform.WebGLPlayer) // TODO - bug with Opengl depth + if(Application.IsPlaying(gameObject) && Application.platform != RuntimePlatform.WebGLPlayer) // TODO - bug with Opengl depth CaptureDepthMap(); } diff --git a/Packages/com.verasl.water-system/Shaders/WaterCommon.hlsl b/Packages/com.verasl.water-system/Shaders/WaterCommon.hlsl index 3e0ba210d..fde61013b 100644 --- a/Packages/com.verasl.water-system/Shaders/WaterCommon.hlsl +++ b/Packages/com.verasl.water-system/Shaders/WaterCommon.hlsl @@ -252,7 +252,12 @@ half4 WaterFragment(WaterVertexOutput IN) : SV_Target BRDFData brdfData; half alpha = 1; InitializeBRDFData(half3(0, 0, 0), 0, half3(1, 1, 1), 0.95, alpha, brdfData); +#if UNITY_VERSION >= 202110 + half3 spec = DirectBDRF(brdfData, IN.normal, mainLight.direction, IN.viewDir,false) * shadow * mainLight.color; +#else half3 spec = DirectBDRF(brdfData, IN.normal, mainLight.direction, IN.viewDir) * shadow * mainLight.color; +#endif + #ifdef _ADDITIONAL_LIGHTS uint pixelLightCount = GetAdditionalLightsCount(); for (uint lightIndex = 0u; lightIndex < pixelLightCount; ++lightIndex)