I'm drawing a rectangle based on input sizes and use it to mask the screen. Now I want to give it 1 pixel stroke but it doesn't rasterize to one pixel. I tried UnityPixelSnap but still no chance.
Here's My Shader:
Shader "MyShaders/Frame"
{
Properties
{
[PerRendererData] _MainTex ("Frame Overlay", 2D) = "white" {}
framesize ("Frame Sizes", Vector) = (0.5 , 0.5, 0.0 , 0.0) // z & w are just value holders
}
SubShader
{
Cull Off ZWrite Off ZTest Off Lighting Off
Blend One OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 c : COLOR;
float4 pos : SV_POSITION;
float4 p : TEXCOORD;
};
v2f vert (appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.c = v.color;
o.p = ComputeScreenPos(o.pos);
return o;
}
sampler2D _MainTex;
float4 framesize;
fixed4 frag (v2f i) : SV_Target
{
// Base Color
fixed4 color = i.c;
float2 screen = i.p.xy;
float2 screenSize = _ScreenParams.xy;
// Get Pixel Size
framesize.z = (1.0f / screenSize.x);
framesize.w = (1.0f / screenSize.y);
// Draw Stroke
if(screen.x > (0.5f - (framesize.x/2) - framesize.z) && screen.x < (0.5f + (framesize.x/2) + framesize.z)
&& screen.y > (0.5f - (framesize.y/2) - framesize.w) && screen.y < (0.5f + (framesize.y/2) + framesize.w))
color = float4(1.0, 1.0, 1.0, 0.4f);
// Delim Using Ratios
if(screen.x > (0.5f - (framesize.x/2) - framesize.z*.2) && screen.x < (0.5f + (framesize.x/2) + framesize.z*.2)
&& screen.y > (0.5f - (framesize.y/2) - framesize.w*.2) && screen.y < (0.5f + (framesize.y/2) + framesize.w*.2))
color.a = 0;
// Apply UI Alpha
color.rgb *= color.a;
return color;
}
ENDCG
}
}
}
It should be assigned to a full width/height panel in a canvas.
This is what happens :
I've found this useful shader, It works perfect but I have no idea how can I use it in my shader.
I'll be very greatful if someone know how to make it work :)