Skip to content

Feature/local water bodies#361

Merged
huwb merged 135 commits intomasterfrom
feature/local-water-bodies
Sep 30, 2021
Merged

Feature/local water bodies#361
huwb merged 135 commits intomasterfrom
feature/local-water-bodies

Conversation

@huwb
Copy link
Contributor

@huwb huwb commented Nov 3, 2019

Status: Ready to merge

What & why:

An often-requested feature is to use Crest for local bodies of water (limited in area), rather than filling the whole world. I refer to this as 'local' as opposed to 'global'.

It turns out Crest is able to do local water well \o/ by adding the following mechanisms.

How:

  • Sea level can vary instead of being globally fixed - extend ocean depth to add sea level value - in this PR
  • Localised gerstner waves - Local gerstner waves #440 (merged)
  • Clipping extensions
  • WaterBody component which demarcates an area in the world. If present, OceanRenderer will intersect all ocean tiles with all WaterBody's and turn off any tiles that don't intersect with a body, meaning they'll never get processed/submitted/rendered. - WaterBody script for tile culling #549 (merged)
  • Any water surface below the terrain are not drawn through normal GPU depth testing / z buffering (works out of the box)
  • Shadow data and underwater effect take sea level offset into account - in this PR . Curtain is deprecated and no attempt is made to extend it to support this.

Authoring all this is a bit of a brainful / juggling act, so i've also experimented with adding a wizard (Window/Crest/Create Water Body) which allows the user to place a water body, configure some settings, and it will create the setup. The resulting setup can be tweaked, moved, duplicated. - #561 (merged) . UPDATE: The authoring has been made much easier and I have now removed this wizard.

Testing:

There's a Lakes scene added. It's not representative of what would be pushed, its just for testing.

Issues:

  • The LODing system scales/adjusts detail based on viewer altitude, measured relative to sea level. This works with one sea level, but breaks with multiple sea levels, and as a result water bodies above/below sea level are starved of detail. I'm not sure how to drive the LODing, I could imagine adding C# to detect when camera is near different sea levels and adjust as necessary. This wouldn't work though if the sea level is generated by geometry (like a river proxy geometry), in which case sea level would not be known to C# (unless it read the geometry on the CPU i suppose..). UPDATE: addressed this problem by driving LOD from height above water, and having this vary smoothly over time. It sort-of works but not sure if it will hold up.
  • Currently sea level is written at same time as cached depths. Cached depths use 'min blending', and since its in the same pass, sea level also has to use min blending, and theres a hack to deal with this which has a side effect that secondary sea levels have to always be greater than the global sea level. This is a bit rubbish/confusing and can probably be fixed by rendering depths and sea levels separately, at the cost of more draw calls. UPDATE: I've left it as is for now. Due to how the Register scripts are written / inputs are registered, i think this would require a new 'LodData' type for sea level offsets. Maybe we should just live with the constraint that water bodies must lie above sea level, so sea level needs to be lowest water level. Sea level can be changed at runtime which might help as well.
  • WaterBody doesn't have correct bounds, its currently hacked. Need to convert OBB to AABB.
  • Probably need validation to warn user if they have local water bodies but don't have clipping set to clip all. UPDATE: I'm not certain if this is a valid warning. Leaving for now
  • Shadow data needs to take into account sea level offset
  • Having to give the materials for gerstner & clip on the local water body wizard sucks. Should we create material assets for them?
  • Can sea floor depth render target be single channel unless sea level offset needed? UPDATE: Added a settings object for sea floor depths. Defaults to on, but can be switched off by advanced users to save a bit of perf.
  • Placement is awkward (creating a plane proxy object), makes it difficult to see what is happening. Needs massaging. UPDATE: Wizard removed

Note on materials: There isnt a good mechanism for varying water materials/appearance. We could probably add a mechansim to assign an ocean material to each WaterBody, but this wouldn't help in the case of rivers which would need smoothly varying & connected attributes across water bodies. I think this is a future fish to fry. UPDATE: the simple approach merged in #902 . A more fancy approach would need to create a separate lod data for material blends, or such.

huwb added 8 commits November 3, 2019 18:01
Cull tiles that dont overlap. Push verts down using a hack.

I think we need a sea level offset. The height needs to be pushed down
per-vert, not per tile. A tile could overlap multiple lakes.
Works "ok" but destroys precision for any large delta :/.
Also foam could not separate displacement from sea level.
# Conflicts:
#	crest/Assets/Crest/Crest/Scripts/LodData/LodDataMgrAnimWaves.cs
@huwb huwb mentioned this pull request Nov 10, 2019
@magenta404
Copy link
Collaborator

Yeah both could work, that sounds good, ill let you play around with it then.

Any ideas yourself?

@huwb
Copy link
Contributor Author

huwb commented Sep 21, 2021

Any ideas yourself?

Not sure, its always tricky.

Wondering if we should try make it textured or just make it grayscale or a grid pattern or etc. Textured will always be more professional/impressive etc but can be tricky to make look good.

For the asset store versions we have some pbr textures used in the PirateCove scene which we have permission to use, maybe they are useful. Maybe a good approach is to take pirate cove and resculpt it into a different scene with a lake and a river, and could sprinkle in the rocks etc, and maybe can look good that way. The textures and assets would not be usable in BIRP (would not be pushable to MIT licensed git i dont think) but thats prob a secondary problem at this point.

Other ideas.. Not sure if theres a free asset we could get away with using: https://www.turbosquid.com/Search/3D-Models/river

Thought maybe this had a river but does not look like it: https://www.youtube.com/watch?v=iV-224nMwN8&ab_channel=Unity

I guess a last option would be to put some funds towards contracting an artist to look at it. This would be good but i dont have one in mind so we'd have to ask on the discord or find one online, i think theres websites for this.

I'll keep thinking about it.

@magenta404
Copy link
Collaborator

We can do both. Having basic scenes like boats.unity which have the flexibility to be purely instructive are useful. And it is good to have a scene for built-in since it is used for evaluation. Then we can keep fancy scenes like Pirate Cove for UAS only.

@huwb
Copy link
Contributor Author

huwb commented Sep 25, 2021

Thanks for the notes.

Shadows fixed now

Data reverted

Attempt at docs done

@huwb
Copy link
Contributor Author

huwb commented Sep 25, 2021

One area that might be an issue is when the camera is up high. The lack of mesh density can cause noticeable degradation - especially with the added normals. But can be solved by giving splines a decent margin so rivers don't disappear etc.

Agreed

@huwb huwb requested a review from magenta404 September 25, 2021 21:39
@huwb
Copy link
Contributor Author

huwb commented Sep 25, 2021

@daleeidd i think i've addressed everything, re-requested review

Mainly to be consistent with other functions.
Copy link
Collaborator

@magenta404 magenta404 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. Just a few review items. Mostly minor ones.

I've enabled docs for this branch in case you wish to review your changes: https://crest.readthedocs.io/en/feature-local-water-bodies/

@huwb huwb requested a review from magenta404 September 30, 2021 14:56
@huwb
Copy link
Contributor Author

huwb commented Sep 30, 2021

I think that may be everything addressed, rerequested review. Thanks for those

Copy link
Collaborator

@magenta404 magenta404 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on achieving an important milestone! Works well and no issues that I experienced.

@huwb
Copy link
Contributor Author

huwb commented Sep 30, 2021

Awesome thanks for all your help!

@huwb huwb merged commit c6538cb into master Sep 30, 2021
@huwb huwb deleted the feature/local-water-bodies branch September 30, 2021 22:15
@magenta404 magenta404 added this to the 4.14 milestone Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants