2023. 1. 20. 07:49
Unity/shader
1:1
2:1 크롭
Shader "Ahzkwid/ScreenOverlay"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _MainTex_TexelSize;
v2f vert (appdata v)
{
v2f o;
o.uv = float4(TRANSFORM_TEX(v.uv, _MainTex),1,1);
o.vertex.xy = o.uv;
o.vertex.xy -= 0.5;
o.vertex.xy *= 2;
o.vertex.y = -o.vertex.y;
o.vertex.zw = 1;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed2 uv=i.uv;
float screenWid = _ScreenParams.x / _ScreenParams.y;
float texelWid = _MainTex_TexelSize.z / _MainTex_TexelSize.w;
if(screenWid>texelWid)
{
uv.x*=screenWid;
uv.x -= screenWid / 2;
uv.x += texelWid / 2;
uv.x/=texelWid;
}
else
{
float screenHei = 1/screenWid;
float texelHei = 1/texelWid;
uv.y*=screenHei;
uv.y -= screenHei / 2;
uv.y += texelHei / 2;
uv.y/=texelHei;
}
fixed4 col = tex2D(_MainTex, uv);
col.a*=all(uv==saturate(uv));
return lerp(0,col,col.a);
}
ENDCG
}
}
}
'Unity > shader' 카테고리의 다른 글
PerlinNoise HLSL (0) | 2023.04.25 |
---|---|
유니티 스카이박스 관련 (0) | 2023.01.16 |
함수 그래프 모음 (0) | 2022.01.15 |