It's been a while since I've had an opportunity to post a blog. But don't fret. I've been having some fun looking more into aesthetics rather than generic gameplay programming. So shaders, modelling and texturing. I must say that taking a step back from the text, and getting into more artsy stuff is awesome, it's refreshing.
I've been interested in shader for a while, but the game dev Joyce[MinionsArt] had some really cool stuff the put my interest over the edge. Therefore I tried to replicate some of the stuff She did using my own vertex shader.
It really opened my eyes, even the most simple aethetic effects might take more than one might think to recreate. I decided to try to make a kind of 'nature' shader. One that can replicate grass physics. Though for a first try, I don't think it's that bad.
The way I started out was by shimmying the gass sideways using a simple sine wave, using Cone Wars' dev blog as a reference. So now I had a bunch of synchronised grass dancers.
The next step was to desynchronise the grass and dampen the effect. The way I ended up doing this was by sampling a perlin noise texture using the objects world position, and used it's colour value to increase or decrease the rate at which the grass swayed. I also then created a grayscaled gradient which I sampled with the uv coordinates of the current vertex and used it to dampen how much the grass would sway the further from the base it was. This easily created a somewhat realistic looking wind effect on the grass.
Needless to say I felt pretty good after some optimisations and tweaks, but just to satisfy myself, added 1 to the sine function, which would make the windflow more uniform / look like the wind is coming from one single direction. This can probably be set as a parameter for customisation.
One of the bigger things that I wanted, and made this shader for was to trample down grass, or part grass as an object walked over it. To be honest, it's an effect which I find really cool if simple. While it's relatively janky, I think that the end result looks pretty good, and it wasn't too hard either.
The first thing I had to do was grab the world space coordinates of the object(s) I wanted to track. So I made a separate C# script with a reference to the player character and fed it's Vector3 position into the Shader parameters. From there I grabbed the difference between the grass' worldspace position and the player's world space coordinates, giving the direction that the grass would bend in and normalised that value. I then multiplied the direction by the maximum of 0 and the bend radius - the normalised direction. This results in a small band around the player that will be manipulated, as seen in the Gif above.
That's all. That's literally the extent of it. It's something that looks relatively decent and only manipulates the vertexes of the meshes, leaving a fragemnt shader free to do it's thing. This entire vertex function was about 10-12 additional line of code. I feels awesome, and it's all maths from here.
I had fun doing this, and I really want to get more into technical art stuff. So I might be a bit more active as I learn Blender and all of the jazz.