More AO fun to play with:
authorTon Roosendaal <ton@blender.org>
Mon, 12 Apr 2004 14:53:17 +0000 (14:53 +0000)
committerTon Roosendaal <ton@blender.org>
Mon, 12 Apr 2004 14:53:17 +0000 (14:53 +0000)
- AO energy slider to control amount
- option "Use sky color" for colored AO. The horizon color will define
  bottom diffuse color, the zenith works on top
- option "Use sky texture" will do a full sky render to define AO color

Please note that AO energy and color only is found when a ray does not
intersect. So for interior scenes make sure 'Dist' value is sufficient
low.

New also is:

- World "Map input" allows "Ang Map" (Angular mapping) which can be used
for 360 degree spherical maps, aka as Light Probes. Check samples here:
http://www.debevec.org/Probes/
Note that Blender doesn't support HDRI images yet, but option "Use sky tex"
already gives intersting results with such images

- World sky rendering with Image Textures now correctly filters and uses
antialiasing. Also noticable for raytrace mirror reflections

- World preview render for sky type "Real" now gives correct view as
defined by current used camera.

I tried to speed up AO tracing with coherence systems, none of it really
worked yet... time to tackle octree itself i guess!

source/blender/blenkernel/intern/world.c
source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_world_types.h
source/blender/render/intern/source/ray.c
source/blender/render/intern/source/rendercore.c
source/blender/render/intern/source/texture.c
source/blender/src/buttons_shading.c
source/blender/src/previewrender.c

index a31c33e76e62b358dd6f0b8d9176952686dd1bbb..e378dd4d996373f0807fab2e0d0e266901bc1b77 100644 (file)
@@ -199,10 +199,6 @@ void init_render_world()
                        }
                }
                
