How to make a Parallax Shader (for stylized effects) in Blender

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody uh in today's video I'm going to show you how to make a parallax Shader inside of blender um as well as how to use that Parallax Shader to make some stylish looking uh like holographic round frame glasses as well as adding a little reflection effect I guess um using parallax so yeah let's start out by making our Parallax Shader which is going to be a normal based Parallax Shader most of the tutorials I've seen online show how to just do like a world Vector based uh Parallax effect which isn't what I was looking for when I figured this out because I wanted to you know work with Armature deformation or shape keys so this will work as long as the shape is the same it'll behave the same from any angle so yeah we'll start out by making a plane and by putting a new material on it and then we'll make a new image texture by the way I heavily encourage you to enable node Wrangler I assume most of you have already enabled that if you haven't look into it it's really good so um let's take a look at this so we've got a texture and now let's think about conceptually how Parallax should work I do have to note that the Parallax we're making here is a very rough approximation you wouldn't really want to use this for like PBR stuff it won't work that well with it um because it's not quite that accurate um but it'll work for stylized effects as you already saw those glasses looks pretty small so let's look at this real quick um if we think that this is our plane that we're trying to render uh and this is what we're trying to render inside of it uh we'll see that we actually want to when we look at it this is going to be a texture Distortion effect that we're essentially doing so what we'd be doing is if I add a mapping note here is we're using some kind of information to distort this texture scale or whatever stretch stretch this texture so it would look like it is further back than the actual plane that's being rendered on right and so if we just think about this if we just imagine this is our plane that we're rendering on if we look at it if we look at it from the top it's going to look basically the same a little bit smaller but we'll ignore that for now if I move the camera up and down you can see that the plane seems to move and stretch seems to move up and down um and if I rotate the other way same thing here it'll just move like that so what we're going to try and do is we're going to try and measure the angle between the Surface here the normal basically and the camera and to use that angle on the X and Y to move the texture back and forth to fake that sort of depth um so how do we do that well we can't just use the normals because the normals won't tell us anything relevant to the UVS because we're going to be doing UV Distortion so we need something that has to do with the UV and the normals and in this case there's something that blender calculates for us which is really useful which is called the UV tangent so you can just grab a tangent node and set it to UV this is actually something that is uh necessary for normal mapping which is why it's calculated for us um because neural mapping is also a UV based effect basically um that needs this to function but I'll just try and explain what this is we'll create a geometry node this will also give us some other information for later but in here we have our normal which you can see currently for this plane it's blue uh that makes sense because if we take a look at our Gizmo up here we can see that the positive X the positive Z direction is up like this and that is blue so you can see that's that works out if I rotate This Plane towards positive X you can see it turns red and if I wrote it rotate it to the Y Direction you can see it turns green so this is just a world Vector that is pointing uh like give me a minute this is our normal which is always going to be aligned to the face um there's always going to point upwards like that and what we want in this case is we want the direction X and Y relative to this normal um for the UVS so if we take a look at our UVS right now so this would be y I think if I could if I could do that yeah so I've got X and Y if I take a look at my UV map here we can see that the UV map seems to be a gradient and if we separate this out separate x y z there's a direction that this is heading in you can see in this case the gradient goes from here to here which is the X direction that I've already drawn in same thing for the Y it's just in that direction so what we want or what we would like to have in this case is this Vector but even if I rotate This Plane around it should still be aligned with the plane like this and yeah again this is what the UV tangent is you can see if I just reset this currently it's facing in positive X so it's red if I rotate this thing 90 degrees you can see it's now pointing in the y direction so this is what we want the only problem is that we still need our bi tangent which is the other part of this which in this case is not calculated for us but we can calculate using a vector math node using an operation called cross product cross product I won't go into detail on what it actually does but it essentially will if you give it two vectors it will find the right another Vector right angled to uh to the other two vectors basically so yeah so we can just plug the normal up into the top part and then our UV tangent into the bottom part and then we'll get the correct by tangent and we can just uh tuck that under here and you can see that's currently pointing in the y direction if I rotate it again it all works so this is the correct vector and now we have our vectors now uh we'll actually want to find out how similar those are to our camera Vector so blender gives this to us it's called the incoming Vector the incoming Vector is basically just if you look at this pixel right here and you draw a line in physical space from this pixel or like this surface point to the camera then it just gives you that direction um like as a unit Vector so you can see currently here that's blue uh actually it would be a little bit like in the negative X and Y because it's pointing towards that if you look at these um but you can see it's pointing upwards so that's just the camera vector by the way this is also useful for stuff like specular effects um for those that do dot product calculation but that's what we'll be doing now is we'll be using a vector math again we'll use a DOT product dot product in this case with unit vectors can basically be used to measure how similar two vectors are so that's what we're going to be doing essentially is we're just going to be comparing the UV tangent with the incoming vector and it's going to give us a positive and negative sort of thing so here if I if we look at this now you can see that this thing moves and the gradient the black part here is just negative so you can't see it but it does give us the offset and this is actually already our Parallax effect the only thing that we'll want to do now is we'll want to combine these two dot products into a vector themselves so this is going to be X and this is y because this is our UV tangent for X this is our UV tangent for y so this is X Y so there you go this is already our like offset for the UVS the only thing we'll do now to make this easier to use is first I'll add a small tidbit that technically isn't necessary but I just think it makes it look a little bit better is by adding a tangent node here that's basically just going to make the offset a bit larger at a steeper angle like this which just makes it so the plane doesn't like move slower when you rotate the camera more because it is a linear value that it's giving you so yeah anyway and then the next thing we'll want to add is a scale node which is basically going to be the strength of our Parallax the distance that we're doing which yes that can also be negative we'll take a look at that in just a second um so we'll add a UV map note here and then we'll subtract our offset from the UV map and that is already the finished node basically so we'll just plug this into our image texture from before um and then you'll see this already works I'll set this to clip and then you can see our Parallax effect works kind of um again this is a rough approximation this is not really that accurate but it works pretty well you can see it it seems to look it's pretty convincing and once again this does rotate I'll disable the notation notes Here it does work from any rotation we can rotate this around any way you want to and it'll work decently um so yeah there we go that's that's the Parallax effect uh the only thing that we'll do now to make this a nice finished node is go Control G and then we'll uh go press n in the end panel and we'll add an input in this case just a float which is going to be our distance I'll also rename the output Vector to UV Parallax UV there we go and then we'll just plug our distance into that scale node there we go and now you can see that if the distance is zero this is just a regular UV because there is no strength and then you can just play with the distance here which by the way that's what negative scale does it does make it look like the plane is in front of it which doesn't make that much sense always but there are use cases for this um in case you would like to do that so there we go that's our Parallax node uh we'll just rename that and then that's the first part done and then we will move on to making our glasses all right so for our glasses I'm just going to make start out with a circle make a face rotate at 90 degrees move it over and then we'll add a mirror modifier because we have two eyes and we'll move it out a bit and we'll duplicate this to make our frame so these are the the first object here this is our lenses uh uh and then the other here the other part here this is the frame so we'll go in here and then we'll add a skin modifier and go into edit mode let's scale this down and then we can add a subdivision surface modifier two levels just to make it look nice and smooth we'll enable smooth shading on this and um then we'll we'll delete only faces uh just because that might mess up some stuff and then I'll just make a nice little Bridge here for the nose enable clipping on our mirror modifier so we can have this in there that's a problem I'll look into later then we'll go Ctrl shift B to Bevel this make it nice and round merge by distance there you go and then we'll add the little parts that go over the ears here Ctrl shift B and there you go that's basically that is basically the frame of her glasses done a very simple um but yeah there we go so let's take a look at our lenses here um we'll create another new material if you are in the same blend file as before you can just go and grab the Parallax node by looking it up if you named it that I've got your Parallax node right there and then what we'll want to do in this case is we'll want to grab an image again so we can just start out on that so the first problem we'll have is that this won't do anything it's purple and that's because we haven't actually made any UVS for our mesh yet so we're going to UV editing go into Ortho view look at it from the front and press U project from view bounds and that's going to drape this out on for us perfectly the way we want it to be then we can go back into our shading Tab and in this case uh the back side of this won't work so we'll enable back face calling and make sure that the normals are in fact pointing towards us in this case they are um and then the next thing we'll do is we'll try and enable our Parallax and you'll see that um this side works but something here doesn't seem to be working correctly so the reason why that's happening is because the UVS on this are mirrored due to the way that tangents or the UV tangents are calculated um this is it's messed up basically by by the mirrored uh UVS so we're just going to go into our mirror modifier and we're going to enable mirroring for the u-access or the x-axis and then we'll have perfectly uh readable textures there basically and now if I enable distance on this it's going to work the way we'd expect it to so now what I'd like to do is I'd like to make some circles that we can put into our little glasses here you could easily do this with a bitmap texture or just like a PNG jpeg anything but in this case we're going to make it procedurally because I don't want to use another program so we're just going to start out by doing that also you guys probably will learn a bit about making some procedural stuff with math so here we go we'll start out with a gradient texture we'll plug our Parallax in there distance zero so it's just going to be UV and actually I'll make a plane using our lens material um SSR lens material this is our lens material there you go um rename your stuff there you go so uh we'll start out with the gradient texture and we'll set it to quadratic sphere and we'll see that we'll get this nice little circle but it's in the bottom left corner the reason that is happening is because the quadratic sphere is generated at zero zero zero zeros in the bottom left corner so we actually want to move it up here uh so we're just going to add a vector math node and subtract 0.5 from X and Y if we look at it now you'll see that 0 0 is right here and if I take a look at our gradient it's um it's correct now basically the circle is in the middle which is what we're looking for then the last thing I'll do is I will invert this inverting in this case actually we'll just do it with math inverting in this case is just going to be a 1 minus so if you think about it if you take 1 minus zero you'll get one and if you take um one minus one you'll get zero so what that does is it it inverts a a color so you'll see that what was one before so the middle of our Circle that was one is now zero it's black and the outside Rim which was Zero before is now one so this is an inversion basically and the reason we want that is because this is going to be basically our radius so this is radius zero this is radius one right and then anything in between otherwise it would be flipped so yeah and then the last thing we'll want to do is we'll want to add another math node and we'll want to use the compare function so we plug that in there and what compare is going to do for us so just conceptually or actually I'll just set up first so you can set the Epsilon to something like 0.1 whatever and then you've got your value here so you can see what this does it creates a nice little circle for us the way this works is that compare node will essentially take a look at your texture or at whatever value you have um and it'll be like for all of these values that are equal to 0.5 plus minus this Epsilon of 0.1 in this case um if they're equal to that with the Epsilon make them white if they aren't make them black so if we change this Epsilon you can see if we said if we set it to zero the only pixels that are going to turn white are ones that are exactly 0.5 which you can see there aren't that many if we increase that margin you can see that circle gets thicker so this is really useful in this case because we can just set as thickness for our ring and and the value that it's actually looking for is our radius which is what we were looking for before so there we go now we have a texture this is just on a regular plane but if we take a look at our glasses here you can see that a ring is perfectly on there um like it is it works out exactly the way we we'd expect um and now what we can do is we can turn this into a node um so we'll just go Ctrl G and then we'll just add two inputs float inputs one of them is going to be our radius the other one is going to be our thickness and then the input is going to be our UV um or you can just call it a vector and then the output is just going to be a value yep okay so we'll just plug the radius into our value here for the compare node and then the thickness into the Epsilon um maybe add reroute nodes just so this is a bit more easy to sort of look at there we go and there we go now we have our Circle node which will rename it there we go and we can set a thickness and we can set a radius for our Circle there we go and what we can do now is we can increase our distance on The Parallax and it's going to work out perfectly you can see it looks really nice and then the only thing we'll want to do now is we'll just duplicate this like four times I think it's good uh and then we'll just combine these all together using math again we'll use a maxim node in this case what it'll do is it'll basically um it'll pick the maximum value that you enter which basically means that if if something is black and something is white like one part is black one part is white it'll always pick the white part and the reason we're not just adding them together in this case is because I don't want them the values like in case the white Parts overlap I don't want those to turn into values like two or four because that's the values output by our compare node are zero and one and if you added them together with four different components you'd get a maximum value of four so yeah in this case it'll just be zero and one and we can just play with our distance now to get these nice little circles um yep and then this one there we go and now you can see we've got a really nice little tunnel effect for our glasses here and then last thing I'll do now that we have this together is I'll use a mix node uh rest in peace makes RGB set the mix note to color and plug that into our factor and then we can mix between two colors in this case one uh on one I'll take this really nice dark purpley color uh something like that I guess and then for our other color I'm gonna pick a very bright uh sort of purpley color you can set the value to something like five and then turn the saturation down just a little bit so it doesn't have full color and then we can enable Bloom to get these nice little to get a nice little glowing effect in this case so there we go we've got our holographic part done next I'll as a quick sort of uh intermission I'll just sort of make the gold Shader for uh for our frames so we'll just go into our viewport shading instead of using the hdris by blender uh we'll add a sunlight which will just rotate something like this I don't know um there we go and increase the brightness on these to some like I don't know three two um and then we can add a material to this so in this case I'll make a really lazy I guess uh tune specular Shader setup uh so we'll just add a specular bsdf then we'll set the base color to Black the specular color to white and that'll give us this really nice metallic um sort of glowy thing to work with um we'll set the roughness to something like 0.5 so we get a slightly more distributed sort of color range or like um value range really and then because I'm really lazy we're just going to add a Shader to RGB node here and then a color ramp which we're just gonna set the constant and then we can just add a few levels so this is going to be our first brightest level I'm just going to set this to I'm going to also make this really a really bright sort of gold shade here then our next color is going to be a sort of um gold of course there we go um so there you go maybe turn down the saturation a little bit and then for our shadow we'll just turn it into a sort of I'll color pick the actual gold itself first um and then we'll just make it a bit darker a bit more saturated and we'll push it over into a sort of red ish I guess sort of color tone so less saturation less brightness a bit more saturation there you go that's already really nice looking gold uh sort of color so there we go that's our gold Shader if you really want to you get an outline to this I'm not going to do that today um yeah okay so let's move on to our lenses and make the reflection effect um so we'll just grab a parallax node again and in this case we can abuse dot product once again to make a nice little diagonal line sort of or diagonal gradient to work with so we'll just get Vector math set the distance on your Parallax to zero for now um we'll grab a DOT product node preview that and then we can input a few values here so in this case I'm just going to go for something like 0.5 and then negative 0.25 so that's going to give us a nice little diagonal gradient um and what we can do now is we can use uh compare again to make nice little lines in there so we'll just grab our compare node and then we can change the Epsilon here and here we go so we've got one streak here already that can move if we set our distance on The Parallax to something else you can see that it moves it looks uh it definitely looks like it is behind something if you if you look closely enough you'll see that it's parallax but if you don't look close it'll just feel like it's a reflection that's moving over the over the glass um so yeah if we want to we can add as many of these as we want to so we can daisy chain these together in this case I'm only going to be doing two because I really don't think you need way more than that so you can just put a second one there and make one of them a little thicker there we go so this is what this would already work I think this would already look pretty great uh in this case I'm going to go a little bit Haywire though and make it look really nice and dynamic by making these uh little reflection streaks thicker towards the rim of the glasses um so the way that we're going to do that is by grabbing a UV map again and we're gonna try and get our gradient sphere on this again so we're going to get a gradient node uh quadratic sphere and then we'll grab a vector math and we'll go subtract 0.5 so this is the same thing as before we're just making a sphere and in this case we're going to do the same thing where we invert this or go minus one I'll use a math node it really doesn't matter but the reason I don't really like using the um the invert node is because it's a color node so it's basically turning your black and white into a color and then you're turning it back into a black and white thing so just use one minus um I mean it really doesn't matter but yeah no so here we go uh now we have black in the middle white on the outside and we can add another node which is going to be a power so uh if you uh no math uh you'll know that if we power numbers between 0 and 1 they'll actually get smaller and we'll get this really nice distribution where they're super low values that increase like exponentially in a certain sense uh here so yeah so we'll set just set this exponent to something like nine I think and then we can use this as our Epsilon on these little Reflections and you can see that that already looks really nice um so you can see that's already really sort of stylized and interesting looking the only thing we'd like to do in this case is actually make it so that the middle here is a little thicker so the way the way we can do that is by using a map range which is uh gonna remap the values so basically as you can turn a zero into 0.1 and there we go so now whatever was Zero before is like 0.2 now so now I've got a really nice little effect here what we can also do is we can blow out the edge of the glasses like that uh which I think looks well uh and then we can just do the same thing add another map range node or in this case actually I'm going to turn all of this into one node that we can just reuse so we'll just go Ctrl G and then I'll just add a uh this input value what is that that is our gradient input then we'll have a Min thickness and we'll have a Max thickness and then we'll just plug those into our Min and our Max in the map range and then we'll also want a position which is going to be where the the little light beam or low reflection is going to be positioned which is here which is our value here in the compare node so there we go that is a really uh really goofy looking node not gonna lie and then actually the one last thing I'd like to do is I would like to be able to control the exponent here so plug that into our exponent here and there we go so now we are exponent one position doesn't matter so we'll get Max thickness here which is going to be something like that minimum thickness which are just going to make very thin and we'll use our exponent to make this nice and thin again there you go and then we can modify the position there we go so I'll just disable The Parallax real quick so we can see this more clearly and then we'll just duplicate this node group I guess I'll call this um reflection something there we go plug this in here and then combine these and there we go and now we have uh our low light beams and then we can adjust how thick they are the exponent here if we'd like to to make them really big so I guess I'll just keep this one at like seven there you go I think that looks pretty swell um so there we go um I'll just modify the position one last time and then we can enable our Parallax again and there we go um that looks really nice I think and now the only thing we need to do is to mix this into our actual shading setup from before so this um and so in this case we'll just add we'll duplicate our mix node and we'll plug this into our Factor and there you go that already sort of works it's the same color though as these little rings so what we're going to do in this case um is obviously you can just change the color of this if you'd like to just something more sort of purpley Bluey my bad in case you can hear that that's the phone ringing um and then what we'll also do is we'll add a map range node so we can make this sort of transparent looking so we'll just change this Max to something like point 0.25 I suppose and then we'll also add some more value here so we'll set it to something like seven and then reduce the saturation a little bit and there we go that is our glasses uh finished uh looking really nice and uh with a fairly fairly uh understandable I guess sort of Parallax effect I hope you guys can use this in some cool ways please tag me on like Twitter or something if you use it um and if you have any questions leave them in the comments and uh yeah I'm looking forward to seeing people use this bye
Info
Channel: Xetirano
Views: 33,992
Rating: undefined out of 5
Keywords:
Id: g3PR4uzbXjs
Channel Id: undefined
Length: 31min 59sec (1919 seconds)
Published: Mon Jul 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.