Advertisement
tonynogo

Demo 64 - 10 PRINT CHR

Jul 6th, 2017
3,182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Noise/10 PRINT CHR$(205.5+RND(1)); : GOTO 10:"
  2. {
  3.     Properties
  4.     {
  5.         _Factor1 ("Factor 1", float) = 1.0
  6.         _Factor2 ("Factor 2", float) = 1.0
  7.         _Factor3 ("Factor 3", float) = 1.0
  8.  
  9.         _GridSize ("GridSize", float) = 1.0
  10.     }
  11.  
  12.     SubShader
  13.     {
  14.         Tags { "RenderType"="Opaque" }
  15.  
  16.         Pass
  17.         {
  18.             CGPROGRAM
  19.             #pragma vertex vert_img
  20.             #pragma fragment frag
  21.            
  22.             #include "UnityCG.cginc"
  23.            
  24.             float _Factor1;
  25.             float _Factor2;
  26.             float _Factor3;
  27.  
  28.             float _GridSize;
  29.  
  30.             float2 truchetPattern(float2 uv, float index)
  31.             {
  32.                 index = frac((index - 0.5) * 2.0);
  33.  
  34.                 if(index > 0.75)
  35.                 {
  36.                     return float2(1.0, 1.0) - uv;
  37.                 }
  38.                
  39.                 if(index > 0.5)
  40.                 {
  41.                     return float2(1.0 - uv.x, uv.y);
  42.                 }
  43.  
  44.                 if(index > 0.25)
  45.                 {
  46.                     return 1.0 - float2(1.0 - uv.x, uv.y);
  47.                 }
  48.  
  49.                 return uv;
  50.             }
  51.  
  52.             float noise(half2 uv)
  53.             {
  54.                 return frac(sin(dot(uv, float2(_Factor1, _Factor2))) * _Factor3);
  55.             }
  56.  
  57.  
  58.  
  59.             fixed4 frag (v2f_img i) : SV_Target
  60.             {
  61.                 i.uv *= _GridSize;
  62.                 float2 intVal = floor(i.uv);
  63.                 float2 fracVal = frac(i.uv);
  64.  
  65.                 float2 tile = truchetPattern(fracVal, noise(intVal));
  66.  
  67.                 fixed col = smoothstep(tile.x - 0.3, tile.x, tile.y)
  68.                 - smoothstep(tile.x, tile.x + 0.3, tile.y);
  69.  
  70.                 return fixed4(col, col, col, 1);
  71.             }
  72.             ENDCG
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement