Skip to content

Instantly share code, notes, and snippets.

@edom18
Created November 20, 2019 07:23
Show Gist options
  • Save edom18/6b39868c84634e4aa89557da4a7f41d9 to your computer and use it in GitHub Desktop.
Save edom18/6b39868c84634e4aa89557da4a7f41d9 to your computer and use it in GitHub Desktop.
This code provide a mask for free aspect rectangle.
Shader "NrealRoom/ViewMask"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_Width("Width", Float) = 10.0
}
SubShader
{
Cull Off ZWrite Off ZTest Always
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;
};
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float _Direction;
float _Width;
fixed4 frag(v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
float2 uv = abs(i.uv * 2.0 - 1.0);
float xu = _Width / _ScreenParams.x * 0.5;
float yu = _Width / _ScreenParams.y * 0.5;
float x = smoothstep(0, xu, 1.0 - uv.x);
float y = smoothstep(0, yu, 1.0 - uv.y);
col = lerp(float4(0, 0, 0, 0), col, x * y);
return col;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment