Thought to be nice for for backwards compat && users... so the old
authorTon Roosendaal <ton@blender.org>
Sat, 10 Jun 2006 16:30:44 +0000 (16:30 +0000)
committerTon Roosendaal <ton@blender.org>
Sat, 10 Jun 2006 16:30:44 +0000 (16:30 +0000)
"Backbuf" image render option is back :)
Nicer coded, using Image texture functions.

If you want 100% reliable pixel to pixel accuracy you have to use
compositing. (Old Backbuf didn't do this accuracy either btw).

source/blender/render/intern/include/render_types.h
source/blender/render/intern/include/texture.h
source/blender/render/intern/source/imagetexture.c
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/pixelshading.c

index 00e6943..5a655c0 100644 (file)
@@ -160,6 +160,8 @@ struct Render
        struct VlakRen **blovl;
        ListBase objecttable;
        
+       struct Image *backbuf;
+       
        struct GHash *orco_hash;
 
        /* arena for allocating data for use during render, for
index f4fd7b8..59c8425 100644 (file)
@@ -67,6 +67,7 @@ void render_realtime_texture(struct ShadeInput *shi);
 
 int imagewraposa(struct Tex *tex, struct Image *ima, float *texvec, float *dxt, float *dyt, struct TexResult *texres);
 int imagewrap(struct Tex *tex, struct Image *ima, float *texvec, struct TexResult *texres);
+void image_sample(struct Image *ima, float fx, float fy, float dx, float dy, float *result);
 
 #endif /* TEXTURE_EXT_H */
 
index 38d47d3..ebb2dfe 100644 (file)
@@ -589,6 +589,25 @@ static void makemipmap(Tex *tex, Image *ima)
        }
 }
 
+void image_sample(Image *ima, float fx, float fy, float dx, float dy, float *result)
+{
+       TexResult texres;
+       
+       if(ima==NULL || ima->ok== 0 || ima->ibuf==NULL) {
+               return;
+       }
+       
+       /* bad globals for boxsample */
+       imaprepeat= 0;
+       imapextend= 0;
+       
+       boxsample(ima->ibuf, fx, fy, fx+dx, fy+dy, &texres);
+       result[0]= texres.tr;
+       result[1]= texres.tg;
+       result[2]= texres.tb;
+       result[3]= texres.ta;
+
+}
 
 int imagewraposa(Tex *tex, Image *ima, float *texvec, float *dxt, float *dyt, TexResult *texres)
 {
index c23f8b7..35f7680 100644 (file)
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 
 #include "DNA_group_types.h"
+#include "DNA_image_types.h"
 #include "DNA_node_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
@@ -1405,6 +1406,40 @@ static void do_render_fields_3d(Render *re)
        re->display_draw(re->result, NULL);
 }
 
+static void load_backbuffer(Render *re)
+{
+       if(re->r.alphamode == R_ADDSKY) {
+               Image *bima;
+               char name[256];
+               
+               strcpy(name, re->r.backbuf);
+               BLI_convertstringcode(name, G.sce, re->r.cfra);
+               
+               if(re->backbuf) {
+                       re->backbuf->id.us--;
+                       bima= re->backbuf;
+               }
+               else bima= NULL;
+               
+               re->backbuf= add_image(name);
+               
+               if(bima && bima->id.us<1) {
+                       free_image_buffers(bima);
+               }
+               
+               if(re->backbuf && re->backbuf->ibuf==NULL) {
+                       re->backbuf->ibuf= IMB_loadiffname(re->backbuf->name, IB_rect);
+                       if(re->backbuf->ibuf==NULL) re->backbuf->ok= 0;
+                       else re->backbuf->ok= 1;
+               }
+               if(re->backbuf==NULL || re->backbuf->ok==0) {
+                       // error() doesnt work with render window open
+                       //error("No backbuf there!");
+                       printf("Error: No backbuf %s\n", name);
+               }
+       }
+}
+
 /* main render routine, no compositing */
 static void do_render_fields_blur_3d(Render *re)
 {
@@ -1414,6 +1449,10 @@ static void do_render_fields_blur_3d(Render *re)
                return;
        }
        
+       /* backbuffer initialize */
+       if(re->r.bufflag & 1)
+               load_backbuffer(re);
+
        /* now use renderdata and camera to set viewplane */
        RE_SetCamera(re, re->scene->camera);
        
index 9dd053c..12b06e8 100644 (file)
@@ -469,6 +469,16 @@ void renderSkyPixelFloat(float *collector, float x, float y, float *rco)
        }
 }
 
+static void fillBackgroundImage(float *collector, float fx, float fy)
+{
+       if(R.backbuf) {
+               float dx= 1.0f/(float)R.winx;
+               float dy= 1.0f/(float)R.winy;
+               
+               image_sample(R.backbuf, fx/(float)R.winx, fy/(float)R.winy, dx, dy, collector);
+       }
+}
+
 /*
   Stuff the sky colour into the collector.
  */
@@ -486,7 +496,7 @@ void shadeSkyPixel(float *collector, float fx, float fy, float *rco)
 
        /* 1. Do a backbuffer image: */ 
        if(R.r.bufflag & 1) {
-//             fillBackgroundImage(collector, fx, fy);
+               fillBackgroundImage(collector, fx, fy);
                return;
        } else if((R.wrld.skytype & (WO_SKYBLEND+WO_SKYTEX))==0) {
                /*