More environment map stuff:
authorTon Roosendaal <ton@blender.org>
Sun, 19 Mar 2006 17:50:53 +0000 (17:50 +0000)
committerTon Roosendaal <ton@blender.org>
Sun, 19 Mar 2006 17:50:53 +0000 (17:50 +0000)
- added a zoom factor for Planar Environment Map, allowing to zoom in or
  out on the reflected object. The zoom is corrected when rendering, so it
  just gives control over the resolution.
- Planar maps don't cycle anymore, but only render the front plane, using
  standard image texture extend mode.
- threaded rendering is back in envmap render

source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_texture_types.h
source/blender/render/intern/include/render_types.h
source/blender/render/intern/source/envmap.c
source/blender/render/intern/source/initrender.c
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/texture.c
source/blender/src/buttons_shading.c

index 6ab68122d5d01cdd59c69550c479e80155985672..ccfb8afedd4e28e7176465c39c3fa7339bf40319 100644 (file)
@@ -5293,7 +5293,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
        }
        
        if(main->versionfile <= 241) {
-//             Tex *tex;
+               Tex *tex;
                Scene *sce;
                Lamp *la;
                bArmature *arm;
@@ -5359,9 +5359,11 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        if(la->buffers==0)
                                la->buffers= 1;
                
-//             for(tex= main->tex.first; tex; tex= tex->id.next)
+               for(tex= main->tex.first; tex; tex= tex->id.next) {
+                       if(tex->env && tex->env->viewscale==0.0f)
+                               tex->env->viewscale= 1.0f;
 //                     tex->imaflag |= TEX_GAUSS_MIP;
-
+               }
                //Object *ob;
                
                /* for empty drawsize and drawtype */
index ea49e7d0e6b3b57e8a37de93935af33ccdc731f4..47e89dbd1c0ab8b0b15f380d519c3f24e55678f2 100644 (file)
@@ -115,6 +115,7 @@ typedef struct EnvMap {
        float obimat[3][3];
        short type, stype;
        float clipsta, clipend;
+       float viewscale, pad;   /* viewscale is for planar envmaps to zoom in or out */
        unsigned int notlay;
        short cuberes, depth;
        short ok, lastframe;
index 504fc228a1af085e967d71b5efd7d8245ac3e3e1..0e405af82985f6311239938a601f189e6b5e788d 100644 (file)
@@ -116,8 +116,8 @@ struct Render
           partx*xparts can be larger than rectx, in that case last part is smaller */
        int partx, party;
        
-       /* correction values for pixels or view */
-       float ycor, viewfac;
+       /* values for viewing */
+       float lens, ycor, viewfac;
        float bluroffsx, bluroffsy;
        float panophi, panosi, panoco, panodxp, panodxv;
        
index 9826c2fde5127f9d5471118dc8bb5e86c3cba7d6..c5425eed90c41a4a8368d3d47879df191865828a 100644 (file)
@@ -138,6 +138,7 @@ static Render *envmap_render_copy(Render *re, EnvMap *env)
        envre->scene= re->scene;        /* unsure about this... */
 
        /* view stuff in env render */
+       envre->lens= env->viewscale*16.0f;
        envre->ycor= 1.0; 
        envre->clipsta= env->clipsta;   /* render_scene_set_window() respects this for now */
        envre->clipend= env->clipend;
@@ -512,48 +513,58 @@ void make_envmaps(Render *re)
 
 /* ------------------------------------------------------------------------- */
 
-static int envcube_isect(float *vec, float *answ)
+static int envcube_isect(EnvMap *env, float *vec, float *answ)
 {
        float labda;
        int face;
        
-       /* which face */
-       if( vec[2]<=-fabs(vec[0]) && vec[2]<=-fabs(vec[1]) ) {
-               face= 0;
-               labda= -1.0/vec[2];
-               answ[0]= labda*vec[0];
-               answ[1]= labda*vec[1];
-       }
-       else if( vec[2]>=fabs(vec[0]) && vec[2]>=fabs(vec[1]) ) {
+       if(env->type==ENV_PLANE) {
                face= 1;
+               
                labda= 1.0/vec[2];
-               answ[0]= labda*vec[0];
-               answ[1]= -labda*vec[1];
-       }
-       else if( vec[1]>=fabs(vec[0]) ) {
-               face= 2;
-               labda= 1.0/vec[1];
-               answ[0]= labda*vec[0];
-               answ[1]= labda*vec[2];
-       }
-       else if( vec[0]<=-fabs(vec[1]) ) {
-               face= 3;
-               labda= -1.0/vec[0];
-               answ[0]= labda*vec[1];
-               answ[1]= labda*vec[2];
-       }
-       else if( vec[1]<=-fabs(vec[0]) ) {
-               face= 4;
-               labda= -1.0/vec[1];
-               answ[0]= -labda*vec[0];
-               answ[1]= labda*vec[2];
+               answ[0]= env->viewscale*labda*vec[0];
+               answ[1]= -env->viewscale*labda*vec[1];
        }
        else {
-               face= 5;
-               labda= 1.0/vec[0];
-               answ[0]= -labda*vec[1];
-               answ[1]= labda*vec[2];
+               /* which face */
+               if( vec[2]<=-fabs(vec[0]) && vec[2]<=-fabs(vec[1]) ) {
+                       face= 0;
+                       labda= -1.0/vec[2];
+                       answ[0]= labda*vec[0];
+                       answ[1]= labda*vec[1];
+               }
+               else if( vec[2]>=fabs(vec[0]) && vec[2]>=fabs(vec[1]) ) {
+                       face= 1;
+                       labda= 1.0/vec[2];
+                       answ[0]= labda*vec[0];
+                       answ[1]= -labda*vec[1];
+               }
+               else if( vec[1]>=fabs(vec[0]) ) {
+                       face= 2;
+                       labda= 1.0/vec[1];
+                       answ[0]= labda*vec[0];
+                       answ[1]= labda*vec[2];
+               }
+               else if( vec[0]<=-fabs(vec[1]) ) {
+                       face= 3;
+                       labda= -1.0/vec[0];
+                       answ[0]= labda*vec[1];
+                       answ[1]= labda*vec[2];
+               }
+               else if( vec[1]<=-fabs(vec[0]) ) {
+                       face= 4;
+                       labda= -1.0/vec[1];
+                       answ[0]= -labda*vec[0];
+                       answ[1]= labda*vec[2];
+               }
+               else {
+                       face= 5;
+                       labda= 1.0/vec[0];
+                       answ[0]= -labda*vec[1];
+                       answ[1]= labda*vec[2];
+               }
        }
+       
        answ[0]= 0.5+0.5*answ[0];
        answ[1]= 0.5+0.5*answ[1];
        return face;
@@ -621,11 +632,8 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe
        if(env->object) MTC_Mat3MulVecfl(env->obimat, vec);
        else MTC_Mat4Mul3Vecfl(R.viewinv, vec);
        
-       face= envcube_isect(vec, sco);
-       if(env->type==ENV_PLANE)
-               ima= env->cube[1];
-       else
-               ima= env->cube[face];
+       face= envcube_isect(env, vec, sco);
+       ima= env->cube[face];
        
        if(osatex) {
                if(env->object) {
@@ -647,13 +655,11 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe
                        texr1.nor= texr2.nor= NULL;
 
                        VecAddf(vec, vec, dxt);
-                       face1= envcube_isect(vec, sco);
+                       face1= envcube_isect(env, vec, sco);
                        VecSubf(vec, vec, dxt);
                        
                        if(face!=face1) {
-                               if(env->type==ENV_CUBE)
-                                       ima= env->cube[face1];
-                               
+                               ima= env->cube[face1];
                                set_dxtdyt(dxts, dyts, dxt, dyt, face1);
                                imagewraposa(tex, ima, sco, dxts, dyts, &texr1);
                        }
@@ -662,12 +668,11 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe
                        /* here was the nasty bug! results were not zero-ed. FPE! */
                        
                        VecAddf(vec, vec, dyt);
-                       face1= envcube_isect(vec, sco);
+                       face1= envcube_isect(env, vec, sco);
                        VecSubf(vec, vec, dyt);
                        
                        if(face!=face1) {
-                               if(env->type==ENV_CUBE)
-                                       ima= env->cube[face1];
+                               ima= env->cube[face1];
                                set_dxtdyt(dxts, dyts, dxt, dyt, face1);
                                imagewraposa(tex, ima, sco, dxts, dyts, &texr2);
                        }
index 8506a5654098dc5a83ed90d78c20d8947dfa160d..520378a9d8688f0ae36a1c196d26f6038d1b85ca 100644 (file)
@@ -485,17 +485,22 @@ void RE_SetCamera(Render *re, Object *camera)
 
                /* phi= acos(fac); */
                /* lens= 16.0*fac/sin(phi); */
-               lens= 35.0;
+               lens= re->lens;
+               if(lens==0.0f)
+                       lens= 35.0;
                clipsta= 0.1;
                clipend= 1000.0;
        }
-       else {  /* envmap exception, can be done better... */
-               lens= 16.0;
+       else {  /* envmap exception... */
+               lens= re->lens;
+               if(lens==0.0f)
+                       lens= 16.0;
+               
                clipsta= re->clipsta;
                clipend= re->clipend;
                if(clipsta==0.0f || clipend==0.0f) {
-                       clipsta= 0.1;
-                       clipend= 1000.0;
+                       clipsta= 0.1f;
+                       clipend= 1000.0f;
                }
        }
 
index 79ec6bb3c5afe26f6770a7f3c84b91d2947a36ae..8ab916e27f9d49a800b356cca579a6b5396353b4 100644 (file)
@@ -1176,10 +1176,10 @@ static void threaded_tile_processor(Render *re)
        freeparts(re);
 }
 
-/* currently only called by preview renders */
+/* currently only called by preview renders and envmap */
 void RE_TileProcessor(Render *re, int firsttile)
 {
-       if(0
+       if(re->r.mode & R_THREADS
                threaded_tile_processor(re);
        else
                render_tile_processor(re, firsttile);   
index 5c2610e45f40bd32759bff0e5cfcad2285413611..8f5c0d5cecbf486913544cce8023b98001a25c71 100644 (file)
@@ -185,7 +185,10 @@ void init_render_texture(Render *re, Tex *tex)
                tex->extend= TEX_CLIP;
                
                if(tex->env) {
-                       /* only free envmap when rendermode has set to render envmaps, for previewrender */
+                       if(tex->env->type==ENV_PLANE)
+                               tex->extend= TEX_EXTEND;
+                       
+                       /* only free envmap when rendermode was set to render envmaps, for previewrender */
                        if(G.rendering) {
                                if (re->r.mode & R_ENVMAP)
                                        if(tex->env->stype==ENV_ANIM) 
index d203de55ac36c56ee2793c28296510310e4cfa5d..e07027cf06c18a4d96697620b9aff646942af453 100644 (file)
@@ -904,8 +904,9 @@ static void texture_panel_envmap(Tex *tex)
                        uiDefBut(block, BUT, B_ENV_FREE_ALL, "Free all EnvMaps", 210,145,100,20, 0, 0, 0, 0, 0, "Frees all rendered environment maps for all materials");
                        
                        uiBlockBeginAlign(block);
-                       uiDefButS(block, ROW, B_REDR, "Cube",                   10,120,100,20, &env->type, 3.0f, 0.0f, 0, 0, "Use environment map with six cube sides");
-                       uiDefButS(block, ROW, B_REDR, "Plane",                  110,120,100,20, &env->type, 3.0f, 1.0f, 0, 0, "Only one side is rendered, with Z axis pointing in direction of image");
+                       uiDefButS(block, ROW, B_NOP, "Cube",                    10,120,100,20, &env->type, 3.0f, 0.0f, 0, 0, "Use environment map with six cube sides");
+                       uiDefButS(block, ROW, B_NOP, "Plane",                   110,120,100,20, &env->type, 3.0f, 1.0f, 0, 0, "Only one side is rendered, with Z axis pointing in direction of image");
+                       uiDefButF(block, NUM, B_NOP, "Zoom: ",                  210,120,100,20, &env->viewscale, 0.5f, 5.0f, 100, 2, "Zoom factor for planar environment map");
                        uiBlockEndAlign(block);
                }
 
@@ -2469,7 +2470,7 @@ void do_matbuts(unsigned short event)
                /* when halo is disabled, clear star flag, this is the same as MA_FACETEXTURE <blush> */
                /* same for 'xtreme alpha' which is 'only shadow' */
                if((ma->mode & MA_HALO)==0) {
-                       ma->mode &= ~(MA_STAR|MA_HALO_XALPHA|MA_ZINV);
+                       ma->mode &= ~(MA_STAR|MA_HALO_XALPHA|MA_ZINV|MA_ENV);
                }
                BIF_preview_changed(ID_MA);
                allqueue(REDRAWBUTSSHADING, 0);