Created
May 2, 2015 03:06
-
-
Save hecomi/c98b11bf68527effced0 to your computer and use it in GitHub Desktop.
Unity でグリッド描くやつ
This file contains hidden or 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 "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