Skip to content

Instantly share code, notes, and snippets.

@mtytheone
Created July 15, 2021 08:25
Show Gist options
  • Save mtytheone/bb4d95aa0dbf89f2513c3e3d2356c8d3 to your computer and use it in GitHub Desktop.
Save mtytheone/bb4d95aa0dbf89f2513c3e3d2356c8d3 to your computer and use it in GitHub Desktop.
CRTの勉強 その①
Shader "CRT_Shader"
{
Properties
{
//_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Cull Off ZWrite Off ZTest Always
Pass
{
Name "Culculate1"
CGPROGRAM
// UnityCustomRenderTexture.cgincをインクルードする
#include "UnityCustomRenderTexture.cginc"
// 頂点シェーダは決まったものを使う
#pragma vertex CustomRenderTextureVertexShader
#pragma fragment frag
// v2f構造体は決まったものを使う
half4 frag(v2f_customrendertexture i) : SV_Target
{
return fixed4(0.8 * frac(_Time.x), 0, 0, 1.0);
}
ENDCG
}
Pass
{
Name "Culculate2"
CGPROGRAM
#include "UnityCustomRenderTexture.cginc"
#pragma vertex CustomRenderTextureVertexShader
#pragma fragment frag
half4 frag(v2f_customrendertexture i) : SV_Target
{
return fixed4(0, 0.7 * frac(_Time.z), 0, 1.0);
}
ENDCG
}
Pass
{
Name "Culculate3"
CGPROGRAM
#include "UnityCustomRenderTexture.cginc"
#pragma vertex CustomRenderTextureVertexShader
#pragma fragment frag
half4 frag(v2f_customrendertexture i) : SV_Target
{
return fixed4(0, 0, 0.6 * frac(_Time.w), 1.0);
}
ENDCG
}
Pass
{
Name "Culculate4"
CGPROGRAM
#include "UnityCustomRenderTexture.cginc"
#pragma vertex CustomRenderTextureVertexShader
#pragma fragment frag
half4 frag(v2f_customrendertexture i) : SV_Target
{
return fixed4(0.8 * frac(_Time.x), 0.7 * frac(_Time.z), 0.6 * frac(_Time.w), 1.0);
}
ENDCG
}
}
}
Shader "CRT_Transfer_Data"
{
Properties
{
_MainTex ("CRT", 2D) = "white"{}
[IntRange] _Index ("Index", Range(1, 4)) = 1
[IntRange] _selectRGB ("R = 1, G = 2, B = 3", Range(1, 3)) = 1
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
int _Index, _selectRGB;
fixed4 frag (v2f i) : SV_Target
{
float uv_x = fmod(_Index, 2) == 0 ? 0.75 : 0.25;
float uv_y = step(1.1, _Index / 2.0) ? 0.75 : 0.25;
fixed4 col = tex2D(_MainTex, float2(uv_x, uv_y));
if(_selectRGB == 1)
{
col = step(0.5, col.r) ? fixed4(1, 1, 1, 1) : fixed4(0, 0, 0, 1);
}
else if(_selectRGB == 2)
{
col = step(0.5, col.g) ? fixed4(1, 1, 1, 1) : fixed4(0, 0, 0, 1);
}
else if(_selectRGB == 3)
{
col = step(0.5, col.b) ? fixed4(1, 1, 1, 1) : fixed4(0, 0, 0, 1);
}
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment