How to make realistic foam in Blender?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
why are there literally no tutorials on making foam on youtube i mean why one of the reasons is that foam is very hard to make and not necessarily because it's complex yes it has many nodes but it's just so slow to render so i will be using a cloud pc service called wagon which gives me a nice and fast gpu and they are not sponsors of this video but they generally make this video possible because it is disastrous to work on that phone with a cpu so if you want to try that too i have a link which gives you five hours of computer usage for free and that should be enough to follow the tutorial so let's start first if you have to add some foam what do we do well we add a mesh to add those bubbles onto so i'm going to add just a back plate like here for example size of four and let's add a meta ball they aren't getting too much love i mean they aren't used too much but this time we're gonna use them heavily so let's take this uh metabol here and let's just make something that looks like foam maybe here i'm going to drag those both down on the z-axis so this foam looks like that and then i'm going to duplicate maybe um one more here drag it on the z-axis yeah let's say this is our foam right and i'm going to go to the metaball settings here and change the resolution viewport to something smaller so that it is smoother now so you can see the edge isn't as checked as it was before so now we can convert this into a mesh you don't have to do that but i'm going to do that because when we are going to displace some bubbles afterwards we need some geometry to work with some actual geometry so i'm going to convert them to mesh from that menu here and now we have actual vertices and edges and faces so let's open a shading window from here because this is gonna be purely shader based and very procedural also just some quick like things that are necessary i mean you have to use cycles of course because this doesn't work with ev and you also need to use your gpu so finally i can use a gpu in blender because i've done all of my blender work on a cpu so far i'm going to use optics and the tesla t4 from the wagon cloud computer now let's take this uh metabolt thing here and let's start with this foam so i'm going to delete the principle bstf and let's add a voronoi texture and now you're asking me why do i need a warranty texture if you look at foam or like a piece of foam you see we need bubbles right so bubbles basically they look like that i think you agree with me basically just some you know dots somewhere and if you add a bump here i'm going to zoom in if you add a bump here connect this to the height you see we have like holes and if you invert this we have something like bubble strike very large and intersecting so to fix that what we need to do is to first add a math node to invert those and i'm not going to invert here and just see in a minute why so i'm going to use a subtract node here and i'm going to put the thing here in the bottom socket so basically this is going to subtract divide the areas from a value of 0.5 so this means when the white areas have a stronger value this is going to result in something black right we have like bubbles here right but this isn't having any effect on the bump why well that's because the bump node has no problems with taking all sorts of values and making them bumpy or making them look like this bump here so i can have any value here and although this is looking like very dark or just uh this also might be super white if for example put here like 5000 this is white very bright and the bump is still gonna work well that's because we haven't clamped so if i clamp this the story is different when i drag this and then i can control the size of those bubbles so if i put something like 0.3 here you see we have bubbles here right and this all works pretty well so if i add for example like glossy shader here and i'm gonna preview it like that then you see we have bubbles but they are not like bubbles right they're like pretty much like bubbles but they should be more smooth they're like like little cones right now so to fix that what we need is a color ramp a little latency here we need color ramp and set it to b spline so this means we're gonna get very smooth here so you just are going to drag this until the end and you see a lot of mess here and that's just something you can fix with this value here so you're going to drag this value right um until you see some bubbles like that and these are gonna be like the first bubbles we have the largest ones but what if you want to look at this foam from an angle then this bubble is here right and this just disappears it's so flat and that's because this is bump this is faking and we're gonna get real here so what we're gonna do is delete this pump here we don't need that we need this placement instead so we need actual geometry to be displaced uh where there are bubbles so i'm gonna plug the displacement here and the value which was uh beforehand going to the bump is now going to the uh height yes to the height and what has happened nothing this is still the same thing i can increase the scale but this is still looking well not very good so the fixation here is going to be going to the settings of the material and under this displacement thing here this might be cut off i don't know if it is but i think it might be basically under displacement here you have bump only and displacement only so i'm going to set it to displacement only this is like very very strange here what has happened let's take the scale down to one and okay we have something very um sad and small in the middle here and that's because the mid level is messed up so let's put zero here and now this is going better and let's increase the scale for about five but this isn't very good we need more geometry and to have more geometry we have to use the experimental feature set and now if you go to this uh modifier menu here menu here you can select subdivision surface and more than that you can select adaptive subdivision so right now dicing scale is one pixel and in viewport this is eight pixels i'm going to set it to 0.5 so that i get a little bit more details out of that i'm going to decrease the roughness and these are pretty much like bubbles what we need to do now is that we have to make sure that the scale is right so let's put 10 here and does that seem okay to me well 10 is for about the nice scale maybe even 15 seems to be good for those bubbles yeah 15 15 is a is an okay number so now we have the displacement for the bubbles here we need more of those and basically this would just mean we're going to duplicate this and add more of those voronoi textures with a different scale but first what you have to do is uh during my my numerous experiments i discovered that actually you have to add some more variation to the scale of those bubbles because otherwise this is not going to look very realistic to do that what we have to do is to basically change this subtract value here for each bubble separately so for example if the scale if the value here is bigger we probably have bigger bubbles which is correct as you see and if this is very very small then we have smaller bubbles so we just have to have a texture that has different values for each bubble so for example here it has different value here it has different value and for this bubble also basically we need a texture like that like the skin of a rhino probably looks like that also we can do that using the color from the same orange texture so this has a different map for each bubble and we can make this black and white and control this a bit more by using a color ramp so i'm gonna put the color ramp down here and then just as you see this is black and white and i'm gonna map those values so the smallest one is gonna be zero and the biggest one is gonna be 0.01 so exactly the same value that you have in this math node here so i'm going to put those put this into this value here and let's preview how this looks well now we have control over uh the scale or the amount of those things so i can make everybody have like pretty much the same scale like you see here or i can track this here and i can move this handle here and i can control the amount of those bubbles so i'm going to move this around here because i don't want to have too much of those bubbles and i'm actually going to make them a bit uh bigger so something like that these are going to be my my big bubbles right now let's add the next level of bubbles so i'm going to take all of that here and just duplicate this with shift d and now we have to find a way to put both of those in this displacement node how do we do that well usually there is a math node that can help us and let's see what works here in case of using the addition this creates something this is exactly the same thing guys up here so basically we're just adding double displacement not a very good idea so i'm going to use eight here for the scale of the voronoi and you see we have smaller bubbles right and this is looking fine and all but they are first um very prominent i mean they are very like they are very pronounced right so we have to make them a bit smaller and to do that we need to multiply them so let's use a multiplication afterwards and for example if i multiply this with 0.5 i make them half as high but there is a formula for like the correct ratio so that the smaller bubbles also have the same height and width ratio than the bigger bubbles and this can be obtained if you look at the scale of the first one this is three and the scale of the second one this is eight so here we have to type three divided by 8 which is going to give us such a number as you see here and this is going to make sure that the bubbles are looking for about the same actually it seems to me that we can increase the scale here so let's put like 25 here yes this is looking better right now the next problem is that you know a smaller bubble just happens to be on the bigger bubble how do you fix that for that let's not use add but let's use maximum which means that it's gonna basically take those two values and those two values are gonna fight which means that the stronger one is gonna win and because we have multiplied the bottom one with a relatively small number this means the upper one the bigger bubble here is stronger so this one is gonna win and this is gonna take the place of the smaller bubble and this works everywhere i mean if the value is smaller it's just gonna be crushed by the bigger one so everything has its own place right now and let's start adding more of those bubbles so let's duplicate this thing here put it down here and let's use different scale for example let's use 16 and let's combine them using maximum so i'm going to put the maximum after the multiplication here and i'm going to drag the the smallest bubbles here and also going to mix them using maximum right but they have to be a bit more weak otherwise they're gonna clash so i'm gonna put here 3 divided by 16 because 16 is the scale of the voronoi texture here so this seems to be working right let's add another set of bubbles so i'm going to take those uh those things here i'm going to duplicate those let's take a maximum nodes put it here let's take a multiplication from here and let's use different scale also for example um 24 and let's uh put here 3 divided by 24 and let's continue adding those bubbles actually i'm gonna drag those color ramps uh here so that we can have more of those bubbles and we don't have to add so much layers so many layers but we can just add for example only five of them yes this seems to be nice and now let's add the last level of the bubbles copy this once more and let's take the maximum and let's mix it with the one down here let's use for the scale for example 40 3 divided by or with 14 and as you see we have the bubble reflections ready because the glossy shader is only for the reflections and now you're asking me how do i only keep the reflections how do i remove this metallic thing in the middle here well for that we can use a mix shader so i'm gonna go up here and taking this glossy i'm gonna use a mix shader and let's mix the glossy with a transparent shader so transparent uh put it here and now we can drag this uh this slider here and we can control for example i'm going to type here 0.95 and this means we only have the like we have a little bit of reflections but mostly we have a transparent film so this is very good for some foam because we have to see through the foam right but there is a problem and the problem is that the foam has this film between those bubbles and this is also having reflections and we don't want that so i'm going to use as defector the the displacement map which looks like that actually this looks different it's just very very dark so i'm going to increase the exposure and you can see it looks okay this is -10 for some reason so yeah this looks like that right like a displacement map and we're gonna use this as defactor so um to make this actually visible i'm gonna use a math note i'm going to put the exposure back to 0 and i'm going to take the maximum value from here i'm going to multiply this with the number for example let's say 5 000 right and let's see how this looks this is obviously visible and also very very bright so i'm gonna clamp this because the factor only needs a range between zero and one not zero and five thousand so i'm gonna use this uh this clamped monstrosity here as the factor and let's see how this looks right now now we have holes where we should have reflections and this isn't a good thing at all so i'm gonna use a color ramp here and put this after the multiplication and i'm going to invert the handles so that i have the inverted map and now we only have the bubbles but the reflections are far too strong so i'm going to use let's see where the bubbles are which color do they have they have the color of black so this means that we're just gonna take this black handle here and i'm gonna increase the value to around 0.5 as it was before 0.95 and as you see we have reflections of only the bubbles and not anything in between so basically we have accomplished the reflection part now we only need the volume and for the volume we basically just need a volume scatter shader so let's add a scatter volume scatter and let's plug this to the volume and let's see what happens right so this is plugged in and this looks basically like something very hazy and foggy and let's increase the density so we can see this better for example 50 and this is like um let's say something slimy like a milk which has like those raindrops on it what we need to do is to only have the volume in places where there are no bubbles so in between bubbles we need to have volume and do that well for that we have a mask right you see here this is the mask and it looks like you know it is inverted so basically we have a lot of volume in the places of the bubbles and not so much in between them exactly zero so let's plug this into the density and let's see the madness which is going to happen which is going to happen hopefully it will happen yes so we have volume only in the uh in the bubbles not very nice so i'm gonna add a what is it called an invert node and this is gonna invert the volume so now this is looking like that and then i'm going to add another multiplication nodes so that i can increase the density where needed right now this is clamped it's not very nice but i'm going to put for example 10 here and remove the clamp so now the density can be bigger than one and look at that we have some foam here now what you can also do is that if this is a a soap foam you can search the glossy shader which is lost here yes the gloss is here and you're gonna take a noise texture and you're gonna use this as the color so uh the noise color as you all know looks pretty much like that so let's use this as the color of the glossy shader and let's preview how this looks probably like soap yeah this has a bit of like iridescence or what's the word for that thing i believe iridescence yes so you see the reflections are a bit more colorful right now so that's how you make uh soap foam the coffee phone will be available on patreon and also if you're interested in using uh using a high performance computer like i'm using here then you can use my referral link in the description anyways i hope you learned something soapy from here and go wash your hands and be safe so have a nice time
Info
Channel: Bad Normals
Views: 178,938
Rating: undefined out of 5
Keywords:
Id: 4EZezYWyelM
Channel Id: undefined
Length: 18min 23sec (1103 seconds)
Published: Thu Aug 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.