Created
June 11, 2021 10:57
-
-
Save sunasaji/02abddc0cabe35d685e8dc2aa978292d to your computer and use it in GitHub Desktop.
This shader generates 5x9 Quilt Image from 45 textures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Copyright (c) 2021 sunasaji | |
//Copyright (c) 2019 yukatayu-vrc https://github.com/yukatayu-vrc/HUD_shader/blob/master/LICENSE | |
//This code is licensed under the MIT License. | |
Shader "Unlit/LKGCamera45" { | |
Properties { | |
_MainTex("Texture00", 2D) = "white" {} | |
_Tex01 ("Texture01", 2D) = "white" {} | |
_Tex02 ("Texture02", 2D) = "white" {} | |
_Tex03 ("Texture03", 2D) = "white" {} | |
_Tex04 ("Texture04", 2D) = "white" {} | |
_Tex05 ("Texture05", 2D) = "white" {} | |
_Tex06 ("Texture06", 2D) = "white" {} | |
_Tex07 ("Texture07", 2D) = "white" {} | |
_Tex08 ("Texture08", 2D) = "white" {} | |
_Tex09 ("Texture09", 2D) = "white" {} | |
_Tex10 ("Texture10", 2D) = "white" {} | |
_Tex11 ("Texture11", 2D) = "white" {} | |
_Tex12 ("Texture12", 2D) = "white" {} | |
_Tex13 ("Texture13", 2D) = "white" {} | |
_Tex14 ("Texture14", 2D) = "white" {} | |
_Tex15 ("Texture15", 2D) = "white" {} | |
_Tex16 ("Texture16", 2D) = "white" {} | |
_Tex17 ("Texture17", 2D) = "white" {} | |
_Tex18 ("Texture18", 2D) = "white" {} | |
_Tex19 ("Texture19", 2D) = "white" {} | |
_Tex20 ("Texture20", 2D) = "white" {} | |
_Tex21 ("Texture21", 2D) = "white" {} | |
_Tex22 ("Texture22", 2D) = "white" {} | |
_Tex23 ("Texture23", 2D) = "white" {} | |
_Tex24 ("Texture24", 2D) = "white" {} | |
_Tex25 ("Texture25", 2D) = "white" {} | |
_Tex26 ("Texture26", 2D) = "white" {} | |
_Tex27 ("Texture27", 2D) = "white" {} | |
_Tex28 ("Texture28", 2D) = "white" {} | |
_Tex29 ("Texture29", 2D) = "white" {} | |
_Tex30 ("Texture30", 2D) = "white" {} | |
_Tex31 ("Texture31", 2D) = "white" {} | |
_Tex32 ("Texture32", 2D) = "white" {} | |
_Tex33 ("Texture33", 2D) = "white" {} | |
_Tex34 ("Texture34", 2D) = "white" {} | |
_Tex35 ("Texture35", 2D) = "white" {} | |
_Tex36 ("Texture36", 2D) = "white" {} | |
_Tex37 ("Texture37", 2D) = "white" {} | |
_Tex38 ("Texture38", 2D) = "white" {} | |
_Tex39 ("Texture39", 2D) = "white" {} | |
_Tex40 ("Texture40", 2D) = "white" {} | |
_Tex41 ("Texture41", 2D) = "white" {} | |
_Tex42 ("Texture42", 2D) = "white" {} | |
_Tex43 ("Texture43", 2D) = "white" {} | |
_Tex44 ("Texture44", 2D) = "white" {} | |
_SwitchTex ("Switch", 2D) = "white" {} | |
_TileX("Tile X number", int) = 5 | |
_TileY("Tile Y number", int) = 9 | |
_TargetScreenX("Target Screen X Resolution", int) = 1920 | |
_TargetScreenY("Target Screen Y Resolution", int) = 1080 | |
} | |
SubShader { | |
Tags { "RenderType"="Transparent" "Queue"="Overlay+4000" "IgnoreProjector"="True" } | |
ZTest Always // 常に前面に表示 | |
Cull Off // 裏面が見えている場合も処理する | |
Pass { | |
// Meta | |
CGPROGRAM | |
#pragma target 3.0 | |
#include "UnityCG.cginc" | |
// Struct | |
struct appdata { | |
float4 vertex : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f { | |
float2 uv : TEXCOORD0; | |
UNITY_FOG_COORDS(1) | |
float4 vertex : SV_POSITION; | |
}; | |
// Param | |
UNITY_DECLARE_TEX2D(_MainTex); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex01); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex02); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex03); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex04); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex05); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex06); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex07); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex08); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex09); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex10); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex11); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex12); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex13); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex14); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex15); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex16); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex17); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex18); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex19); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex20); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex21); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex22); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex23); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex24); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex25); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex26); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex27); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex28); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex29); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex30); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex31); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex32); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex33); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex34); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex35); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex36); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex37); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex38); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex39); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex40); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex41); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex42); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex43); | |
UNITY_DECLARE_TEX2D_NOSAMPLER(_Tex44); | |
sampler2D _SwitchTex; | |
float2 maxScreenRatio; | |
int _TileX, _TileY, _TargetScreenX, _TargetScreenY; | |
float _PosX, _PosY, _Shift; | |
// Vertex | |
#pragma vertex vert | |
v2f vert (appdata v) { | |
v2f o; | |
// Shift Quilt Area to the Center | |
_Shift = 1.0 - (1.0 * min(_TargetScreenX, _TargetScreenY) / max (_TargetScreenX, _TargetScreenY)); | |
if(_TargetScreenX > _TargetScreenY){ | |
_PosX = _Shift; | |
}else{ | |
_PosY = _Shift; | |
} | |
// Hide vertex to other players | |
half4 showBoolTex = tex2Dlod(_SwitchTex, float4(0, 0, 0, 0)); | |
bool showFlag = showBoolTex.r != 0; | |
// Hide vertex if screen ratio is different from _TargetScreenX / _TargetScreenY | |
if(0.01<abs(1.0*_TargetScreenX/_TargetScreenY - _ScreenParams.x/_ScreenParams.y)) showFlag = 0; | |
o.vertex = float4 (v.vertex.x * 2 + _PosX, v.vertex.y * -2 * _ProjectionParams.x + _PosY, 1, 1) * showFlag; | |
// Adjust render area from rectangle to square | |
maxScreenRatio = float2 ( _ScreenParams.x / min(_ScreenParams.x, _ScreenParams.y), _ScreenParams.y / min(_ScreenParams.x, _ScreenParams.y)); | |
o.uv = v.uv * maxScreenRatio; | |
return o; | |
} | |
// Fragment | |
#pragma fragment frag | |
fixed4 frag (v2f i) : SV_Target { | |
fixed4 col = fixed4(0,0,0,0); | |
fixed2 fullUV, p; | |
uint n; | |
uint quiltX, quiltY; | |
fullUV = fixed2 (i.uv * float2(1, -1) + float2(0, 1)); | |
quiltX = floor(fullUV.x * _TileX); | |
quiltY = floor(fullUV.y * _TileY); | |
p = fullUV * float2(_TileX,_TileY) - float2(quiltX,quiltY); | |
n = quiltX + quiltY * _TileX; | |
if(n==0)col = UNITY_SAMPLE_TEX2D(_MainTex, p); | |
if(n==1)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex01, _MainTex, p); | |
if(n==2)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex02, _MainTex, p); | |
if(n==3)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex03, _MainTex, p); | |
if(n==4)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex04, _MainTex, p); | |
if(n==5)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex05, _MainTex, p); | |
if(n==6)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex06, _MainTex, p); | |
if(n==7)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex07, _MainTex, p); | |
if(n==8)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex08, _MainTex, p); | |
if(n==9)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex09, _MainTex, p); | |
if(n==10)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex10, _MainTex, p); | |
if(n==11)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex11, _MainTex, p); | |
if(n==12)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex12, _MainTex, p); | |
if(n==13)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex13, _MainTex, p); | |
if(n==14)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex14, _MainTex, p); | |
if(n==15)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex15, _MainTex, p); | |
if(n==16)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex16, _MainTex, p); | |
if(n==17)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex17, _MainTex, p); | |
if(n==18)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex18, _MainTex, p); | |
if(n==19)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex19, _MainTex, p); | |
if(n==20)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex20, _MainTex, p); | |
if(n==21)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex21, _MainTex, p); | |
if(n==22)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex22, _MainTex, p); | |
if(n==23)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex23, _MainTex, p); | |
if(n==24)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex24, _MainTex, p); | |
if(n==25)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex25, _MainTex, p); | |
if(n==26)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex26, _MainTex, p); | |
if(n==27)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex27, _MainTex, p); | |
if(n==28)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex28, _MainTex, p); | |
if(n==29)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex29, _MainTex, p); | |
if(n==30)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex30, _MainTex, p); | |
if(n==31)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex31, _MainTex, p); | |
if(n==32)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex32, _MainTex, p); | |
if(n==33)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex33, _MainTex, p); | |
if(n==34)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex34, _MainTex, p); | |
if(n==35)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex35, _MainTex, p); | |
if(n==36)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex36, _MainTex, p); | |
if(n==37)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex37, _MainTex, p); | |
if(n==38)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex38, _MainTex, p); | |
if(n==39)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex39, _MainTex, p); | |
if(n==40)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex40, _MainTex, p); | |
if(n==41)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex41, _MainTex, p); | |
if(n==42)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex42, _MainTex, p); | |
if(n==43)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex43, _MainTex, p); | |
if(n==44)col = UNITY_SAMPLE_TEX2D_SAMPLER(_Tex44, _MainTex, p); | |
clip(1.0 - i.uv.x); | |
clip(1.0 - i.uv.y); | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment