Unity - Can anybody suggest how to create an oil-and-soap effect?

unity
shaders
particles

#1

I’m looking to create an effect in Unity similar to this. I could do something vaguely similar in Blender fairly easily, but I need to be able to do this in realtime… any suggestions? I’ve tried using Unity’s particle system for this, but can’t find something that will create the correct intermixing quality… More than happy to do a little shader coding if you can point me in the right direction.

Thank you in advance for any help! =D

EDIT:

Maybe I could do something like this, but put two distinct mixing colours into the diffuse? The problem is that the looping nature of the effect is likely to become very obvious - this will be front and centre for a long period of time, and even if I distort the model dynamically in an attempt to randomise the visuals further, the effect is likely to become evident. I guess I could make the texture HUGE and UV scroll it, but I’m afraid folks are likely to twig to that.

…Maybe it would be possible to record a simulation from Blender as a movie file and just play it with the water flow & UV scrolling…? Do multiples of these on cards, fade them in and out over each other?

I guess I’ll start experimenting tomorrow… (5am here!)


#2

not sure quite what you need. if you aren’t aware of flowmaps I would look into that.

if you want to get really fancy, this was made in unreal and could take a good bit of time to convert to unity. timestamp 20min


#3

Do you need the effect to be pre-mixed 2 colors, then transition into mixed state creating an additional color at the mixing point? Or is it more so you have 2 colors intermixing constantly, never at any point completely separate?


#4

@Cel - Hey there! Thanks for the reference - I actually suggested using flowmaps in the third link. The Unreal vid is bang on the money… hmm. Looks computationally expensive. I’ll have a lot to study there. I’m not sure if I really want to do a simulation at that level in 3D, but we’ll see. Thanks again!

@NateLane - The latter, Nate, I think. The spec is as follows…

phosphenes floating in an outer space place, these are akin to those when you close and rub your eyes. Aesthetically they resemble the reaction of chemicals that do not mix with each other like baking soda & vinegar or oil & water with added food colouring.

I’m also investigating doing this with a writhing mass of particles, creating a cloudy, amorphous blob. Another way might be to build some animations with metaballs, bake them out and put them in the environment - but none of these really capture that intermixing quality my client has identified…

Thank you for your attention, folks.


#5

Yeah you already got it with the flow map method. Maybe transitioning with a nice mask between flow maps you could get extra life out of it since it stays on screen so long?


#6

Yeah, I agree with you Nate. Flow maps, some kind of mask dissolve / fade between multiple instances of the object. Actually, I might add a displacement shader to the object so I can hint at some kind of 3D movement / perturbation. Thanks for hearing me out.


#7

If you’re feeling adventurous, you could try your hand at a CFD or Suture shader:
https://www.shadertoy.com/results?query=Fluid

This one in particular might be the kind of thing you could look at.
https://www.shadertoy.com/view/MsGSRd


#8

@bgolus Ohh… that’s very nice. Yeah, that’s bang on the money. Honestly, my shader-fu probably isn’t sufficient to execute this, but I’m looking forward to trying. Hope it’s performant, as this project is for VR… =/

Thank you, again!


#9

It’s not super cheap, but that particular technique has two nice advantages:

  1. You can (and would actually need to) render it to an offscreen render texture which means you can control the resolution you run the simulation at to control the performance. If you’re using Unity, you could implement it using a custom render texture asset, or implement it by manually ping ponging between two render textures which would give you some extra control.
  2. This particular implementation seamlessly wraps, so you could put it on a sphere or cylinder as a repeating texture and it’ll look correct.

One additional thought. You could randomly splash shapes of color into the buffer to add some randomness to the simulation.


#10

Thank you, Ben. I’m not going to have a chance to experiment for the next couple of days, but I’ll update this thread when I have something…!

Best regards,

–Rev


#11

I’m not sure if Unity offers the same functionality, but I’ll describe how I would do it in UE4, maybe that helps! :slight_smile:

So what you can do in UE4 is create an orthographic top-down scene capture camera and tell that camera to only render a specific effect.

So you create one of those scene captures and tell it to render a ribbon trail that is attached to e.g. your character or whatever (can be a dummy object). You can save that out to a render target / texture every frame (which has a cost, but not through-the-roof or anything) and then use it in your shaders.

If you distort this texture with a flowy-smooth noise texture your trail should end up getting this soapy-oily look that you’re going for.


#12

I think this paper should be mentioned here

and here a bit more related math https://en.wikipedia.org/wiki/Shallow_water_equations