Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTon Roosendaal <ton@blender.org>2006-01-12 01:36:31 +0300
committerTon Roosendaal <ton@blender.org>2006-01-12 01:36:31 +0300
commit0665f0d64799e6a38c4ca0930df73271f246e422 (patch)
treefa488d33452f0bfc6ec91e5bbbec726afcbcb9f3 /source/blender/render
parentb92fa4151645d50e40faa8f4aaea4b7f6149947c (diff)
Orange;
Until now, the zbuffer was written straight from the internal zbuffer, which has values that are inverse-proportional (like 1.0/z) which makes it very hard to use it for postprocess, like zblur or other composit effects that require Z. Based on info from ILM, the values stored for Z in exr files is the actual distance from a camera. I think that's about time to migrate to that convention! By default now, after render, the z values are converted to floats. This saves in exr files now, but not in the Iris Z files. That latter was a blender-only anyway, so might be not a real hassle to drop. :) You can see the difference in the image window, but notice the range now is linear mapped from camera clipstart to clipend. Note; I just discover that ortho Z values need a different correction...
Diffstat (limited to 'source/blender/render')
-rw-r--r--source/blender/render/extern/include/render_types.h3
-rw-r--r--source/blender/render/intern/source/initrender.c49
-rw-r--r--source/blender/render/intern/source/rendercore.c2
3 files changed, 52 insertions, 2 deletions
diff --git a/source/blender/render/extern/include/render_types.h b/source/blender/render/extern/include/render_types.h
index efb0863b94a..8fad87c2707 100644
--- a/source/blender/render/extern/include/render_types.h
+++ b/source/blender/render/extern/include/render_types.h
@@ -161,7 +161,8 @@ typedef struct RE_Render
struct MemArena *memArena;
int *rectaccu;
- int *rectz; /* z buffer: distance buffer */
+ int *rectz; /* z buffer: distance buffer */
+ float *rectzf; /* z distances, camera space */
unsigned int *rectf1, *rectf2;
unsigned int *rectot; /* z buffer: face index buffer, recycled as colour buffer! */
unsigned int *rectspare; /* */
diff --git a/source/blender/render/intern/source/initrender.c b/source/blender/render/intern/source/initrender.c
index c0c175709e1..948c1179b3b 100644
--- a/source/blender/render/intern/source/initrender.c
+++ b/source/blender/render/intern/source/initrender.c
@@ -501,10 +501,12 @@ void RE_free_render_data()
if(R.rectot) MEM_freeN(R.rectot);
if(R.rectftot) MEM_freeN(R.rectftot);
if(R.rectz) MEM_freeN(R.rectz);
+ if(R.rectzf) MEM_freeN(R.rectzf);
if(R.rectspare) MEM_freeN(R.rectspare);
R.rectot= NULL;
R.rectftot= NULL;
R.rectz= NULL;
+ R.rectzf= NULL;
R.rectspare= NULL;
free_filt_mask();
@@ -805,6 +807,43 @@ static void addparttorect(Part *pa)
}
}
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+static void convert_zbuf_to_distbuf(void)
+{
+ float *rectzf, zco;
+ int a, *rectz;
+
+ if(R.rectz==NULL) return;
+ if(R.rectzf) {
+ printf("called convert zbuf wrong...\n");
+ MEM_freeN(R.rectzf);
+ }
+
+ /* need to make sure winmat is OK */
+ R.xstart= -R.afmx;
+ R.ystart= -R.afmy;
+ R.xend= R.xstart+R.rectx-1;
+ R.yend= R.ystart+R.recty-1;
+
+ RE_setwindowclip(0, -1);
+
+ rectzf= R.rectzf= MEM_mallocN(R.rectx*R.recty*sizeof(float), "rectzf");
+ rectz= R.rectz;
+
+ for(a=R.rectx*R.recty; a>0; a--, rectz++, rectzf++) {
+ if(*rectz==0x7FFFFFFF)
+ *rectzf= 10e10;
+ else {
+ zco= ((float)*rectz)/2147483647.0f;
+ *rectzf= R.winmat[3][2]/(R.winmat[2][2] - R.winmat[2][3]*zco);
+ }
+ }
+
+ MEM_freeN(R.rectz);
+ R.rectz= NULL;
+}
+
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
@@ -872,6 +911,9 @@ static void add_to_blurbuf(int blur)
}
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+
/* yafray: main yafray render/export call */
static void yafrayRender(void)
{
@@ -889,6 +931,8 @@ static void yafrayRender(void)
R.rectot = MEM_callocN(sizeof(int)*R.rectx*R.recty, "rectot");
/* zbuf */
if (R.rectz) MEM_freeN(R.rectz);
+ if (R.rectzf) MEM_freeN(R.rectzf);
+ R.rectzf= NULL;
R.rectz = (unsigned int *)MEM_mallocN(sizeof(int)*R.rectx*R.recty, "rectz");
/* float rgba buf */
if (R.rectftot) MEM_freeN(R.rectftot);
@@ -970,6 +1014,8 @@ static void mainRenderLoop(void) /* here the PART and FIELD loops */
if(R.rectz) MEM_freeN(R.rectz);
R.rectz = NULL;
+ if(R.rectzf) MEM_freeN(R.rectzf);
+ R.rectzf = NULL;
if(R.rectftot) MEM_freeN(R.rectftot);
R.rectftot = NULL;
@@ -1448,6 +1494,9 @@ void RE_initrender(struct View3D *ogl_render_view3d)
/* grms... this is a nasty global */
do_gamma= 0;
+ /* for now, we do always */
+ convert_zbuf_to_distbuf();
+
/* these flags remain on, until reset in caller to render (renderwin.c) */
R.flag &= (R_RENDERING|R_ANIMRENDER|R_REDRAW_PRV);
}
diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c
index 5ad6f4e84a9..24751c6a66f 100644
--- a/source/blender/render/intern/source/rendercore.c
+++ b/source/blender/render/intern/source/rendercore.c
@@ -2345,7 +2345,7 @@ void *shadepixel(float x, float y, int z, int facenr, int mask, float *col, floa
float zco;
/* inverse of zbuf calc: zbuf = MAXZ*hoco_z/hoco_w */
- zco= ((float)z)/(float)0x7FFFFFFF;
+ zco= ((float)z)/2147483647.0f;
shi.co[2]= R.winmat[3][2]/( R.winmat[2][3]*zco - R.winmat[2][2] );
fac= zcor= shi.co[2]/shi.view[2];