Skip to content

Instantly share code, notes, and snippets.

@prehnRA
Last active May 6, 2016 03:19
Show Gist options
  • Save prehnRA/5a710950f6b531a2bfe0bdd11a3c9353 to your computer and use it in GitHub Desktop.
Save prehnRA/5a710950f6b531a2bfe0bdd11a3c9353 to your computer and use it in GitHub Desktop.
A basic shader for making grids on an object
Shader "Unlit/StripeShader"
{
Properties
{
// Color property for material inspector, default to white
// _Color is the color of the grid lines, actually (need to flip these
// at some point)
_Color ("Main Color", Color) = (1,1,1,0.5)
// _Color2 is actually the main body color
_Color2 ("Other Color", Color) = (1,1,1,0.5)
// Offset the grid pattern
_OffsetX ("X Offset", Float) = 0
_OffsetY ("Y Offset", Float) = 0
}
SubShader
{
// TODO: Figure out why transparency doesn't actually work right now
Tags { "Queue"="Transparent" "RenderType"="Transparent" "IgnoreProjector"="True" }
Pass
{
ZWrite Off
Blend DstAlpha OneMinusDstAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
float4 vert (float4 vertex : POSITION) : SV_POSITION
{
// Basically just pass through the vertex coordinates in scale
return mul(UNITY_MATRIX_MVP, vertex);
}
// color from the material
fixed4 _Color;
fixed4 _Color2;
float _OffsetX;
float _OffsetY;
// pixel shader, no inputs needed
fixed4 frag (float4 i : POSITION) : COLOR
{
// First two out of 10 pixel along either access, return hash color
if((i.x + _OffsetX) % 10.0f < 2.0f || (i.y + _OffsetY) % 10.0f < 2.0f) {
return _Color;
} else {
// Return main body color
return _Color2;
}
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment