Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for newer version #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion Packages/com.verasl.water-system/Scripts/Water.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,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();
}

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