~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to release/plugins/texture/tiles.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 /**
2
 
 *
3
 
 * ***** BEGIN GPL LICENSE BLOCK *****
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU General Public License
7
 
 * as published by the Free Software Foundation; either version 2
8
 
 * of the License, or (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software Foundation,
17
 
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
 
 *
19
 
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20
 
 * All rights reserved.
21
 
 *
22
 
 * The Original Code is: all of this file.
23
 
 *
24
 
 * Contributor(s): none yet.
25
 
 *
26
 
 * ***** END GPL LICENSE BLOCK *****
27
 
 */
28
 
 
29
 
#include <math.h>
30
 
#include "plugin.h"
31
 
 
32
 
/* ******************** GLOBAL VARIABLES ***************** */
33
 
 
34
 
char name[]= "tiles";
35
 
 
36
 
/* Subtype names must be less than 15 characters */
37
 
 
38
 
#define NR_TYPES        2
39
 
char stnames[NR_TYPES][16]= {"Square", "Deformed"};
40
 
 
41
 
VarStruct varstr[]= {
42
 
         NUM|FLO,       "size",                 1.0,     0.0, 1.0,  "The size of each tile", 
43
 
         NUM|FLO,       "Noise",                1.0,     0.01, 10.0, ""
44
 
};
45
 
 
46
 
/* The cast struct is for input in the main doit function
47
 
   Varstr and Cast must have the same variables in the same order */ 
48
 
 
49
 
typedef struct Cast {
50
 
        float size;
51
 
        float noise;
52
 
} Cast;
53
 
 
54
 
/* result: 
55
 
   Intensity, R, G, B, Alpha, nor.x, nor.y, nor.z
56
 
 */
57
 
 
58
 
float result[8];
59
 
 
60
 
/* cfra: the current frame */
61
 
 
62
 
float cfra;
63
 
 
64
 
int plugin_tex_doit(int, Cast *, float *, float *, float *, float *);
65
 
void plugin_instance_init(Cast*);
66
 
 
67
 
/* ******************** Fixed functions ***************** */
68
 
 
69
 
int plugin_tex_getversion(void) 
70
 
{       
71
 
        return B_PLUGIN_VERSION;
72
 
}
73
 
 
74
 
void plugin_but_changed(int but) 
75
 
{
76
 
}
77
 
 
78
 
void plugin_init(void)
79
 
{
80
 
}
81
 
 
82
 
/* 
83
 
 * initialize any data for a particular instance of
84
 
 * the plugin here
85
 
 */
86
 
void plugin_instance_init(Cast *cast)
87
 
{
88
 
}
89
 
 
90
 
/* this function should not be changed: */
91
 
 
92
 
void plugin_getinfo(PluginInfo *info)
93
 
{
94
 
        info->name= name;
95
 
        info->stypes= NR_TYPES;
96
 
        info->nvars= sizeof(varstr)/sizeof(VarStruct);
97
 
        
98
 
        info->snames= stnames[0];
99
 
        info->result= result;
100
 
        info->cfra= &cfra;
101
 
        info->varstr= varstr;
102
 
 
103
 
        info->init= plugin_init;
104
 
        info->tex_doit=  (TexDoit) plugin_tex_doit;
105
 
        info->callback= plugin_but_changed;
106
 
        info->instance_init= (void (*)(void *)) plugin_instance_init;
107
 
 
108
 
}
109
 
 
110
 
/* ************************************************************
111
 
        Tiles
112
 
        
113
 
        Demonstration of a simple square wave function sampled
114
 
        with anti-aliasing.
115
 
        It is not mipmapped yet...
116
 
        
117
 
   ************************************************************ */
118
 
 
119
 
 
120
 
/* square wave, antialiased, no mipmap! */
121
 
 
122
 
float sample_wave(float freq, float coord, float pixsize)
123
 
{
124
 
        float fac, frac,  retval;
125
 
        int part1, part2;
126
 
        
127
 
        if(pixsize > freq) return 0.5;
128
 
        
129
 
        pixsize/= freq;
130
 
        
131
 
        fac= coord/freq;
132
 
        part1= ffloor(fac);
133
 
        frac= fac - part1;
134
 
 
135
 
        if(part1 & 1) retval= 0.0;
136
 
        else retval= 1.0;
137
 
        
138
 
        if(pixsize != 0.0) {
139
 
                
140
 
                /* is coord+pixsize another value? */
141
 
                
142
 
                part2= ffloor(fac + pixsize);
143
 
                if(part1==part2) return retval;
144
 
                
145
 
                /* antialias */ 
146
 
                if(retval==1.0) retval= (1.0-frac)/pixsize;
147
 
                else retval= 1.0-(1.0-frac)/pixsize;
148
 
        }
149
 
        return retval;
150
 
}
151
 
 
152
 
int plugin_tex_doit(int stype, Cast *cast, float *texvec, float *dxt, float *dyt, float *result)
153
 
{
154
 
        float xwave, ywave;
155
 
        
156
 
        if(stype==1) {
157
 
                texvec[0]+= hnoise(cast->noise, texvec[0], texvec[1], texvec[2]);
158
 
                texvec[1]+= hnoise(cast->noise, texvec[1], texvec[2], texvec[0]);
159
 
        }
160
 
        
161
 
        if(dxt && dyt) {
162
 
                xwave= sample_wave(cast->size, texvec[0], fabs(dxt[0]) + fabs(dyt[0]) );
163
 
                ywave= sample_wave(cast->size, texvec[1], fabs(dxt[1]) + fabs(dyt[1]) );
164
 
 
165
 
                if(xwave > ywave) result[0]= xwave-ywave;
166
 
                else result[0]= ywave-xwave;
167
 
        } 
168
 
        else {
169
 
                xwave= sample_wave(cast->size, texvec[0], 0.0 );
170
 
                ywave= sample_wave(cast->size, texvec[1], 0.0 );
171
 
                
172
 
                if(xwave > ywave) result[0]= xwave-ywave;
173
 
                else result[0]= ywave-xwave;
174
 
        }
175
 
 
176
 
        return TEX_INT;
177
 
}