Bugfix, own collection:
authorTon Roosendaal <ton@blender.org>
Tue, 21 Nov 2006 15:52:45 +0000 (15:52 +0000)
committerTon Roosendaal <ton@blender.org>
Tue, 21 Nov 2006 15:52:45 +0000 (15:52 +0000)
Random seeding is still not perfect in render, especially lack of good
thread support still.

- VectorBlur node was calling seed for each exec, causing other nodes to
  get fixed random too.
- added seed in non-OSA main loop for render
- use BLI_srandom, is better than BLI_srand

source/blender/blenkernel/intern/node.c
source/blender/blenlib/intern/rand.c
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/rendercore.c
source/blender/render/intern/source/zbuf.c

index 2702fd6d3f1ee7e51e6146b9e32176762d66f8fb..ab705770da1535df7502c443e47e037cc637da3c 100644 (file)
@@ -2120,8 +2120,8 @@ void ntreeCompositExecTree(bNodeTree *ntree, RenderData *rd, int do_preview)
        thdata.stack= ntree->stack;
        
        /* fixed seed, for example noise texture */
-       BLI_srand(rd->cfra);
-       
+       BLI_srandom(rd->cfra);
+
        /* sets need_exec tags in nodes */
        totnode= setExecutableNodes(ntree, &thdata);
        
index e80ab07f8a90f3ada3dfc7533c2211a1e8517e12..bf700f8c62c469677ca741db589c2125e09875ac 100644 (file)
@@ -171,6 +171,9 @@ void BLI_thread_srandom(int thread, unsigned int seed)
 {
        extern unsigned char hash[];    // noise.c
        
+       if(thread >= MAX_RNG_THREADS)
+               thread= 0;
+       
        rng_seed(&rng_tab[thread], seed + hash[seed & 255]);
        seed= rng_getInt(&rng_tab[thread]);
        rng_seed(&rng_tab[thread], seed + hash[seed & 255]);
index f21ee9c0c1abb820e0f702fe4f621b6df518601b..5db575d35506540800eb7adae48f5d81df017268 100644 (file)
@@ -1640,7 +1640,7 @@ static void do_render_composite_fields_blur_3d(Render *re)
        bNodeTree *ntree= re->scene->nodetree;
        
        /* INIT seeding, compositor can use random texture */
-       BLI_srand(re->r.cfra);
+       BLI_srandom(re->r.cfra);
        
        if(composite_needs_render(re->scene)) {
                /* save memory... free all cached images */
index 13cc5118003dfe50c580b27bf445b27b821f6b4c..142e5ddbdbdd5ece3d7546c25cf346d79c141624 100644 (file)
@@ -3026,7 +3026,7 @@ static void shadeDA_tile(RenderPart *pa, RenderLayer *rl)
                od= offs;
                
                for(x=pa->disprect.xmin+crop; x<pa->disprect.xmax-crop; x++, rd++, rf+=4, od++) {
-                       BLI_thread_srandom(pa->thread, seed+x);
+                       BLI_thread_srandom(pa->thread, seed++);
                        
                        ps= (PixStr *)(*rd);
                        mask= 0;
@@ -3098,7 +3098,6 @@ static void shadeDA_tile(RenderPart *pa, RenderLayer *rl)
                rectf+= 4*pa->rectx;
                rectdaps+= pa->rectx;
                offs+= pa->rectx;
-               seed+= pa->rectx;
                
                if(y&1) if(R.test_break()) break; 
        }
@@ -3368,7 +3367,10 @@ void zbufshade_tile(RenderPart *pa)
                        
                        if(rl->layflag & SCE_LAY_SOLID) {
                                float *fcol= rl->rectf;
-                               int x, y, *rp= pa->rectp, *rz= pa->rectz, offs=0;
+                               int x, y, *rp= pa->rectp, *rz= pa->rectz, offs=0, seed;
+                               
+                               /* we set per pixel a fixed seed, for random AO and shadow samples */
+                               seed= pa->rectx*pa->disprect.ymin;
                                
                                /* irregular shadowb buffer creation */
                                if(R.r.mode & R_SHADOW)
@@ -3376,6 +3378,8 @@ void zbufshade_tile(RenderPart *pa)
                                
                                for(y=pa->disprect.ymin; y<pa->disprect.ymax; y++, rr->renrect.ymax++) {
                                        for(x=pa->disprect.xmin; x<pa->disprect.xmax; x++, rz++, rp++, fcol+=4, offs++) {
+                                               BLI_thread_srandom(pa->thread, seed++);
+                                               
                                                shadepixel_sky(&shpi, (float)x, (float)y, *rz, *rp, 0);
                                                QUATCOPY(fcol, shpi.shr.combined);
                                                
index 737f4884dddbfefb2eb36380e335dce2be1bbc13..b724aeb704fdf57a413a2ddc454dcb0739499b2d 100644 (file)
@@ -2237,12 +2237,13 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
 {
        ZSpan zspan;
        DrawBufPixel *rectdraw, *dr;
-       float jit[16][2];
+       static float jit[16][2];
        float v1[3], v2[3], v3[3], v4[3], fx, fy;
        float *rectvz, *dvz, *dimg, *dvec1, *dvec2, *dz1, *dz2, *rectz, *minvecbufrect= NULL;
        float maxspeedsq= (float)nbd->maxspeed*nbd->maxspeed;
        int y, x, step, maxspeed=nbd->maxspeed, samples= nbd->samples;
        int tsktsk= 0;
+       static int firsttime= 1;
        char *rectmove, *dm;
        
        zbuf_alloc_span(&zspan, xsize, ysize);
@@ -2420,8 +2421,11 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
        
        antialias_tagbuf(xsize, ysize, rectmove);
        
-       BLI_initjit(jit[0], 16);
-       
+       /* has to become static, the init-jit calls a random-seed, screwing up texture noise node */
+       if(firsttime) {
+               firsttime= 0;
+               BLI_initjit(jit[0], 16);
+       }
        
        /* accumulate */
        samples/= 2;