Last active
April 26, 2021 10:02
-
-
Save antonkudin/06fd804068f7e9a00af010d41ac4c46d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// threshold for mask can be controlled using vertex color alpha (useful for spriteRenderers or particle systems) | |
// _MainTex: alpha of this texture is used as a mask | |
// _EmissionTex: usually rgb noise texture, adjust it's scaling if needed | |
// color remap and oscilation for each channel of emission can be modified in _EmStrobeBFALR, _EmStrobeBFALG, _EmStrobeBFALB | |
// Base: base amplitude of brightness oscilation | |
// Freq: frequency of oscilation | |
// Ampl: amplitude of oscilation | |
// L: how much _EmissionTex affects this color | |
Shader "StandardWMask" { | |
Properties { | |
_Color ("Color", Color) = (1,1,1,1) | |
[Header(Mask)] | |
_MaskSoft ("Smoothness", Range (0.001, 1)) = .1 | |
[Space] | |
_MaskBrightOffset ("Shadow Mask Offset", Range (-.5, .5)) = 0 | |
_MainTex ("Albedo (RGB)", 2D) = "white" {} | |
_AlphaClip ("Alpha clip", Float) = 0.01 | |
_SpecGlossMap("Specular", 2D) = "white" {} | |
_Specular ("Specular Mult", Range (0, 1)) = .5 | |
_Smoothness ("Glossiness Mult", Range (0, 1)) = .5 | |
[Normal][NoScaleOffset] _BumpMap ("Normal", 2D) = "bump" {} | |
_BumpScale ("BumpScale", Range (0, 4)) = 1 | |
[Space(20)] | |
_MaskEmissOffset ("Emis Mask Offset", Range (-.5, .5)) = 0 | |
[NoScaleOffset] _EmissionMap ("Emission Mask", 2D) = "white" {} | |
[Space(20)] | |
[Toggle] _QuantEmisPos ("Snap Emission?", Float) = 0 | |
[NoScaleOffset] _EmTxtrQuant ("Quantisize", Vector) = (1,1,0,0) | |
[NoScaleOffset] _ColorPhase ("ColorPhase", Float) = 0 | |
[Space(20)] | |
[Toggle] _UseColor ("Use Material Color?", Float) = 0 | |
[Toggle] _UseVertexColor ("Use Vertex?", Float) = 0 | |
[Space(20)] | |
_EmSpeed ("UV Speed (XY) UV Scale (ZW)", Vector) = (0,5,1,1) | |
_EmissionTex ("Emission FX", 2D) = "white" {} | |
[HDR]_EmissionColor ("Emission Color", Color) = (1,1,1,1) | |
[Header(Red remap)] | |
[HDR]_EmisRemapR ("Remap", Color) = (1,1,1,1) | |
_EmStrobeBFALR ("Oscilate [Base,Freq,Ampl,L]", Vector) = (.2,2,2,1) | |
[Header(Green remap)] | |
[HDR]_EmisRemapG ("Remap", Color) = (1,1,1,1) | |
_EmStrobeBFALG ("Oscilate [Base,Freq,Ampl,L]", Vector) = (8,120,1.7,1) | |
[Header(Blue remap)] | |
[HDR]_EmisRemapB ("Remap", Color) = (1,1,1,1) | |
_EmStrobeBFALB ("Oscilate [Base,Freq,Ampl,L]", Vector) = (2,.5,10,1) | |
} | |
SubShader { | |
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } | |
Blend SrcAlpha OneMinusSrcAlpha | |
Cull off | |
ZWrite Off | |
CGPROGRAM | |
#pragma surface surf StandardSpecular nofog keepalpha vertex:vert | |
#pragma target 3.0 | |
#pragma multi_compile_instancing | |
sampler2D _BumpMap; | |
sampler2D _MainTex; | |
sampler2D _SpecGlossMap; | |
sampler2D _EmissionMap; | |
sampler2D _EmissionTex; | |
half _MaskSoft, _MaskEmissOffset, _MaskBrightOffset; | |
half4 _EmissionTex_ST; | |
half4 _EmissionColor; | |
fixed4 _Color; | |
half _AlphaClip; | |
half _BumpScale, _ColorPhase; | |
half _Smoothness; | |
half _Specular; | |
fixed _QuantEmisPos; | |
float4 _EmSpeed; | |
float4 _EmTxtrSize, _EmTxtrQuant; | |
half4 _EmisRemapR, _EmisRemapG, _EmisRemapB; | |
float4 _EmStrobeBFALR, _EmStrobeBFALG, _EmStrobeBFALB; | |
struct Input { | |
float2 uv_MainTex; | |
float2 emisUV; | |
float2 emisUVOffset; | |
fixed4 color : COLOR; | |
fixed3 strobe; | |
}; | |
float quant(float q, float v){ | |
return floor(q/v)*v; | |
} | |
float2 quant(float2 q, float2 v){ | |
return floor(q/v)*v; | |
} | |
float TriangleWave( float x ) { return abs( frac(x+0.5)*2.0 - 1.0 ); } | |
float SmoothCurve( float x ) { return x * x *( 3.0 - 2.0 * x ); } | |
float SmoothTriangleWave( float x ) { return SmoothCurve( TriangleWave( x ) ); } | |
void vert (inout appdata_full v, out Input o) { | |
UNITY_INITIALIZE_OUTPUT(Input,o); | |
o.emisUV = v.texcoord * _EmissionTex_ST.xy; | |
o.emisUVOffset = _Time.xx * _EmSpeed.xy + _EmissionTex_ST.zw; | |
o.emisUVOffset = lerp( o.emisUVOffset, quant(o.emisUVOffset, 1/_EmTxtrQuant.xy), _QuantEmisPos); | |
o.emisUVOffset = frac( o.emisUVOffset ); | |
o.strobe = | |
fixed3( | |
saturate( _EmStrobeBFALR.r + SmoothTriangleWave( ((_Time.x*(1+v.color.r))+_ColorPhase)*_EmStrobeBFALR.g) * _EmStrobeBFALR.b), | |
saturate( _EmStrobeBFALG.r + SmoothTriangleWave( ((_Time.x*(1+v.color.g))+_ColorPhase)*_EmStrobeBFALG.g) * _EmStrobeBFALG.b), | |
saturate( _EmStrobeBFALB.r + SmoothTriangleWave( ((_Time.x*(1+v.color.b))+_ColorPhase)*_EmStrobeBFALB.g) * _EmStrobeBFALB.b) | |
); | |
} | |
void surf (Input IN, inout SurfaceOutputStandardSpecular o) { | |
fixed4 c = tex2D (_MainTex, IN.uv_MainTex); | |
half mm = IN.color.a+IN.color.a*_MaskSoft; | |
// lowers brightness for 'burned effect' | |
half bright = smoothstep(mm+_MaskBrightOffset, mm-_MaskSoft+_MaskBrightOffset, c.a); | |
o.Albedo = c*bright; | |
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP(_Color_arr, _Color); | |
o.Alpha = smoothstep(mm, mm-_MaskSoft, c.a); // mask itself | |
clip(c.a-_AlphaClip); | |
fixed4 spec = tex2D(_SpecGlossMap, IN.uv_MainTex); | |
o.Specular = spec.rgb * _Specular * bright; | |
o.Smoothness = spec.a * _Smoothness * bright; | |
o.Normal = UnpackScaleNormal(tex2D (_BumpMap, IN.uv_MainTex), _BumpScale); | |
half3 e_clr = tex2D(_EmissionMap, IN.uv_MainTex); | |
half3 e_ovr = tex2D(_EmissionTex, IN.emisUV + IN.emisUVOffset).rgb; | |
e_clr = IN.color.rgb * e_clr; | |
half3 osc = | |
_EmisRemapR * saturate(lerp(e_clr.r, e_ovr.r*e_clr.r, _EmStrobeBFALR.a)) * IN.strobe.r + | |
_EmisRemapG * saturate(lerp(e_clr.g, e_ovr.g*e_clr.g, _EmStrobeBFALG.a)) * IN.strobe.g + | |
_EmisRemapB * saturate(lerp(e_clr.b, e_ovr.b*e_clr.b, _EmStrobeBFALB.a)) * IN.strobe.b; | |
tint.rgb = osc*tint.rgb; | |
o.Emission = tint.rgb * _EmissionColor * TriangleWave( smoothstep(mm+_MaskEmissOffset, mm-_MaskSoft+_MaskEmissOffset, c.a) ); | |
} | |
ENDCG | |
} | |
FallBack "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment