~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/render/intern/source/renderdatabase.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: renderdatabase.c 26841 2010-02-12 13:34:04Z campbellbarton $
3
 
 *
 
1
/*
4
2
 * ***** BEGIN GPL LICENSE BLOCK *****
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or
25
23
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
26
24
 */
27
25
 
 
26
/** \file blender/render/intern/source/renderdatabase.c
 
27
 *  \ingroup render
 
28
 */
 
29
 
 
30
 
28
31
/*
29
32
 * Storage, retrieval and query of render specific data.
30
33
 *
58
61
#include <string.h>
59
62
 
60
63
#include "MEM_guardedalloc.h"
61
 
#include "BKE_utildefines.h"
 
64
 
62
65
 
63
66
#include "BLI_math.h"
64
67
#include "BLI_blenlib.h"
 
68
#include "BLI_utildefines.h"
65
69
#include "BLI_ghash.h"
66
70
#include "BLI_memarena.h"
67
71
 
75
79
#include "BKE_DerivedMesh.h"
76
80
 
77
81
#include "RE_render_ext.h"      /* externtex */
78
 
#include "RE_raytrace.h"
79
82
 
 
83
#include "rayobject.h"
80
84
#include "renderpipeline.h"
81
85
#include "render_types.h"
82
86
#include "renderdatabase.h"
86
90
 
87
91
/* ------------------------------------------------------------------------- */
88
92
 
89
 
/* More dynamic allocation of options for render vertices and faces, so we dont
90
 
   have to reserve this space inside vertices.
91
 
   Important; vertices and faces, should have been created already (to get tables
92
 
   checked) that's a reason why the calls demand VertRen/VlakRen * as arg, not
93
 
   the index */
 
93
/* More dynamic allocation of options for render vertices and faces, so we don't
 
94
 * have to reserve this space inside vertices.
 
95
 * Important; vertices and faces, should have been created already (to get tables
 
96
 * checked) that's a reason why the calls demand VertRen/VlakRen * as arg, not
 
97
 * the index */
94
98
 
95
99
/* NOTE! the hardcoded table size 256 is used still in code for going quickly over vertices/faces */
96
100
 
108
112
#define RE_RADFACE_ELEMS        1
109
113
#define RE_SIMPLIFY_ELEMS       2
110
114
#define RE_FACE_ELEMS           1
111
 
#define RE_NMAP_TANGENT_ELEMS   12
 
115
#define RE_NMAP_TANGENT_ELEMS   16
112
116
 
