Intro To Functions - 03 Random Ranges

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] in this video i want to take a look at accessing the random seed and random functions within substance designer to allow us to very easily create quick and seamless variations of information in our projects so here we can see i've got a value processor node and if we take a look it's just a float one of a value of one and so in order to access the random functionality all we have to do is go and search for random and we're going to select the first or top note here if we take a look at the tooltip it's going to tell us that really all this node is going to do is generate a floating value between 0 and our entry value so in this case it's going to be between 0 and 1. so if i right click and set this as output now we can see that our value is actually much closer to zero and it's going to just be a bunch of random digits so we can see that the function is actually working but how do we access this value and change it into a different random value right so if i come back out to my pixel graph here and i go and click on our value processor node in the base parameters of this node and many others you'll notice that there's this random seed slider and you've probably seen this before and so if i go ahead and bring this up we'll notice that the value is going to change right and we'll see that this value right here is 0.010 however notice that if i go up to a different value and then back down right it's still going to give us the same random value so that's something to be aware of is that as we're navigating the random seed slider while each new interval is going to be a different random number each interval on the slider is going to be mapped to a specific one so if i was to come back to this value of 4 on the random seed it's not going to generate some entirely new random value so how can we go ahead and use this random value that we're getting via the random seed to drive new and interesting information in our graph so i've got this uniform grayscale color down here and i've just created an input value of a float1 type so i'm going to quickly just override this with our input value and let's go and plug our value processor in so now visualizing our color and changing the random seed of our value processor we can see that the random values that we're going to get are actually going to drive the color randomly of this uniform grayscale node and finally there's one last thing that i want to show you about random seed before we really dive into things because there's really two distinct ways that we can access the random seed for use in a typical graph so if i go ahead and duplicate our value processor here right we'll notice that they're both going to be at the same value with a random seed of five however if i go ahead and start manipulating the random seed of this node here it's going to act locally so we can see that as i bring this down right to 2 it's going to change the value here but it did not change the value of our top value processor now that's going to be useful if you want to keep the randomness local but what if you want to go ahead and change all of the values randomly across any of the nodes that use and access this random function well just like we access exposed parameters in a graph we can do the same thing here so i'm going to double click in my graph and we'll notice that we have the random seed parameter or property in the graph properties as well so now when i go ahead and change this random seed it's actually going to change both of our nodes here and so what we can use this global random seed to do is really just transform any of the nodes within the graph that access this random function so that we can just generate new random values for everything in one go so that's something to be aware about whether you want to access things locally at a node level or you want to access them globally at a graph level now let's take a look at a more practical example by creating a function that's going to allow us to give random colors without actually changing the alpha channel so if i come into our value processor node again we're just going to have a simple float 1 value and now if we're thinking about our uniform color here right we can see that it's going to be four different float values so at the end of the day we're going to need to consolidate all of this information into a float4 value so how do i go about randomizing the three different channels right well we've seen how to randomize stuff all we have to do is go ahead and add a random node and i'm going to want the values to be between 0 and 1. so i'm going to use this float 1 value and i'm going to just duplicate the random three times so that we can randomize the three different r g and b channels so we'll go and plug in 1 to all of these so that the range is going to be between 0 and 1 randomly and i'm going to go ahead and just create another float node now we could just use the information here because ultimately we're going to just be using a float value of one but to try and keep things a little bit more straightforward i'm just going to use a second node so ultimately this is going to be the function for our random colors right we have a random red we have a random green and a random blue but our alpha is going to be locked at a value of one or opaque so now how do we go about reconstructing this into a vector four well i'm going to go and add a vector flow 2 node so that we can start to add together our red and our green i'll then go ahead and add a vector 3 so that we're now constructing a vector 3 node and we're going to add both our red and our green with our blue channel and then finally we're going to need a vector 4 so that we're going to take all three of those channels and add them or glue them back together with our alpha channel here so that now i can go ahead and right click and set this as output and if we come back to our graph we're going to be accessing a float4 with random values for each of the colored channels so let's quickly just create an input value here and make sure it's on flow four and let's just override this onto this property here and we'll plug this in so that now it looks as if we're going to get a random blue color so if i go ahead and change the random seed again of this local node and we can really bring this up to whatever values we want and it's just going to continuously add and change the random rgb values let's go ahead now and take a look at how we can use random functions to author different extents or limits for a range value ranges determine behavior between minimum and maximum values using simple math operations we can transform our working range multiply scales the spread of a range where add or subtract shift the position of a range and so what i mean by range is if we take a look at this transformation 2d in the offset properties here we can see that we have x and y and so if i go ahead and start to slide this around on the x right we're really interacting with a range of negative 0.5 all the way up to positive 0.5 and so what i want to do is create a function where once we go ahead and play around with the random seed it's going to create different range lengths or range extents so that my new range may be 0 to 0.31 or from 0 to negative 0.4 we'll go you know 4 5 4 4. really any kind of random range here so how we can go ahead and start to do that is if i come into my graph here i'm going to call this random offset range and i want it to be of a type float 1 and at a default value of 0. so the first thing i want to get is going to be our custom variable that we just created so let's go ahead and get float and select that variable now from that range on that slider that we're going to go from 0 to 1 i want to grab a random value and so that we can just essentially draw random values from the numbers that we're actually giving it so we can go ahead and create a random node there and now we're going to have to essentially construct a vector 2 because if we go back to our transformation 2d node right this is going to be a vector 2 and this is going to be the value that i want to override so very easily we can just create a vector flow 2 making sure to plug our random value into the x value here or the top value and i'm just going to create a float 1 and leaving it at a value of 0 because we're not going to want to access the y here so let's right click and set this as output come back to our functions here i'm quickly going to have to change our input value to be a float too and let's go and just override this so that now when i come into my parameters here we can see that i can bring this all the way up and start to play around with our random seed and say we can go right here right we can see that this is going to be our x value and as i bring this down i've essentially just remapped this entire range so that we're going from 0 all the way up to a value of 0.87 however something you might notice is that playing around with the random seed we're only going to get positive numbers right so what that means is that any time we want to get a random offset it's only going to be essentially pushing our square here to the left side so how do we go and actually expand this random range to actually include negative ranges as well so back here in my function graph we're going to have to do a little bit of editing between our random value and our final vector output so from our initial float that we're getting our custom variable let's go ahead and create a division node here and i'll just drag this down and let's create a float one as well and let's give this a value of two so essentially what we're doing is taking whatever input that we've created on our slider over here we're going to divide it in half and then we're going to subtract it from the random value that we're getting here so that now whenever we change the random seed value there's a 50 50 chance each time that the final output value is going to be either a positive or negative float 1 value so now when i come back to our graph here and we scroll all the way down to our parameters we can see that as i bring this up right we're still working in the positive direction but as i play around with it now we're going to have negative values so now i can move this towards the right side and it's going to depend on which random seed interval that you're going to be at so it's important to remember that random seed here is going to be an indicator for which direction we're going to be moving this range in as well as the limits or the extent of that range and this float value here is going to act much like a position random slider in a tile sampler node controlling the maximum variation limit for this range let's take a look at one final example where we're going to be able to use randomness to drive and alter different variations for ranges within our project so in this example i want to go ahead and develop a function that's going to allow me to once again play around with my random seed to drive the direction as well as the extents of a particular range and in this case it's going to be for a color so we can see here that i have this kind of like mid greenish blue color and so what i want to do is use the random seed to give me one a direction to move on this hue and two give me an actual final limit to know how far i can actually travel in each direction and then from there we just have a very simple slider that's going to allow me to move and alter our hue along that range that we've specified with the random function so i've gone ahead and just created these parameters here one for our color which is going to be a float three and one for the hue variation slider which is just a float one with a default value of 0. so i've gone into our value processor and the first thing that i want to do is actually get the color that we're giving this parameter here because we're going to need to use that as the basis of our range so i've got a get float 3 here and let's go and just select that property and now by default we're going to be working within rgb space but it's a little bit difficult to actually alter just the hue when working in the rgb color space so what we have to do is go ahead and just convert that to hue saturation and lightness so i'm going to start typing in rgb 2 and you can see that we can actually convert it to a couple different spaces here so let's go ahead and change this to hue saturation and lightness so that now any of that color information that we are getting from that parameter is now going to be operating within the hsl space within this function graph and now in order to access only the hue we need to go ahead and swizzle these values out so from our rgb node here let's go ahead and type in swizzle float 1 and this is going to be for our hue and i'm going to do another swizzle node but this one's going to be a flow 2 because this is going to be our saturation and lightness and so let's go ahead and just quickly change the x to be y and the y to be zed right so that these are actually getting the saturation lightness and this is going to get our hue and now i've gone ahead and just set up this little subsystem here because it's the exact same process we used in the previous example to go ahead and give our range the ability to access a negative range so now we want to go ahead and just make sure that with this get flow value we're going to go ahead and select our hue variation here and now with these two we need to go ahead and actually combine them onto our color values so i'm going to create an add node here and this part's going to be a little complex but ultimately what i want to do is i want to take our hue value and i want to add whatever value we're creating randomly to that hue value and that's how we're going to be able to actually define these ranges and actually change the hue value itself so now that we've done the alterations that we're going to need for our range and our hue value let's go ahead and reconstruct this back in to a vector float3 so we'll go ahead and select vector float3 making sure to plug our hue into the top so that it's going to be ordered properly and we can plug our saturation and lightness into the bottom here so that now we're going to go ahead and get a vector 3 if we go and just take a look at our processor node here but we're not done just yet because we're still working in hue saturation and lightness and i want to reconvert that back into rgb values so like we did with the rgb to hsl let's just start to type in hsl to rgb and we can go and use this node to convert everything back together and finally we're going to need to create a vector float4 as substance designer is just better suited to work with colors that have an alpha channel so we'll go ahead and create a float value that's going to be one and let's finally construct this all together with a vector float4 so now we can set this as output and if i come back into our graph here we're now going to have access to a completely randomized value range that we're going to be able to use to drive just random hue variations so let's plug this in to our uniform color again making sure it's at float4 and we can just override this so now if i come over to our parameters right i can go ahead and change the hue but now as i go and change the variation slider we can see that i'm altering the maximum variation limit again however this time it results in a deviation from our initial hue value so if i go ahead and move our random seed a couple down we can see that now we're actually moving the other direction and we're going to end our range kind of in this area over here and so with this hue variation it's going to just allow us to kind of sift through these values depending on the direction and the extent or limit that is going to be defined by our random seed in this video we've taken a look at incorporating the random function in random seed into our function graphs we've also taken a look at how randomness can be injected into various use cases to make random variations incredibly simple don't forget that you can also use random seeds locally on nodes or globally across all nodes for different effects
Info
Channel: Adobe Substance 3D
Views: 2,419
Rating: undefined out of 5
Keywords: materials, procedural, PBR, Physically based rendering, Scans, Photogrammetry, scanning, environment art, 3D support, 3D design, 3D painting, 3D texturing, realistic, hyper-realistic, texturing, 3D material
Id: lidkGjL7bh8
Channel Id: undefined
Length: 19min 10sec (1150 seconds)
Published: Fri May 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.