Unity-Technologies / BoatAttack

Demo Project using the Universal RP from Unity3D
Other
2.49k stars 944 forks source link

Wake Generation regression in urp-water-system 2.0.0-preview.2 #196

Closed Torgo13 closed 9 months ago

Torgo13 commented 9 months ago

Wakes no longer render correctly in newer versions of the urp-water-system using RTHandles. This has been tested in 2022.3.10 LTS with the DirectX11 and Vulkan renderers.

Here is how they look in the branch testing/2021-update, using urp-water-system 2.0.0-preview.1: 2021-update

Here is how they look in the branch dynamic-scaling-issue, using urp-water-system 2.0.0-preview.2: dynamic-scaling-issue

It's easier to see on the wake to the left. Although it's still displacing the water mesh, the water isn't being lit correctly and the wake geometry is less smooth. Turning the boat sometimes causes very sharp and jagged wakes to appear briefly.

I've tried updating the water system in the dynamic-scaling-issue branch to use the fixes-temp branch of the boat-attack-water repo. It doesn't seem to improve them compared to preview.2.

The issue seems to come from the Water Effects Pass, which is in WaterSystemPasses.cs in preview.1 and WaterFXBuffers.cs in preview.2. On line 14 in WaterSystemPasses.cs : private static int m_MockDepthTexture = Shader.PropertyToID("_DepthBufferMock"); // TODO remove once bug is fixed This mock depth texture seems to be necessary for the wakes to render correctly. I've tried updating it to use RTHandles but it renders the wakes upside down, like the screen is inverted but only for the wakes.

Another possible issue might be from the WaterInput.hlsl shader. In the struct WaterInputData the depth was changed from a float to a: float2 depth; // x = distorted depth, y = raw depth The wakes might be using depth.x instead of depth.y, causing the exaggerated heights.

Torgo13 commented 9 months ago

Here's what I did to fix the wakes in urp-water-system 2.0.0-preview.2. In WaterCommon.hlsl, at lines 20-23 in #if UNITY_UV_STARTS_AT_TOP, replace each instance of half2(1-uv.x, 1-uv.y) with half2(uv.x, uv.y). You can also just remove the #if UNITY_UV_STARTS_AT_TOP section since this just ends up casting uv to a half2.

Then in DetailNormals() update line 228 from normalWS = normalize(normalWS + normal1);// normalize(normalWS + normal1 + normal2); to normalWS = normalize(normalWS + normal1 + normal2); normal2 provides the normal map for the wakes.

In WaveVertexOperations() change line 252 half waterDepth = WaterBufferBVert(screenUV).b; to half waterDepth = 1.0 - WaterBufferBVert(screenUV).b;

Optionally, you can prevent the wakes changing the height of the water and only affect the normal map by commenting out line 270. //input.positionWS.y += waterFX.w * 2 - 1;