-               /* ambient occlusion */
-               R.wrld.aototsamp= R.wrld.aosamp*R.wrld.aosamp;
-               
-               
        }
        else {
                memset(&R.wrld, 0, sizeof(World));
index 9f6ba3761805add2bd1319660e0f0f63b93f2824..6708db87d2b248a048315ab5cc87dcfd36c11c4a 100644 (file)
@@ -4143,6 +4143,7 @@ static void do_versions(Main *main)
                while(wrld) {
                        if(wrld->aodist==0.0) wrld->aodist= 10.0;
                        if(wrld->aosamp==0.0) wrld->aosamp= 5;
+                       if(wrld->aoenergy==0.0) wrld->aoenergy= 1.0;
                        wrld= wrld->id.next;
                }
                
index c325c2d1b8addd271e1fbb041279712cf9f7820e..baceb4e17e9de5f39dc3f139638325635c002036 100644 (file)
@@ -95,8 +95,8 @@ typedef struct World {
        short dofsta, dofend, dofmin, dofmax;
        
        /* ambient occlusion */
-       float aodist, aodistfac;
-       short aomode, aosamp, aomix, aototsamp;
+       float aodist, aodistfac, aoenergy, pad;
+       short aomode, aosamp, aomix, aocolor;
        
        int physicsEngine;
 
@@ -113,7 +113,7 @@ typedef struct World {
 #define WO_SKYBLEND            1
 #define WO_SKYREAL             2
 #define WO_SKYPAPER            4
-/* tijdens render: */
+/* while render: */
 #define WO_SKYTEX              8
 #define WO_ZENUP               16
 
@@ -133,6 +133,13 @@ typedef struct World {
 #define WO_AODIST              1
 #define WO_AORNDSMP            2
 
+/* aocolor */
+#define WO_AOPLAIN     0
+#define WO_AOSKYCOL    1
+#define WO_AOSKYTEX    2
+
+/* texco (also in DNA_material_types.h) */
+#define TEXCO_ANGMAP   64
 
 /* mapto */
 #define WOMAP_BLEND            1
index dc736b85e22547b5a7936027156e89517b4d5c68..f7f5e76a825020b0a5e5042df20c60eb9ff99385 100644 (file)
@@ -1074,7 +1074,7 @@ static int d3dda(Isect *is)
                */
                if(coh_test) {
                        if(coh_ocx1==ocx1 && coh_ocy1==ocy1 && coh_ocz1==ocz1
-                                && coh_ocx2==ocx2 && coh_ocy2==ocy2 && coh_ocz2==ocz2);
+                          && coh_ocx2==ocx2 && coh_ocy2==ocy2 && coh_ocz2==ocz2);
                        else coh_test= 0;
                }
                
@@ -1878,6 +1878,8 @@ void ray_ao(ShadeInput *shi, World *wrld, float *shadfac)
        isec.mode= DDA_SHADOW;
        coh_test= 0;            // reset coherence optimize
 
+       shadfac[0]= shadfac[1]= shadfac[2]= 0.0;
+
        VECCOPY(nrm, shi->vn);
        if ((nrm[0]==0.0) && (nrm[1]==0.0)) {
                if (nrm[2]<0) ru[0]=-1; else ru[0]=1;
@@ -1929,14 +1931,43 @@ void ray_ao(ShadeInput *shi, World *wrld, float *shadfac)
                                isec.start[2]= shi->co[2] + (jit[j][0]-0.5)*O.dxco[2] + (jit[j][1]-0.5)*O.dyco[2] ;
                                j = ((j+1) % R.osa);
                        }
+                       /* do the trace */
                        if (d3dda(&isec)) {
                                if (wrld->aomode & WO_AODIST) sh+=exp(-isec.labda*wrld->aodistfac); else sh+=1.0;
                        }
+                       else if(wrld->aocolor!=WO_AOPLAIN) {
+                               char skycol[4];
+                               float fac, view[3];
+                               
+                               view[0]= -vec[0];
+                               view[1]= -vec[1];
+                               view[2]= -vec[2];
+                               Normalise(view);
+                               
+                               if(wrld->aocolor==WO_AOSKYCOL) {
+                                       fac= 0.5*(1.0+view[0]*R.grvec[0]+ view[1]*R.grvec[1]+ view[2]*R.grvec[2]);
+                                       shadfac[0]+= (1.0-fac)*R.wrld.horr + fac*R.wrld.zenr;
+                                       shadfac[1]+= (1.0-fac)*R.wrld.horg + fac*R.wrld.zeng;
+                                       shadfac[2]+= (1.0-fac)*R.wrld.horb + fac*R.wrld.zenb;
+                               }
+                               else {
+                                       RE_sky(view, skycol);
+                                       shadfac[0]+= skycol[0]/255.0;
+                                       shadfac[1]+= skycol[1]/255.0;
+                                       shadfac[2]+= skycol[2]/255.0;
+                               }
+                       }
                }
        }
-
-       shadfac[3] = 1.0 - (sh/(float)wrld->aototsamp);
-
+       
+       gdiv= wrld->aoenergy/(float)(wrld->aosamp*wrld->aosamp);
+       shadfac[3] = wrld->aoenergy - (sh*gdiv);
+       
+       if(wrld->aocolor!=WO_AOPLAIN) {
+               shadfac[0] *= gdiv;
+               shadfac[1] *= gdiv;
+               shadfac[2] *= gdiv;
+       }
 }
 
 
index 8c12ed47b4898424d21abb896dd0ca7a4710f298..7bc27258e91dda02e2d8e2755b0d7e1634dc7d6d 100644 (file)
@@ -193,7 +193,7 @@ void RE_sky(float *view, char *col)
                if(R.wrld.skytype & WO_SKYREAL) {
                        
                        MTC_Mat3MulVecfl(R.imat, lo);
-
+       
                        SWAP(float, lo[1],  lo[2]);
                        
                }
@@ -1647,13 +1647,31 @@ static void ambient_occlusion(World *wrld, ShadeInput *shi, ShadeResult *shr)
        if(wrld->mode & WO_AMB_OCC) {
                ray_ao(shi, wrld, shadfac);
 
-               if (wrld->aomix==WO_AOADDSUB) shadfac[3] = 2.0*shadfac[3]-1.0;
-               else if (wrld->aomix==WO_AOSUB) shadfac[3] = -(1.0-shadfac[3]);
+               if(wrld->aocolor==WO_AOPLAIN) {
+                       if (wrld->aomix==WO_AOADDSUB) shadfac[3] = 2.0*shadfac[3]-1.0;
+                       else if (wrld->aomix==WO_AOSUB) shadfac[3] = shadfac[3]-1.0;
 
-               f= shadfac[3]*shi->matren->amb;
-               shr->diff[0] += f;
-               shr->diff[1] += f;
-               shr->diff[2] += f;
+                       f= shadfac[3]*shi->matren->amb;
+                       shr->diff[0] += f;
+                       shr->diff[1] += f;
+                       shr->diff[2] += f;
+               }
+               else {
+                       if (wrld->aomix==WO_AOADDSUB) {
+                               shadfac[0] = 2.0*shadfac[0]-1.0;
+                               shadfac[1] = 2.0*shadfac[1]-1.0;
+                               shadfac[2] = 2.0*shadfac[2]-1.0;
+                       }
+                       else if (wrld->aomix==WO_AOSUB) {
+                               shadfac[0] = shadfac[0]-1.0;
+                               shadfac[1] = shadfac[1]-1.0;
+                               shadfac[2] = shadfac[2]-1.0;
+                       }
+                       f= shi->matren->amb;
+                       shr->diff[0] += f*shadfac[0];
+                       shr->diff[1] += f*shadfac[1];
+                       shr->diff[2] += f*shadfac[2];
+               }
        }
 }
 
index 275d2af5e8d03dcd35c08a6c96ec36fb6557aa12..d99c58d6aa33ade9b7513dcd66e44840c31c663c 100644 (file)
@@ -1719,8 +1719,21 @@ void do_sky_tex(float *lo)
                        /* which coords */
                        co= lo;
                        
+                       /* dxt dyt just from 1 value */
+                       dxt[0]= dxt[1]= dxt[2]= O.dxview;
+                       dyt[0]= dyt[1]= dyt[2]= O.dyview;
+                       
                        /* Grab the mapping settings for this texture */
