Neopallium / bevy_water

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

Add most of the `StandardMaterial` fields to the water material. #10

Closed Neopallium closed 1 year ago

Neopallium commented 1 year ago

The most important fields would be the base_color, fog and alpha modes.

noebm commented 1 year ago

I thought about that too. In the long run it might be easier to make a compute prepass to update the mesh and output a texture sampling the wave function and passing that to the default pbr shader directly. The only possible downside I can see is that you cannot do some water specific effects.

If I understand the current version correctly it just displaces the vertices and does normal mapping.

Neopallium commented 1 year ago

I thought about that too. In the long run it might be easier to make a compute prepass to update the mesh and output a texture sampling the wave function and passing that to the default pbr shader directly. The only possible downside I can see is that you cannot do some water specific effects.

I want to avoid compute shaders since they are not fully supported on WebGPU (at least not without enabling flags and not all browsers).

A prepass saving the wave pattern to a texture would require a lot of texture memory. Also right now all of the water entities can share the same mesh, but if a compute prepass was modifying them, they would all need to have their own mesh.

I have created a custom PBR based shader before, it isn't too hard. Most of it is just passing some of the StandardMaterial fields through to the bevy PBR shader functions. I don't think the water will need every thing.

If I understand the current version correctly it just displaces the vertices and does normal mapping.

Yes, it displaces the vertices. The normal calculation is basically do the same thing as a normal_map texture (Adding extra surface details without a large number of vertices).

A compute prepass would be doing the same work, but needs to save the results before the render pass.

Neopallium commented 1 year ago

This is done: https://github.com/Neopallium/bevy_water/commit/21037d6e578019dc474862561063bfeaebc4ba4b