Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "VFX/FresnelShading"
- {
- Properties
- {
- //Color of the sphere. Fadeout is an extra modifier for fade agressiveness.
- _Color ("Color", Color) = (1,1,1,1)
- _Fadeout ("Fadeout", Float) = 4
- }
- SubShader
- {
- //Enable transparency:
- Tags { "Queue"="Transparent" "RenderType"="Transparent" }
- ZWrite Off
- Blend SrcAlpha OneMinusSrcAlpha
- //Only one pass needed:
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- fixed4 _Color;
- half _Fadeout;
- //We need position and color by default.
- struct VertShaderOutput
- {
- float4 Position : SV_POSITION;
- fixed4 color : COLOR0;
- };
- VertShaderOutput vert (appdata_base v)
- {
- VertShaderOutput o;
- o.Position = mul (UNITY_MATRIX_MVP, v.vertex);
- //Here we calculate intensity of the color. Closer to the edge, more intensity:
- float intensity;
- float3 direction = normalize(WorldSpaceViewDir(v.vertex));
- intensity = 1 / dot(direction, v.normal);
- //Color by intensity
- o.color = (_Color * intensity);
- //Alpha is intensity itself, plus modified a bit by the fade.
- o.color.a = intensity / _Fadeout;
- return o;
- }
- fixed4 frag (VertShaderOutput input) : SV_Target
- {
- //Finally, return color modified by Color's Alpha (modified by script).
- return input.color * _Color.a;
- }
- ENDCG
- }
- }
- FallBack "Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement