revival/game/Assets/Shaders/glitch.shader

148 lines
5.0 KiB
Plaintext
Raw Normal View History

2021-04-24 03:06:03 +02:00
// This shader draws a texture on the mesh.
Shader "KernelPanic/glitch"
{
// The _BaseMap variable is visible in the Material's Inspector, as a field
// called Base Map.
Properties
{
[HDR] _BaseColor("Base Color", Color) = (1,1,1,1)
[HDR] _NoiseColor("Noise Color", Color) = (1,1,1,1)
_BaseMap("Base Map", 2D) = "white"
_NoiseMap1("Noise 1", 2D) = "black"
_NoiseMap2("Noise 2", 2D) = "black"
_NoiseMap3("Noise 3", 2D) = "black"
_GlitchTex("Glitch Tex", 2D) = "black"
_Distortion("Distortion", Float) = 0
}
SubShader
{
Tags {
"RenderType" = "Opaque"
"Queue" = "Geometry"
"RenderPipeline" = "UniversalRenderPipeline"
}
Pass
{
// Stencil
// {
// Ref 1
// Pass replace
// Fail replace
// ZFail replace
// }
Cull Off
Zwrite On
// ZTest LEqual
Blend SrcAlpha OneMinusSrcAlpha
HLSLPROGRAM
// #pragma target 5.0
// #pragma only_renderers d3d11
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Assets/Shaders/random.cginc"
struct Attributes
{
float4 positionOS : POSITION;
// The uv variable contains the UV coordinate on the texture for the
// given vertex.
float2 uv : TEXCOORD0;
half3 normal : NORMAL;
};
struct Varyings
{
float4 positionHCS : SV_POSITION;
// The uv variable contains the UV coordinate on the texture for the
// given vertex.
float2 uv : TEXCOORD0;
half3 normal : NORMAL;
float4 screenPos : TEXCOORD1;
};
float _Distortion;
float4 _NoiseColor;
float4 _BaseColor;
// This macro declares _BaseMap as a Texture2D object.
TEXTURE2D(_BaseMap);
TEXTURE2D(_NoiseMap1);
TEXTURE2D(_NoiseMap2);
TEXTURE2D(_NoiseMap3);
TEXTURE2D(_GlitchTex);
TEXTURE2D(_CameraDepthTexture);
// This macro declares the sampler for the _BaseMap texture.
SAMPLER(sampler_BaseMap);
SAMPLER(sampler_NoiseMap1);
SAMPLER(sampler_NoiseMap2);
SAMPLER(sampler_NoiseMap3);
SAMPLER(sampler_GlitchTex);
SAMPLER(sampler_CameraDepthTexture);
CBUFFER_START(UnityPerMaterial)
// The following line declares the _BaseMap_ST variable, so that you
// can use the _BaseMap variable in the fragment shader. The _ST
// suffix is necessary for the tiling and offset function to work.
float4 _BaseMap_ST;
float4 _NoiseMap_ST;
CBUFFER_END
Varyings vert(Attributes IN)
{
Varyings OUT;
OUT.normal = TransformObjectToWorldDir(IN.normal);
// OUT.normal = IN.normal;
OUT.positionHCS = TransformObjectToHClip(IN.positionOS);
// The TRANSFORM_TEX macro performs the tiling and offset
// transformation.
OUT.uv = TRANSFORM_TEX(IN.uv, _BaseMap);
OUT.screenPos = ComputeScreenPos(OUT.positionHCS);
return OUT;
}
half4 frag(Varyings IN) : SV_Target
{
float2 suv = IN.screenPos.xy/IN.screenPos.w;
float d = SAMPLE_TEXTURE2D(_CameraDepthTexture, sampler_CameraDepthTexture, suv);
float4 p = float4(.42069, .6969, .1337, .8008);
float t = sin(_Time.y)*0.5+0.5;
float2 nuv = lerp(p.xz, p.yw, t);
float4 n = SAMPLE_TEXTURE2D(_NoiseMap1, sampler_NoiseMap1, suv + float2(_Time.y*69.6969, _Time.y*23.513));
n *= _NoiseColor;
// sample color
float4 c = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, nuv);
// c *= _BaseColor;
// sample blended glitch
float4 b = SAMPLE_TEXTURE2D(_GlitchTex, sampler_GlitchTex, suv);
c = lerp(c,(1-c),b);
c += n;
// cheeky bit of top shading
c += dot(float3(0,1,0), IN.normal) * d;
return c *= _BaseColor;
}
ENDHLSL
}
UsePass "Universal Render Pipeline/Lit/DepthOnly"
}
}