Files
bansonic_beta_main/Assets/Shaders/BansonicSpriteLightCurtain.shader

133 lines
5.0 KiB
Plaintext

Shader "Bansonic/Sprite Light Curtain"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
[HideInInspector] _Color ("Tint", Color) = (1,1,1,1)
[HideInInspector] PixelSnap ("Pixel snap", Float) = 0
[HideInInspector] _RendererColor ("RendererColor", Color) = (1,1,1,1)
[HideInInspector] _AlphaTex ("External Alpha", 2D) = "white" {}
[HideInInspector] _EnableExternalAlpha ("Enable External Alpha", Float) = 0
[HDR]_GlowColor ("Glow Color", Color) = (0.55,0.85,1,1)
_Opacity ("Opacity", Range(0, 1)) = 1
_EmissionIntensity ("Emission Intensity", Range(0, 12)) = 3.5
_EdgeSoftness ("Edge Softness", Range(0.001, 1)) = 0.18
_RiseSpeed ("Rise Speed", Range(0, 6)) = 0.8
_BandWidth ("Moving Band Width", Range(0.01, 0.5)) = 0.12
_BandIntensity ("Moving Band Intensity", Range(0, 6)) = 1.5
_ScanDirection ("Scan Direction", Range(-1, 1)) = 1
_CurtainAlpha ("Curtain Alpha", Range(0, 2)) = 0.9
_EdgeFeather ("Edge Feather", Range(0.001, 0.5)) = 0.08
_BandFeather ("Band Feather", Range(0.001, 0.5)) = 0.12
}
SubShader
{
Tags
{
"Queue" = "Transparent"
"RenderType" = "Transparent"
"RenderPipeline" = "UniversalPipeline"
"CanUseSpriteAtlas" = "True"
}
Cull Off
ZWrite Off
Blend One OneMinusSrcAlpha
Pass
{
Tags { "LightMode" = "Universal2D" }
HLSLPROGRAM
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/Core2D.hlsl"
#pragma vertex SpriteVertex
#pragma fragment SpriteFragment
#pragma target 2.0
#pragma multi_compile_instancing
#pragma multi_compile _ SKINNED_SPRITE
struct Attributes
{
float3 positionOS : POSITION;
float4 color : COLOR;
float2 uv : TEXCOORD0;
UNITY_SKINNED_VERTEX_INPUTS
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 positionCS : SV_POSITION;
half4 color : COLOR;
float2 uv : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
CBUFFER_START(UnityPerMaterial)
half4 _Color;
half4 _GlowColor;
half _Opacity;
half _EmissionIntensity;
half _EdgeSoftness;
half _RiseSpeed;
half _BandWidth;
half _BandIntensity;
half _ScanDirection;
half _CurtainAlpha;
half _EdgeFeather;
half _BandFeather;
CBUFFER_END
Varyings SpriteVertex(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
UNITY_SKINNED_VERTEX_COMPUTE(input);
SetUpSpriteInstanceProperties();
input.positionOS = UnityFlipSprite(input.positionOS, unity_SpriteProps.xy);
output.positionCS = TransformObjectToHClip(input.positionOS);
output.uv = input.uv;
output.color = input.color * _Color * unity_SpriteColor;
return output;
}
half4 SpriteFragment(Varyings input) : SV_Target
{
half4 src = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv) * input.color;
half spriteMask = smoothstep(0.0h, max(1e-4h, _EdgeFeather), src.a);
half alpha = saturate(spriteMask * _Opacity);
float y = saturate(input.uv.y);
float scanAxis = lerp(1.0 - y, y, step(0.0, _ScanDirection));
float rise = frac(_Time.y * _RiseSpeed);
float bandDistance = abs(scanAxis - rise);
float front = 1.0 - smoothstep(0.0, max(1e-4, _BandFeather), bandDistance);
float trail = smoothstep(0.0, max(1e-4, _BandWidth), scanAxis - rise);
float oneWayFill = saturate(front * trail);
float movingBand = 1.0 - saturate(abs(scanAxis - rise) / max(1e-4, _BandWidth));
movingBand = smoothstep(0.0, 1.0, movingBand);
movingBand = pow(saturate(movingBand), 1.2) * _BandIntensity;
float curtain = saturate((oneWayFill + movingBand) * spriteMask);
half glowAlpha = saturate(curtain * alpha * _CurtainAlpha);
half3 emission = _GlowColor.rgb * curtain * _EmissionIntensity * alpha * _GlowColor.a;
half3 rgb = emission;
return half4(rgb, glowAlpha);
}
ENDHLSL
}
}
}