Advertisement
Guest User

Untitled

a guest
Mar 14th, 2016
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. Shader "VFX/FresnelShading"
  2. {
  3.     Properties
  4.     {
  5.     //Color of the sphere. Fadeout is an extra modifier for fade agressiveness.
  6.         _Color ("Color", Color) = (1,1,1,1)
  7.         _Fadeout ("Fadeout", Float) = 4
  8.     }
  9.     SubShader
  10.     {
  11.     //Enable transparency:
  12.         Tags { "Queue"="Transparent" "RenderType"="Transparent" }
  13.         ZWrite Off
  14.         Blend SrcAlpha OneMinusSrcAlpha
  15.        
  16.     //Only one pass needed:
  17.         Pass
  18.         {
  19.             CGPROGRAM
  20.            
  21.             #pragma vertex vert
  22.             #pragma fragment frag
  23.             #include "UnityCG.cginc"
  24.            
  25.             fixed4 _Color;
  26.             half _Fadeout;
  27.            
  28.             //We need position and color by default.
  29.             struct VertShaderOutput
  30.             {
  31.                 float4 Position : SV_POSITION;
  32.                 fixed4 color : COLOR0;
  33.             };
  34.            
  35.             VertShaderOutput vert (appdata_base v)
  36.             {
  37.                 VertShaderOutput o;
  38.                 o.Position = mul (UNITY_MATRIX_MVP, v.vertex);
  39.                
  40.                 //Here we calculate intensity of the color. Closer to the edge, more intensity:
  41.                 float intensity;
  42.                
  43.                 float3 direction = normalize(WorldSpaceViewDir(v.vertex));
  44.                 intensity = 1 / dot(direction, v.normal);
  45.                
  46.                 //Color by intensity
  47.                 o.color = (_Color * intensity);
  48.  
  49.                 //Alpha is intensity itself, plus modified a bit by the fade.
  50.                 o.color.a = intensity / _Fadeout;
  51.                 return o;
  52.                
  53.             }
  54.            
  55.             fixed4 frag (VertShaderOutput input) : SV_Target
  56.             {
  57.             //Finally, return color modified by Color's Alpha (modified by script).
  58.                 return input.color * _Color.a;
  59.             }
  60.            
  61.             ENDCG
  62.         }
  63.     }
  64.     FallBack "Diffuse"
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement