~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 * 
32
32
 *  may 1999
33
33
 * 
34
 
 * $Id: envmap.c,v 1.9 2004/01/23 22:33:33 ton Exp $
 
34
 * $Id: envmap.c,v 1.20 2005/06/04 16:22:50 lukep Exp $
35
35
 */
36
36
 
37
37
#include <math.h>
41
41
#include <config.h>
42
42
#endif
43
43
 
44
 
#ifdef WIN32
45
 
#include "BLI_winstuff.h"
46
 
#endif
47
 
 
48
44
/* external modules: */
49
45
#include "MEM_guardedalloc.h"
50
46
#include "BLI_arithb.h"
51
47
#include "BLI_blenlib.h"
 
48
#include "BKE_utildefines.h"
 
49
 
52
50
#include "IMB_imbuf_types.h"
53
51
#include "IMB_imbuf.h"        /* for rectcpy */
54
52
 
58
56
#include "DNA_scene_types.h"
59
57
#include "DNA_texture_types.h"
60
58
 
61
 
#include "BIF_space.h"
62
 
#include "BIF_toolbox.h"
63
 
 
64
59
#include "BKE_library.h"
65
60
#include "BKE_main.h"
66
61
#include "BKE_global.h"
67
62
#include "BKE_world.h"   // init_render_world
68
63
#include "BKE_image.h"   // BKE_write_ibuf 
69
64
 
 
65
#include "MTC_matrixops.h"
 
66
 
 
67
#include "SDL_thread.h"
 
68
#undef main 
 
69
#define main main /* stupid SDL_main redefines main as SDL_main */
70
70
 
71
71
/* this module */
72
72
#include "RE_callbacks.h"
73
73
#include "render.h"
74
 
#include "render_intern.h"
75
74
#include "envmap.h"
76
75
#include "mydevice.h"
77
 
#include "rendercore.h" /* calls zbufShade(DA).... I want to replace this with my own :)*/
 
76
#include "rendercore.h" 
78
77
#include "renderHelp.h"
79
 
#include "MTC_matrixops.h"
 
78
#include "texture.h"
80
79
#include "zbuf.h"
81
80
 
82
 
/* ------------------------------------------------------------------------- */
83
 
 
84
 
void envmap_split_ima(EnvMap *env);
85
 
void envmap_renderdata(EnvMap *env);
86
 
void envmap_transmatrix(float mat[][4], int part);
87
 
void env_rotate_scene(float mat[][4], int mode);
88
 
void env_layerflags(unsigned int notlay);
89
 
void env_set_imats(void);
90
 
void render_envmap(EnvMap *env);
91
 
int envcube_isect(float *vec, float *answ);
92
 
static void set_dxtdyt(float *dxts, float *dyts, float *dxt, float *dyt, int face);
93
81
 
94
82
/* ------------------------------------------------------------------------- */
95
83
 
127
115
void RE_free_envmapdata(EnvMap *env)
128
116
{
129
117
        Image *ima;
130
 
        int a, part;
 
118
        unsigned int a, part;
131
119
        
132
120
        for(part=0; part<6; part++) {
133
121
                ima= env->cube[part];
156
144
 
157
145
/* ------------------------------------------------------------------------- */
158
146
 
159
 
void envmap_split_ima(EnvMap *env)
 
147
static void envmap_split_ima(EnvMap *env)
160
148
{
161
149
        ImBuf *ibuf;
162
150
        Image *ima;
168
156
        dx= env->ima->ibuf->y;
169
157
        dx/= 2;
170
158
        if(3*dx != env->ima->ibuf->x) {
171
 
                error("Incorrect envmap size");
 
159
                printf("Incorrect envmap size\n");
172
160
                env->ok= 0;
173
161
                env->ima->ok= 0;
174
162
        }
199
187
/* ------------------------------------------------------------------------- */
200
188
/* ****************** RENDER ********************** */
201
189
 
202
 
void envmap_renderdata(EnvMap *env)
 
190
static void envmap_renderdata(EnvMap *env)
203
191
{
 
192
        extern void init_filt_mask(void);
204
193
        static RE_Render envR;
205
194
        static Object *camera;
206
195
        int cuberes;
217
206
                R.xstart= R.ystart= -R.afmx;
218
207
                R.xend= R.yend= R.xstart+R.rectx-1;
219
208
 
220
 
                R.r.mode &= ~(R_BORDER | R_PANORAMA | R_ORTHO | R_MBLUR);
 
209
                R.r.mode &= ~(R_BORDER | R_PANORAMA | R_ORTHO | R_MBLUR | R_GAUSS);
221
210
                R.r.xparts= R.r.yparts= 1;
222
211
                R.r.bufflag= 0;
223
212
                R.r.size= 100;
241
230
                G.scene->camera= camera;
242
231
        }
243
232
        
 
233
        /* gauss, gamma, etc */
 
234
        init_filt_mask();
244
235
}
245
236
 
246
237
/* ------------------------------------------------------------------------- */
247
238
 
248
 
void envmap_transmatrix(float mat[][4], int part)
 
239
static void envmap_transmatrix(float mat[][4], int part)
249
240
{
250
241
        float tmat[4][4], eul[3], rotmat[4][4];
251
242
        
277
268
 
278
269
/* ------------------------------------------------------------------------- */
279
270
 
280
 
void env_rotate_scene(float mat[][4], int mode)
 
271
static void env_rotate_scene(float mat[][4], int mode)
281
272
{
282
273
        VlakRen *vlr = NULL;
283
274
        VertRen *ver = NULL;
366
357
 
367
358
/* ------------------------------------------------------------------------- */
368
359
 
369
 
void env_layerflags(unsigned int notlay)
 
360
static void env_layerflags(unsigned int notlay)
370
361
{
371
362
        VlakRen *vlr = NULL;
372
363
        int a;
378
369
        }
379
370
}
380
371
 
381
 
void env_hideobject(Object *ob)
 
372
static void env_hideobject(Object *ob)
382
373
{
383
374
        VlakRen *vlr = NULL;
384
375
        int a;
392
383
 
393
384
/* ------------------------------------------------------------------------- */
394
385
 
395
 
void env_set_imats()
 
386
static void env_set_imats()
396
387
{
397
388
        Base *base;
398
389
        float mat[4][4];
409
400
 
410
401
/* ------------------------------------------------------------------------- */
411
402
 
412
 
void render_envmap(EnvMap *env)
 
403
static void render_envmap(EnvMap *env)
413
404
{
414
405
        /* only the cubemap is implemented */
415
406
        ImBuf *ibuf;
420
411
        /* need a recalc: ortho-render has no correct viewinv */
421
412
        MTC_Mat4Invert(oldviewinv, R.viewmat);
422
413
 
 
414
        /* do first, envmap_renderdata copies entire R struct */
 
415
        if(R.rectz) MEM_freeN(R.rectz); R.rectz= NULL;
 
416
        if(R.rectot) MEM_freeN(R.rectot); R.rectot= NULL;
 
417
        if(R.rectftot) MEM_freeN(R.rectftot); R.rectftot= NULL;
 
418
        
423
419
        /* setup necessary globals */
424
420
        envmap_renderdata(env);
425
421
        
480
476
 
481
477
        }
482
478
        
483
 
        if(R.rectz) MEM_freeN(R.rectz); R.rectz= 0;
484
 
        if(R.rectot) MEM_freeN(R.rectot); R.rectot= 0;
 
479
        if(R.rectz) MEM_freeN(R.rectz); R.rectz= NULL;
 
480
        if(R.rectot) MEM_freeN(R.rectot); R.rectot= NULL;
 
481
        if(R.rectftot) MEM_freeN(R.rectftot); R.rectftot= NULL;
485
482
        
486
483
        if(RE_local_test_break()) RE_free_envmapdata(env);
487
484
        else {
557
554
        if(do_init) {
558
555
                RE_local_init_render_display();
559
556
                RE_local_clear_render_display(R.win);
560
 
                allqueue(REDRAWBUTSSHADING, 0);                 // bad!
 
557
                R.flag |= R_REDRAW_PRV;
561
558
        }       
562
559
        // restore
563
560
        R.r.mode |= trace;
566
563
 
567
564
/* ------------------------------------------------------------------------- */
568
565
 
569
 
int envcube_isect(float *vec, float *answ)
 
566
static int envcube_isect(float *vec, float *answ)
570
567
{
571
568
        float labda;
572
569
        int face;
639
636
 
640
637
/* ------------------------------------------------------------------------- */
641
638
 
642
 
extern float Tin, Ta, Tr, Tg, Tb; /* texture.c */
643
 
int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex)
 
639
int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexResult *texres)
644
640
{
 
641
        extern SDL_mutex *load_ibuf_lock; // initrender.c
645
642
        /* texvec should be the already reflected normal */
646
643
        EnvMap *env;
647
 
        float fac, vec[3], sco[3], col[20], dxts[3], dyts[3];
 
644
        Image *ima;
 
645
        float fac, vec[3], sco[3], dxts[3], dyts[3];
648
646
        int face, face1;
649
647
        
650
648
        env= tex->env;
651
 
        if(env==0 || env->object==0) return 0;
652
 
        
 
649
        if(env==NULL || (env->stype!=ENV_LOAD && env->object==NULL)) {
 
650
                texres->tin= 0.0;
 
651
                return 0;
 
652
        }
653
653
        if(env->stype==ENV_LOAD) {
654
654
                env->ima= tex->ima;
655
655
                if(env->ima && env->ima->ok) {
656
 
                        if(env->ima->ibuf==0) ima_ibuf_is_nul(tex);
 
656
                        // Now thread safe
 
657
                        if(load_ibuf_lock) SDL_mutexP(load_ibuf_lock);
 
658
                        if(env->ima->ibuf==NULL) ima_ibuf_is_nul(tex, tex->ima);
 
659
                        if(load_ibuf_lock) SDL_mutexV(load_ibuf_lock);
657
660
                        if(env->ima->ok && env->ok==0) envmap_split_ima(env);
658
661
                }
659
662
        }
660
663
 
661
664
        if(env->ok==0) {
662
665
                
663
 
                Tin= 0.0;
 
666
                texres->tin= 0.0;
664
667
                return 0;
665
668
        }
666
669
        
667
 
        /* rotate to envmap space */
 
670
        /* rotate to envmap space, if object is set */
668
671
        VECCOPY(vec, texvec);
669
 
        MTC_Mat4Mul3Vecfl(env->object->imat, vec);
 
672
        if(env->object) MTC_Mat4Mul3Vecfl(env->object->imat, vec);
 
673
        else MTC_Mat4Mul3Vecfl(R.viewinv, vec);
670
674
        
671
675
        face= envcube_isect(vec, sco);
672
 
        tex->ima= env->cube[face];
 
676
        ima= env->cube[face];
673
677
        
674
678
        if(osatex) {
675
 
                MTC_Mat4Mul3Vecfl(env->object->imat, dxt);
676
 
                MTC_Mat4Mul3Vecfl(env->object->imat, dyt);
677
 
                
 
679
                if(env->object) {
 
680
                        MTC_Mat4Mul3Vecfl(env->object->imat, dxt);
 
681
                        MTC_Mat4Mul3Vecfl(env->object->imat, dyt);
 
682
                }
 
683
                else {
 
684
                        MTC_Mat4Mul3Vecfl(R.viewinv, dxt);
 
685
                        MTC_Mat4Mul3Vecfl(R.viewinv, dyt);
 
686
                }
678
687
                set_dxtdyt(dxts, dyts, dxt, dyt, face);
679
 
                imagewraposa(tex, sco, dxts, dyts);
 
688
                imagewraposa(tex, ima, sco, dxts, dyts, texres);
680
689
                
681
690
                /* edges? */
682
691
                
683
 
                if(Ta<1.0) {
684
 
                        col[0]= Ta; col[1]= Tr; col[2]= Tg; col[3]= Tb;
 
692
                if(texres->ta<1.0) {
 
693
                        TexResult texr1, texr2;
685
694
        
 
695
                        texr1.nor= texr2.nor= NULL;
 
696
 
686
697
                        VecAddf(vec, vec, dxt);
687
698
                        face1= envcube_isect(vec, sco);
688
699
                        VecSubf(vec, vec, dxt);
689
700
                        
690
701
                        if(face!=face1) {
691
 
                                tex->ima= env->cube[face1];
 
702
                                ima= env->cube[face1];
692
703
                                set_dxtdyt(dxts, dyts, dxt, dyt, face1);
693
 
                                imagewraposa(tex, sco, dxts, dyts);
694
 
                                col[4]= Ta; col[5]= Tr; col[6]= Tg; col[7]= Tb;
 
704
                                imagewraposa(tex, ima, sco, dxts, dyts, &texr1);
695
705
                        }
696
 
                        else col[4]= col[5]= col[6]= col[7]= 0.0;
 
706
                        else texr1.tr= texr1.tg= texr1.tb= texr1.ta= 0.0;
697
707
                        
698
 
                        /* here was the nasty bug! col[5,6,7] were not zero-ed. FPE! */
 
708
                        /* here was the nasty bug! results were not zero-ed. FPE! */
699
709
                        
700
710
                        VecAddf(vec, vec, dyt);
701
711
                        face1= envcube_isect(vec, sco);
702
712
                        VecSubf(vec, vec, dyt);
703
713
                        
704
714
                        if(face!=face1) {
705
 
                                tex->ima= env->cube[face1];
 
715
                                ima= env->cube[face1];
706
716
                                set_dxtdyt(dxts, dyts, dxt, dyt, face1);
707
 
                                imagewraposa(tex, sco, dxts, dyts);
708
 
                                col[8]= Ta; col[9]= Tr; col[10]= Tg; col[11]= Tb;
709
 
                        }
710
 
                        else col[8]= col[9]= col[10]= col[11]= 0.0;
711
 
                        
712
 
                        fac= (col[0]+col[4]+col[8]);
713
 
                        fac= 1.0/fac;
714
 
                        
715
 
                        Tr= fac*(col[0]*col[1] + col[4]*col[5] + col[8]*col[9] );
716
 
                        Tg= fac*(col[0]*col[2] + col[4]*col[6] + col[8]*col[10] );
717
 
                        Tb= fac*(col[0]*col[3] + col[4]*col[7] + col[8]*col[11] );
718
 
                        Ta= 1.0;
719
 
 
 
717
                                imagewraposa(tex, ima, sco, dxts, dyts, &texr2);
 
718
                        }
 
719
                        else texr2.tr= texr2.tg= texr2.tb= texr2.ta= 0.0;
 
720
                        
 
721
                        fac= (texres->ta+texr1.ta+texr2.ta);
 
722
                        if(fac!=0.0) {
 
723
                                fac= 1.0/fac;
 
724
                                
 
725
                                texres->tr= fac*(texres->ta*texres->tr + texr1.ta*texr1.tr + texr2.ta*texr2.tr );
 
726
                                texres->tg= fac*(texres->ta*texres->tg + texr1.ta*texr1.tg + texr2.ta*texr2.tg );
 
727
                                texres->tb= fac*(texres->ta*texres->tb + texr1.ta*texr1.tb + texr2.ta*texr2.tb );
 
728
                        }
 
729
                        texres->ta= 1.0;
720
730
                }
721
731
        }
722
732
        else {
723
 
                imagewrap(tex, sco);
 
733
                imagewrap(tex, ima, sco, texres);
724
734
        }
725
735
        
726
 
        tex->ima= env->ima;
727
 
        
728
736
        return 1;
729
737
}
730
738