TIP: Ambient Occlusion in Geometry Nodes!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right so hi everyone a little while ago we did this video 14 more node and art tips for blender 3.1 and i shared in this video a method of using the edge angle node to basically get kind of curvature data for geometry notes so you'd be able to tell where to put like dirt build up effects in like kind of inner curved areas but it was a bit limited in the fact that you would only get angle data and it really wasn't enough especially not when compared to like the shader editor nodes when using ambient occlusion which is what i'm using for like a lot of my other procedural effects a lot of my metal stuff my grunge stuff etc so i always really wanted a way of getting ambient occlusion data inside of geometry notes and i know that a lot of other people have wanted that as well maybe not on youtube but like on twitter and other places in the community but recently i found out there is a way to do it but it's just not procedural so the way you do it just to kind of give it to you right away is if you take your object here let's um we'll give it a geometry node to modify now but we'll just make sure they're disabled in the viewport there because it's going to disrupt the baking process then if you go down to the object data properties and if you make a vertex color layer or group i tend to call them groups but it gets a bit confusing because it's a group of data right and so is the weight groups so when i say weight i'm referring to these vertex groups here when i say color i'm referring to the vertex colors even though the vertex color is just going to be a black and white result and the way it's actually going to be the colored result anyway it's confusing just follow along um so we make a vertex color layer and i'm going to name this one ambient occlusion okay now we're going to go up to the render properties i'm going to make sure that cycles is selected because we're going to do some baking then if we go down to the bake section here but the drop down yours may be higher up in the chain here it doesn't really matter you want to make sure the bake type is set to ambient occlusion there's all sorts of other things you could bake out here but we're going to go with the ao and then under output you want to set the target to vertex colors because you may or may not know that you don't just have to bake to texture maps in blender you can bake to vertex colors as well so if you do that then press bake there's going to be a loading bar at the bottom when it's done you'll see nothing happens but that's okay because we're in the wrong mode at the top if you then go down to the vertex paint mode which is going to be redundant eventually when the new paint mode comes in then you'll see that the object darkens and that's because we have the airbnb occlusion bake here although you may notice some artifacts but that's okay you can kind of just paint those out so the thing about the detail level of color layers like this is that they're based directly on the geometry density of the object so the data is attached to the different polygons so depending on how many polygons you have on your mesh that's basically going to dictate the resolution if you want to think about it that way of the vertex color layer we've created which means that for flat surfaces like this part of the cube here you need to have like a fair number of faces to get like some pretty good data anyway upon doing that bake you could stop here technically and just to use that as your ambient occlusion input but that's not where we're going to stop so i'm going to show you how to use this directly and then i'm going to show you how to turn it into a weight group as well so the way you'd actually use this as an input now is first of all if i make a i will do a quick setup here so distribute points on faces set point radius and a joint geometry let me just set these up so plugging that into the distribute and to the join geometry points there as well and we'll put the radius in between and set that down to something like 0.01 and then we're going to take the join geometry output and there we go and then let's just re-enable these in the modifier stack okay so this setup here is literally just distributing points around the mesh and we're going to use a lot of points because i'm going to restrict them to the ambient occlusion color layer that we've just created the way we bring this in is by taking this kind of small circle thing here and by connecting it to another value but you need to be careful here because if you connect it to the wrong value then you're going to get the wrong data type and that's going to cause a problem so i'm going to make a math node and i'm going to plug that circle into the value here so we now have a new float value and you can tell it's a float because if you hover over the icon it will say in brackets there likewise this green one here is a geometry value and if we made one for the selection over here you'd see this one is a boolean value but we want a nice float value now that we've made it if we go over to the modify stack properties and press this button here it's going to turn the simple into an attribute so if we do that we can now click on this and then select some data which is attached to the object so in this case we have our face corner airbnb occlusion color so basically the color layer that we've created for this object is of a type called face corner if we select that now that's basically going to pass that color data so like the brighter and the darker pixels that we've just baked down through this and into the math node and then if i set this to less than and then plug that into our selection then you'll start to see something happen on the mesh if i hold shift while scrubbing the threshold value you'll see the points are now attached to the darker areas of that color later and this is essentially an ambient occlusion mask so without needing to use any of that edge data stuff any ray casting or whatever we now know exactly where we can place our dirt buildup effects inside of a geometry nodes tree like i said the only problem is it's not procedural so it's pre-baked now you can re-bake that out like if you change your scene or if you change the position of the object you can rebake that and then it will update the color layer there and then that will re-feed in the new input data but here's the thing color layers are a little bit limited there are a lot of artistic procedures which use like weight groups and also it's a different and i think maybe more useful data type which they consider point for geometry nodes as well so i wanted to find a way to convert the vertex colors into weight groups so i did some research through the internet because i wasn't too sure what kind of procedure i need to do and i found some examples by valken varkan on github they have a repository called blender add-ons but they've got like a collection of different like use cases workflow tools etc written in python and down here two years ago weight of a vertex colored up pi so how to read through this found the vertex color to weight class that's exactly what we want and look in the execute function here and saw the general process for the loop so in the process of converting one like list of a data type to another list you need to cycle through each index have a look at the data they basically convert it in a line while also appending it to the other list i say appending or technically it's just placing it at like an appropriate index but anyway that doesn't really matter so much this is the code so i took a slice from this and then put it inside of a script here all it does is it gets the active object makes a vertex color group and then initiates a bake just as we already did then it makes a weight group and then begins that procedure of conversion so basically if i get rid of this now and if i hide our geometry note 3 again if we have a look at the object data properties down here while i have the object selected if i run the script by hovering over it and pressing alt and p or by going to text and then run script it's going to generate both of these masks for us so we now have the vertex color layer which is exactly what we saw before if i go to the vertex paint mode but now we also have an admin occlusion vertex group or a weight group i'm actually going to rename that input group at the end so the geometry node's attribute input doesn't get confused when they're both called the same thing so with that selected we can actually go to the weight paint mode and here we go you can see the obvious result so now that ambient occlusion data has been turned into a weight group and we can now paint over it and change the values so you still have like manual painting control and i should just point out that i have the brush set to subtract for this weight group because it's kind of doing like the inverse of what you might expect oh it depends on how you think about masking like are you painting on areas you do want stuff to appear or you don't this goes back to our inverse masking discussion in the paint mode video it's not really relevant for here so anyway yes we now have a weight group with the amp inclusion and if we turn our geometry notes tree back on we can select this and get pretty much the same effect although the range of the values will be slightly different so if i put this down to something low you can see that as i go back to the color mode there's more points and if i go back to the weight group there's fewer points that's the only real difference between them so i just thought that it would be important to find a way to get both of these in the same procedure so that you'd have the choice of what data type you'd want to use in your geometry notes tree so that's a general procedure and this file by the way is available on my patreon for second tier members and above if you can't be bothered to set this up for yourself but that's not where i stopped with my experimenting i felt like doing some development work recently so i went back to baijin my personal add-on for like generative modeling stuff by jen represent and um i thought it'd be fun to make a new kind of like grungy mode for like a potential content pack or maybe even ambient grunge or something like that i just wanted to see if it would work so i've got like a dirt and grunge content pack here and a physical grunge effect so this basically automates that entire process so if i cleared off all the geometry nodes and stuff but the object selected i can apply this effect and if we wait it will generate and here we go so if i go into the rendered view we now have muck and mud and dirt so it's using these ambient occlusion masks like i've just showed you how to create but if i put this less than value to like 0.8 for example it's going to come out even more so we now have this procedural physical control over these dirt and grunge build up effects based on an ambient occlusion mask yet inside of geometry nodes without using the edge angle node or raycasting or anything like that so i just thought that you might find this tip useful and hopefully it gives you something to work from as well but again it's not procedural that's the only downside and maybe they will add something like a regular ambient occlusion node like we have in the shader editor eventually i don't know how challenging that will be though for like real time control especially since this bake was dependent on cycles i haven't actually tried to see if the bake works with the eevee rendering engine active but from the looks of it i don't even think we can bake with that active so yeah that may be a problem because obviously geometry is like kind of unanimous across all the rendering engines but baking is not so i don't know i just thought i'd show you this workaround but why not test it on a more complex scene so calling back to that node tips video i've got the same statue here i believe this is the waters family grave one by katie wolfe a statue using so many of my videos because i just love the variety of the shaping on it like it's perfect for doing these kinds of effects especially with the cape here where we can get some like a really strong cavity effects on the inside there so for the sake of teaching this is a really good object but anyway here comes the cool part about being a tools developer is when stuff just works so i have the object selected here i'm going to go into the rendered view i specifically have this effect set up to use the weight version rather than the color version of the mask if i apply it to selected it might take a while to calculate because it's a complex object so there's a lot of vertices to bake onto but hopefully no crash please and it's done but you can see the overlay is quite complex let's get rid of that so here we go we've just now generated a dirt layer based on the ambient occlusion data of this object and it's all completely physical so we can look around and see how this has been generated around the shape of the object and again because there's like a strong proximity effect going on where that cape is coming down it's all very covered under there under the arm that side of the body and also this side of the face here on the right side because that's coming close to other geometry as well so you can see that the procedure works it can be automated and it can be used for cool effects and if we wanted we can take this further as well because this is all physical geometry if i wanted i could apply my ambient grunge node to the actual statue to give that more complex material and that shader data will react with what we've just generated so maybe i'll do that i already have my node here ready in the statue material so if i plug that color in to the principal bsdf and then let's turn down the cleanup values turn up the level turn that down a bit more so i'm just balancing these values to get it right and then maybe apply the normal data as well and i'm going to turn down the scale slightly as well to try and break up some of that obvious repetition and let's also finally turn the brightness of the statue up a bit as well just to make it a bit more obvious to see the pattern that's going on so now we have an example of a completely procedurally dirtified object now when i say procedural obviously the ambient occlusion was baked and the grass blades and like stone pieces they come from collections which are pre-made objects so i suppose the appropriate term isn't necessarily procedural even though parts of it are is probably more parametric then again there's a whole debate about where to use those terms technically everything's procedural even extruding a face as procedural but anyway this is a combination of geometry nodes and shader nodes making use of the same data sets and just to demonstrate this maybe i will make a cube and bring that up next to the statue here and you'll see that now where that cube is coming close to the statue if i turn on my overlays you're now getting this extra dirt being generated around the arm there so again this is a very procedural part of the shader so hopefully you have found this interesting to see how you can take these ambient occlusion data sets from different parts of blender and combine them so we have the geometry nodes version and the shader notes version so yeah now i wanted to make this video because i saw that there were some people on twitter that wanted to know how to do something like this because i think this is quite an in demand feature but as we said for the video there are just a few things to keep in mind so like the color layer and the weight layer they are two different data types so it depends what you want to go for also if you are trying to rebake a map so say if you weren't happy with the result that you got and you wanted to rebake the color version make sure your geometry nodes trees are disabled in the modifier stack so turn off all the visibilities if you don't disable them then you will get a black bake result which isn't very useful so yes hopefully you found this interesting um you might also notice some new features here so i've actually made a shortcut for doing that auto baking in biogen this is not available to the public yet you know i guess i've just started working on version 10 and again this content pack for like this physical grunge is not available i'm not actually sure whether i'll do that as a separate content pack or whatever i'll do as part of the ambient grunge node package we'll have to wait and see so for now it just belongs to me i've made all these tools and you can't have them but anyway hopefully you found this interesting if you made it this far then the emoji for this video is going to be a tree um i would have gone for like a mud or something but i don't think mud is an emoji and i don't think like regular grasses there are different plants but i know that there's trees anyway just put a tree in the comments so i can see who made it this far and they'll let me know who the real og viewers are of course like i said you can get access to the file i showed you earlier on that demonstration file on my patreon second tier members and above that will also help to support me with my work across like the entire field so the add-on development stuff the youtube videos discussion videos artwork like everything you can also check out my resources on my website cody's holder online store and you'll find like a bunch of free and paid stuff on there which you can use for your own artwork there's like a large variety of stuff on there now especially with that community material pack but there's so much more i want to make oh yeah and about the patreon if you sign up you can get your name put permanently on this piece of artwork it's an evolving piece of volvo called the hall of patrons and basically even if you stop supporting your name will still be on there so it's going to like carry on forward and i want to give big thanks to everyone that subscribed in like the last month thank you you have been a massive help and it also helps to justify like putting more experiments and files on the actual patreon page so thanks for watching everyone stay safe and i will see you next time
Info
Channel: Curtis Holt
Views: 12,644
Rating: undefined out of 5
Keywords: geometry, nodes, ambient, occlusion, procedural, vertex, bake, how to, group
Id: 41otDCLeVEs
Channel Id: undefined
Length: 14min 49sec (889 seconds)
Published: Tue May 31 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.