4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
33 /* ******************** GLOBAL VARIABLES ***************** */
37 /* Subtype names must be less than 15 characters */
40 char stnames[NR_TYPES][16]= {"Square", "Deformed"};
43 NUM|FLO, "size", 1.0, 0.0, 1.0, "The size of each tile",
44 NUM|FLO, "Noise", 1.0, 0.01, 10.0, ""
47 /* The cast struct is for input in the main doit function
48 Varstr and Cast must have the same variables in the same order */
56 Intensity, R, G, B, Alpha, nor.x, nor.y, nor.z
61 /* cfra: the current frame */
65 int plugin_tex_doit(int, Cast *, float *, float *, float *, float *);
66 void plugin_instance_init(Cast*);
68 /* ******************** Fixed functions ***************** */
70 int plugin_tex_getversion(void)
72 return B_PLUGIN_VERSION;
75 void plugin_but_changed(int but)
79 void plugin_init(void)
84 * initialize any data for a particular instance of
87 void plugin_instance_init(Cast *cast)
91 /* this function should not be changed: */
93 void plugin_getinfo(PluginInfo *info)
96 info->stypes= NR_TYPES;
97 info->nvars= sizeof(varstr)/sizeof(VarStruct);
99 info->snames= stnames[0];
100 info->result= result;
102 info->varstr= varstr;
104 info->init= plugin_init;
105 info->tex_doit= (TexDoit) plugin_tex_doit;
106 info->callback= plugin_but_changed;
107 info->instance_init= (void (*)(void *)) plugin_instance_init;
111 /* ************************************************************
114 Demonstration of a simple square wave function sampled
116 It is not mipmapped yet...
118 ************************************************************ */
121 /* square wave, antialiased, no mipmap! */
123 float sample_wave(float freq, float coord, float pixsize)
125 float fac, frac, retval;
128 if(pixsize > freq) return 0.5;
136 if(part1 & 1) retval= 0.0;
141 /* is coord+pixsize another value? */
143 part2= ffloor(fac + pixsize);
144 if(part1==part2) return retval;
147 if(retval==1.0) retval= (1.0-frac)/pixsize;
148 else retval= 1.0-(1.0-frac)/pixsize;
153 int plugin_tex_doit(int stype, Cast *cast, float *texvec, float *dxt, float *dyt, float *result)
158 texvec[0]+= hnoise(cast->noise, texvec[0], texvec[1], texvec[2]);
159 texvec[1]+= hnoise(cast->noise, texvec[1], texvec[2], texvec[0]);
163 xwave= sample_wave(cast->size, texvec[0], fabs(dxt[0]) + fabs(dyt[0]) );
164 ywave= sample_wave(cast->size, texvec[1], fabs(dxt[1]) + fabs(dyt[1]) );
166 if(xwave > ywave) result[0]= xwave-ywave;
167 else result[0]= ywave-xwave;
170 xwave= sample_wave(cast->size, texvec[0], 0.0 );
171 ywave= sample_wave(cast->size, texvec[1], 0.0 );
173 if(xwave > ywave) result[0]= xwave-ywave;
174 else result[0]= ywave-xwave;