Advertisement
Guest User

Untitled

a guest
Jan 7th, 2020
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.02 KB | None | 0 0
  1. Shader "Custom/Standard_Single_Flash"
  2. {
  3.     Properties
  4.     {
  5.         _Color ("Color", Color) = (1,1,1,1)
  6.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
  7.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
  8.         _Metallic ("Metallic", Range(0,1)) = 0.0
  9.         _FlashPos ("Flash Position",Color) =(0,0,0,0)
  10.         _FlashColor("Flash Color",Color) = (0,0,0,1)
  11.         _FlashStartTime("Flash Start", float) = 0
  12.         _FlashEndTime("Flash End", float) = 0
  13.         _FlashRange("Flash Range",float) = 10.0
  14.     }
  15.     SubShader
  16.     {
  17.         Tags { "RenderType"="Opaque" }
  18.         LOD 200
  19.  
  20.         CGPROGRAM
  21.         // Physically based Standard lighting model, and enable shadows on all light types
  22.         #pragma surface surf Standard fullforwardshadows
  23.  
  24.         // Use shader model 3.0 target, to get nicer looking lighting
  25.         #pragma target 3.0
  26.  
  27.         sampler2D _MainTex;
  28.  
  29.         struct Input
  30.         {
  31.             float2 uv_MainTex;
  32.             float3 worldPos;
  33.             float3 worldNormal;
  34.         };
  35.  
  36.         half    _Glossiness;
  37.         half    _Metallic;
  38.         fixed4  _Color;
  39.         fixed4  _FlashPos;
  40.         fixed4  _FlashColor;
  41.         fixed   _FlashStartTime;
  42.         fixed   _FlashEndTime;
  43.         fixed   _FlashRange;
  44.  
  45.         // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
  46.         // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
  47.         // #pragma instancing_options assumeuniformscaling
  48.         UNITY_INSTANCING_BUFFER_START(Props)
  49.             // put more per-instance properties here
  50.         UNITY_INSTANCING_BUFFER_END(Props)
  51.  
  52.         void surf (Input IN, inout SurfaceOutputStandard o)
  53.         {
  54.             //Animated intensity value controlled from script
  55.             fixed flashIntensity =  1.0-clamp((_Time.y - _FlashStartTime)/(_FlashEndTime - _FlashStartTime),0.0,1.0);
  56.             //_FlashPos coming from script as well
  57.             fixed3 lightDir =_FlashPos.xyz - IN.worldPos;
  58.             float dist = length(lightDir);
  59.  
  60.             //Fairly standard NDotL
  61.            
  62.             float nl = max(0, dot(IN.worldNormal,lightDir));
  63.             //All the different attenuation formulas Ive played around with:
  64.             //float atten = 1.0/dist * 0.5;
  65.             //float inverseRange = _FlashRange;
  66.             //float atten = 1.0-(dist / (1.0 / inverseRange));
  67.             //float atten=1.0/(1.0+0.1*dist+0.01*dist*dist);
  68.             //float att = clamp(1.0 - dist/_FlashRange, 0.0, 1.0);
  69.             //att *= att;
  70.  
  71.             float att = 1.0 / (1.0 + 0 * dist + 1.0 * dist * dist);
  72.             float3 flashTerm = nl* _FlashColor * flashIntensity * att;
  73.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
  74.  
  75.             o.Albedo = c.rgb;
  76.             o.Metallic = _Metallic;
  77.             o.Smoothness = _Glossiness;
  78.             o.Alpha = c.a;
  79.             o.Emission = flashTerm;
  80.         }
  81.         ENDCG
  82.     }
  83.     FallBack "Diffuse"
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement