Gradient glow shader
Hey guys. This is driving me crazy, I'm searching for solution for days, but nothing seems to answer my problem. Here is the deal. I need to create aura around low poly planet. So I was looking for shaders to add outline of some kind, but this won't work since with flat shading, normals break the effect.
So basically I need to fake the effect by getting the shape of rendered object in solid color, apply large blur and then maybe in another pass place image of the standard render over it. I don't need any atmosphere-like scattering, just to make it look like the color from the planet bleeds into the space somehow.
I attach picture of what I'm looking for. Can someone maybe guide me on which way to look to achieve this? (Mind, I'm complete shader noob.)
i think you can archive this with the help of this: http://xroft666.blogspot.de/2015/07/glow-highlighting-in-unity.html
it's imho the best way for outlines/glow effects in unity
Answer by Namey5 · Apr 22, 2016 at 10:26 AM
You don't need to do that at all. All you need to do is have the same model at a larger size, and interpolate the alpha based on the fresnel shading technique. The following shader will do all of this, including the size:
Shader "Custom/Atmosphere" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_Size ("Atmosphere Size Multiplier", Range(0,16)) = 4
_Rim ("Fade Power", Range(0,8)) = 4
}
SubShader {
Tags { "RenderType"="Transparent" }
LOD 200
Cull Front
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Lambert fullforwardshadows alpha:fade
#pragma vertex vert
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
struct Input {
float3 viewDir;
};
half _Size;
half _Rim;
fixed4 _Color;
void vert (inout appdata_full v) {
v.vertex.xyz += v.vertex.xyz * _Size / 10;
v.normal *= -1;
}
void surf (Input IN, inout SurfaceOutput o) {
half rim = saturate (dot (normalize (IN.viewDir), normalize (o.Normal)));
// Albedo comes from a texture tinted by color
fixed4 c = _Color;
o.Emission = c.rgb;
o.Alpha = lerp (0, 1, pow (rim, _Rim));
}
ENDCG
}
FallBack "Diffuse"
}
If you want this to interact with lighting, you can use this:
Shader "Custom/Atmosphere" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_Size ("Atmosphere Size $$anonymous$$ultiplier", Range(0,16)) = 4
_Rim ("Fade Power", Range(0,8)) = 4
_Light ("Lighting Power", Range(0,10)) = 1.4
_Ambient ("Ambient Power", Range (0,6)) = 0.8
}
SubShader {
Tags { "RenderType"="Transparent" }
LOD 200
Cull Front
CGPROGRA$$anonymous$$
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf NegativeLambert fullforwardshadows alpha:fade
#pragma vertex vert
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
struct Input {
float3 viewDir;
};
half _Size;
half _Rim;
half _Light;
half _Ambient;
fixed4 _Color;
void vert (inout appdata_full v) {
v.vertex.xyz += v.vertex.xyz * _Size / 10;
v.normal *= -1;
}
half4 LightingNegativeLambert (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
s.Normal = normalize (s.Normal);
half diff = max (0, dot (-s.Normal, lightDir)) * _Light + _Ambient;
half4 c;
c.rgb = (s.Albedo * _LightColor0 * diff) * atten;
c.a = s.Alpha;
return c;
}
void surf (Input IN, inout SurfaceOutput o) {
half rim = saturate (dot (normalize (IN.viewDir), o.Normal));
// Albedo comes from a texture tinted by color
fixed4 c = _Color;
o.Albedo = c.rgb;
o.Alpha = lerp (0, 1, pow (rim, _Rim));
}
ENDCG
}
FallBack "Diffuse"
}
I know this question is 2y old but this shader is amazing! Too bad on Unity 2017.2 the mesh gets transparent if the directional light has any shadows, also for some reason my low poly models done on blender gets somewhat weird when I apply the material with this shader. It creates the atmosphere but doesnt fade the edges like the unity-made primitives.... any ideas on how to fix this?
Make sure the normals of the geometry you are using are correct. I had the same problem, and I realized it was because the low poly mesh I was using was exported with flat normals.
Your answer
Follow this Question
Related Questions
Unity 5 Custom Terrian Shader appears blurry. 1 Answer
Shader blurs only one shader 0 Answers
About blur shader 0 Answers
Why is shader hiding some components in front of it but not others? 0 Answers