Revision: 30073
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30073
Author:   blendix
Date:     2010-07-07 13:13:34 +0200 (Wed, 07 Jul 2010)

Log Message:
-----------
Render Branch: code to check if ao/env/indirect should be computed
was confusing and wrong in a few cases, with shadeless, ambient,
passes, etc, now added a single function for it.

Modified Paths:
--------------
    branches/render25/source/blender/render/intern/include/material.h
    branches/render25/source/blender/render/intern/include/shading.h
    branches/render25/source/blender/render/intern/source/bake.c
    branches/render25/source/blender/render/intern/source/cache.c
    branches/render25/source/blender/render/intern/source/material.c
    branches/render25/source/blender/render/intern/source/shadeoutput.c

Modified: branches/render25/source/blender/render/intern/include/material.h
===================================================================
--- branches/render25/source/blender/render/intern/include/material.h   
2010-07-07 09:29:11 UTC (rev 30072)
+++ branches/render25/source/blender/render/intern/include/material.h   
2010-07-07 11:13:34 UTC (rev 30073)
@@ -80,5 +80,9 @@
 
 void mat_displacement(struct Render *re, struct ShadeInput *shi, float 
displacement[3]);
 
+/* Queries */
+
+int mat_need_ao_env_indirect(struct Render *re, struct ShadeInput *shi);
+
 #endif /* __RENDER_MATERIAL_H__ */
 

Modified: branches/render25/source/blender/render/intern/include/shading.h
===================================================================
--- branches/render25/source/blender/render/intern/include/shading.h    
2010-07-07 09:29:11 UTC (rev 30072)
+++ branches/render25/source/blender/render/intern/include/shading.h    
2010-07-07 11:13:34 UTC (rev 30073)
@@ -103,7 +103,7 @@
 /* Utilities */
 void environment_lighting_apply(struct Render *re, struct ShadeInput *shi, 
struct ShadeResult *shr);
 
-void ambient_occlusion(struct Render *re, struct ShadeInput *shi);
+void shade_ao_env_indirect(struct Render *re, struct ShadeInput *shi);
 float fresnel_fac(float *view, float *vn, float fresnel, float fac);
 void shade_ray(struct Render *re, struct Isect *is, struct ShadeInput *shi, 
struct ShadeResult *shr);
 

Modified: branches/render25/source/blender/render/intern/source/bake.c
===================================================================
--- branches/render25/source/blender/render/intern/source/bake.c        
2010-07-07 09:29:11 UTC (rev 30072)
+++ branches/render25/source/blender/render/intern/source/bake.c        
2010-07-07 11:13:34 UTC (rev 30073)
@@ -196,7 +196,7 @@
        VlakRen *vlr= shi->primitive.vlr;
        
        if(bs->type==RE_BAKE_AO) {
-               ambient_occlusion(re, shi);
+               shade_ao_env_indirect(re, shi);
 
                if(re->params.r.bake_flag & R_BAKE_NORMALIZE) {
                        copy_v3_v3(shr.combined, shi->shading.ao);

Modified: branches/render25/source/blender/render/intern/source/cache.c
===================================================================
--- branches/render25/source/blender/render/intern/source/cache.c       
2010-07-07 09:29:11 UTC (rev 30072)
+++ branches/render25/source/blender/render/intern/source/cache.c       
2010-07-07 11:13:34 UTC (rev 30073)
@@ -51,14 +51,12 @@
 
 /******************************** Utilities **********************************/
 
-static int mat_need_cache(Render *re, Material *ma)
+static int mat_need_cache(Render *re, ShadeInput *shi)
 {
-       if(ma->mode & MA_SHLESS)
+       if(!mat_need_ao_env_indirect(re, shi))
                return 0;
-       else if(ma->amb == 0.0f && !(ma->mapto & MAP_AMB))
+       else if(!re->db.sss_pass && mat_has_only_sss(shi->material.mat))
                return 0;
-       else if(!re->db.sss_pass && mat_has_only_sss(ma))
-               return 0;
        
        return 1;
 }
@@ -227,7 +225,7 @@
                        shade_samples_from_pixel(re, ssamp, &row[0], x, y);
 
                        shi= ssamp->shi;
-                       if(shi->primitive.vlr && mat_need_cache(re, 
shi->material.mat)) {
+                       if(shi->primitive.vlr && mat_need_cache(re, shi)) {
                                disk_occlusion_sample_direct(re, shi);
 
                                copy_v3_v3(sample->co, shi->geometry.co);
@@ -1117,7 +1115,7 @@
                                                float *indirect= 
(re->db.wrld.mode & WO_INDIRECT_LIGHT)? shi->shading.indirect: NULL;
                                                int added;
 
-                                               if(!mat_need_cache(re, 
shi->material.mat))
+                                               if(!mat_need_cache(re, shi))
                                                        continue;
 
                                                if(shi->primitive.strand) {

Modified: branches/render25/source/blender/render/intern/source/material.c
===================================================================
--- branches/render25/source/blender/render/intern/source/material.c    
2010-07-07 09:29:11 UTC (rev 30072)
+++ branches/render25/source/blender/render/intern/source/material.c    
2010-07-07 11:13:34 UTC (rev 30073)
@@ -653,3 +653,36 @@
        }
 }
 
+/* Queries */
+
+int mat_need_ao_env_indirect(Render *re, ShadeInput *shi)
+{
+       Material *ma= shi->material.mat;
+
+       /* do we have it enabled at all? */
+       if(!(re->db.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)))
+               return 0;
+       if(!((re->params.r.mode & R_RAYTRACE) || re->db.wrld.ao_gather_method 
== WO_LIGHT_GATHER_APPROX))
+               return 0;
+       
+       /* if requested for passes, always render it */
+       if(shi->shading.passflag & 
(SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))
+               return 1;
+
+       if(shi->shading.passflag & SCE_PASS_COMBINED) {
+               /* rendering combined but no included, so can skip */
+               if(!(shi->shading.combinedflag & 
(SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT)))
+                       return 0;
+
+               /* some materials don't need it */
+               if(ma->mode & MA_SHLESS)
+                       return 0;
+               else if(ma->amb == 0.0f && !(ma->mapto & MAP_AMB))
+                       return 0;
+
+               return 1;
+       }
+
+       return 0;
+}
+

Modified: branches/render25/source/blender/render/intern/source/shadeoutput.c
===================================================================
--- branches/render25/source/blender/render/intern/source/shadeoutput.c 
2010-07-07 09:29:11 UTC (rev 30072)
+++ branches/render25/source/blender/render/intern/source/shadeoutput.c 
2010-07-07 11:13:34 UTC (rev 30073)
@@ -113,15 +113,14 @@
        }
 }
 
-/***************************** Ambient Occlusion *****************************/
+/***************************** AO / Env / Indirect 
*****************************/
 
-/* pure AO, check for raytrace and world should have been done */
-/* preprocess, textures were not done, don't use shi->material.amb for that 
reason */
-void ambient_occlusion(Render *re, ShadeInput *shi)
+void shade_ao_env_indirect(Render *re, ShadeInput *shi)
 {
-       if((re->db.wrld.ao_gather_method == WO_LIGHT_GATHER_APPROX) && 
shi->material.mat->amb!=0.0f)
+       if(re->db.wrld.ao_gather_method == WO_LIGHT_GATHER_APPROX) {
                disk_occlusion_sample(re, shi);
-       else if((re->params.r.mode & R_RAYTRACE) && 
shi->material.mat->amb!=0.0f) {
+       }
+       else if(re->params.r.mode & R_RAYTRACE) {
                int thread= shi->shading.thread;
                float *ao= (re->db.wrld.mode & WO_AMB_OCC)? shi->shading.ao: 
NULL;
                float *env= (re->db.wrld.mode & WO_ENV_LIGHT)? 
shi->shading.env: NULL;
@@ -170,31 +169,32 @@
 
        copy_v3_v3(shr->ao, shi->shading.ao);
 
-       if(!(shi->shading.combinedflag & SCE_PASS_AO))
-               return;
+       if(shi->shading.combinedflag & SCE_PASS_AO) {
+               if(f == 0.0f)
+                       return;
 
-       if(f == 0.0f)
-               return;
+               if(re->db.wrld.aomix==WO_AO_ADD) {
+                       /* additive */
+                       mat_color(color, &shi->material);
 
-       if(re->db.wrld.aomix==WO_AO_ADD) {
-               mat_color(color, &shi->material);
+                       shr->diff[0] += shi->shading.ao[0]*color[0]*f;
+                       shr->diff[1] += shi->shading.ao[1]*color[1]*f;
+                       shr->diff[2] += shi->shading.ao[2]*color[2]*f;
+               }
+               else if(re->db.wrld.aomix==WO_AO_MUL) {
+                       /* multiply to darken */
+                       mul_v3_v3v3(tmp, shr->diff, shi->shading.ao);
+                       mul_v3_v3v3(tmpspec, shr->spec, shi->shading.ao);
 
-               shr->diff[0] += shi->shading.ao[0]*color[0]*f;
-               shr->diff[1] += shi->shading.ao[1]*color[1]*f;
-               shr->diff[2] += shi->shading.ao[2]*color[2]*f;
-       }
-       else if(re->db.wrld.aomix==WO_AO_MUL) {
-               mul_v3_v3v3(tmp, shr->diff, shi->shading.ao);
-               mul_v3_v3v3(tmpspec, shr->spec, shi->shading.ao);
-
-               if(f == 1.0f) {
-                       copy_v3_v3(shr->diff, tmp);
-                       copy_v3_v3(shr->spec, tmpspec);
+                       if(f == 1.0f) {
+                               copy_v3_v3(shr->diff, tmp);
+                               copy_v3_v3(shr->spec, tmpspec);
+                       }
+                       else {
+                               interp_v3_v3v3(shr->diff, shr->diff, tmp, f);
+                               interp_v3_v3v3(shr->spec, shr->spec, tmpspec, 
f);
+                       }
                }
-               else {
-                       interp_v3_v3v3(shr->diff, shr->diff, tmp, f);
-                       interp_v3_v3v3(shr->spec, shr->spec, tmpspec, f);
-               }
        }
 }
 
@@ -218,19 +218,6 @@
                add_v3_v3(shr->diff, shr->indirect);
 }
 
-static void shade_compute_ao(Render *re, ShadeInput *shi, ShadeResult *shr)
-{
-       int passflag= shi->shading.passflag;
-
-       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);
-               }
-       }
-}
-
 /********************************* Shading ***********************************/
 
 static float shade_phong_correction(Render *re, LampRen *lar, ShadeInput *shi, 
float *lv)
@@ -301,10 +288,10 @@
        }
        
        /* quite disputable this...  also note it doesn't mirror-raytrace */    
-       if((re->db.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT)) && 
shi->material.amb!=0.0f) {
+       if(mat_need_ao_env_indirect(re, shi)) {
                float f;
 
-               ambient_occlusion(re, shi);
+               shade_ao_env_indirect(re, shi);
                
                if(re->db.wrld.mode & WO_AMB_OCC) {
                        f= re->db.wrld.aoenergy*shi->material.amb;
@@ -702,20 +689,17 @@
        int post_sss= ((ma->sss_flag & MA_DIFF_SSS) && sss_pass_done(re, ma));
 
        if(!post_sss || (passflag & 
(SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) {
-               shade_compute_ao(re, shi, shr); /* .ao */
+               if(mat_need_ao_env_indirect(re, shi)) {
+                       shade_ao_env_indirect(re, shi);
 
-               /* 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(re->db.wrld.mode & WO_ENV_LIGHT)
-                                       environment_lighting_apply(re, shi, 
shr);
+                       if(re->db.wrld.mode & WO_ENV_LIGHT)
+                               environment_lighting_apply(re, shi, shr);
 
-                               if(re->db.wrld.mode & WO_INDIRECT_LIGHT)
-                                       indirect_lighting_apply(re, shi, shr);
+                       if(re->db.wrld.mode & WO_INDIRECT_LIGHT)
+                               indirect_lighting_apply(re, shi, shr);
 
-                               if(re->db.wrld.mode & WO_AMB_OCC)
-                                       ambient_occlusion_apply(re, shi, shr);
-                       }
+                       if(re->db.wrld.mode & WO_AMB_OCC)
+                               ambient_occlusion_apply(re, shi, shr);
                }
                        
                /* ambient light */


_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to