Last active
March 23, 2020 03:41
-
-
Save partybusiness/3ac856b917ef9e90050246ecade4f6de to your computer and use it in GitHub Desktop.
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
Shader that changes width of every second pixel by shifting UVs. |
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
Shader "Unlit/TartanShifting" | |
{ | |
// offsets UVs to make alternating thick and thin stripes | |
Properties | |
{ | |
_MainTex ("Texture", 2D) = "white" {} | |
_Threshold("Threshold", Range(0, 1)) = 0.2 | |
} | |
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; | |
float _Threshold; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.uv = TRANSFORM_TEX(v.uv, _MainTex); | |
return o; | |
} | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
fixed2 uvs = i.uv*_MainTex_TexelSize.zw/2; //scale it up | |
fixed2 offset = fmod(uvs/2,1)>(1-_Threshold/2); | |
uvs = floor(floor(uvs) + offset)+0.5; | |
uvs = uvs / (_MainTex_TexelSize.zw); //scale it down | |
fixed4 col = tex2D(_MainTex, uvs); | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment