~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/render/intern/source/envmap.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
1
/* 
2
 
 * $Id: envmap.c 28395 2010-04-23 23:57:00Z campbellbarton $
3
2
 *
4
3
 * ***** BEGIN GPL LICENSE BLOCK *****
5
4
 *
25
24
 * ***** END GPL LICENSE BLOCK *****
26
25
 */
27
26
 
 
27
/** \file blender/render/intern/source/envmap.c
 
28
 *  \ingroup render
 
29
 */
 
30
 
 
31
 
28
32
#include <math.h>
29
33
#include <string.h>
30
34
 
34
38
#include "BLI_math.h"
35
39
#include "BLI_blenlib.h"
36
40
#include "BLI_threads.h"
 
41
#include "BLI_utildefines.h"
37
42
 
38
43
#include "IMB_imbuf_types.h"
39
44
#include "IMB_imbuf.h"        /* for rectcpy */
46
51
 
47
52
#include "BKE_library.h"
48
53
#include "BKE_main.h"
49
 
#include "BKE_global.h"
50
54
#include "BKE_image.h"   // BKE_write_ibuf 
51
55
#include "BKE_texture.h"
52
 
#include "BKE_utildefines.h"
 
56
 
53
57
 
54
58
 
55
59
 
70
74
{
71
75
        int dx, part;
72
76
        
73
 
        BKE_free_envmapdata(env);       
74
 
        
75
 
        dx= ibuf->y;
76
 
        dx/= 2;
77
 
        if (3*dx == ibuf->x) {
78
 
                env->type = ENV_CUBE;
79
 
        } else if (ibuf->x == ibuf->y) {
80
 
                env->type = ENV_PLANE;
81
 
        } else {
82
 
                printf("Incorrect envmap size\n");
83
 
                env->ok= 0;
84
 
                env->ima->ok= 0;
85
 
                return;
86
 
        }
87
 
        
88
 
        if (env->type == ENV_CUBE) {
89
 
                for(part=0; part<6; part++) {
90
 
                        env->cube[part]= IMB_allocImBuf(dx, dx, 24, IB_rect|IB_rectfloat, 0);
91
 
                }
92
 
                IMB_float_from_rect(ibuf);
93
 
                
94
 
                IMB_rectcpy(env->cube[0], ibuf, 
95
 
                        0, 0, 0, 0, dx, dx);
96
 
                IMB_rectcpy(env->cube[1], ibuf, 
97
 
                        0, 0, dx, 0, dx, dx);
98
 
                IMB_rectcpy(env->cube[2], ibuf, 
99
 
                        0, 0, 2*dx, 0, dx, dx);
100
 
                IMB_rectcpy(env->cube[3], ibuf, 
101
 
                        0, 0, 0, dx, dx, dx);
102
 
                IMB_rectcpy(env->cube[4], ibuf, 
103
 
                        0, 0, dx, dx, dx, dx);
104
 
                IMB_rectcpy(env->cube[5], ibuf, 
105
 
                        0, 0, 2*dx, dx, dx, dx);
106
 
                env->ok= ENV_OSA;
107
 
        }
108
 
        else { /* ENV_PLANE */
109
 
                env->cube[1]= IMB_dupImBuf(ibuf);
110
 
                IMB_float_from_rect(env->cube[1]);
111
 
                
112
 
                env->ok= ENV_OSA;
113
 
        }
 
77
        /* after lock we test cube[1], if set the other thread has done it fine */
 
78
        BLI_lock_thread(LOCK_IMAGE);
 
79
        if (env->cube[1]==NULL) {
 
80
 
 
81
                BKE_free_envmapdata(env);       
 
82
        
 
83
                dx= ibuf->y;
 
84
                dx/= 2;
 
85
                if (3*dx == ibuf->x) {
 
86
                        env->type = ENV_CUBE;
 
87
                        env->ok= ENV_OSA;
 
88
                }
 
89
                else if (ibuf->x == ibuf->y) {
 
90
                        env->type = ENV_PLANE;
 
91
                        env->ok= ENV_OSA;
 
92
                }
 
93
                else {
 
94
                        printf("Incorrect envmap size\n");
 
95
                        env->ok= 0;
 
96
                        env->ima->ok= 0;
 
97
                }
 
98
                
 
99
                if (env->ok) {
 
100
                        if (env->type == ENV_CUBE) {
 
101
                                for (part=0; part<6; part++) {
 
102
                                        env->cube[part]= IMB_allocImBuf(dx, dx, 24, IB_rect|IB_rectfloat);
 
103
                                }
 
104
                                IMB_float_from_rect(ibuf);
 
105
                                
 
106
                                IMB_rectcpy(env->cube[0], ibuf, 
 
107
                                        0, 0, 0, 0, dx, dx);
 
108
                                IMB_rectcpy(env->cube[1], ibuf, 
 
109
                                        0, 0, dx, 0, dx, dx);
 
110
                                IMB_rectcpy(env->cube[2], ibuf, 
 
111
                                        0, 0, 2*dx, 0, dx, dx);
 
112
                                IMB_rectcpy(env->cube[3], ibuf, 
 
113
                                        0, 0, 0, dx, dx, dx);
 
114
                                IMB_rectcpy(env->cube[4], ibuf, 
 
115
                                        0, 0, dx, dx, dx, dx);
 
116
                                IMB_rectcpy(env->cube[5], ibuf, 
 
117
                                        0, 0, 2*dx, dx, dx, dx);
 
118
                                
 
119
                        }
 
120
                        else { /* ENV_PLANE */
 
121
                                env->cube[1]= IMB_dupImBuf(ibuf);
 
122
                                IMB_float_from_rect(env->cube[1]);
 
123
                        }
 
124
                }
 
125
        }       
 
126
        BLI_unlock_thread(LOCK_IMAGE);
114
127
}
115
128
 
116
129
/* ------------------------------------------------------------------------- */
120
133
static Render *envmap_render_copy(Render *re, EnvMap *env)
121
134
{
122
135
        Render *envre;
 
136
        float viewscale;
123
137
        int cuberes;
124
138
        
125
139
        envre= RE_NewRender("Envmap");
137
151
        envre->r.layers.first= envre->r.layers.last= NULL;
138
152
        envre->r.filtertype= 0;
139
153
        envre->r.xparts= envre->r.yparts= 2;
140
 
        envre->r.bufflag= 0;
141
154
        envre->r.size= 100;
142
155
        envre->r.yasp= envre->r.xasp= 1;
143
156
        
146
159
        envre->lay= re->lay;
147
160
 
148
161
        /* view stuff in env render */
149
 
        envre->lens= 16.0f;
150
 
        if(env->type==ENV_PLANE)
151
 
                envre->lens*= env->viewscale;
152
 
        envre->ycor= 1.0f; 
153
 
        envre->clipsta= env->clipsta;   /* render_scene_set_window() respects this for now */
154
 
        envre->clipend= env->clipend;
155
 
        
156
 
        RE_SetCamera(envre, env->object);
 
162
        viewscale= (env->type == ENV_PLANE)? env->viewscale: 1.0f;
 
163
        RE_SetEnvmapCamera(envre, env->object, viewscale, env->clipsta, env->clipend);
157
164
        
158
165
        /* callbacks */
159
166
        envre->display_draw= re->display_draw;
209
216
        
210
217
        eul[0]= eul[1]= eul[2]= 0.0;
211
218
        
212
 
        if(part==0) {                   /* neg z */
 
219
        if (part==0) {                  /* neg z */
213
220
                ;
214
 
        } else if(part==1) {    /* pos z */
 
221
        }
 
222
        else if (part==1) {     /* pos z */
215
223
                eul[0]= M_PI;
216
 
        } else if(part==2) {    /* pos y */
 
224
        }
 
225
        else if (part==2) {     /* pos y */
217
226
                eul[0]= M_PI/2.0;
218
 
        } else if(part==3) {    /* neg x */
 
227
        }
 
228
        else if (part==3) {     /* neg x */
219
229
                eul[0]= M_PI/2.0;
220
230
                eul[2]= M_PI/2.0;
221
 
        } else if(part==4) {    /* neg y */
 
231
        }
 
232
        else if (part==4) {     /* neg y */
222
233
                eul[0]= M_PI/2.0;
223
234
                eul[2]= M_PI;
224
 
        } else {                                /* pos x */
 
235
        }
 
236
        else {                          /* pos x */
225
237
                eul[0]= M_PI/2.0;
226
238
                eul[2]= -M_PI/2.0;
227
239
        }
229
241
        copy_m4_m4(tmat, mat);
230
242
        eul_to_mat4( rotmat,eul);
231
243
        mul_serie_m4(mat, tmat, rotmat,
232
 
                                         0,   0,    0,
233
 
                                         0,   0,    0);
 
244
                                         NULL, NULL, NULL,
 
245
                                         NULL, NULL, NULL);
234
246
}
235
247
 
236
248
/* ------------------------------------------------------------------------- */
245
257
        float imat[3][3], pmat[4][4], smat[4][4], tmat[4][4], cmat[3][3], tmpmat[4][4];
246
258
        int a;
247
259
        
248
 
        if(mode==0) {
 
260
        if (mode==0) {
249
261
                invert_m4_m4(tmat, mat);
250
262
                copy_m3_m4(imat, tmat);
251
263
        }
254
266
                copy_m3_m4(imat, mat);
255
267
        }
256
268
 
257
 
        for(obi=re->instancetable.first; obi; obi=obi->next) {
 
269
        for (obi=re->instancetable.first; obi; obi=obi->next) {
258
270
                /* append or set matrix depending on dupli */
259
 
                if(obi->flag & R_DUPLI_TRANSFORMED) {
 
271
                if (obi->flag & R_DUPLI_TRANSFORMED) {
260
272
                        copy_m4_m4(tmpmat, obi->mat);
261
 
                        mul_m4_m4m4(obi->mat, tmpmat, tmat);
 
273
                        mult_m4_m4m4(obi->mat, tmat, tmpmat);
262
274
                }
263
 
                else if(mode==1)
 
275
                else if (mode==1)
264
276
                        copy_m4_m4(obi->mat, tmat);
265
277
                else
266
278
                        unit_m4(obi->mat);
270
282
                transpose_m3(obi->nmat);
271
283
 
272
284
                /* indicate the renderer has to use transform matrices */
273
 
                if(mode==0)
 
285
                if (mode==0)
274
286
                        obi->flag &= ~R_ENV_TRANSFORMED;
275
287
                else
276
288
                        obi->flag |= R_ENV_TRANSFORMED;
277
289
        }
278
290
        
279
291
 
280
 
        for(obr=re->objecttable.first; obr; obr=obr->next) {
281
 
                for(a=0; a<obr->tothalo; a++) {
282
 
                        if((a & 255)==0) har= obr->bloha[a>>8];
 
292
        for (obr=re->objecttable.first; obr; obr=obr->next) {
 
293
                for (a=0; a<obr->tothalo; a++) {
 
294
                        if ((a & 255)==0) har= obr->bloha[a>>8];
283
295
                        else har++;
284
296
                
285
297
                        mul_m4_v3(tmat, har->co);
286
298
                }
287
299
        }
288
300
        
289
 
        for(go=re->lights.first; go; go= go->next) {
 
301
        for (go=re->lights.first; go; go= go->next) {
290
302
                lar= go->lampren;
291
303
                
292
304
                /* removed here some horrible code of someone in NaN who tried to fix
293
 
                   prototypes... just solved by introducing a correct cmat[3][3] instead
294
 
                   of using smat. this works, check square spots in reflections  (ton) */
 
305
                 * prototypes... just solved by introducing a correct cmat[3][3] instead
 
306
                 * of using smat. this works, check square spots in reflections  (ton) */
295
307
                copy_m3_m3(cmat, lar->imat); 
296
308
                mul_m3_m3m3(lar->imat, cmat, imat); 
297
309
 
304
316
                mul_m3_v3(lar->imat, lar->sh_invcampos);
305
317
                lar->sh_invcampos[2]*= lar->sh_zfac;
306
318
                
307
 
                if(lar->shb) {
308
 
                        if(mode==1) {
 
319
                if (lar->shb) {
 
320
                        if (mode==1) {
309
321
                                invert_m4_m4(pmat, mat);
310
 
                                mul_m4_m4m4(smat, pmat, lar->shb->viewmat);
311
 
                                mul_m4_m4m4(lar->shb->persmat, smat, lar->shb->winmat);
 
322
                                mult_m4_m4m4(smat, lar->shb->viewmat, pmat);
 
323
                                mult_m4_m4m4(lar->shb->persmat, lar->shb->winmat, smat);
312
324
                        }
313
 
                        else mul_m4_m4m4(lar->shb->persmat, lar->shb->viewmat, lar->shb->winmat);
 
325
                        else mult_m4_m4m4(lar->shb->persmat, lar->shb->winmat, lar->shb->viewmat);
314
326
                }
315
327
        }
316
328
        
325
337
        int a;
326
338
        
327
339
        /* invert notlay, so if face is in multiple layers it will still be visible,
328
 
           unless all 'notlay' bits match the face bits.
329
 
           face: 0110
330
 
           not:  0100
331
 
           ~not: 1011
332
 
           now (face & ~not) is true
333
 
        */
 
340
         * unless all 'notlay' bits match the face bits.
 
341
         * face: 0110
 
342
         * not:  0100
 
343
         * ~not: 1011
 
344
         * now (face & ~not) is true
 
345
         */
334
346
        
335
347
        notlay= ~notlay;
336
348
        
337
 
        for(obr=re->objecttable.first; obr; obr=obr->next) {
338
 
                if((obr->lay & notlay)==0) {
339
 
                        for(a=0; a<obr->totvlak; a++) {
340
 
                                if((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak;
 
349
        for (obr=re->objecttable.first; obr; obr=obr->next) {
 
350
                if ((obr->lay & notlay)==0) {
 
351
                        for (a=0; a<obr->totvlak; a++) {
 
352
                                if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak;
341
353
                                else vlr++;
342
354
 
343
355
                                vlr->flag |= R_HIDDEN;
352
364
        VlakRen *vlr = NULL;
353
365
        int a;
354
366
        
355
 
        for(obr=re->objecttable.first; obr; obr=obr->next) {
356
 
                for(a=0; a<obr->totvlak; a++) {
357
 
                        if((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak;
 
367
        for (obr=re->objecttable.first; obr; obr=obr->next) {
 
368
                for (a=0; a<obr->totvlak; a++) {
 
369
                        if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak;
358
370
                        else vlr++;
359
371
 
360
 
                        if(obr->ob == ob)
 
372
                        if (obr->ob == ob)
361
373
                                vlr->flag |= R_HIDDEN;
362
374
                }
363
375
        }
369
381
        VlakRen *vlr = NULL;
370
382
        int a;
371
383
        
372
 
        for(obr=re->objecttable.first; obr; obr=obr->next) {
373
 
                for(a=0; a<obr->totvlak; a++) {
374
 
                        if((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak;
 
384
        for (obr=re->objecttable.first; obr; obr=obr->next) {
 
385
                for (a=0; a<obr->totvlak; a++) {
 
386
                        if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak;
375
387
                        else vlr++;
376
388
 
377
389
                        vlr->flag &= ~R_HIDDEN;
387
399
        float mat[4][4];
388
400
        
389
401
        base= re->scene->base.first;
390
 
        while(base) {
391
 
                mul_m4_m4m4(mat, base->object->obmat, re->viewmat);
 
402
        while (base) {
 
403
                mult_m4_m4m4(mat, re->viewmat, base->object->obmat);
392
404
                invert_m4_m4(base->object->imat, mat);
393
405
                
394
406
                base= base->next;
417
429
        normalize_m4(orthmat);
418
430
        
419
431
        /* need imat later for texture imat */
420
 
        mul_m4_m4m4(mat, orthmat, re->viewmat);
 
432
        mult_m4_m4m4(mat, re->viewmat, orthmat);
421
433
        invert_m4_m4(tmat, mat);
422
434
        copy_m3_m4(env->obimat, tmat);
423
435
 
424
 
        for(part=0; part<6; part++) {
425
 
                if(env->type==ENV_PLANE && part!=1)
 
436
        for (part=0; part<6; part++) {
 
437
                if (env->type==ENV_PLANE && part!=1)
426
438
                        continue;
427
439
                
428
440
                re->display_clear(re->dch, envre->result);
436
448
                copy_m4_m4(envre->viewinv, tmat);
437
449
                
438
450
                /* we have to correct for the already rotated vertexcoords */
439
 
                mul_m4_m4m4(tmat, oldviewinv, envre->viewmat);
 
451
                mult_m4_m4m4(tmat, envre->viewmat, oldviewinv);
440
452
                invert_m4_m4(env->imat, tmat);
441
453
                
442
454
                env_rotate_scene(envre, tmat, 1);
446
458
                env_hideobject(envre, env->object);
447
459
                env_set_imats(envre);
448
460
                                
449
 
                if(re->test_break(re->tbh)==0) {
 
461
                if (re->test_break(re->tbh)==0) {
450
462
                        RE_TileProcessor(envre);
451
463
                }
452
464
                
454
466
                env_showobjects(envre);
455
467
                env_rotate_scene(envre, tmat, 0);
456
468
 
457
 
                if(re->test_break(re->tbh)==0) {
 
469
                if (re->test_break(re->tbh)==0) {
458
470
                        RenderLayer *rl= envre->result->layers.first;
459
471
                        int y;
460
472
                        float *alpha;
461
473
                        
462
 
                        ibuf= IMB_allocImBuf(envre->rectx, envre->recty, 24, IB_rect|IB_rectfloat, 0);
 
474
                        ibuf= IMB_allocImBuf(envre->rectx, envre->recty, 24, IB_rect|IB_rectfloat);
463
475
                        memcpy(ibuf->rect_float, rl->rectf, ibuf->channels * ibuf->x * ibuf->y * sizeof(float));
464
476
                        
465
477
                        if (re->scene->r.color_mgt_flag & R_COLOR_MANAGEMENT)
467
479
                        
468
480
                        /* envmap renders without alpha */
469
481
                        alpha= ((float *)ibuf->rect_float)+3;
470
 
                        for(y= ibuf->x*ibuf->y - 1; y>=0; y--, alpha+=4)
 
482
                        for (y= ibuf->x*ibuf->y - 1; y>=0; y--, alpha+=4)
471
483
                                *alpha= 1.0;
472
484
                        
473
485
                        env->cube[part]= ibuf;
474
486
                }
475
487
                
476
 
                if(re->test_break(re->tbh)) break;
 
488
                if (re->test_break(re->tbh)) break;
477
489
 
478
490
        }
479
491
        
480
 
        if(re->test_break(re->tbh)) BKE_free_envmapdata(env);
 
492
        if (re->test_break(re->tbh)) BKE_free_envmapdata(env);
481
493
        else {
482
 
                if(envre->r.mode & R_OSA) env->ok= ENV_OSA;
 
494
                if (envre->r.mode & R_OSA) env->ok= ENV_OSA;
483
495
                else env->ok= ENV_NORMAL;
484
496
                env->lastframe= re->scene->r.cfra;
485
497
        }
499
511
        
500
512
        if (!(re->r.mode & R_ENVMAP)) return;
501
513
        
502
 
        /* we dont raytrace, disabling the flag will cause ray_transp render solid */
 
514
        /* we don't raytrace, disabling the flag will cause ray_transp render solid */
503
515
        trace= (re->r.mode & R_RAYTRACE);
504
516
        re->r.mode &= ~R_RAYTRACE;
505
517
 
507
519
        re->stats_draw(re->sdh, &re->i);
508
520
        
509
521
        /* 5 = hardcoded max recursion level */
510
 
        while(depth<5) {
511
 
                tex= G.main->tex.first;
512
 
                while(tex) {
513
 
                        if(tex->id.us && tex->type==TEX_ENVMAP) {
514
 
                                if(tex->env && tex->env->object) {
 
522
        while (depth<5) {
 
523
                tex= re->main->tex.first;
 
524
                while (tex) {
 
525
                        if (tex->id.us && tex->type==TEX_ENVMAP) {
 
526
                                if (tex->env && tex->env->object) {
515
527
                                        EnvMap *env= tex->env;
516
528
                                        
517
 
                                        if(env->object->lay & re->lay) {
518
 
                                                if(env->stype==ENV_LOAD) {
 
529
                                        if (env->object->lay & re->lay) {
 
530
                                                if (env->stype==ENV_LOAD) {
519
531
                                                        float orthmat[4][4], mat[4][4], tmat[4][4];
520
532
                                                        
521
533
                                                        /* precalc orthmat for object */
523
535
                                                        normalize_m4(orthmat);
524
536
                                                        
525
537
                                                        /* need imat later for texture imat */
526
 
                                                        mul_m4_m4m4(mat, orthmat, re->viewmat);
 
538
                                                        mult_m4_m4m4(mat, re->viewmat, orthmat);
527
539
                                                        invert_m4_m4(tmat, mat);
528
540
                                                        copy_m3_m4(env->obimat, tmat);
529
541
                                                }
530
542
                                                else {
531
543
                                                        
532
544
                                                        /* decide if to render an envmap (again) */
533
 
                                                        if(env->depth >= depth) {
 
545
                                                        if (env->depth >= depth) {
534
546
                                                                
535
547
                                                                /* set 'recalc' to make sure it does an entire loop of recalcs */
536
548
                                                                
537
 
                                                                if(env->ok) {
 
549
                                                                if (env->ok) {
538
550
                                                                                /* free when OSA, and old one isn't OSA */
539
 
                                                                        if((re->r.mode & R_OSA) && env->ok==ENV_NORMAL) 
 
551
                                                                        if ((re->r.mode & R_OSA) && env->ok==ENV_NORMAL)
540
552
                                                                                BKE_free_envmapdata(env);
541
553
                                                                                /* free when size larger */
542
 
                                                                        else if(env->lastsize < re->r.size) 
 
554
                                                                        else if (env->lastsize < re->r.size)
543
555
                                                                                BKE_free_envmapdata(env);
544
556
                                                                                /* free when env is in recalcmode */
545
 
                                                                        else if(env->recalc)
 
557
                                                                        else if (env->recalc)
546
558
                                                                                BKE_free_envmapdata(env);
547
559
                                                                }
548
560
                                                                
549
 
                                                                if(env->ok==0 && depth==0) env->recalc= 1;
 
561
                                                                if (env->ok==0 && depth==0) env->recalc= 1;
550
562
                                                                
551
 
                                                                if(env->ok==0) {
 
563
                                                                if (env->ok==0) {
552
564
                                                                        do_init= 1;
553
565
                                                                        render_envmap(re, env);
554
566
                                                                        
555
 
                                                                        if(depth==env->depth) env->recalc= 0;
 
567
                                                                        if (depth==env->depth) env->recalc= 0;
556
568
                                                                }
557
569
                                                        }
558
570
                                                }
564
576
                depth++;
565
577
        }
566
578
 
567
 
        if(do_init) {
 
579
        if (do_init) {
568
580
                re->display_init(re->dih, re->result);
569
581
                re->display_clear(re->dch, re->result);
570
582
                // re->flag |= R_REDRAW_PRV;
581
593
        float labda;
582
594
        int face;
583
595
        
584
 
        if(env->type==ENV_PLANE) {
 
596
        if (env->type==ENV_PLANE) {
585
597
                face= 1;
586
598
                
587
 
                labda= 1.0/vec[2];
 
599
                labda= 1.0f/vec[2];
588
600
                answ[0]= env->viewscale*labda*vec[0];
589
601
                answ[1]= -env->viewscale*labda*vec[1];
590
602
        }
591
603
        else {
592
604
                /* which face */
593
 
                if( vec[2]<=-fabs(vec[0]) && vec[2]<=-fabs(vec[1]) ) {
 
605
                if ( vec[2] <= -fabsf(vec[0]) && vec[2] <= -fabsf(vec[1]) ) {
594
606
                        face= 0;
595
 
                        labda= -1.0/vec[2];
 
607
                        labda= -1.0f/vec[2];
596
608
                        answ[0]= labda*vec[0];
597
609
                        answ[1]= labda*vec[1];
598
610
                }
599
 
                else if( vec[2]>=fabs(vec[0]) && vec[2]>=fabs(vec[1]) ) {
 
611
                else if (vec[2] >= fabsf(vec[0]) && vec[2] >= fabsf(vec[1])) {
600
612
                        face= 1;
601
 
                        labda= 1.0/vec[2];
 
613
                        labda= 1.0f/vec[2];
602
614
                        answ[0]= labda*vec[0];
603
615
                        answ[1]= -labda*vec[1];
604
616
                }
605
 
                else if( vec[1]>=fabs(vec[0]) ) {
 
617
                else if (vec[1] >= fabsf(vec[0])) {
606
618
                        face= 2;
607
 
                        labda= 1.0/vec[1];
 
619
                        labda= 1.0f/vec[1];
608
620
                        answ[0]= labda*vec[0];
609
621
                        answ[1]= labda*vec[2];
610
622
                }
611
 
                else if( vec[0]<=-fabs(vec[1]) ) {
 
623
                else if (vec[0] <= -fabsf(vec[1])) {
612
624
                        face= 3;
613
 
                        labda= -1.0/vec[0];
 
625
                        labda= -1.0f/vec[0];
614
626
                        answ[0]= labda*vec[1];
615
627
                        answ[1]= labda*vec[2];
616
628
                }
617
 
                else if( vec[1]<=-fabs(vec[0]) ) {
 
629
                else if (vec[1] <= -fabsf(vec[0])) {
618
630
                        face= 4;
619
 
                        labda= -1.0/vec[1];
 
631
                        labda= -1.0f/vec[1];
620
632
                        answ[0]= -labda*vec[0];
621
633
                        answ[1]= labda*vec[2];
622
634
                }
623
635
                else {
624
636
                        face= 5;
625
 
                        labda= 1.0/vec[0];
 
637
                        labda= 1.0f/vec[0];
626
638
                        answ[0]= -labda*vec[1];
627
639
                        answ[1]= labda*vec[2];
628
640
                }
629
641
        }
630
642
        
631
 
        answ[0]= 0.5+0.5*answ[0];
632
 
        answ[1]= 0.5+0.5*answ[1];
 
643
        answ[0]= 0.5f+0.5f*answ[0];
 
644
        answ[1]= 0.5f+0.5f*answ[1];
633
645
        return face;
634
646
}
635
647
 
637
649
 
638
650
static void set_dxtdyt(float *dxts, float *dyts, float *dxt, float *dyt, int face)
639
651
{
640
 
        if(face==2 || face==4) {
 
652
        if (face==2 || face==4) {
641
653
                dxts[0]= dxt[0];
642
654
                dyts[0]= dyt[0];
643
655
                dxts[1]= dxt[2];
644
656
                dyts[1]= dyt[2];
645
657
        }
646
 
        else if(face==3 || face==5) {
 
658
        else if (face==3 || face==5) {
647
659
                dxts[0]= dxt[1];
648
660
                dxts[1]= dxt[2];
649
661
                dyts[0]= dyt[1];
669
681
        int face, face1;
670
682
        
671
683
        env= tex->env;
672
 
        if(env==NULL || (env->stype!=ENV_LOAD && env->object==NULL)) {
 
684
        if (env==NULL || (env->stype!=ENV_LOAD && env->object==NULL)) {
673
685
                texres->tin= 0.0;
674
686
                return 0;
675
687
        }
676
688
        
677
 
        if(env->stype==ENV_LOAD) {
 
689
        if (env->stype==ENV_LOAD) {
678
690
                env->ima= tex->ima;
679
 
                if(env->ima && env->ima->ok) {
680
 
                        if(env->cube[1]==NULL) {
681
 
                                ImBuf *ibuf= BKE_image_get_ibuf(env->ima, NULL);
682
 
                                if(ibuf)
683
 
                                        envmap_split_ima(env, ibuf);
 
691
                if (env->ima && env->ima->ok) {
 
692
                        if (env->cube[1]==NULL) {
 
693
                                ImBuf *ibuf_ima= BKE_image_get_ibuf(env->ima, NULL);
 
694
                                if (ibuf_ima)
 
695
                                        envmap_split_ima(env, ibuf_ima);
684
696
                                else
685
697
                                        env->ok= 0;
686
698
                        }
687
699
                }
688
700
        }
689
701
 
690
 
        if(env->ok==0) {
 
702
        if (env->ok==0) {
691
703
                texres->tin= 0.0;
692
704
                return 0;
693
705
        }
694
706
        
695
707
        /* rotate to envmap space, if object is set */
696
 
        VECCOPY(vec, texvec);
697
 
        if(env->object) mul_m3_v3(env->obimat, vec);
 
708
        copy_v3_v3(vec, texvec);
 
709
        if (env->object) mul_m3_v3(env->obimat, vec);
698
710
        else mul_mat3_m4_v3(R.viewinv, vec);
699
711
        
700
712
        face= envcube_isect(env, vec, sco);
701
713
        ibuf= env->cube[face];
702
714
        
703
 
        if(osatex) {
704
 
                if(env->object) {
 
715
        if (osatex) {
 
716
                if (env->object) {
705
717
                        mul_m3_v3(env->obimat, dxt);
706
718
                        mul_m3_v3(env->obimat, dyt);
707
719
                }
714
726
                
715
727
                /* edges? */
716
728
                
717
 
                if(texres->ta<1.0) {
 
729
                if (texres->ta<1.0f) {
718
730
                        TexResult texr1, texr2;
719
731
        
720
732
                        texr1.nor= texr2.nor= NULL;
 
733
                        texr1.talpha= texr2.talpha= texres->talpha; /* boxclip expects this initialized */
721
734
 
722
735
                        add_v3_v3(vec, dxt);
723
736
                        face1= envcube_isect(env, vec, sco);
724
737
                        sub_v3_v3(vec, dxt);
725
738
                        
726
 
                        if(face!=face1) {
 
739
                        if (face!=face1) {
727
740
                                ibuf= env->cube[face1];
728
741
                                set_dxtdyt(dxts, dyts, dxt, dyt, face1);
729
742
                                imagewraposa(tex, NULL, ibuf, sco, dxts, dyts, &texr1);
736
749
                        face1= envcube_isect(env, vec, sco);
737
750
                        sub_v3_v3(vec, dyt);
738
751
                        
739
 
                        if(face!=face1) {
 
752
                        if (face!=face1) {
740
753
                                ibuf= env->cube[face1];
741
754
                                set_dxtdyt(dxts, dyts, dxt, dyt, face1);
742
755
                                imagewraposa(tex, NULL, ibuf, sco, dxts, dyts, &texr2);
744
757
                        else texr2.tr= texr2.tg= texr2.tb= texr2.ta= 0.0;
745
758
                        
746
759
                        fac= (texres->ta+texr1.ta+texr2.ta);
747
 
                        if(fac!=0.0) {
748
 
                                fac= 1.0/fac;
 
760
                        if (fac!=0.0f) {
 
761
                                fac= 1.0f/fac;
749
762
 
750
763
                                texres->tr= fac*(texres->ta*texres->tr + texr1.ta*texr1.tr + texr2.ta*texr2.tr );
751
764
                                texres->tg= fac*(texres->ta*texres->tg + texr1.ta*texr1.tg + texr2.ta*texr2.tg );