diff options
author | Ton Roosendaal <ton@blender.org> | 2004-04-12 18:53:17 +0400 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2004-04-12 18:53:17 +0400 |
commit | c2526dc92214e6c1929c98d32db744451aa81599 (patch) | |
tree | 1fee7998ce742314dac6a79ca9d9584da29013b4 /source/blender | |
parent | b78641f524936785b39704e2c0b6b70c03d9f2b5 (diff) |
More AO fun to play with:
- 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!
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/world.c | 4 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 1 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_world_types.h | 13 | ||||
-rw-r--r-- | source/blender/render/intern/source/ray.c | 39 | ||||
-rw-r--r-- | source/blender/render/intern/source/rendercore.c | 32 | ||||
-rw-r--r-- | source/blender/render/intern/source/texture.c | 17 | ||||
-rw-r--r-- | source/blender/src/buttons_shading.c | 18 | ||||
-rw-r--r-- | source/blender/src/previewrender.c | 6 |
8 files changed, 105 insertions, 25 deletions
diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index a31c33e76e6..e378dd4d996 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -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)); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 9f6ba376180..6708db87d2b 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -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; } diff --git a/source/blender/makesdna/DNA_world_types.h b/source/blender/makesdna/DNA_world_types.h index c325c2d1b8a..baceb4e17e9 100644 --- a/source/blender/makesdna/DNA_world_types.h +++ b/source/blender/makesdna/DNA_world_types.h @@ -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 diff --git a/source/blender/render/intern/source/ray.c b/source/blender/render/intern/source/ray.c index dc736b85e22..f7f5e76a825 100644 --- a/source/blender/render/intern/source/ray.c +++ b/source/blender/render/intern/source/ray.c @@ -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; + } } diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index 8c12ed47b48..7bc27258e91 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -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]; + } } } diff --git a/source/blender/render/intern/source/texture.c b/source/blender/render/intern/source/texture.c index 275d2af5e8d..d99c58d6aa3 100644 --- a/source/blender/render/intern/source/texture.c +++ b/source/blender/render/intern/source/texture.c @@ -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)) { diff --git a/source/blender/src/buttons_shading.c b/source/blender/src/buttons_shading.c index 10259ca2621..b8835e7c5a9 100644 --- a/source/blender/src/buttons_shading.c +++ b/source/blender/src/buttons_shading.c @@ -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"); } } diff --git a/source/blender/src/previewrender.c b/source/blender/src/previewrender.c index a5543d8276a..9621c3f2faa 100644 --- a/source/blender/src/previewrender.c +++ b/source/blender/src/previewrender.c @@ -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) */ } |