Skip to content

Instantly share code, notes, and snippets.

@hecomi
Created May 2, 2015 03:06
Show Gist options
  • Save hecomi/c98b11bf68527effced0 to your computer and use it in GitHub Desktop.
Save hecomi/c98b11bf68527effced0 to your computer and use it in GitHub Desktop.
Unity でグリッド描くやつ
Shader "Grid/Rect" {
Properties {
_Color("Color", Color) = (0.5, 0.5, 0.5, 1.0)
_Width("Width", Range(0.0, 1.0)) = 0.5
_GridNumX("GridNumX", Int) = 10
_GridNumY("GridNumY", Int) = 10
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
uniform half _Width;
uniform int _GridNumX;
uniform int _GridNumY;
uniform half4 _Color;
half4 frag(v2f_img i) : COLOR {
half x0 = fmod(i.uv.x * _GridNumX, 1.0);
half y0 = fmod(i.uv.y * _GridNumY, 1.0);
half p = pow(1/ _Width, 2);
half x1 = pow(x0, p);
half y1 = pow(y0, p);
half x2 = pow(1.0 - x0, p);
half y2 = pow(1.0 - y0, p);
return ((x1 + x2) + (y1 + y2)) / 2 * _Color;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment