Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Custom/Standard_Single_Flash"
- {
- Properties
- {
- _Color ("Color", Color) = (1,1,1,1)
- _MainTex ("Albedo (RGB)", 2D) = "white" {}
- _Glossiness ("Smoothness", Range(0,1)) = 0.5
- _Metallic ("Metallic", Range(0,1)) = 0.0
- _FlashPos ("Flash Position",Color) =(0,0,0,0)
- _FlashColor("Flash Color",Color) = (0,0,0,1)
- _FlashStartTime("Flash Start", float) = 0
- _FlashEndTime("Flash End", float) = 0
- _FlashRange("Flash Range",float) = 10.0
- }
- SubShader
- {
- Tags { "RenderType"="Opaque" }
- LOD 200
- CGPROGRAM
- // Physically based Standard lighting model, and enable shadows on all light types
- #pragma surface surf Standard fullforwardshadows
- // Use shader model 3.0 target, to get nicer looking lighting
- #pragma target 3.0
- sampler2D _MainTex;
- struct Input
- {
- float2 uv_MainTex;
- float3 worldPos;
- float3 worldNormal;
- };
- half _Glossiness;
- half _Metallic;
- fixed4 _Color;
- fixed4 _FlashPos;
- fixed4 _FlashColor;
- fixed _FlashStartTime;
- fixed _FlashEndTime;
- fixed _FlashRange;
- // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
- // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
- // #pragma instancing_options assumeuniformscaling
- UNITY_INSTANCING_BUFFER_START(Props)
- // put more per-instance properties here
- UNITY_INSTANCING_BUFFER_END(Props)
- void surf (Input IN, inout SurfaceOutputStandard o)
- {
- //Animated intensity value controlled from script
- fixed flashIntensity = 1.0-clamp((_Time.y - _FlashStartTime)/(_FlashEndTime - _FlashStartTime),0.0,1.0);
- //_FlashPos coming from script as well
- fixed3 lightDir =_FlashPos.xyz - IN.worldPos;
- float dist = length(lightDir);
- //Fairly standard NDotL
- float nl = max(0, dot(IN.worldNormal,lightDir));
- //All the different attenuation formulas Ive played around with:
- //float atten = 1.0/dist * 0.5;
- //float inverseRange = _FlashRange;
- //float atten = 1.0-(dist / (1.0 / inverseRange));
- //float atten=1.0/(1.0+0.1*dist+0.01*dist*dist);
- //float att = clamp(1.0 - dist/_FlashRange, 0.0, 1.0);
- //att *= att;
- float att = 1.0 / (1.0 + 0 * dist + 1.0 * dist * dist);
- float3 flashTerm = nl* _FlashColor * flashIntensity * att;
- fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
- o.Albedo = c.rgb;
- o.Metallic = _Metallic;
- o.Smoothness = _Glossiness;
- o.Alpha = c.a;
- o.Emission = flashTerm;
- }
- ENDCG
- }
- FallBack "Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement