00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef PATTERNS_H
00018 #define PATTERNS_H 1
00019
00020 #include "filterwidth.h"
00021
00022
00023
00024
00025 float sqr (float x)
00026 {
00027 return x*x;
00028 }
00029
00030
00031
00032
00033
00034
00035
00036
00037 float filteredabs (float x, dx)
00038 {
00039 float integral (float t) {
00040 return sign(t) * 0.5 * t*t;
00041 }
00042
00043 float x0 = x - 0.5*dx;
00044 float x1 = x0 + dx;
00045 return (integral(x1) - integral(x0)) / dx;
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 float filteredsmoothstep (float e0, e1, x, dx)
00059 {
00060 float integral (float t) {
00061 return -0.5*t*t * (t*t + t);
00062 }
00063
00064
00065
00066
00067 float edgediff = e1 - e0;
00068 float x0 = (x-e0)/edgediff;
00069 float fw = dx / edgediff;
00070 x0 -= 0.5*fw;
00071 float x1 = x0 + fw;
00072
00073
00074 float int = 0;
00075
00076 if (x0 < 1 && x1 > 0)
00077 int += integral(min(x1,1)) - integral(max(x0,0));
00078
00079 if (x1 > 1)
00080 int += x1-max(1,x0);
00081 return int / fw;
00082 }
00083
00084
00085
00086
00087 float pulse (float edge0, edge1, x)
00088 {
00089 return step(edge0,x) - step(edge1,x);
00090 }
00091
00092
00093
00094 float filteredpulse (float edge0, edge1, x, dx)
00095 {
00096 float x0 = x - dx/2;
00097 float x1 = x0 + dx;
00098 return max (0, (min(x1,edge1)-max(x0,edge0)) / dx);
00099 }
00100
00101
00102
00103
00104
00105
00106 float pulsetrain (float edge, period, x)
00107 {
00108 return pulse (edge, period, mod(x,period));
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118 float filteredpulsetrain (float edge, period, x, dx)
00119 {
00120
00121 float w = dx/period;
00122 float x0 = x/period - w/2;
00123 float x1 = x0+w;
00124 float nedge = edge / period;
00125
00126
00127 float integral (float t) {
00128 extern float nedge;
00129 return ((1-nedge)*floor(t) + max(0,t-floor(t)-nedge));
00130 }
00131
00132
00133 return (integral(x1) - integral(x0)) / w;
00134 }
00135
00136
00137
00138 float
00139 smoothpulse (float e0, e1, e2, e3, x)
00140 {
00141 return smoothstep(e0,e1,x) - smoothstep(e2,e3,x);
00142 }
00143
00144
00145 float
00146 filteredsmoothpulse (float e0, e1, e2, e3, x, dx)
00147 {
00148 return filteredsmoothstep(e0,e1,x,dx) - filteredsmoothstep(e2,e3,x,dx);
00149 }
00150
00151
00152
00153
00154
00155
00156
00157 float smoothpulsetrain (float e0, e1, e2, e3, period, x)
00158 {
00159 return smoothpulse (e0, e1, e2, e3, mod(x,period));
00160 }
00161
00162
00163
00164
00165
00166
00167
00168
00169 color varyEach (color Cin; float index, varyhue, varysat, varylum;)
00170 {
00171
00172 color Chsl = ctransform ("hsl", Cin);
00173 float h = comp(Chsl,0), s = comp(Chsl,1), l = comp(Chsl,2);
00174
00175 h += varyhue * (cellnoise(index+3)-0.5);
00176 s *= 1 - varysat * (cellnoise(index-14)-0.5);
00177 l *= 1 - varylum * (cellnoise(index+37)-0.5);
00178 Chsl = color (mod(h,1), clamp(s,0,1), clamp(l,0,1));
00179
00180 return ctransform ("hsl", "rgb", clamp(Chsl,color 0, color 1));
00181 }
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 float
00192 tilepattern (float ss, tt, ds, dt;
00193 float groovewidth, grooveheight;
00194 output float swhichtile, twhichtile;
00195 output float stile, ttile;)
00196 {
00197 swhichtile = floor (ss);
00198 twhichtile = floor (tt);
00199 stile = ss - swhichtile;
00200 ttile = tt - twhichtile;
00201
00202 return filteredpulsetrain (groovewidth, 1, ss+groovewidth/2, ds)
00203 * filteredpulsetrain (grooveheight, 1, tt+grooveheight/2, dt);
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 void basicbrick (float x, y;
00221 uniform float tilewidth, tileheight;
00222 uniform float rowstagger, rowstaggervary;
00223 uniform float jaggedfreq, jaggedamp;
00224 output float column, row;
00225 output float xtile, ytile;
00226 )
00227 {
00228 point PP;
00229 float scoord = x, tcoord = y;
00230
00231 if (jaggedamp != 0.0) {
00232
00233 PP = point noise (x*jaggedfreq/tilewidth, y*jaggedfreq/tileheight);
00234 scoord += jaggedamp * xcomp (PP);
00235 tcoord += jaggedamp * ycomp (PP);
00236 }
00237
00238 xtile = scoord / tilewidth;
00239 ytile = tcoord / tileheight;
00240 row = floor (ytile);
00241
00242
00243 xtile += mod (rowstagger * row, 1);
00244 xtile += rowstaggervary * (noise (row+0.5) - 0.5);
00245
00246 column = floor (xtile);
00247 xtile -= column;
00248 ytile -= row;
00249 }
00250
00251
00252
00253 #endif