It has been a while since I have done any type of tutorial or any technical related blog post, so I thought I would share the process of how I implemented a “cloak” effect on my character. Essentially in my game, I am adding a cloak skill and in order to visualize this to the player I want a sort of holographic semi-transparent cloak effect. Something magicy and Sci-Fi. So I jumped back into my shader coding.
If you need a quick refresh of the make up of shaders in Unity then here are a couple of previous posts (with horrendous typos that I should probably sort):
Cool, let’s do it.
First we start by creating a Surface Shader and then strip it back so it just performs diffuse lighting, a good starting point for all shader creation.
Firstly in our properties section we are going to add… well… a new property
Which will expose the following “_DotProduct” float value to the editor that we add in our CG Program.
We also want to add a _MainTex property value pair into our shader.
We also want to change the tags.
This will render the shader in the transparent rendering queue and will ignore projectors. If we want, as the player character is becoming invisible, we can also add the “ForceNoShadowCasting” tag that will mean the object does not cast shadows.
We also want to disable the expensive PBR in this shader and switch it out for Lambertion reflectance before telling the CG program this is a transparent shader and then finally disable the lighting. Wow that was a long sentence.
The last thing we want to do before we actually jump into our surface function is change what actually gets run into the shader. In this case we want the world normal and view direction as well as what is already there.
Cool, now we whack this code in the surface function.
And we get this effect:
On a sphere it looks pretty basic although it makes a cool atmosphere effect one, similar to the one I used in my seasonal globe:
What this shader is doing is actually showing the silhouette of the object. If I swap the circle out for something else and we move around it we can see the outline changes.
After I tweaked the values a bit and applied it to my asset store model, here is what I got:
The gif doesn’t do it as much justice as in-game, but I actually think this is quite cool and that shader is cheaper than the previous refraction shader I was using.
I also had a little experiment for fun with my enemy model by adding a wave to all the verts and made what I am calling the “Demontor” shader