Files

121 lines
3.8 KiB
Plaintext

Shader "AibisDream/DreamSeaMemory"
{
Properties
{
[PerRendererData] _MainTex ("Poster Texture", 2D) = "white" {}
_VideoTex ("Video Texture", 2D) = "black" {}
_UseVideo ("Use Prepared Video", Range(0, 1)) = 0
_Color ("Tint", Color) = (1,1,1,1)
_PixelGrid ("Virtual Pixel Grid", Vector) = (240,426,0,0)
_Contrast ("Contrast", Range(0.5, 2)) = 1
_Levels ("Luminance Levels", Range(2, 16)) = 10
_DitherStrength ("Dither Strength", Range(0, 0.1)) = 0.002
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Cull Off
Lighting Off
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
sampler2D _VideoTex;
fixed4 _Color;
float _UseVideo;
float4 _PixelGrid;
float _Contrast;
float _Levels;
float _DitherStrength;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.color = v.color * _Color;
return o;
}
float Bayer4x4(float2 pixel)
{
int x = ((int)pixel.x) & 3;
int y = ((int)pixel.y) & 3;
int index = x + y * 4;
if (index == 0) return 0.0 / 16.0;
if (index == 1) return 8.0 / 16.0;
if (index == 2) return 2.0 / 16.0;
if (index == 3) return 10.0 / 16.0;
if (index == 4) return 12.0 / 16.0;
if (index == 5) return 4.0 / 16.0;
if (index == 6) return 14.0 / 16.0;
if (index == 7) return 6.0 / 16.0;
if (index == 8) return 3.0 / 16.0;
if (index == 9) return 11.0 / 16.0;
if (index == 10) return 1.0 / 16.0;
if (index == 11) return 9.0 / 16.0;
if (index == 12) return 15.0 / 16.0;
if (index == 13) return 7.0 / 16.0;
if (index == 14) return 13.0 / 16.0;
return 5.0 / 16.0;
}
fixed4 frag(v2f i) : SV_Target
{
float2 grid = max(_PixelGrid.xy, float2(1.0, 1.0));
float2 pixel = floor(i.uv * grid);
float2 sampleUv = (pixel + 0.5) / grid;
fixed4 poster = tex2D(_MainTex, sampleUv);
fixed4 video = tex2D(_VideoTex, sampleUv);
float3 source = lerp(poster.rgb, video.rgb, saturate(_UseVideo));
float luminance = dot(source, float3(0.299, 0.587, 0.114));
luminance = saturate((luminance - 0.5) * _Contrast + 0.5);
luminance = saturate(luminance + (Bayer4x4(pixel) - 0.5) * _DitherStrength);
float levels = max(2.0, floor(_Levels + 0.5));
luminance = floor(luminance * (levels - 1.0) + 0.5) / (levels - 1.0);
return fixed4(luminance.xxx * i.color.rgb, poster.a * i.color.a);
}
ENDCG
}
}
Fallback "Sprites/Default"
}