Moonlit-Games / Ultimate-Water-System

15 stars 7 forks source link

Performance issues #28

Closed leonidasos closed 6 years ago

leonidasos commented 6 years ago

I recommend to change two trivial changes which have huge performance impact.

1) Do not use regexp in OnPreCull() method in WaterCamera class. Why do we need to call for version in PreCull ? [Time ms] is very slow here. VersionCompatibility.Version >= 560

Solution: I moved it to Awake() get_version

2) Another thing is DynamicWater class

 if (waterCamera.MainWater == _Water && Camera.main == camera)  {
    Shader.SetGlobalTexture(_TotalDisplacementMapId, overlays.TotalDisplacementMap);
}

Do we really need this here? Camera.main is always very slow and calling it every frame kill performance. Solution: Remove it?

cameramain

uws version: 2.0.0b3

MCPGNZ commented 6 years ago

Yeah, .Version is a problem already mentioned in Forum thread and totally my fault. It will be fixed in the next iteration.

Setting the TotalDisplacementMap is necessary for correct shader behaviour. It's pretty costly as it needs to update the displacement map for further processing.

leonidasos commented 6 years ago

My fault. Maybe I did not precise myself enough. It's not about 'TotalDisplacementMap'. Below example works for me. WaterCamera is known because we have all information about current Camera and attached WaterCamera component. Why do we have to check if it's Camera.main ? We can have a different cameras. The most cost is Camera.main and it's very slow in Unity.

if (waterCamera.MainWater == _Water)  { //&& Camera.main == camera)  {
    Shader.SetGlobalTexture(_TotalDisplacementMapId, overlays.TotalDisplacementMap);
}
MCPGNZ commented 6 years ago

@leonidasos

I guess that this check was there to ensure that the texture will be set to the shader only one per frame (it's not really what you call a good solution, i know). Your fix to just skip the check should be fine in that case.

I've fixed both this issues and there will be available in the next release.