Skip to content

Commit c441623

Browse files
committed
fix for newer version
1 parent e4864ca commit c441623

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

Packages/com.verasl.water-system/Scripts/Rendering/WaterSystemFeature.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ class WaterFxPass : ScriptableRenderPass
1616
private readonly ShaderTagId m_WaterFXShaderTag = new ShaderTagId("WaterFX");
1717
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
1818
private FilteringSettings m_FilteringSettings;
19+
#if UNITY_2022_1_OR_NEWER
20+
private RTHandle m_WaterFX = RTHandles.Alloc(BuiltinRenderTextureType.CameraTarget,"_WaterFXMap");
21+
#else
1922
private RenderTargetHandle m_WaterFX = RenderTargetHandle.CameraTarget;
23+
#endif
2024

2125
public WaterFxPass()
2226
{
27+
#if !UNITY_2022_1_OR_NEWER
2328
m_WaterFX.Init("_WaterFXMap");
29+
#endif
2430
// only wanting to render transparent objects
2531
m_FilteringSettings = new FilteringSettings(RenderQueueRange.transparent);
2632
}
@@ -36,8 +42,13 @@ public override void Configure(CommandBuffer cmd, RenderTextureDescriptor camera
3642
// default format TODO research usefulness of HDR format
3743
cameraTextureDescriptor.colorFormat = RenderTextureFormat.Default;
3844
// get a temp RT for rendering into
45+
#if UNITY_2022_1_OR_NEWER
46+
cmd.GetTemporaryRT(Shader.PropertyToID(m_WaterFX.name), cameraTextureDescriptor, FilterMode.Bilinear);
47+
ConfigureTarget(m_WaterFX);
48+
#else
3949
cmd.GetTemporaryRT(m_WaterFX.id, cameraTextureDescriptor, FilterMode.Bilinear);
4050
ConfigureTarget(m_WaterFX.Identifier());
51+
#endif
4152
// clear the screen with a specific color for the packed data
4253
ConfigureClear(ClearFlag.Color, m_ClearColor);
4354
}
@@ -55,7 +66,13 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
5566
SortingCriteria.CommonTransparent);
5667

5768
// draw all the renderers matching the rules we setup
69+
#if UNITY_2022_1_OR_NEWER
70+
var param = new RendererListParams(renderingData.cullResults,drawSettings,m_FilteringSettings);
71+
var rendererList = context.CreateRendererList(ref param);
72+
cmd.DrawRendererList(rendererList);
73+
#else
5874
context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref m_FilteringSettings);
75+
#endif
5976
}
6077
context.ExecuteCommandBuffer(cmd);
6178
CommandBufferPool.Release(cmd);
@@ -64,7 +81,11 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
6481
public override void OnCameraCleanup(CommandBuffer cmd)
6582
{
6683
// since the texture is used within the single cameras use we need to cleanup the RT afterwards
84+
#if UNITY_2022_1_OR_NEWER
85+
cmd.ReleaseTemporaryRT(Shader.PropertyToID(m_WaterFX.name));
86+
#else
6787
cmd.ReleaseTemporaryRT(m_WaterFX.id);
88+
#endif
6889
}
6990
}
7091

Packages/com.verasl.water-system/Scripts/Water.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public void Init()
171171
{
172172
resources = Resources.Load("WaterResources") as WaterResources;
173173
}
174-
if(Application.platform != RuntimePlatform.WebGLPlayer) // TODO - bug with Opengl depth
174+
if(Application.IsPlaying(gameObject) && Application.platform != RuntimePlatform.WebGLPlayer) // TODO - bug with Opengl depth
175175
CaptureDepthMap();
176176
}
177177

Packages/com.verasl.water-system/Shaders/WaterCommon.hlsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,12 @@ half4 WaterFragment(WaterVertexOutput IN) : SV_Target
252252
BRDFData brdfData;
253253
half alpha = 1;
254254
InitializeBRDFData(half3(0, 0, 0), 0, half3(1, 1, 1), 0.95, alpha, brdfData);
255+
#if UNITY_VERSION >= 202110
256+
half3 spec = DirectBDRF(brdfData, IN.normal, mainLight.direction, IN.viewDir,false) * shadow * mainLight.color;
257+
#else
255258
half3 spec = DirectBDRF(brdfData, IN.normal, mainLight.direction, IN.viewDir) * shadow * mainLight.color;
259+
#endif
260+
256261
#ifdef _ADDITIONAL_LIGHTS
257262
uint pixelLightCount = GetAdditionalLightsCount();
258263
for (uint lightIndex = 0u; lightIndex < pixelLightCount; ++lightIndex)

0 commit comments

Comments
 (0)