Advertisement
Guest User

AuraShader

a guest
Sep 26th, 2021
1,590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "FX/Aura Outline" {
  2.     Properties{
  3.        
  4.         _Color("Aura Inner Color", Color) = (0,0,1,1)
  5.         _ColorR("Rim Color", Color) = (0,1,1,1)
  6.         _Outline("Outline width", Range(.002, 0.8)) = .3
  7.         _OutlineZ("Outline Z", Range(-.06, 0)) = -.05
  8.         _NoiseTex("Noise Texture", 2D) = "white" { }
  9.         _Scale("Noise Scale", Range(0.0, 0.2)) = 0.01
  10.         _SpeedX("Speed X", Range(-10, 10)) = 0
  11.         _SpeedY("Speed Y", Range(-10, 10)) = 3.0
  12.         _Opacity("Noise Opacity", Range(0.01, 10.0)) = 10
  13.         _Brightness("Brightness", Range(0.5, 3)) = 2
  14.         _Edge("Rim Edge", Range(0.0, 1)) = 0.1
  15.         _RimPower("Rim Power", Range(0.01, 10.0)) = 1
  16.        
  17.     }
  18.    
  19.     HLSLINCLUDE
  20.     #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  21.     #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  22.    
  23.    
  24.     struct appdata {
  25.         float4 vertex : POSITION;
  26.         float3 normal : NORMAL;
  27.        
  28.     };
  29.    
  30.     struct v2f {
  31.         float4 pos : SV_POSITION;
  32.         float3 viewDir : TEXCOORD1;
  33.         float3 normalDir : TEXCOORD2;
  34.     };
  35.    
  36.    
  37.     float _Outline;
  38.     float _OutlineZ;
  39.     float _RimPower;
  40.    
  41.     v2f vert(appdata v) {
  42.         v2f o;
  43.         // clipspace
  44.         o.pos = TransformObjectToHClip(v.vertex.xyz);
  45.        
  46.         // scale of object
  47.         float3 scale = float3(
  48.         length(unity_ObjectToWorld._m00_m10_m20),
  49.         length(unity_ObjectToWorld._m01_m11_m21),
  50.         length(unity_ObjectToWorld._m02_m12_m22)
  51.         );
  52.         // normals for fresnel
  53.         o.normalDir = normalize(mul(float4(v.normal, 1), unity_WorldToObject).xyz); // normal direction
  54.         // view direction for fresnel
  55.         float3 worldPos =  mul(unity_ObjectToWorld, v.vertex).xyz;
  56.         o.viewDir = normalize(GetWorldSpaceViewDir(worldPos)); // view direction
  57.        
  58.         // rotate normals to eye space
  59.         float3 norm = normalize(mul((float3x3)UNITY_MATRIX_IT_MV, v.normal)) * scale;
  60.         float2 offset = (mul((float2x2)UNITY_MATRIX_P, norm.xy));
  61.         // add the offset
  62.         o.pos.xy += offset * _Outline;
  63.         // flatten
  64.         o.pos.z *= 0.01;
  65.         // push away from camera
  66.         o.pos.z -= (_OutlineZ);
  67.        
  68.         return o;
  69.     }
  70.     ENDHLSL
  71.    
  72.     SubShader{
  73.        
  74.         Pass{        
  75.             Tags { "LightMode"="UniversalForward" }
  76.             Blend SrcAlpha OneMinusSrcAlpha // Transparency Blending
  77.             ZWrite Off
  78.             Cull Back
  79.            
  80.             HLSLPROGRAM
  81.             #pragma vertex vert
  82.             #pragma fragment frag
  83.            
  84.             sampler2D _NoiseTex;
  85.             float _Scale, _Opacity, _Edge;
  86.             float4 _Color, _ColorR;
  87.             float _Brightness, _SpeedX, _SpeedY;
  88.            
  89.             float4 frag(v2f i) : SV_Target
  90.             {
  91.                 float2 uv = float2(i.pos.x* _Scale - (_Time.x * _SpeedX), i.pos.y * _Scale - (_Time.x * _SpeedY)); // float2 based on speed, position and, scale
  92.                 float text = tex2D(_NoiseTex, uv).r;
  93.                 float rim = pow(saturate(dot(i.viewDir, i.normalDir)), _RimPower).r; // calculate inverted rim based on view and normal
  94.                 rim -= text; // subtract noise texture
  95.                 float4 texturedAura = saturate(rim * _Opacity); // make a harder edge
  96.                 float4 extraRim = (saturate((_Edge + rim) * _Opacity) - texturedAura);// extra edge, subtracting the textured rim
  97.                 float4 result = ((_Color * texturedAura) + (_ColorR * extraRim));// combine both with colors
  98.                 return saturate(result) * _Brightness;
  99.             }
  100.             ENDHLSL
  101.         }
  102.     }
  103.    
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement