127 lines
4.0 KiB
Plaintext
127 lines
4.0 KiB
Plaintext
Shader "Hidden/BrokenGlassEffect"
|
|
{
|
|
Properties
|
|
{
|
|
_MainTex ("Main Texture", 2D) = "white" {}
|
|
_MainTex2 ("Glass Texture", 2D) = "white" {}
|
|
_Value ("Distortion Strength", Float) = 1.0
|
|
_Bullet_1 ("Bullet 1", Float) = 1.0
|
|
_Bullet_2 ("Bullet 2", Float) = 1.0
|
|
_Bullet_3 ("Bullet 3", Float) = 1.0
|
|
_Bullet_4 ("Bullet 4", Float) = 1.0
|
|
_Bullet_5 ("Bullet 5", Float) = 1.0
|
|
_Bullet_6 ("Bullet 6", Float) = 1.0
|
|
_Bullet_7 ("Bullet 7", Float) = 1.0
|
|
_Bullet_8 ("Bullet 8", Float) = 1.0
|
|
_Bullet_9 ("Bullet 9", Float) = 1.0
|
|
_Bullet_10 ("Bullet 10", Float) = 1.0
|
|
_Bullet_11 ("Bullet 11", Float) = 1.0
|
|
_Bullet_12 ("Bullet 12", Float) = 1.0
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags { "RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline" }
|
|
LOD 100
|
|
|
|
Pass
|
|
{
|
|
Name "BrokenGlassEffect"
|
|
ZTest Always Cull Off ZWrite Off
|
|
|
|
HLSLPROGRAM
|
|
#pragma vertex Vert
|
|
#pragma fragment Frag
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
|
|
struct Attributes
|
|
{
|
|
float4 positionOS : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 positionHCS : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
sampler2D _MainTex;
|
|
sampler2D _MainTex2;
|
|
float4 _MainTex_TexelSize;
|
|
|
|
float _Value;
|
|
float _Bullet_1;
|
|
float _Bullet_2;
|
|
float _Bullet_3;
|
|
float _Bullet_4;
|
|
float _Bullet_5;
|
|
float _Bullet_6;
|
|
float _Bullet_7;
|
|
float _Bullet_8;
|
|
float _Bullet_9;
|
|
float _Bullet_10;
|
|
float _Bullet_11;
|
|
float _Bullet_12;
|
|
|
|
Varyings Vert(Attributes input)
|
|
{
|
|
Varyings output;
|
|
output.positionHCS = TransformObjectToHClip(input.positionOS.xyz);
|
|
output.uv = input.uv;
|
|
return output;
|
|
}
|
|
|
|
half4 Frag(Varyings i) : SV_Target
|
|
{
|
|
float2 uv = i.uv;
|
|
float2 uv2 = uv;
|
|
|
|
#if UNITY_UV_STARTS_AT_TOP
|
|
if (_MainTex_TexelSize.y < 0)
|
|
uv.y = 1-uv.y;
|
|
#endif
|
|
|
|
uv /= 2;
|
|
float col = 0;
|
|
|
|
// Red channel sampling
|
|
col = (tex2D(_MainTex2, uv).rgb * _Bullet_1).r;
|
|
uv += float2(0.5, 0);
|
|
col += (tex2D(_MainTex2, uv).rgb * _Bullet_2).r;
|
|
uv += float2(0, 0.5);
|
|
col += (tex2D(_MainTex2, uv).rgb * _Bullet_3).r;
|
|
uv -= float2(0.5, 0.0);
|
|
col += (tex2D(_MainTex2, uv).rgb * _Bullet_4).r;
|
|
|
|
// Green channel sampling
|
|
col += (tex2D(_MainTex2, uv).rgb * _Bullet_5).g;
|
|
uv += float2(0.5, 0);
|
|
col += (tex2D(_MainTex2, uv).rgb * _Bullet_6).g;
|
|
uv += float2(0, 0.5);
|
|
col += (tex2D(_MainTex2, uv).rgb * _Bullet_7).g;
|
|
uv -= float2(0.5, 0.0);
|
|
col += (tex2D(_MainTex2, uv).rgb * _Bullet_8).g;
|
|
|
|
// Blue channel sampling
|
|
col += (tex2D(_MainTex2, uv).rgb * _Bullet_9).b;
|
|
uv += float2(0.5, 0);
|
|
col += (tex2D(_MainTex2, uv).rgb * _Bullet_10).b;
|
|
uv += float2(0, 0.5);
|
|
col += (tex2D(_MainTex2, uv).rgb * _Bullet_11).b;
|
|
uv -= float2(0.5, 0.0);
|
|
col += (tex2D(_MainTex2, uv).rgb * _Bullet_12).b;
|
|
|
|
uv2 += float2(col, col) / 4;
|
|
|
|
float3 col2 = tex2D(_MainTex, uv2).rgb;
|
|
float c = col;
|
|
col2 = col2 + float3(c, c, c);
|
|
|
|
return float4(col2, 1.0);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
}
|