Neopallium / bevy_water

Dynamic ocean material for Bevy.
https://neopallium.github.io/bevy_water/
134 stars 12 forks source link

Low FPS on good hardware #31

Open PTFOPlayer opened 2 months ago

PTFOPlayer commented 2 months ago

I am currently developing RTS game. In places with water i encountered FPS drops by 2x. I am using this settings for water:

            .insert_resource(WaterSettings {
                height: 0.0,
                clarity: 0.95,
                ..default()
            })

I'm also using TAA for anti aliasing, CAS and SSAO, but when i turn them off (and add DepthPrepass in place of TAA) drops still ocure.

I currently have RX 7600 (arround RTX 4060 performance)

PTFOPlayer commented 2 months ago

After some benchmarking and experimenting with code i found a solution.

fn fbm(v2: vec2<f32>) -> f32 {
  let m2 = mat2x2<f32>(vec2<f32>(0.8, 0.6), vec2<f32>(-0.6, 0.8));
  var p = v2;
  var f = 0.;
  f = f + 0.5000 * vnoise2d(p); p = m2 * p * 2.02;
  // f = f + 0.2500 * vnoise2d(p); p = m2 * p * 2.03;
  // f = f + 0.1250 * vnoise2d(p); p = m2 * p * 2.01;
  // f = f + 0.0625 * vnoise2d(p);
  return f / 0.9375;
}

commenting out some of those iterations reduced fps drops while maintaining "similar" look

consider adding to water settings some way to reduce ammount of iterations, i will work on it myself and maybe make a pull request

0xh007 commented 2 months ago

On another note, I've noticed that the Steam Deck really struggles to run a game using this library. If there's any kind of low-performance mode that could be added in it would be phenomenal. I may the running @PTFOPlayer changes above and see how it does on the steam deck.

PTFOPlayer commented 2 months ago

@0xh007 I am currently working on performance friendly version

Look into my fork

Neopallium commented 2 months ago

@PTFOPlayer Thanks for profiling that.

Also something I just realized is that maybe we don't need both "deferred" and "non-deferred" vertex and fragment shaders here: https://github.com/Neopallium/bevy_water/blob/ee29445e22a281a1ca7c544bc5623e96a27f96da/src/water/material.rs#L108

I don't have time right now to do testing, but try commenting out one set of shaders.

I still don't fully understand bevy's render pipeline. So any extra help is great.

PTFOPlayer commented 2 months ago

I will test that in a moment

In previous tests i figured out that leaving non-deferred shaders only doesn't change anything but also does not improve performance that much

PTFOPlayer commented 2 months ago

I made a PR

Please modify code for settings as you like, I made mine to work on weak devices.

Neopallium commented 1 month ago

@PTFOPlayer Thanks for the improvements. I have merged your changes with some modifications. I changed the shaders to use defs (#ifdef) instead of a uniform for the quality setting. This should be cheaper.

Fixed an issue with the vertex height for the two lower quality settings (it was a little bit too high).

Also found a way to use Partial derivative to make the wave height code cheaper, this improvement only works when the vertex shader doesn't move the vertices up/down.

@0xh007 If you can also test the latest main branch code and let me know if it works for you.

I will roll a release if the current code works well.