Posts: 25
Threads: 3
Joined: Jan 2021
Reputation:
2
Hi, I've been messing around with ObiFluid the last few days and I'm starting to achieve a look I like, but I have two questions:
Firstly, how can I change the rendering order so that fluid appears behind particles from a VFX graph?
Secondly, how can I get rid of this white edge colour where the fluid contacts the ground? It is only visible in the game view (pic below), but my experimenting with the fluid renderer settings hasn't revealed the cause, this was the least obvious I could make it.
I'm using URP in 2021.2.7 and I've followed the basic setup guides but may have missed something.
As a final bonus question, are there any example shaders that allow some sort of projected texture mapping onto obi fluid, or is that a dumb question?
Thanks in advance Jose!
Posts: 6,300
Threads: 24
Joined: Jun 2017
Reputation:
397
Obi Owner:
13-03-2022, 06:33 PM
(This post was last modified: 13-03-2022, 06:35 PM by josemendez.)
Hi Xanduffy!
(12-03-2022, 11:18 PM)Xanduffy Wrote: Firstly, how can I change the rendering order so that fluid appears behind particles from a VFX graph?
Fluid is rendered after all opaque objects, right before transparent rendering begins. Also, depth testing agains whatever is in the depth buffer at that point.
Never used VFX Graph, but the sensible thing to assume is that most of what it draws is transparent stuff. So it *should* appear on top of fluids. Will test it myself tomorrow morning and report back.
(12-03-2022, 11:18 PM)Xanduffy Wrote: Secondly, how can I get rid of this white edge colour where the fluid contacts the ground? It is only visible in the game view(pic below), but my experimenting with the fluid renderer settings hasn't revealed the cause, this was the least obvious I could make it.
I guess this is the fresnel rim? reducing "smoothness" in the fluid renderer should reduce its intensity. But it could also be the particle blending background, which is pure white by default. Does this go away if you use multiplicative blending for the fluid? (using the source/dest blend modes in the fluid renderer)
(12-03-2022, 11:18 PM)Xanduffy Wrote: As a final bonus question, are there any example shaders that allow some sort of projected texture mapping onto obi fluid, or is that a dumb question?
The thing with textured fluids is that the naive approach (which is indeed projecting a texture on top of them) looks terrible, because the fluid is moving and the texture is not. So the end result looks like a comic book cutout pattern thing, which might only be good for NPR stuff.
The usual way to circumvent this is to advect textures. Advecting a texture means "moving" it along the fluid's velocity field, so that if the fluid stretches/flows, the texture does too. Sadly this generally stretches/distorts the texture beyond recognition, and the workaround available (advect two offsetted versions of the texture, and lerp between them) results in noticeable pulsating artifacts. Better approaches exist, such as lagrangian advection (give each particle a "billboard" with a piece of the texture and blend them together) but it still generally looks pretty "poppy".
The takeaway point is that there's no good looking, performant, widely known way of doing this. Depending on your exact use case you might be able to hack something that looks good enough for your particular case. Can you share a bit more details about the results that you're after?
Posts: 25
Threads: 3
Joined: Jan 2021
Reputation:
2
13-03-2022, 08:38 PM
(This post was last modified: 13-03-2022, 08:46 PM by Xanduffy.
Edit Reason: Whoops, tried to embed an image; Also mislabeled the main image
)
Hi Jose! Thanks for the quick response.
Regarding the white outline issue, I think it is a blending issue as I have smoothness at 0, and the effect does get worse the lower I set the thickness cutoff, pushing that to 5 has mostly gotten rid of it, but obviously limits the look of the fluid a lot. Changing around the 'basic blending' settings can get rid of it completely, but seemingly not while achieving the lava look that I have currently using this setup:
Now where things get interesting is that while messing around with these settings I unwittingly managed to partially solve the other issue with VFX particles!
As you'll see in the image below, using the blend settings above allows some of the particles to render in front of the fluid. The flames are visible when blending towards the DST Color, while the previous settings which blended towards Zero occluded both the flames and the smoke. I'm not sure why this is happening, but I think the problem stems from the flames being set to additive blending while the smoke is set to alpha. I hope that information can reveal the problem quicker!
As for the idea of texture mapping, I had been learning about flow map shaders recently and experimenting with them in the shader graph, which started me thinking about somehow projecting that onto an obifluid surface, which in theory could blend much better with the flow of the particles, at least in somewhat predictable simulations. That is mostly pipe dreaming anyway as I have zero meaningful experience in writing my own shaders.
As for the more practical suggestions, the project I'm working on is quite stylized and honestly a certain amount of popping/pulsing is completely fine, flow map shaders have a similar pulsing effect when overlapping the flow out of phase. I'm after two effects specifically: mud and lava. The mud is clearly much easier to achieve though it is slightly difficult to find renderer settings that suit it as well as the lava. (The mud is intended to have a specific bubbling vfx graph attached so popping really doesn't matter there.) The lava is moreso the one I would like to somehow texture, and again the nature of the liquid, the stylized look and the intended flames/smoke effect may be enough to cover for imperfections in the texture.
As it stands though, using particle Z write and very specific colours has at least gotten the point across that it's lava, and looks quite good in motion too. The blending/occlusion issue is more of a concern.
Posts: 6,300
Threads: 24
Joined: Jun 2017
Reputation:
397
Obi Owner:
14-03-2022, 12:02 PM
(This post was last modified: 14-03-2022, 12:12 PM by josemendez.)
(13-03-2022, 08:38 PM)Xanduffy Wrote: Hi Jose! Thanks for the quick response.
Regarding the white outline issue, I think it is a blending issue as I have smoothness at 0, and the effect does get worse the lower I set the thickness cutoff, pushing that to 5 has mostly gotten rid of it, but obviously limits the look of the fluid a lot. Changing around the 'basic blending' settings can get rid of it completely, but seemingly not while achieving the lava look that I have currently using this setup:
If thickness cutoff affects the white outline, then it's definitely the blending background color showing trough.
Particle colors are blended over a white background (this blending is controlled by Particle blend source/destination), then the resulting fluid render target is blended on top of the frame (controlled using Blend source and Blend destination). The blend source/destination values are just your typical blend factors).
The blend factors you're using basically multiply the fluid color by itself, and then add them to the screen's color multiplied by itself - which isn't at all how fluids usually behave. The resulting blend equation is:
finalColor = fluidColor * fluidColor + sceneColor * sceneColor
Compared to the default blending (fluidColor * fluidThickness + sceneColor * (1-fluidThickness)), this makes no use of the alpha channel(transparency/thickness) so the particle blending background will be fully visible, resulting in a white halo/outline.
While you cannot get rid of the outline entirely without throwing alpha into the equation, you can choose its color by modifying FluidRenderingUtils.cs and setting thicknessBufferClear value to the color of your choice.
(13-03-2022, 08:38 PM)Xanduffy Wrote: As for the idea of texture mapping, I had been learning about flow map shaders recently and experimenting with them in the shader graph, which started me thinking about somehow projecting that onto an obifluid surface, which in theory could blend much better with the flow of the particles, at least in somewhat predictable simulations.
Flowmaps are essentially 2D textures where uv coordinates are advected. Projecting a flowmapped texture onto the fluid surface, while possible, will probably result in some funky looking stuff. You could project from the camera, or maybe top-down if your fluid sits on the floor most of the time. There's certainly room for experimentation. However I think the most promising route is still lagrangian advection, which is on my long term to-do list.
Will try to figure out sorting with VFX graph and get back to you shortly!
(13-03-2022, 08:38 PM)Xanduffy Wrote: As it stands though, using particle Z write and very specific colours has at least gotten the point across that it's lava,
If you're planning to use some bloom in your game (be it true HDR tone mapping or fake overexposure) I'd consider using the fluid's color or thickness as emissive. That would make your lava glow, helping sell the "hotness" of it. This does require some shader writing, though.
Posts: 6,300
Threads: 24
Joined: Jun 2017
Reputation:
397
Obi Owner:
Hi again,
Been testing VFX graph and ObiFluid integration in URP, and sadly VFX graph does not play nice with *any* transparent objects in URP. Particles are drawn on top/behind other objects depending on the camera position relative to the effect pivot.
https://issuetracker.unity3d.com/issues/...1518523487
A workaround is to change the fluid renderer's render pass event. Open up ObiFluidRendererFeature.cs, and change all instances of RenderPassEvent.BeforeRenderingTransparents + 1; to just RenderPassEvent.BeforeRenderingTransparents;
That should get VFX particles rendered on top of fluids.
|