113
117
float *RE_vertren_get_sticky(ObjectRen *obr, VertRen *ver, int verify)
114
118
{
116
120
        int nr= ver->index>>8;
117
121
        
118
122
        sticky= obr->vertnodes[nr].sticky;
119
 
        if(sticky==NULL) {
120
 
                if(verify) 
 
123
        if (sticky==NULL) {
 
124
                if (verify) 
121
125
                        sticky= obr->vertnodes[nr].sticky= MEM_mallocN(256*RE_STICKY_ELEMS*sizeof(float), "sticky table");
122
126
                else
123
127
                        return NULL;
131
135
        int nr= ver->index>>8;
132
136
        
133
137
        stress= obr->vertnodes[nr].stress;
134
 
        if(stress==NULL) {
135
 
                if(verify) 
 
138
        if (stress==NULL) {
 
139
                if (verify) 
136
140
                        stress= obr->vertnodes[nr].stress= MEM_mallocN(256*RE_STRESS_ELEMS*sizeof(float), "stress table");
137
141
                else
138
142
                        return NULL;
147
151
        int nr= ver->index>>8;
148
152
        
149
153
        rad= obr->vertnodes[nr].rad;
150
 
        if(rad==NULL) {
151
 
                if(verify) 
 
154
        if (rad==NULL) {
 
155
                if (verify) 
152
156
                        rad= obr->vertnodes[nr].rad= MEM_callocN(256*RE_RAD_ELEMS*sizeof(float), "rad table");
153
157
                else
154
158
                        return NULL;
162
166
        int nr= ver->index>>8;
163
167
        
164
168
        strand= obr->vertnodes[nr].strand;
165
 
        if(strand==NULL) {
166
 
                if(verify) 
 
169
        if (strand==NULL) {
 
170
                if (verify) 
167
171
                        strand= obr->vertnodes[nr].strand= MEM_mallocN(256*RE_STRAND_ELEMS*sizeof(float), "strand table");
168
172
                else
169
173
                        return NULL;
178
182
        int nr= ver->index>>8;
179
183
        
180
184
        tangent= obr->vertnodes[nr].tangent;
181
 
        if(tangent==NULL) {
182
 
                if(verify) 
 
185
        if (tangent==NULL) {
 
186
                if (verify) 
183
187
                        tangent= obr->vertnodes[nr].tangent= MEM_callocN(256*RE_TANGENT_ELEMS*sizeof(float), "tangent table");
184
188
                else
185
189
                        return NULL;
195
199
        int totvector;
196
200
        
197
201
        winspeed= obi->vectors;
198
 
        if(winspeed==NULL) {
199
 
                if(verify) {
 
202
        if (winspeed==NULL) {
 
203
                if (verify) {
200
204
                        totvector= obi->obr->totvert + obi->obr->totstrand;
201
205
                        winspeed= obi->vectors= MEM_callocN(totvector*RE_WINSPEED_ELEMS*sizeof(float), "winspeed table");
202
206
                }
216
220
        v1->index= index;
217
221
        
218
222
        fp1= RE_vertren_get_sticky(obr, ver, 0);
219
 
        if(fp1) {
 
223
        if (fp1) {
220
224
                fp2= RE_vertren_get_sticky(obr, v1, 1);
221
225
                memcpy(fp2, fp1, RE_STICKY_ELEMS*sizeof(float));
222
226
        }
223
227
        fp1= RE_vertren_get_stress(obr, ver, 0);
224
 
        if(fp1) {
 
228
        if (fp1) {
225
229
                fp2= RE_vertren_get_stress(obr, v1, 1);
226
230
                memcpy(fp2, fp1, RE_STRESS_ELEMS*sizeof(float));
227
231
        }
228
232
        fp1= RE_vertren_get_rad(obr, ver, 0);
229
 
        if(fp1) {
 
233
        if (fp1) {
230
234
                fp2= RE_vertren_get_rad(obr, v1, 1);
231
235
                memcpy(fp2, fp1, RE_RAD_ELEMS*sizeof(float));
232
236
        }
233
237
        fp1= RE_vertren_get_strand(obr, ver, 0);
234
 
        if(fp1) {
 
238
        if (fp1) {
235
239
                fp2= RE_vertren_get_strand(obr, v1, 1);
236
240
                memcpy(fp2, fp1, RE_STRAND_ELEMS*sizeof(float));
237
241
        }
238
242
        fp1= RE_vertren_get_tangent(obr, ver, 0);
239
 
        if(fp1) {
 
243
        if (fp1) {
240
244
                fp2= RE_vertren_get_tangent(obr, v1, 1);
241
245
                memcpy(fp2, fp1, RE_TANGENT_ELEMS*sizeof(float));
242
246
        }
249
253
        VertRen *v;
250
254
        int a;
251
255
 
252
 
        if(nr<0) {
 
256
        if (nr<0) {
253
257
                printf("error in findOrAddVert: %d\n",nr);
254
258
                return NULL;
255
259
        }
259
263
                temp= obr->vertnodes;
260
264
                
261
265
                obr->vertnodes= MEM_mallocN(sizeof(VertTableNode)*(obr->vertnodeslen+TABLEINITSIZE) , "vertnodes");
262
 
                if(temp) memcpy(obr->vertnodes, temp, obr->vertnodeslen*sizeof(VertTableNode));
 
266
                if (temp) memcpy(obr->vertnodes, temp, obr->vertnodeslen*sizeof(VertTableNode));
263
267
                memset(obr->vertnodes+obr->vertnodeslen, 0, TABLEINITSIZE*sizeof(VertTableNode));
264
268
                
265
269
                obr->vertnodeslen+=TABLEINITSIZE; 
266
 
                if(temp) MEM_freeN(temp);       
 
270
                if (temp) MEM_freeN(temp);      
267
271
        }
268
272
        
269
273
        v= obr->vertnodes[a].vert;
270
 
        if(v==NULL) {
 
274
        if (v==NULL) {
271
275
                int i;
272
276
                
273
277
                v= (VertRen *)MEM_callocN(256*sizeof(VertRen),"findOrAddVert");
274
278
                obr->vertnodes[a].vert= v;
275
279
                
276
 
                for(i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++) {
 
280
                for (i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++) {
277
281
                        v[a].index= i;
278
282
                }
279
283
        }
291
295
 
292
296
        node= &obr->vlaknodes[nr];
293
297
 
294
 
        if(verify) {
295
 
                if(n>=node->totmtface) {
 
298
        if (verify) {
 
299
                if (n>=node->totmtface) {
296
300
                        MTFace *mtface= node->mtface;
297
 
                        int size= size= (n+1)*256;
 
301
                        int size= (n+1)*256;
298
302
 
299
303
                        node->mtface= MEM_callocN(size*sizeof(MTFace), "Vlak mtface");
300
304
 
301
 
                        if(mtface) {
 
305
                        if (mtface) {
302
306
                                size= node->totmtface*256;
303
307
                                memcpy(node->mtface, mtface, size*sizeof(MTFace));
304
308
                                MEM_freeN(mtface);
308
312
                }
309
313
        }
310
314
        else {
311
 
                if(n>=node->totmtface)
 
315
                if (n>=node->totmtface)
312
316
                        return NULL;
313
317
 
314
 
                if(name) *name= obr->mtface[n];
 
318
                if (name) *name= obr->mtface[n];
315
319
        }
316
320
 
317
321
        return node->mtface + index;
325
329
 
326
330
        node= &obr->vlaknodes[nr];
327
331
 
328
 
        if(verify) {
329
 
                if(n>=node->totmcol) {
 
332
        if (verify) {
 
333
                if (n>=node->totmcol) {
330
334
                        MCol *mcol= node->mcol;
331
335
                        int size= (n+1)*256;
332
336
 
333
337
                        node->mcol= MEM_callocN(size*sizeof(MCol)*RE_MCOL_ELEMS, "Vlak mcol");
334
338
 
335
 
                        if(mcol) {
 
339
                        if (mcol) {
336
340
                                size= node->totmcol*256;
337
341
                                memcpy(node->mcol, mcol, size*sizeof(MCol)*RE_MCOL_ELEMS);
338
342
                                MEM_freeN(mcol);
342
346
                }
343
347
        }
344
348
        else {
345
 
                if(n>=node->totmcol)
 
349
                if (n>=node->totmcol)
346
350
                        return NULL;
347
351
 
348
 
                if(name) *name= obr->mcol[n];
 
352
                if (name) *name= obr->mcol[n];
349
353
        }
350
354
 
351
355
        return node->mcol + index*RE_MCOL_ELEMS;
357
361
        int nr= vlak->index>>8;
358
362
        
359
363
        surfnor= obr->vlaknodes[nr].surfnor;
360
 
        if(surfnor==NULL) {
361
 
                if(verify) 
 
364
        if (surfnor==NULL) {
 
365
                if (verify) 
362
366
                        surfnor= obr->vlaknodes[nr].surfnor= MEM_callocN(256*RE_SURFNOR_ELEMS*sizeof(float), "surfnor table");
363
367
                else
364
368
                        return NULL;
372
376
        int nr= vlak->index>>8;
373
377
 
374
378
        tangent= obr->vlaknodes[nr].tangent;
375
 
        if(tangent==NULL) {
376
 
                if(verify) 
 
379
        if (tangent==NULL) {
 
380
                if (verify) 
377
381
                        tangent= obr->vlaknodes[nr].tangent= MEM_callocN(256*RE_NMAP_TANGENT_ELEMS*sizeof(float), "tangent table");
378
382
                else
379
383
                        return NULL;
387
391
        int nr= vlak->index>>8;
388
392
        
389
393
        radface= obr->vlaknodes[nr].radface;
390
 
        if(radface==NULL) {
391
 
                if(verify) 
 
394
        if (radface==NULL) {
 
395
                if (verify) 
392
396
                        radface= obr->vlaknodes[nr].radface= MEM_callocN(256*RE_RADFACE_ELEMS*sizeof(void*), "radface table");
393
397
                else
394
398
                        return NULL;
420
424
        }
421
425
 
422
426
        surfnor= RE_vlakren_get_surfnor(obr, vlr, 0);
423
 
        if(surfnor) {
 
427
        if (surfnor) {
424
428
                surfnor1= RE_vlakren_get_surfnor(obr, vlr1, 1);
425
 
                VECCOPY(surfnor1, surfnor);
 
429
                copy_v3_v3(surfnor1, surfnor);
426
430
        }
427
431
 
428
432
        tangent= RE_vlakren_get_nmap_tangent(obr, vlr, 0);
429
 
        if(tangent) {
 
433
        if (tangent) {
430
434
                tangent1= RE_vlakren_get_nmap_tangent(obr, vlr1, 1);
431
435
                memcpy(tangent1, tangent, sizeof(float)*RE_NMAP_TANGENT_ELEMS);
432
436
        }
433
437
 
434
438
        radface= RE_vlakren_get_radface(obr, vlr, 0);
435
 
        if(radface) {
 
439
        if (radface) {
436
440
                radface1= RE_vlakren_get_radface(obr, vlr1, 1);
437
441
                *radface1= *radface;
438
442
        }
440
444
        return vlr1;
441
445
}
442
446
 
443
 
int RE_vlakren_get_normal(Render *re, ObjectInstanceRen *obi, VlakRen *vlr, float *nor)
 
447
void RE_vlakren_get_normal(Render *UNUSED(re), ObjectInstanceRen *obi, VlakRen *vlr, float *nor)
444
448
{
445
 
        float v1[3], (*nmat)[3]= obi->nmat;
446
 
        int flipped= 0;
 
449
        float (*nmat)[3]= obi->nmat;
447
450
 
448
 
        if(obi->flag & R_TRANSFORMED) {
449
 
                VECCOPY(nor, vlr->n);
450
 
                
451
 
                mul_m3_v3(nmat, nor);
 
451
        if (obi->flag & R_TRANSFORMED) {
 
452
                mul_v3_m3v3(nor, nmat, vlr->n);
452
453
                normalize_v3(nor);
453
454
        }
454
 
        else
455
 
                VECCOPY(nor, vlr->n);
456
 
 
457
 
        if((vlr->flag & R_NOPUNOFLIP)==0) {
458
 
                if(re->r.mode & R_ORTHO) {
459
 
                        if(nor[2] > 0.0f)
460
 
                                flipped= 1;
461
 
                }
462
 
                else {
463
 
                        VECCOPY(v1, vlr->v1->co);
464
 
                        if(obi->flag & R_TRANSFORMED)
465
 
                                mul_m4_v3(obi->mat, v1);
466
 
                        if(INPR(v1, nor) < 0.0f) {
467
 
                                flipped= 1;
468
 
                        }
469
 
                }
470
 
 
471
 
                if(flipped) {
472
 
                        nor[0]= -nor[0];
473
 
                        nor[1]= -nor[1];
474
 
                        nor[2]= -nor[2];
475
 
                }
 
455
        else {
 
456
                copy_v3_v3(nor, vlr->n);
476
457
        }
477
 
 
478
 
        return flipped;
479
458
}
480
459
 
481
460
void RE_set_customdata_names(ObjectRen *obr, CustomData *data)
482
461
{
483
462
        /* CustomData layer names are stored per object here, because the
484
 
           DerivedMesh which stores the layers is freed */
 
463
         * DerivedMesh which stores the layers is freed */
485
464
        
486
465
        CustomDataLayer *layer;
487
466
        int numtf = 0, numcol = 0, i, mtfn, mcn;
500
479
                layer= &data->layers[i];
501
480
 
502
481
                if (layer->type == CD_MTFACE) {
503
 
                        strcpy(obr->mtface[mtfn++], layer->name);
 
482
                        BLI_strncpy(obr->mtface[mtfn++], layer->name, sizeof(layer->name));
504
483
                        obr->actmtface= CLAMPIS(layer->active_rnd, 0, numtf);
505
484
                        obr->bakemtface= layer->active;
506
485
                }
507
486
                else if (layer->type == CD_MCOL) {
508
 
                        strcpy(obr->mcol[mcn++], layer->name);
 
487
                        BLI_strncpy(obr->mcol[mcn++], layer->name, sizeof(layer->name));
509
488
                        obr->actmcol= CLAMPIS(layer->active_rnd, 0, numcol);
510
489
                }
511
490
        }
517
496
        VlakRen *v;
518
497
        int a;
519
498
 
520
 
        if(nr<0) {
 
499
        if (nr<0) {
521
500
                printf("error in findOrAddVlak: %d\n",nr);
522
501
                return obr->vlaknodes[0].vlak;
523
502
        }
524
503
        a= nr>>8;
525
504
        
526
 
        if (a>=obr->vlaknodeslen-1){  /* Need to allocate more columns..., and keep last element NULL for free loop */
 
505
        if (a>=obr->vlaknodeslen-1) {  /* Need to allocate more columns..., and keep last element NULL for free loop */
527
506
                temp= obr->vlaknodes;
528
507
                
529
508
                obr->vlaknodes= MEM_mallocN(sizeof(VlakTableNode)*(obr->vlaknodeslen+TABLEINITSIZE) , "vlaknodes");
530
 
                if(temp) memcpy(obr->vlaknodes, temp, obr->vlaknodeslen*sizeof(VlakTableNode));
 
509
                if (temp) memcpy(obr->vlaknodes, temp, obr->vlaknodeslen*sizeof(VlakTableNode));
531
510
                memset(obr->vlaknodes+obr->vlaknodeslen, 0, TABLEINITSIZE*sizeof(VlakTableNode));
532
511
 
533
512
                obr->vlaknodeslen+=TABLEINITSIZE;  /*Does this really need to be power of 2?*/
534
 
                if(temp) MEM_freeN(temp);       
 
513
                if (temp) MEM_freeN(temp);      
535
514
        }
536
515
 
537
516
        v= obr->vlaknodes[a].vlak;
538
517
        
539
 
        if(v==NULL) {
 
518
        if (v==NULL) {
540
519
                int i;
541
520
 
542
521
                v= (VlakRen *)MEM_callocN(256*sizeof(VlakRen),"findOrAddVlak");
543
522
                obr->vlaknodes[a].vlak= v;
544
523
 
545
 
                for(i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++)
 
524
                for (i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++)
546
525
                        v[a].index= i;
547
526
        }
548
527
        v+= (nr & 255);
557
536
        int nr= strand->index>>8;
558
537
        
559
538
        surfnor= obr->strandnodes[nr].surfnor;
560
 
        if(surfnor==NULL) {
561
 
                if(verify) 
 
539
        if (surfnor==NULL) {
 
540
                if (verify) 
562
541
                        surfnor= obr->strandnodes[nr].surfnor= MEM_callocN(256*RE_SURFNOR_ELEMS*sizeof(float), "surfnor strand table");
563
542
                else
564
543
                        return NULL;
574
553
 
575
554
        node= &obr->strandnodes[nr];
576
555
 
577
 
        if(verify) {
578
 
                if(n>=node->totuv) {
 
556
        if (verify) {
 
557
                if (n>=node->totuv) {
579
558
                        float *uv= node->uv;
580
559
                        int size= (n+1)*256;
581
560
 
582
561
                        node->uv= MEM_callocN(size*sizeof(float)*RE_UV_ELEMS, "strand uv table");
583
562
 
584
 
                        if(uv) {
 
563
                        if (uv) {
585
564
                                size= node->totuv*256;
586
565
                                memcpy(node->uv, uv, size*sizeof(float)*RE_UV_ELEMS);
587
566
                                MEM_freeN(uv);
591
570
                }
592
571
        }
593
572
        else {
594
 
                if(n>=node->totuv)
 
573
                if (n>=node->totuv)
595
574
                        return NULL;
596
575
 
597
 
                if(name) *name= obr->mtface[n];
 
576
                if (name) *name= obr->mtface[n];
598
577
        }
599
578
 
600
579
        return node->uv + index*RE_UV_ELEMS;
608
587
 
609
588
        node= &obr->strandnodes[nr];
610
589
 
611
 
        if(verify) {
612
 
                if(n>=node->totmcol) {
 
590
        if (verify) {
 
591
                if (n>=node->totmcol) {
613
592
                        MCol *mcol= node->mcol;
614
593
                        int size= (n+1)*256;
615
594
 
616
595
                        node->mcol= MEM_callocN(size*sizeof(MCol)*RE_MCOL_ELEMS, "strand mcol table");
617
596
 
618
 
                        if(mcol) {
 
597
                        if (mcol) {
619
598
                                size= node->totmcol*256;
620
599
                                memcpy(node->mcol, mcol, size*sizeof(MCol)*RE_MCOL_ELEMS);
621
600
                                MEM_freeN(mcol);
625
604
                }
626
605
        }
627
606
        else {
628
 
                if(n>=node->totmcol)
 
607
                if (n>=node->totmcol)
629
608
                        return NULL;
630
609
 
631
 
                if(name) *name= obr->mcol[n];
 
610
                if (name) *name= obr->mcol[n];
632
611
        }
633
612
 
634
613
        return node->mcol + index*RE_MCOL_ELEMS;
640
619
        int nr= strand->index>>8;
641
620
        
642
621
        simplify= obr->strandnodes[nr].simplify;
643
 
        if(simplify==NULL) {
644
 
                if(verify) 
 
622
        if (simplify==NULL) {
 
623
                if (verify) 
645
624
                        simplify= obr->strandnodes[nr].simplify= MEM_callocN(256*RE_SIMPLIFY_ELEMS*sizeof(float), "simplify strand table");
646
625
                else
647
626
                        return NULL;
655
634
        int nr= strand->index>>8;
656
635
        
657
636
        face= obr->strandnodes[nr].face;
658
 
        if(face==NULL) {
659
 
                if(verify) 
 
637
        if (face==NULL) {
 
638
                if (verify) 
660
639
                        face= obr->strandnodes[nr].face= MEM_callocN(256*RE_FACE_ELEMS*sizeof(int), "face strand table");
661
640
                else
662
641
                        return NULL;
671
650
        int totvector;
672
651
        
673
652
        winspeed= obi->vectors;
674
 
        if(winspeed==NULL) {
675
 
                if(verify) {
 
653
        if (winspeed==NULL) {
 
654
                if (verify) {
676
655
                        totvector= obi->obr->totvert + obi->obr->totstrand;
677
656
                        winspeed= obi->vectors= MEM_callocN(totvector*RE_WINSPEED_ELEMS*sizeof(float), "winspeed strand table");
678
657
                }
688
667
        StrandRen *v;
689
668
        int a;
690
669
 
691
 
        if(nr<0) {
 
670
        if (nr<0) {
692
671
                printf("error in findOrAddStrand: %d\n",nr);
693
672
                return obr->strandnodes[0].strand;
694
673
        }
695
674
        a= nr>>8;
696
675
        
697
 
        if (a>=obr->strandnodeslen-1){  /* Need to allocate more columns..., and keep last element NULL for free loop */
 
676
        if (a>=obr->strandnodeslen-1) {  /* Need to allocate more columns..., and keep last element NULL for free loop */
698
677
                temp= obr->strandnodes;
699
678
                
700
679
                obr->strandnodes= MEM_mallocN(sizeof(StrandTableNode)*(obr->strandnodeslen+TABLEINITSIZE) , "strandnodes");
701
 
                if(temp) memcpy(obr->strandnodes, temp, obr->strandnodeslen*sizeof(StrandTableNode));
 
680
                if (temp) memcpy(obr->strandnodes, temp, obr->strandnodeslen*sizeof(StrandTableNode));
702
681
                memset(obr->strandnodes+obr->strandnodeslen, 0, TABLEINITSIZE*sizeof(StrandTableNode));
703
682
 
704
683
                obr->strandnodeslen+=TABLEINITSIZE;  /*Does this really need to be power of 2?*/
705
 
                if(temp) MEM_freeN(temp);       
 
684
                if (temp) MEM_freeN(temp);      
706
685
        }
707
686
 
708
687
        v= obr->strandnodes[a].strand;
709
688
        
710
 
        if(v==NULL) {
 
689
        if (v==NULL) {
711
690
                int i;
712
691
 
713
692
                v= (StrandRen *)MEM_callocN(256*sizeof(StrandRen),"findOrAddStrand");
714
693
                obr->strandnodes[a].strand= v;
715
694
 
716
 
                for(i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++)
 
695
                for (i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++)
717
696
                        v[a].index= i;
718
697
        }
719
698
        v+= (nr & 255);
754
733
{
755
734
        int a;
756
735
        
757
 
        if(vertnodes==NULL) return;
 
736
        if (vertnodes==NULL) return;
758
737
        
759
 
        for(a=0; vertnodes[a].vert; a++) {
 
738
        for (a=0; vertnodes[a].vert; a++) {
760
739
                MEM_freeN(vertnodes[a].vert);
761
740
                
762
 
                if(vertnodes[a].rad)
 
741
                if (vertnodes[a].rad)
763
742
                        MEM_freeN(vertnodes[a].rad);
764
 
                if(vertnodes[a].sticky)
 
743
                if (vertnodes[a].sticky)
765
744
                        MEM_freeN(vertnodes[a].sticky);
766
 
                if(vertnodes[a].strand)
 
745
                if (vertnodes[a].strand)
767
746
                        MEM_freeN(vertnodes[a].strand);
768
 
                if(vertnodes[a].tangent)
 
747
                if (vertnodes[a].tangent)
769
748
                        MEM_freeN(vertnodes[a].tangent);
770
 
                if(vertnodes[a].stress)
 
749
                if (vertnodes[a].stress)
771
750
                        MEM_freeN(vertnodes[a].stress);
772
 
                if(vertnodes[a].winspeed)
 
751
                if (vertnodes[a].winspeed)
773
752
                        MEM_freeN(vertnodes[a].winspeed);
774
753
        }
775
754
        
780
759
{
781
760
        int a;
782
761
        
783
 
        if(vlaknodes==NULL) return;
 
762
        if (vlaknodes==NULL) return;
784
763
        
785
 
        for(a=0; vlaknodes[a].vlak; a++) {
 
764
        for (a=0; vlaknodes[a].vlak; a++) {
786
765
                MEM_freeN(vlaknodes[a].vlak);
787
766
                
788
 
                if(vlaknodes[a].mtface)
 
767
                if (vlaknodes[a].mtface)
789
768
                        MEM_freeN(vlaknodes[a].mtface);
790
 
                if(vlaknodes[a].mcol)
 
769
                if (vlaknodes[a].mcol)
791
770
                        MEM_freeN(vlaknodes[a].mcol);
792
 
                if(vlaknodes[a].surfnor)
 
771
                if (vlaknodes[a].surfnor)
793
772
                        MEM_freeN(vlaknodes[a].surfnor);
794
 
                if(vlaknodes[a].tangent)
 
773
                if (vlaknodes[a].tangent)
795
774
                        MEM_freeN(vlaknodes[a].tangent);
796
 
                if(vlaknodes[a].radface)
 
775
                if (vlaknodes[a].radface)
797
776
                        MEM_freeN(vlaknodes[a].radface);
798
777
        }
799
778
        
800
779
        MEM_freeN(vlaknodes);
801
780
}
802
781
 
803
 
void free_renderdata_strandnodes(StrandTableNode *strandnodes)
 
782
static void free_renderdata_strandnodes(StrandTableNode *strandnodes)
804
783
{
805
784
        int a;
806
785
        
807
 
        if(strandnodes==NULL) return;
 
786
        if (strandnodes==NULL) return;
808
787
        
809
 
        for(a=0; strandnodes[a].strand; a++) {
 
788
        for (a=0; strandnodes[a].strand; a++) {
810
789
                MEM_freeN(strandnodes[a].strand);
811
790
                
812
 
                if(strandnodes[a].uv)
 
791
                if (strandnodes[a].uv)
813
792
                        MEM_freeN(strandnodes[a].uv);
814
 
                if(strandnodes[a].mcol)
 
793
                if (strandnodes[a].mcol)
815
794
                        MEM_freeN(strandnodes[a].mcol);
816
 
                if(strandnodes[a].winspeed)
 
795
                if (strandnodes[a].winspeed)
817
796
                        MEM_freeN(strandnodes[a].winspeed);
818
 
                if(strandnodes[a].surfnor)
 
797
                if (strandnodes[a].surfnor)
819
798
                        MEM_freeN(strandnodes[a].surfnor);
820
 
                if(strandnodes[a].simplify)
 
799
                if (strandnodes[a].simplify)
821
800
                        MEM_freeN(strandnodes[a].simplify);
822
 
                if(strandnodes[a].face)
 
801
                if (strandnodes[a].face)
823
802
                        MEM_freeN(strandnodes[a].face);
824
803
        }
825
804
        
833
812
        StrandBuffer *strandbuf;
834
813
        int a=0;
835
814
        
836
 
        for(obr=re->objecttable.first; obr; obr=obr->next) {
837
 
                if(obr->vertnodes) {
 
815
        for (obr=re->objecttable.first; obr; obr=obr->next) {
 
816
                if (obr->vertnodes) {
838
817
                        free_renderdata_vertnodes(obr->vertnodes);
839
818
                        obr->vertnodes= NULL;
840
819
                        obr->vertnodeslen= 0;
841
820
                }
842
821
 
843
 
                if(obr->vlaknodes) {
 
822
                if (obr->vlaknodes) {
844
823
                        free_renderdata_vlaknodes(obr->vlaknodes);
845
824
                        obr->vlaknodes= NULL;
846
825
                        obr->vlaknodeslen= 0;
847
826
                        obr->totvlak= 0;
848
827
                }
849
828
 
850
 
                if(obr->bloha) {
851
 
                        for(a=0; obr->bloha[a]; a++)
 
829
                if (obr->bloha) {
 
830
                        for (a=0; obr->bloha[a]; a++)
852
831
                                MEM_freeN(obr->bloha[a]);
853
832
 
854
833
                        MEM_freeN(obr->bloha);
856
835
                        obr->blohalen= 0;
857
836
                }
858
837
 
859
 
                if(obr->strandnodes) {
 
838
                if (obr->strandnodes) {
860
839
                        free_renderdata_strandnodes(obr->strandnodes);
861
840
                        obr->strandnodes= NULL;
862
841
                        obr->strandnodeslen= 0;
863
842
                }
864
843
 
865
844
                strandbuf= obr->strandbuf;
866
 
                if(strandbuf) {
867
 
                        if(strandbuf->vert) MEM_freeN(strandbuf->vert);
868
 
                        if(strandbuf->bound) MEM_freeN(strandbuf->bound);
 
845
                if (strandbuf) {
 
846
                        if (strandbuf->vert) MEM_freeN(strandbuf->vert);
 
847
                        if (strandbuf->bound) MEM_freeN(strandbuf->bound);
869
848
                        MEM_freeN(strandbuf);
870
849
                }
871
850
 
872
 
                if(obr->mtface)
 
851
                if (obr->mtface)
873
852
                        MEM_freeN(obr->mtface);
874
 
                if(obr->mcol)
 
853
 
 
854
                if (obr->mcol)
875
855
                        MEM_freeN(obr->mcol);
876
856
                        
877
 
                if(obr->rayfaces)
878
 
                {
 
857
                if (obr->rayfaces) {
879
858
                        MEM_freeN(obr->rayfaces);
880
859
                        obr->rayfaces = NULL;
881
860
                }
882
 
                if(obr->rayprimitives)
883
 
                {
 
861
 
 
862
                if (obr->rayprimitives) {
884
863
                        MEM_freeN(obr->rayprimitives);
885
864
                        obr->rayprimitives = NULL;
886
865
                }
887
 
                if(obr->raytree)
888
 
                {
 
866
 
 
867
                if (obr->raytree) {
889
868
                        RE_rayobject_free(obr->raytree);
890
869
                        obr->raytree = NULL;
891
870
                }
892
871
        }
893
872
 
894
 
        if(re->objectinstance) {
895
 
                for(obi=re->instancetable.first; obi; obi=obi->next)
 
873
        if (re->objectinstance) {
 
874
                for (obi=re->instancetable.first; obi; obi=obi->next)
896
875
                {
897
 
                        if(obi->vectors)
 
876
                        if (obi->vectors)
898
877
                                MEM_freeN(obi->vectors);
899
878
 
900
 
                        if(obi->raytree)
 
879
                        if (obi->raytree)
901
880
                                RE_rayobject_free(obi->raytree);
902
881
                }
903
882
 
907
886
                re->instancetable.first= re->instancetable.last= NULL;
908
887
        }
909
888
 
910
 
        if(re->sortedhalos) {
 
889
        if (re->sortedhalos) {
911
890
                MEM_freeN(re->sortedhalos);
912
891
                re->sortedhalos= NULL;
913
892
        }
924
903
        HaloRen *h, **temp;
925
904
        int a;
926
905
 
927
 
        if(nr<0) {
 
906
        if (nr<0) {
928
907
                printf("error in findOrAddHalo: %d\n",nr);
929
908
                return NULL;
930
909
        }
931
910
        a= nr>>8;
932
911
        
933
 
        if (a>=obr->blohalen-1){  /* Need to allocate more columns..., and keep last element NULL for free loop */
 
912
        if (a>=obr->blohalen-1) {  /* Need to allocate more columns..., and keep last element NULL for free loop */
934
913
                //printf("Allocating %i more halo groups.  %i total.\n", 
935
914
                //      TABLEINITSIZE, obr->blohalen+TABLEINITSIZE );
936
915
                temp=obr->bloha;
937
916
                
938
917
                obr->bloha=(HaloRen**)MEM_callocN(sizeof(void*)*(obr->blohalen+TABLEINITSIZE) , "Bloha");
939
 
                if(temp) memcpy(obr->bloha, temp, obr->blohalen*sizeof(void*));
 
918
                if (temp) memcpy(obr->bloha, temp, obr->blohalen*sizeof(void*));
940
919
                memset(&(obr->bloha[obr->blohalen]), 0, TABLEINITSIZE*sizeof(void*));
941
920
                obr->blohalen+=TABLEINITSIZE;  /*Does this really need to be power of 2?*/
942
 
                if(temp) MEM_freeN(temp);       
 
921
                if (temp) MEM_freeN(temp);      
943
922
        }
944
923
        
945
924
        h= obr->bloha[a];
946
 
        if(h==NULL) {
 
925
        if (h==NULL) {
947
926
                h= (HaloRen *)MEM_callocN(256*sizeof(HaloRen),"findOrAdHalo");
948
927
                obr->bloha[a]= h;
949
928
        }
961
940
        float tin, tr, tg, tb, ta;
962
941
        float xn, yn, zn, texvec[3], hoco[4], hoco1[4];
963
942
 
964
 
        if(hasize==0.0) return NULL;
 
943
        if (hasize==0.0f) return NULL;
965
944
 
966
945
        projectverto(vec, re->winmat, hoco);
967
 
        if(hoco[3]==0.0) return NULL;
968
 
        if(vec1) {
 
946
        if (hoco[3]==0.0f) return NULL;
 
947
        if (vec1) {
969
948
                projectverto(vec1, re->winmat, hoco1);
970
 
                if(hoco1[3]==0.0) return NULL;
 
949
                if (hoco1[3]==0.0f) return NULL;
971
950
        }
972
951
 
973
952
        har= RE_findOrAddHalo(obr, obr->tothalo++);
974
 
        VECCOPY(har->co, vec);
 
953
        copy_v3_v3(har->co, vec);
975
954
        har->hasize= hasize;
976
955
 
977
956
        /* actual projectvert is done in function project_renderdata() because of parts/border/pano */
978
957
        /* we do it here for sorting of halos */
979
958
        zn= hoco[3];
980
 
        har->xs= 0.5*re->winx*(hoco[0]/zn);
981
 
        har->ys= 0.5*re->winy*(hoco[1]/zn);
 
959
        har->xs= 0.5f*re->winx*(hoco[0]/zn);
 
960
        har->ys= 0.5f*re->winy*(hoco[1]/zn);
982
961
        har->zs= 0x7FFFFF*(hoco[2]/zn);
983
962
        
984
963
        har->zBufDist = 0x7FFFFFFF*(hoco[2]/zn); 
985
964
        
986
965
        /* halovect */
987
 
        if(vec1) {
 
966
        if (vec1) {
988
967
 
989
968
                har->type |= HA_VECT;
990
969
 
991
 
                xn=  har->xs - 0.5*re->winx*(hoco1[0]/hoco1[3]);
992
 
                yn=  har->ys - 0.5*re->winy*(hoco1[1]/hoco1[3]);
993
 
                if(xn==0.0 || (xn==0.0 && yn==0.0)) zn= 0.0;
 
970
                xn=  har->xs - 0.5f*re->winx*(hoco1[0]/hoco1[3]);
 
971
                yn=  har->ys - 0.5f*re->winy*(hoco1[1]/hoco1[3]);
 
972
                if (xn==0.0f || (xn==0.0f && yn==0.0f)) zn= 0.0f;
994
973
                else zn= atan2(yn, xn);
995
974
 
996
975
                har->sin= sin(zn);
997
976
                har->cos= cos(zn);
998
977
                zn= len_v3v3(vec1, vec);
999
978
 
1000
 
                har->hasize= vectsize*zn + (1.0-vectsize)*hasize;
 
979
                har->hasize= vectsize*zn + (1.0f-vectsize)*hasize;
1001
980
                
1002
981
                sub_v3_v3v3(har->no, vec, vec1);
1003
982
                normalize_v3(har->no);
1004
983
        }
1005
984
 
1006
 
        if(ma->mode & MA_HALO_XALPHA) har->type |= HA_XALPHA;
 
985
        if (ma->mode & MA_HALO_XALPHA) har->type |= HA_XALPHA;
1007
986
 
1008
987
        har->alfa= ma->alpha;
1009
988
        har->r= ma->r;
1010
989
        har->g= ma->g;
1011
990
        har->b= ma->b;
1012
 
        har->add= (255.0*ma->add);
 
991
        har->add= (255.0f*ma->add);
1013
992
        har->mat= ma;
1014
993
        har->hard= ma->har;
1015
994
        har->seed= seed % 256;
1016
995
 
1017
 
        if(ma->mode & MA_STAR) har->starpoints= ma->starc;
1018
 
        if(ma->mode & MA_HALO_LINES) har->linec= ma->linec;
1019
 
        if(ma->mode & MA_HALO_RINGS) har->ringc= ma->ringc;
1020
 
        if(ma->mode & MA_HALO_FLARE) har->flarec= ma->flarec;
1021
 
 
1022
 
 
1023
 
        if(ma->mtex[0]) {
1024
 
 
1025
 
                if( (ma->mode & MA_HALOTEX) ) har->tex= 1;
 
996
        if (ma->mode & MA_STAR) har->starpoints= ma->starc;
 
997
        if (ma->mode & MA_HALO_LINES) har->linec= ma->linec;
 
998
        if (ma->mode & MA_HALO_RINGS) har->ringc= ma->ringc;
 
999
        if (ma->mode & MA_HALO_FLARE) har->flarec= ma->flarec;
 
1000
 
 
1001
 
 
1002
        if (ma->mtex[0]) {
 
1003
 
 
1004
                if ( (ma->mode & MA_HALOTEX) ) har->tex= 1;
 
1005
                else if (har->mat->septex & (1<<0));    /* only 1 level textures */
1026
1006
                else {
1027
1007
 
1028
1008
                        mtex= ma->mtex[0];
1029
 
                        VECCOPY(texvec, vec);
 
1009
                        copy_v3_v3(texvec, vec);
1030
1010
 
1031
 
                        if(mtex->texco & TEXCO_NORM) {
 
1011
                        if (mtex->texco & TEXCO_NORM) {
1032
1012
                                ;
1033
1013
                        }
1034
 
                        else if(mtex->texco & TEXCO_OBJECT) {
 
1014
                        else if (mtex->texco & TEXCO_OBJECT) {
1035
1015
                                /* texvec[0]+= imatbase->ivec[0]; */
1036
1016
                                /* texvec[1]+= imatbase->ivec[1]; */
1037
1017
                                /* texvec[2]+= imatbase->ivec[2]; */
1038
1018
                                /* mul_m3_v3(imatbase->imat, texvec); */
1039
1019
                        }
1040
1020
                        else {
1041
 
                                if(orco) {
1042
 
                                        VECCOPY(texvec, orco);
 
1021
                                if (orco) {
 
1022
                                        copy_v3_v3(texvec, orco);
1043
1023
                                }
1044
1024
                        }
1045
1025
 
1046
 
                        externtex(mtex, texvec, &tin, &tr, &tg, &tb, &ta);
 
1026
                        externtex(mtex, texvec, &tin, &tr, &tg, &tb, &ta, 0);
1047
1027
 
1048
1028
                        yn= tin*mtex->colfac;
1049
 
                        zn= tin*mtex->alphafac;
 
1029
                        //zn= tin*mtex->alphafac;
1050
1030
 
1051
 
                        if(mtex->mapto & MAP_COL) {
1052
 
                                zn= 1.0-yn;
 
1031
                        if (mtex->mapto & MAP_COL) {
 
1032
                                zn= 1.0f-yn;
1053
1033
                                har->r= (yn*tr+ zn*ma->r);
1054
1034
                                har->g= (yn*tg+ zn*ma->g);
1055
1035
                                har->b= (yn*tb+ zn*ma->b);
1056
1036
                        }
1057
 
                        if(mtex->texco & TEXCO_UV) {
 
1037
                        if (mtex->texco & TEXCO_UV) {
1058
1038
                                har->alfa= tin;
1059
1039
                        }
1060
 
                        if(mtex->mapto & MAP_ALPHA)
 
1040
                        if (mtex->mapto & MAP_ALPHA)
1061
1041
                                har->alfa= tin;
1062
1042
                }
1063
1043
        }
1066
1046
}
1067
1047
 
1068
1048
HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Material *ma,   float *vec,   float *vec1, 
1069
 
                                  float *orco, float *uvco, float hasize, float vectsize, int seed)
 
1049
                                  float *orco, float *uvco, float hasize, float vectsize, int seed, float *pa_co)
1070
1050
{
1071
1051
        HaloRen *har;
1072
1052
        MTex *mtex;
1073
1053
        float tin, tr, tg, tb, ta;
1074
1054
        float xn, yn, zn, texvec[3], hoco[4], hoco1[4], in[3],tex[3],out[3];
1075
 
        int i;
 
1055
        int i, hasrgb;
1076
1056
 
1077
 
        if(hasize==0.0) return NULL;
 
1057
        if (hasize==0.0f) return NULL;
1078
1058
 
1079
1059
        projectverto(vec, re->winmat, hoco);
1080
 
        if(hoco[3]==0.0) return NULL;
1081
 
        if(vec1) {
 
1060
        if (hoco[3]==0.0f) return NULL;
 
1061
        if (vec1) {
1082
1062
                projectverto(vec1, re->winmat, hoco1);
1083
 
                if(hoco1[3]==0.0) return NULL;
 
1063
                if (hoco1[3]==0.0f) return NULL;
1084
1064
        }
1085
1065
 
1086
1066
        har= RE_findOrAddHalo(obr, obr->tothalo++);
1087
 
        VECCOPY(har->co, vec);
 
1067
        copy_v3_v3(har->co, vec);
1088
1068
        har->hasize= hasize;
1089
1069
 
1090
1070
        /* actual projectvert is done in function project_renderdata() because of parts/border/pano */
1091
1071
        /* we do it here for sorting of halos */
1092
1072
        zn= hoco[3];
1093
 
        har->xs= 0.5*re->winx*(hoco[0]/zn);
1094
 
        har->ys= 0.5*re->winy*(hoco[1]/zn);
 
1073
        har->xs= 0.5f*re->winx*(hoco[0]/zn);
 
1074
        har->ys= 0.5f*re->winy*(hoco[1]/zn);
1095
1075
        har->zs= 0x7FFFFF*(hoco[2]/zn);
1096
1076
        
1097
1077
        har->zBufDist = 0x7FFFFFFF*(hoco[2]/zn); 
1098
1078
        
1099
1079
        /* halovect */
1100
 
        if(vec1) {
 
1080
        if (vec1) {
1101
1081
 
1102
1082
                har->type |= HA_VECT;
1103
1083
 
1104
 
                xn=  har->xs - 0.5*re->winx*(hoco1[0]/hoco1[3]);
1105
 
                yn=  har->ys - 0.5*re->winy*(hoco1[1]/hoco1[3]);
1106
 
                if(xn==0.0 || (xn==0.0 && yn==0.0)) zn= 0.0;
 
1084
                xn=  har->xs - 0.5f*re->winx*(hoco1[0]/hoco1[3]);
 
1085
                yn=  har->ys - 0.5f*re->winy*(hoco1[1]/hoco1[3]);
 
1086
                if (xn==0.0f || (xn==0.0f && yn==0.0f)) zn= 0.0;
1107
1087
                else zn= atan2(yn, xn);
1108
1088
 
1109
1089
                har->sin= sin(zn);
1110
1090
                har->cos= cos(zn);
1111
 
                zn= len_v3v3(vec1, vec)*0.5;
 
1091
                zn= len_v3v3(vec1, vec)*0.5f;
1112
1092
 
1113
 
                har->hasize= vectsize*zn + (1.0-vectsize)*hasize;
 
1093
                har->hasize= vectsize*zn + (1.0f-vectsize)*hasize;
1114
1094
                
1115
1095
                sub_v3_v3v3(har->no, vec, vec1);
1116
1096
                normalize_v3(har->no);
1117
1097
        }
1118
1098
 
1119
 
        if(ma->mode & MA_HALO_XALPHA) har->type |= HA_XALPHA;
 
1099
        if (ma->mode & MA_HALO_XALPHA) har->type |= HA_XALPHA;
1120
1100
 
1121
1101
        har->alfa= ma->alpha;
1122
1102
        har->r= ma->r;
1123
1103
        har->g= ma->g;
1124
1104
        har->b= ma->b;
1125
 
        har->add= (255.0*ma->add);
 
1105
        har->add= (255.0f*ma->add);
1126
1106
        har->mat= ma;
1127
1107
        har->hard= ma->har;
1128
1108
        har->seed= seed % 256;
1129
1109
 
1130
 
        if(ma->mode & MA_STAR) har->starpoints= ma->starc;
1131
 
        if(ma->mode & MA_HALO_LINES) har->linec= ma->linec;
1132
 
        if(ma->mode & MA_HALO_RINGS) har->ringc= ma->ringc;
1133
 
        if(ma->mode & MA_HALO_FLARE) har->flarec= ma->flarec;
 
1110
        if (ma->mode & MA_STAR) har->starpoints= ma->starc;
 
1111
        if (ma->mode & MA_HALO_LINES) har->linec= ma->linec;
 
1112
        if (ma->mode & MA_HALO_RINGS) har->ringc= ma->ringc;
 
1113
        if (ma->mode & MA_HALO_FLARE) har->flarec= ma->flarec;
1134
1114
 
1135
 
        if((ma->mode & MA_HALOTEX) && ma->mtex[0]){
 
1115
        if ((ma->mode & MA_HALOTEX) && ma->mtex[0])
1136
1116
                har->tex= 1;
1137
 
                i=1;
1138
 
        }
1139
1117
        
1140
 
        for(i=0; i<MAX_MTEX; i++)
1141
 
                if(ma->mtex[i] && (ma->septex & (1<<i))==0) {
 
1118
        for (i=0; i<MAX_MTEX; i++)
 
1119
                if (ma->mtex[i] && (ma->septex & (1<<i))==0) {
1142
1120
                        mtex= ma->mtex[i];
1143
 
                        VECCOPY(texvec, vec);
 
1121
                        copy_v3_v3(texvec, vec);
1144
1122
 
1145
 
                        if(mtex->texco & TEXCO_NORM) {
 
1123
                        if (mtex->texco & TEXCO_NORM) {
1146
1124
                                ;
1147
1125
                        }
1148
 
                        else if(mtex->texco & TEXCO_OBJECT) {
1149
 
                                if(mtex->object){
1150
 
                                        float imat[4][4];
1151
 
                                        /* imat should really be cached somewhere before this */
1152
 
                                        invert_m4_m4(imat,mtex->object->obmat);
1153
 
                                        mul_m4_v3(imat,texvec);
1154
 
                                }
1155
 
                                /* texvec[0]+= imatbase->ivec[0]; */
1156
 
                                /* texvec[1]+= imatbase->ivec[1]; */
1157
 
                                /* texvec[2]+= imatbase->ivec[2]; */
1158
 
                                /* mul_m3_v3(imatbase->imat, texvec); */
1159
 
                        }
1160
 
                        else if(mtex->texco & TEXCO_GLOB){
1161
 
                                VECCOPY(texvec,vec);
1162
 
                        }
1163
 
                        else if(mtex->texco & TEXCO_UV && uvco){
 
1126
                        else if (mtex->texco & TEXCO_OBJECT) {
 
1127
                                if (mtex->object)
 
1128
                                        mul_m4_v3(mtex->object->imat_ren,texvec);
 
1129
                        }
 
1130
                        else if (mtex->texco & TEXCO_GLOB) {
 
1131
                                copy_v3_v3(texvec,vec);
 
1132
                        }
 
1133
                        else if (mtex->texco & TEXCO_UV && uvco) {
1164
1134
                                int uv_index=CustomData_get_named_layer_index(&dm->faceData,CD_MTFACE,mtex->uvname);
1165
 
                                if(uv_index<0)
 
1135
                                if (uv_index<0)
1166
1136
                                        uv_index=CustomData_get_active_layer_index(&dm->faceData,CD_MTFACE);
1167
1137
 
1168
1138
                                uv_index-=CustomData_get_layer_index(&dm->faceData,CD_MTFACE);
1171
1141
                                texvec[1]=2.0f*uvco[2*uv_index+1]-1.0f;
1172
1142
                                texvec[2]=0.0f;
1173
1143
                        }
1174
 
                        else if(orco) {
1175
 
                                VECCOPY(texvec, orco);
 
1144
                        else if (mtex->texco & TEXCO_PARTICLE) {
 
1145
                                /* particle coordinates in range [0,1] */
 
1146
                                texvec[0] = 2.f * pa_co[0] - 1.f;
 
1147
                                texvec[1] = 2.f * pa_co[1] - 1.f;
 
1148
                                texvec[2] = pa_co[2];
 
1149
                        }
 
1150
                        else if (orco) {
 
1151
                                copy_v3_v3(texvec, orco);
1176
1152
                        }
1177
1153
 
1178
 
                        externtex(mtex, texvec, &tin, &tr, &tg, &tb, &ta);
 
1154
                        hasrgb = externtex(mtex, texvec, &tin, &tr, &tg, &tb, &ta, 0);
1179
1155
 
1180
1156
                        //yn= tin*mtex->colfac;
1181
1157
                        //zn= tin*mtex->alphafac;
1182
 
                        if(mtex->mapto & MAP_COL) {
 
1158
                        if (mtex->mapto & MAP_COL) {
1183
1159
                                tex[0]=tr;
1184
1160
                                tex[1]=tg;
1185
1161
                                tex[2]=tb;
1196
1172
                                har->g= in[1];
1197
1173
                                har->b= in[2];
1198
1174
                        }
1199
 
                        if(mtex->mapto & MAP_ALPHA)
 
1175
 
 
1176
                        /* alpha returned, so let's use it instead of intensity */
 
1177
                        if (hasrgb)
 
1178
                                tin = ta;
 
1179
 
 
1180
                        if (mtex->mapto & MAP_ALPHA)
1200
1181
                                har->alfa = texture_value_blend(mtex->def_var,har->alfa,tin,mtex->alphafac,mtex->blendtype);
1201
 
                        if(mtex->mapto & MAP_HAR)
1202
 
                                har->hard = 1.0+126.0*texture_value_blend(mtex->def_var,((float)har->hard)/127.0,tin,mtex->hardfac,mtex->blendtype);
1203
 
                        if(mtex->mapto & MAP_RAYMIRR)
1204
 
                                har->hasize = 100.0*texture_value_blend(mtex->def_var,har->hasize/100.0,tin,mtex->raymirrfac,mtex->blendtype);
 
1182
                        if (mtex->mapto & MAP_HAR)
 
1183
                                har->hard = 1.0f+126.0f*texture_value_blend(mtex->def_var,((float)har->hard)/127.0f,tin,mtex->hardfac,mtex->blendtype);
 
1184
                        if (mtex->mapto & MAP_RAYMIRR)
 
1185
                                har->hasize = 100.0f*texture_value_blend(mtex->def_var,har->hasize/100.0f,tin,mtex->raymirrfac,mtex->blendtype);
 
1186
                        if (mtex->mapto & MAP_TRANSLU) {
 
1187
                                float add = texture_value_blend(mtex->def_var,(float)har->add/255.0f,tin,mtex->translfac,mtex->blendtype);
 
1188
                                CLAMP(add, 0.f, 1.f);
 
1189
                                har->add = 255.0f*add;
 
1190
                        }
1205
1191
                        /* now what on earth is this good for?? */
1206
 
                        //if(mtex->texco & 16) {
 
1192
                        //if (mtex->texco & 16) {
1207
1193
                        //      har->alfa= tin;
1208
1194
                        //}
1209
1195
                }
1220
1206
        float abs4;
1221
1207
        short c=0;
1222
1208
 
1223
 
        if(do_pano==0) return testclip(v);
 
1209
        if (do_pano==0) return testclip(v);
1224
1210
 
1225
1211
        abs4= fabs(v[3]);
1226
1212
 
1227
 
        if(v[2]< -abs4) c=16;           /* this used to be " if(v[2]<0) ", see clippz() */
1228
 
        else if(v[2]> abs4) c+= 32;
 
1213
        if (v[2]< -abs4) c=16;          /* this used to be " if (v[2]<0) ", see clippz() */
 
1214
        else if (v[2]> abs4) c+= 32;
1229
1215
 
1230
 
        if( v[1]>abs4) c+=4;
1231
 
        else if( v[1]< -abs4) c+=8;
 
1216
        if ( v[1]>abs4) c+=4;
 
1217
        else if ( v[1]< -abs4) c+=8;
1232
1218
 
1233
1219
        abs4*= re->xparts;
1234
 
        if( v[0]>abs4) c+=2;
1235
 
        else if( v[0]< -abs4) c+=1;
 
1220
        if ( v[0]>abs4) c+=2;
 
1221
        else if ( v[0]< -abs4) c+=1;
1236
1222
 
1237
1223
        return c;
1238
1224
}
1239
1225
 
1240
 
/*
1241
 
  This adds the hcs coordinates to vertices. It iterates over all
1242
 
  vertices, halos and faces. After the conversion, we clip in hcs.
1243
 
 
1244
 
  Elsewhere, all primites are converted to vertices. 
1245
 
  Called in 
1246
 
  - envmapping (envmap.c)
1247
 
  - shadow buffering (shadbuf.c)
1248
 
*/
1249
 
 
1250
 
void project_renderdata(Render *re, void (*projectfunc)(float *, float mat[][4], float *),  int do_pano, float xoffs, int do_buckets)
 
1226
/**
 
1227
 * This adds the hcs coordinates to vertices. It iterates over all
 
1228
 * vertices, halos and faces. After the conversion, we clip in hcs.
 
1229
 *
 
1230
 * Elsewhere, all primites are converted to vertices.
 
1231
 * Called in
 
1232
 * - envmapping (envmap.c)
 
1233
 * - shadow buffering (shadbuf.c)
 
1234
 */
 
1235
 
 
1236
void project_renderdata(Render *re, void (*projectfunc)(const float *, float mat[][4], float *),  int do_pano, float xoffs, int UNUSED(do_buckets))
1251
1237
{
1252
1238
        ObjectRen *obr;
1253
1239
        HaloRen *har = NULL;
1254
1240
        float zn, vec[3], hoco[4];
1255
1241
        int a;
1256
1242
 
1257
 
        if(do_pano) {
 
1243
        if (do_pano) {
1258
1244
                float panophi= xoffs;
1259
1245
                
1260
1246
                re->panosi= sin(panophi);
1261
1247
                re->panoco= cos(panophi);
1262
1248
        }
1263
1249
 
1264
 
        for(obr=re->objecttable.first; obr; obr=obr->next) {
 
1250
        for (obr=re->objecttable.first; obr; obr=obr->next) {
1265
1251
                /* calculate view coordinates (and zbuffer value) */
1266
 
                for(a=0; a<obr->tothalo; a++) {
1267
 
                        if((a & 255)==0) har= obr->bloha[a>>8];
 
1252
                for (a=0; a<obr->tothalo; a++) {
 
1253
                        if ((a & 255)==0) har= obr->bloha[a>>8];
1268
1254
                        else har++;
1269
1255
 
1270
 
                        if(do_pano) {
 
1256
                        if (do_pano) {
1271
1257
                                vec[0]= re->panoco*har->co[0] + re->panosi*har->co[2];
1272
1258
                                vec[1]= har->co[1];
1273
1259
                                vec[2]= -re->panosi*har->co[0] + re->panoco*har->co[2];
1274
1260
                        }
1275
1261
                        else {
1276
 
                                VECCOPY(vec, har->co);
 
1262
                                copy_v3_v3(vec, har->co);
1277
1263
                        }
1278
1264
 
1279
1265
                        projectfunc(vec, re->winmat, hoco);
1280
1266
                        
1281
1267
                        /* we clip halos less critical, but not for the Z */
1282
 
                        hoco[0]*= 0.5;
1283
 
                        hoco[1]*= 0.5;
 
1268
                        hoco[0]*= 0.5f;
 
1269
                        hoco[1]*= 0.5f;
1284
1270
                        
1285
 
                        if( panotestclip(re, do_pano, hoco) ) {
 
1271
                        if ( panotestclip(re, do_pano, hoco) ) {
1286
1272
                                har->miny= har->maxy= -10000;   /* that way render clips it */
1287
1273
                        }
1288
 
                        else if(hoco[3]<0.0) {
 
1274
                        else if (hoco[3]<0.0f) {
1289
1275
                                har->miny= har->maxy= -10000;   /* render clips it */
1290
1276
                        }
1291
1277
                        else /* do the projection...*/
1292
1278
                        {
1293
1279
                                /* bring back hocos */
1294
 
                                hoco[0]*= 2.0;
1295
 
                                hoco[1]*= 2.0;
 
1280
                                hoco[0]*= 2.0f;
 
1281
                                hoco[1]*= 2.0f;
1296
1282
                                
1297
1283
                                zn= hoco[3];
1298
 
                                har->xs= 0.5*re->winx*(1.0+hoco[0]/zn); /* the 0.5 negates the previous 2...*/
1299
 
                                har->ys= 0.5*re->winy*(1.0+hoco[1]/zn);
 
1284
                                har->xs= 0.5f*re->winx*(1.0f+hoco[0]/zn); /* the 0.5 negates the previous 2...*/
 
1285
                                har->ys= 0.5f*re->winy*(1.0f+hoco[1]/zn);
1300
1286
                        
1301
1287
                                /* this should be the zbuffer coordinate */
1302
1288
                                har->zs= 0x7FFFFF*(hoco[2]/zn);
1307
1293
                                projectfunc(vec, re->winmat, hoco);
1308
1294
                                vec[0]-= har->hasize;
1309
1295
                                zn= hoco[3];
1310
 
                                har->rad= fabs(har->xs- 0.5*re->winx*(1.0+hoco[0]/zn));
 
1296
                                har->rad= fabsf(har->xs- 0.5f*re->winx*(1.0f+hoco[0]/zn));
1311
1297
                        
1312
1298
                                /* this clip is not really OK, to prevent stars to become too large */
1313
 
                                if(har->type & HA_ONLYSKY) {
1314
 
                                        if(har->rad>3.0) har->rad= 3.0;
 
1299
                                if (har->type & HA_ONLYSKY) {
 
1300
                                        if (har->rad>3.0f) har->rad= 3.0f;
1315
1301
                                }
1316
1302
                        
1317
1303
                                har->radsq= har->rad*har->rad;
1348
1334
        obi->psysindex= psysindex;
1349
1335
        obi->lay= lay;
1350
1336
 
1351
 
        if(mat) {
 
1337
        if (mat) {
1352
1338
                copy_m4_m4(obi->mat, mat);
1353
1339
                copy_m3_m4(mat3, mat);
1354
1340
                invert_m3_m3(obi->nmat, mat3);
1374
1360
        newlist.first= newlist.last= NULL;
1375
1361
 
1376
1362
        obi= re->objectinstance;
1377
 
        for(oldobi=re->instancetable.first; oldobi; oldobi=oldobi->next) {
 
1363
        for (oldobi=re->instancetable.first; oldobi; oldobi=oldobi->next) {
1378
1364
                *obi= *oldobi;
1379
1365
 
1380
 
                if(obi->obr) {
 
1366
                if (obi->obr) {
1381
1367
                        obi->prev= obi->next= NULL;
1382
1368
                        BLI_addtail(&newlist, obi);
1383
1369
                        obi++;
1397
1383
 
1398
1384
        copy_m4_m4(mat, winmat);
1399
1385
 
1400
 
        for(a=0; a<8; a++) {
 
1386
        for (a=0; a<8; a++) {
1401
1387
                vec[0]= (a & 1)? boundbox[0][0]: boundbox[1][0];
1402
1388
                vec[1]= (a & 2)? boundbox[0][1]: boundbox[1][1];
1403
1389
                vec[2]= (a & 4)? boundbox[0][2]: boundbox[1][2];
1405
1391
                mul_m4_v4(mat, vec);
1406
1392
 
1407
1393
                fl= 0;
1408
 
                if(bounds) {
1409
 
                        if(vec[0] > bounds[1]*vec[3]) fl |= 1;
1410
 
                        if(vec[0]< bounds[0]*vec[3]) fl |= 2;
1411
 
                        if(vec[1] > bounds[3]*vec[3]) fl |= 4;
1412
 
                        if(vec[1]< bounds[2]*vec[3]) fl |= 8;
 
1394
                if (bounds) {
 
1395
                        if (vec[0] < bounds[0]*vec[3]) fl |= 1;
 
1396
                        else if (vec[0] > bounds[1]*vec[3]) fl |= 2;
 
1397
                        
 
1398
                        if (vec[1] > bounds[3]*vec[3]) fl |= 4;
 
1399
                        else if (vec[1]< bounds[2]*vec[3]) fl |= 8;
1413
1400
                }
1414
1401
                else {
1415
 
                        if(vec[0] < -vec[3]) fl |= 1;
1416
 
                        if(vec[0] > vec[3]) fl |= 2;
1417
 
                        if(vec[1] < -vec[3]) fl |= 4;
1418
 
                        if(vec[1] > vec[3]) fl |= 8;
 
1402
                        if (vec[0] < -vec[3]) fl |= 1;
 
1403
                        else if (vec[0] > vec[3]) fl |= 2;
 
1404
                        
 
1405
                        if (vec[1] > vec[3]) fl |= 4;
 
1406
                        else if (vec[1] < -vec[3]) fl |= 8;
1419
1407
                }
1420
 
                if(vec[2] < -vec[3]) fl |= 16;
1421
 
                if(vec[2] > vec[3]) fl |= 32;
 
1408
                if (vec[2] < -vec[3]) fl |= 16;
 
1409
                else if (vec[2] > vec[3]) fl |= 32;
1422
1410
 
1423
1411
                flag &= fl;
1424
 
                if(flag==0) return 0;
 
1412
                if (flag==0) return 0;
1425
1413
        }
1426
1414
 
1427
1415
        return flag;