Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. Shader "Unlit/Polygon"
  2. {
  3. Properties
  4. {
  5. [HideInInspector] _MainTex ("Texture", 2D) = "white" {}
  6. _N("N", Int) = 3
  7. }
  8. SubShader
  9. {
  10. Tags { "RenderType"="Opaque" }
  11. LOD 100
  12.  
  13. Pass
  14. {
  15. CGPROGRAM
  16. #pragma vertex vert
  17. #pragma fragment frag
  18. // make fog work
  19. #pragma multi_compile_fog
  20.  
  21. #include "UnityCG.cginc"
  22.  
  23. struct appdata
  24. {
  25. float4 vertex : POSITION;
  26. float2 uv : TEXCOORD0;
  27. };
  28.  
  29. struct v2f
  30. {
  31. float2 uv : TEXCOORD0;
  32. UNITY_FOG_COORDS(1)
  33. float4 vertex : SV_POSITION;
  34. };
  35.  
  36. sampler2D _MainTex;
  37. float4 _MainTex_ST;
  38.  
  39. v2f vert (appdata v)
  40. {
  41. v2f o;
  42. o.vertex = UnityObjectToClipPos(v.vertex);
  43. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  44. UNITY_TRANSFER_FOG(o,o.vertex);
  45. return o;
  46. }
  47.  
  48. #define PI 3.14159265358979
  49. int _N;
  50.  
  51. fixed4 frag (v2f i) : SV_Target
  52. {
  53. float2 uv = i.uv - 0.5;
  54. float r = length(uv); // 原点からの距離
  55. float theta = atan2(uv.x, uv.y) + 2.0 * PI; // 原点からの角度 (負にならないように2π足しています)
  56. theta = theta % (2.0 * PI / _N); // 角度の補正
  57.  
  58. float r2 = cos(PI / _N) / cos (PI / _N - theta); // 中心から多角形までの距離
  59.  
  60. return step(r, r2 * 0.5);
  61. }
  62. ENDCG
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement