Make Realistic Procedural Candies with Blender

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] these are the candies we're gonna make so as you see we have this little ballast candy in the middle here that has been made using quite some quite cool matte operations for example arc tangent and stuff here we use some ping pong and here we use some sign functions so they are all very procedural sweets so we're gonna make the middle one here so let's make a new scene and don't save this and let's delete the cube so if you look at this candy or remember this candy it was like a it was like a cylinder right so let's add the cylinder but the problem with the cylinder is that you know this face up here has a very round single like blob face and this isn't good because we cannot displace i mean we just don't have enough geometry there and if you start to subdivide then it's going to turn into something strange it has some you know it's not good geometry anyways so let's delete this cylinder here and let's add a new one and in this menu here select the cap fill type to be nothing so now it's nothing and we have this kind of a pipe and what we're going to do is to enter edit mode select this upper loop here and press command f and grid fill it so now it's created film and we are gonna use the one down here as well so now we have a better cylinder this is too tall for a candy so let's go to the side view and select all of that and let's scale it down for about this size and also let's move this up half a meter and this is pretty much ready just we need to add some loop cuts to make all the faces look rectangular not rectangular square shaped so this is a perfectly prepared cylinder for us so now let's go to the geometry node workspace and this is where the fun starts or for some people if you don't like maths it's not gonna be fun but actually i promise you i will explain like very thoroughly what's gonna happen here so let's add a new set of geometry notes and actually let's not use them because i'm gonna explain you in the shaders first and let's go to the top view and i'm gonna add a new material and remove the principled stuff here and let's add some let's let's not add nothing actually so again i'm gonna use my brother's graphics tablet because i don't have my own if the candy from top down looks like that we have those um like a fan blades or something like that coming from the center right now this is a bit too complex to think of like the solution right now so let's simplify that let's say we don't have them curved but let's say we just make them straight so let's for example make six of them uh straight yeah this is pretty horrible uh i just have to make it smaller i'm i'm not a good good graphics artist as you can see right that's oh anyways you can understand that we have like those um these places are like higher and the places between those lines are going to be lower so that this creates this kind of a like the surface of the candies so right so in displacement world you know when something is higher it has the value of one when something is lower it has a lower value let's say it's zero or minus one so let's make those minus one so in the middle here we have minus one and also um in all of those black areas we have minus one and when the blue line is in place we have one there so this means this place is going to be higher once we have all of those numbers we can see that we need a displacement map that has this kind of values now this pattern is repeating all over uh all around the circle and this tells us that we need a repeating pattern so what kind of math functions can we use to create a repeating pattern in blender we have quite a few of them we have the sign which is a smooth wave like that then we have a ping pong which is a triangle wave and then we also have the modulo which is a sawdust wave like that a little more beautiful but like that now because the candy was smooth i think you can agree with me that we don't need any uh triangle or sword with way we need sine wave and as you know the sine wave is infinitely repeatable it just creates a sine wave out from some values so for example let's say we have here the value of zero and here we have the value of 100 and well we could have like a thousand here it just is gonna create more of those waves if you have more values or a bigger range of values so to actually put this in action here as you see we need a range of increasing values all over the circle like that because if you use a sine function on this kind of values we are going to have repeating waves like that around this circle which are going to form our candy so how to do that well there are a couple of possibilities and in shaders some of them are easier but in geometry notes some of them are not very easy let's find the easiest one what we can do is to use the angle let's say this is our start of the circle from here it's like a clock and this thing here is going to rotate around the circle and it's eventually gonna make a turn of 360 degrees right so the whole circle has 360 degrees of a rotation possibilities right what we can do is to calculate the angle for the circle here right so this is the way we can get a constantly increasing value all over the circle to do that what we need to do is to use some trigonometry because this is pretty much our friend in every case where we need angles so let's say we have for example a point here on the circle and we want to calculate the angle of this circle or this point like that so as you see the angle is going to be here this is the angle alpha and here we have 90 degrees and up here we have some kind of a degrees i don't know and if we mean the legs of the triangle are gonna be the h which is the hypotenuse then here we have the y movement because this is going up i mean you see the y axis is here and then we have the x leg down here so trigonometry has quite a few functions to calculate this stuff there are three functions actually three very useful functions in some cases first of them is sine so sine alpha will be y divided by h so the opposite leg divided by the hypotenuse then the cosine is going to be something different it's going to be x divided by h the adjacent leg divided by the hypotenuse and then the tangent tangent alpha and it's going to be y divided by the x or is it divided with the x i don't know what the preposition there is we don't actually have prepositions in estonian so i have quite some quite a hard time with them yeah so what can we use here as you see we don't know the length of the h because i mean i just don't know the length of the h like i really don't know then the length of the x and y we do know because in shaders as you know we have texture coordinates somewhere here and if you take the object coordinates which are really useful stuff then you can separate them by x y and z and as you see the x is gonna tell us the moment on this axis and the y is gonna tell us the movement on this axis so we know the x and the y we don't know the h here so we cannot use any formulas that have h in it so sine has h in it so we don't need the sine at all cosine also has an h in it so we don't need this cosine but tangent has y divided by x and this is perfectly possible for us because as you see here we have the x and we have the y so that's pretty useful right so dividing y by x we get the tangent value of this angle but we don't get the angle itself so to get the angle itself we need to use the inverse function so the inverse function for tangent is called arc tangent so if you take arc tangent of some kind of a value we get the alpha right so let's do that let's take the x and y first let's divide y by the x so let's use a math node here let's use the y divided by the x division and what do we have here we have something like that and let's use after that the arc tangent so the arc tangent is here but we don't have an increasing value all around circle because we have some black quadrants here every trigonometric function has some quadrants and some of them are negative some of them are positive and in our case we want all of them to be positive and constantly increasing around the circle this arc tangent isn't working for us because arc tangent is only like usable for triangles where this angle here isn't bigger than 90 degrees you can basically understand we have a very very steep triangle and this is like the last thing that can be calculated using arc tangent but luckily we are in a very good place because we have another function and this is called arc 10 2 or arc tangent square something like that anyways this is gonna give us the whole circle and this is a pretty my pretty elaborate function by itself and i don't exactly know how it works but it works so switch it to arc tangent two and as you know the division or as you see the division is already inside this function you see the signed angle arc tangent a over b so let's just take our a which is the y and our b which is the x and plug them here and we have something like that and you're saying okay this has some black quadrants also or two black quadrants actually well uh yes but it isn't very important because we can use the creator then and as you see this is actually increasing in value we just can't see the part here to be increasing because it is negative and everything negative is converted to black in the display color space so now that we have our values like that what we can do is uh to take the sign of these values and we should have like this sun rays coming from the center so let's duplicate this and let's use this sine function and we have something there but because the range is so small for designed work i mean we don't have any rays here they are very big right now we just have to multiply the range to make it bigger so let's multiply it with the number like for example let's make six and now we have six rays here very nice isn't it we have done those things here and now the question is how do you make them look like spirals so to do that what we need to do is add something to the uh to these areas here i can show you how it works and then i can explain we need a vector math node here and then we need to connect it to the object coordinates and use the length of the vectors which gives us a basically gradient like that you see in the middle the vector or the distance from the center point of the object is very small and as it progresses outwards we're going to have a bigger distance so this is how the length works and now what we're going to do with the length is to add to the values before taking the sign of them and we have our spiral right it is very subtle right now so what we can do is to multiply the length and we have the spiral so basically why this works is that right now it looks like that basically the thing we have multiplied let's put it to one actually so we can see this better and after that uh we are basically adding let me just check if my color conversion is right here so after basically before taking the sign of it we are going to add a gradient to that so as you see because we add more to those areas like which are closer to the borders uh the white thing is shifting and then when you take a sign of that it's gonna give us a spiral so if a type six here again and six here again we have like a lollipop for a spyra basically so now we have everything here and we have to put it into geometry nodes so how do we do that well that is actually pretty simple so the first thing we need is a separate xyz nodes so what we need to do is to select or search for separate and we have attribute separate xyz so let's separate our only attribute right now the position attribute so the position attribute into x then into y and then into z so we have our x y and z right now and as you see with our y and x we have to do an arc tangent calculation so for that nothing better than a good old math node let's put it here and select arc tangent two now the first one is going to be y the second one is going to be x and in geometry notes we need an attribute to write the result to or into so let's use for example the angle attribute which is just a new attribute i made i could have made here like a tomato attribute this works as well but let's use an angle attribute it makes more a little bit more sense and what is the next thing we have to multiply it with six and and and actually let's make it visible first so let's use a vector math node attribute vector math nodes and to display something we have to add we have to mangle the position of all these points we have here currently have 290 vertices or points here as you see in vertex mode we have 290 of them and if you want to displace them we have to change their position so i'm gonna add to the position you see add to the position so i'm gonna add the angle which is our coming from the arc tangent and result back into the position which is the thing we're going to want to change so what you have here madness going on and that's because well first of course we don't have too much geometry here so let's add the subdivision surface simple and let's actually make it cut more clark so yes this is the thing we have here uh looking pretty messy and that's the problem here so uh basically as you know the angle attribute here is a float attribute which means it only has one value inside of it so you see here angle has only one value in its column for example position has three values because position is a vector because position is a vector attribute and angle is a float attribute now if you use a float attribute here you know the position is a vector attribute so if you want to change the position we have to change it on all the axises i mean it has to know like what is it doing on x what is it doing on the y and what has it what it has to do on the z axis so right now we only have a float attribute and the float attribute is gonna slam this one single value into all of those axises and this means it's gonna displace diagonally like all over the world because it's gonna displace on all the axises at once now to fix that we have to convert the angle attribute into a vector attribute that only has those angle values for the z axis because we want to displace the candy like only on the z axis so let's use the vector math node here let's take the angle attribute result in the angle attribute and multiply it with a one on the z channel so right now we took the float attribute multiplied with the vector of zero zero one uh resulted in a new angle attribute which is now a vector attribute as you see here so this means that it's only displacing on the z axis and this is pretty much the case as you see here so if you make this a bit smaller you see we basically have a displacement dependent on the angle so here we are displacing zero right or actually negative we have negative displacement here and it's gonna increase as the angle around the center increases so this is a good thing on its own but now we need to calculate the sign of it we can do the multiplication things and all that afterwards so let's use an attribute math note and calculate the sign of this angle and you see you have something here but it isn't visible because you have to multiply it with something before that so let's take a math note and put it before that and let's multiply the angle attribute with a float of for example 6 just like in shaders and look at that we have a we have the early stages of a candy here we could actually add some more geometry it's going to be expensive but sad something so now we need to tackle this spiral stuff so to do that let's check the shaders we need to add before taking design a multiplication of the length of the vector so let's first calculate the length this is pretty easy to do we just need a vector attribute vector math add it here and let's calculate the length of our position and just write it to an attribute called length very boring name for an attribute now we have the length attribute as you already see here as well and what we need to do with it is to add before taking design so let's use the attribute math note and let's add to the angle another attribute called the length and what do we have here we have a spiral a very faint spiral but we have a spiral we also have to multiply this before the addition so that it becomes stronger so do that there is nothing easier than just adding math notes and multiply the length at tribute with a float value of for example six right and this is very well done i'm gonna apply the scale for just in case when i could have some problems afterwards but here is our candy and it seems to be working pretty nicely but the problem is that we have also displacement down here basically we have to multiply the displacement attribute which is the angle attribute because this is used for the displacement we have to multiply it with a number that has the value of a 0 down here and that is going progressively up and reaching some kind of a positive value up here so that we have displacement up here but we have nothing down here sounds simple how do we do that well we have our z attribute as you see here the position has been separated into xyz we use x and y for the angle calculation but we don't use the z in any ways the z is sad let's use the z because this has the value of zero down here and the positive value as it goes upwards right so let's multiply our angle attribute let's multiply apply multiply our angle attribute with the z attribute and nothing has changed maybe a little bit let me check yes something has changed and the problem here is that you know it has this little yellow dot here this is the center point of the mesh and the z uh like the z attribute is being calculated from this point so we don't have this kind of range there we actually have zero in the middle and then we have increasing values upwards and decreasing values downwards so right now we only have like some kind of positive displacement up here and some kind of a negative displacement down here and nothing is working as we intend to so let's delete all of that and what we have to do is to move the center point basically or the shift is the attribute but i think it's easier to move the center point so go here and select affect only origins and now what we can do is to shift s cursor to world origin and shift as selection to cursor so now the origin is exactly like i mean this very precise location we can uncheck uh the origins here and now we have displacement only on the z axis like only on the top right very simple now the problem is for example if you want to have a little bit taller candy then if you move those up you see it's gonna have more and more displacement over time and this isn't very good at least i think so so to fix that we have to clamp the z attribute so that it is only between zero and one so we have no displacement up until full displacement but nothing more so for that we have attribute color ramp so let's um put it before we multiply because if we would clamp this afterwards this wouldn't have any effect at all so let's uh take the z attribute and let's result in also the z attribute now this is clamped so if i move this thing upwards it's gonna rotate but it isn't gonna displace anymore so this is pretty much fixed and also what i'm gonna do is to select the faces down here and make them bigger a bit make them a bit bigger because um using the linear uh what is it called uh proportional editing right so linear proportional editing and i'm gonna scale it to make it a bit bigger something like that let's say looks pretty nice i'd say so this is basically the candy i mean you can add some control snow so let's go here let's add controls for the first thing here which is gonna change let me see what it's gonna change ah the number of those uh what are these called actually a number of lines number of uh segments something like that so let's just call this the number right so we have a control for the number and there is a horrible not a horrible problem actually it's just a little problem we have to fix you know it has this kind of a seams right as you know the seams only appear when the number isn't a full number so for example if you have 5 we don't have any of those seams if you have 5.2 we have those seams so we have to have some kind of a math operation between here that basically removes those point twos point threes point sevens whatever after the whole number so for that we have a truncate uh separation called truncate here you see the integer part of a removing fractional tickets so let's put it here it's going to convert all those numbers into whole numbers which is very useful at least i think so so we have a control for the count and we also have the control for this thing here which is doing what it's eyes adding the rotation right the curvature so the swirliness is in its place and doing something like that so the candy is ready now we only need the shader so for this shader let's go to the shading workspace and let's see what we have here we have exactly nothing let's add the principle bsdf shader principle bsdf the shader is actually pretty easy i don't know like yeah it's it's gonna be easy but maybe you learn something from here i do have something that could be interesting so texture coordinates uh i should explain what i'm doing here actually as you remember my candy had dark chocolate on the top for the spiral and also it had white chocolate down here so to do that we have to have a mask for the lower places of the candy and the higher places of the candy for the high ground and the low ground so let's use a separate xyz separate the object coordinates into x y and z and the z is gonna be the most useful one because it gives us the gradient so now if you want to add some contrast what we can do is to use a power node so let's use the power node which is basically giving us uh contrast and i'm gonna make an explanatory video on the power soon maybe in the next let's say two weeks i'm sure this will come out anyways we can add some more contrast like that and this is the way we can do that and now if you want to control this further we can use a color ramp and do something like that this seems to be a nice thing so let's use those as the base color let's check how it looks and the first problem is that we have this kind of an ugly thing in the middle here and we can fix that by using a modifier i actually have never used before i believe so this is the smooth modifier so you just add a factor that seems to be working nicely i mean something like 0.5 is apparently good and you add some repetitions like that like 20 repetitions and this is working pretty nicely or 10 repetitions works well so this is the thing fixed and now let's go to the material preview and the dark areas are going to be white chocolate so actually i'm going to add some more yeah dark areas are gonna be white chocolate so something like that and something a little bit yellowish and something precious no it isn't white chocolate definitely anyways i'm gonna make the dark chocolate first something this looks like this looks like not definitely chocolate and i think this is chocolate fair enough so this is basically the candy as you see the white chocolate isn't fully white and also has a little bit of a yellow yellowish things here so this is basically the candy and also the specularity the specularity basically is how reflective this mesh is so chocolate isn't reflective like that it also isn't like that so it's for about point i'd say 0.3 or something like that at least i found this the most chocolatey let it be like that and roughness this is quite melt molten but we can use something different here as well so let's say something around that seems to be working pretty nicely so the chocolate looks like that also some subsurface scattering because you know chocolate has some light passing through it and don't add too much of that because this is just gonna look very cheap like the chocolate is gonna be like greasy or something like that so this is the chocolate substitute scattering now as you remember my candy also had this kind of sprinkles i'm gonna add them using a procedural noise so let's add a noise texture bump noise texture and let's add a color ramp i think some things are just not worth explaining i mean you can understand them after i made them so for example this is the case with the noise so if i increase this constantly you see i have some things appearing on my candy now first of course you see they are very squeezed on the z-axis so this is the problem with mapping so let's use object coordinates for the nice texture now they are better but there are still not like some dust or some powder on the candy so let's add more detail for example eight and let's add some more roughness like that oh that's some kind of a powder already so let's increase this to around here and this seems to be like a powder on the candy now how do we add some powder only down here and not up there well for that we have to use our z coordinates because those give us like the possibility to differentiate between the higher and lower parts of the mesh so let's use the z coordinates and actually i'm gonna add a different one and you can see in a minute why so i'm gonna add the z coordinates here and right now we have a dark dark like area here and the white area here and this means that we basically have less sprinkles down here and more sprinkles or this powder up there and this isn't what we want to do so we need to invert this and if you want to invert this well you can just use a subtract note and subtract the thing from a value for example one so why does this work well it works because you see down here we subtract nothing and up here we subtract a lot so if you subtract a lot from the number of one we get a zero up here and if you subtract nothing from the number of one we get the number one down here so this is how it works so this is inverted and now i'm gonna multiply it with the color ramp and the order is really important here because why is it important right now when i have done it the right way you see basically the sprinkles you have a lot of like this powder here and as it goes upwards we have less and less of powder but they all have the same brightness uh i mean they're not just fainting away if you would do this in the different directions or in a different order so we would do something like that then we would just have sprinkles the same amount all over the candy but they're just fading away and this isn't realistic at all i mean what kind of a powder has opacity settings like none of them so we can just remove this multiply here and put it before again so this is the setup here i'm gonna make this a little bit more visible this is the thing here and now we have a problem where we have really like a really sharp line where we have a lot of those powders this powder and up here we have nothing i want this to be a little bit more gradual so what i can do is now to add a mapping node before this separate xyz and scale it on the z-axis like that like let's put 0.15 here and now let's uh i do something like that with color ramp you can also change this with the subtraction node the right amount of powder on the candy maybe 0.2 works better actually yes so this is the reason why i did separate a separate separate xyz because if i would have used the mapping for this one it would have messed up the chocolate colors so now when i preview this shader we only see chocolate because we haven't used this this powder thing here in literally anyways let's use a mix rgb and let's add it to our base color by using this asti mask and using another color down here for example green and now we have some green things down here i'm gonna switch them to red because this seems to be tasty you know so let's check how this looks and it looks like a vat maybe we need to add some more of those with the color ramp yeah this is nice right seems to be working pretty well you can also add some bump mapping you know if you want to be extremely realistic so let's add those mappings to the bump and now we have bump like that and this isn't very good because this is very strong so let's add a really weak bump here so for example 0.001 and let's maybe also make a bit weaker and let's see how it looks looks like that i think it looks a bit better maybe it's still a bit strong so let's i like point one for the bump or point to yes this seems to be working better anyways this is the candy and the other candies including the paper thing under them are gonna be on patreon because this video is already very long if you're interested in making those you can check it out and i hope you learned something useful from here yes see you next time
Info
Channel: Bad Normals
Views: 18,867
Rating: undefined out of 5
Keywords:
Id: O9qqWfxxoCM
Channel Id: undefined
Length: 34min 14sec (2054 seconds)
Published: Mon Jul 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.