-                       if(mtex->texco==TEXCO_OBJECT) {
+                       if(mtex->texco==TEXCO_ANGMAP) {
+                               
+                               fact= (1.0/M_PI)*acos(lo[2])/(sqrt(lo[0]*lo[0] + lo[1]*lo[1])); 
+                               tempvec[0]= lo[0]*fact;
+                               tempvec[1]= lo[1]*fact;
+                               tempvec[2]= 0.0;
+                               co= tempvec;
+                               
+                       }
+                       else if(mtex->texco==TEXCO_OBJECT) {
                                Object *ob= mtex->object;
                                if(ob) {
                                        VECCOPY(tempvec, lo);
@@ -1742,7 +1755,7 @@ void do_sky_tex(float *lo)
                        /* texture */
                        if(mtex->tex->type==TEX_IMAGE) do_2d_mapping(mtex, texvec, NULL, dxt, dyt);
                        
-                       rgb= multitex(mtex->tex, texvec, dxt, dyt, 0);
+                       rgb= multitex(mtex->tex, texvec, dxt, dyt, R.osa);
                        
                        /* texture output */
                        if(rgb && (mtex->texflag & MTEX_RGBTOINT)) {
index 10259ca2621f5c3492603960a44c86a439f31749..b8835e7c5a947a205894405ee04be34144d2945c 100644 (file)
@@ -1626,10 +1626,11 @@ static void world_panel_texture(World *wrld)
 
        /* TEXCO */
        uiBlockBeginAlign(block);
-       uiDefButS(block, ROW, B_MATPRV, "View",                 100,110,50,19, &(mtex->texco), 4.0, (float)TEXCO_VIEW, 0, 0, "Uses camera view vector for texture coordinates");
-       uiDefButS(block, ROW, B_MATPRV, "Object",               150,110,50,19, &(mtex->texco), 4.0, (float)TEXCO_OBJECT, 0, 0, "Uses linked object's coordinates for texture coordinates: click to change");
-       uiDefIDPoinBut(block, test_obpoin_but, B_MATPRV, "", 200,110,100,19, &(mtex->object), "");
-       
+       uiDefButS(block, ROW, B_MATPRV, "View",                 100,110,60,20, &(mtex->texco), 4.0, (float)TEXCO_VIEW, 0, 0, "Uses global coordinates for the texture coordinates");
+       uiDefButS(block, ROW, B_MATPRV, "AngMap",               160,110,70,20, &(mtex->texco), 4.0, (float)TEXCO_ANGMAP, 0, 0, "Uses angular coordinates for the texture coordinates");
+       uiDefButS(block, ROW, B_MATPRV, "Object",               230,110,70,20, &(mtex->texco), 4.0, (float)TEXCO_OBJECT, 0, 0, "Uses linked object's coordinates for texture coordinates");
+       uiDefIDPoinBut(block, test_obpoin_but, B_MATPRV, "", 100,90,200,20, &(mtex->object), "");
+
        uiBlockBeginAlign(block);
        uiDefButF(block, NUM, B_MATPRV, "dX",           100,50,100,19, mtex->ofs, -20.0, 20.0, 10, 0, "Fine tunes texture mapping X coordinate");
        uiDefButF(block, NUM, B_MATPRV, "dY",           100,30,100,19, mtex->ofs+1, -20.0, 20.0, 10, 0, "Fine tunes texture mapping Y coordinate");
@@ -1722,6 +1723,15 @@ static void world_panel_amb_occ(World *wrld)
                uiDefButS(block, ROW, B_REDR, "Add", 10, 45, 100, 20, &wrld->aomix, 1.0, (float)WO_AOADD, 0, 0, "adds light/shadows");
                uiDefButS(block, ROW, B_REDR, "Sub", 110, 45, 100, 20, &wrld->aomix, 1.0, (float)WO_AOSUB, 0, 0, "subtracts light/shadows (needs at least one normal light to make anything visible)");
                uiDefButS(block, ROW, B_REDR, "Both", 210, 45, 100, 20, &wrld->aomix, 1.0, (float)WO_AOADDSUB, 0, 0, "both lightens & darkens");
+
+               /* color treatment */
+               uiBlockBeginAlign(block);
+               uiDefButS(block, ROW, B_REDR, "Plain", 10, 25, 100, 20, &wrld->aocolor, 2.0, (float)WO_AOPLAIN, 0, 0, "Plain diffuse energy (white)");
+               uiDefButS(block, ROW, B_REDR, "Sky Color", 110, 25, 100, 20, &wrld->aocolor, 2.0, (float)WO_AOSKYCOL, 0, 0, "Use horizon and zenith color for diffuse energy");
+               uiDefButS(block, ROW, B_REDR, "Sky Texture", 210, 25, 100, 20, &wrld->aocolor, 2.0, (float)WO_AOSKYTEX, 0, 0, "Does full Sky texture render for diffuse energy");
+               uiBlockEndAlign(block);
+               
+               uiDefButF(block, NUMSLI, 0, "Energy:", 10, 0, 300, 19, &wrld->aoenergy, 0.01, 50.0, 100, 0, "Sets global energy scale for AO");
        }
 
 }
index a5543d8276a0abb1300c424ab602674d7e438256..9621c3f2faa87b67d467a1812ede9e1cfa20e6e8 100644 (file)
@@ -1082,7 +1082,11 @@ void BIF_previewrender(SpaceButs *sbuts)
                if(G.scene->camera) {
                        lens= ( (Camera *)G.scene->camera->data)->lens;
                }
-               
+               /* needed for init_render_world */
+               MTC_Mat4CpyMat4(R.viewinv, G.scene->camera->obmat);
+               MTC_Mat4Ortho(R.viewinv);
+               MTC_Mat4Invert(R.viewmat, R.viewinv);
+
                init_render_world();
                init_render_textures(); /* dont do it twice!! (brightness) */
        }