New Shiny Sparkly Shader

Hey all, 

I've made a similar version before but this one is a bit nicer, initially made for Harry Alisavakis' tech art challenge for a foil card effect.

Code linked at the bottom !

The Shader Graph version follows soon!

Fresnel and Gradient

We start with a classic Fresnel effect, using the Normals and the View Direction

half f = 1 - dot(o.Normal, IN.viewDir);

Then project a Gradient Texture over the fresnel

fixed4 fGradient = tex2D (_MainGradient,float2(f,f));

Blending Normals

For more interesting result, blend the normals with a noisy texture before the first Fresnel

float3 blNormal= BlendNormals(o.Normal, UnpackNormal(n));
half f = 1 - dot(blNormal, IN.viewDir);


Sparkles

We're going to do another fresnel, but this time we project a texture normally, and add it to the WorldNormals, this will give a better result for sparkles than the BlendNormals way.

float3 sparkles = tex2D(_Sparks, IN.uv_MainTex);
sparkles = (o.Normal * sparkles);

The Fresnel result

half sparkFres = dot(IN.viewDirsparkles);

Project another Gradient Texture over this fresnel 

fixed3 SparkGradient = tex2D(_SparksGradient,(float2( sparkFressparkFres)));

Cut off the result with a step of the sparkFresnel + a standard fresnel, the standard fresnel gets added otherwise we lose a bunch of color from the SparkGradient.

fixed cutoff = step(_CutoffSparks,saturate(Fres + sparkleFres );
SparkGradient *=  cutoff;

Fake Specular

Start with a dot product of the View Direction and the Light Direction added together

half d = dot(o.Normal, normalize(IN.lightDir + IN.viewDir));

Then Step through it for a nice hard edge

float specular = step(_SpecSize, d);

Masking

fixed4 mask = tex2D (_Mask, IN.uv_MainTex ) ;

Finally you can add an optional mask, so you can control where the Main Gradient, Sparkles, and Specular appear.

I've set it up so that the Red channel is Main Gradient, Green channel is Sparkles, and Blue channel is Specular

Then add in a main texture at the end

fixed4 mainTexture = tex2D (_MainTex, IN.uv_MainTex ) ;
Just add to you final color like
o.Albedo += mainTexture;

Gradient Editor in a Material   

Ever wanted to have that nice little gradient property in a material? Well, you can have that! Ronja wrote a neat editor script that lets you use them. 

Grab the script here : Github Link   

You just have to add [Gradient] Before the texture property like so :   

Thanks Ronja!


Shader Code: Pastebin Link 

Example, Lizard Mat Settings:


 

Get more from Minions Art

168
Unlock 168 exclusive posts
Be part of the community
Connect via private message

Minions Art

creating Game Art Tips and Astro Kat, a Catventure game!

Minions Art

creating Game Art Tips and Astro Kat, a Catventure game!

Recent Posts