Skip to content

Commit

Permalink
fix for newer version
Browse files Browse the repository at this point in the history
  • Loading branch information
Thaina committed Jun 24, 2023
1 parent e4864ca commit 572f26f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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
}
}

Expand Down
5 changes: 5 additions & 0 deletions Packages/com.verasl.water-system/Shaders/WaterCommon.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 572f26f

Please sign in to comment.