Revision: 28231
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28231
Author:   blendix
Date:     2010-04-16 16:09:25 +0200 (Fri, 16 Apr 2010)

Log Message:
-----------
Render Branch: SSS now works together with irradiance caching.

Modified Paths:
--------------
    branches/render25/source/blender/render/intern/include/zbuf.h
    branches/render25/source/blender/render/intern/source/cache.c
    branches/render25/source/blender/render/intern/source/rendercore.c
    branches/render25/source/blender/render/intern/source/shadeoutput.c
    branches/render25/source/blender/render/intern/source/zbuf.c

Modified: branches/render25/source/blender/render/intern/include/zbuf.h
===================================================================
--- branches/render25/source/blender/render/intern/include/zbuf.h       
2010-04-16 12:00:56 UTC (rev 28230)
+++ branches/render25/source/blender/render/intern/include/zbuf.h       
2010-04-16 14:09:25 UTC (rev 28231)
@@ -60,7 +60,7 @@
 /* SSS Rasterization */
 
 void zbuffer_sss(struct Render *re, struct RenderPart *pa, unsigned int lay,
-       void *handle, void (*func)(void*, int, int, int, int, int));
+       void *handle, void (*func)(void*, int, int, int, int, int), struct 
ListBase *psmlist);
 
 /* Pixel Struct Utilities */
 

Modified: branches/render25/source/blender/render/intern/source/cache.c
===================================================================
--- branches/render25/source/blender/render/intern/source/cache.c       
2010-04-16 12:00:56 UTC (rev 28230)
+++ branches/render25/source/blender/render/intern/source/cache.c       
2010-04-16 14:09:25 UTC (rev 28231)
@@ -47,15 +47,18 @@
 #include "rendercore.h"
 #include "render_types.h"
 #include "shading.h"
+#include "sss.h"
 
 /******************************** Utilities **********************************/
 
-static int mat_need_cache(Material *ma)
+static int mat_need_cache(Render *re, Material *ma)
 {
        if(ma->mode & MA_SHLESS)
                return 0;
        else if(ma->amb == 0.0f && !(ma->mapto & MAP_AMB))
                return 0;
+       else if((ma->sss_flag & MA_DIFF_SSS) && sss_pass_done(re, ma))
+               return 0;
        
        return 1;
 }
@@ -220,12 +223,11 @@
                        if(!(((y - pa->disprect.ymin + step) % step) == 0 || y 
== pa->disprect.ymax-1))
                                continue;
 
-                       /* XXX test */
                        totrow= pixel_row_fill(row, re, pa, offs);
                        shade_samples_from_pixel(re, ssamp, &row[0], x, y);
 
                        shi= ssamp->shi;
-                       if(shi->primitive.vlr && 
mat_need_cache(shi->material.mat)) {
+                       if(shi->primitive.vlr && mat_need_cache(re, 
shi->material.mat)) {
                                disk_occlusion_sample_direct(re, shi);
 
                                copy_v3_v3(sample->co, shi->geometry.co);
@@ -1077,7 +1079,7 @@
                                                float *indirect= 
(re->db.wrld.mode & WO_INDIRECT_LIGHT)? shi->shading.indirect: NULL;
                                                int added;
 
-                                               
if(!mat_need_cache(shi->material.mat))
+                                               if(!mat_need_cache(re, 
shi->material.mat))
                                                        continue;
 
                                                if(shi->primitive.strand) {

Modified: branches/render25/source/blender/render/intern/source/rendercore.c
===================================================================
--- branches/render25/source/blender/render/intern/source/rendercore.c  
2010-04-16 12:00:56 UTC (rev 28230)
+++ branches/render25/source/blender/render/intern/source/rendercore.c  
2010-04-16 14:09:25 UTC (rev 28231)
@@ -1027,19 +1027,17 @@
        *area *= alpha;
 }
 
-static void zbufshade_sss_free(RenderPart *pa)
+static void zbufshade_sss_free(RenderPart *pa, ListBase *psmlist)
 {
-#if 0
-       MEM_freeN(pa->rectall); pa->rectall= NULL;
-       free_pixel_structs(&handle.psmlist);
-#else
        MEM_freeN(pa->rectz); pa->rectz= NULL;
        MEM_freeN(pa->rectp); pa->rectp= NULL;
        MEM_freeN(pa->recto); pa->recto= NULL;
        MEM_freeN(pa->rectbackz); pa->rectbackz= NULL;
        MEM_freeN(pa->rectbackp); pa->rectbackp= NULL;
        MEM_freeN(pa->rectbacko); pa->rectbacko= NULL;
-#endif
+       MEM_freeN(pa->rectdaps); pa->rectdaps= NULL;
+
+       free_pixel_structs(psmlist);
 }
 
 static void render_sss_layer(Render *re, RenderResult *rr, Material *ma, 
ShadeInput *shi)
@@ -1086,30 +1084,20 @@
        Material *mat= re->db.sss_mat;
        float (*co)[3], (*color)[3], *area, *fcol;
        int x, y, seed, quad, totpoint, display = !(re->params.r.scemode & 
R_PREVIEWBUTS);
-       int *ro, *rz, *rp, *rbo, *rbz, *rbp, lay;
-#if 0
-       PixStr *ps;
-       void **rs;
-       int z;
-#endif
+       int lay, offs, a;
+       ListBase psmlist= {NULL, NULL};
 
        /* setup pixelstr list and buffer for zbuffering */
        handle.pa= pa;
        handle.totps= 0;
 
-#if 0
-       handle.psmlist.first= handle.psmlist.last= NULL;
-       addpsmain(&handle.psmlist);
-
-       pa->rectall= MEM_callocN(sizeof(void*)*pa->rectx*pa->recty+4, 
"rectall");
-#else
        pa->recto= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "recto");
        pa->rectp= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectp");
        pa->rectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectz");
        pa->rectbacko= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, 
"rectbacko");
        pa->rectbackp= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, 
"rectbackp");
        pa->rectbackz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, 
"rectbackz");
-#endif
+       pa->rectdaps= MEM_callocN(sizeof(void*)*pa->rectx*pa->recty+4, 
"zbufDArectd");
 
        /* setup shade sample with correct passes */
        memset(&ssamp, 0, sizeof(ssamp));
@@ -1126,13 +1114,13 @@
        ssamp.shi[0].material.light_override= NULL;
 
        /* create the pixelstrs to be used later */
-       zbuffer_sss(re, pa, lay, &handle, addps_sss);
+       zbuffer_sss(re, pa, lay, &handle, addps_sss, &psmlist);
 
        if(handle.totps==0) {
-               zbufshade_sss_free(pa);
+               zbufshade_sss_free(pa, &psmlist);
                return;
        }
-       
+
        fcol= rl->rectf;
 
        co= MEM_mallocN(sizeof(float)*3*handle.totps, "SSSCo");
@@ -1145,6 +1133,11 @@
                irregular_shadowbuf_create(re, pa, NULL);
 #endif
 
+       if(re->db.occlusiontree)
+               disk_occlusion_cache_create(re, pa, &ssamp);
+       else
+               irr_cache_create(re, pa, rl, &ssamp);
+       
        if(display) {
                /* initialize scanline updates for main thread */
                rr->renrect.ymin= 0;
@@ -1152,94 +1145,49 @@
        }
        
        seed= pa->rectx*pa->disprect.ymin;
-#if 0
-       rs= pa->rectall;
-#else
-       rz= pa->rectz;
-       rp= pa->rectp;
-       ro= pa->recto;
-       rbz= pa->rectbackz;
-       rbp= pa->rectbackp;
-       rbo= pa->rectbacko;
-#endif
        totpoint= 0;
+       offs= 0;
 
        for(y=pa->disprect.ymin; y<pa->disprect.ymax; y++, rr->renrect.ymax++) {
-               for(x=pa->disprect.xmin; x<pa->disprect.xmax; x++, fcol+=4) {
+               for(x=pa->disprect.xmin; x<pa->disprect.xmax; x++, fcol+=4, 
offs++) {
+                       PixelRow *row= pa->pixelrow;
+                       int totrow;
+
                        /* per pixel fixed seed */
                        BLI_thread_srandom(pa->thread, seed++);
                        
-#if 0
-                       if(rs) {
-                               /* for each sample in this pixel, shade it */
-                               for(ps=(PixStr*)*rs; ps; ps=ps->next) {
-                                       ObjectInstanceRen *obi= 
&re->db.objectinstance[ps->obi];
-                                       ObjectRen *obr= obi->obr;
-                                       vlr= render_object_vlak_get(obr, 
(ps->facenr-1) & RE_QUAD_MASK);
-                                       quad= (ps->facenr & RE_QUAD_OFFS);
-                                       z= ps->z;
+                       totrow= pixel_row_fill(row, re, pa, offs);
 
-                                       shade_sample_sss(re, &ssamp, mat, obi, 
vlr, quad, x, y, z,
-                                               co[totpoint], color[totpoint], 
&area[totpoint]);
+                       for(a=0; a<totrow; a++) {
+                               ObjectInstanceRen *obi= 
&re->db.objectinstance[row[a].obi];
 
-                                       totpoint++;
+                               /* shade front */
+                               vlr= render_object_vlak_get(obi->obr, 
(row[a].p-1) & RE_QUAD_MASK);
+                               quad= ((row[a].p) & RE_QUAD_OFFS);
 
-                                       add_v3_v3v3(fcol, fcol, color);
-                                       fcol[3]= 1.0f;
-                               }
-
-                               rs++;
-                       }
-#else
-                       if(rp) {
-                               if(*rp != 0) {
-                                       ObjectInstanceRen *obi= 
&re->db.objectinstance[*ro];
-                                       ObjectRen *obr= obi->obr;
-
-                                       /* shade front */
-                                       vlr= render_object_vlak_get(obr, 
(*rp-1) & RE_QUAD_MASK);
-                                       quad= ((*rp) & RE_QUAD_OFFS);
-
-                                       shade_sample_sss(re, &ssamp, mat, obi, 
vlr, quad, x, y, *rz,
-                                               co[totpoint], color[totpoint], 
&area[totpoint]);
-                                       
-                                       add_v3_v3v3(fcol, fcol, 
color[totpoint]);
-                                       fcol[3]= 1.0f;
-                                       totpoint++;
-                               }
-
-                               rp++; rz++; ro++;
-                       }
-
-                       if(rbp) {
-                               if(*rbp != 0 && !(*rbp == *(rp-1) && *rbo == 
*(ro-1))) {
-                                       ObjectInstanceRen *obi= 
&re->db.objectinstance[*rbo];
-                                       ObjectRen *obr= obi->obr;
-
-                                       /* shade back */
-                                       vlr= render_object_vlak_get(obr, 
(*rbp-1) & RE_QUAD_MASK);
-                                       quad= ((*rbp) & RE_QUAD_OFFS);
-
-                                       shade_sample_sss(re, &ssamp, mat, obi, 
vlr, quad, x, y, *rbz,
-                                               co[totpoint], color[totpoint], 
&area[totpoint]);
-                                       
-                                       /* to indicate this is a back sample */
+                               shade_sample_sss(re, &ssamp, mat, obi, vlr, 
quad, x, y, row[a].z,
+                                       co[totpoint], color[totpoint], 
&area[totpoint]);
+                               
+                               /* to indicate this is a back sample */
+                               if(a > 0)
                                        area[totpoint]= -area[totpoint];
 
-                                       add_v3_v3v3(fcol, fcol, 
color[totpoint]);
-                                       fcol[3]= 1.0f;
-                                       totpoint++;
-                               }
-
-                               rbz++; rbp++; rbo++;
+                               add_v3_v3v3(fcol, fcol, color[totpoint]);
+                               fcol[3]= 1.0f;
+                               totpoint++;
                        }
-#endif
                }
 
                if(y&1)
                        if(re->cb.test_break(re->cb.tbh)) break; 
        }
 
+       /* free tile precomputed data */
+       if(re->db.occlusiontree)
+               disk_occlusion_cache_free(re, pa);
+       else
+               irr_cache_free(re, pa);
+
        /* note: after adding we do not free these arrays, sss keeps them */
        if(totpoint > 0) {
                sss_add_points(re, co, color, area, totpoint);
@@ -1261,6 +1209,6 @@
                rr->renlay= render_get_active_layer(re, rr);
        }
        
-       zbufshade_sss_free(pa);
+       zbufshade_sss_free(pa, &psmlist);
 }
 

Modified: branches/render25/source/blender/render/intern/source/shadeoutput.c
===================================================================
--- branches/render25/source/blender/render/intern/source/shadeoutput.c 
2010-04-16 12:00:56 UTC (rev 28230)
+++ branches/render25/source/blender/render/intern/source/shadeoutput.c 
2010-04-16 14:09:25 UTC (rev 28231)
@@ -381,11 +381,12 @@
        if(!shi->primitive.strand && shi->shading.depth == 0 && count > 1 && 
count <= max) {
                float xs, ys, zs, view[3];
                int samp, ordsamp, tot= 0;
+               int osa= (re->params.osa)? re->params.osa: 1;
 
-               for(samp=0; samp<re->params.osa; samp++) {
-                       if(re->params.osa == 8) ordsamp = order8[samp];
-                       else if(re->params.osa == 11) ordsamp = order11[samp];
-                       else if(re->params.osa == 16) ordsamp = order16[samp];
+               for(samp=0; samp<osa; samp++) {
+                       if(osa == 8) ordsamp = order8[samp];
+                       else if(osa == 11) ordsamp = order11[samp];
+                       else if(osa == 16) ordsamp = order16[samp];
                        else ordsamp = samp;
 
                        if(shi->shading.mask & (1<<ordsamp)) {
@@ -692,30 +693,34 @@
 
 static void shade_surface_indirect(Render *re, ShadeInput *shi, ShadeResult 
*shr, int backside)
 {
+       Material *ma= shi->material.mat;
        int passflag= shi->shading.passflag;
+       int post_sss= ((ma->sss_flag & MA_DIFF_SSS) && sss_pass_done(re, ma));
 
-       shade_compute_ao(re, shi, shr); /* .ao */
+       if(!post_sss) {
+               shade_compute_ao(re, shi, shr); /* .ao */
 
-       /* add AO in combined? */
-       if((re->params.r.mode & R_RAYTRACE) || re->db.wrld.ao_gather_method == 
WO_LIGHT_GATHER_APPROX) {
-               if(re->db.wrld.mode & 
(WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) {
-                       if(((passflag & SCE_PASS_COMBINED) && 
(shi->shading.combinedflag & 
(SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT)))
-                               || (passflag & 
(SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT)))
-                               ambient_occlusion(re, shi);
+               /* add AO in combined? */

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to