Code Monkey home page Code Monkey logo

Comments (6)

huwb avatar huwb commented on May 30, 2024

Yes this is a common problem with refract surfaces like water. I brainstormed some "solutions" below, but i dont think any of them are perfect..

Solution A: Render your transparents as opaque..!? Sounds dumb but maybe with it can be faked to look transparent or something!

Solution B: Render using alpha test - if this helps at all?

Solution C: If you're using TAA, you might be able to go full stochastic transparency - render as alpha test and randomly accept or reject pixels using a noise function and the desired alpha as the probability. I'd be surprised if this can work really well but its possible i guess..

Solution D: Refuse to accept that alpha does not work and strong arm it into submission:

  1. Render your alpha towards the end of the opaque pass (!) - perhaps queue 2450 or something (so Geometry+450). EDIT: as i've just discovered the hard way, Renderer.sortingOrder takes priority over the queue setting it seems, so additionally you'll need to see the sortingOrder to less than say -16, to render before any ocean lods.
  2. When it blends onto the background it will need to fake depth fog between itself and the opaque surface behind. So if it is 5m above the sea floor, it should compute scattering using the same technique as the ocean shader, using the same density values. This will give an alpha value and colour which it should be able to incorporate into its final colour, so it will appear to have water behind it when it blends onto the opaque geom. The problem is knowing how far you are from the sea floor - perhaps that can be fed to the shader using raycasts etc. Or perhaps you know your stuff will always be some distance from a relatively flat sea floor. I'm sure this step 2 is very confusing - you might experiment with faking stuff/tweaking by hand before going full math and trying to get all of this working.
  3. The shader needs to write depth (turn ZWrite On). The ocean will use this depth later to do refraction and depth fog/scattering for water in front of the alpha surface.
  4. Hope that two jellyfish do not overlap! This does not support overlapping surfaces.

This is not a robust, general solution, but could get your across the line for specific cases.

Solution E: Turn on MSAA and use alpha to coverage. I have never used alpha to coverage so I'd need to refer you to google.

Out of all the above, i think E is the only once i really believe in, but it relies on MSAA and i've never used it in practice so i cant speak to the trade offs..

What do you think? If others have ideas please add them!

from crest.

huwb avatar huwb commented on May 30, 2024

( @Midda-C - probably of interest )

from crest.

Midda-C avatar Midda-C commented on May 30, 2024

Yeah, we did notice this limitation early on, but pretty much wrote it off as a thing we'd need to live with. I don't think we'll need to display any transparent objects under water (the one thing we were we simply changed to dithered alphatest which looks better for us anyway). Solution C is interesting, though. I have wondered how using a simple bluenoise flipbook might look (not for this issue specifically, just for avoiding transparency in general). Unrelated, but I should play with that some more. :)

from crest.

huwb avatar huwb commented on May 30, 2024

Ha option C, i like it! If you do happen to experiment with this there are some GPU-friendly noise functions that might be useful for quick experiments. https://twitter.com/stormoid/status/1021397559699558401

And of course it would be very interesting to discuss any results!

from crest.

holdingjason avatar holdingjason commented on May 30, 2024

Will need to play with opt C. Right now we are doing dithering when spawning stuff or despawning things like fish where the dither into and out of existence. Works really well but have not tried it with something like persistent alpha objects like jelly or bottles.

from crest.

huwb avatar huwb commented on May 30, 2024

I think I will close this - for now - as I don't think much will be done from my side for now or in the near future, although I'll definitely keep it in mind and return to it if I have thoughts or if I see something that could be of use.

I would of course be very happy to hear any experiences you guys have if you try this stuff out, please do post back if you do.

from crest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.