From ec99255c2729b555f34d75c0a2c59f141e327924 Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Sun, 21 Dec 2003 21:52:51 +0000 Subject: [PATCH] Phew, a lot of work, and no new features... Main target was to make the inner rendering loop using no globals anymore. This is essential for proper usage while raytracing, it caused a lot of hacks in the raycode as well, which even didn't work correctly for all situations (textures especially). Done this by creating a new local struct RenderInput, which replaces usage of the global struct Render R. The latter now only is used to denote image size, viewmatrix, and the like. Making the inner render loops using no globals caused 1000s of vars to be changed... but the result definitely is much nicer code, which enables making 'real' shaders in a next stage. It also enabled me to remove the hacks from ray.c Then i went to the task of removing redundant code. Especially the calculus of texture coords took place (identical) in three locations. Most obvious is the change in the unified render part, which is much less code now; it uses the same rendering routines as normal render now. (Note; not for halos yet!) I also removed 6 files called 'shadowbuffer' something. This was experimen- tal stuff from NaN days. And again saved a lot of double used code. Finally I went over the blenkernel and blender/src calls to render stuff. Here the same local data is used now, resulting in less dependency. I also moved render-texture to the render module, this was still in Kernel. (new file: texture.c) So! After this commit I will check on the autofiles, to try to fix that. MSVC people have to do it themselves. This commit will need quite some testing help, but I'm around! --- source/blender/blenkernel/BKE_global.h | 1 - source/blender/blenkernel/BKE_texture.h | 23 - .../blenkernel/bad_level_call_stubs/stubs.c | 7 - source/blender/blenkernel/intern/displist.c | 51 +- source/blender/blenkernel/intern/effect.c | 3 +- source/blender/blenkernel/intern/exotic.c | 5 +- source/blender/blenkernel/intern/library.c | 4 +- source/blender/blenkernel/intern/object.c | 3 - source/blender/blenkernel/intern/scene.c | 1 + source/blender/blenkernel/intern/texture.c | 1785 ---------------- source/blender/makesdna/DNA_camera_types.h | 5 - source/blender/render/extern/include/render.h | 59 +- .../render/extern/include/render_types.h | 21 +- .../intern/include/RE_DummyShadowBuffer.h | 71 - .../render/intern/include/RE_ShadowBuffer.h | 62 - .../intern/include/RE_basicShadowBuffer.h | 93 - source/blender/render/intern/include/envmap.h | 1 + .../render/intern/include/pixelshading.h | 59 +- .../render/intern/include/rendercore.h | 23 +- .../render/intern/include/rendercore_int.h | 3 +- .../blender/render/intern/include/shadbuf.h | 13 +- .../render/intern/include/shadowBuffer.h | 80 - .../blender/render/intern/include/texture.h | 36 +- .../blender/render/intern/include/zbuf_int.h | 2 +- .../intern/source/RE_DummyShadowBuffer.cpp | 68 - .../intern/source/RE_basicShadowBuffer.cpp | 694 ------ .../blender/render/intern/source/edgeRender.c | 3 +- source/blender/render/intern/source/envmap.c | 4 +- .../blender/render/intern/source/initrender.c | 53 +- .../render/intern/source/outerRenderLoop.c | 6 - .../render/intern/source/pixelshading.c | 1334 +----------- source/blender/render/intern/source/ray.c | 604 ++---- .../render/intern/source/renderPreAndPost.c | 13 +- .../blender/render/intern/source/rendercore.c | 1291 ++++++------ .../render/intern/source/renderdatabase.c | 1 + source/blender/render/intern/source/shadbuf.c | 18 +- .../render/intern/source/shadowBuffer.cpp | 102 - source/blender/render/intern/source/texture.c | 1872 +++++++++++++++++ .../render/intern/source/vanillaRenderPipe.c | 34 +- source/blender/render/intern/source/zbuf.c | 43 +- .../intern/convertBlenderScene.c | 36 +- source/blender/src/previewrender.c | 204 +- source/blender/src/toolbox.c | 3 +- source/blender/src/view.c | 18 +- source/blender/src/writeavicodec.c | 1 - source/blender/src/writeimage.c | 2 +- source/blender/src/writemovie.c | 2 - 47 files changed, 3067 insertions(+), 5750 deletions(-) delete mode 100644 source/blender/render/intern/include/RE_DummyShadowBuffer.h delete mode 100644 source/blender/render/intern/include/RE_ShadowBuffer.h delete mode 100644 source/blender/render/intern/include/RE_basicShadowBuffer.h delete mode 100644 source/blender/render/intern/include/shadowBuffer.h delete mode 100644 source/blender/render/intern/source/RE_DummyShadowBuffer.cpp delete mode 100644 source/blender/render/intern/source/RE_basicShadowBuffer.cpp delete mode 100644 source/blender/render/intern/source/shadowBuffer.cpp create mode 100644 source/blender/render/intern/source/texture.c diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h index 698982f5396..c8564e44cdc 100644 --- a/source/blender/blenkernel/BKE_global.h +++ b/source/blender/blenkernel/BKE_global.h @@ -244,7 +244,6 @@ typedef struct Global { #define B_ENDIAN 0 /* G.special1 */ -#define G_HOLO 1 /* Memory is allocated where? blender.c */ extern Global G; diff --git a/source/blender/blenkernel/BKE_texture.h b/source/blender/blenkernel/BKE_texture.h index 711ad893486..547ac593d15 100644 --- a/source/blender/blenkernel/BKE_texture.h +++ b/source/blender/blenkernel/BKE_texture.h @@ -59,29 +59,6 @@ struct MTex *add_mtex(void); struct Tex *copy_texture(struct Tex *tex); void make_local_texture(struct Tex *tex); void autotexname(struct Tex *tex); -void init_render_texture(struct Tex *tex); -void init_render_textures(void); -void end_render_texture(struct Tex *tex); -void end_render_textures(void); -int clouds(struct Tex *tex, float *texvec); -int blend(struct Tex *tex, float *texvec); -int wood(struct Tex *tex, float *texvec); -int marble(struct Tex *tex, float *texvec); -int magic(struct Tex *tex, float *texvec); -int stucci(struct Tex *tex, float *texvec); -int texnoise(struct Tex *tex); -int plugintex(struct Tex *tex, float *texvec, float *dxt, float *dyt); -void tubemap(float x, float y, float z, float *adr1, float *adr2); -void spheremap(float x, float y, float z, float *adr1, float *adr2); -void do_2d_mapping(struct MTex *mtex, float *t, float *dxt, float *dyt); -int multitex(struct Tex *tex, float *texvec, float *dxt, float *dyt); -void do_material_tex(void); -void do_halo_tex(struct HaloRen *har, float xn, float yn, float *colf); -void do_sky_tex(void); -void do_lamp_tex(struct LampRen *la, float *lavec); -void externtex(struct MTex *mtex, float *vec); -void externtexcol(struct MTex *mtex, float *orco, char *col); -void render_realtime_texture(void); #endif diff --git a/source/blender/blenkernel/bad_level_call_stubs/stubs.c b/source/blender/blenkernel/bad_level_call_stubs/stubs.c index 302810fa919..81d77dac227 100644 --- a/source/blender/blenkernel/bad_level_call_stubs/stubs.c +++ b/source/blender/blenkernel/bad_level_call_stubs/stubs.c @@ -90,13 +90,6 @@ ListBase editNurb; #include "render_types.h" struct RE_Render R; -float Phong_Spec(float *n, float *l, float *v, int hard){return 0;} -float Blinn_Spec(float *n, float *l, float *v, float a, float b){return 0;} -float CookTorr_Spec(float *n, float *l, float *v, int hard){return 0;} -float Toon_Spec(float *n, float *l, float *v, float a, float b){return 0;} -float Toon_Diff(float *n, float *l, float *v, float a, float b){return 0;} -float OrenNayar_Diff(float *n, float *l, float *v, float a, float b){return 0;} - void waitcursor(int val){} void allqueue(unsigned short event, short val){} #define REDRAWVIEW3D 0x4010 diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 3a42d708f28..c60a614bab8 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -46,9 +46,6 @@ #endif #include "MEM_guardedalloc.h" -#include "nla.h" /* For __NLA: Please do not remove yet */ -#include "render.h" - #include "IMB_imbuf_types.h" #include "DNA_texture_types.h" @@ -88,6 +85,10 @@ #include "BKE_scene.h" #include "BKE_subsurf.h" +#include "nla.h" /* For __NLA: Please do not remove yet */ +#include "render.h" + + /***/ typedef struct _FastLamp FastLamp; @@ -226,8 +227,6 @@ static void initfastshade(void) FastLamp *fl; float mat[4][4]; - R.vlr= 0; - init_render_world(); if(fastlamplist) return; @@ -301,16 +300,18 @@ void freefastshade() static void fastshade(float *co, float *nor, float *orco, Material *ma, char *col1, char *col2, char *vertcol) { + ShadeInput shi; FastLamp *fl; float i, t, inp, soft, inpr, inpg, inpb, isr=0, isg=0, isb=0, lv[3], view[3], lampdist, ld; float inpr1, inpg1, inpb1, isr1=0, isg1=0, isb1=0; int a, back; if(ma==0) return; - R.mat= ma; - R.matren= ma->ren; - ma= R.matren; - + shi.mat= ma; + shi.matren= ma->ren; + shi.vlr= NULL; // have to do this! + ma= shi.matren; + if(ma->mode & MA_VERTEXCOLP) { if(vertcol) { ma->r= vertcol[3]/255.0; @@ -320,41 +321,41 @@ static void fastshade(float *co, float *nor, float *orco, Material *ma, char *co } if(ma->texco) { - VECCOPY(R.lo, orco); - VECCOPY(R.vn, nor); + VECCOPY(shi.lo, orco); + VECCOPY(shi.vn, nor); if(ma->texco & TEXCO_GLOB) { - VECCOPY(R.gl, R.lo); + VECCOPY(shi.gl, shi.lo); } if(ma->texco & TEXCO_WINDOW) { - VECCOPY(R.winco, R.lo); + VECCOPY(shi.winco, shi.lo); } if(ma->texco & TEXCO_STICKY) { - VECCOPY(R.sticky, R.lo); + VECCOPY(shi.sticky, shi.lo); } if(ma->texco & TEXCO_UV) { - VECCOPY(R.uv, R.lo); + VECCOPY(shi.uv, shi.lo); } if(ma->texco & TEXCO_OBJECT) { - VECCOPY(R.co, R.lo); + VECCOPY(shi.co, shi.lo); } if(ma->texco & TEXCO_NORM) { - VECCOPY(R.orn, R.vn); + VECCOPY(shi.orn, shi.vn); } if(ma->texco & TEXCO_REFL) { - inp= 2.0*(R.vn[2]); - R.ref[0]= (inp*R.vn[0]); - R.ref[1]= (inp*R.vn[1]); - R.ref[2]= (-1.0+inp*R.vn[2]); + inp= 2.0*(shi.vn[2]); + shi.ref[0]= (inp*shi.vn[0]); + shi.ref[1]= (inp*shi.vn[1]); + shi.ref[2]= (-1.0+inp*shi.vn[2]); } if(ma->mode & MA_VERTEXCOLP) { - R.mat->r= ma->r; - R.mat->g= ma->g; - R.mat->b= ma->b; + shi.mat->r= ma->r; + shi.mat->g= ma->g; + shi.mat->b= ma->b; } - do_material_tex(); + do_material_tex(&shi); } if(ma->mode & MA_SHLESS) { diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 7dbc7f05f8f..18f3ebd7197 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -59,12 +59,13 @@ #include "BKE_key.h" #include "BKE_ipo.h" #include "BKE_screen.h" -#include "BKE_texture.h" #include "BKE_blender.h" #include "BKE_object.h" #include "BKE_displist.h" #include "BKE_lattice.h" +#include "render.h" + #ifdef HAVE_CONFIG_H #include #endif diff --git a/source/blender/blenkernel/intern/exotic.c b/source/blender/blenkernel/intern/exotic.c index fb4735bbb9d..e1ff554494d 100644 --- a/source/blender/blenkernel/intern/exotic.c +++ b/source/blender/blenkernel/intern/exotic.c @@ -683,7 +683,8 @@ static void read_videoscape_nurbs(char *str) static void read_videoscape(char *str) { int file, type; - unsigned int val, numlen; + unsigned int val; + unsigned short numlen; char name[FILE_MAXDIR+FILE_MAXFILE], head[FILE_MAXFILE], tail[FILE_MAXFILE]; strcpy(name, str); @@ -2234,7 +2235,7 @@ void write_videoscape(char *str) { Base *base; int file, val, lampdone=0; - unsigned int numlen; + unsigned short numlen; char head[FILE_MAXFILE], tail[FILE_MAXFILE]; if(BLI_testextensie(str,".trace")) str[ strlen(str)-6]= 0; diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index d693148fe94..51d22b2802d 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -514,7 +514,7 @@ void free_main(Main *mainvar) ListBase *lb= lbarray[a]; ID *id; - while (id= lb->first) { + while ( (id= lb->first) ) { free_libblock(lb, id); } } @@ -810,7 +810,7 @@ int new_id(ListBase *lb, ID *id, char *tname) return (new_id(lb, id, left)); } /* this format specifier is from hell... */ - sprintf(id->name+2, "%s.%0.3d", left, nr); + sprintf(id->name+2, "%s.%.3d", left, nr); } sort_alpha_id(lb, id); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index cabaf088147..eeba4b91e01 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -356,9 +356,6 @@ void *add_camera() cam->clipsta= 0.1f; cam->clipend= 100.0f; cam->drawsize= 0.5f; - cam->netsta= 0.5f; - cam->netend= 10.0f; - cam->hold= 50; return cam; } diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 38c23e3d09c..4ca2187e576 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -33,6 +33,7 @@ */ #include +#include #ifdef HAVE_CONFIG_H #include diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 32856145727..5875356bae9 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -588,1790 +588,5 @@ void autotexname(Tex *tex) /* ------------------------------------------------------------------------- */ -void init_render_texture(Tex *tex) -{ - Image *ima; - int imanr; - unsigned short numlen; - char name[256], head[FILE_MAXFILE], tail[FILE_MAXFILE]; - - /* is also used as signal */ - tex->nor= 0; - - /* imap test */ - if(tex->frames && tex->ima && tex->ima->name) { /* frames */ - strcpy(name, tex->ima->name); - - imanr= calcimanr(G.scene->r.cfra, tex); - - if(tex->imaflag & TEX_ANIM5) { - if(tex->ima->lastframe != imanr) { - if(tex->ima->ibuf) IMB_freeImBuf(tex->ima->ibuf); - tex->ima->ibuf= 0; - tex->ima->lastframe= imanr; - } - } - else { - /* for patch field-ima rendering */ - tex->ima->lastframe= imanr; - - BLI_stringdec(name, head, tail, &numlen); - BLI_stringenc(name, head, tail, numlen, imanr); - - ima= add_image(name); - - if(ima) { - ima->flag |= IMA_FROMANIM; - - if(tex->ima) tex->ima->id.us--; - tex->ima= ima; - - ima->ok= 1; - } - } - } - if(tex->imaflag & (TEX_ANTIALI+TEX_ANTISCALE)) { - if(tex->ima && tex->ima->lastqualityima->ibuf) IMB_freeImBuf(tex->ima->ibuf); - tex->ima->ibuf= 0; - } - } - - if(tex->type==TEX_PLUGIN) { - if(tex->plugin && tex->plugin->doit) { - if(tex->plugin->cfra) { - *(tex->plugin->cfra)= frame_to_float(G.scene->r.cfra); - } - } - } - else if(tex->type==TEX_ENVMAP) { - /* just in case */ - tex->imaflag= TEX_INTERPOL | TEX_MIPMAP; - tex->extend= TEX_CLIP; - - if(tex->env) { - if(R.flag & R_RENDERING) { - if(tex->env->stype==ENV_ANIM) RE_free_envmapdata(tex->env); - } - } - } -} - -/* ------------------------------------------------------------------------- */ - -void init_render_textures() -{ - Tex *tex; - - tex= G.main->tex.first; - while(tex) { - if(tex->id.us) init_render_texture(tex); - tex= tex->id.next; - } - - free_unused_animimages(); -} - -/* ------------------------------------------------------------------------- */ - -void end_render_texture(Tex *tex) -{ - - -} - -/* ------------------------------------------------------------------------- */ - -void end_render_textures() -{ - Tex *tex; - - tex= G.main->tex.first; - while(tex) { - if(tex->id.us) end_render_texture(tex); - tex= tex->id.next; - } - -} - - -/* ************************** */ - -int clouds(Tex *tex, float *texvec) -{ - float (*turbfunc)(float, float, float, float, int); - - if(tex->noisetype==TEX_NOISESOFT) turbfunc= BLI_turbulence; - else turbfunc= BLI_turbulence1; - - Tin= turbfunc(tex->noisesize, texvec[0], texvec[1], texvec[2], tex->noisedepth); - - if(tex->stype==1) { - - Tr= Tin; - Tg= turbfunc(tex->noisesize, texvec[1], texvec[0], texvec[2], tex->noisedepth); - - Tb= turbfunc(tex->noisesize,texvec[1],texvec[2],texvec[0], tex->noisedepth); - - BRICONRGB; - Ta= 1.0; - - return 1; - } - - BRICON; - - if(tex->flag & TEX_COLORBAND) return do_colorband(tex->coba); - - return 0; -} - -/* ------------------------------------------------------------------------- */ - -int blend(Tex *tex, float *texvec) -{ - float x, y, t; - - if(tex->flag & TEX_FLIPBLEND) { - x= texvec[1]; - y= texvec[0]; - } - else { - x= texvec[0]; - y= texvec[1]; - } - - if(tex->stype==0) { /* lin */ - Tin= (1.0+x)/2.0; - } - else if(tex->stype==1) { /* quad */ - Tin= (1.0+x)/2.0; - if(Tin<0.0) Tin= 0.0; - else Tin*= Tin; - } - else if(tex->stype==2) { /* ease */ - Tin= (1.0+x)/2.0; - if(Tin<=.0) Tin= 0.0; - else if(Tin>=1.0) Tin= 1.0; - else { - t= Tin*Tin; - Tin= (3.0*t-2.0*t*Tin); - } - } - else if(tex->stype==3) { /* diag */ - Tin= (2.0+x+y)/4.0; - } - else { /* sphere */ - Tin= 1.0-sqrt(x*x+ y*y+texvec[2]*texvec[2]); - if(Tin<0.0) Tin= 0.0; - if(tex->stype==5) Tin*= Tin; /* halo */ - } - - BRICON; - if(tex->flag & TEX_COLORBAND) return do_colorband(tex->coba); - - return 0; -} - -/* ------------------------------------------------------------------------- */ - -int wood(Tex *tex, float *texvec) -{ - float (*noisefunc)(float, float, float, float); - - if(tex->noisetype==TEX_NOISESOFT) noisefunc= BLI_hnoise; - else noisefunc= BLI_hnoisep; - - - if(tex->stype==0) { - Tin= 0.5+0.5*sin( (texvec[0]+texvec[1]+texvec[2])*10.0 ); - } - else if(tex->stype==1) { - Tin= 0.5+0.5*sin( sqrt(texvec[0]*texvec[0]+texvec[1]*texvec[1]+texvec[2]*texvec[2])*20.0 ); - } - else if(tex->stype==2) { - Tin= noisefunc(tex->noisesize, texvec[0], texvec[1], texvec[2]); - Tin= 0.5+ 0.5*sin(tex->turbul*Tin+(texvec[0]+texvec[1]+texvec[2])*10.0); - } - else if(tex->stype==3) { - Tin= noisefunc(tex->noisesize, texvec[0], texvec[1], texvec[2]); - Tin= 0.5+ 0.5*sin(tex->turbul*Tin+(sqrt(texvec[0]*texvec[0]+texvec[1]*texvec[1]+texvec[2]*texvec[2]))*20.0); - } - - - BRICON; - if(tex->flag & TEX_COLORBAND) return do_colorband(tex->coba); - - return 0; -} - -/* ------------------------------------------------------------------------- */ - -int marble(Tex *tex, float *texvec) -{ - float n; - float (*turbfunc)(float, float, float, float, int); - - if(tex->noisetype==TEX_NOISESOFT) turbfunc= BLI_turbulence; - else turbfunc= BLI_turbulence1; - - n= 5.0*(texvec[0]+texvec[1]+texvec[2]); - - Tin = 0.5+0.5*sin(n+tex->turbul*turbfunc(tex->noisesize, texvec[0],texvec[1],texvec[2], tex->noisedepth)); - - switch (tex->stype) { - case 1: - Tin= sqrt(Tin); - break; - case 2: - Tin= sqrt(Tin); - Tin= sqrt(Tin); - break; - } - - BRICON; - if(tex->flag & TEX_COLORBAND) return do_colorband(tex->coba); - - return 0; -} - -/* ------------------------------------------------------------------------- */ - -int magic(Tex *tex, float *texvec) -{ - float x, y, z, turb=1.0; - int n; - - n= tex->noisedepth; - turb= tex->turbul/5.0; - - x= sin( ( texvec[0]+texvec[1]+texvec[2])*5.0 ); - y= cos( (-texvec[0]+texvec[1]-texvec[2])*5.0 ); - z= -cos( (-texvec[0]-texvec[1]+texvec[2])*5.0 ); - if(n>0) { - x*= turb; - y*= turb; - z*= turb; - y= -cos(x-y+z); - y*= turb; - if(n>1) { - x= cos(x-y-z); - x*= turb; - if(n>2) { - z= sin(-x-y-z); - z*= turb; - if(n>3) { - x= -cos(-x+y-z); - x*= turb; - if(n>4) { - y= -sin(-x+y+z); - y*= turb; - if(n>5) { - y= -cos(-x+y+z); - y*= turb; - if(n>6) { - x= cos(x+y+z); - x*= turb; - if(n>7) { - z= sin(x+y-z); - z*= turb; - if(n>8) { - x= -cos(-x-y+z); - x*= turb; - if(n>9) { - y= -sin(x-y+z); - y*= turb; - } - } - } - } - } - } - } - } - } - } - - if(turb!=0.0) { - turb*= 2.0; - x/= turb; - y/= turb; - z/= turb; - } - Tr= 0.5-x; - Tg= 0.5-y; - Tb= 0.5-z; - - BRICONRGB; - Ta= 1.0; - - return 1; -} - -/* ------------------------------------------------------------------------- */ - -int stucci(Tex *tex, float *texvec) -{ - float b2, vec[3]; - float ofs; - float (*noisefunc)(float, float, float, float); - - if(tex->nor == NULL) return 0; - - if(tex->noisetype==TEX_NOISESOFT) noisefunc= BLI_hnoise; - else noisefunc= BLI_hnoisep; - - ofs= tex->turbul/200.0; - - b2= noisefunc(tex->noisesize, texvec[0], texvec[1], texvec[2]); - if(tex->stype) ofs*=(b2*b2); - vec[0]= b2-noisefunc(tex->noisesize, texvec[0]+ofs, texvec[1], texvec[2]); - vec[1]= b2-noisefunc(tex->noisesize, texvec[0], texvec[1]+ofs, texvec[2]); - vec[2]= b2-noisefunc(tex->noisesize, texvec[0], texvec[1], texvec[2]+ofs); - - if(tex->stype==1) { - tex->nor[0]= vec[0]; - tex->nor[1]= vec[1]; - tex->nor[2]= vec[2]; - } - else { - tex->nor[0]= -vec[0]; - tex->nor[1]= -vec[1]; - tex->nor[2]= -vec[2]; - } - - return 2; -} - -/* ------------------------------------------------------------------------- */ - -int texnoise(Tex *tex) -{ - float div=3.0; - int val, ran, loop; - - ran= BLI_rand(); - val= (ran & 3); - - loop= tex->noisedepth; - while(loop--) { - ran= (ran>>2); - val*= (ran & 3); - div*= 3.0; - } - - Tin= ((float)val)/div;; - - BRICON; - if(tex->flag & TEX_COLORBAND) return do_colorband(tex->coba); - - return 0; -} - -/* ------------------------------------------------------------------------- */ - -int plugintex(Tex *tex, float *texvec, float *dxt, float *dyt) -{ - PluginTex *pit; - int rgbnor=0; - - Tin= 0.0; - - pit= tex->plugin; - if(pit && pit->doit) { - VECCOPY(pit->result+5, R.vn); - - if(R.osatex) rgbnor= ((TexDoit)pit->doit)(tex->stype, pit->data, texvec, dxt, dyt); - else rgbnor= ((TexDoit)pit->doit)(tex->stype, pit->data, texvec, 0, 0); - - Tin= pit->result[0]; - - if(rgbnor & TEX_NOR) { - if(tex->nor) { - VECCOPY(tex->nor, pit->result+5); - } - } - - if(rgbnor & TEX_RGB) { - Tr= pit->result[1]; - Tg= pit->result[2]; - Tb= pit->result[3]; - Ta= pit->result[4]; - - BRICONRGB; - } - - BRICON; - if(tex->flag & TEX_COLORBAND) rgbnor |= do_colorband(tex->coba); - } - - return rgbnor; -} - -/* *************** PROJECTIONS ******************* */ - -void tubemap(float x, float y, float z, float *adr1, float *adr2) -{ - float len; - - *adr2 = (z + 1.0) / 2.0; - - len= sqrt(x*x+y*y); - if(len>0) { - *adr1 = (1.0 - (atan2(x/len,y/len) / M_PI)) / 2.0; - } -} - -/* ------------------------------------------------------------------------- */ - -void spheremap(float x, float y, float z, float *adr1, float *adr2) -{ - float len; - - len= sqrt(x*x+y*y+z*z); - if(len>0.0) { - - if(x==0.0 && y==0.0) *adr1= 0.0; /* othwise domain error */ - else *adr1 = (1.0 - atan2(x,y)/M_PI )/2.0; - - z/=len; - *adr2 = 1.0- saacos(z)/M_PI; - } -} - -/* ------------------------------------------------------------------------- */ - -static int cubemap_glob(MTex *mtex, float x, float y, float z, float *adr1, float *adr2) -{ - float x1, y1, z1, nor[3]; - int ret; - - VECCOPY(nor, R.vn); - MTC_Mat4Mul3Vecfl(R.viewinv, nor); - - x1= fabs(nor[0]); - y1= fabs(nor[1]); - z1= fabs(nor[2]); - - if(z1>=x1 && z1>=y1) { - *adr1 = (x + 1.0) / 2.0; - *adr2 = (y + 1.0) / 2.0; - ret= 0; - } - else if(y1>=x1 && y1>=z1) { - *adr1 = (x + 1.0) / 2.0; - *adr2 = (z + 1.0) / 2.0; - ret= 1; - } - else { - *adr1 = (y + 1.0) / 2.0; - *adr2 = (z + 1.0) / 2.0; - ret= 2; - } - return ret; -} - -/* ------------------------------------------------------------------------- */ - -static int cubemap(MTex *mtex, float x, float y, float z, float *adr1, float *adr2) -{ - int proj[4], ret= 0; - - if(R.vlr && R.vlr->mface) { - int index; - /* the mtex->proj{xyz} have type char. maybe this should be wider? */ - /* casting to int ensures that the index type is right. */ - index = (int) mtex->projx; - proj[index]= ME_PROJXY; - - index = (int) mtex->projy; - proj[index]= ME_PROJXZ; - - index = (int) mtex->projz; - proj[index]= ME_PROJYZ; - - if(R.vlr->mface->puno & proj[1]) { - *adr1 = (x + 1.0) / 2.0; - *adr2 = (y + 1.0) / 2.0; - } - else if(R.vlr->mface->puno & proj[2]) { - *adr1 = (x + 1.0) / 2.0; - *adr2 = (z + 1.0) / 2.0; - ret= 1; - } - else { - *adr1 = (y + 1.0) / 2.0; - *adr2 = (z + 1.0) / 2.0; - ret= 2; - } - } else - return cubemap_glob(mtex, x, y, z, adr1, adr2); - - return ret; -} - -/* ------------------------------------------------------------------------- */ - -static int cubemap_ob(MTex *mtex, float x, float y, float z, float *adr1, float *adr2) -{ - float x1, y1, z1, nor[3]; - int ret; - - VECCOPY(nor, R.vn); - if(mtex->object) MTC_Mat4Mul3Vecfl(mtex->object->imat, nor); - - x1= fabs(nor[0]); - y1= fabs(nor[1]); - z1= fabs(nor[2]); - - if(z1>=x1 && z1>=y1) { - *adr1 = (x + 1.0) / 2.0; - *adr2 = (y + 1.0) / 2.0; - ret= 0; - } - else if(y1>=x1 && y1>=z1) { - *adr1 = (x + 1.0) / 2.0; - *adr2 = (z + 1.0) / 2.0; - ret= 1; - } - else { - *adr1 = (y + 1.0) / 2.0; - *adr2 = (z + 1.0) / 2.0; - ret= 2; - } - return ret; -} - -/* ------------------------------------------------------------------------- */ - -void do_2d_mapping(MTex *mtex, float *t, float *dxt, float *dyt) -{ - Tex *tex; - float fx, fy, fac1, area[8]; - int ok, proj, areaflag= 0, wrap; - - wrap= mtex->mapping; - tex= mtex->tex; - - if(R.osa==0) { - - if(wrap==MTEX_FLAT) { - fx = (t[0] + 1.0) / 2.0; - fy = (t[1] + 1.0) / 2.0; - } - else if(wrap==MTEX_TUBE) tubemap(t[0], t[1], t[2], &fx, &fy); - else if(wrap==MTEX_SPHERE) spheremap(t[0], t[1], t[2], &fx, &fy); - else { - if(mtex->texco==TEXCO_OBJECT) cubemap_ob(mtex, t[0], t[1], t[2], &fx, &fy); - else if(mtex->texco==TEXCO_GLOB) cubemap_glob(mtex, t[0], t[1], t[2], &fx, &fy); - else cubemap(mtex, t[0], t[1], t[2], &fx, &fy); - } - - /* repeat */ - if(tex->xrepeat>1) { - fx *= tex->xrepeat; - if(fx>1.0) fx -= (int)(fx); - else if(fx<0.0) fx+= 1-(int)(fx); - } - if(tex->yrepeat>1) { - fy *= tex->yrepeat; - if(fy>1.0) fy -= (int)(fy); - else if(fy<0.0) fy+= 1-(int)(fy); - } - - /* crop */ - if(tex->cropxmin!=0.0 || tex->cropxmax!=1.0) { - fac1= tex->cropxmax - tex->cropxmin; - fx= tex->cropxmin+ fx*fac1; - } - if(tex->cropymin!=0.0 || tex->cropymax!=1.0) { - fac1= tex->cropymax - tex->cropymin; - fy= tex->cropymin+ fy*fac1; - } - - t[0]= fx; - t[1]= fy; - } - else { - - if(wrap==MTEX_FLAT) { - fx= (t[0] + 1.0) / 2.0; - fy= (t[1] + 1.0) / 2.0; - dxt[0]/= 2.0; - dxt[1]/= 2.0; - dyt[0]/= 2.0; - dyt[1]/= 2.0; - } - else if ELEM(wrap, MTEX_TUBE, MTEX_SPHERE) { - /* exception: the seam behind (y<0.0) */ - ok= 1; - if(t[1]<=0.0) { - fx= t[0]+dxt[0]; - fy= t[0]+dyt[0]; - if(fx>=0.0 && fy>=0.0 && t[0]>=0.0); - else if(fx<=0.0 && fy<=0.0 && t[0]<=0.0); - else ok= 0; - } - if(ok) { - if(wrap==MTEX_TUBE) { - tubemap(t[0], t[1], t[2], area, area+1); - tubemap(t[0]+dxt[0], t[1]+dxt[1], t[2]+dxt[2], area+2, area+3); - tubemap(t[0]+dyt[0], t[1]+dyt[1], t[2]+dyt[2], area+4, area+5); - } - else { - spheremap(t[0], t[1], t[2],area,area+1); - spheremap(t[0]+dxt[0], t[1]+dxt[1], t[2]+dxt[2], area+2, area+3); - spheremap(t[0]+dyt[0], t[1]+dyt[1], t[2]+dyt[2], area+4, area+5); - } - areaflag= 1; - } - else { - if(wrap==MTEX_TUBE) tubemap(t[0], t[1], t[2], &fx, &fy); - else spheremap(t[0], t[1], t[2], &fx, &fy); - dxt[0]/= 2.0; - dxt[1]/= 2.0; - dyt[0]/= 2.0; - dyt[1]/= 2.0; - } - } - else { - - if(mtex->texco==TEXCO_OBJECT) proj = cubemap_ob(mtex, t[0], t[1], t[2], &fx, &fy); - else if (mtex->texco==TEXCO_GLOB) proj = cubemap_glob(mtex, t[0], t[1], t[2], &fx, &fy); - else proj = cubemap(mtex, t[0], t[1], t[2], &fx, &fy); - - if(proj==1) { - dxt[1]= dxt[2]; - dyt[1]= dyt[2]; - } - else if(proj==2) { - dxt[0]= dxt[1]; - dyt[0]= dyt[1]; - dxt[1]= dxt[2]; - dyt[1]= dyt[2]; - } - dxt[0]/= 2.0; - dxt[1]/= 2.0; - dyt[0]/= 2.0; - dyt[1]/= 2.0; - } - - /* if area, then reacalculate dxt[] and dyt[] */ - if(areaflag) { - fx= area[0]; - fy= area[1]; - dxt[0]= area[2]-fx; - dxt[1]= area[3]-fy; - dyt[0]= area[4]-fx; - dyt[1]= area[5]-fy; - } - - /* repeat */ - if(tex->xrepeat>1) { - fx *= tex->xrepeat; - dxt[0]*= tex->xrepeat; - dyt[0]*= tex->xrepeat; - if(fx>1.0) fx -= (int)(fx); - else if(fx<0.0) fx+= 1-(int)(fx); - } - if(tex->yrepeat>1) { - fy *= tex->yrepeat; - dxt[1]*= tex->yrepeat; - dyt[1]*= tex->yrepeat; - if(fy>1.0) fy -= (int)(fy); - else if(fy<0.0) fy+= 1-(int)(fy); - } - - /* crop */ - if(tex->cropxmin!=0.0 || tex->cropxmax!=1.0) { - fac1= tex->cropxmax - tex->cropxmin; - fx= tex->cropxmin+ fx*fac1; - dxt[0]*= fac1; - dyt[0]*= fac1; - } - if(tex->cropymin!=0.0 || tex->cropymax!=1.0) { - fac1= tex->cropymax - tex->cropymin; - fy= tex->cropymin+ fy*fac1; - dxt[1]*= fac1; - dyt[1]*= fac1; - } - - t[0]= fx; - t[1]= fy; - - } -} - - -/* ************************************** */ - -int multitex(Tex *tex, float *texvec, float *dxt, float *dyt) -{ - - - switch(tex->type) { - - case 0: - Tin= 0.0; - return 0; - case TEX_CLOUDS: - return clouds(tex, texvec); - case TEX_WOOD: - return wood(tex, texvec); - case TEX_MARBLE: - return marble(tex, texvec); - case TEX_MAGIC: - return magic(tex, texvec); - case TEX_BLEND: - return blend(tex, texvec); - case TEX_STUCCI: - Tin= 0.0; - return stucci(tex, texvec); - case TEX_NOISE: - return texnoise(tex); - case TEX_IMAGE: - if(R.osatex) return imagewraposa(tex, texvec, dxt, dyt); - else return imagewrap(tex, texvec); - break; - case TEX_PLUGIN: - return plugintex(tex, texvec, dxt, dyt); - break; - case TEX_ENVMAP: - return RE_envmaptex(tex, texvec, dxt, dyt); - break; - } - return 0; -} - -/* ------------------------------------------------------------------------- */ - -void do_material_tex() -{ - Object *ob; - Material *mat_col, *mat_colspec, *mat_colmir, *mat_ref; - Material *mat_spec, *mat_har, *mat_emit, *mat_alpha, *mat_ray_mirr, *mat_translu; - MTex *mtex; - Tex *tex; - float *co = NULL, *dx = NULL, *dy = NULL, fact, - facm, factt, facmm, facmul = 0.0, stencilTin=1.0; - float texvec[3], dxt[3], dyt[3], tempvec[3], norvec[3], Tnor=1.0; - int tex_nr, rgbnor= 0; - - /* here: test flag if there's a tex (todo) */ - - mat_col=mat_colspec=mat_colmir=mat_ref=mat_spec=mat_har=mat_emit=mat_alpha=mat_ray_mirr=mat_translu= R.mat; - - for(tex_nr=0; tex_nr<8; tex_nr++) { - - /* separate tex switching */ - if(R.mat->septex & (1<mtex[tex_nr]) { - mtex= R.mat->mtex[tex_nr]; - - tex= mtex->tex; - if(tex==0) continue; - - /* which coords */ - if(mtex->texco==TEXCO_ORCO) { - co= R.lo; dx= O.dxlo; dy= O.dylo; - } - else if(mtex->texco==TEXCO_STICKY) { - co= R.sticky; dx= O.dxsticky; dy= O.dysticky; - } - else if(mtex->texco==TEXCO_OBJECT) { - ob= mtex->object; - if(ob) { - co= tempvec; - dx= dxt; - dy= dyt; - VECCOPY(tempvec, R.co); - MTC_Mat4MulVecfl(ob->imat, tempvec); - if(R.osatex) { - VECCOPY(dxt, O.dxco); - VECCOPY(dyt, O.dyco); - MTC_Mat4Mul3Vecfl(ob->imat, dxt); - MTC_Mat4Mul3Vecfl(ob->imat, dyt); - } - } - else { - /* if object doesn't exist, do not use orcos (not initialized) */ - co= R.co; - dx= O.dxco; dy= O.dyco; - } - } - else if(mtex->texco==TEXCO_REFL) { - co= R.ref; dx= O.dxref; dy= O.dyref; - } - else if(mtex->texco==TEXCO_NORM) { - co= R.orn; dx= O.dxno; dy= O.dyno; - } - else if(mtex->texco==TEXCO_GLOB) { - co= R.gl; dx= O.dxco; dy= O.dyco; - } - else if(mtex->texco==TEXCO_UV) { - co= R.uv; dx= O.dxuv; dy= O.dyuv; - } - else if(mtex->texco==TEXCO_WINDOW) { - co= R.winco; dx= O.dxwin; dy= O.dywin; - } - - /* de pointer defines if bumping happens */ - if(mtex->mapto & MAP_NORM) { - tex->nor= norvec; - norvec[0]= norvec[1]= norvec[2]= 0.0; - } - else tex->nor= 0; - - if(tex->type==TEX_IMAGE) { - - /* new: first swap coords, then map, then trans/scale */ - - /* placement */ - if(mtex->projx) texvec[0]= co[mtex->projx-1]; - else texvec[0]= 0.0; - if(mtex->projy) texvec[1]= co[mtex->projy-1]; - else texvec[1]= 0.0; - if(mtex->projz) texvec[2]= co[mtex->projz-1]; - else texvec[2]= 0.0; - - if(R.osatex) { - - if(mtex->projx) { - dxt[0]= dx[mtex->projx-1]; - dyt[0]= dy[mtex->projx-1]; - } - else dxt[0]= 0.0; - if(mtex->projy) { - dxt[1]= dx[mtex->projy-1]; - dyt[1]= dy[mtex->projy-1]; - } - else dxt[1]= 0.0; - if(mtex->projx) { - dxt[2]= dx[mtex->projz-1]; - dyt[2]= dy[mtex->projz-1]; - } - else dxt[2]= 0.0; - } - - do_2d_mapping(mtex, texvec, dxt, dyt); - - /* translate and scale */ - texvec[0]= mtex->size[0]*(texvec[0]-0.5) +mtex->ofs[0]+0.5; - texvec[1]= mtex->size[1]*(texvec[1]-0.5) +mtex->ofs[1]+0.5; - if(R.osatex) { - dxt[0]= mtex->size[0]*dxt[0]; - dxt[1]= mtex->size[1]*dxt[1]; - dyt[0]= mtex->size[0]*dyt[0]; - dyt[1]= mtex->size[1]*dyt[1]; - } - } - else { - - /* placement */ - if(mtex->projx) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]); - else texvec[0]= mtex->size[0]*(mtex->ofs[0]); - - if(mtex->projy) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]); - else texvec[1]= mtex->size[1]*(mtex->ofs[1]); - - if(mtex->projz) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]); - else texvec[2]= mtex->size[2]*(mtex->ofs[2]); - - if(R.osatex) { - if(mtex->projx) { - dxt[0]= mtex->size[0]*dx[mtex->projx-1]; - dyt[0]= mtex->size[0]*dy[mtex->projx-1]; - } - else dxt[0]= 0.0; - if(mtex->projy) { - dxt[1]= mtex->size[1]*dx[mtex->projy-1]; - dyt[1]= mtex->size[1]*dy[mtex->projy-1]; - } - else dxt[1]= 0.0; - if(mtex->projx) { - dxt[2]= mtex->size[2]*dx[mtex->projz-1]; - dyt[2]= mtex->size[2]*dy[mtex->projz-1]; - } - else dxt[2]= 0.0; - } - } - - rgbnor= multitex(tex, texvec, dxt, dyt); - - /* texture output */ - - if( (rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) { - Tin= (0.35*Tr+0.45*Tg+0.2*Tb); - rgbnor-= 1; - } - if(mtex->texflag & MTEX_NEGATIVE) { - if(rgbnor & TEX_RGB) { - Tr= 1.0-Tr; - Tg= 1.0-Tg; - Tb= 1.0-Tb; - } - Tin= 1.0-Tin; - } - if(mtex->texflag & MTEX_STENCIL) { - if(rgbnor & TEX_RGB) { - fact= Ta; - Ta*= stencilTin; - stencilTin*= fact; - } - else { - fact= Tin; - Tin*= stencilTin; - stencilTin*= fact; - } - } - else { - Ta*= stencilTin; - Tnor*= stencilTin; - Tin*= stencilTin; - } - - if(tex->nor && (rgbnor & TEX_NOR)==0) { - /* make our own normal */ - if(rgbnor & TEX_RGB) { - tex->nor[0]= Tr; - tex->nor[1]= Tg; - tex->nor[2]= Tb; - } - else { - float co= 0.5*cos(Tin-0.5); - float si= 0.5*sin(Tin-0.5); - float f1, f2; - - f1= R.vn[0]; - f2= R.vn[1]; - tex->nor[0]= f1*co+f2*si; - tex->nor[1]= f2*co-f1*si; - f1= R.vn[1]; - f2= R.vn[2]; - tex->nor[1]= f1*co+f2*si; - tex->nor[2]= f2*co-f1*si; - } - } - - - /* mapping */ - if(mtex->mapto & (MAP_COL+MAP_COLSPEC+MAP_COLMIR)) { - - if((rgbnor & TEX_RGB)==0) { - Tr= mtex->r; - Tg= mtex->g; - Tb= mtex->b; - } - else if(mtex->mapto & MAP_ALPHA) { - if(mtex->texflag & MTEX_ALPHAMIX) Tin= Ta; - else Tin= stencilTin; - } - else Tin= Ta; - - fact= Tin*mtex->colfac; - facm= 1.0-fact; - if(mtex->blendtype==MTEX_MUL) facm= 1.0-mtex->colfac; - if(mtex->blendtype==MTEX_SUB) fact= -fact; - - if(mtex->mapto & MAP_COL) { - if(mtex->blendtype==MTEX_BLEND) { - R.matren->r= (fact*Tr + facm*mat_col->r); - R.matren->g= (fact*Tg + facm*mat_col->g); - R.matren->b= (fact*Tb + facm*mat_col->b); - } - else if(mtex->blendtype==MTEX_MUL) { - R.matren->r= (facm+fact*Tr)*mat_col->r; - R.matren->g= (facm+fact*Tg)*mat_col->g; - R.matren->b= (facm+fact*Tb)*mat_col->b; - } - else { - R.matren->r= (fact*Tr + mat_col->r); - R.matren->g= (fact*Tg + mat_col->g); - R.matren->b= (fact*Tb + mat_col->b); - } - mat_col= R.matren; - } - if(mtex->mapto & MAP_COLSPEC) { - if(mtex->blendtype==MTEX_BLEND) { - R.matren->specr= (fact*Tr + facm*mat_colspec->specr); - R.matren->specg= (fact*Tg + facm*mat_colspec->specg); - R.matren->specb= (fact*Tb + facm*mat_colspec->specb); - } - else if(mtex->blendtype==MTEX_MUL) { - R.matren->specr= (facm+fact*Tr)*mat_colspec->specr; - R.matren->specg= (facm+fact*Tg)*mat_colspec->specg; - R.matren->specb= (facm+fact*Tb)*mat_colspec->specb; - } - else { - R.matren->specr= (fact*Tr + mat_colspec->specr); - R.matren->specg= (fact*Tg + mat_colspec->specg); - R.matren->specb= (fact*Tb + mat_colspec->specb); - } - mat_colspec= R.matren; - } - if(mtex->mapto & MAP_COLMIR) { - if(mtex->blendtype==MTEX_BLEND) { - // exception for envmap only - if(tex->type==TEX_ENVMAP) { - R.refcol[0]= fact + facm*R.refcol[0]; - R.refcol[1]= fact*Tr + facm*R.refcol[1]; - R.refcol[2]= fact*Tg + facm*R.refcol[2]; - R.refcol[3]= fact*Tb + facm*R.refcol[3]; - } else { - R.matren->mirr= fact*Tr + facm*mat_colmir->mirr; - R.matren->mirg= fact*Tg + facm*mat_colmir->mirg; - R.matren->mirb= fact*Tb + facm*mat_colmir->mirb; - } - } - else if(mtex->blendtype==MTEX_MUL) { - R.matren->mirr= (facm+fact*Tr)*mat_colmir->mirr; - R.matren->mirg= (facm+fact*Tg)*mat_colmir->mirg; - R.matren->mirb= (facm+fact*Tb)*mat_colmir->mirb; - } - else { - R.matren->mirr= (fact*Tr + mat_colmir->mirr); - R.matren->mirg= (fact*Tg + mat_colmir->mirg); - R.matren->mirb= (fact*Tb + mat_colmir->mirb); - } - mat_colmir= R.matren; - } - } - if( (mtex->mapto & MAP_NORM) ) { - if(tex->nor) { - - if(mtex->maptoneg & MAP_NORM) tex->norfac= -mtex->norfac; - else tex->norfac= mtex->norfac; - - R.vn[0]+= Tnor*tex->norfac*tex->nor[0]; - R.vn[1]+= Tnor*tex->norfac*tex->nor[1]; - R.vn[2]+= Tnor*tex->norfac*tex->nor[2]; - - Normalise(R.vn); - - /* this makes sure the bump is passed on to the next texture */ - R.orn[0]= R.vn[0]; - R.orn[1]= -R.vn[1]; - R.orn[2]= R.vn[2]; - - /* reflection vector */ - RE_calc_R_ref(); - } - } - - if(mtex->mapto & MAP_VARS) { - if(rgbnor & TEX_RGB) { - if(Talpha) Tin= Ta; - else Tin= (0.35*Tr+0.45*Tg+0.2*Tb); - } - - fact= Tin*mtex->varfac; - facm= 1.0-fact; - if(mtex->blendtype==MTEX_MUL) facmul= 1.0-mtex->varfac; - if(mtex->blendtype==MTEX_SUB) fact= -fact; - - if(mtex->mapto & MAP_REF) { - if(mtex->maptoneg & MAP_REF) {factt= facm; facmm= fact;} - else {factt= fact; facmm= facm;} - - if(mtex->blendtype==MTEX_BLEND) - R.matren->ref= factt*mtex->def_var+ facmm*mat_ref->ref; - else if(mtex->blendtype==MTEX_MUL) - R.matren->ref= (facmul+factt)*mat_ref->ref; - else { - R.matren->ref= factt+mat_ref->ref; - if(R.matren->ref<0.0) R.matren->ref= 0.0; - } - mat_ref= R.matren; - } - if(mtex->mapto & MAP_SPEC) { - if(mtex->maptoneg & MAP_SPEC) {factt= facm; facmm= fact;} - else {factt= fact; facmm= facm;} - - if(mtex->blendtype==MTEX_BLEND) - R.matren->spec= factt*mtex->def_var+ facmm*mat_spec->spec; - else if(mtex->blendtype==MTEX_MUL) - R.matren->spec= (facmul+factt)*mat_spec->spec; - else { - R.matren->spec= factt+mat_spec->spec; - if(R.matren->spec<0.0) R.matren->spec= 0.0; - } - mat_spec= R.matren; - } - if(mtex->mapto & MAP_EMIT) { - if(mtex->maptoneg & MAP_EMIT) {factt= facm; facmm= fact;} - else {factt= fact; facmm= facm;} - - if(mtex->blendtype==MTEX_BLEND) - R.matren->emit= factt*mtex->def_var+ facmm*mat_emit->emit; - else if(mtex->blendtype==MTEX_MUL) - R.matren->emit= (facmul+factt)*mat_emit->emit; - else { - R.matren->emit= factt+mat_emit->emit; - if(R.matren->emit<0.0) R.matren->emit= 0.0; - } - mat_emit= R.matren; - } - if(mtex->mapto & MAP_ALPHA) { - if(mtex->maptoneg & MAP_ALPHA) {factt= facm; facmm= fact;} - else {factt= fact; facmm= facm;} - - if(mtex->blendtype==MTEX_BLEND) - R.matren->alpha= factt*mtex->def_var+ facmm*mat_alpha->alpha; - else if(mtex->blendtype==MTEX_MUL) - R.matren->alpha= (facmul+factt)*mat_alpha->alpha; - else { - R.matren->alpha= factt+mat_alpha->alpha; - if(R.matren->alpha<0.0) R.matren->alpha= 0.0; - else if(R.matren->alpha>1.0) R.matren->alpha= 1.0; - } - mat_alpha= R.matren; - } - if(mtex->mapto & MAP_HAR) { - if(mtex->maptoneg & MAP_HAR) {factt= facm; facmm= fact;} - else {factt= fact; facmm= facm;} - - if(mtex->blendtype==MTEX_BLEND) { - R.matren->har= 128.0*factt*mtex->def_var+ facmm*mat_har->har; - } else if(mtex->blendtype==MTEX_MUL) { - R.matren->har= (facmul+factt)*mat_har->har; - } else { - R.matren->har= 128.0*factt+mat_har->har; - if(R.matren->har<1) R.matren->har= 1; - } - mat_har= R.matren; - } - if(mtex->mapto & MAP_RAYMIRR) { - if(mtex->maptoneg & MAP_RAYMIRR) {factt= facm; facmm= fact;} - else {factt= fact; facmm= facm;} - - if(mtex->blendtype==MTEX_BLEND) - R.matren->ray_mirror= factt*mtex->def_var+ facmm*mat_ray_mirr->ray_mirror; - else if(mtex->blendtype==MTEX_MUL) - R.matren->ray_mirror= (facmul+factt)*mat_ray_mirr->ray_mirror; - else { - R.matren->ray_mirror= factt+mat_ray_mirr->ray_mirror; - if(R.matren->ray_mirror<0.0) R.matren->ray_mirror= 0.0; - else if(R.matren->ray_mirror>1.0) R.matren->ray_mirror= 1.0; - } - mat_ray_mirr= R.matren; - } - if(mtex->mapto & MAP_TRANSLU) { - if(mtex->maptoneg & MAP_TRANSLU) {factt= facm; facmm= fact;} - else {factt= fact; facmm= facm;} - - if(mtex->blendtype==MTEX_BLEND) - R.matren->translucency= factt*mtex->def_var+ facmm*mat_translu->translucency; - else if(mtex->blendtype==MTEX_MUL) - R.matren->translucency= (facmul+factt)*mat_translu->translucency; - else { - R.matren->translucency= factt+mat_translu->translucency; - if(R.matren->translucency<0.0) R.matren->translucency= 0.0; - else if(R.matren->translucency>1.0) R.matren->translucency= 1.0; - } - mat_translu= R.matren; - } - } - } - } -} - -/* ------------------------------------------------------------------------- */ - -void do_halo_tex(HaloRen *har, float xn, float yn, float *colf) -{ - MTex *mtex; - float texvec[3], dxt[3], dyt[3], fact, facm, dx; - int rgb; - - mtex= har->mat->mtex[0]; - if(mtex->tex==0) return; - /* no normal mapping */ - mtex->tex->nor= 0; - - texvec[0]= xn/har->rad; - texvec[1]= yn/har->rad; - texvec[2]= 0.0; - - R.osatex= (har->mat->texco & TEXCO_OSA); - - /* placement */ - if(mtex->projx) texvec[0]= mtex->size[0]*(texvec[mtex->projx-1]+mtex->ofs[0]); - else texvec[0]= mtex->size[0]*(mtex->ofs[0]); - - if(mtex->projy) texvec[1]= mtex->size[1]*(texvec[mtex->projy-1]+mtex->ofs[1]); - else texvec[1]= mtex->size[1]*(mtex->ofs[1]); - - if(mtex->projz) texvec[2]= mtex->size[2]*(texvec[mtex->projz-1]+mtex->ofs[2]); - else texvec[2]= mtex->size[2]*(mtex->ofs[2]); - - if(R.osatex) { - - dx= 1.0/har->rad; - - if(mtex->projx) { - dxt[0]= mtex->size[0]*dx; - dyt[0]= mtex->size[0]*dx; - } - else dxt[0]= 0.0; - if(mtex->projy) { - dxt[1]= mtex->size[1]*dx; - dyt[1]= mtex->size[1]*dx; - } - else dxt[1]= 0.0; - if(mtex->projz) { - dxt[2]= 0.0; - dyt[2]= 0.0; - } - else dxt[2]= 0.0; - - } - - - if(mtex->tex->type==TEX_IMAGE) do_2d_mapping(mtex, texvec, dxt, dyt); - - rgb= multitex(mtex->tex, texvec, dxt, dyt); - - /* texture output */ - if(rgb && (mtex->texflag & MTEX_RGBTOINT)) { - Tin= (0.35*Tr+0.45*Tg+0.2*Tb); - rgb= 0; - } - if(mtex->texflag & MTEX_NEGATIVE) { - if(rgb) { - Tr= 1.0-Tr; - Tg= 1.0-Tg; - Tb= 1.0-Tb; - } - else Tin= 1.0-Tin; - } - - /* mapping */ - if(mtex->mapto & MAP_COL) { - - if(rgb==0) { - Tr= mtex->r; - Tg= mtex->g; - Tb= mtex->b; - } - else if(mtex->mapto & MAP_ALPHA) { - if(mtex->texflag & MTEX_ALPHAMIX) Tin= Ta; - else Tin= 1.0; - } - else Tin= Ta; - - fact= Tin*mtex->colfac; - facm= 1.0-fact; - - if(mtex->blendtype==MTEX_MUL) { - facm= 1.0-mtex->colfac; - } - else fact*= 256; - - if(mtex->blendtype==MTEX_SUB) fact= -fact; - - if(mtex->blendtype==MTEX_BLEND) { - colf[0]= (fact*Tr + facm*har->r); - colf[1]= (fact*Tg + facm*har->g); - colf[2]= (fact*Tb + facm*har->b); - } - else if(mtex->blendtype==MTEX_MUL) { - colf[0]= (facm+fact*Tr)*har->r; - colf[1]= (facm+fact*Tg)*har->g; - colf[2]= (facm+fact*Tb)*har->b; - } - else { - colf[0]= (fact*Tr + har->r); - colf[1]= (fact*Tg + har->g); - colf[2]= (fact*Tb + har->b); - - CLAMP(colf[0], 0.0, 1.0); - CLAMP(colf[1], 0.0, 1.0); - CLAMP(colf[2], 0.0, 1.0); - } - } - if(mtex->mapto & MAP_ALPHA) { - if(rgb) { - if(Talpha) Tin= Ta; - else Tin= (0.35*Tr+0.45*Tg+0.2*Tb); - } - - colf[3]*= Tin; - } - - R.osatex= 0; -} - -/* ------------------------------------------------------------------------- */ - -void do_sky_tex() -{ - World *wrld_hor, *wrld_zen; - MTex *mtex; - float *co, fact, facm, factt, facmm, facmul = 0.0, stencilTin=1.0; - float tempvec[3], texvec[3], dxt[3], dyt[3]; - int tex_nr, rgb= 0, ok; - - - /* todo: add flag to test if there's a tex */ - - wrld_hor= wrld_zen= G.scene->world; - - /* The 6 here is the max amount of channels for a world */ - for(tex_nr=0; tex_nr<6; tex_nr++) { - if(R.wrld.mtex[tex_nr]) { - mtex= R.wrld.mtex[tex_nr]; - - if(mtex->tex==0) continue; - /* if(mtex->mapto==0) continue; */ - - /* which coords */ - co= R.lo; - - /* Grab the mapping settings for this texture */ - if(mtex->texco==TEXCO_OBJECT) { - Object *ob= mtex->object; - if(ob) { - VECCOPY(tempvec, R.lo); - MTC_Mat4MulVecfl(ob->imat, tempvec); - co= tempvec; - } - } - - /* placement */ - if(mtex->projx) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]); - else texvec[0]= mtex->size[0]*(mtex->ofs[0]); - - if(mtex->projy) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]); - else texvec[1]= mtex->size[1]*(mtex->ofs[1]); - - if(mtex->projz) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]); - else texvec[2]= mtex->size[2]*(mtex->ofs[2]); - - /* texture */ - if(mtex->tex->type==TEX_IMAGE) do_2d_mapping(mtex, texvec, dxt, dyt); - - rgb= multitex(mtex->tex, texvec, dxt, dyt); - - /* texture output */ - if(rgb && (mtex->texflag & MTEX_RGBTOINT)) { - Tin= (0.35*Tr+0.45*Tg+0.2*Tb); - rgb= 0; - } - if(mtex->texflag & MTEX_NEGATIVE) { - if(rgb) { - Tr= 1.0-Tr; - Tg= 1.0-Tg; - Tb= 1.0-Tb; - } - else Tin= 1.0-Tin; - } - if(mtex->texflag & MTEX_STENCIL) { - if(rgb) { - - } - else { - fact= Tin; - Tin*= stencilTin; - stencilTin*= fact; - } - } - else { - if(rgb) ; - else Tin*= stencilTin; - } - - /* colour mapping */ - if(mtex->mapto & (WOMAP_HORIZ+WOMAP_ZENUP+WOMAP_ZENDOWN)) { - - if(rgb==0) { - Tr= mtex->r; - Tg= mtex->g; - Tb= mtex->b; - } - else Tin= 1.0; - - fact= Tin*mtex->colfac; - facm= 1.0-fact; - if(mtex->blendtype==MTEX_MUL) facm= 1.0-mtex->colfac; - if(mtex->blendtype==MTEX_SUB) fact= -fact; - - if(mtex->mapto & WOMAP_HORIZ) { - if(mtex->blendtype==MTEX_BLEND) { - R.wrld.horr= (fact*Tr + facm*wrld_hor->horr); - R.wrld.horg= (fact*Tg + facm*wrld_hor->horg); - R.wrld.horb= (fact*Tb + facm*wrld_hor->horb); - } - else if(mtex->blendtype==MTEX_MUL) { - R.wrld.horr= (facm+fact*Tr)*wrld_hor->horr; - R.wrld.horg= (facm+fact*Tg)*wrld_hor->horg; - R.wrld.horb= (facm+fact*Tb)*wrld_hor->horb; - } - else { - R.wrld.horr= (fact*Tr + wrld_hor->horr); - R.wrld.horg= (fact*Tg + wrld_hor->horg); - R.wrld.horb= (fact*Tb + wrld_hor->horb); - } - wrld_hor= &R.wrld; - } - if(mtex->mapto & (WOMAP_ZENUP+WOMAP_ZENDOWN)) { - ok= 0; - if(R.wrld.skytype & WO_SKYREAL) { - if((R.wrld.skytype & WO_ZENUP)) { - if(mtex->mapto & WOMAP_ZENUP) ok= 1; - } - else if(mtex->mapto & WOMAP_ZENDOWN) ok= 1; - } - else ok= 1; - - if(ok) { - - if(mtex->blendtype==MTEX_BLEND) { - R.wrld.zenr= (fact*Tr + facm*wrld_zen->zenr); - R.wrld.zeng= (fact*Tg + facm*wrld_zen->zeng); - R.wrld.zenb= (fact*Tb + facm*wrld_zen->zenb); - } - else if(mtex->blendtype==MTEX_MUL) { - R.wrld.zenr= (facm+fact*Tr)*wrld_zen->zenr; - R.wrld.zeng= (facm+fact*Tg)*wrld_zen->zeng; - R.wrld.zenb= (facm+fact*Tb)*wrld_zen->zenb; - } - else { - R.wrld.zenr= (fact*Tr + wrld_zen->zenr); - R.wrld.zeng= (fact*Tg + wrld_zen->zeng); - R.wrld.zenb= (fact*Tb + wrld_zen->zenb); - } - wrld_zen= &R.wrld; - } - else { - /* otherwise zenRGB undefined */ - R.wrld.zenr= wrld_zen->zenr; - R.wrld.zeng= wrld_zen->zeng; - R.wrld.zenb= wrld_zen->zenb; - } - } - } - if(mtex->mapto & WOMAP_BLEND) { - if(rgb) Tin= (0.35*Tr+0.45*Tg+0.2*Tb); - - fact= Tin*mtex->varfac; - facm= 1.0-fact; - if(mtex->blendtype==MTEX_MUL) facmul= 1.0-mtex->varfac; - if(mtex->blendtype==MTEX_SUB) fact= -fact; - - factt= fact; facmm= facm; - - if(mtex->blendtype==MTEX_BLEND) - R.inprz= factt*mtex->def_var+ facmm*R.inprz; - else if(mtex->blendtype==MTEX_MUL) - R.inprz= (facmul+factt)*R.inprz; - else { - R.inprz= factt+R.inprz; - } - } - } - } -} - -/* ------------------------------------------------------------------------- */ -/* explicit lampren stuff should be factored out! or rather, the - texturing stuff might need to go...*/ -void do_lamp_tex(LampRen *la, float *lavec) -{ - Object *ob; - LampRen *la_col; - MTex *mtex; - Tex *tex; - float *co = NULL, *dx = NULL, *dy = NULL, fact, facm, stencilTin=1.0; - float texvec[3], dxt[3], dyt[3], tempvec[3]; - int tex_nr, rgb= 0; - - la_col= la->org; - - tex_nr= 0; - - for(; tex_nr<6; tex_nr++) { - - if(la->mtex[tex_nr]) { - mtex= la->mtex[tex_nr]; - - tex= mtex->tex; - if(tex==0) continue; - - /* which coords */ - if(mtex->texco==TEXCO_OBJECT) { - ob= mtex->object; - if(ob) { - co= tempvec; - dx= dxt; - dy= dyt; - VECCOPY(tempvec, R.co); - MTC_Mat4MulVecfl(ob->imat, tempvec); - if(R.osatex) { - VECCOPY(dxt, O.dxco); - VECCOPY(dyt, O.dyco); - MTC_Mat4Mul3Vecfl(ob->imat, dxt); - MTC_Mat4Mul3Vecfl(ob->imat, dyt); - } - } - else { - co= R.co; - dx= O.dxco; dy= O.dyco; - } - } - else if(mtex->texco==TEXCO_GLOB) { - co= R.gl; dx= O.dxco; dy= O.dyco; - VECCOPY(R.gl, R.co); - MTC_Mat4MulVecfl(R.viewinv, R.gl); - } - else if(mtex->texco==TEXCO_VIEW) { - - VECCOPY(tempvec, lavec); - MTC_Mat3MulVecfl(la->imat, tempvec); - - tempvec[0]*= la->spottexfac; - tempvec[1]*= la->spottexfac; - co= tempvec; - - dx= dxt; dy= dyt; - if(R.osatex) { - VECCOPY(dxt, O.dxlv); - VECCOPY(dyt, O.dylv); - /* need some matrix conversion here? la->imat is a [3][3] matrix!!! **/ - MTC_Mat3MulVecfl(la->imat, dxt); - MTC_Mat3MulVecfl(la->imat, dyt); - - VecMulf(dxt, la->spottexfac); - VecMulf(dyt, la->spottexfac); - } - } - - - /* placement */ - if(mtex->projx) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]); - else texvec[0]= mtex->size[0]*(mtex->ofs[0]); - - if(mtex->projy) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]); - else texvec[1]= mtex->size[1]*(mtex->ofs[1]); - - if(mtex->projz) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]); - else texvec[2]= mtex->size[2]*(mtex->ofs[2]); - - if(R.osatex) { - if(mtex->projx) { - dxt[0]= mtex->size[0]*dx[mtex->projx-1]; - dyt[0]= mtex->size[0]*dy[mtex->projx-1]; - } - else dxt[0]= 0.0; - if(mtex->projy) { - dxt[1]= mtex->size[1]*dx[mtex->projy-1]; - dyt[1]= mtex->size[1]*dy[mtex->projy-1]; - } - else dxt[1]= 0.0; - if(mtex->projx) { - dxt[2]= mtex->size[2]*dx[mtex->projz-1]; - dyt[2]= mtex->size[2]*dy[mtex->projz-1]; - } - else dxt[2]= 0.0; - } - - /* texture */ - if(tex->type==TEX_IMAGE) { - do_2d_mapping(mtex, texvec, dxt, dyt); - - if(mtex->mapto & MAP_NORM) { - /* the pointer defines if bump happens */ - tex->nor= R.vn; - if(mtex->maptoneg & MAP_NORM) tex->norfac= -mtex->norfac; - else tex->norfac= mtex->norfac; - } - else tex->nor= 0; - } - - rgb= multitex(tex, texvec, dxt, dyt); - - - - /* texture output */ - if(rgb && (mtex->texflag & MTEX_RGBTOINT)) { - Tin= (0.35*Tr+0.45*Tg+0.2*Tb); - rgb= 0; - } - if(mtex->texflag & MTEX_NEGATIVE) { - if(rgb) { - Tr= 1.0-Tr; - Tg= 1.0-Tg; - Tb= 1.0-Tb; - } - else Tin= 1.0-Tin; - } - if(mtex->texflag & MTEX_STENCIL) { - if(rgb) { - fact= Ta; - Ta*= stencilTin; - stencilTin*= fact; - } - else { - fact= Tin; - Tin*= stencilTin; - stencilTin*= fact; - } - } - else { - if(rgb) Ta*= stencilTin; - else Tin*= stencilTin; - } - - /* mapping */ - if(mtex->mapto & LAMAP_COL) { - - if(rgb==0) { - Tr= mtex->r; - Tg= mtex->g; - Tb= mtex->b; - } - else if(mtex->mapto & MAP_ALPHA) { - if(mtex->texflag & MTEX_ALPHAMIX) Tin= Ta; - else Tin= stencilTin; - } - else Tin= Ta; - - Tr*= la->energy; - Tg*= la->energy; - Tb*= la->energy; - - fact= Tin*mtex->colfac; - facm= 1.0-fact; - if(mtex->blendtype==MTEX_MUL) facm= 1.0-mtex->colfac; - if(mtex->blendtype==MTEX_SUB) fact= -fact; - - if(mtex->blendtype==MTEX_BLEND) { - la->r= (fact*Tr + facm*la_col->r); - la->g= (fact*Tg + facm*la_col->g); - la->b= (fact*Tb + facm*la_col->b); - } - else if(mtex->blendtype==MTEX_MUL) { - la->r= (facm+fact*Tr)*la_col->r; - la->g= (facm+fact*Tg)*la_col->g; - la->b= (facm+fact*Tb)*la_col->b; - } - else { - la->r= (fact*Tr + la_col->r); - la->g= (fact*Tg + la_col->g); - la->b= (fact*Tb + la_col->b); - } - la_col= la; /* Is it just me or is this a useless statement? */ - } - - } - } -} - -/* ------------------------------------------------------------------------- */ - -void externtex(MTex *mtex, float *vec) -{ - Tex *tex; - float dxt[3], dyt[3], texvec[3]; - int rgb; - - tex= mtex->tex; - if(tex==0) return; - - R.osatex= 0; - R.vlr= 0; - - /* placement */ - if(mtex->projx) texvec[0]= mtex->size[0]*(vec[mtex->projx-1]+mtex->ofs[0]); - else texvec[0]= mtex->size[0]*(mtex->ofs[0]); - - if(mtex->projy) texvec[1]= mtex->size[1]*(vec[mtex->projy-1]+mtex->ofs[1]); - else texvec[1]= mtex->size[1]*(mtex->ofs[1]); - - if(mtex->projz) texvec[2]= mtex->size[2]*(vec[mtex->projz-1]+mtex->ofs[2]); - else texvec[2]= mtex->size[2]*(mtex->ofs[2]); - - /* texture */ - if(tex->type==TEX_IMAGE) { - do_2d_mapping(mtex, texvec, dxt, dyt); - - if(mtex->mapto & MAP_NORM) { - /* the pointer defines if there's bump */ - tex->nor= R.vn; - if(mtex->maptoneg & MAP_NORM) tex->norfac= -mtex->norfac; - else tex->norfac= mtex->norfac; - } - else tex->nor= 0; - } - - rgb= multitex(tex, texvec, dxt, dyt); - if(rgb) { - Tin= (0.35*Tr+0.45*Tg+0.2*Tb); - } - else { - Tr= mtex->r; - Tg= mtex->g; - Tb= mtex->b; - } -} - -/* ------------------------------------------------------------------------- */ - -void externtexcol(MTex *mtex, float *orco, char *col) -{ - int temp; - float b1; - - if(mtex->tex==0) return; - - externtex(mtex, orco); - - b1= 1.0-Tin; - - temp= 255*(Tin*Tr)+b1*col[0]; - if(temp>255) col[0]= 255; else col[0]= temp; - temp= 255*(Tin*Tg)+b1*col[1]; - if(temp>255) col[1]= 255; else col[1]= temp; - temp= 255*(Tin*Tb)+b1*col[2]; - if(temp>255) col[2]= 255; else col[2]= temp; - -} - -/* ------------------------------------------------------------------------- */ - -void render_realtime_texture() -{ - static Tex tex; - static int firsttime= 1; - float texvec[2], dx[2], dy[2]; - - if(firsttime) { - default_tex(&tex); - tex.type= TEX_IMAGE; - firsttime= 0; - } - - tex.ima = R.vlr->tface->tpage; - if(tex.ima) { - - texvec[0]= 0.5+0.5*R.uv[0]; - texvec[1]= 0.5+0.5*R.uv[1]; - if(R.osatex) { - dx[0]= 0.5*O.dxuv[0]; - dx[1]= 0.5*O.dxuv[1]; - dy[0]= 0.5*O.dyuv[0]; - dy[1]= 0.5*O.dyuv[1]; - } - - if(R.osatex) imagewraposa(&tex, texvec, dx, dy); - else imagewrap(&tex, texvec); - - R.vcol[0]*= Tr; - R.vcol[1]*= Tg; - R.vcol[2]*= Tb; - } - - -} /* eof */ diff --git a/source/blender/makesdna/DNA_camera_types.h b/source/blender/makesdna/DNA_camera_types.h index aa126ff6f5d..84e463bde84 100644 --- a/source/blender/makesdna/DNA_camera_types.h +++ b/source/blender/makesdna/DNA_camera_types.h @@ -48,9 +48,7 @@ typedef struct Camera { short type, flag, drawzoom, hold; float clipsta, clipend; - float netsta, netend; /* network camera (obsolete -ton) */ float lens, drawsize; - float hololen, hololen1; /* obsolete (ton) */ struct Ipo *ipo; @@ -67,9 +65,6 @@ typedef struct Camera { #define CAM_SHOWLIMITS 1 #define CAM_SHOWMIST 2 -#define CAM_HOLO1 16 -#define CAM_HOLO2 32 - #ifdef __cplusplus } #endif diff --git a/source/blender/render/extern/include/render.h b/source/blender/render/extern/include/render.h index 40bebb43c24..7d039349e73 100644 --- a/source/blender/render/extern/include/render.h +++ b/source/blender/render/extern/include/render.h @@ -85,34 +85,12 @@ struct View3D; /* ------------------------------------------------------------------------- */ -/* Needed for the outside world referring to shadowbuffers */ +/* shadbuf.c (1) */ /* ------------------------------------------------------------------------- */ -#ifndef RE_SHADOWBUFFERHANDLE -#define RE_SHADOWBUFFERHANDLE -#define RE_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name - RE_DECLARE_HANDLE(RE_ShadowBufferHandle); -#endif - - /** - * Create a new, empty shadow buffer with certain settings. - * - * @param mode 0 is a dummy buffer, 1 is the old buffer for - * c-based shadowing, 2 is the old buffer with c++ refit , 2 is a - * deep buffer - */ - extern RE_ShadowBufferHandle RE_createShadowBuffer(struct LampRen *lar, - float mat[][4], - int mode); - - /** - * Delete a shadow buffer. - * @param shb handle to the buffer to be released - */ - extern void RE_deleteShadowBuffer(RE_ShadowBufferHandle shb); +void RE_initshadowbuf(struct LampRen *lar, float mat[][4]); - /* ------------------------------------------------------------------------- */ /* initrender (14) */ /* ------------------------------------------------------------------------- */ @@ -140,7 +118,6 @@ void RE_setwindowclip(int mode, int jmode); void RE_animrender(struct View3D *ogl_render_view3d); void RE_free_render_data(void); void RE_free_filt_mask(void); -void RE_holoview(void); void RE_init_filt_mask(void); void RE_init_render_data(void); void RE_jitterate1(float *jit1, float *jit2, int num, float rad1); @@ -174,7 +151,30 @@ void RE_zbufferall_radio(struct RadView *vw, struct RNode **rg_elem, int rg_t /* ------------------------------------------------------------------------- */ -/* envmap (5) */ +/* texture */ +/* ------------------------------------------------------------------------- */ +struct MTex; +struct Tex; + +void init_render_textures(void); +void end_render_textures(void); +void init_render_texture(struct Tex *tex); +void end_render_texture(struct Tex *tex); + +void tubemap(float x, float y, float z, float *adr1, float *adr2); +void spheremap(float x, float y, float z, float *adr1, float *adr2); + +void do_material_tex(ShadeInput *shi); +void externtex(struct MTex *mtex, float *vec); +void externtexcol(struct MTex *mtex, float *orco, char *col); +void do_lamp_tex(struct LampRen *la, float *lavec, ShadeInput *shi); +void do_sky_tex(float *); + +int multitex(struct Tex *tex, float *texvec, float *dxt, float *dyt, int osatex); + + +/* ------------------------------------------------------------------------- */ +/* envmap (4) */ /* ------------------------------------------------------------------------- */ struct EnvMap; struct Tex; @@ -183,8 +183,6 @@ void RE_free_envmap(struct EnvMap *env); struct EnvMap *RE_add_envmap(void); /* these two maybe not external? yes, they are, for texture.c */ struct EnvMap *RE_copy_envmap(struct EnvMap *env); -/* (used in texture.c) */ -int RE_envmaptex(struct Tex *tex, float *texvec, float *dxt, float *dyt); /* --------------------------------------------------------------------- */ /* rendercore (2) */ @@ -196,9 +194,6 @@ int RE_envmaptex(struct Tex *tex, float *texvec, float *dxt, float *dyt); float OrenNayar_Diff(float *n, float *l, float *v, float rough); float Toon_Diff( float *n, float *l, float *v, float size, float smooth); - /* maybe not external */ - void RE_calc_R_ref(void); - /* --------------------------------------------------------------------- */ /* renderdatabase (3) */ /* --------------------------------------------------------------------- */ @@ -257,7 +252,7 @@ int RE_envmaptex(struct Tex *tex, float *texvec, float *dxt, float *dyt); /* patch for the external if, to support the split for the ui */ void RE_addalphaAddfac(char *doel, char *bron, char addfac); - void RE_sky(char *col); + void RE_sky(float *view, char *col); void RE_renderflare(struct HaloRen *har); /** * Shade the pixel at xn, yn for halo har, and write the result to col. diff --git a/source/blender/render/extern/include/render_types.h b/source/blender/render/extern/include/render_types.h index 4ef7162e2e3..cad1a2faec5 100644 --- a/source/blender/render/extern/include/render_types.h +++ b/source/blender/render/extern/include/render_types.h @@ -51,13 +51,20 @@ /* ------------------------------------------------------------------------- */ -typedef struct RE_Render +/* localized renderloop data */ +typedef struct ShadeInput { + struct Material *mat, *matren; + struct VlakRen *vlr; float co[3]; float lo[3], gl[3], uv[3], ref[3], orn[3], winco[3], sticky[3], vcol[3], rad[3]; - float itot, i, ic, rgb, norm; - float vn[3], view[3], *vno, refcol[4]; + float vn[3], view[3], refcol[4]; + short osatex; +} ShadeInput; +/* here only stuff to initalize the render itself */ +typedef struct RE_Render +{ float grvec[3], inprz, inprh; float imat[3][3]; @@ -65,7 +72,7 @@ typedef struct RE_Render float persmat[4][4], persinv[4][4]; float winmat[4][4]; - short flag, osatex, osa, rt; + short flag, osa, rt, pad; /** * Screen sizes and positions, in pixels */ @@ -89,12 +96,6 @@ typedef struct RE_Render int totvlak, totvert, tothalo, totlamp; - /* internal: these two are a sort of cache for the render pipe */ - struct VlakRen *vlr; - int vlaknr; - - /* external */ - struct Material *mat, *matren; /* internal, fortunately */ struct LampRen **la; struct VlakRen **blovl; diff --git a/source/blender/render/intern/include/RE_DummyShadowBuffer.h b/source/blender/render/intern/include/RE_DummyShadowBuffer.h deleted file mode 100644 index 2522943fff2..00000000000 --- a/source/blender/render/intern/include/RE_DummyShadowBuffer.h +++ /dev/null @@ -1,71 +0,0 @@ -/** - * $Id$ - * - * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. The Blender - * Foundation also sells licenses for use in proprietary software under - * the Blender License. See http://www.blender.org/BL/ for information - * about this. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL/BL DUAL LICENSE BLOCK ***** - */ - -#ifndef RE_DUMMYSHADOWBUFFER_H -#define RE_DUMMYSHADOWBUFFER_H - -#include "RE_ShadowBuffer.h" - -struct LampRen; - -class RE_DummyShadowBuffer : public RE_ShadowBuffer { - - public: - /** - * Make an empty shadow buffer - */ - RE_DummyShadowBuffer(void); - - /** - * Delete and clear this buffer - */ - virtual ~RE_DummyShadowBuffer(void); - - /** - * Place this scene in the buffer - */ - virtual void importScene(struct LampRen* lar); - - /** - * Always return a fixed shadow factor. - * @param inp ignored - * @param shb ignored - * @param shadowResult a vector of 3 floats with rgb shadow values - */ - virtual void readShadowValue(struct ShadBuf *shb, - float inp, - float* shadowResult); - -}; - -#endif /* RE_SHADOWBUFFER_H */ - diff --git a/source/blender/render/intern/include/RE_ShadowBuffer.h b/source/blender/render/intern/include/RE_ShadowBuffer.h deleted file mode 100644 index c501b3b1b82..00000000000 --- a/source/blender/render/intern/include/RE_ShadowBuffer.h +++ /dev/null @@ -1,62 +0,0 @@ -/** - * $Id$ - * - * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. The Blender - * Foundation also sells licenses for use in proprietary software under - * the Blender License. See http://www.blender.org/BL/ for information - * about this. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL/BL DUAL LICENSE BLOCK ***** - */ - -#ifndef RE_SHADOWBUFFER_H -#define RE_SHADOWBUFFER_H - -#include - -struct ShadBuf; -struct LampRen; - -class RE_ShadowBuffer { - - public: - - virtual ~RE_ShadowBuffer(void){}; - /** - * Place this scene in the buffer - */ - virtual void importScene(struct LampRen* lar) = 0; - - /** - * Test the shadow factor at a location in the buffer - * @param shadowResult a vector of 3 floats with rgb shadow values - */ - virtual void readShadowValue(struct ShadBuf *shb, - float inp, - float* shadowResult) = 0; - -}; - -#endif /* RE_SHADOWBUFFER_H */ - diff --git a/source/blender/render/intern/include/RE_basicShadowBuffer.h b/source/blender/render/intern/include/RE_basicShadowBuffer.h deleted file mode 100644 index 2bf9fcd1ff0..00000000000 --- a/source/blender/render/intern/include/RE_basicShadowBuffer.h +++ /dev/null @@ -1,93 +0,0 @@ -/** - * $Id$ - * - * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. The Blender - * Foundation also sells licenses for use in proprietary software under - * the Blender License. See http://www.blender.org/BL/ for information - * about this. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL/BL DUAL LICENSE BLOCK ***** - */ - -#ifndef RE_BASICSHADOWBUFFER_H -#define RE_BASICSHADOWBUFFER_H - -#include "RE_ShadowBuffer.h" - -struct LampRen; -struct Lamp; - -class RE_BasicShadowBuffer : public RE_ShadowBuffer { - - private: - - void lrectreadRectz(int x1, int y1, int x2, int y2, char *r1); - int sizeoflampbuf(struct ShadBuf *shb); - int firstreadshadbuf(struct ShadBuf *shb, int xs, int ys, int nr); - float readshadowbuf(struct ShadBuf *shb, int xs, int ys, int zs); - float readshadowbuf_halo(struct ShadBuf *shb, int xs, int ys, int zs); - float *give_jitter_tab(int samp); - - int bias; - - public: - /** - * Make a shadow buffer from these settings - */ - RE_BasicShadowBuffer(struct LampRen *lar, float mat[][4]); - - /** - * Delete and clear this buffer - */ - virtual ~RE_BasicShadowBuffer(void); - - /** - * Calculates shadowbuffers for a vector of shadow-giving lamps - * @param lar The vector of lamps - */ - void importScene(LampRen *lar); - - /** - * Determines the shadow factor for a face and lamp. There is some - * communication with global variables here. - * @param shadres The RGB shadow factors: 1.0 for no shadow, 0.0 for complete - * shadow. There must be a float[3] to write the result to. - * @param shb The shadowbuffer to find the shadow factor in. - * @param inp The inproduct between viewvector and ? - * - */ - virtual void readShadowValue(struct ShadBuf *shb, - float inp, - float* shadowResult); - - /** - * Determines the shadow factor for lamp , between - * and . (Which CS?) - */ - float shadow_halo(LampRen *lar, float *p1, float *p2); - -}; - -#endif /* RE_BASICSHADOWBUFFER_H */ - diff --git a/source/blender/render/intern/include/envmap.h b/source/blender/render/intern/include/envmap.h index de5c0de974d..c77bb01f6ac 100644 --- a/source/blender/render/intern/include/envmap.h +++ b/source/blender/render/intern/include/envmap.h @@ -41,6 +41,7 @@ * (initrender.c) */ void make_envmaps(void); +int envmaptex(struct Tex *tex, float *texvec, float *dxt, float *dyt, int osatex); #endif /* ENVMAP_EXT_H */ diff --git a/source/blender/render/intern/include/pixelshading.h b/source/blender/render/intern/include/pixelshading.h index 3df3067f0a5..dd429f9ff61 100644 --- a/source/blender/render/intern/include/pixelshading.h +++ b/source/blender/render/intern/include/pixelshading.h @@ -48,19 +48,19 @@ * t[2] - jitter mask * t[3] - type ZB_POLY or ZB_HALO * t[4] - max. distance + * mask is pixel coverage in bits * @return pointer to the object */ -void *renderPixel(float x, float y, int *t); +void *renderPixel(float x, float y, int *t, int mask); + +void *renderHaloPixel(float x, float y, int haloNr) ; -/** - * Spothalos on otherwise empty pixels. - */ -void renderSpotHaloPixel(float x, float y, float* colbuf); -/** - * Set the sky blending to the indicated type. - */ void setSkyBlendingMode(enum RE_SkyAlphaBlendingType mode); +void shadeHaloFloat(HaloRen *har, + float *col, unsigned int zz, + float dist, float xn, + float yn, short flarec); /** * Get the sky blending mode. @@ -71,47 +71,10 @@ enum RE_SkyAlphaBlendingType getSkyBlendingMode(void); */ void renderSkyPixelFloat(float x, float y); -/* ------------------------------------------------------------------------- */ -/* All these are supposed to be internal. I should move these to a separate */ -/* header. */ - -/** - * Determine colour for pixel at SCS x,y for face . Result end up in - * - * @return pointer to this object's VlakRen - */ -void *renderFacePixel(float x, float y, int vlaknr); - -/** - * Render this pixel for halo haloNr. Leave result in . - * @return pointer to this object's HaloRen - */ -void *renderHaloPixel(float x, float y, int haloNr); - -/** - * Shade the halo at the given location - */ -void shadeHaloFloat(HaloRen *har, float *col, unsigned int zz, - float dist, float xn, float yn, short flarec); - -/** - * Shade a sky pixel on a certain line, into collector[4] - * The x-coordinate (y as well, actually) are communicated through - * R.view[3] - */ -void shadeSkyPixel(float x, float y); - -void shadeSpotHaloPixelFloat(float *col); -void spotHaloFloat(struct LampRen *lar, float *view, float *intens); -void shadeLampLusFloat(void); - -/* this should be replaced by shadeSpotHaloPixelFloat(), but there's */ -/* something completely fucked up here with the arith. */ -/* void renderspothaloFix(unsigned short *col); */ -void renderspothaloFix(float *col); - /* used by shadeSkyPixel: */ -void shadeSkyPixelFloat(float y); +void shadeSkyPixelFloat(float y, float *view); +void renderSpotHaloPixel(float x, float y, float *target); +void shadeSkyPixel(float fx, float fy); void fillBackgroundImage(float x, float y); /* ------------------------------------------------------------------------- */ diff --git a/source/blender/render/intern/include/rendercore.h b/source/blender/render/intern/include/rendercore.h index 6872ef3ed50..c463d9cdaae 100644 --- a/source/blender/render/intern/include/rendercore.h +++ b/source/blender/render/intern/include/rendercore.h @@ -37,6 +37,7 @@ #include "render_types.h" struct HaloRen; +struct ShadeInput; typedef struct ShadeResult { @@ -46,18 +47,21 @@ typedef struct ShadeResult } ShadeResult; - float mistfactor(float *co); /* dist en hoogte, return alpha */ -void renderspothalo(unsigned short *col); -void render_lighting_halo(struct HaloRen *har, float *colf); -unsigned int calchalo_z(struct HaloRen *har, unsigned int zz); -void shade_color(ShadeResult *shr); -void shade_lamp_loop(int mask, ShadeResult *shr); -float fresnel_fac(float *view, float *vn, float fresnel); +void render_lighting_halo(struct HaloRen *har, float *colf); +unsigned int calchalo_z(struct HaloRen *har, unsigned int zz); +void add_halo_flare(void); + +void shade_input_set_coords(ShadeInput *shi, float u, float v, int i1, int i2, int i3); + +void shade_color(struct ShadeInput *shi, ShadeResult *shr); +void shade_lamp_loop(struct ShadeInput *shi, ShadeResult *shr, int mask); + +float fresnel_fac(float *view, float *vn, float fresnel); +void calc_R_ref(struct ShadeInput *shi); float spec(float inp, int hard); -void add_halo_flare(void); /** * Apply the background (sky). Depending on the active alphamode and @@ -96,7 +100,8 @@ void zbufshadeDA(void); /* Delta Accum Pixel Struct */ /** * Also called in: zbuf.c */ -void shadepixel(float x, float y, int vlaknr, int mask); +void *shadepixel(float x, float y, int vlaknr, int mask, float *col); +void shadepixel_short(float x, float y, int vlaknr, int mask, unsigned short *shortcol); /** * Shade the pixel at xn, yn for halo har, and write the result to col. diff --git a/source/blender/render/intern/include/rendercore_int.h b/source/blender/render/intern/include/rendercore_int.h index 5ee63eb68ee..6b6ae899a8d 100644 --- a/source/blender/render/intern/include/rendercore_int.h +++ b/source/blender/render/intern/include/rendercore_int.h @@ -38,8 +38,7 @@ #include "zbuf_types.h" #include "render_types.h" -void do_lamphalo_tex(LampRen *lar, float *p1, float *p2, float *intens); -void spothalo(struct LampRen *lar, float *view, float *intens); +void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens); void add_filt_mask(unsigned int mask, unsigned short *col, unsigned int *rb1, unsigned int *rb2, unsigned int *rb3); void addps(long *rd, int vlak, unsigned int z, short ronde); PixStr *addpsmain(void); diff --git a/source/blender/render/intern/include/shadbuf.h b/source/blender/render/intern/include/shadbuf.h index 81ec34397cc..f0bdcd224b6 100644 --- a/source/blender/render/intern/include/shadbuf.h +++ b/source/blender/render/intern/include/shadbuf.h @@ -37,14 +37,6 @@ #include "render_types.h" -#ifdef __cplusplus -extern "C" { -#endif - -/** Init memory for old-style shodow buffers. */ -void initshadowbuf(struct LampRen *lar, float mat[][4]); - - /** * Calculates shadowbuffers for a vector of shadow-giving lamps * @param lar The vector of lamps @@ -60,7 +52,7 @@ void makeshadowbuf(LampRen *lar); * @param inp The inproduct between viewvector and ? * */ -float testshadowbuf(struct ShadBuf *shb, float inp); +float testshadowbuf(struct ShadBuf *shb, float *rco, float inp); /** * Determines the shadow factor for lamp , between @@ -68,9 +60,6 @@ float testshadowbuf(struct ShadBuf *shb, float inp); */ float shadow_halo(LampRen *lar, float *p1, float *p2); -#ifdef __cplusplus -} -#endif #endif /* SHADBUF_EXT_H */ diff --git a/source/blender/render/intern/include/shadowBuffer.h b/source/blender/render/intern/include/shadowBuffer.h deleted file mode 100644 index 46b24573fa8..00000000000 --- a/source/blender/render/intern/include/shadowBuffer.h +++ /dev/null @@ -1,80 +0,0 @@ -/** - * $Id$ - * - * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. The Blender - * Foundation also sells licenses for use in proprietary software under - * the Blender License. See http://www.blender.org/BL/ for information - * about this. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL/BL DUAL LICENSE BLOCK ***** - */ - -#ifndef SHADOWBUFFER_H -#define SHADOWBUFFER_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef RE_SHADOWBUFFERHANDLE -#define RE_SHADOWBUFFERHANDLE -#define RE_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name -RE_DECLARE_HANDLE(RE_ShadowBufferHandle); -#endif - - struct ShadBuf; - struct LampRen; - -/** - * Calculates shadowbuffers for a vector of shadow-giving lamps - * @param lar The vector of lamps - * @returns a handle to the buffer - */ - extern void RE_buildShadowBuffer(RE_ShadowBufferHandle dsbh, - struct LampRen *lar); - -/** - * Determines the shadow factor for a face and lamp. There is some - * communication with global variables here? Should be made explicit... - * @param shadres The RGB shadow factors: 1.0 for no shadow, 0.0 for complete - * shadow. There must be a float[3] to write the result to. - * @param shb The shadowbuffer to find the shadow factor in. - * @param inp The inproduct between viewvector and ? - * - */ - void RE_testshadowbuf(RE_ShadowBufferHandle dsbh, - struct ShadBuf* shbp, - float inp, - float* shadres); - -/** - * Determines a shadow factor for halo-shadows. - */ - -#ifdef __cplusplus -} -#endif - -#endif /* SHADOWBUFFER_H */ - diff --git a/source/blender/render/intern/include/texture.h b/source/blender/render/intern/include/texture.h index 5cf2c077926..9932f5a60ea 100644 --- a/source/blender/render/intern/include/texture.h +++ b/source/blender/render/intern/include/texture.h @@ -33,42 +33,14 @@ */ #ifndef TEXTURE_EXT_H -#define TEXTURE_EXT_H "$Id$" -#define TEXTURE_EXT_H "Copyright (C) 2001 NaN Technologies B.V. +#define TEXTURE_EXT_H -struct Tex; -struct MTex; struct HaloRen; -struct LampRen; -/** - * Takes uv coordinates (R.uv[], O.dxuv, O.dyuv), find texture colour - * at that spot (using imagewrap()). - * Result is kept in R.vcol (float vector 3) - */ -void render_realtime_texture(void); +struct ShadeInput; -/** - * Do texture mapping for materials. Communicates with R.... variables. - */ -void do_material_tex(void); - -/* unsorted */ -int blend(struct Tex *tex, float *texvec); -int clouds(struct Tex *tex, float *texvec); -int cubemap(struct MTex *mtex, float x, float y, float z, float *adr1, float *adr2); -int cubemap_glob(struct MTex *mtex, float x, float y, float z, float *adr1, float *adr2); -int cubemap_ob(struct MTex *mtex, float x, float y, float z, float *adr1, float *adr2); -void do_2d_mapping(struct MTex *mtex, float *t, float *dxt, float *dyt); void do_halo_tex(struct HaloRen *har, float xn, float yn, float *colf); -void do_lamp_tex(struct LampRen *la, float *lavec); -void do_sky_tex(void); -int magic(struct Tex *tex, float *texvec); -int marble(struct Tex *tex, float *texvec); -int multitex(struct Tex *tex, float *texvec, float *dxt, float *dyt); -int plugintex(struct Tex *tex, float *texvec, float *dxt, float *dyt); -int stucci(struct Tex *tex, float *texvec); -int texnoise(struct Tex *tex); -int wood(struct Tex *tex, float *texvec); +void render_realtime_texture(struct ShadeInput *shi); + #endif /* TEXTURE_EXT_H */ diff --git a/source/blender/render/intern/include/zbuf_int.h b/source/blender/render/intern/include/zbuf_int.h index d1c5f03d3b7..59a394d2908 100644 --- a/source/blender/render/intern/include/zbuf_int.h +++ b/source/blender/render/intern/include/zbuf_int.h @@ -186,7 +186,7 @@ void zbuffer_abuf(void); /** * Shade this face at this location in SCS. */ -void shadetrapixel(float x, float y, int vlak, int mask); +void shadetrapixel(float x, float y, int vlak, int mask, unsigned short *shortcol); /** * Determine the distance to the camera of this halo, in ZCS. diff --git a/source/blender/render/intern/source/RE_DummyShadowBuffer.cpp b/source/blender/render/intern/source/RE_DummyShadowBuffer.cpp deleted file mode 100644 index 02858cba717..00000000000 --- a/source/blender/render/intern/source/RE_DummyShadowBuffer.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/** - * $Id$ - * - * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. The Blender - * Foundation also sells licenses for use in proprietary software under - * the Blender License. See http://www.blender.org/BL/ for information - * about this. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL/BL DUAL LICENSE BLOCK ***** - */ - -#include "render_intern.h" -#include "RE_DummyShadowBuffer.h" - -#ifdef HAVE_CONFIG_H -#include -#endif - -struct LampRen; - -RE_DummyShadowBuffer::RE_DummyShadowBuffer(void) -{ - /* empty for now */ -// cout << "Constructing dummy SB\n"; -} - -RE_DummyShadowBuffer::~RE_DummyShadowBuffer(void) -{ - /* empty for now */ -// cout << "Deconstructing dummy SB\n"; -} - -void RE_DummyShadowBuffer::importScene(struct LampRen* lar) -{ - /* empty for now */ -// cout << "Importing scene in dummy SB\n"; -} - -void RE_DummyShadowBuffer::readShadowValue(struct ShadBuf *shb, - float inp, - float* shadowResult) -{ - /* a sort of puple-ish colour */ - shadowResult[0] = 1.0; - shadowResult[1] = 0.0; - shadowResult[2] = 0.5; -} diff --git a/source/blender/render/intern/source/RE_basicShadowBuffer.cpp b/source/blender/render/intern/source/RE_basicShadowBuffer.cpp deleted file mode 100644 index 9a6262f5608..00000000000 --- a/source/blender/render/intern/source/RE_basicShadowBuffer.cpp +++ /dev/null @@ -1,694 +0,0 @@ -/** - * $Id$ - * - * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. The Blender - * Foundation also sells licenses for use in proprietary software under - * the Blender License. See http://www.blender.org/BL/ for information - * about this. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL/BL DUAL LICENSE BLOCK ***** - */ - -#include -#include -#include "MEM_guardedalloc.h" -#include "BLI_arithb.h" - -#include "DNA_lamp_types.h" -/* c stuff */ -#include "MTC_matrixops.h" -#include "render.h" -#include "render_intern.h" -#include "renderHelp.h" -#include "jitter.h" -#include "zbuf.h" -#include "shadbuf.h" - -/* own include */ -#include "RE_basicShadowBuffer.h" - -#ifdef HAVE_CONFIG_H -#include -#endif - -/* crud */ -#define MIN2(x,y) ( (x)<(y) ? (x) : (y) ) -/* ------------------------------------------------------------------------- */ -/* The implementation of this one is a bit of a fraud still, as it - * still relies on everything internally to be done in C. Memory is - * allocated on the fly, and deallocated elsewhere... There's not much - * more than a handle for the implementation here. This is an exact - * copy of the old code, retrofitted for integration in the unified - * renderer. - * - * - the shadow values are tripled to make a shadow vector out of a - * single shadow value - */ - -RE_BasicShadowBuffer::RE_BasicShadowBuffer(struct LampRen *lar, float mat[][4]) -{ -// cout << "Constructing basic SB\n"; - bias = 0x00500000; - initshadowbuf(lar, mat); /* a ref to the shb is stored in the lar */ -} - -RE_BasicShadowBuffer::~RE_BasicShadowBuffer(void) -{ - /* clean-up is done when the lar's are deleted */ -// cout << "Destroying basic SB\n"; -} - -void RE_BasicShadowBuffer::lrectreadRectz(int x1, int y1, - int x2, int y2, - char *r1) /* reads part from rectz in r1 */ -{ - unsigned int len4, *rz; - - if(x1>=R.rectx || x2>=R.rectx || y1>=R.recty || y2>=R.recty) return; - if(x1>x2 || y1>y2) return; - - len4= 4*(x2- x1+1); - rz= R.rectz+R.rectx*y1+x1; - for(;y1<=y2;y1++) { - memcpy(r1,rz,len4); - rz+= R.rectx; - r1+= len4; - } -} - - -int RE_BasicShadowBuffer::sizeoflampbuf(struct ShadBuf *shb) -{ - int num,count=0; - char *cp; - - cp= shb->cbuf; - num= (shb->size*shb->size)/256; - - while(num--) count+= *(cp++); - - return 256*count; -} - -float* RE_BasicShadowBuffer::give_jitter_tab(int samp) -{ - /* these are all possible jitter tables, takes up some - * 12k, not really bad! - * For soft shadows, it saves memory and render time - */ - static int tab[17]={1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256}; - static float jit[1496][2]; - static char ctab[17]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - int a, offset=0; - - if(samp<2) samp= 2; - else if(samp>16) samp= 16; - - for(a=0; ashb; - float panophi; - float temp, wsize, dist; - int *rz, *rz1, verg, verg1; - unsigned long *ztile; - int a, x, y, minx, miny, byt1, byt2; - short temprx,tempry, square; - char *rc, *rcline, *ctile, *zt; - - panophi = getPanoPhi(); - - /* store view vars */ - temprx= R.rectx; tempry= R.recty; - R.rectx= R.recty= shb->size; - - shb->jit= give_jitter_tab(shb->samp); - - /* matrices and window: in R.winmat the transformation is being put, - transforming from observer view to lamp view, including lamp window matrix */ - - wsize= shb->pixsize*(shb->size/2.0); - - i_window(-wsize, wsize, -wsize, wsize, shb->d, shb->far, shb->winmat); - - MTC_Mat4MulMat4(shb->persmat, shb->viewmat, shb->winmat); - - /* temp, will be restored */ - MTC_Mat4SwapMat4(shb->persmat, R.winmat); - - /* zbuffering */ - if(R.rectz) MEM_freeN(R.rectz); - R.rectz= (unsigned int *)MEM_mallocN(sizeof(int)*shb->size*shb->size,"makeshadbuf"); - rcline= (char*) MEM_mallocN(256*4+sizeof(int),"makeshadbuf2"); - - /* store: panorama rot */ - temp= panophi; - panophi= 0.0; - pushTempPanoPhi(0.0); - - /* pano interference here? */ - setzbufvlaggen(projectvert); - - popTempPanoPhi(); - panophi= temp; - - zbuffershad(lar); - - square= lar->mode & LA_SQUARE; - - /* create Z tiles (for compression): this system is 24 bits!!! */ - - ztile= shb->zbuf; - ctile= shb->cbuf; - for(y=0; ysize; y+=16) { - if(y< shb->size/2) miny= y+15-shb->size/2; - else miny= y-shb->size/2; - - for(x=0; xsize; x+=16) { - - /* is tile within spotbundle? */ - a= shb->size/2; - if(x< a) minx= x+15-a; - else minx= x-a; - - dist= sqrt( (float)(minx*minx+miny*miny) ); - - if(square==0 && dist>(float)(a+12)) { /* 12, tested with a onlyshadow lamp */ - a= 256; verg= 0; /* 0x80000000; */ /* 0x7FFFFFFF; */ - rz1= (&verg)+1; - } - else { - lrectreadRectz(x, y, MIN2(shb->size-1,x+15), MIN2(shb->size-1,y+15), rcline); - rz1= (int *)rcline; - - verg= (*rz1 & 0xFFFFFF00); - - for(a=0;a<256;a++,rz1++) { - if( (*rz1 & 0xFFFFFF00) != verg) break; - } - } - if(a==256) { /* complete empty tile */ - *ctile= 0; - *ztile= *(rz1-1); - } - else { - - /* ACOMP etc. are defined to work L/B endian */ - - rc= rcline; - rz1= (int *)rcline; - verg= rc[ACOMP]; - verg1= rc[BCOMP]; - rc+= 4; - byt1= 1; byt2= 1; - for(a=1;a<256;a++,rc+=4) { - byt1 &= (verg==rc[ACOMP]); - byt2 &= (verg1==rc[BCOMP]); - - if(byt1==0) break; - } - if(byt1 && byt2) { /* only store byte */ - *ctile= 1; - *ztile= (unsigned long)MEM_mallocN(256+4, "tile1"); - rz= (int *)*ztile; - *rz= *rz1; - - zt= (char *)(rz+1); - rc= rcline; - for(a=0; a<256; a++, zt++, rc+=4) *zt= rc[GCOMP]; - } - else if(byt1) { /* store short */ - *ctile= 2; - *ztile= (unsigned long)MEM_mallocN(2*256+4,"Tile2"); - rz= (int *)*ztile; - *rz= *rz1; - - zt= (char *)(rz+1); - rc= rcline; - for(a=0; a<256; a++, zt+=2, rc+=4) { - zt[0]= rc[BCOMP]; - zt[1]= rc[GCOMP]; - } - } - else { /* store triple */ - *ctile= 3; - *ztile= (unsigned long)MEM_mallocN(3*256,"Tile3"); - - zt= (char *)*ztile; - rc= rcline; - for(a=0; a<256; a++, zt+=3, rc+=4) { - zt[0]= rc[ACOMP]; - zt[1]= rc[BCOMP]; - zt[2]= rc[GCOMP]; - } - } - } - ztile++; - ctile++; - } - } - - MEM_freeN(rcline); - MEM_freeN(R.rectz); R.rectz= 0; - - R.rectx= temprx; R.recty= tempry; - MTC_Mat4SwapMat4(shb->persmat, R.winmat); - - /* printf("lampbuf %d\n", sizeoflampbuf(shb)); */ -} - -int RE_BasicShadowBuffer::firstreadshadbuf(struct ShadBuf *shb, int xs, int ys, int nr) -{ - /* return a 1 if fully compressed shadbuf-tile && z==const */ - static int *rz; - int ofs; - char *ct; - - /* always test borders of shadowbuffer */ - if(xs<0) xs= 0; else if(xs>=shb->size) xs= shb->size-1; - if(ys<0) ys= 0; else if(ys>=shb->size) ys= shb->size-1; - - /* z calc */ - ofs= (ys>>4)*(shb->size>>4) + (xs>>4); - ct= shb->cbuf+ofs; - if(*ct==0) { - if(nr==0) { - rz= *( (int **)(shb->zbuf+ofs) ); - return 1; - } - else if(rz!= *( (int **)(shb->zbuf+ofs) )) return 0; - - return 1; - } - - return 0; -} - -float RE_BasicShadowBuffer::readshadowbuf(struct ShadBuf *shb, - int xs, int ys, int zs) /* return 1.0 : fully in light */ -{ - float temp; - int *rz, ofs; - int zsamp; - char *ct, *cz; - - /* simple clip */ - /* if(xs<0 || ys<0) return 1.0; */ - /* if(xs>=shb->size || ys>=shb->size) return 1.0; */ - - /* always test borders of shadowbuffer */ - if(xs<0) xs= 0; else if(xs>=shb->size) xs= shb->size-1; - if(ys<0) ys= 0; else if(ys>=shb->size) ys= shb->size-1; - - /* z calc */ - ofs= (ys>>4)*(shb->size>>4) + (xs>>4); - ct= shb->cbuf+ofs; - rz= *( (int **)(shb->zbuf+ofs) ); - - if(*ct==3) { - ct= ((char *)rz)+3*16*(ys & 15)+3*(xs & 15); - cz= (char *)&zsamp; - cz[ACOMP]= ct[0]; - cz[BCOMP]= ct[1]; - cz[GCOMP]= ct[2]; - } - else if(*ct==2) { - ct= ((char *)rz); - ct+= 4+2*16*(ys & 15)+2*(xs & 15); - zsamp= *rz; - - cz= (char *)&zsamp; - cz[BCOMP]= ct[0]; - cz[GCOMP]= ct[1]; - } - else if(*ct==1) { - ct= ((char *)rz); - ct+= 4+16*(ys & 15)+(xs & 15); - zsamp= *rz; - - cz= (char *)&zsamp; - cz[GCOMP]= ct[0]; - - } - else { - /* got warning on this from DEC alpha (64 bits).... */ - /* but it's working code! (ton) */ - zsamp= (int) rz; - } - - if(zsamp > zs) return 1.0; /* absolute no shadow */ - else if( zsamp < zs-bias) return 0.0 ; /* absolute in shadow */ - else { /* soft area */ - - temp= ( (float)(zs- zsamp) )/(float)bias; - return 1.0 - temp*temp; - - } -} - - -void RE_BasicShadowBuffer::readShadowValue(struct ShadBuf *shb, - float inp, - float * shadres) /* return 1.0: no shadow */ -{ - float fac, co[4], dx[3], dy[3], aantal=0; - float xs1,ys1, siz, *j, xres, yres; - int xs,ys, zs; - short a,num; - float shadowfactor = 1.0; - -#ifdef RE_NO_SHADOWS - shadres[0] = shadowfactor; - shadres[1] = shadowfactor; - shadres[2] = shadowfactor; - return; -#endif - - /* rotate renderco en osaco */ - siz= 0.5*(float)shb->size; - VECCOPY(co, R.co); - co[3]= 1.0; - - MTC_Mat4MulVec4fl(shb->persmat, co); /* rational homogenic co */ - - xs1= siz*(1.0+co[0]/co[3]); - ys1= siz*(1.0+co[1]/co[3]); - - /* Clip for z: near and far clip values of the shadow buffer. We - * can test for -1.0/1.0 because of the properties of the - * coordinate transformations. */ - fac= (co[2]/co[3]); - - if(fac>=1.0) { - shadres[0] = 0.0; - shadres[1] = 0.0; - shadres[2] = 0.0; - return; - } else if(fac<= -1.0) { - shadres[0] = 1.0; - shadres[1] = 1.0; - shadres[2] = 1.0; - return; - } - - zs = (int) (((float)0x7FFFFFFF)*fac); - - /* take num*num samples, increase area with fac */ - num= shb->samp*shb->samp; - fac= shb->soft; - - - bias = (int) ((1.1-inp*inp)*shb->bias); - - if(num==1) { - shadowfactor = readshadowbuf(shb,(int)xs1, (int)ys1, zs); - shadres[0] = shadowfactor; - shadres[1] = shadowfactor; - shadres[2] = shadowfactor; - return; - } - - co[0]= R.co[0]+O.dxco[0]; - co[1]= R.co[1]+O.dxco[1]; - co[2]= R.co[2]+O.dxco[2]; - co[3]= 1.0; - MTC_Mat4MulVec4fl(shb->persmat,co); /* rational hom co */ - dx[0]= xs1- siz*(1.0+co[0]/co[3]); - dx[1]= ys1- siz*(1.0+co[1]/co[3]); - - co[0]= R.co[0]+O.dyco[0]; - co[1]= R.co[1]+O.dyco[1]; - co[2]= R.co[2]+O.dyco[2]; - co[3]= 1.0; - MTC_Mat4MulVec4fl(shb->persmat,co); /* rational hom co */ - dy[0]= xs1- siz*(1.0+co[0]/co[3]); - dy[1]= ys1- siz*(1.0+co[1]/co[3]); - - xres= fac*( fabs(dx[0])+fabs(dy[0]) ); - yres= fac*( fabs(dx[1])+fabs(dy[1]) ); - - if(xresjit; - - if(xres<16.0 && yres<16.0) { - if(firstreadshadbuf(shb, (int)xs1, (int)ys1, 0)) { - if(firstreadshadbuf(shb, (int)(xs1+xres), (int)ys1, 1)) { - if(firstreadshadbuf(shb, (int)xs1, (int)(ys1+yres), 1)) { - if(firstreadshadbuf(shb, (int)(xs1+xres), (int)(ys1+yres), 1)) { - /* this return should do some renormalization, methinks */ - shadowfactor = readshadowbuf(shb,(int)xs1, (int)ys1, zs); - shadres[0] = shadowfactor; - shadres[1] = shadowfactor; - shadres[2] = shadowfactor; - return; - } - } - } - } - } - - for(a=num;a>0;a--) { - /* instead of jit i tried random: ugly! */ - xs= (int) (xs1 + xres*j[0]); - ys= (int) (ys1 + yres*j[1]); - j+=2; - - aantal+= readshadowbuf(shb, xs, ys, zs); - } - - /* Renormalizes for the sample number: */ - shadowfactor = aantal/( (float)(num) ); - shadres[0] = shadowfactor; - shadres[1] = shadowfactor; - shadres[2] = shadowfactor; - return; -} - -/* different function... sampling behind clipend can be LIGHT, bias is negative! */ -/* return: light */ -float RE_BasicShadowBuffer::readshadowbuf_halo(struct ShadBuf *shb, int xs, int ys, int zs) -{ - float temp; - int *rz, ofs; - int zbias, zsamp; - char *ct, *cz; - - /* simpleclip */ - if(xs<0 || ys<0) return 0.0; - if(xs>=shb->size || ys>=shb->size) return 0.0; - - /* z calc */ - ofs= (ys>>4)*(shb->size>>4) + (xs>>4); - ct= shb->cbuf+ofs; - rz= *( (int **)(shb->zbuf+ofs) ); - - if(*ct==3) { - ct= ((char *)rz)+3*16*(ys & 15)+3*(xs & 15); - cz= (char *)&zsamp; - zsamp= 0; - cz[ACOMP]= ct[0]; - cz[BCOMP]= ct[1]; - cz[GCOMP]= ct[2]; - } - else if(*ct==2) { - ct= ((char *)rz); - ct+= 4+2*16*(ys & 15)+2*(xs & 15); - zsamp= *rz; - - cz= (char *)&zsamp; - cz[BCOMP]= ct[0]; - cz[GCOMP]= ct[1]; - } - else if(*ct==1) { - ct= ((char *)rz); - ct+= 4+16*(ys & 15)+(xs & 15); - zsamp= *rz; - - cz= (char *)&zsamp; - cz[GCOMP]= ct[0]; - - } - else { - /* same as before */ - /* still working code! (ton) */ - zsamp= (int) rz; - } - - /* NO schadow when sampled at 'eternal' distance */ - - if(zsamp >= 0x7FFFFE00) return 1.0; - - if(zsamp > zs) return 1.0; /* absolute no shadww */ - else { - /* bias is negative, so the (zs-bias) can be beyond 0x7fffffff */ - zbias= 0x7fffffff - zs; - if(zbias > -bias) { - if( zsamp < zs-bias) return 0.0 ; /* absolute in shadow */ - } - else return 0.0 ; /* absolute shadow */ - } - - /* soft area */ - - temp= ( (float)(zs- zsamp) )/(float)bias; - return 1.0 - temp*temp; -} - - -float RE_BasicShadowBuffer::shadow_halo(LampRen *lar, float *p1, float *p2) -{ - /* p1 p2 already are rotated in spot-space */ - ShadBuf *shb= lar->shb; - float co[4], siz; - float labda, labdao, labdax, labday, ldx, ldy; - float zf, xf1, yf1, zf1, xf2, yf2, zf2; - float count, lightcount; - int x, y, z, xs1, ys1; - int dx = 0, dy = 0; - - siz= 0.5*(float)shb->size; - /* negative! The other side is more important */ - bias= -shb->bias; - - co[0]= p1[0]; - co[1]= p1[1]; - co[2]= p1[2]/lar->sh_zfac; - co[3]= 1.0; - MTC_Mat4MulVec4fl(shb->winmat, co); /* rational hom co */ - xf1= siz*(1.0+co[0]/co[3]); - yf1= siz*(1.0+co[1]/co[3]); - zf1= (co[2]/co[3]); - - - co[0]= p2[0]; - co[1]= p2[1]; - co[2]= p2[2]/lar->sh_zfac; - co[3]= 1.0; - MTC_Mat4MulVec4fl(shb->winmat, co); /* rational hom co */ - xf2= siz*(1.0+co[0]/co[3]); - yf2= siz*(1.0+co[1]/co[3]); - zf2= (co[2]/co[3]); - - /* the 2dda (a pixel line formula) */ - - xs1= (int)xf1; - ys1= (int)yf1; - - if(xf1 != xf2) { - if(xf2-xf1 > 0.0) { - labdax= (xf1-xs1-1.0)/(xf1-xf2); - ldx= -shb->shadhalostep/(xf1-xf2); - dx= shb->shadhalostep; - } - else { - labdax= (xf1-xs1)/(xf1-xf2); - ldx= shb->shadhalostep/(xf1-xf2); - dx= -shb->shadhalostep; - } - } - else { - labdax= 1.0; - ldx= 0.0; - } - - if(yf1 != yf2) { - if(yf2-yf1 > 0.0) { - labday= (yf1-ys1-1.0)/(yf1-yf2); - ldy= -shb->shadhalostep/(yf1-yf2); - dy= shb->shadhalostep; - } - else { - labday= (yf1-ys1)/(yf1-yf2); - ldy= shb->shadhalostep/(yf1-yf2); - dy= -shb->shadhalostep; - } - } - else { - labday= 1.0; - ldy= 0.0; - } - - x= xs1; - y= ys1; - labda= count= lightcount= 0.0; - -/* printf("start %x %x \n", (int)(0x7FFFFFFF*zf1), (int)(0x7FFFFFFF*zf2)); */ - - while(1) { - labdao= labda; - - if(labdax==labday) { - labdax+= ldx; - x+= dx; - labday+= ldy; - y+= dy; - } - else { - if(labdax=1.0) break; - - zf= zf1 + labda*(zf2-zf1); - count+= 1.0; - - if(zf<= 0.0) lightcount += 1.0; /* close to the spot */ - else { - - /* make sure, behind the clipend we extend halolines. */ - if(zf>=1.0) z= 0x7FFFF000; - else z= (int)(0x7FFFF000*zf); - - lightcount+= readshadowbuf_halo(shb, x, y, z); - - } - } - - if(count!=0.0) return (lightcount/count); - return 0.0; - -} - diff --git a/source/blender/render/intern/source/edgeRender.c b/source/blender/render/intern/source/edgeRender.c index c4f7ad34cd6..d8f03e6b0de 100644 --- a/source/blender/render/intern/source/edgeRender.c +++ b/source/blender/render/intern/source/edgeRender.c @@ -54,6 +54,7 @@ #include #include +#include #include /* INT_MIN,MAX are used here */ #include @@ -381,7 +382,7 @@ void renderEdges(char *colourRect) rz3= rz2 + bufWidth; if (same_mat_redux) { - matptr_low = matBuffer; + matptr_low = (int *) matBuffer; matptr_cent = matptr_low + bufWidth; matptr_high = matptr_cent + bufWidth; } diff --git a/source/blender/render/intern/source/envmap.c b/source/blender/render/intern/source/envmap.c index 397853e5ecd..425ad69f7cd 100644 --- a/source/blender/render/intern/source/envmap.c +++ b/source/blender/render/intern/source/envmap.c @@ -634,7 +634,7 @@ static void set_dxtdyt(float *dxts, float *dyts, float *dxt, float *dyt, int fac /* ------------------------------------------------------------------------- */ extern float Tin, Ta, Tr, Tg, Tb; /* texture.c */ -int RE_envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt) +int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex) { /* texvec should be the already reflected normal */ EnvMap *env; @@ -665,7 +665,7 @@ int RE_envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt) face= envcube_isect(vec, sco); tex->ima= env->cube[face]; - if(R.osatex) { + if(osatex) { MTC_Mat4Mul3Vecfl(env->object->imat, dxt); MTC_Mat4Mul3Vecfl(env->object->imat, dyt); diff --git a/source/blender/render/intern/source/initrender.c b/source/blender/render/intern/source/initrender.c index cfacb85fba0..8edde6563b7 100644 --- a/source/blender/render/intern/source/initrender.c +++ b/source/blender/render/intern/source/initrender.c @@ -472,13 +472,10 @@ void RE_make_existing_file(char *name) /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -/* code for holographic hack, used in the neogeo days. SHould be removed (ton) */ - -extern float holoofs; /* render.c */ void RE_setwindowclip(int mode, int jmode) { Camera *cam=0; - float lens, fac, minx, miny, maxx, maxy; + float lens, minx, miny, maxx, maxy; float xd, yd, afmx, afmy; if(G.scene->camera==0) return; @@ -554,24 +551,6 @@ void RE_setwindowclip(int mode, int jmode) } - if(G.special1 & G_HOLO) { - if(G.scene->camera->type==OB_CAMERA) { - cam= G.scene->camera->data; - if(cam->flag & CAM_HOLO2) { - - if(cam->netend==0.0) cam->netend= (G.scene->r.efra); - - fac= ((G.scene->r.cfra)-1.0)/(cam->netend)-0.5; - fac*= (R.rectx); - fac*= cam->hololen1; - - holoofs= -fac; - minx-= fac; - maxx-= fac; - } - } - } - minx= R.pixsize*(minx+xd); maxx= R.pixsize*(maxx+xd); miny= R.pixsize*(miny+yd); @@ -694,27 +673,6 @@ void addparttorect(short nr, Part *part) /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -void RE_holoview() -{ - Camera *cam; - float dist, fac, fy, fz; - - if(G.scene==0 || G.scene->camera==0) return; - - if(G.scene->camera->type==OB_CAMERA) { - cam= G.scene->camera->data; - if(cam->flag & (CAM_HOLO1|CAM_HOLO2)) { - fy= G.scene->camera->loc[1]; - fz= G.scene->camera->loc[2]; - dist= cam->hololen*sqrt( fy*fy+ fz*fz ); - - fac= ((G.scene->r.cfra)-(G.scene->r.sfra))/((float)((G.scene->r.efra)-(G.scene->r.sfra))); - - G.scene->camera->loc[0]= -dist+ 2*fac*dist; - } - } -} - void add_to_blurbuf(int blur) { static unsigned int *blurrect= 0; @@ -818,17 +776,13 @@ void oldRenderLoop(void) /* here the PART and FIELD loops */ /* INIT */ BLI_srand( 2*(G.scene->r.cfra)+fi); - - - R.vlaknr= -1; + R.flag|= R_RENDERING; if(fi==1) R.flag |= R_SEC_FIELD; - /* MOTIONBLUR loop */ if(R.r.mode & R_MBLUR) blur= R.osa; else blur= 1; - while(blur--) { @@ -1210,9 +1164,6 @@ void RE_initrender(struct View3D *ogl_render_view3d) RE_local_printrenderinfo((PIL_check_seconds_timer() - start_time), -1); - /* restore variables */ - R.osatex= 0; - R.vlr= 0; /* at cubemap */ R.flag= 0; } diff --git a/source/blender/render/intern/source/outerRenderLoop.c b/source/blender/render/intern/source/outerRenderLoop.c index 809e5066b9e..06c2ef0bf2e 100644 --- a/source/blender/render/intern/source/outerRenderLoop.c +++ b/source/blender/render/intern/source/outerRenderLoop.c @@ -271,25 +271,19 @@ void unifiedRenderingLoop(void) /* here the PART en FIELD loops */ R.afmy/= 2; R.r.yasp*= 2; R.ycor= ( (float)R.r.yasp)/( (float)R.r.xasp); - } - for(fi=0; fir.cfra)+fi); - - R.vlaknr= -1; R.flag|= R_RENDERING; if(fi==1) R.flag |= R_SEC_FIELD; - /* MOTIONBLUR loop */ if(R.r.mode & R_MBLUR) blur= R.osa; else blur= 1; - while(blur--) { diff --git a/source/blender/render/intern/source/pixelshading.c b/source/blender/render/intern/source/pixelshading.c index ec9dd633361..425cb44fb37 100644 --- a/source/blender/render/intern/source/pixelshading.c +++ b/source/blender/render/intern/source/pixelshading.c @@ -33,19 +33,6 @@ * * $Id$ * - * Shading hierarchy: - * - * (externally visible) - * - * renderPixel---------- - * | renderHaloPixel-- shadeHaloFloat - * | - * | renderFacePixel-- shadeLampLusFloat - * | shadeSpotHaloPixelFloat-- spotHaloFloat - * - * - * renderSpotHaloPixel--(should call shadeSpotHaloPixelFloat, but there's numerical) - * ( issues there... need to iron that out still ) */ #include @@ -69,17 +56,14 @@ #include "BKE_utildefines.h" #include "render.h" +#include "texture.h" #include "render_intern.h" #include "vanillaRenderPipe_types.h" #include "pixelblending.h" -#include "zbuf.h" #include "rendercore.h" /* for some shading functions... */ #include "zbufferdatastruct.h" -#include "shadbuf.h" -#include "shadowBuffer.h" - #include "renderHelp.h" #include "gammaCorrectionTables.h" @@ -90,38 +74,46 @@ #include #endif -/* ------------------------------------------------------------------------- */ -/* maybe declare local functions here? */ -/* ------------------------------------------------------------------------- */ /* The collector is the communication channel with the render pipe. */ extern RE_COLBUFTYPE collector[4]; /* used throughout as pixel colour accu */ -/* shortcol was the old collector */ -extern float holoofs, fmask[256]; -extern float Zmulx, Zmuly; /* Some kind of scale? */ -unsigned int calcHaloZ(HaloRen *har, unsigned int zz); - -/* ------------------------------------------------------------------------- */ -/* if defined: do full error tracing and reporting here */ -/* #define RE_PIXSHADE_FULL_SAFETY */ -/* if defined: use fake (dummy) colours for filling pixels (all is purple) */ -/* #define RE_FAKE_PIXELS */ -/* if defined: use fake (dummy) colours for filling faces (all blue) */ -/* #define RE_FAKE_FACE_PIXELS */ -/* if defined: use fake (dummy) colours for filling halos (all red) */ -/* #define RE_FAKE_HALO_PIXELS */ -/* #define RE_FAKE_HALO_PIXELS_2 */ -/* if defined: use fake (dummy) colours for filling spothalos (green) */ -/* #define RE_FAKE_SPOTHALO_PIXELS */ -/* if defined: use fake (dummy) colours for shading lighting */ -/* #define RE_FAKE_LAMP_SHADE */ -/* if defined: fake colours for sky pixels */ -/* #define RE_FAKE_SKY_PIXELS */ +/* ton: + - unified render now uses face render routines from rendercore.c + - todo still: shalo render and sky routines */ /* ------------------------------------------------------------------------- */ -unsigned int calcHaloZ(HaloRen *har, unsigned int zz) +void *renderPixel(float x, float y, int *obdata, int mask) +{ + void* data = NULL; + + if (obdata[3] & RE_POLY) { + /* face pixels aren't rendered in floats yet, so we wrap it here */ + data = shadepixel(x, y, obdata[1], mask, collector); + } + else if (obdata[3] & RE_HALO) { + data = renderHaloPixel(x, y, obdata[1]); + } + else if( obdata[1] == 0 ) { + /* for lamphalo, but doesn't seem to be called? Actually it is, and */ + /* it returns NULL pointers. */ + data = shadepixel(x, y, obdata[1], mask, collector); + } + return data; + +} /* end of void renderPixel(float x, float y, int *obdata) */ + +/* ------------------------------------------------------------------------- */ + +void renderSpotHaloPixel(float x, float y, float* target) +{ + shadepixel(x, y, 0, 0, target); +} + + +/* ------------------------------------------------------------------------- */ +static unsigned int calcHaloZ(HaloRen *har, unsigned int zz) { if(har->type & HA_ONLYSKY) { @@ -135,1119 +127,8 @@ unsigned int calcHaloZ(HaloRen *har, unsigned int zz) return zz; } -/* ------------------------------------------------------------------------- */ - -void *renderPixel(float x, float y, int *obdata) +void *renderHaloPixel(float x, float y, int haloNr) { - void* data = NULL; - - if (obdata[3] & RE_POLY) { - /* face pixels aren't rendered in floats yet, so we wrap it here */ - data = renderFacePixel(x, y, obdata[1]); - } - else if (obdata[3] & RE_HALO) { - data = renderHaloPixel(x, y, obdata[1]); - } - else if( obdata[1] == 0 ) { - /* for lamphalo, but doesn't seem to be called? Actually it is, and */ - /* it returns NULL pointers. */ - data = renderFacePixel(x, y, obdata[1]); - } - return data; - -} /* end of void renderPixel(float x, float y, int *obdata) */ - -/* ------------------------------------------------------------------------- */ - -void *renderFacePixel(float x, float y, int vlaknr) -/* Result goes into */ -{ - static VlakRen *vlr; /* static, because we don't want to recalculate vlr */ - /* when we already know it */ - static VertRen *v1, *v2, *v3; - static float t00, t01, t10, t11, dvlak, n1[3], n2[3], n3[3]; - static float s00, s01, s10, s11; - float *o1, *o2, *o3; - float u, v, l, dl, hox, hoy, detsh, fac, deler, alpha; - char *cp1, *cp2, *cp3; - - if(R.vlaknr== -1) { /* set by initrender */ - /* also set in the pixelrender loop */ - vlr= R.vlr= 0; - } - - if(vlaknr<=0) { /* sky */ - R.vlaknr= 0; - collector[3] = 0.0; - } - else if( (vlaknr & 0x7FFFFF) <= R.totvlak) { - - /* What follows now is a large bunch of texture coordinate mappings. */ - /* When this face is the same as the previous one, that means all */ - /* the coordinate remapping does not need to be recomputed. */ - if(vlaknr!=R.vlaknr) { - - vlr= RE_findOrAddVlak( (vlaknr-1) & 0x7FFFFF); - - R.mat= vlr->mat; - R.matren= R.mat->ren; - - if(R.matren==0) { /* purple color, for debug */ - collector[3] = RE_UNITY_COLOUR_FLOAT; - collector[2] = 0.0; - collector[1] = RE_UNITY_COLOUR_FLOAT; - collector[0] = RE_UNITY_COLOUR_FLOAT; - return NULL; - } - - R.vlr= vlr; - - R.vno= vlr->n; - R.osatex= (R.matren->texco & TEXCO_OSA); - R.vlaknr= vlaknr; - - v1= vlr->v1; - dvlak= MTC_dot3Float(v1->co, vlr->n); - - if( (vlr->flag & R_SMOOTH) || (R.matren->texco & NEED_UV)) { /* uv needed */ - if(vlaknr & 0x800000) { - v2= vlr->v3; - v3= vlr->v4; - } - else { - v2= vlr->v2; - v3= vlr->v3; - } - - if(vlr->snproj==0) { - t00= v3->co[0]-v1->co[0]; t01= v3->co[1]-v1->co[1]; - t10= v3->co[0]-v2->co[0]; t11= v3->co[1]-v2->co[1]; - } - else if(vlr->snproj==1) { - t00= v3->co[0]-v1->co[0]; t01= v3->co[2]-v1->co[2]; - t10= v3->co[0]-v2->co[0]; t11= v3->co[2]-v2->co[2]; - } - else { - t00= v3->co[1]-v1->co[1]; t01= v3->co[2]-v1->co[2]; - t10= v3->co[1]-v2->co[1]; t11= v3->co[2]-v2->co[2]; - } - - detsh= t00*t11-t10*t01; - t00/= detsh; t01/=detsh; - t10/=detsh; t11/=detsh; - - if(vlr->flag & R_SMOOTH) { /* set vertex normals ("punos") */ - if(vlr->puno & ME_FLIPV1) MTC_cp3FloatInv(v1->n, n1); - else MTC_cp3Float(v1->n, n1); - - if(vlaknr & 0x800000) { - if(vlr->puno & ME_FLIPV3) MTC_cp3FloatInv(v2->n, n2); - else MTC_cp3Float(v2->n, n2); - - if(vlr->puno & ME_FLIPV4) MTC_cp3FloatInv(v3->n, n3); - else MTC_cp3Float(v3->n, n3); - } - else { - if(vlr->puno & ME_FLIPV2) MTC_cp3FloatInv(v2->n, n2); - else MTC_cp3Float(v2->n, n2); - - if(vlr->puno & ME_FLIPV3) MTC_cp3FloatInv(v3->n, n3); - else MTC_cp3Float(v3->n, n3); - } - } - if(R.matren->texco & TEXCO_STICKY) { - s00= v3->ho[0]/v3->ho[3] - v1->ho[0]/v1->ho[3]; - s01= v3->ho[1]/v3->ho[3] - v1->ho[1]/v1->ho[3]; - s10= v3->ho[0]/v3->ho[3] - v2->ho[0]/v2->ho[3]; - s11= v3->ho[1]/v3->ho[3] - v2->ho[1]/v2->ho[3]; - - detsh= s00*s11-s10*s01; - s00/= detsh; s01/=detsh; - s10/=detsh; s11/=detsh; - } - } - } /* end of if vlaknr*/ - - /* This trafo might be migrated to a separate function. It is used */ - /* quite often. */ - if( (G.special1 & G_HOLO) - && (((Camera *)G.scene->camera->data)->flag & CAM_HOLO2) ) { - R.view[0]= (x+(R.xstart)+1.0+holoofs); - } - else { - R.view[0]= (x+(R.xstart)+1.0); - } - - if(R.flag & R_SEC_FIELD) { - if(R.r.mode & R_ODDFIELD) R.view[1]= (y+R.ystart+0.5)*R.ycor; - else R.view[1]= (y+R.ystart+1.5)*R.ycor; - } - else R.view[1]= (y+R.ystart+1.0)*R.ycor; - - R.view[2]= -R.viewfac; - - if(R.r.mode & R_PANORAMA) { - float panoco, panosi; - panoco = getPanovCo(); - panosi = getPanovSi(); - u= R.view[0]; v= R.view[2]; - - R.view[0]= panoco*u + panosi*v; - R.view[2]= -panosi*u + panoco*v; - } - - deler= vlr->n[0]*R.view[0] + vlr->n[1]*R.view[1] + vlr->n[2]*R.view[2]; - if (deler!=0.0) fac= R.zcor= dvlak/deler; - else fac= R.zcor= 0.0; - - R.co[0]= fac*R.view[0]; - R.co[1]= fac*R.view[1]; - R.co[2]= fac*R.view[2]; - - if(R.osatex || (R.r.mode & R_SHADOW) ) { - u= dvlak/(deler-vlr->n[0]); - v= dvlak/(deler- R.ycor*vlr->n[1]); - - O.dxco[0]= R.co[0]- (R.view[0]-1.0)*u; - O.dxco[1]= R.co[1]- (R.view[1])*u; - O.dxco[2]= R.co[2]- (R.view[2])*u; - - O.dyco[0]= R.co[0]- (R.view[0])*v; - O.dyco[1]= R.co[1]- (R.view[1]-1.0*R.ycor)*v; - O.dyco[2]= R.co[2]- (R.view[2])*v; - - } - - fac= Normalise(R.view); - R.zcor*= fac; /* for mist */ - - if(R.osatex) { - if( (R.matren->texco & TEXCO_REFL) ) { - O.dxview= 1.0/fac; - O.dyview= R.ycor/fac; - } - } - - /* UV en TEX*/ - if( (vlr->flag & R_SMOOTH) || (R.matren->texco & NEED_UV)) { - if(vlr->snproj==0) { - u= (R.co[0]-v3->co[0])*t11-(R.co[1]-v3->co[1])*t10; - v= (R.co[1]-v3->co[1])*t00-(R.co[0]-v3->co[0])*t01; - if(R.osatex) { - O.dxuv[0]= O.dxco[0]*t11- O.dxco[1]*t10; - O.dxuv[1]= O.dxco[1]*t00- O.dxco[0]*t01; - O.dyuv[0]= O.dyco[0]*t11- O.dyco[1]*t10; - O.dyuv[1]= O.dyco[1]*t00- O.dyco[0]*t01; - } - } - else if(vlr->snproj==1) { - u= (R.co[0]-v3->co[0])*t11-(R.co[2]-v3->co[2])*t10; - v= (R.co[2]-v3->co[2])*t00-(R.co[0]-v3->co[0])*t01; - if(R.osatex) { - O.dxuv[0]= O.dxco[0]*t11- O.dxco[2]*t10; - O.dxuv[1]= O.dxco[2]*t00- O.dxco[0]*t01; - O.dyuv[0]= O.dyco[0]*t11- O.dyco[2]*t10; - O.dyuv[1]= O.dyco[2]*t00- O.dyco[0]*t01; - } - } - else { - u= (R.co[1]-v3->co[1])*t11-(R.co[2]-v3->co[2])*t10; - v= (R.co[2]-v3->co[2])*t00-(R.co[1]-v3->co[1])*t01; - if(R.osatex) { - O.dxuv[0]= O.dxco[1]*t11- O.dxco[2]*t10; - O.dxuv[1]= O.dxco[2]*t00- O.dxco[1]*t01; - O.dyuv[0]= O.dyco[1]*t11- O.dyco[2]*t10; - O.dyuv[1]= O.dyco[2]*t00- O.dyco[1]*t01; - } - } - l= 1.0+u+v; - - if(vlr->flag & R_SMOOTH) { - R.vn[0]= l*n3[0]-u*n1[0]-v*n2[0]; - R.vn[1]= l*n3[1]-u*n1[1]-v*n2[1]; - R.vn[2]= l*n3[2]-u*n1[2]-v*n2[2]; - - Normalise(R.vn); - if(R.osatex && (R.matren->texco & (TEXCO_NORM+TEXCO_REFL)) ) { - dl= O.dxuv[0]+O.dxuv[1]; - O.dxno[0]= dl*n3[0]-O.dxuv[0]*n1[0]-O.dxuv[1]*n2[0]; - O.dxno[1]= dl*n3[1]-O.dxuv[0]*n1[1]-O.dxuv[1]*n2[1]; - O.dxno[2]= dl*n3[2]-O.dxuv[0]*n1[2]-O.dxuv[1]*n2[2]; - dl= O.dyuv[0]+O.dyuv[1]; - O.dyno[0]= dl*n3[0]-O.dyuv[0]*n1[0]-O.dyuv[1]*n2[0]; - O.dyno[1]= dl*n3[1]-O.dyuv[0]*n1[1]-O.dyuv[1]*n2[1]; - O.dyno[2]= dl*n3[2]-O.dyuv[0]*n1[2]-O.dyuv[1]*n2[2]; - - } - } - else { - VECCOPY(R.vn, vlr->n); - } - - if(R.matren->mode & MA_ZINV) { /* z invert */ - /* R.vn[0]= -R.vn[0]; */ - /* R.vn[1]= -R.vn[1]; */ - } - - if(R.matren->texco & TEXCO_ORCO) { - if(v2->orco) { - o1= v1->orco; - o2= v2->orco; - o3= v3->orco; - - R.lo[0]= l*o3[0]-u*o1[0]-v*o2[0]; - R.lo[1]= l*o3[1]-u*o1[1]-v*o2[1]; - R.lo[2]= l*o3[2]-u*o1[2]-v*o2[2]; - - if(R.osatex) { - dl= O.dxuv[0]+O.dxuv[1]; - O.dxlo[0]= dl*o3[0]-O.dxuv[0]*o1[0]-O.dxuv[1]*o2[0]; - O.dxlo[1]= dl*o3[1]-O.dxuv[0]*o1[1]-O.dxuv[1]*o2[1]; - O.dxlo[2]= dl*o3[2]-O.dxuv[0]*o1[2]-O.dxuv[1]*o2[2]; - dl= O.dyuv[0]+O.dyuv[1]; - O.dylo[0]= dl*o3[0]-O.dyuv[0]*o1[0]-O.dyuv[1]*o2[0]; - O.dylo[1]= dl*o3[1]-O.dyuv[0]*o1[1]-O.dyuv[1]*o2[1]; - O.dylo[2]= dl*o3[2]-O.dyuv[0]*o1[2]-O.dyuv[1]*o2[2]; - } - } - } - - if(R.matren->texco & TEXCO_GLOB) { - VECCOPY(R.gl, R.co); - MTC_Mat4MulVecfl(R.viewinv, R.gl); - if(R.osatex) { - VECCOPY(O.dxgl, O.dxco); - MTC_Mat3MulVecfl(R.imat, O.dxco); - VECCOPY(O.dygl, O.dyco); - MTC_Mat3MulVecfl(R.imat, O.dyco); - } - } - if((R.matren->texco & TEXCO_UV) || (R.matren->mode & (MA_VERTEXCOL|MA_FACETEXTURE))) { - if(R.vlr->tface) { - float *uv1, *uv2, *uv3; - - uv1= R.vlr->tface->uv[0]; - if( (vlaknr & 0x800000) || (R.vlr->flag & R_FACE_SPLIT) ) { - uv2= R.vlr->tface->uv[2]; - uv3= R.vlr->tface->uv[3]; - } - else { - uv2= R.vlr->tface->uv[1]; - uv3= R.vlr->tface->uv[2]; - } - - R.uv[0]= -1.0 + 2.0*(l*uv3[0]-u*uv1[0]-v*uv2[0]); - R.uv[1]= -1.0 + 2.0*(l*uv3[1]-u*uv1[1]-v*uv2[1]); - - if(R.osatex) { - float duv[2]; - - dl= O.dxuv[0]+O.dxuv[1]; - duv[0]= O.dxuv[0]; - duv[1]= O.dxuv[1]; - - O.dxuv[0]= 2.0*(dl*uv3[0]-duv[0]*uv1[0]-duv[1]*uv2[0]); - O.dxuv[1]= 2.0*(dl*uv3[1]-duv[0]*uv1[1]-duv[1]*uv2[1]); - - dl= O.dyuv[0]+O.dyuv[1]; - duv[0]= O.dyuv[0]; - duv[1]= O.dyuv[1]; - - O.dyuv[0]= 2.0*(dl*uv3[0]-duv[0]*uv1[0]-duv[1]*uv2[0]); - O.dyuv[1]= 2.0*(dl*uv3[1]-duv[0]*uv1[1]-duv[1]*uv2[1]); - } - } - else { - R.uv[0]= 2.0*(u+.5); - R.uv[1]= 2.0*(v+.5); - } - } - if(R.matren->texco & TEXCO_NORM) { - R.orn[0]= R.vn[0]; - R.orn[1]= -R.vn[1]; - R.orn[2]= R.vn[2]; - } - if(R.matren->mode & MA_VERTEXCOL) { - - /* some colour calculations here */ - cp1= (char *)vlr->vcol; - if(cp1) { - if( (vlaknr & 0x800000) || (R.vlr->flag & R_FACE_SPLIT) ) { - cp2= (char *)(vlr->vcol+2); - cp3= (char *)(vlr->vcol+3); - } - else { - cp2= (char *)(vlr->vcol+1); - cp3= (char *)(vlr->vcol+2); - } - R.vcol[0]= (l*cp3[3]-u*cp1[3]-v*cp2[3])/255.0; - R.vcol[1]= (l*cp3[2]-u*cp1[2]-v*cp2[2])/255.0; - R.vcol[2]= (l*cp3[1]-u*cp1[1]-v*cp2[1])/255.0; - - } - else { - R.vcol[0]= 0.0; - R.vcol[1]= 0.0; - R.vcol[2]= 0.0; - } - } - if(R.matren->mode & MA_FACETEXTURE) { - if((R.matren->mode & MA_VERTEXCOL)==0) { - R.vcol[0]= 1.0; - R.vcol[1]= 1.0; - R.vcol[2]= 1.0; - } - /* shading here */ - if(vlr->tface) render_realtime_texture(); - } - - /* after this, the u en v AND O.dxuv and O.dyuv are incorrect */ - if(R.matren->texco & TEXCO_STICKY) { - if(v2->sticky) { - - /* recalc u en v */ - hox= x/Zmulx -1.0; - hoy= y/Zmuly -1.0; - u= (hox - v3->ho[0]/v3->ho[3])*s11 - - (hoy - v3->ho[1]/v3->ho[3])*s10; - v= (hoy - v3->ho[1]/v3->ho[3])*s00 - - (hox - v3->ho[0]/v3->ho[3])*s01; - l= 1.0+u+v; - - o1= v1->sticky; - o2= v2->sticky; - o3= v3->sticky; - - R.sticky[0]= l*o3[0]-u*o1[0]-v*o2[0]; - R.sticky[1]= l*o3[1]-u*o1[1]-v*o2[1]; - - if(R.osatex) { - O.dxuv[0]= s11/Zmulx; - O.dxuv[1]= - s01/Zmulx; - O.dyuv[0]= - s10/Zmuly; - O.dyuv[1]= s00/Zmuly; - - dl= O.dxuv[0]+O.dxuv[1]; - O.dxsticky[0]= dl*o3[0]-O.dxuv[0]*o1[0]-O.dxuv[1]*o2[0]; - O.dxsticky[1]= dl*o3[1]-O.dxuv[0]*o1[1]-O.dxuv[1]*o2[1]; - dl= O.dyuv[0]+O.dyuv[1]; - O.dysticky[0]= dl*o3[0]-O.dyuv[0]*o1[0]-O.dyuv[1]*o2[0]; - O.dysticky[1]= dl*o3[1]-O.dyuv[0]*o1[1]-O.dyuv[1]*o2[1]; - } - } - } - } - else { - VECCOPY(R.vn, vlr->n); - } - if(R.matren->texco & TEXCO_WINDOW) { - R.winco[0]= (x+(R.xstart))/(float)R.afmx; - R.winco[1]= (y+(R.ystart))/(float)R.afmy; - } - - /* After all texture coordinates are set and converted and */ - /* transformed, we need to put some colour on it: */ - shadeLampLusFloat(); - - /* MIST */ - if( (R.wrld.mode & WO_MIST) && (R.matren->mode & MA_NOMIST)==0 ){ - /* alpha returned in float? */ - alpha= mistfactor(R.co); - } - else alpha= 1.0; - - /* RAYTRACE WAS HERE! */ - - if(R.matren->alpha!=1.0 || alpha!=1.0) { - fac= alpha*(R.matren->alpha); - - collector[0] *= fac; /* This applies to transparent faces! Even */ - collector[1] *= fac; /* though it may seem to be a premul op, it */ - collector[2] *= fac; /* isn't. */ - collector[3] = fac; /* doesn't need scaling? */ - } - else { - collector[3] = 1.0; - } - } - else { - collector[0] = 1.0; - collector[1] = 1.0; - collector[2] = 0.0; - collector[3] = 1.0; - } - - /* Spothalos: do this here for covered pixels. It seems messy to place */ - /* it here, structure-wise, but it's more efficient. Also, not having it */ - /* here makes it difficult to do proper overlaying later on. */ - /* It starts off with a coordinate transform again. */ - if(R.flag & R_LAMPHALO) { - if(vlaknr<=0) { /* calculate view vector and set R.co at far */ - - /* this view vector stuff should get its own function */ - R.view[0]= (x+(R.xstart)+1.0); - - if(R.flag & R_SEC_FIELD) { - if(R.r.mode & R_ODDFIELD) R.view[1]= (y+R.ystart+0.5)*R.ycor; - else R.view[1]= (y+R.ystart+1.5)*R.ycor; - } else { - R.view[1]= (y+R.ystart+1.0)*R.ycor; - } - - R.view[2]= -R.viewfac; - - if(R.r.mode & R_PANORAMA) { - float panoco, panosi; - panoco = getPanovCo(); - panosi = getPanovSi(); - u= R.view[0]; v= R.view[2]; - - R.view[0]= panoco*u + panosi*v; - R.view[2]= -panosi*u + panoco*v; - } - - R.co[2]= 0.0; - - } - - shadeSpotHaloPixelFloat(collector); - } - - return vlr; - -} /* end of void renderFacePixelFloat(float x, float y, int vlaknr) */ - -/* ------------------------------------------------------------------------- */ -/* - - uses R.view to determine which pixel, I think? - - the spothalo is dumped quite unceremoniously on top of the col vector - This function is also (sort of) implemented in shadespothalofix, but without - all the clipping stuff. Somehow, the clipping here is _quite_ critical. - */ -void shadeSpotHaloPixelFloat(float *col) -{ - LampRen *lar; - float factor = 0.0; - int a; - float rescol[4]; - - - for(a=0; atype==LA_SPOT && (lar->mode & LA_HALO) && lar->haint>0) { - - if(lar->org) { - lar->r= lar->org->r; - lar->g= lar->org->g; - lar->b= lar->org->b; - } - - /* determines how much spothalo we see */ - spotHaloFloat(lar, R.view, &factor); - - if(factor>0.0) { - - /* Why is alpha clipped? */ - if(factor > RE_FULL_COLOUR_FLOAT) rescol[3]= 1.0; - else rescol[3]= factor; - - /* nasty issue: gamma corrected rendering AND 'addalphaADD' */ - /* do not work well togethe */ - /* actually, we should invent a new 'add' gamma type... (ton) */ - /* - There is a strange thing here: the spothalo seems to be - calculated in the space you would get when you go from - value space through inverse gamma! So we gamma-transform - to value-space, then integrate, blend, and gamma correct - _again_. -nzc- - */ - - rescol[0] = factor * lar->r; /* Lampren rgb's are floats */ - rescol[1] = factor * lar->g; - rescol[2] = factor * lar->b; - - /* ---->add values, disregard alpha */ - /* - check for dest. alpha = 0. If so , just copy */ - /* this is a slightly different approach: I do the gamma */ - /* correction BEFORE the addition. What does the other */ - /* approach do? */ - - /* removed gamma correction here (ton) looks better, but still not 100% OK */ - if (col[3]< RE_EMPTY_COLOUR_FLOAT) { - col[0] = (rescol[0]); - col[1] = (rescol[1]); - col[2] = (rescol[2]); - col[3] = rescol[3]; - } else { - col[0] += (rescol[0]); - col[1] += (rescol[1]); - col[2] += (rescol[2]); - col[3] += rescol[3]; - } - - /* this clipping may have to go? Actually, if it's */ - /* done sooner, it may be more efficient */ - if(col[0] > RE_FULL_COLOUR_FLOAT) col[0] = 1.0; - if(col[1] > RE_FULL_COLOUR_FLOAT) col[1] = 1.0; - if(col[2] > RE_FULL_COLOUR_FLOAT) col[2] = 1.0; - if(col[3] > RE_FULL_COLOUR_FLOAT) col[3] = 1.0; - if(col[0] < RE_EMPTY_COLOUR_FLOAT) col[0] = 0.0; - if(col[1] < RE_EMPTY_COLOUR_FLOAT) col[1] = 0.0; - if(col[2] < RE_EMPTY_COLOUR_FLOAT) col[2] = 0.0; - if(col[3] < RE_EMPTY_COLOUR_FLOAT) col[3] = 0.0; - } - } - } - - if(col[0] < RE_EMPTY_COLOUR_FLOAT) col[0] = 0.0; - if(col[1] < RE_EMPTY_COLOUR_FLOAT) col[1] = 0.0; - if(col[2] < RE_EMPTY_COLOUR_FLOAT) col[2] = 0.0; - if(col[3] < RE_EMPTY_COLOUR_FLOAT) col[3] = 0.0; - -} - -/* ------------------------------------------------------------------------- */ - -void spotHaloFloat(struct LampRen *lar, float *view, float *intens) -{ - double a, b, c, disc, nray[3], npos[3]; - float t0, t1 = 0.0, t2= 0.0, t3, haint; - float p1[3], p2[3], ladist, maxz = 0.0, maxy = 0.0; - int snijp, doclip=1, use_yco=0; - int ok1=0, ok2=0; - - *intens= 0.0; - haint= lar->haint; - - VECCOPY(npos, lar->sh_invcampos); /* calculated in initlamp */ - - /* rotate view */ - VECCOPY(nray, view); - MTC_Mat3MulVecd(lar->imat, nray); - - if(R.wrld.mode & WO_MIST) { - /* a bit patchy... */ - R.zcor= -lar->co[2]; - haint *= mistfactor(lar->co); - if(haint==0.0) { - return; - } - } - - - /* rotate maxz */ - if(R.co[2]==0) doclip= 0; /* for when halo over a sky */ - else { - p1[0]= R.co[0]-lar->co[0]; - p1[1]= R.co[1]-lar->co[1]; - p1[2]= R.co[2]-lar->co[2]; - - maxz= lar->imat[0][2]*p1[0]+lar->imat[1][2]*p1[1]+lar->imat[2][2]*p1[2]; - maxz*= lar->sh_zfac; - maxy= lar->imat[0][1]*p1[0]+lar->imat[1][1]*p1[1]+lar->imat[2][1]*p1[2]; - - if( fabs(nray[2]) <0.000001 ) use_yco= 1; - } - - /* scale z to make sure we've got a normalized volume */ - nray[2]*= lar->sh_zfac; - /* nray does not need normalize */ - - ladist= lar->sh_zfac*lar->dist; - - /* solve */ - a = nray[0] * nray[0] + nray[1] * nray[1] - nray[2]*nray[2]; - b = nray[0] * npos[0] + nray[1] * npos[1] - nray[2]*npos[2]; - c = npos[0] * npos[0] + npos[1] * npos[1] - npos[2]*npos[2]; - - snijp= 0; - if (fabs(a) < 0.00000001) { - /* - * Only one intersection point... - */ - return; - } - else { - disc = b*b - a*c; - - if(disc==0.0) { - t1=t2= (-b)/ a; - snijp= 2; - } - else if (disc > 0.0) { - disc = sqrt(disc); - t1 = (-b + disc) / a; - t2 = (-b - disc) / a; - snijp= 2; - } - } - if(snijp==2) { - /* sort */ - if(t1>t2) { - a= t1; t1= t2; t2= a; - } - - /* the z of intersection points with 'diabolo' shape */ - p1[2]= npos[2] + t1*nray[2]; - p2[2]= npos[2] + t2*nray[2]; - - /* evaluate both points */ - if(p1[2]<=0.0) ok1= 1; - if(p2[2]<=0.0 && t1!=t2) ok2= 1; - - /* at least 1 point with negative z */ - if(ok1==0 && ok2==0) return; - - /* intersction point with -ladist, the bottom of the cone */ - if(use_yco==0) { - t3= (-ladist-npos[2])/nray[2]; - - /* does one intersection point has to be replaced? */ - if(ok1) { - if(p1[2]<-ladist) t1= t3; - } - else { - ok1= 1; - t1= t3; - } - if(ok2) { - if(p2[2]<-ladist) t2= t3; - } - else { - ok2= 1; - t2= t3; - } - } - else if(ok1==0 || ok2==0) return; - - /* at least 1 visible intersection point */ - if(t1<0.0 && t2<0.0) return; - - if(t1<0.0) t1= 0.0; - if(t2<0.0) t2= 0.0; - - if(t1==t2) return; - - /* to be sure, sort again */ - if(t1>t2) { - a= t1; t1= t2; t2= a; - } - - /* calculate t0: is de maximal visible z (for when halo was intersected with face */ - if(doclip) { - if(use_yco==0) t0= (maxz-npos[2])/nray[2]; - else t0= (maxy-npos[1])/nray[1]; - - if(t0shb && lar->shb->shadhalostep) { - /* from shadbuf.c, returns float */ - *intens *= shadow_halo(lar, p1, p2); - } - /* this was a test, for textured halos! unfortunately i could not get transformations right... (ton) */ - /* if(lar->mode & LA_TEXTURE) do_lamphalo_tex(lar, p1, p2, intens); */ - - } -} /* end of void spotHaloFloat(struct LampRen *, float *view, float *intens) */ - -/* ------------------------------------------------------------------------- */ - -void shadeLampLusFloat() -{ - LampRen *lar; - register Material *ma; - float i, inp, inpr, t, lv[3], lampdist, ld = 0; - float ir, ig, ib; - float isr=0,isg=0,isb=0; - float lvrot[3], *vn, *view, shadfac, soft; - int a; - float shadfacvec[3] = {1.0, 1.0, 1.0}; - - vn= R.vn; - view= R.view; - ma= R.matren; - - /* separate loop */ - if(ma->mode & MA_ONLYSHADOW) { - shadfac= ir= 0.0; - for(a=0; amode & LA_LAYER) if((lar->lay & R.vlr->lay)==0) continue; - - if(lar->shb) { - /* only test within spotbundle */ - lv[0]= R.co[0]-lar->co[0]; - lv[1]= R.co[1]-lar->co[1]; - lv[2]= R.co[2]-lar->co[2]; - Normalise(lv); - inpr= lv[0]*lar->vec[0]+lv[1]*lar->vec[1]+lv[2]*lar->vec[2]; - if(inpr>lar->spotsi) { - - inp= vn[0]*lv[0] + vn[1]*lv[1] + vn[2]*lv[2]; - - RE_testshadowbuf(lar->shadowBufOb, lar->shb, inp, shadfacvec); -/* testshadowbuf(lar->shb, inp, shadfacvec); */ - - i= shadfacvec[0]; - - t= inpr - lar->spotsi; - if(tspotbl && lar->spotbl!=0.0) { - t/= lar->spotbl; - t*= t; - i= t*i+(1.0-t); - } - - shadfac+= i; - ir+= 1.0; - } - else { - shadfac+= 1.0; - ir+= 1.0; - } - } - } - if(ir>0.0) shadfac/= ir; - ma->alpha= (R.mat->alpha)*(1.0-shadfac); - - collector[0] = 0.0; - collector[1] = 0.0; - collector[2] = 0.0; - /* alpha is not set.... why?*/ - return; - } - - if(ma->mode & (MA_VERTEXCOLP|MA_FACETEXTURE)) { - ma->r= R.vcol[0]; - ma->g= R.vcol[1]; - ma->b= R.vcol[2]; - } - - /* mirror reflection colour */ - R.refcol[0]= R.refcol[1]= R.refcol[2]= R.refcol[3]= 0.0; - - if(ma->texco) { - - if(ma->texco & TEXCO_REFL) { - RE_calc_R_ref(); - } - - if(ma->mode & (MA_VERTEXCOLP|MA_FACETEXTURE)) { - R.mat->r= R.vcol[0]; - R.mat->g= R.vcol[1]; - R.mat->b= R.vcol[2]; - } - - do_material_tex(); - } - - if(ma->mode & MA_SHLESS) { - ir= ma->r; /* apparently stored as [0,1]? */ - ig= ma->g; - ib= ma->b; - - collector[0] = ir; /* no clipping, no alpha */ - collector[1] = ig; - collector[2] = ib; - return; - } - - if( (ma->mode & (MA_VERTEXCOL+MA_VERTEXCOLP))== MA_VERTEXCOL ) { - ir= ma->emit+R.vcol[0]; - ig= ma->emit+R.vcol[1]; - ib= ma->emit+R.vcol[2]; - } - else ir= ig= ib= ma->emit; - - for(a=0; amode & LA_LAYER) if((lar->lay & R.vlr->lay)==0) continue; - - /* lampdist calculation */ - if(lar->type==LA_SUN || lar->type==LA_HEMI) { - VECCOPY(lv, lar->vec); - lampdist= 1.0; - } - else { - lv[0]= R.co[0]-lar->co[0]; - lv[1]= R.co[1]-lar->co[1]; - lv[2]= R.co[2]-lar->co[2]; - ld= sqrt(lv[0]*lv[0]+lv[1]*lv[1]+lv[2]*lv[2]); - lv[0]/= ld; - lv[1]/= ld; - lv[2]/= ld; - - /* ld is used further on too (texco's) */ - - if(lar->mode & LA_QUAD) { - t= 1.0; - if(lar->ld1>0.0) - t= lar->dist/(lar->dist+lar->ld1*ld); - if(lar->ld2>0.0) - t*= lar->distkw/(lar->distkw+lar->ld2*ld*ld); - - lampdist= t; - } - else { - lampdist= (lar->dist/(lar->dist+ld)); - } - - if(lar->mode & LA_SPHERE) { - t= lar->dist - ld; - if(t<0.0) continue; - - t/= lar->dist; - lampdist*= (t); - } - - } - - if(lar->mode & LA_TEXTURE) do_lamp_tex(lar, lv); - - if(lar->type==LA_SPOT) { - - /* using here a function call Inp() slows down! */ - - if(lar->mode & LA_SQUARE) { - if(lv[0]*lar->vec[0]+lv[1]*lar->vec[1]+lv[2]*lar->vec[2]>0.0) { - float x; - - /* rotate view to lampspace */ - VECCOPY(lvrot, lv); - MTC_Mat3MulVecfl(lar->imat, lvrot); - - x= MAX2(fabs(lvrot[0]/lvrot[2]) , fabs(lvrot[1]/lvrot[2])); - /* 1.0/(sqrt(1+x*x)) is equivalent to cos(atan(x)) */ - - inpr= 1.0/(sqrt(1+x*x)); - } - else inpr= 0.0; - } - else { - inpr= lv[0]*lar->vec[0]+lv[1]*lar->vec[1]+lv[2]*lar->vec[2]; - } - - t= lar->spotsi; - if(inprspotbl && lar->spotbl!=0.0) { - /* soft area */ - i= t/lar->spotbl; - t= i*i; - soft= (3.0*t-2.0*t*i); - inpr*= soft; - } - if(lar->mode & LA_ONLYSHADOW && lar->shb) { - if(ma->mode & MA_SHADOW) { - /* dot product positive: front side face! */ - inp= vn[0]*lv[0] + vn[1]*lv[1] + vn[2]*lv[2]; - if(inp>0.0) { - - /* testshadowbuf==0.0 : 100% shadow */ - RE_testshadowbuf(lar->shadowBufOb, lar->shb, inp, shadfacvec); - shadfac = 1.0 - shadfacvec[0]; - - if(shadfac>0.0) { - shadfac*= inp*soft*lar->energy; - ir -= shadfac; - ig -= shadfac; - ib -= shadfac; - - continue; - } - } - } - } - lampdist*=inpr; - } - if(lar->mode & LA_ONLYSHADOW) continue; - - if(lar->mode & LA_OSATEX) { - R.osatex= 1; /* signal for multitex() */ - - O.dxlv[0]= lv[0] - (R.co[0]-lar->co[0]+O.dxco[0])/ld; - O.dxlv[1]= lv[1] - (R.co[1]-lar->co[1]+O.dxco[1])/ld; - O.dxlv[2]= lv[2] - (R.co[2]-lar->co[2]+O.dxco[2])/ld; - - O.dylv[0]= lv[0] - (R.co[0]-lar->co[0]+O.dyco[0])/ld; - O.dylv[1]= lv[1] - (R.co[1]-lar->co[1]+O.dyco[1])/ld; - O.dylv[2]= lv[2] - (R.co[2]-lar->co[2]+O.dyco[2])/ld; - } - - } - - /* dot product and reflectivity*/ - inp=i= vn[0]*lv[0] + vn[1]*lv[1] + vn[2]*lv[2]; - - if(lar->mode & LA_NO_DIFF) { - i= 0.0; // skip shaders - } - else if(lar->type==LA_HEMI) { - i= 0.5*i+0.5; - } - else { - /* diffuse shaders */ - if(ma->diff_shader==MA_DIFF_ORENNAYAR) i= OrenNayar_Diff(vn, lv, view, ma->roughness); - else if(ma->diff_shader==MA_DIFF_TOON) i= Toon_Diff(vn, lv, view, ma->param[0], ma->param[1]); - else i= inp; // Lambert - } - if(i>0.0) { - i*= lampdist*ma->ref; - } - - /* shadow and spec */ - if(i> -0.41) { /* heuristic value... :) */ - shadfac= 1.0; - if(lar->shb) { - if(ma->mode & MA_SHADOW) { - float shadfacvec[3] = {1.0, 1.0, 1.0}; - RE_testshadowbuf(lar->shadowBufOb, lar->shb, inp, shadfacvec); - shadfac = shadfacvec[0]; - -/* shadfac = 1.0; : no shadow */ - if(shadfac==0.0) continue; - i*= shadfac; - } - } - /* specularity */ - - if(ma->spec!=0.0 && !(lar->mode & LA_NO_SPEC)) { - - if(lar->type==LA_HEMI) { - /* hemi uses no spec shaders (yet) */ - - lv[0]+= view[0]; - lv[1]+= view[1]; - lv[2]+= view[2]; - - Normalise(lv); - - t= vn[0]*lv[0]+vn[1]*lv[1]+vn[2]*lv[2]; - - if(lar->type==LA_HEMI) { - t= 0.5*t+0.5; - } - - t= ma->spec*spec(t, ma->har); - isr+= t*(lar->r * ma->specr); - isg+= t*(lar->g * ma->specg); - isb+= t*(lar->b * ma->specb); - } - else { - /* specular shaders */ - float specfac; - - /* we force a different lamp vector for sun light */ - if(lar->type==LA_SUN) lv[2]-= 1.0; - - if(ma->spec_shader==MA_SPEC_PHONG) - specfac= Phong_Spec(vn, lv, view, ma->har); - else if(ma->spec_shader==MA_SPEC_COOKTORR) - specfac= CookTorr_Spec(vn, lv, view, ma->har); - else if(ma->spec_shader==MA_SPEC_BLINN) - specfac= Blinn_Spec(vn, lv, view, ma->refrac, (float)ma->har); - else - specfac= Toon_Spec(vn, lv, view, ma->param[2], ma->param[3]); - - t= shadfac*ma->spec*lampdist*specfac; - - isr+= t*(lar->r * ma->specr); - isg+= t*(lar->g * ma->specg); - isb+= t*(lar->b * ma->specb); - } - } - } - - if(i>0.0 && !(lar->mode & LA_NO_DIFF)) { - ir+= i*lar->r; - ig+= i*lar->g; - ib+= i*lar->b; - } - } - - /* clipping: maybe don't clip? (nzc) */ - /* yes, it shouldn't be done... unfortunately the current - * gammaCorrect implementation doesn't handle negative values - * correctly ( (-1)^2 = 1!!) (ton) - */ - /* Well, it does now. -(1^2) = -1 :) (nzc) */ - - if(ma->mode & MA_ZTRA) { /* ztra shade */ - if(ma->spectra!=0.0) { - - t = MAX3(isr, isb, isg); - t *= ma->spectra; - if(t>1.0) t= 1.0; - if(ma->mapto & MAP_ALPHA) ma->alpha= (1.0-t)*ma->alpha+t; - else ma->alpha= (1.0-t)*R.mat->alpha+t; - } - } - - if(R.refcol[0]==0.0) { - collector[0] = (ma->r * ir) + ma->ambr + isr; - collector[1] = (ma->g * ig) + ma->ambg + isg; - collector[2] = (ma->b * ib) + ma->ambb + isb; - /* clip for >0 ? */ - } - else { - collector[0] = (ma->mirr * R.refcol[1]) - + ((1.0 - (ma->mirr * R.refcol[0])) * ((ma->r * ir) + ma->ambr)) - + isr; - collector[1] = (ma->mirg*R.refcol[2]) - + ((1.0 - (ma->mirg * R.refcol[0])) * ((ma->g * ig) +ma->ambg)) - +isg; - collector[2] = (ma->mirb*R.refcol[3]) - + ((1.0 - (ma->mirb * R.refcol[0])) * ((ma->b * ib) +ma->ambb)) - +isb; - } - -} - -/* ------------------------------------------------------------------------- */ - -void* renderHaloPixel(float x, float y, int haloNr) { HaloRen *har = NULL; float dist = 0.0; unsigned int zz = 0; @@ -1478,96 +359,6 @@ void shadeHaloFloat(HaloRen *har, } /* end of shadeHaloFloat() */ -/* ------------------------------------------------------------------------- */ - -void renderSpotHaloPixel(float x, float y, float* target) -{ - float u = 0.0, v = 0.0; - - /* this needs to be cleared */ - target[0]= target[1]= target[2]= target[3]= 0.0; - - /* Strange fix? otherwise done inside shadepixel. It's sort */ - /* of like telling this is a 'sky' pixel. */ - R.vlaknr = 0; - target[3] = 0.0; - - /* - Here's the viewvector setting again. - */ - R.view[0]= (x+(R.xstart)+1.0); - - if(R.flag & R_SEC_FIELD) { - if(R.r.mode & R_ODDFIELD) R.view[1]= (y+R.ystart+0.5)*R.ycor; - else R.view[1]= (y+R.ystart+1.5)*R.ycor; - } - else R.view[1]= (y+R.ystart+1.0)*R.ycor; - - R.view[2]= -R.viewfac; - - if(R.r.mode & R_PANORAMA) { - float panoco, panosi; - panoco = getPanovCo(); - panosi = getPanovSi(); - u= R.view[0]; v= R.view[2]; - - R.view[0]= panoco*u + panosi*v; - R.view[2]= -panosi*u + panoco*v; - } - - R.co[2]= 0.0; - - /* This little function is a patch for spothalos on non-covered pixels. */ - renderspothaloFix(target); - -} /* end of void renderSpotHaloPixel(float x, float y, float colbuf[4]) */ - -/* ------------------------------------------------------------------------- */ -/* - This routine is only for sky-pixels. Therefore, no gamma needs to be done. - One strange side-effect is when you have a negative halo lamp. This suddenly - gives loads of colour. That particular case has been explicitly guarded: no - halo for negative halo spots! - - This routine uses the viewvector in R... to determine what to shade. Just - deposit the colour to be blended in col. - - I would like to add colours 'normally', so this routine would be the same - for spothalo on covered pixels, but that doesn't work. Some strange clipping - occurs... - */ -void renderspothaloFix(float *col) -{ - LampRen *lar; - float i; - int a; - - for(a=0; atype==LA_SPOT) - && (lar->mode & LA_HALO) - && !(lar->mode & LA_NEG) - && (lar->haint>0)) { - - if(lar->org) { - lar->r= lar->org->r; - lar->g= lar->org->g; - lar->b= lar->org->b; - } - - /* returns the intensity in i */ - spotHaloFloat(lar, R.view, &i); - - if(i>0.0) { - /* Premul colours here! */ - col[0]+= i * lar->r; - col[1]+= i * lar->g; - col[2]+= i * lar->b; - col[3]+= i; - } - } - } -} /* ------------------------------------------------------------------------- */ /* @@ -1629,11 +420,15 @@ void renderSkyPixelFloat(float x, float y) } } + + /* Stuff the sky colour into the collector. */ -void shadeSkyPixel(float fx, float fy) { - +void shadeSkyPixel(float fx, float fy) +{ + float view[3]; + /* The rules for sky: 1. Draw an image, if a background image was provided. Stop @@ -1667,23 +462,23 @@ void shadeSkyPixel(float fx, float fy) { /* This one true because of the context of this routine */ /* if(rect[3] < 254) { */ if(R.wrld.skytype & WO_SKYPAPER) { - R.view[0]= (fx+(R.xstart))/(float)R.afmx; - R.view[1]= (fy+(R.ystart))/(float)R.afmy; - R.view[2]= 0.0; + view[0]= (fx+(R.xstart))/(float)R.afmx; + view[1]= (fy+(R.ystart))/(float)R.afmy; + view[2]= 0.0; } else { /* Wasn't this some pano stuff? */ - R.view[0]= (fx+(R.xstart)+1.0); + view[0]= (fx+(R.xstart)+1.0); if(R.flag & R_SEC_FIELD) { - if(R.r.mode & R_ODDFIELD) R.view[1]= (fy+R.ystart+0.5)*R.ycor; - else R.view[1]= (fy+R.ystart+1.5)*R.ycor; + if(R.r.mode & R_ODDFIELD) view[1]= (fy+R.ystart+0.5)*R.ycor; + else view[1]= (fy+R.ystart+1.5)*R.ycor; } - else R.view[1]= (fy+R.ystart+1.0)*R.ycor; + else view[1]= (fy+R.ystart+1.0)*R.ycor; - R.view[2]= -R.viewfac; + view[2]= -R.viewfac; - fac= Normalise(R.view); + fac= Normalise(view); if(R.wrld.skytype & WO_SKYTEX) { O.dxview= 1.0/fac; O.dyview= R.ycor/fac; @@ -1696,59 +491,58 @@ void shadeSkyPixel(float fx, float fy) { panoco = getPanovCo(); panosi = getPanovSi(); - u= R.view[0]; v= R.view[2]; + u= view[0]; v= view[2]; - R.view[0]= panoco*u + panosi*v; - R.view[2]= -panosi*u + panoco*v; + view[0]= panoco*u + panosi*v; + view[2]= -panosi*u + panoco*v; } /* get sky colour in the collector */ - shadeSkyPixelFloat(fy); + shadeSkyPixelFloat(fy, view); } } /* Only line number is important here. Result goes to collector[4] */ -void shadeSkyPixelFloat(float y) +void shadeSkyPixelFloat(float y, float *view) { - + float lo[3]; + /* Why is this setting forced? Seems silly to me. It is tested in the texture unit. */ R.wrld.skytype |= WO_ZENUP; /* Some view vector stuff. */ if(R.wrld.skytype & WO_SKYREAL) { - R.inprz= R.view[0]*R.grvec[0]+ R.view[1]*R.grvec[1]+ R.view[2]*R.grvec[2]; + R.inprz= view[0]*R.grvec[0]+ view[1]*R.grvec[1]+ view[2]*R.grvec[2]; if(R.inprz<0.0) R.wrld.skytype-= WO_ZENUP; R.inprz= fabs(R.inprz); } else if(R.wrld.skytype & WO_SKYPAPER) { - R.inprz= 0.5+ 0.5*R.view[1]; + R.inprz= 0.5+ 0.5*view[1]; } else { /* the fraction of how far we are above the bottom of the screen */ - R.inprz= fabs(0.5+ R.view[1]); + R.inprz= fabs(0.5+ view[1]); } /* Careful: SKYTEX and SKYBLEND are NOT mutually exclusive! If */ /* SKYBLEND is active, the texture and colour blend are added. */ if(R.wrld.skytype & WO_SKYTEX) { - VECCOPY(R.lo, R.view); + VECCOPY(lo, view); if(R.wrld.skytype & WO_SKYREAL) { - MTC_Mat3MulVecfl(R.imat, R.lo); + MTC_Mat3MulVecfl(R.imat, lo); - SWAP(float, R.lo[1], R.lo[2]); + SWAP(float, lo[1], lo[2]); } - R.osatex= 0; - /* sky texture? I wonder how this manages to work... */ /* Does this communicate with R.wrld.hor{rgb}? Yes. */ - do_sky_tex(); + do_sky_tex(lo); /* internally, T{rgb} are used for communicating colours in the */ /* texture pipe, externally, this particular routine uses the */ /* R.wrld.hor{rgb} thingies. */ diff --git a/source/blender/render/intern/source/ray.c b/source/blender/render/intern/source/ray.c index d2aecee5b27..04ca80171d5 100644 --- a/source/blender/render/intern/source/ray.c +++ b/source/blender/render/intern/source/ray.c @@ -40,7 +40,6 @@ #include "DNA_mesh_types.h" #include "BKE_utildefines.h" -#include "BKE_texture.h" #include "BLI_arithb.h" @@ -49,6 +48,7 @@ #include "rendercore.h" #include "pixelblending.h" #include "jitter.h" +#include "texture.h" #define OCRES 64 @@ -74,7 +74,7 @@ typedef struct Octree { typedef struct Isect { float start[3], end[3]; float labda, u, v; - struct VlakRen *vlr, *vlrcontr; + struct VlakRen *vlr, *vlrcontr, *vlrorig; short isect, mode; /* mode: DDA_SHADOW or DDA_MIRROR or DDA_SHADOW_TRA */ float ddalabda; float col[4]; /* RGBA for shadow_tra */ @@ -536,20 +536,20 @@ void makeoctree() /* ************ raytracer **************** */ /* only for self-intersecting test with current render face (where ray left) */ -static short intersection2(float r0, float r1, float r2, float rx1, float ry1, float rz1) +static short intersection2(VlakRen *vlr, float r0, float r1, float r2, float rx1, float ry1, float rz1) { VertRen *v1,*v2,*v3,*v4=NULL; float x0,x1,x2,t00,t01,t02,t10,t11,t12,t20,t21,t22; float m0, m1, m2, divdet, det, det1; float u1, v, u2; - v1= R.vlr->v1; - v2= R.vlr->v2; - if(R.vlr->v4) { - v3= R.vlr->v4; - v4= R.vlr->v3; + v1= vlr->v1; + v2= vlr->v2; + if(vlr->v4) { + v3= vlr->v4; + v4= vlr->v3; } - else v3= R.vlr->v3; + else v3= vlr->v3; t00= v3->co[0]-v1->co[0]; t01= v3->co[1]-v1->co[1]; @@ -726,23 +726,24 @@ static short intersection(Isect *is) if(is->vlrcontr && vlrisect); // optimizing, the tests below are not needed else if(is->labda< .1) { + VlakRen *vlr= is->vlrorig; short de= 0; - if(v1==R.vlr->v1 || v2==R.vlr->v1 || v3==R.vlr->v1 || v4==R.vlr->v1) de++; - if(v1==R.vlr->v2 || v2==R.vlr->v2 || v3==R.vlr->v2 || v4==R.vlr->v2) de++; - if(v1==R.vlr->v3 || v2==R.vlr->v3 || v3==R.vlr->v3 || v4==R.vlr->v3) de++; - if(R.vlr->v4) { - if(v1==R.vlr->v4 || v2==R.vlr->v4 || v3==R.vlr->v4 || v4==R.vlr->v4) de++; + if(v1==vlr->v1 || v2==vlr->v1 || v3==vlr->v1 || v4==vlr->v1) de++; + if(v1==vlr->v2 || v2==vlr->v2 || v3==vlr->v2 || v4==vlr->v2) de++; + if(v1==vlr->v3 || v2==vlr->v3 || v3==vlr->v3 || v4==vlr->v3) de++; + if(vlr->v4) { + if(v1==vlr->v4 || v2==vlr->v4 || v3==vlr->v4 || v4==vlr->v4) de++; } if(de) { - /* so there's a shared edge or vertex, let's intersect ray with R.vlr + /* so there's a shared edge or vertex, let's intersect ray with vlr itself, if that's true we can safely return 1, otherwise we assume the intersection is invalid, 0 */ if(is->vlrcontr==NULL) { - is->vlrcontr= R.vlr; - vlrisect= intersection2(r0, r1, r2, is->start[0], is->start[1], is->start[2]); + is->vlrcontr= vlr; + vlrisect= intersection2(vlr, r0, r1, r2, is->start[0], is->start[1], is->start[2]); } if(vlrisect) return 1; @@ -923,7 +924,7 @@ static short cliptest(float p, float q, float *u1, float *u2) } /* return 1: found valid intersection */ -/* starts with global R.vlr */ +/* starts with is->vlrorig */ static int d3dda(Isect *is) { Node *no; @@ -939,11 +940,11 @@ static int d3dda(Isect *is) /* do this before intersect calls */ raycount++; - R.vlr->raycount= raycount; + is->vlrorig->raycount= raycount; is->vlrcontr= NULL; /* to check shared edge */ /* only for shadow! */ - if(is->mode==DDA_SHADOW && g_oc.vlr_last!=NULL && g_oc.vlr_last!=R.vlr) { + if(is->mode==DDA_SHADOW && g_oc.vlr_last!=NULL && g_oc.vlr_last!=is->vlrorig) { is->vlr= g_oc.vlr_last; if(intersection(is)) return 1; } @@ -1148,227 +1149,76 @@ static int d3dda(Isect *is) return 0; } -/* for now; mostly a duplicate of shadepixel() itself... could be unified once */ -/* R.view has been set */ -static void shade_ray(Isect *is, int mask, ShadeResult *shr) -{ - VertRen *v1, *v2, *v3; - float n1[3], n2[3], n3[3]; - float *o1, *o2, *o3; - float u, v, l; - int flip= 0; - char p1, p2, p3; - - R.co[0]= is->start[0]+is->labda*(is->end[0]-is->start[0]); - R.co[1]= is->start[1]+is->labda*(is->end[1]-is->start[1]); - R.co[2]= is->start[2]+is->labda*(is->end[2]-is->start[2]); - - R.vlaknr= -1; // signal to reset static variables in rendercore.c shadepixel - R.vlr= is->vlr; - R.mat= R.vlr->mat; - R.matren= R.mat->ren; - R.osatex= (R.matren->texco & TEXCO_OSA); +static void shade_ray(Isect *is, ShadeInput *shi, ShadeResult *shr, int mask) +{ + VlakRen *vlr= is->vlr; + int flip= 0; + + /* set up view vector */ + VecSubf(shi->view, is->end, is->start); + + /* render co */ + shi->co[0]= is->start[0]+is->labda*(shi->view[0]); + shi->co[1]= is->start[1]+is->labda*(shi->view[1]); + shi->co[2]= is->start[2]+is->labda*(shi->view[2]); + + Normalise(shi->view); + + shi->vlr= vlr; + shi->mat= vlr->mat; + shi->matren= shi->mat->ren; /* face normal, check for flip */ - R.vno= R.vlr->n; - if((R.matren->mode & MA_RAYTRANSP)==0) { - l= R.vlr->n[0]*R.view[0]+R.vlr->n[1]*R.view[1]+R.vlr->n[2]*R.view[2]; + if((shi->matren->mode & MA_RAYTRANSP)==0) { + float l= vlr->n[0]*shi->view[0]+vlr->n[1]*shi->view[1]+vlr->n[2]*shi->view[2]; if(l<0.0) { flip= 1; - R.vlr->n[0]= -R.vlr->n[0]; - R.vlr->n[1]= -R.vlr->n[1]; - R.vlr->n[2]= -R.vlr->n[2]; - R.vlr->puno= ~(R.vlr->puno); + vlr->n[0]= -vlr->n[0]; + vlr->n[1]= -vlr->n[1]; + vlr->n[2]= -vlr->n[2]; + vlr->puno= ~(vlr->puno); } } - if(R.vlr->v4) { - if(is->isect==2) { - v1= R.vlr->v3; - p1= ME_FLIPV3; - } else { - v1= R.vlr->v1; - p1= ME_FLIPV1; - } - v2= R.vlr->v2; - v3= R.vlr->v4; - p2= ME_FLIPV2; p3= ME_FLIPV4; - } - else { - v1= R.vlr->v1; - v2= R.vlr->v2; - v3= R.vlr->v3; - p1= ME_FLIPV1; p2= ME_FLIPV2; p3= ME_FLIPV3; - } - - if(R.vlr->flag & R_SMOOTH) { /* adjust punos (vertexnormals) */ - if(R.vlr->puno & p1) { - n1[0]= -v1->n[0]; n1[1]= -v1->n[1]; n1[2]= -v1->n[2]; - } else { - n1[0]= v1->n[0]; n1[1]= v1->n[1]; n1[2]= v1->n[2]; - } - if(R.vlr->puno & p2) { - n2[0]= -v2->n[0]; n2[1]= -v2->n[1]; n2[2]= -v2->n[2]; - } else { - n2[0]= v2->n[0]; n2[1]= v2->n[1]; n2[2]= v2->n[2]; - } - - if(R.vlr->puno & p3) { - n3[0]= -v3->n[0]; n3[1]= -v3->n[1]; n3[2]= -v3->n[2]; - } else { - n3[0]= v3->n[0]; n3[1]= v3->n[1]; n3[2]= v3->n[2]; - } - } - - u= is->u; - v= is->v; - // Osa structs we leave unchanged now + shi->osatex= 0; - - /* UV and TEX*/ - if( (R.vlr->flag & R_SMOOTH) || (R.matren->texco & NEED_UV)) { - - l= 1.0+u+v; - - if(R.vlr->flag & R_SMOOTH) { - R.vn[0]= l*n3[0]-u*n1[0]-v*n2[0]; - R.vn[1]= l*n3[1]-u*n1[1]-v*n2[1]; - R.vn[2]= l*n3[2]-u*n1[2]-v*n2[2]; - - Normalise(R.vn); - } - else { - VECCOPY(R.vn, R.vlr->n); - } - - if(R.matren->texco & TEXCO_ORCO) { - if(v2->orco) { - o1= v1->orco; - o2= v2->orco; - o3= v3->orco; - - R.lo[0]= l*o3[0]-u*o1[0]-v*o2[0]; - R.lo[1]= l*o3[1]-u*o1[1]-v*o2[1]; - R.lo[2]= l*o3[2]-u*o1[2]-v*o2[2]; - - } - } - - if(R.matren->texco & TEXCO_GLOB) { - VECCOPY(R.gl, R.co); - Mat4MulVecfl(R.viewinv, R.gl); - } - if(R.matren->texco & TEXCO_NORM) { - R.orn[0]= R.vn[0]; - R.orn[1]= -R.vn[1]; - R.orn[2]= R.vn[2]; - } - - if((R.matren->texco & TEXCO_UV) || (R.matren->mode & (MA_VERTEXCOL|MA_FACETEXTURE))) { - if(R.vlr->tface) { - float *uv1, *uv2, *uv3; - - if( R.vlr->v4 || (R.vlr->flag & R_FACE_SPLIT) ) { - if(is->isect==2) uv1= R.vlr->tface->uv[2]; - else uv1= R.vlr->tface->uv[0]; - uv2= R.vlr->tface->uv[1]; - uv3= R.vlr->tface->uv[3]; - } - else { - uv1= R.vlr->tface->uv[0]; - uv2= R.vlr->tface->uv[1]; - uv3= R.vlr->tface->uv[2]; - } - - R.uv[0]= -1.0 + 2.0*(l*uv3[0]-u*uv1[0]-v*uv2[0]); - R.uv[1]= -1.0 + 2.0*(l*uv3[1]-u*uv1[1]-v*uv2[1]); - } - else { - R.uv[0]= 2.0*(u+.5); - R.uv[1]= 2.0*(v+.5); - } - } - - if(R.matren->mode & MA_VERTEXCOL) { - char *cp3, *cp2, *cp1= (char *)R.vlr->vcol; - if(cp1) { - if( R.vlr->v4 || (R.vlr->flag & R_FACE_SPLIT) ) { - if(is->isect==2) cp1= (char *)(R.vlr->vcol+2); - else cp1= (char *)(R.vlr->vcol+0); - - cp2= (char *)(R.vlr->vcol+1); - cp3= (char *)(R.vlr->vcol+3); - } - else { - cp1= (char *)(R.vlr->vcol+0); - cp2= (char *)(R.vlr->vcol+1); - cp3= (char *)(R.vlr->vcol+2); - } - R.vcol[0]= (l*cp3[3]-u*cp1[3]-v*cp2[3])/255.0; - R.vcol[1]= (l*cp3[2]-u*cp1[2]-v*cp2[2])/255.0; - R.vcol[2]= (l*cp3[1]-u*cp1[1]-v*cp2[1])/255.0; - - } - else { - R.vcol[0]= 0.0; - R.vcol[1]= 0.0; - R.vcol[2]= 0.0; - } - } - if(R.matren->mode & MA_RADIO) { - R.rad[0]= (l*v3->rad[0] - u*v1->rad[0] - v*v2->rad[0]); - R.rad[1]= (l*v3->rad[1] - u*v1->rad[1] - v*v2->rad[1]); - R.rad[2]= (l*v3->rad[2] - u*v1->rad[2] - v*v2->rad[2]); - } - else { - R.rad[0]= R.rad[1]= R.rad[2]= 0.0; - } - if(R.matren->mode & MA_FACETEXTURE) { - if((R.matren->mode & MA_VERTEXCOL)==0) { - R.vcol[0]= 1.0; - R.vcol[1]= 1.0; - R.vcol[2]= 1.0; - } - if(R.vlr->tface) render_realtime_texture(); - } - if(R.matren->texco & TEXCO_REFL) { - /* R.vn dot R.view */ - float i= -2.0*(R.vn[0]*R.view[0]+R.vn[1]*R.view[1]+R.vn[2]*R.view[2]); - - R.ref[0]= (R.view[0]+i*R.vn[0]); - R.ref[1]= (R.view[1]+i*R.vn[1]); - R.ref[2]= (R.view[2]+i*R.vn[2]); - } + if(vlr->v4) { + if(is->isect==2) + shade_input_set_coords(shi, is->u, is->v, 2, 1, 3); + else + shade_input_set_coords(shi, is->u, is->v, 0, 1, 3); } else { - VECCOPY(R.vn, R.vlr->n); + shade_input_set_coords(shi, is->u, is->v, 0, 1, 2); } + + shi->osatex= (shi->matren->texco & TEXCO_OSA); - if(is->mode==DDA_SHADOW_TRA) shade_color(shr); + if(is->mode==DDA_SHADOW_TRA) shade_color(shi, shr); else { - shade_lamp_loop(mask, shr); + shade_lamp_loop(shi, shr, mask); - if(R.matren->translucency!=0.0) { + if(shi->matren->translucency!=0.0) { ShadeResult shr_t; - VecMulf(R.vn, -1.0); - VecMulf(R.vlr->n, -1.0); - shade_lamp_loop(mask, &shr_t); - shr->diff[0]+= R.matren->translucency*shr_t.diff[0]; - shr->diff[1]+= R.matren->translucency*shr_t.diff[1]; - shr->diff[2]+= R.matren->translucency*shr_t.diff[2]; - VecMulf(R.vn, -1.0); - VecMulf(R.vlr->n, -1.0); + VecMulf(shi->vn, -1.0); + VecMulf(vlr->n, -1.0); + shade_lamp_loop(shi, &shr_t, mask); + shr->diff[0]+= shi->matren->translucency*shr_t.diff[0]; + shr->diff[1]+= shi->matren->translucency*shr_t.diff[1]; + shr->diff[2]+= shi->matren->translucency*shr_t.diff[2]; + VecMulf(shi->vn, -1.0); + VecMulf(vlr->n, -1.0); } } if(flip) { - R.vlr->n[0]= -R.vlr->n[0]; - R.vlr->n[1]= -R.vlr->n[1]; - R.vlr->n[2]= -R.vlr->n[2]; - R.vlr->puno= ~(R.vlr->puno); + vlr->n[0]= -vlr->n[0]; + vlr->n[1]= -vlr->n[1]; + vlr->n[2]= -vlr->n[2]; + vlr->puno= ~(vlr->puno); } } @@ -1398,7 +1248,7 @@ static void refraction(float *refract, float *n, float *view, float index) refract[2]= index*view[2] + fac*n[2]; } -static void calc_dx_dy_refract(float *ref, float *n, float *view, float index) +static void calc_dx_dy_refract(float *ref, float *n, float *view, float index, int smooth) { float dref[3], dview[3], dnor[3]; @@ -1408,7 +1258,7 @@ static void calc_dx_dy_refract(float *ref, float *n, float *view, float index) dview[1]= view[1]; dview[2]= view[2]; - if(R.vlr->flag & R_SMOOTH) { + if(smooth) { VecAddf(dnor, n, O.dxno); refraction(dref, dnor, dview, index); } @@ -1420,7 +1270,7 @@ static void calc_dx_dy_refract(float *ref, float *n, float *view, float index) dview[0]= view[0]; dview[1]= view[1]+ O.dyview; - if(R.vlr->flag & R_SMOOTH) { + if(smooth) { VecAddf(dnor, n, O.dyno); refraction(dref, dnor, dview, index); } @@ -1480,8 +1330,9 @@ static void color_combine(float *result, float fac1, float fac2, float *col1, fl } /* the main recursive tracer itself */ -static void traceray(short depth, float *start, float *vec, float *col, int mask) +static void traceray(short depth, float *start, float *vec, float *col, VlakRen *vlr, int mask) { + ShadeInput shi; ShadeResult shr; Isect isec; float f, f1, fr, fg, fb; @@ -1492,33 +1343,19 @@ static void traceray(short depth, float *start, float *vec, float *col, int mask isec.end[1]= start[1]+g_oc.ocsize*vec[1]; isec.end[2]= start[2]+g_oc.ocsize*vec[2]; isec.mode= DDA_MIRROR; - + isec.vlrorig= vlr; + if( d3dda(&isec) ) { - /* set up view vector */ - VECCOPY(R.view, vec); - Normalise(R.view); - - shade_ray(&isec, mask, &shr); + shade_ray(&isec, &shi, &shr, mask); if(depth>0) { - if(R.matren->mode & MA_RAYMIRROR) { - f= R.matren->ray_mirror; - if(f!=0.0) f*= fresnel_fac(R.view, R.vn, R.matren->fresnel_mir); - } - else f= 0.0; - - /* have to do it here, make local vars... */ - fr= R.matren->mirr; - fg= R.matren->mirg; - fb= R.matren->mirb; - - if(R.matren->mode & MA_RAYTRANSP && shr.alpha!=1.0) { + if(shi.matren->mode & MA_RAYTRANSP && shr.alpha!=1.0) { float f, f1, refract[3], tracol[3]; - refraction(refract, R.vn, R.view, R.matren->ang); - traceray(depth-1, R.co, refract, tracol, mask); + refraction(refract, shi.vn, shi.view, shi.matren->ang); + traceray(depth-1, shi.co, refract, tracol, shi.vlr, mask); f= shr.alpha; f1= 1.0-f; shr.diff[0]= f*shr.diff[0] + f1*tracol[0]; @@ -1527,10 +1364,16 @@ static void traceray(short depth, float *start, float *vec, float *col, int mask shr.alpha= 1.0; } + if(shi.matren->mode & MA_RAYMIRROR) { + f= shi.matren->ray_mirror; + if(f!=0.0) f*= fresnel_fac(shi.view, shi.vn, shi.matren->fresnel_mir); + } + else f= 0.0; + if(f!=0.0) { - reflection(ref, R.vn, R.view, NULL); - traceray(depth-1, R.co, ref, col, mask); + reflection(ref, shi.vn, shi.view, NULL); + traceray(depth-1, shi.co, ref, col, shi.vlr, mask); f1= 1.0-f; @@ -1540,10 +1383,12 @@ static void traceray(short depth, float *start, float *vec, float *col, int mask //col[1]+= shr.spec[1]; //col[2]+= shr.spec[2]; + fr= shi.matren->mirr; + fg= shi.matren->mirg; + fb= shi.matren->mirb; + col[0]= f*fr*(1.0-shr.spec[0])*col[0] + f1*shr.diff[0] + shr.spec[0]; - col[1]= f*fg*(1.0-shr.spec[1])*col[1] + f1*shr.diff[1] + shr.spec[1]; - col[2]= f*fb*(1.0-shr.spec[2])*col[2] + f1*shr.diff[2] + shr.spec[2]; } else { @@ -1562,10 +1407,10 @@ static void traceray(short depth, float *start, float *vec, float *col, int mask else { /* sky */ char skycol[4]; - VECCOPY(R.view, vec); - Normalise(R.view); + VECCOPY(shi.view, vec); + Normalise(shi.view); - RE_sky(skycol); + RE_sky(shi.view, skycol); col[0]= skycol[0]/255.0; col[1]= skycol[1]/255.0; @@ -1662,86 +1507,72 @@ static void *jitter_cube(int resol) /* extern call from render loop */ -void ray_trace(int mask, ShadeResult *shr) +void ray_trace(ShadeInput *shi, ShadeResult *shr, int mask) { VlakRen *vlr; float i, f, f1, fr, fg, fb, vec[3], mircol[3], tracol[3]; int do_tra, do_mir; - do_tra= ((R.matren->mode & MA_RAYTRANSP) && shr->alpha!=1.0); - do_mir= ((R.matren->mode & MA_RAYMIRROR) && R.matren->ray_mirror!=0.0); - vlr= R.vlr; + do_tra= ((shi->matren->mode & MA_RAYTRANSP) && shr->alpha!=1.0); + do_mir= ((shi->matren->mode & MA_RAYMIRROR) && shi->matren->ray_mirror!=0.0); + vlr= shi->vlr; if(R.r.mode & R_OSA) { - float accum[3], rco[3], ref[3], dxref[3], dyref[3]; + float accum[3], rco[3], ref[3]; float accur[3], refract[3], divr=0.0, div= 0.0; int j; - if(do_tra) calc_dx_dy_refract(refract, R.vn, R.view, R.matren->ang); - + if(do_tra) calc_dx_dy_refract(refract, shi->vn, shi->view, shi->matren->ang, vlr->flag & R_SMOOTH); + if(do_mir) { + if(vlr->flag & R_SMOOTH) + reflection(ref, shi->vn, shi->view, vlr->n); + else + reflection(ref, shi->vn, shi->view, NULL); + } + accum[0]= accum[1]= accum[2]= 0.0; accur[0]= accur[1]= accur[2]= 0.0; - /* store variables which change during tracing */ - VECCOPY(rco, R.co); - VECCOPY(ref, R.ref); - VECCOPY(dxref, O.dxref); - VECCOPY(dyref, O.dyref); - for(j=0; jco[0] + (jit[j][0]-0.5)*O.dxco[0] + (jit[j][1]-0.5)*O.dyco[0]; + rco[1]= shi->co[1] + (jit[j][0]-0.5)*O.dxco[1] + (jit[j][1]-0.5)*O.dyco[1]; + rco[2]= shi->co[2] + (jit[j][0]-0.5)*O.dxco[2] + (jit[j][1]-0.5)*O.dyco[2]; + } + if(do_tra) { vec[0]= refract[0] + (jit[j][0]-0.5)*O.dxrefract[0] + (jit[j][1]-0.5)*O.dyrefract[0] ; vec[1]= refract[1] + (jit[j][0]-0.5)*O.dxrefract[1] + (jit[j][1]-0.5)*O.dyrefract[1] ; vec[2]= refract[2] + (jit[j][0]-0.5)*O.dxrefract[2] + (jit[j][1]-0.5)*O.dyrefract[2] ; - R.co[0]+= (jit[j][0]-0.5)*O.dxco[0] + (jit[j][1]-0.5)*O.dyco[0] ; - R.co[1]+= (jit[j][0]-0.5)*O.dxco[1] + (jit[j][1]-0.5)*O.dyco[1] ; - R.co[2]+= (jit[j][0]-0.5)*O.dxco[2] + (jit[j][1]-0.5)*O.dyco[2] ; - - traceray(R.matren->ray_depth_tra, R.co, vec, tracol, mask); + traceray(shi->matren->ray_depth_tra, rco, vec, tracol, shi->vlr, mask); VecAddf(accur, accur, tracol); divr+= 1.0; - - /* restore */ - VECCOPY(R.co, rco); - R.vlr= vlr; - R.mat= vlr->mat; - R.matren= R.mat->ren; } if(do_mir) { - vec[0]= ref[0] + 2.0*(jit[j][0]-0.5)*dxref[0] + 2.0*(jit[j][1]-0.5)*dyref[0] ; - vec[1]= ref[1] + 2.0*(jit[j][0]-0.5)*dxref[1] + 2.0*(jit[j][1]-0.5)*dyref[1] ; - vec[2]= ref[2] + 2.0*(jit[j][0]-0.5)*dxref[2] + 2.0*(jit[j][1]-0.5)*dyref[2] ; + vec[0]= ref[0] + 2.0*(jit[j][0]-0.5)*O.dxref[0] + 2.0*(jit[j][1]-0.5)*O.dyref[0] ; + vec[1]= ref[1] + 2.0*(jit[j][0]-0.5)*O.dxref[1] + 2.0*(jit[j][1]-0.5)*O.dyref[1] ; + vec[2]= ref[2] + 2.0*(jit[j][0]-0.5)*O.dxref[2] + 2.0*(jit[j][1]-0.5)*O.dyref[2] ; /* prevent normal go to backside */ - i= vec[0]*R.vlr->n[0]+ vec[1]*R.vlr->n[1]+ vec[2]*R.vlr->n[2]; + i= vec[0]*vlr->n[0]+ vec[1]*vlr->n[1]+ vec[2]*vlr->n[2]; if(i>0.0) { i+= .01; - vec[0]-= i*R.vlr->n[0]; - vec[1]-= i*R.vlr->n[1]; - vec[2]-= i*R.vlr->n[2]; + vec[0]-= i*vlr->n[0]; + vec[1]-= i*vlr->n[1]; + vec[2]-= i*vlr->n[2]; } - R.co[0]+= (jit[j][0]-0.5)*O.dxco[0] + (jit[j][1]-0.5)*O.dyco[0] ; - R.co[1]+= (jit[j][0]-0.5)*O.dxco[1] + (jit[j][1]-0.5)*O.dyco[1] ; - R.co[2]+= (jit[j][0]-0.5)*O.dxco[2] + (jit[j][1]-0.5)*O.dyco[2] ; - /* we use a new mask here, only shadow uses it */ /* result in accum, this is copied to shade_lamp_loop */ - traceray(R.matren->ray_depth, R.co, vec, mircol, 1<matren->ray_depth, rco, vec, mircol, shi->vlr, 1<mat; - R.matren= R.mat->ren; } } } @@ -1755,10 +1586,10 @@ void ray_trace(int mask, ShadeResult *shr) } if(div!=0.0) { - i= R.matren->ray_mirror; - fr= R.matren->mirr; - fg= R.matren->mirg; - fb= R.matren->mirb; + i= shi->matren->ray_mirror; + fr= shi->matren->mirr; + fg= shi->matren->mirg; + fb= shi->matren->mirb; /* result */ f= i*fr*(1.0-shr->spec[0]); f1= 1.0-i; f/= div; @@ -1774,47 +1605,32 @@ void ray_trace(int mask, ShadeResult *shr) else { if(do_tra) { - float rvn[3], view[3], rco[3], ref[3], refract[3]; + float refract[3]; - /* store variables which change during tracing */ - VECCOPY(view, R.view); - VECCOPY(rco, R.co); - VECCOPY(rvn, R.vn); - VECCOPY(ref, R.ref); - - refraction(refract, R.vn, R.view, R.matren->ang); - traceray(R.matren->ray_depth_tra, R.co, refract, tracol, mask); + refraction(refract, shi->vn, shi->view, shi->matren->ang); + traceray(shi->matren->ray_depth_tra, shi->co, refract, tracol, shi->vlr, mask); f= shr->alpha; f1= 1.0-f; shr->diff[0]= f*shr->diff[0] + f1*tracol[0]; shr->diff[1]= f*shr->diff[1] + f1*tracol[1]; shr->diff[2]= f*shr->diff[2] + f1*tracol[2]; shr->alpha= 1.0; - - /* store variables which change during tracing */ - VECCOPY(R.view, view); - VECCOPY(R.co, rco); - VECCOPY(R.ref, ref); - VECCOPY(R.vn, rvn); - R.vlr= vlr; - R.mat= vlr->mat; - R.matren= R.mat->ren; } if(do_mir) { - i= R.matren->ray_mirror*fresnel_fac(R.view, R.vn, R.matren->fresnel_mir); + i= shi->matren->ray_mirror*fresnel_fac(shi->view, shi->vn, shi->matren->fresnel_mir); if(i!=0.0) { - fr= R.matren->mirr; - fg= R.matren->mirg; - fb= R.matren->mirb; + fr= shi->matren->mirr; + fg= shi->matren->mirg; + fb= shi->matren->mirb; - if(R.vlr->flag & R_SMOOTH) - reflection(vec, R.vn, R.view, R.vlr->n); + if(vlr->flag & R_SMOOTH) + reflection(vec, shi->vn, shi->view, vlr->n); else - reflection(vec, R.vn, R.view, NULL); + reflection(vec, shi->vn, shi->view, NULL); - traceray(R.matren->ray_depth, R.co, vec, mircol, mask); + traceray(shi->matren->ray_depth, shi->co, vec, mircol, shi->vlr, mask); f= i*fr*(1.0-shr->spec[0]); f1= 1.0-i; shr->diff[0]= f*mircol[0] + f1*shr->diff[0]; @@ -1843,72 +1659,111 @@ static void addAlphaLight(float *old, float *over) } -static int ray_trace_shadow_tra(Isect *isec, int depth) +static void ray_trace_shadow_tra(Isect *is, int depth) { /* ray to lamp, find first face that intersects, check alpha properties, if it has alpha<1 continue. exit when alpha is full */ + ShadeInput shi; ShadeResult shr; - - if( d3dda(isec)) { - VlakRen *vlr=NULL; - float col[4], rvn[3], view[3], rco[3], ref[3]; + + if( d3dda(is)) { + float col[4]; /* we got a face */ - /* store variables which change during tracing */ - if(depth==DEPTH_SHADOW_TRA) { - vlr= R.vlr; - VECCOPY(view, R.view); - VECCOPY(rco, R.co); - VECCOPY(rvn, R.vn); - VECCOPY(ref, R.ref); - } - - /* set up view vector */ - VecSubf(R.view, isec->end, isec->start); - Normalise(R.view); - - shade_ray(isec, 0, &shr); + shade_ray(is, &shi, &shr, 0); // mask not needed /* add color */ VECCOPY(col, shr.diff); col[3]= shr.alpha; - addAlphaLight(isec->col, col); + addAlphaLight(is->col, col); - if(depth>0 && isec->col[3]<1.0) { - VECCOPY(isec->start, R.co); - ray_trace_shadow_tra(isec, depth-1); + if(depth>0 && is->col[3]<1.0) { + + /* adapt isect struct */ + VECCOPY(is->start, shi.co); + is->vlrorig= shi.vlr; + + ray_trace_shadow_tra(is, depth-1); } - else if(isec->col[3]>1.0) isec->col[3]= 1.0; + else if(is->col[3]>1.0) is->col[3]= 1.0; - /* restore variables which change during tracing */ - if(depth==DEPTH_SHADOW_TRA) { - VECCOPY(R.view, view); - VECCOPY(R.co, rco); - VECCOPY(R.ref, ref); - VECCOPY(R.vn, rvn); - R.vlr= vlr; - R.mat= vlr->mat; - R.matren= R.mat->ren; - } } - return 0; } +int ray_trace_shadow_rad(ShadeInput *ship, ShadeResult *shr) +{ + static int counter=0, only_one= 0; + extern float hashvectf[]; + Isect isec; + ShadeInput shi; + ShadeResult shr_t; + float vec[3], accum[3], div= 0.0; + int a; + + if(only_one) { + return 0; + } + only_one= 1; + + accum[0]= accum[1]= accum[2]= 0.0; + isec.mode= DDA_MIRROR; + isec.vlrorig= ship->vlr; + + for(a=0; a<8*8; a++) { + + counter+=3; + counter %= 768; + VECCOPY(vec, hashvectf+counter); + if(ship->vn[0]*vec[0]+ship->vn[1]*vec[1]+ship->vn[2]*vec[2]>0.0) { + vec[0]-= vec[0]; + vec[1]-= vec[1]; + vec[2]-= vec[2]; + } + VECCOPY(isec.start, ship->co); + isec.end[0]= isec.start[0] + g_oc.ocsize*vec[0]; + isec.end[1]= isec.start[1] + g_oc.ocsize*vec[1]; + isec.end[2]= isec.start[2] + g_oc.ocsize*vec[2]; + + if( d3dda(&isec)) { + float fac; + shade_ray(&isec, &shi, &shr_t, 0); // mask not needed + fac= isec.labda*isec.labda; + fac= 1.0; + accum[0]+= fac*(shr_t.diff[0]+shr_t.spec[0]); + accum[1]+= fac*(shr_t.diff[1]+shr_t.spec[1]); + accum[2]+= fac*(shr_t.diff[2]+shr_t.spec[2]); + div+= fac; + } + else div+= 1.0; + } + + if(div!=0.0) { + shr->diff[0]+= accum[0]/div; + shr->diff[1]+= accum[1]/div; + shr->diff[2]+= accum[2]/div; + } + shr->alpha= 1.0; + + only_one= 0; + return 1; +} + + /* extern call from shade_lamp_loop */ -void ray_shadow(LampRen *lar, float *shadfac, int mask) +void ray_shadow(ShadeInput *shi, LampRen *lar, float *shadfac, int mask) { Isect isec; float fac, div=0.0, lampco[3]; - if(R.matren->mode & MA_SHADOW_TRA) isec.mode= DDA_SHADOW_TRA; + if(shi->matren->mode & MA_SHADOW_TRA) isec.mode= DDA_SHADOW_TRA; else isec.mode= DDA_SHADOW; shadfac[3]= 1.0; // 1=full light if(lar->type==LA_SUN || lar->type==LA_HEMI) { - lampco[0]= R.co[0] - g_oc.ocsize*lar->vec[0]; - lampco[1]= R.co[1] - g_oc.ocsize*lar->vec[1]; - lampco[2]= R.co[2] - g_oc.ocsize*lar->vec[2]; + lampco[0]= shi->co[0] - g_oc.ocsize*lar->vec[0]; + lampco[1]= shi->co[1] - g_oc.ocsize*lar->vec[1]; + lampco[2]= shi->co[2] - g_oc.ocsize*lar->vec[2]; } else { VECCOPY(lampco, lar->co); @@ -1923,10 +1778,13 @@ void ray_shadow(LampRen *lar, float *shadfac, int mask) for(j=0; jco[0] + (jit[j][0]-0.5)*O.dxco[0] + (jit[j][1]-0.5)*O.dyco[0] ; + isec.start[1]= shi->co[1] + (jit[j][0]-0.5)*O.dxco[1] + (jit[j][1]-0.5)*O.dyco[1] ; + isec.start[2]= shi->co[2] + (jit[j][0]-0.5)*O.dxco[2] + (jit[j][1]-0.5)*O.dyco[2] ; VECCOPY(isec.end, lampco); + isec.vlrorig= shi->vlr; + if(isec.mode==DDA_SHADOW_TRA) { isec.col[0]= isec.col[1]= isec.col[2]= 1.0; isec.col[3]= 0.0; //alpha @@ -1951,8 +1809,11 @@ void ray_shadow(LampRen *lar, float *shadfac, int mask) else shadfac[3]= 1.0-fac/div; } else { - VECCOPY(isec.start, R.co); + /* set up isec */ + VECCOPY(isec.start, shi->co); VECCOPY(isec.end, lampco); + isec.vlrorig= shi->vlr; + if(isec.mode==DDA_SHADOW_TRA) { isec.col[0]= isec.col[1]= isec.col[2]= 1.0; isec.col[3]= 0.0; //alpha @@ -1974,8 +1835,9 @@ void ray_shadow(LampRen *lar, float *shadfac, int mask) float vec[3]; int a, j=0; - VECCOPY(isec.start, R.co); - + VECCOPY(isec.start, shi->co); + isec.vlrorig= shi->vlr; + fac= 0.0; a= lar->ray_samp*lar->ray_samp; jitlamp= jitter_plane(lar->ray_samp); @@ -1992,9 +1854,9 @@ void ray_shadow(LampRen *lar, float *shadfac, int mask) isec.end[2]= lampco[2]+vec[2]; if(R.r.mode & R_OSA) { - isec.start[0]= R.co[0] + (jit[j][0]-0.5)*O.dxco[0] + (jit[j][1]-0.5)*O.dyco[0] ; - isec.start[1]= R.co[1] + (jit[j][0]-0.5)*O.dxco[1] + (jit[j][1]-0.5)*O.dyco[1] ; - isec.start[2]= R.co[2] + (jit[j][0]-0.5)*O.dxco[2] + (jit[j][1]-0.5)*O.dyco[2] ; + isec.start[0]= shi->co[0] + (jit[j][0]-0.5)*O.dxco[0] + (jit[j][1]-0.5)*O.dyco[0] ; + isec.start[1]= shi->co[1] + (jit[j][0]-0.5)*O.dxco[1] + (jit[j][1]-0.5)*O.dyco[1] ; + isec.start[2]= shi->co[2] + (jit[j][0]-0.5)*O.dxco[2] + (jit[j][1]-0.5)*O.dyco[2] ; j++; if(j>=R.osa) j= 0; } diff --git a/source/blender/render/intern/source/renderPreAndPost.c b/source/blender/render/intern/source/renderPreAndPost.c index fd33d054e64..e6a3465bc1b 100644 --- a/source/blender/render/intern/source/renderPreAndPost.c +++ b/source/blender/render/intern/source/renderPreAndPost.c @@ -42,7 +42,6 @@ #include "shadbuf.h" #include "envmap.h" #include "renderHelp.h" -#include "shadowBuffer.h" #include "radio.h" #ifdef HAVE_CONFIG_H @@ -67,17 +66,7 @@ void prepareScene() /* SHADOW BUFFER */ for(a=0; ashadowBufOb) { - RE_buildShadowBuffer(R.la[a]->shadowBufOb, - R.la[a]); - } - } else { - if(R.la[a]->shb) makeshadowbuf(R.la[a]); - } + if(R.la[a]->shb) makeshadowbuf(R.la[a]); } /* RADIO */ diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index 093da9b56b7..5342fef9934 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -59,6 +59,7 @@ #include "renderHelp.h" #include "jitter.h" +#include "texture.h" /* system includes */ #include @@ -79,12 +80,11 @@ RE_Render R; Osa O; -extern float Zjitx,Zjity, Zmulx, Zmuly; PixStrMain psmfirst; int psmteller; -float holoofs= 0.0, fmask[256], centLut[16]; -unsigned short usegamtab=0, shortcol[4], *mask1[9], *mask2[9], *igamtab1, *igamtab2, *gamtab; +float fmask[256], centLut[16]; +unsigned short usegamtab=0, *mask1[9], *mask2[9], *igamtab1, *igamtab2, *gamtab; char cmask[256], *centmask; /* functions */ @@ -163,9 +163,9 @@ float mistfactor(float *co) /* dist en height, return alpha */ return (1.0-fac)* (1-R.wrld.misi); } -void RE_sky(char *col) +void RE_sky(float *view, char *col) { - float rf, gf, bf; + float lo[3], rf, gf, bf; if((R.wrld.skytype & (WO_SKYBLEND+WO_SKYTEX))==0) { *( (unsigned int *)col)= R.wrld.fastcol; @@ -176,31 +176,29 @@ void RE_sky(char *col) if(R.wrld.skytype & WO_SKYREAL) { - R.inprz= R.view[0]*R.grvec[0]+ R.view[1]*R.grvec[1]+ R.view[2]*R.grvec[2]; + R.inprz= view[0]*R.grvec[0]+ view[1]*R.grvec[1]+ view[2]*R.grvec[2]; if(R.inprz<0.0) R.wrld.skytype-= WO_ZENUP; R.inprz= fabs(R.inprz); } else if(R.wrld.skytype & WO_SKYPAPER) { - R.inprz= 0.5+ 0.5*R.view[1]; + R.inprz= 0.5+ 0.5*view[1]; } else { - R.inprz= fabs(0.5+ R.view[1]); + R.inprz= fabs(0.5+ view[1]); } if(R.wrld.skytype & WO_SKYTEX) { - VECCOPY(R.lo, R.view); + VECCOPY(lo, view); if(R.wrld.skytype & WO_SKYREAL) { - MTC_Mat3MulVecfl(R.imat, R.lo); + MTC_Mat3MulVecfl(R.imat, lo); - SWAP(float, R.lo[1], R.lo[2]); + SWAP(float, lo[1], lo[2]); } - R.osatex= 0; - - do_sky_tex(); + do_sky_tex(lo); } @@ -235,12 +233,11 @@ void scanlinesky(char *rect, int y) * addalphaUnderGamma: ditto called with char *, uint* !!! * unmangle this shit... */ void (*alphafunc)(); - float fac; + float fac, u, v, view[3]; int dx, x, ofs; unsigned int col=0, *rt; short *sp; char *cp, *cp1; - float u, v; if(R.r.alphamode & R_ALPHAPREMUL) return; @@ -350,22 +347,22 @@ void scanlinesky(char *rect, int y) for(x=0; xsh_zfac; - - VecSubf(vec, p2, p1); - dist= Normalise(vec); - - /* fixed number of steps */ - dist/= (float)steps; - - for(a=0; ash_invcampos); /* in initlamp calculated */ /* rotate view */ - VECCOPY(nray, view); + VECCOPY(nray, shi->view); MTC_Mat3MulVecd(lar->imat, nray); if(R.wrld.mode & WO_MIST) { @@ -457,11 +419,11 @@ void spothalo(struct LampRen *lar, float *view, float *intens) /* rotate maxz */ - if(R.co[2]==0) doclip= 0; /* for when halo at sky */ + if(shi->co[2]==0) doclip= 0; /* for when halo at sky */ else { - p1[0]= R.co[0]-lar->co[0]; - p1[1]= R.co[1]-lar->co[1]; - p1[2]= R.co[2]-lar->co[2]; + p1[0]= shi->co[0]-lar->co[0]; + p1[1]= shi->co[1]-lar->co[1]; + p1[2]= shi->co[2]-lar->co[2]; maxz= lar->imat[0][2]*p1[0]+lar->imat[1][2]*p1[1]+lar->imat[2][2]*p1[2]; maxz*= lar->sh_zfac; @@ -601,18 +563,15 @@ void spothalo(struct LampRen *lar, float *view, float *intens) if(lar->shb && lar->shb->shadhalostep) { *intens *= shadow_halo(lar, p1, p2); } - /* if(lar->mode & LA_TEXTURE) do_lamphalo_tex(lar, p1, p2, intens); */ } } -void renderspothalo(unsigned short *col) +static void renderspothalo(ShadeInput *shi, float *col) { LampRen *lar; float i; - int colt, a; - unsigned short scol[4]; - + int a; for(a=0; ab= lar->org->b; } - spothalo(lar, R.view, &i); + spothalo(lar, shi, &i); if(i>0.0) { - - i*= 65536.0; - - colt= i; - if(colt>65535) scol[3]= 65535; else scol[3]= colt; - - /* really bad: gamma corrected rendering AND addalphaADD doesnt work together */ - /* actually we should invent a special add-gamma type */ - - colt= i*lar->r; - if(colt>65535) scol[0]= 65535; else scol[0]= colt; - if(usegamtab) scol[0]= igamtab2[scol[0]]; - colt= i*lar->g; - if(colt>65535) scol[1]= 65535; else scol[1]= colt; - if(usegamtab) scol[1]= igamtab2[scol[1]]; - colt= i*lar->b; - if(colt>65535) scol[2]= 65535; else scol[2]= colt; - if(usegamtab) scol[2]= igamtab2[scol[2]]; - - addalphaAddshort(col, scol); + col[3]+= i; + col[0]+= i*lar->r; + col[1]+= i*lar->g; + col[2]+= i*lar->b; } } } @@ -655,12 +598,12 @@ void renderspothalo(unsigned short *col) void render_lighting_halo(HaloRen *har, float *colf) { LampRen *lar; - float i, inp, inpr, lv[3], lampdist, ld, t, *vn; + float i, inp, inpr, rco[3], lv[3], lampdist, ld, t, *vn; float ir, ig, ib, shadfac, soft; int a; ir= ig= ib= 0.0; - VECCOPY(R.co, har->co); + VECCOPY(rco, har->co); vn= har->no; O.dxco[0]= har->hasize; @@ -683,9 +626,9 @@ void render_lighting_halo(HaloRen *har, float *colf) lampdist= 1.0; } else { - lv[0]= R.co[0]-lar->co[0]; - lv[1]= R.co[1]-lar->co[1]; - lv[2]= R.co[2]-lar->co[2]; + lv[0]= rco[0]-lar->co[0]; + lv[1]= rco[1]-lar->co[1]; + lv[2]= rco[2]-lar->co[2]; ld= sqrt(lv[0]*lv[0]+lv[1]*lv[1]+lv[2]*lv[2]); lv[0]/= ld; lv[1]/= ld; @@ -716,8 +659,13 @@ void render_lighting_halo(HaloRen *har, float *colf) } - if(lar->mode & LA_TEXTURE) do_lamp_tex(lar, lv); - + if(lar->mode & LA_TEXTURE) { + ShadeInput shi; + VECCOPY(shi.co, rco); + shi.osatex= 0; + do_lamp_tex(lar, lv, &shi); + } + if(lar->type==LA_SPOT) { if(lar->mode & LA_SQUARE) { @@ -758,7 +706,7 @@ void render_lighting_halo(HaloRen *har, float *colf) inp= vn[0]*lv[0] + vn[1]*lv[1] + vn[2]*lv[2]; if(inp>0.0) { /* testshadowbuf==0.0 : 100% shadow */ - shadfac = testshadowbuf(lar->shb, inp); + shadfac = testshadowbuf(lar->shb, rco, inp); if( shadfac>0.0 ) { shadfac*= inp*soft*lar->energy; ir -= shadfac; @@ -797,7 +745,7 @@ void render_lighting_halo(HaloRen *har, float *colf) shadfac= 1.0; if(lar->shb) { /* if(ma->mode & MA_SHADOW) { */ - shadfac = testshadowbuf(lar->shb, inp); + shadfac = testshadowbuf(lar->shb, rco, inp); if(shadfac==0.0) continue; i*= shadfac; /* } */ @@ -822,10 +770,10 @@ void render_lighting_halo(HaloRen *har, float *colf) } -extern float hashvectf[]; void RE_shadehalo(HaloRen *har, char *col, unsigned int zz, float dist, float xn, float yn, short flarec) { /* fill in in col */ + extern float hashvectf[]; float t, zn, radist, ringf=0.0, linef=0.0, alpha, si, co, colf[4]; int colt, a; @@ -1372,22 +1320,22 @@ float Blinn_Spec(float *n, float *l, float *v, float refrac, float spec_power ) h[2]= v[2]+l[2]; Normalise(h); - nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; /* Dot product between surface normal and half-way vector. */ + nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; /* Dot product between surface normal and half-way vector */ if(nh<0.0) return 0.0; - nv= n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; /* Dot product between surface normal and view vector. */ + nv= n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; /* Dot product between surface normal and view vector */ if(nv<=0.0) nv= 0.01; - nl= n[0]*l[0]+n[1]*l[1]+n[2]*l[2]; /* Dot product between surface normal and light vector. */ + nl= n[0]*l[0]+n[1]*l[1]+n[2]*l[2]; /* Dot product between surface normal and light vector */ if(nl<=0.0) { nl= 0.0; return 0.0; } - vh= v[0]*h[0]+v[1]*h[1]+v[2]*h[2]; /* Dot product between view vector and half-way vector. */ + vh= v[0]*h[0]+v[1]*h[1]+v[2]*h[2]; /* Dot product between view vector and half-way vector */ if(vh<=0.0) vh= 0.01; a = 1.0; @@ -1458,16 +1406,16 @@ float OrenNayar_Diff(float *n, float *l, float *v, float rough ) h[2]= v[2]+l[2]; Normalise(h); - nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; /* Dot product between surface normal and half-way vector. */ + nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; /* Dot product between surface normal and half-way vector */ if(nh<0.0) nh = 0.0; - nv= n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; /* Dot product between surface normal and view vector. */ + nv= n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; /* Dot product between surface normal and view vector */ if(nv<=0.0) nv= 0.0; - nl= n[0]*l[0]+n[1]*l[1]+n[2]*l[2]; /* Dot product between surface normal and light vector. */ + nl= n[0]*l[0]+n[1]*l[1]+n[2]*l[2]; /* Dot product between surface normal and light vector */ if(nl<0.0) nl= 0.0; - vh= v[0]*h[0]+v[1]*h[1]+v[2]*h[2]; /* Dot product between view vector and halfway vector. */ + vh= v[0]*h[0]+v[1]*h[1]+v[2]*h[2]; /* Dot product between view vector and halfway vector */ if(vh<=0.0) vh= 0.0; Lit_A = acos( nl ); @@ -1505,48 +1453,48 @@ float OrenNayar_Diff(float *n, float *l, float *v, float rough ) /* --------------------------------------------- */ -void RE_calc_R_ref() +void calc_R_ref(ShadeInput *shi) { float i; - /* R.vn dot R.view */ - i= -2*(R.vn[0]*R.view[0]+R.vn[1]*R.view[1]+R.vn[2]*R.view[2]); + /* shi->vn dot shi->view */ + i= -2*(shi->vn[0]*shi->view[0]+shi->vn[1]*shi->view[1]+shi->vn[2]*shi->view[2]); - R.ref[0]= (R.view[0]+i*R.vn[0]); - R.ref[1]= (R.view[1]+i*R.vn[1]); - R.ref[2]= (R.view[2]+i*R.vn[2]); - if(R.osatex) { - if(R.vlr->flag & R_SMOOTH) { - i= -2*( (R.vn[0]+O.dxno[0])*(R.view[0]+O.dxview) + - (R.vn[1]+O.dxno[1])*R.view[1]+ (R.vn[2]+O.dxno[2])*R.view[2] ); + shi->ref[0]= (shi->view[0]+i*shi->vn[0]); + shi->ref[1]= (shi->view[1]+i*shi->vn[1]); + shi->ref[2]= (shi->view[2]+i*shi->vn[2]); + if(shi->osatex) { + if(shi->vlr->flag & R_SMOOTH) { + i= -2*( (shi->vn[0]+O.dxno[0])*(shi->view[0]+O.dxview) + + (shi->vn[1]+O.dxno[1])*shi->view[1]+ (shi->vn[2]+O.dxno[2])*shi->view[2] ); - O.dxref[0]= R.ref[0]- ( R.view[0]+O.dxview+i*(R.vn[0]+O.dxno[0])); - O.dxref[1]= R.ref[1]- (R.view[1]+ i*(R.vn[1]+O.dxno[1])); - O.dxref[2]= R.ref[2]- (R.view[2]+ i*(R.vn[2]+O.dxno[2])); + O.dxref[0]= shi->ref[0]- ( shi->view[0]+O.dxview+i*(shi->vn[0]+O.dxno[0])); + O.dxref[1]= shi->ref[1]- (shi->view[1]+ i*(shi->vn[1]+O.dxno[1])); + O.dxref[2]= shi->ref[2]- (shi->view[2]+ i*(shi->vn[2]+O.dxno[2])); - i= -2*( (R.vn[0]+O.dyno[0])*R.view[0]+ - (R.vn[1]+O.dyno[1])*(R.view[1]+O.dyview)+ (R.vn[2]+O.dyno[2])*R.view[2] ); + i= -2*( (shi->vn[0]+O.dyno[0])*shi->view[0]+ + (shi->vn[1]+O.dyno[1])*(shi->view[1]+O.dyview)+ (shi->vn[2]+O.dyno[2])*shi->view[2] ); - O.dyref[0]= R.ref[0]- (R.view[0]+ i*(R.vn[0]+O.dyno[0])); - O.dyref[1]= R.ref[1]- (R.view[1]+O.dyview+i*(R.vn[1]+O.dyno[1])); - O.dyref[2]= R.ref[2]- (R.view[2]+ i*(R.vn[2]+O.dyno[2])); + O.dyref[0]= shi->ref[0]- (shi->view[0]+ i*(shi->vn[0]+O.dyno[0])); + O.dyref[1]= shi->ref[1]- (shi->view[1]+O.dyview+i*(shi->vn[1]+O.dyno[1])); + O.dyref[2]= shi->ref[2]- (shi->view[2]+ i*(shi->vn[2]+O.dyno[2])); } else { - i= -2*( R.vn[0]*(R.view[0]+O.dxview) + - R.vn[1]*R.view[1]+ R.vn[2]*R.view[2] ); + i= -2*( shi->vn[0]*(shi->view[0]+O.dxview) + + shi->vn[1]*shi->view[1]+ shi->vn[2]*shi->view[2] ); - O.dxref[0]= R.ref[0]- (R.view[0]+O.dxview+i*R.vn[0]); - O.dxref[1]= R.ref[1]- (R.view[1]+ i*R.vn[1]); - O.dxref[2]= R.ref[2]- (R.view[2]+ i*R.vn[2]); + O.dxref[0]= shi->ref[0]- (shi->view[0]+O.dxview+i*shi->vn[0]); + O.dxref[1]= shi->ref[1]- (shi->view[1]+ i*shi->vn[1]); + O.dxref[2]= shi->ref[2]- (shi->view[2]+ i*shi->vn[2]); - i= -2*( R.vn[0]*R.view[0]+ - R.vn[1]*(R.view[1]+O.dyview)+ R.vn[2]*R.view[2] ); + i= -2*( shi->vn[0]*shi->view[0]+ + shi->vn[1]*(shi->view[1]+O.dyview)+ shi->vn[2]*shi->view[2] ); - O.dyref[0]= R.ref[0]- (R.view[0]+ i*R.vn[0]); - O.dyref[1]= R.ref[1]- (R.view[1]+O.dyview+i*R.vn[1]); - O.dyref[2]= R.ref[2]- (R.view[2]+ i*R.vn[2]); + O.dyref[0]= shi->ref[0]- (shi->view[0]+ i*shi->vn[0]); + O.dyref[1]= shi->ref[1]- (shi->view[1]+O.dyview+i*shi->vn[1]); + O.dyref[2]= shi->ref[2]- (shi->view[2]+ i*shi->vn[2]); } } @@ -1554,7 +1502,7 @@ void RE_calc_R_ref() float fresnel_fac(float *view, float *vn, float ior) { - float t1, t2; + float rf, t1, t2; if(ior==1.0) return 1.0; @@ -1563,38 +1511,60 @@ float fresnel_fac(float *view, float *vn, float ior) else t1 = 1.0-t1; t2 = t1*t1; - - t2= ior + (1.0-ior)*t2*t2*t1; + t2= (ior + (1.0-ior)*t2*t2*t1); if(t2<0.0) return 0.0; else if(t2>1.0) return 1.0; return t2; } - -void shade_color(ShadeResult *shr) +#if 0 +/* correctness fresnel, schlick approx */ +float fresnel_fac1(float *view, float *vn, float ior) { - Material *ma= R.matren; + float rf, t1, t2; + + if(ior==1.0) return 1.0; + + rf = ((ior-1)/(ior+1)); + rf*= rf; + + t1= (view[0]*vn[0] + view[1]*vn[1] + view[2]*vn[2]); + if(t1>0.0) t1= 1.0-t1; + else t1 = 1.0+t1; + + t2 = t1*t1; + t2= (rf + (1.0-rf)*t2*t2*t1); + + if(t2<0.0) return 0.0; + else if(t2>1.0) return 1.0; + return t2; +} +#endif + +void shade_color(ShadeInput *shi, ShadeResult *shr) +{ + Material *ma= shi->matren; if(ma->mode & (MA_VERTEXCOLP|MA_FACETEXTURE)) { - ma->r= R.vcol[0]; - ma->g= R.vcol[1]; - ma->b= R.vcol[2]; + ma->r= shi->vcol[0]; + ma->g= shi->vcol[1]; + ma->b= shi->vcol[2]; } - ma->alpha= R.mat->alpha; // copy to render material, for fresnel and spectra + ma->alpha= shi->mat->alpha; // copy to render material, for fresnel and spectra if(ma->texco) { if(ma->mode & (MA_VERTEXCOLP|MA_FACETEXTURE)) { - R.mat->r= R.vcol[0]; - R.mat->g= R.vcol[1]; - R.mat->b= R.vcol[2]; + shi->mat->r= shi->vcol[0]; + shi->mat->g= shi->vcol[1]; + shi->mat->b= shi->vcol[2]; } - do_material_tex(); + do_material_tex(shi); } if(ma->mode & (MA_ZTRA|MA_RAYTRANSP)) { if(ma->fresnel_tra!=1.0) - ma->alpha*= fresnel_fac(R.view, R.vn, ma->fresnel_tra); + ma->alpha*= fresnel_fac(shi->view, shi->vn, ma->fresnel_tra); } shr->diff[0]= ma->r; @@ -1604,7 +1574,7 @@ void shade_color(ShadeResult *shr) } /* mask is used to define the amount of rays/samples */ -void shade_lamp_loop(int mask, ShadeResult *shr) +void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr, int mask) { LampRen *lar; Material *ma; @@ -1612,9 +1582,9 @@ void shade_lamp_loop(int mask, ShadeResult *shr) float lvrot[3], *vn, *view, shadfac[4], soft; // shadfac = rgba int a; - vn= R.vn; - view= R.view; - ma= R.matren; + vn= shi->vn; + view= shi->view; + ma= shi->matren; memset(shr, 0, sizeof(ShadeResult)); @@ -1626,20 +1596,20 @@ void shade_lamp_loop(int mask, ShadeResult *shr) for(a=0; amode & LA_LAYER) if((lar->lay & R.vlr->lay)==0) continue; + if(lar->mode & LA_LAYER) if((lar->lay & shi->vlr->lay)==0) continue; if(lar->shb) { /* only test within spotbundel */ - lv[0]= R.co[0]-lar->co[0]; - lv[1]= R.co[1]-lar->co[1]; - lv[2]= R.co[2]-lar->co[2]; + lv[0]= shi->co[0]-lar->co[0]; + lv[1]= shi->co[1]-lar->co[1]; + lv[2]= shi->co[2]-lar->co[2]; Normalise(lv); inpr= lv[0]*lar->vec[0]+lv[1]*lar->vec[1]+lv[2]*lar->vec[2]; if(inpr>lar->spotsi) { inp= vn[0]*lv[0] + vn[1]*lv[1] + vn[2]*lv[2]; - i = testshadowbuf(lar->shb, inp); + i = testshadowbuf(lar->shb, shi->co, inp); t= inpr - lar->spotsi; if(tspotbl && lar->spotbl!=0.0) { @@ -1658,26 +1628,29 @@ void shade_lamp_loop(int mask, ShadeResult *shr) } } if(ir>0.0) shadfac[3]/= ir; - shr->alpha= (R.mat->alpha)*(1.0-shadfac[3]); + shr->alpha= (shi->mat->alpha)*(1.0-shadfac[3]); return; } if(ma->mode & (MA_VERTEXCOLP|MA_FACETEXTURE)) { - ma->r= R.vcol[0]; - ma->g= R.vcol[1]; - ma->b= R.vcol[2]; + ma->r= shi->vcol[0]; + ma->g= shi->vcol[1]; + ma->b= shi->vcol[2]; } - ma->alpha= R.mat->alpha; // copy to render material, for fresnel and spectra + ma->alpha= shi->mat->alpha; // copy to render material, for fresnel and spectra + + /* envmap hack, always reset */ + shi->refcol[0]= shi->refcol[1]= shi->refcol[2]= shi->refcol[3]= 0.0; if(ma->texco) { if(ma->mode & (MA_VERTEXCOLP|MA_FACETEXTURE)) { - R.mat->r= R.vcol[0]; - R.mat->g= R.vcol[1]; - R.mat->b= R.vcol[2]; + shi->mat->r= shi->vcol[0]; + shi->mat->g= shi->vcol[1]; + shi->mat->b= shi->vcol[2]; } - do_material_tex(); + do_material_tex(shi); } if(ma->mode & MA_SHLESS) { @@ -1689,9 +1662,9 @@ void shade_lamp_loop(int mask, ShadeResult *shr) } if( (ma->mode & (MA_VERTEXCOL+MA_VERTEXCOLP))== MA_VERTEXCOL ) { - shr->diff[0]= ma->emit+R.vcol[0]; - shr->diff[1]= ma->emit+R.vcol[1]; - shr->diff[2]= ma->emit+R.vcol[2]; + shr->diff[0]= ma->emit+shi->vcol[0]; + shr->diff[1]= ma->emit+shi->vcol[1]; + shr->diff[2]= ma->emit+shi->vcol[2]; } else shr->diff[0]= shr->diff[1]= shr->diff[2]= ma->emit; @@ -1699,7 +1672,7 @@ void shade_lamp_loop(int mask, ShadeResult *shr) lar= R.la[a]; /* test for lamp layer */ - if(lar->mode & LA_LAYER) if((lar->lay & R.vlr->lay)==0) continue; + if(lar->mode & LA_LAYER) if((lar->lay & shi->vlr->lay)==0) continue; /* lampdist calculation */ if(lar->type==LA_SUN || lar->type==LA_HEMI) { @@ -1707,9 +1680,9 @@ void shade_lamp_loop(int mask, ShadeResult *shr) lampdist= 1.0; } else { - lv[0]= R.co[0]-lar->co[0]; - lv[1]= R.co[1]-lar->co[1]; - lv[2]= R.co[2]-lar->co[2]; + lv[0]= shi->co[0]-lar->co[0]; + lv[1]= shi->co[1]-lar->co[1]; + lv[2]= shi->co[2]-lar->co[2]; ld= sqrt(lv[0]*lv[0]+lv[1]*lv[1]+lv[2]*lv[2]); lv[0]/= ld; lv[1]/= ld; @@ -1740,7 +1713,7 @@ void shade_lamp_loop(int mask, ShadeResult *shr) } - if(lar->mode & LA_TEXTURE) do_lamp_tex(lar, lv); + if(lar->mode & LA_TEXTURE) do_lamp_tex(lar, lv, shi); /* init transp shadow */ shadfac[3]= 1.0; @@ -1786,7 +1759,7 @@ void shade_lamp_loop(int mask, ShadeResult *shr) inp= vn[0]*lv[0] + vn[1]*lv[1] + vn[2]*lv[2]; if(inp>0.0) { /* testshadowbuf==0.0 : 100% shadow */ - shadfac[3] = 1.0 - testshadowbuf(lar->shb, inp); + shadfac[3] = 1.0 - testshadowbuf(lar->shb, shi->co, inp); if(shadfac[3]>0.0) { shadfac[3]*= inp*soft*lar->energy; shr->diff[0] -= shadfac[3]; @@ -1803,15 +1776,15 @@ void shade_lamp_loop(int mask, ShadeResult *shr) if(lar->mode & LA_ONLYSHADOW) continue; if(lar->mode & LA_OSATEX) { - R.osatex= 1; /* signal for multitex() */ + shi->osatex= 1; /* signal for multitex() */ - O.dxlv[0]= lv[0] - (R.co[0]-lar->co[0]+O.dxco[0])/ld; - O.dxlv[1]= lv[1] - (R.co[1]-lar->co[1]+O.dxco[1])/ld; - O.dxlv[2]= lv[2] - (R.co[2]-lar->co[2]+O.dxco[2])/ld; + O.dxlv[0]= lv[0] - (shi->co[0]-lar->co[0]+O.dxco[0])/ld; + O.dxlv[1]= lv[1] - (shi->co[1]-lar->co[1]+O.dxco[1])/ld; + O.dxlv[2]= lv[2] - (shi->co[2]-lar->co[2]+O.dxco[2])/ld; - O.dylv[0]= lv[0] - (R.co[0]-lar->co[0]+O.dyco[0])/ld; - O.dylv[1]= lv[1] - (R.co[1]-lar->co[1]+O.dyco[1])/ld; - O.dylv[2]= lv[2] - (R.co[2]-lar->co[2]+O.dyco[2])/ld; + O.dylv[0]= lv[0] - (shi->co[0]-lar->co[0]+O.dyco[0])/ld; + O.dylv[1]= lv[1] - (shi->co[1]-lar->co[1]+O.dyco[1])/ld; + O.dylv[2]= lv[2] - (shi->co[2]-lar->co[2]+O.dyco[2])/ld; } } @@ -1843,16 +1816,16 @@ void shade_lamp_loop(int mask, ShadeResult *shr) if(ma->mode & MA_SHADOW) { if(lar->shb) { - shadfac[3] = testshadowbuf(lar->shb, inp); + shadfac[3] = testshadowbuf(lar->shb, shi->co, inp); if(shadfac[3]==0.0) continue; i*= shadfac[3]; } else if(lar->mode & LA_SHAD_RAY) { if(R.r.mode & R_RAYTRACE) { - extern void ray_shadow(LampRen *, float *, int); + extern void ray_shadow(ShadeInput *, LampRen *, float *, int); /* hurms, single sided? */ - if( R.vlr->n[0]*lv[0] + R.vlr->n[1]*lv[1] + R.vlr->n[2]*lv[2] > -0.01) { - ray_shadow(lar, shadfac, mask); + if( shi->vlr->n[0]*lv[0] + shi->vlr->n[1]*lv[1] + shi->vlr->n[2]*lv[2] > -0.01) { + ray_shadow(shi, lar, shadfac, mask); if(shadfac[3]==0.0) continue; i*= shadfac[3]; } @@ -1923,7 +1896,7 @@ void shade_lamp_loop(int mask, ShadeResult *shr) if(ma->mode & (MA_ZTRA|MA_RAYTRANSP)) { if(ma->fresnel_tra!=1.0) - ma->alpha*= fresnel_fac(R.view, R.vn, ma->fresnel_tra); + ma->alpha*= fresnel_fac(shi->view, shi->vn, ma->fresnel_tra); if(ma->spectra!=0.0) { @@ -1941,202 +1914,91 @@ void shade_lamp_loop(int mask, ShadeResult *shr) if(shr->spec[2]<0.0) shr->spec[2]= 0.0; if(shr->diff[0]<0.0) shr->diff[0]= 0.0; else shr->diff[0]*= ma->r; - shr->diff[0]+= ma->ambr +ma->amb*R.rad[0]; + shr->diff[0]+= ma->ambr +ma->amb*shi->rad[0]; if(shr->diff[1]<0.0) shr->diff[1]= 0.0; else shr->diff[1]*= ma->g; - shr->diff[1]+= ma->ambg +ma->amb*R.rad[1]; + shr->diff[1]+= ma->ambg +ma->amb*shi->rad[1]; if(shr->diff[2]<0.0) shr->diff[2]= 0.0; else shr->diff[2]*= ma->b; - shr->diff[2]+= ma->ambb +ma->amb*R.rad[2]; + shr->diff[2]+= ma->ambb +ma->amb*shi->rad[2]; /* refcol is for envmap only */ - if(R.refcol[0]!=0.0) { - shr->diff[0]= ma->mirr*R.refcol[1] + (1.0 - ma->mirr*R.refcol[0])*shr->diff[0]; - shr->diff[1]= ma->mirg*R.refcol[2] + (1.0 - ma->mirg*R.refcol[0])*shr->diff[1]; - shr->diff[2]= ma->mirb*R.refcol[3] + (1.0 - ma->mirb*R.refcol[0])*shr->diff[2]; + if(shi->refcol[0]!=0.0) { + shr->diff[0]= ma->mirr*shi->refcol[1] + (1.0 - ma->mirr*shi->refcol[0])*shr->diff[0]; + shr->diff[1]= ma->mirg*shi->refcol[2] + (1.0 - ma->mirg*shi->refcol[0])*shr->diff[1]; + shr->diff[2]= ma->mirb*shi->refcol[3] + (1.0 - ma->mirb*shi->refcol[0])*shr->diff[2]; } } - -void shadepixel(float x, float y, int vlaknr, int mask) - /* x,y: window coordinate from 0 to rectx,y */ +void shade_input_set_coords(ShadeInput *shi, float u, float v, int i1, int i2, int i3) { - static VlakRen *vlr; - static VertRen *v1, *v2, *v3; - static float t00, t01, t10, t11, dvlak, n1[3], n2[3], n3[3]; - static float s00, s01, s10, s11; - ShadeResult shr; - float *o1, *o2, *o3; - float u, v, l, dl, hox, hoy, detsh, fac, deler, alpha; - char *cp1, *cp2, *cp3; + VertRen *v1, *v2, *v3; + VlakRen *vlr= shi->vlr; + float l, dl; + short texco= shi->matren->texco; + int mode= shi->matren->mode; + char p1, p2, p3; - if(R.vlaknr== -1) { /* does initrender */ - vlr= R.vlr= 0; + /* for rendering of quads, the following values are used to denote vertices: + 0 1 2 scanline + 0 2 3 + 0 1 3 raytracer + 2 1 3 + */ + +// check!!! vlr1->flag |= R_FACE_SPLIT; + + if(i1==0) { + v1= vlr->v1; + p1= ME_FLIPV1; + } else { + v1= vlr->v3; + p1= ME_FLIPV3; + } + + if(i2==1) { + v2= vlr->v2; + p2= ME_FLIPV2; + } else { + v2= vlr->v3; + p2= ME_FLIPV3; } - if(vlaknr<=0) { /* sky */ - R.vlaknr= 0; - shortcol[3]= 0; + if(i3==2) { + v3= vlr->v3; + p3= ME_FLIPV3; + } else { + v3= vlr->v4; + p3= ME_FLIPV4; } - else if( (vlaknr & 0x7FFFFF) <= R.totvlak) { - if(vlaknr!=R.vlaknr) { - vlr= RE_findOrAddVlak( (vlaknr-1) & 0x7FFFFF); - - R.mat= vlr->mat; - R.matren= R.mat->ren; - - if(R.matren==0) { /* for debug */ - shortcol[3]= 65535; - shortcol[2]= 0; - shortcol[1]= 65535; - shortcol[0]= 65535; - return; + /* calculate U and V, for scanline (normal u and v are -1 to 0) */ + if(u==1.0) { + if( (vlr->flag & R_SMOOTH) || (texco & NEED_UV)) { + float detsh, t00, t10, t01, t11; + + if(vlr->snproj==0) { + t00= v3->co[0]-v1->co[0]; t01= v3->co[1]-v1->co[1]; + t10= v3->co[0]-v2->co[0]; t11= v3->co[1]-v2->co[1]; + } + else if(vlr->snproj==1) { + t00= v3->co[0]-v1->co[0]; t01= v3->co[2]-v1->co[2]; + t10= v3->co[0]-v2->co[0]; t11= v3->co[2]-v2->co[2]; + } + else { + t00= v3->co[1]-v1->co[1]; t01= v3->co[2]-v1->co[2]; + t10= v3->co[1]-v2->co[1]; t11= v3->co[2]-v2->co[2]; } - R.vlr= vlr; - - R.vno= vlr->n; - R.osatex= (R.matren->texco & TEXCO_OSA); - R.vlaknr= vlaknr; - - v1= vlr->v1; - dvlak= v1->co[0]*vlr->n[0]+v1->co[1]*vlr->n[1]+v1->co[2]*vlr->n[2]; - - if( (vlr->flag & R_SMOOTH) || (R.matren->texco & NEED_UV)) { /* uv needed */ - if(vlaknr & 0x800000) { - v2= vlr->v3; - v3= vlr->v4; - } - else { - v2= vlr->v2; - v3= vlr->v3; - } - - if(vlr->snproj==0) { - t00= v3->co[0]-v1->co[0]; t01= v3->co[1]-v1->co[1]; - t10= v3->co[0]-v2->co[0]; t11= v3->co[1]-v2->co[1]; - } - else if(vlr->snproj==1) { - t00= v3->co[0]-v1->co[0]; t01= v3->co[2]-v1->co[2]; - t10= v3->co[0]-v2->co[0]; t11= v3->co[2]-v2->co[2]; - } - else { - t00= v3->co[1]-v1->co[1]; t01= v3->co[2]-v1->co[2]; - t10= v3->co[1]-v2->co[1]; t11= v3->co[2]-v2->co[2]; - } - - detsh= t00*t11-t10*t01; - t00/= detsh; t01/=detsh; - t10/=detsh; t11/=detsh; - - if(vlr->flag & R_SMOOTH) { /* adjust punos (vertexnormals) */ - if(vlr->puno & ME_FLIPV1) { - n1[0]= -v1->n[0]; n1[1]= -v1->n[1]; n1[2]= -v1->n[2]; - } else { - n1[0]= v1->n[0]; n1[1]= v1->n[1]; n1[2]= v1->n[2]; - } - if(vlaknr & 0x800000) { - if(vlr->puno & ME_FLIPV3) { - n2[0]= -v2->n[0]; n2[1]= -v2->n[1]; n2[2]= -v2->n[2]; - } else { - n2[0]= v2->n[0]; n2[1]= v2->n[1]; n2[2]= v2->n[2]; - } - - if(vlr->puno & ME_FLIPV4) { - n3[0]= -v3->n[0]; n3[1]= -v3->n[1]; n3[2]= -v3->n[2]; - } else { - n3[0]= v3->n[0]; n3[1]= v3->n[1]; n3[2]= v3->n[2]; - } - - } - else { - if(vlr->puno & ME_FLIPV2) { - n2[0]= -v2->n[0]; n2[1]= -v2->n[1]; n2[2]= -v2->n[2]; - } else { - n2[0]= v2->n[0]; n2[1]= v2->n[1]; n2[2]= v2->n[2]; - } - - if(vlr->puno & ME_FLIPV3) { - n3[0]= -v3->n[0]; n3[1]= -v3->n[1]; n3[2]= -v3->n[2]; - } else { - n3[0]= v3->n[0]; n3[1]= v3->n[1]; n3[2]= v3->n[2]; - } - } - } - if(R.matren->texco & TEXCO_STICKY) { - s00= v3->ho[0]/v3->ho[3] - v1->ho[0]/v1->ho[3]; - s01= v3->ho[1]/v3->ho[3] - v1->ho[1]/v1->ho[3]; - s10= v3->ho[0]/v3->ho[3] - v2->ho[0]/v2->ho[3]; - s11= v3->ho[1]/v3->ho[3] - v2->ho[1]/v2->ho[3]; - - detsh= s00*s11-s10*s01; - s00/= detsh; s01/=detsh; - s10/=detsh; s11/=detsh; - } - } - } - - /* COXYZ */ - R.view[0]= (x+(R.xstart)+1.0); - - if(R.flag & R_SEC_FIELD) { - if(R.r.mode & R_ODDFIELD) R.view[1]= (y+R.ystart+0.5)*R.ycor; - else R.view[1]= (y+R.ystart+1.5)*R.ycor; - } - else R.view[1]= (y+R.ystart+1.0)*R.ycor; + detsh= t00*t11-t10*t01; + t00/= detsh; t01/=detsh; + t10/=detsh; t11/=detsh; - R.view[2]= -R.viewfac; - - if(R.r.mode & R_PANORAMA) { - float panoco, panosi; - panoco = getPanovCo(); - panosi = getPanovSi(); - - u= R.view[0]; v= R.view[2]; - R.view[0]= panoco*u + panosi*v; - R.view[2]= -panosi*u + panoco*v; - } - - deler= vlr->n[0]*R.view[0] + vlr->n[1]*R.view[1] + vlr->n[2]*R.view[2]; - if (deler!=0.0) fac= R.zcor= dvlak/deler; - else fac= R.zcor= 0.0; - - R.co[0]= fac*R.view[0]; - R.co[1]= fac*R.view[1]; - R.co[2]= fac*R.view[2]; - - if(R.osatex || (R.r.mode & R_SHADOW) ) { - u= dvlak/(deler-vlr->n[0]); - v= dvlak/(deler- R.ycor*vlr->n[1]); - - O.dxco[0]= R.co[0]- (R.view[0]-1.0)*u; - O.dxco[1]= R.co[1]- (R.view[1])*u; - O.dxco[2]= R.co[2]- (R.view[2])*u; - - O.dyco[0]= R.co[0]- (R.view[0])*v; - O.dyco[1]= R.co[1]- (R.view[1]-1.0*R.ycor)*v; - O.dyco[2]= R.co[2]- (R.view[2])*v; - - } - - fac= Normalise(R.view); - R.zcor*= fac; /* for mist */ - - if(R.osatex) { - if( (R.matren->texco & TEXCO_REFL) ) { - O.dxview= -1.0/fac; - O.dyview= -R.ycor/fac; - } - } - - /* UV and TEX*/ - if( (vlr->flag & R_SMOOTH) || (R.matren->texco & NEED_UV)) { if(vlr->snproj==0) { - u= (R.co[0]-v3->co[0])*t11-(R.co[1]-v3->co[1])*t10; - v= (R.co[1]-v3->co[1])*t00-(R.co[0]-v3->co[0])*t01; - if(R.osatex) { + u= (shi->co[0]-v3->co[0])*t11-(shi->co[1]-v3->co[1])*t10; + v= (shi->co[1]-v3->co[1])*t00-(shi->co[0]-v3->co[0])*t01; + if(shi->osatex) { O.dxuv[0]= O.dxco[0]*t11- O.dxco[1]*t10; O.dxuv[1]= O.dxco[1]*t00- O.dxco[0]*t01; O.dyuv[0]= O.dyco[0]*t11- O.dyco[1]*t10; @@ -2144,9 +2006,9 @@ void shadepixel(float x, float y, int vlaknr, int mask) } } else if(vlr->snproj==1) { - u= (R.co[0]-v3->co[0])*t11-(R.co[2]-v3->co[2])*t10; - v= (R.co[2]-v3->co[2])*t00-(R.co[0]-v3->co[0])*t01; - if(R.osatex) { + u= (shi->co[0]-v3->co[0])*t11-(shi->co[2]-v3->co[2])*t10; + v= (shi->co[2]-v3->co[2])*t00-(shi->co[0]-v3->co[0])*t01; + if(shi->osatex) { O.dxuv[0]= O.dxco[0]*t11- O.dxco[2]*t10; O.dxuv[1]= O.dxco[2]*t00- O.dxco[0]*t01; O.dyuv[0]= O.dyco[0]*t11- O.dyco[2]*t10; @@ -2154,313 +2016,429 @@ void shadepixel(float x, float y, int vlaknr, int mask) } } else { - u= (R.co[1]-v3->co[1])*t11-(R.co[2]-v3->co[2])*t10; - v= (R.co[2]-v3->co[2])*t00-(R.co[1]-v3->co[1])*t01; - if(R.osatex) { + u= (shi->co[1]-v3->co[1])*t11-(shi->co[2]-v3->co[2])*t10; + v= (shi->co[2]-v3->co[2])*t00-(shi->co[1]-v3->co[1])*t01; + if(shi->osatex) { O.dxuv[0]= O.dxco[1]*t11- O.dxco[2]*t10; O.dxuv[1]= O.dxco[2]*t00- O.dxco[1]*t01; O.dyuv[0]= O.dyco[1]*t11- O.dyco[2]*t10; O.dyuv[1]= O.dyco[2]*t00- O.dyco[1]*t01; } } - l= 1.0+u+v; - - if(vlr->flag & R_SMOOTH) { - R.vn[0]= l*n3[0]-u*n1[0]-v*n2[0]; - R.vn[1]= l*n3[1]-u*n1[1]-v*n2[1]; - R.vn[2]= l*n3[2]-u*n1[2]-v*n2[2]; - - Normalise(R.vn); - if(R.osatex && (R.matren->texco & (TEXCO_NORM+TEXCO_REFL)) ) { - dl= O.dxuv[0]+O.dxuv[1]; - O.dxno[0]= dl*n3[0]-O.dxuv[0]*n1[0]-O.dxuv[1]*n2[0]; - O.dxno[1]= dl*n3[1]-O.dxuv[0]*n1[1]-O.dxuv[1]*n2[1]; - O.dxno[2]= dl*n3[2]-O.dxuv[0]*n1[2]-O.dxuv[1]*n2[2]; - dl= O.dyuv[0]+O.dyuv[1]; - O.dyno[0]= dl*n3[0]-O.dyuv[0]*n1[0]-O.dyuv[1]*n2[0]; - O.dyno[1]= dl*n3[1]-O.dyuv[0]*n1[1]-O.dyuv[1]*n2[1]; - O.dyno[2]= dl*n3[2]-O.dyuv[0]*n1[2]-O.dyuv[1]*n2[2]; - - } - } - else { - VECCOPY(R.vn, vlr->n); - } - - if(R.matren->mode & MA_ZINV) { /* z invert */ - /* R.vn[0]= -R.vn[0]; */ - /* R.vn[1]= -R.vn[1]; */ - } - - if(R.matren->texco & TEXCO_ORCO) { - if(v2->orco) { - o1= v1->orco; - o2= v2->orco; - o3= v3->orco; - - R.lo[0]= l*o3[0]-u*o1[0]-v*o2[0]; - R.lo[1]= l*o3[1]-u*o1[1]-v*o2[1]; - R.lo[2]= l*o3[2]-u*o1[2]-v*o2[2]; - - if(R.osatex) { - dl= O.dxuv[0]+O.dxuv[1]; - O.dxlo[0]= dl*o3[0]-O.dxuv[0]*o1[0]-O.dxuv[1]*o2[0]; - O.dxlo[1]= dl*o3[1]-O.dxuv[0]*o1[1]-O.dxuv[1]*o2[1]; - O.dxlo[2]= dl*o3[2]-O.dxuv[0]*o1[2]-O.dxuv[1]*o2[2]; - dl= O.dyuv[0]+O.dyuv[1]; - O.dylo[0]= dl*o3[0]-O.dyuv[0]*o1[0]-O.dyuv[1]*o2[0]; - O.dylo[1]= dl*o3[1]-O.dyuv[0]*o1[1]-O.dyuv[1]*o2[1]; - O.dylo[2]= dl*o3[2]-O.dyuv[0]*o1[2]-O.dyuv[1]*o2[2]; - } - } - } - - if(R.matren->texco & TEXCO_GLOB) { - VECCOPY(R.gl, R.co); - MTC_Mat4MulVecfl(R.viewinv, R.gl); - if(R.osatex) { - VECCOPY(O.dxgl, O.dxco); - MTC_Mat3MulVecfl(R.imat, O.dxco); - VECCOPY(O.dygl, O.dyco); - MTC_Mat3MulVecfl(R.imat, O.dyco); - } - } - if((R.matren->texco & TEXCO_UV) || (R.matren->mode & (MA_VERTEXCOL|MA_FACETEXTURE))) { - if(R.vlr->tface) { - float *uv1, *uv2, *uv3; - - uv1= R.vlr->tface->uv[0]; - if( (vlaknr & 0x800000) || (R.vlr->flag & R_FACE_SPLIT) ) { - uv2= R.vlr->tface->uv[2]; - uv3= R.vlr->tface->uv[3]; - } - else { - uv2= R.vlr->tface->uv[1]; - uv3= R.vlr->tface->uv[2]; - } - - R.uv[0]= -1.0 + 2.0*(l*uv3[0]-u*uv1[0]-v*uv2[0]); - R.uv[1]= -1.0 + 2.0*(l*uv3[1]-u*uv1[1]-v*uv2[1]); - - if(R.osatex) { - float duv[2]; - - dl= O.dxuv[0]+O.dxuv[1]; - duv[0]= O.dxuv[0]; - duv[1]= O.dxuv[1]; - - O.dxuv[0]= 2.0*(dl*uv3[0]-duv[0]*uv1[0]-duv[1]*uv2[0]); - O.dxuv[1]= 2.0*(dl*uv3[1]-duv[0]*uv1[1]-duv[1]*uv2[1]); - - dl= O.dyuv[0]+O.dyuv[1]; - duv[0]= O.dyuv[0]; - duv[1]= O.dyuv[1]; - - O.dyuv[0]= 2.0*(dl*uv3[0]-duv[0]*uv1[0]-duv[1]*uv2[0]); - O.dyuv[1]= 2.0*(dl*uv3[1]-duv[0]*uv1[1]-duv[1]*uv2[1]); - } - - } - else { - R.uv[0]= 2.0*(u+.5); - R.uv[1]= 2.0*(v+.5); - } - } - if(R.matren->texco & TEXCO_NORM) { - R.orn[0]= R.vn[0]; - R.orn[1]= -R.vn[1]; - R.orn[2]= R.vn[2]; - } - if(R.matren->mode & MA_VERTEXCOL) { - cp1= (char *)vlr->vcol; - if(cp1) { - if( (vlaknr & 0x800000) || (R.vlr->flag & R_FACE_SPLIT) ) { - cp2= (char *)(vlr->vcol+2); - cp3= (char *)(vlr->vcol+3); - } - else { - cp2= (char *)(vlr->vcol+1); - cp3= (char *)(vlr->vcol+2); - } - R.vcol[0]= (l*cp3[3]-u*cp1[3]-v*cp2[3])/255.0; - R.vcol[1]= (l*cp3[2]-u*cp1[2]-v*cp2[2])/255.0; - R.vcol[2]= (l*cp3[1]-u*cp1[1]-v*cp2[1])/255.0; - - } - else { - R.vcol[0]= 0.0; - R.vcol[1]= 0.0; - R.vcol[2]= 0.0; - } - } - if(R.matren->mode & MA_RADIO) { - R.rad[0]= (l*v3->rad[0] - u*v1->rad[0] - v*v2->rad[0]); - R.rad[1]= (l*v3->rad[1] - u*v1->rad[1] - v*v2->rad[1]); - R.rad[2]= (l*v3->rad[2] - u*v1->rad[2] - v*v2->rad[2]); - } - else { - R.rad[0]= R.rad[1]= R.rad[2]= 0.0; - } - if(R.matren->mode & MA_FACETEXTURE) { - if((R.matren->mode & MA_VERTEXCOL)==0) { - R.vcol[0]= 1.0; - R.vcol[1]= 1.0; - R.vcol[2]= 1.0; - } - if(vlr->tface) render_realtime_texture(); - } - - if(R.matren->texco & TEXCO_REFL) { - /* mirror reflection colour textures (envmap) */ - - RE_calc_R_ref(); - } - - /* after this the u and v AND O.dxuv and O.dyuv are incorrect */ - if(R.matren->texco & TEXCO_STICKY) { - if(v2->sticky) { - - /* recalc u and v again */ - hox= x/Zmulx -1.0; - hoy= y/Zmuly -1.0; - u= (hox - v3->ho[0]/v3->ho[3])*s11 - (hoy - v3->ho[1]/v3->ho[3])*s10; - v= (hoy - v3->ho[1]/v3->ho[3])*s00 - (hox - v3->ho[0]/v3->ho[3])*s01; - l= 1.0+u+v; - - o1= v1->sticky; - o2= v2->sticky; - o3= v3->sticky; - - R.sticky[0]= l*o3[0]-u*o1[0]-v*o2[0]; - R.sticky[1]= l*o3[1]-u*o1[1]-v*o2[1]; - - if(R.osatex) { - O.dxuv[0]= s11/Zmulx; - O.dxuv[1]= - s01/Zmulx; - O.dyuv[0]= - s10/Zmuly; - O.dyuv[1]= s00/Zmuly; - - dl= O.dxuv[0]+O.dxuv[1]; - O.dxsticky[0]= dl*o3[0]-O.dxuv[0]*o1[0]-O.dxuv[1]*o2[0]; - O.dxsticky[1]= dl*o3[1]-O.dxuv[0]*o1[1]-O.dxuv[1]*o2[1]; - dl= O.dyuv[0]+O.dyuv[1]; - O.dysticky[0]= dl*o3[0]-O.dyuv[0]*o1[0]-O.dyuv[1]*o2[0]; - O.dysticky[1]= dl*o3[1]-O.dyuv[0]*o1[1]-O.dyuv[1]*o2[1]; - } - } - } - } - else { - VECCOPY(R.vn, vlr->n); - R.rad[0]= R.rad[1]= R.rad[2]= 0.0; - } - /* always reset */ - R.refcol[0]= R.refcol[1]= R.refcol[2]= R.refcol[3]= 0.0; - - if(R.matren->texco & TEXCO_WINDOW) { - R.winco[0]= (x+(R.xstart))/(float)R.afmx; - R.winco[1]= (y+(R.ystart))/(float)R.afmy; } - shade_lamp_loop(mask, &shr); - if(R.matren->translucency!=0.0) { + } + l= 1.0+u+v; + + /* calculate punos (vertexnormals) */ + if(vlr->flag & R_SMOOTH) { + float n1[3], n2[3], n3[3]; + + if(vlr->puno & p1) { + n1[0]= -v1->n[0]; n1[1]= -v1->n[1]; n1[2]= -v1->n[2]; + } else { + n1[0]= v1->n[0]; n1[1]= v1->n[1]; n1[2]= v1->n[2]; + } + if(vlr->puno & p2) { + n2[0]= -v2->n[0]; n2[1]= -v2->n[1]; n2[2]= -v2->n[2]; + } else { + n2[0]= v2->n[0]; n2[1]= v2->n[1]; n2[2]= v2->n[2]; + } + + if(vlr->puno & p3) { + n3[0]= -v3->n[0]; n3[1]= -v3->n[1]; n3[2]= -v3->n[2]; + } else { + n3[0]= v3->n[0]; n3[1]= v3->n[1]; n3[2]= v3->n[2]; + } + + shi->vn[0]= l*n3[0]-u*n1[0]-v*n2[0]; + shi->vn[1]= l*n3[1]-u*n1[1]-v*n2[1]; + shi->vn[2]= l*n3[2]-u*n1[2]-v*n2[2]; + + Normalise(shi->vn); + + if(shi->osatex && (texco & (TEXCO_NORM|TEXCO_REFL)) ) { + dl= O.dxuv[0]+O.dxuv[1]; + O.dxno[0]= dl*n3[0]-O.dxuv[0]*n1[0]-O.dxuv[1]*n2[0]; + O.dxno[1]= dl*n3[1]-O.dxuv[0]*n1[1]-O.dxuv[1]*n2[1]; + O.dxno[2]= dl*n3[2]-O.dxuv[0]*n1[2]-O.dxuv[1]*n2[2]; + dl= O.dyuv[0]+O.dyuv[1]; + O.dyno[0]= dl*n3[0]-O.dyuv[0]*n1[0]-O.dyuv[1]*n2[0]; + O.dyno[1]= dl*n3[1]-O.dyuv[0]*n1[1]-O.dyuv[1]*n2[1]; + O.dyno[2]= dl*n3[2]-O.dyuv[0]*n1[2]-O.dyuv[1]*n2[2]; + + } + } + else { + VECCOPY(shi->vn, vlr->n); + } + + /* texture coordinates. O.dxuv O.dyuv have been set */ + if(texco & NEED_UV) { + if(texco & TEXCO_ORCO) { + if(v1->orco) { + float *o1, *o2, *o3; + + o1= v1->orco; + o2= v2->orco; + o3= v3->orco; + + shi->lo[0]= l*o3[0]-u*o1[0]-v*o2[0]; + shi->lo[1]= l*o3[1]-u*o1[1]-v*o2[1]; + shi->lo[2]= l*o3[2]-u*o1[2]-v*o2[2]; + + if(shi->osatex) { + dl= O.dxuv[0]+O.dxuv[1]; + O.dxlo[0]= dl*o3[0]-O.dxuv[0]*o1[0]-O.dxuv[1]*o2[0]; + O.dxlo[1]= dl*o3[1]-O.dxuv[0]*o1[1]-O.dxuv[1]*o2[1]; + O.dxlo[2]= dl*o3[2]-O.dxuv[0]*o1[2]-O.dxuv[1]*o2[2]; + dl= O.dyuv[0]+O.dyuv[1]; + O.dylo[0]= dl*o3[0]-O.dyuv[0]*o1[0]-O.dyuv[1]*o2[0]; + O.dylo[1]= dl*o3[1]-O.dyuv[0]*o1[1]-O.dyuv[1]*o2[1]; + O.dylo[2]= dl*o3[2]-O.dyuv[0]*o1[2]-O.dyuv[1]*o2[2]; + } + } + } + + if(texco & TEXCO_GLOB) { + VECCOPY(shi->gl, shi->co); + MTC_Mat4MulVecfl(R.viewinv, shi->gl); + if(shi->osatex) { + VECCOPY(O.dxgl, O.dxco); + MTC_Mat3MulVecfl(R.imat, O.dxco); + VECCOPY(O.dygl, O.dyco); + MTC_Mat3MulVecfl(R.imat, O.dyco); + } + } + if((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL|MA_FACETEXTURE))) { + if(mode & MA_VERTEXCOL) { + + if(vlr->vcol) { + char *cp1, *cp2, *cp3; + + cp1= (char *)(vlr->vcol+i1); + cp2= (char *)(vlr->vcol+i2); + cp3= (char *)(vlr->vcol+i3); + + shi->vcol[0]= (l*cp3[3]-u*cp1[3]-v*cp2[3])/255.0; + shi->vcol[1]= (l*cp3[2]-u*cp1[2]-v*cp2[2])/255.0; + shi->vcol[2]= (l*cp3[1]-u*cp1[1]-v*cp2[1])/255.0; + + } + else { + shi->vcol[0]= 0.0; + shi->vcol[1]= 0.0; + shi->vcol[2]= 0.0; + } + } + if(vlr->tface) { + float *uv1, *uv2, *uv3; + + uv1= vlr->tface->uv[i1]; + uv2= vlr->tface->uv[i2]; + uv3= vlr->tface->uv[i3]; + + shi->uv[0]= -1.0 + 2.0*(l*uv3[0]-u*uv1[0]-v*uv2[0]); + shi->uv[1]= -1.0 + 2.0*(l*uv3[1]-u*uv1[1]-v*uv2[1]); + + if(shi->osatex) { + float duv[2]; + + dl= O.dxuv[0]+O.dxuv[1]; + duv[0]= O.dxuv[0]; + duv[1]= O.dxuv[1]; + + O.dxuv[0]= 2.0*(dl*uv3[0]-duv[0]*uv1[0]-duv[1]*uv2[0]); + O.dxuv[1]= 2.0*(dl*uv3[1]-duv[0]*uv1[1]-duv[1]*uv2[1]); + + dl= O.dyuv[0]+O.dyuv[1]; + duv[0]= O.dyuv[0]; + duv[1]= O.dyuv[1]; + + O.dyuv[0]= 2.0*(dl*uv3[0]-duv[0]*uv1[0]-duv[1]*uv2[0]); + O.dyuv[1]= 2.0*(dl*uv3[1]-duv[0]*uv1[1]-duv[1]*uv2[1]); + } + + if(mode & MA_FACETEXTURE) { + if((mode & MA_VERTEXCOL)==0) { + shi->vcol[0]= 1.0; + shi->vcol[1]= 1.0; + shi->vcol[2]= 1.0; + } + if(vlr->tface) render_realtime_texture(shi); + } + } + else { + shi->uv[0]= 2.0*(u+.5); + shi->uv[1]= 2.0*(v+.5); + } + } + if(texco & TEXCO_NORM) { + shi->orn[0]= shi->vn[0]; + shi->orn[1]= shi->vn[1]; + shi->orn[2]= shi->vn[2]; + } + + if(mode & MA_RADIO) { + shi->rad[0]= (l*v3->rad[0] - u*v1->rad[0] - v*v2->rad[0]); + shi->rad[1]= (l*v3->rad[1] - u*v1->rad[1] - v*v2->rad[1]); + shi->rad[2]= (l*v3->rad[2] - u*v1->rad[2] - v*v2->rad[2]); + } + else { + shi->rad[0]= shi->rad[1]= shi->rad[2]= 0.0; + } + + if(texco & TEXCO_REFL) { + /* mirror reflection colour textures (and envmap) */ + calc_R_ref(shi); + } + + } + else { + shi->rad[0]= shi->rad[1]= shi->rad[2]= 0.0; + } +} + + /* x,y: window coordinate from 0 to rectx,y */ + /* return pointer to rendered face */ +void *shadepixel(float x, float y, int vlaknr, int mask, float *col) +{ + ShadeResult shr; + ShadeInput shi; + VlakRen *vlr=NULL; + + if(vlaknr< 0) { /* error */ + return NULL; + } + + if(vlaknr==0) { /* sky */ + col[0]= 0.0; col[1]= 0.0; col[2]= 0.0; col[3]= 0.0; + } + else if( (vlaknr & 0x7FFFFF) <= R.totvlak) { + VertRen *v1, *v2, *v3; + float alpha, fac, dvlak, deler; + + vlr= RE_findOrAddVlak( (vlaknr-1) & 0x7FFFFF); + + shi.mat= vlr->mat; + shi.matren= shi.mat->ren; + shi.vlr= vlr; + shi.osatex= (shi.matren->texco & TEXCO_OSA); + + v1= vlr->v1; + dvlak= v1->co[0]*vlr->n[0]+v1->co[1]*vlr->n[1]+v1->co[2]*vlr->n[2]; + + /* COXYZ AND VIEW VECTOR */ + shi.view[0]= (x+(R.xstart)+1.0); + + if(R.flag & R_SEC_FIELD) { + if(R.r.mode & R_ODDFIELD) shi.view[1]= (y+R.ystart+0.5)*R.ycor; + else shi.view[1]= (y+R.ystart+1.5)*R.ycor; + } + else shi.view[1]= (y+R.ystart+1.0)*R.ycor; + + shi.view[2]= -R.viewfac; + + if(R.r.mode & R_PANORAMA) { + float panoco, panosi, u, v; + panoco = getPanovCo(); + panosi = getPanovSi(); + + u= shi.view[0]; v= shi.view[2]; + shi.view[0]= panoco*u + panosi*v; + shi.view[2]= -panosi*u + panoco*v; + } + + deler= vlr->n[0]*shi.view[0] + vlr->n[1]*shi.view[1] + vlr->n[2]*shi.view[2]; + if (deler!=0.0) fac= R.zcor= dvlak/deler; + else fac= R.zcor= 0.0; + + shi.co[0]= fac*shi.view[0]; + shi.co[1]= fac*shi.view[1]; + shi.co[2]= fac*shi.view[2]; + + /* pixel dx/dy for render coord */ + if(shi.osatex || (R.r.mode & R_SHADOW) ) { + float u= dvlak/(deler-vlr->n[0]); + float v= dvlak/(deler- R.ycor*vlr->n[1]); + + O.dxco[0]= shi.co[0]- (shi.view[0]-1.0)*u; + O.dxco[1]= shi.co[1]- (shi.view[1])*u; + O.dxco[2]= shi.co[2]- (shi.view[2])*u; + + O.dyco[0]= shi.co[0]- (shi.view[0])*v; + O.dyco[1]= shi.co[1]- (shi.view[1]-1.0*R.ycor)*v; + O.dyco[2]= shi.co[2]- (shi.view[2])*v; + + } + + fac= Normalise(shi.view); + R.zcor*= fac; /* for mist */ + + if(shi.osatex) { + if( (shi.matren->texco & TEXCO_REFL) ) { + O.dxview= -1.0/fac; + O.dyview= -R.ycor/fac; + } + } + + /* calcuate normals, texture coords, vertex colors, etc */ + if(vlaknr & 0x800000) + shade_input_set_coords(&shi, 1.0, 1.0, 0, 2, 3); + else + shade_input_set_coords(&shi, 1.0, 1.0, 0, 1, 2); + + /* this only avalailable for scanline */ + if(shi.matren->texco & TEXCO_WINDOW) { + shi.winco[0]= (x+(R.xstart))/(float)R.afmx; + shi.winco[1]= (y+(R.ystart))/(float)R.afmy; + } + /* after this the u and v AND O.dxuv and O.dyuv are incorrect */ + if(shi.matren->texco & TEXCO_STICKY) { + if(v1->sticky) { + extern float Zmulx, Zmuly; + float *o1, *o2, *o3, hox, hoy, l, dl, u, v; + float s00, s01, s10, s11, detsh; + + if(vlaknr & 0x800000) { + v2= vlr->v3; v3= vlr->v4; + } else { + v2= vlr->v2; v3= vlr->v3; + } + + s00= v3->ho[0]/v3->ho[3] - v1->ho[0]/v1->ho[3]; + s01= v3->ho[1]/v3->ho[3] - v1->ho[1]/v1->ho[3]; + s10= v3->ho[0]/v3->ho[3] - v2->ho[0]/v2->ho[3]; + s11= v3->ho[1]/v3->ho[3] - v2->ho[1]/v2->ho[3]; + + detsh= s00*s11-s10*s01; + s00/= detsh; s01/=detsh; + s10/=detsh; s11/=detsh; + + /* recalc u and v again */ + hox= x/Zmulx -1.0; + hoy= y/Zmuly -1.0; + u= (hox - v3->ho[0]/v3->ho[3])*s11 - (hoy - v3->ho[1]/v3->ho[3])*s10; + v= (hoy - v3->ho[1]/v3->ho[3])*s00 - (hox - v3->ho[0]/v3->ho[3])*s01; + l= 1.0+u+v; + + o1= v1->sticky; + o2= v2->sticky; + o3= v3->sticky; + + shi.sticky[0]= l*o3[0]-u*o1[0]-v*o2[0]; + shi.sticky[1]= l*o3[1]-u*o1[1]-v*o2[1]; + + if(shi.osatex) { + O.dxuv[0]= s11/Zmulx; + O.dxuv[1]= - s01/Zmulx; + O.dyuv[0]= - s10/Zmuly; + O.dyuv[1]= s00/Zmuly; + + dl= O.dxuv[0]+O.dxuv[1]; + O.dxsticky[0]= dl*o3[0]-O.dxuv[0]*o1[0]-O.dxuv[1]*o2[0]; + O.dxsticky[1]= dl*o3[1]-O.dxuv[0]*o1[1]-O.dxuv[1]*o2[1]; + dl= O.dyuv[0]+O.dyuv[1]; + O.dysticky[0]= dl*o3[0]-O.dyuv[0]*o1[0]-O.dyuv[1]*o2[0]; + O.dysticky[1]= dl*o3[1]-O.dyuv[0]*o1[1]-O.dyuv[1]*o2[1]; + } + } + } + + /* ------ main shading loop */ + shade_lamp_loop(&shi, &shr, mask); + + if(shi.matren->translucency!=0.0) { ShadeResult shr_t; - VecMulf(R.vn, -1.0); - VecMulf(R.vlr->n, -1.0); - shade_lamp_loop(mask, &shr_t); - shr.diff[0]+= R.matren->translucency*shr_t.diff[0]; - shr.diff[1]+= R.matren->translucency*shr_t.diff[1]; - shr.diff[2]+= R.matren->translucency*shr_t.diff[2]; - VecMulf(R.vn, -1.0); - VecMulf(R.vlr->n, -1.0); + + VecMulf(shi.vn, -1.0); + VecMulf(shi.vlr->n, -1.0); + shade_lamp_loop(&shi, &shr_t, mask); + shr.diff[0]+= shi.matren->translucency*shr_t.diff[0]; + shr.diff[1]+= shi.matren->translucency*shr_t.diff[1]; + shr.diff[2]+= shi.matren->translucency*shr_t.diff[2]; + VecMulf(shi.vn, -1.0); + VecMulf(shi.vlr->n, -1.0); } if(R.r.mode & R_RAYTRACE) { - if(R.matren->ray_mirror!=0.0 || (R.mat->mode & MA_RAYTRANSP && shr.alpha!=1.0)) { - extern void ray_trace(int, ShadeResult *); + if(shi.matren->ray_mirror!=0.0 || (shi.mat->mode & MA_RAYTRANSP && shr.alpha!=1.0)) { + extern void ray_trace(ShadeInput *shi, ShadeResult *shr, int mask); - ray_trace(mask, &shr); + ray_trace(&shi, &shr, mask); } } - fac= shr.diff[0] + shr.spec[0]; - if(fac<=0.0) shortcol[0]= 0; else if(fac>=1.0) shortcol[0]= 65535; - else shortcol[0]= 65535.0*fac; + VecAddf(col, shr.diff, shr.spec); - fac= shr.diff[1] + shr.spec[1]; - if(fac<=0.0) shortcol[1]= 0; else if(fac>=1.0) shortcol[1]= 65535; - else shortcol[1]= 65535.0*fac; - - fac= shr.diff[2] + shr.spec[2]; - if(fac<=0.0) shortcol[2]= 0; else if(fac>=1.0) shortcol[2]= 65535; - else shortcol[2]= 65535.0*fac; - - if(usegamtab) { - shortcol[0]= igamtab2[ shortcol[0] ]; - shortcol[1]= igamtab2[ shortcol[1] ]; - shortcol[2]= igamtab2[ shortcol[2] ]; - } - /* MIST */ - if( (R.wrld.mode & WO_MIST) && (R.matren->mode & MA_NOMIST)==0 ){ - alpha= mistfactor(R.co); + if( (R.wrld.mode & WO_MIST) && (shi.matren->mode & MA_NOMIST)==0 ){ + alpha= mistfactor(shi.co); } else alpha= 1.0; if(shr.alpha!=1.0 || alpha!=1.0) { fac= alpha*(shr.alpha); - /* gamma */ - if(R.osa && usegamtab) fac*= fac; - - shortcol[3]= 65535.0*fac; - shortcol[0]*= fac; - shortcol[1]*= fac; - shortcol[2]*= fac; + col[3]= fac; + col[0]*= fac; + col[1]*= fac; + col[2]*= fac; } - else { - shortcol[3]= 65535; - } - } - else { - shortcol[0]= 65535; - shortcol[1]= 65535; - shortcol[2]= 0; - shortcol[3]= 65535; + else col[3]= 1.0; } if(R.flag & R_LAMPHALO) { - if(vlaknr<=0) { /* calc view vector and put R.co at far */ + if(vlaknr<=0) { /* calc view vector and put shi.co at far */ - if( (G.special1 & G_HOLO) && ((Camera *)G.scene->camera->data)->flag & CAM_HOLO2) { - R.view[0]= (x+(R.xstart)+1.0+holoofs); - } - else { - R.view[0]= (x+(R.xstart)+1.0); - } + shi.view[0]= (x+(R.xstart)+1.0); if(R.flag & R_SEC_FIELD) { - if(R.r.mode & R_ODDFIELD) R.view[1]= (y+R.ystart+0.5)*R.ycor; - else R.view[1]= (y+R.ystart+1.5)*R.ycor; + if(R.r.mode & R_ODDFIELD) shi.view[1]= (y+R.ystart+0.5)*R.ycor; + else shi.view[1]= (y+R.ystart+1.5)*R.ycor; } - else R.view[1]= (y+R.ystart+1.0)*R.ycor; + else shi.view[1]= (y+R.ystart+1.0)*R.ycor; - R.view[2]= -R.viewfac; + shi.view[2]= -R.viewfac; if(R.r.mode & R_PANORAMA) { - float panoco, panosi; + float u,v, panoco, panosi; panoco = getPanovCo(); panosi = getPanovSi(); - u= R.view[0]; v= R.view[2]; - R.view[0]= panoco*u + panosi*v; - R.view[2]= -panosi*u + panoco*v; + u= shi.view[0]; v= shi.view[2]; + shi.view[0]= panoco*u + panosi*v; + shi.view[2]= -panosi*u + panoco*v; } - R.co[2]= 0.0; + shi.co[2]= 0.0; } - renderspothalo(shortcol); + renderspothalo(&shi, col); + } + + return vlr; +} + +void shadepixel_short(float x, float y, int vlaknr, int mask, unsigned short *shortcol) +{ + float colf[4]; + + shadepixel(x, y, vlaknr, mask, colf); + + if(colf[0]<=0.0) shortcol[0]= 0; else if(colf[0]>=1.0) shortcol[0]= 65535; + else shortcol[0]= 65535.0*colf[0]; + if(colf[1]<=0.0) shortcol[1]= 0; else if(colf[1]>=1.0) shortcol[1]= 65535; + else shortcol[1]= 65535.0*colf[1]; + if(colf[2]<=0.0) shortcol[2]= 0; else if(colf[2]>=1.0) shortcol[2]= 65535; + else shortcol[2]= 65535.0*colf[2]; + if(colf[3]<=0.0) shortcol[3]= 0; else if(colf[3]>=1.0) shortcol[3]= 65535; + else shortcol[3]= 65535.0*colf[3]; + + if(usegamtab) { + shortcol[0]= igamtab2[ shortcol[0] ]; + shortcol[1]= igamtab2[ shortcol[1] ]; + shortcol[2]= igamtab2[ shortcol[2] ]; } } @@ -2695,13 +2673,14 @@ extern unsigned short *Acolrow; /* short zbuffermetdehand(); */ void zbufshadeDA(void) /* Delta Accum Pixel Struct */ { + extern float Zjitx,Zjity; PixStr *ps; float xd, yd, xs, ys; unsigned int *rz, *rp, *rt, mask, fullmask; unsigned int *rowbuf1, *rowbuf2, *rowbuf3, *rb1, *rb2, *rb3; int a, b; long *rd; - unsigned short *colrb, *acol; + unsigned short *colrb, *acol, shortcol[4]; short v, x, y; char *colrt, tempcol[4]; @@ -2765,7 +2744,6 @@ void zbufshadeDA(void) /* Delta Accum Pixel Struct */ zbufferall(); } - R.vlaknr= -1; rd= R.rectdaps; rz= R.rectz; colrt= (char *)R.rectot; @@ -2795,7 +2773,7 @@ void zbufshadeDA(void) /* Delta Accum Pixel Struct */ xs= (float)x+centLut[b & 15]; ys= (float)y+centLut[b>>4]; - shadepixel(xs, ys, ps->vlak, ps->mask); + shadepixel_short(xs, ys, ps->vlak, ps->mask, shortcol); if(shortcol[3]) { add_filt_mask(ps->mask, shortcol, rb1, rb2, rb3); @@ -2811,14 +2789,14 @@ void zbufshadeDA(void) /* Delta Accum Pixel Struct */ xs= (float)x+centLut[b & 15]; ys= (float)y+centLut[b>>4]; - shadepixel(xs, ys, ps->vlak0, mask); + shadepixel_short(xs, ys, ps->vlak0, mask, shortcol); if(shortcol[3]) { add_filt_mask(mask, shortcol, rb1, rb2, rb3); } } else { - shadepixel((float)x, (float)y, (int)*rd, fullmask); + shadepixel_short((float)x, (float)y, (int)*rd, fullmask, shortcol); if(shortcol[3]) { add_filt_mask(fullmask, shortcol, rb1, rb2, rb3); } @@ -2865,9 +2843,6 @@ void zbufshadeDA(void) /* Delta Accum Pixel Struct */ } scanlinesky(colrt-4*R.rectx, y-1); - /* scanline starts nicely: halos use textures as well! */ - R.vlaknr= -1; - } if(y0 && G.background==0) { if((y & 1)==0) { - RE_local_render_display(y-2, y-1, - R.rectx, R.recty, - R.rectot); + RE_local_render_display(y-2, y-1, R.rectx, R.recty, R.rectot); } } rz+= R.rectx; @@ -2912,10 +2885,11 @@ void zbufshadeDA(void) /* Delta Accum Pixel Struct */ void zbufshade(void) { + extern float Zjitx,Zjity; unsigned int *rz,*rp; float fy; int x,y; - unsigned short *acol; + unsigned short *acol, shortcol[4]; char *charcol, *rt; Zjitx=Zjity= -.5; @@ -2935,7 +2909,6 @@ void zbufshade(void) if(R.flag & R_ZTRA) bgnaccumbuf(); for(y=0; y +#include #include "MEM_guardedalloc.h" #include "BLI_arithb.h" diff --git a/source/blender/render/intern/source/shadbuf.c b/source/blender/render/intern/source/shadbuf.c index 545bcce6d3a..1abb5a796dc 100644 --- a/source/blender/render/intern/source/shadbuf.c +++ b/source/blender/render/intern/source/shadbuf.c @@ -77,7 +77,7 @@ float *give_jitter_tab(int samp); /* ------------------------------------------------------------------------- */ -void initshadowbuf(LampRen *lar, float mat[][4]) +void RE_initshadowbuf(LampRen *lar, float mat[][4]) { struct ShadBuf *shb; float hoek, temp, viewinv[4][4]; @@ -436,7 +436,7 @@ float readshadowbuf(struct ShadBuf *shb, int xs, int ys, int zs) /* return 1.0 : } -float testshadowbuf(struct ShadBuf *shb, float inp) /* return 1.0: no shadow at all */ +float testshadowbuf(struct ShadBuf *shb, float *rco, float inp) /* return 1.0: no shadow at all */ { float fac, co[4], dx[3], dy[3], aantal=0; float xs1,ys1, siz, *j, xres, yres; @@ -451,7 +451,7 @@ float testshadowbuf(struct ShadBuf *shb, float inp) /* return 1.0: no shadow a /* rotate renderco en osaco */ siz= 0.5*(float)shb->size; - VECCOPY(co, R.co); + VECCOPY(co, rco); co[3]= 1.0; MTC_Mat4MulVec4fl(shb->persmat, co); /* rational hom co */ @@ -483,17 +483,17 @@ float testshadowbuf(struct ShadBuf *shb, float inp) /* return 1.0: no shadow a return readshadowbuf(shb,(int)xs1, (int)ys1, zs); } - co[0]= R.co[0]+O.dxco[0]; - co[1]= R.co[1]+O.dxco[1]; - co[2]= R.co[2]+O.dxco[2]; + co[0]= rco[0]+O.dxco[0]; + co[1]= rco[1]+O.dxco[1]; + co[2]= rco[2]+O.dxco[2]; co[3]= 1.0; MTC_Mat4MulVec4fl(shb->persmat,co); /* rational hom co */ dx[0]= xs1- siz*(1.0+co[0]/co[3]); dx[1]= ys1- siz*(1.0+co[1]/co[3]); - co[0]= R.co[0]+O.dyco[0]; - co[1]= R.co[1]+O.dyco[1]; - co[2]= R.co[2]+O.dyco[2]; + co[0]= rco[0]+O.dyco[0]; + co[1]= rco[1]+O.dyco[1]; + co[2]= rco[2]+O.dyco[2]; co[3]= 1.0; MTC_Mat4MulVec4fl(shb->persmat,co); /* rational hom co */ dy[0]= xs1- siz*(1.0+co[0]/co[3]); diff --git a/source/blender/render/intern/source/shadowBuffer.cpp b/source/blender/render/intern/source/shadowBuffer.cpp deleted file mode 100644 index b60f7e160eb..00000000000 --- a/source/blender/render/intern/source/shadowBuffer.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/** - * $Id$ - * - * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. The Blender - * Foundation also sells licenses for use in proprietary software under - * the Blender License. See http://www.blender.org/BL/ for information - * about this. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL/BL DUAL LICENSE BLOCK ***** - */ - -#include -#include "render.h" -#include "render_intern.h" -#include "shadbuf.h" -#include "shadowBuffer.h" /* the C header */ -#include "RE_ShadowBuffer.h" /* the base buffer */ -#include "RE_DummyShadowBuffer.h" /* A dummy shadow buffer */ -#include "RE_basicShadowBuffer.h" /* the 'old' shadow buffer */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -struct ShadBuf; -struct LampRen; -struct Lamp; -/* - * Creates a shadow buffer of a certain type - */ -RE_ShadowBufferHandle RE_createShadowBuffer(struct LampRen *lar, - float mat[][4], - int mode) -{ - /* make a dummy: this always returns a fixed value */ - RE_ShadowBuffer* buf = NULL; - switch (mode) { - case 0: - buf = new RE_DummyShadowBuffer(); - break; - case 1: - /* loop to the old c-based buffer */ - /* memory release is done implicitly! */ - initshadowbuf(lar, mat); - break; - case 2: - buf = new RE_BasicShadowBuffer(lar, mat); - break; - case 3: -// cout << "Deep shadow buffer requested\n"; - break; - default: -// cerr << "Bad shadow buffer type specified\n"; - ; /* nada */ - } - return (RE_ShadowBufferHandle) buf; -} - -void RE_deleteShadowBuffer(RE_ShadowBufferHandle buf) -{ -// cout << "requesting buffer delete\n"; - assert(buf); - delete (RE_ShadowBuffer*) buf; -} - -void RE_buildShadowBuffer(RE_ShadowBufferHandle buf, - struct LampRen *lar) -{ - assert(buf); - ((RE_ShadowBuffer*) buf)->importScene(lar); -} - - -void RE_testshadowbuf(RE_ShadowBufferHandle buf, - struct ShadBuf* shbp, - float inp, - float* shadres) -{ - assert(buf); - ((RE_ShadowBuffer*) buf)->readShadowValue(shbp, inp, shadres); -} diff --git a/source/blender/render/intern/source/texture.c b/source/blender/render/intern/source/texture.c new file mode 100644 index 00000000000..587775d2602 --- /dev/null +++ b/source/blender/render/intern/source/texture.c @@ -0,0 +1,1872 @@ +/* texture.c + * + * + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#include +#include +#include +#include + +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifdef WIN32 +#include "BLI_winstuff.h" +#endif + +#include "MTC_matrixops.h" + +#include "BLI_blenlib.h" +#include "BLI_arithb.h" +#include "BLI_rand.h" + +#include "DNA_texture_types.h" +#include "DNA_object_types.h" +#include "DNA_lamp_types.h" +#include "DNA_mesh_types.h" +#include "DNA_material_types.h" +#include "DNA_image_types.h" + +#include "IMB_imbuf_types.h" +#include "IMB_imbuf.h" + +#include "BKE_osa_types.h" +#include "BKE_plugin_types.h" +#include "BKE_utildefines.h" + +#include "BKE_global.h" +#include "BKE_main.h" + +#include "BKE_library.h" +#include "BKE_image.h" +#include "BKE_texture.h" +#include "BKE_key.h" +#include "BKE_ipo.h" + +#include "render.h" +#include "rendercore.h" +#include "envmap.h" + +/* These vars form the texture channel */ +float Tin, Tr, Tg, Tb, Ta, Txtra; +extern int Talpha; + + +/* ------------------------------------------------------------------------- */ + +void init_render_texture(Tex *tex) +{ + Image *ima; + int imanr; + unsigned short numlen; + char name[256], head[FILE_MAXFILE], tail[FILE_MAXFILE]; + + /* is also used as signal */ + tex->nor= 0; + + /* imap test */ + if(tex->frames && tex->ima && tex->ima->name) { /* frames */ + strcpy(name, tex->ima->name); + + imanr= calcimanr(G.scene->r.cfra, tex); + + if(tex->imaflag & TEX_ANIM5) { + if(tex->ima->lastframe != imanr) { + if(tex->ima->ibuf) IMB_freeImBuf(tex->ima->ibuf); + tex->ima->ibuf= 0; + tex->ima->lastframe= imanr; + } + } + else { + /* for patch field-ima rendering */ + tex->ima->lastframe= imanr; + + BLI_stringdec(name, head, tail, &numlen); + BLI_stringenc(name, head, tail, numlen, imanr); + + ima= add_image(name); + + if(ima) { + ima->flag |= IMA_FROMANIM; + + if(tex->ima) tex->ima->id.us--; + tex->ima= ima; + + ima->ok= 1; + } + } + } + if(tex->imaflag & (TEX_ANTIALI+TEX_ANTISCALE)) { + if(tex->ima && tex->ima->lastqualityima->ibuf) IMB_freeImBuf(tex->ima->ibuf); + tex->ima->ibuf= 0; + } + } + + if(tex->type==TEX_PLUGIN) { + if(tex->plugin && tex->plugin->doit) { + if(tex->plugin->cfra) { + *(tex->plugin->cfra)= frame_to_float(G.scene->r.cfra); + } + } + } + else if(tex->type==TEX_ENVMAP) { + /* just in case */ + tex->imaflag= TEX_INTERPOL | TEX_MIPMAP; + tex->extend= TEX_CLIP; + + if(tex->env) { + if(R.flag & R_RENDERING) { + if(tex->env->stype==ENV_ANIM) RE_free_envmapdata(tex->env); + } + } + } +} + +/* ------------------------------------------------------------------------- */ + +void init_render_textures() +{ + Tex *tex; + + tex= G.main->tex.first; + while(tex) { + if(tex->id.us) init_render_texture(tex); + tex= tex->id.next; + } + + free_unused_animimages(); +} + +/* ------------------------------------------------------------------------- */ + +void end_render_texture(Tex *tex) +{ + + +} + +/* ------------------------------------------------------------------------- */ + +void end_render_textures() +{ + Tex *tex; + + tex= G.main->tex.first; + while(tex) { + if(tex->id.us) end_render_texture(tex); + tex= tex->id.next; + } + +} + + +/* ************************** */ + +static int clouds(Tex *tex, float *texvec) +{ + float (*turbfunc)(float, float, float, float, int); + + if(tex->noisetype==TEX_NOISESOFT) turbfunc= BLI_turbulence; + else turbfunc= BLI_turbulence1; + + Tin= turbfunc(tex->noisesize, texvec[0], texvec[1], texvec[2], tex->noisedepth); + + if(tex->stype==1) { + + Tr= Tin; + Tg= turbfunc(tex->noisesize, texvec[1], texvec[0], texvec[2], tex->noisedepth); + + Tb= turbfunc(tex->noisesize,texvec[1],texvec[2],texvec[0], tex->noisedepth); + + BRICONRGB; + Ta= 1.0; + + return 1; + } + + BRICON; + + if(tex->flag & TEX_COLORBAND) return do_colorband(tex->coba); + + return 0; +} + +/* ------------------------------------------------------------------------- */ + +static int blend(Tex *tex, float *texvec) +{ + float x, y, t; + + if(tex->flag & TEX_FLIPBLEND) { + x= texvec[1]; + y= texvec[0]; + } + else { + x= texvec[0]; + y= texvec[1]; + } + + if(tex->stype==0) { /* lin */ + Tin= (1.0+x)/2.0; + } + else if(tex->stype==1) { /* quad */ + Tin= (1.0+x)/2.0; + if(Tin<0.0) Tin= 0.0; + else Tin*= Tin; + } + else if(tex->stype==2) { /* ease */ + Tin= (1.0+x)/2.0; + if(Tin<=.0) Tin= 0.0; + else if(Tin>=1.0) Tin= 1.0; + else { + t= Tin*Tin; + Tin= (3.0*t-2.0*t*Tin); + } + } + else if(tex->stype==3) { /* diag */ + Tin= (2.0+x+y)/4.0; + } + else { /* sphere */ + Tin= 1.0-sqrt(x*x+ y*y+texvec[2]*texvec[2]); + if(Tin<0.0) Tin= 0.0; + if(tex->stype==5) Tin*= Tin; /* halo */ + } + + BRICON; + if(tex->flag & TEX_COLORBAND) return do_colorband(tex->coba); + + return 0; +} + +/* ------------------------------------------------------------------------- */ + +static int wood(Tex *tex, float *texvec) +{ + float (*noisefunc)(float, float, float, float); + + if(tex->noisetype==TEX_NOISESOFT) noisefunc= BLI_hnoise; + else noisefunc= BLI_hnoisep; + + + if(tex->stype==0) { + Tin= 0.5+0.5*sin( (texvec[0]+texvec[1]+texvec[2])*10.0 ); + } + else if(tex->stype==1) { + Tin= 0.5+0.5*sin( sqrt(texvec[0]*texvec[0]+texvec[1]*texvec[1]+texvec[2]*texvec[2])*20.0 ); + } + else if(tex->stype==2) { + Tin= noisefunc(tex->noisesize, texvec[0], texvec[1], texvec[2]); + Tin= 0.5+ 0.5*sin(tex->turbul*Tin+(texvec[0]+texvec[1]+texvec[2])*10.0); + } + else if(tex->stype==3) { + Tin= noisefunc(tex->noisesize, texvec[0], texvec[1], texvec[2]); + Tin= 0.5+ 0.5*sin(tex->turbul*Tin+(sqrt(texvec[0]*texvec[0]+texvec[1]*texvec[1]+texvec[2]*texvec[2]))*20.0); + } + + + BRICON; + if(tex->flag & TEX_COLORBAND) return do_colorband(tex->coba); + + return 0; +} + +/* ------------------------------------------------------------------------- */ + +static int marble(Tex *tex, float *texvec) +{ + float n; + float (*turbfunc)(float, float, float, float, int); + + if(tex->noisetype==TEX_NOISESOFT) turbfunc= BLI_turbulence; + else turbfunc= BLI_turbulence1; + + n= 5.0*(texvec[0]+texvec[1]+texvec[2]); + + Tin = 0.5+0.5*sin(n+tex->turbul*turbfunc(tex->noisesize, texvec[0],texvec[1],texvec[2], tex->noisedepth)); + + switch (tex->stype) { + case 1: + Tin= sqrt(Tin); + break; + case 2: + Tin= sqrt(Tin); + Tin= sqrt(Tin); + break; + } + + BRICON; + if(tex->flag & TEX_COLORBAND) return do_colorband(tex->coba); + + return 0; +} + +/* ------------------------------------------------------------------------- */ + +static int magic(Tex *tex, float *texvec) +{ + float x, y, z, turb=1.0; + int n; + + n= tex->noisedepth; + turb= tex->turbul/5.0; + + x= sin( ( texvec[0]+texvec[1]+texvec[2])*5.0 ); + y= cos( (-texvec[0]+texvec[1]-texvec[2])*5.0 ); + z= -cos( (-texvec[0]-texvec[1]+texvec[2])*5.0 ); + if(n>0) { + x*= turb; + y*= turb; + z*= turb; + y= -cos(x-y+z); + y*= turb; + if(n>1) { + x= cos(x-y-z); + x*= turb; + if(n>2) { + z= sin(-x-y-z); + z*= turb; + if(n>3) { + x= -cos(-x+y-z); + x*= turb; + if(n>4) { + y= -sin(-x+y+z); + y*= turb; + if(n>5) { + y= -cos(-x+y+z); + y*= turb; + if(n>6) { + x= cos(x+y+z); + x*= turb; + if(n>7) { + z= sin(x+y-z); + z*= turb; + if(n>8) { + x= -cos(-x-y+z); + x*= turb; + if(n>9) { + y= -sin(x-y+z); + y*= turb; + } + } + } + } + } + } + } + } + } + } + + if(turb!=0.0) { + turb*= 2.0; + x/= turb; + y/= turb; + z/= turb; + } + Tr= 0.5-x; + Tg= 0.5-y; + Tb= 0.5-z; + + BRICONRGB; + Ta= 1.0; + + return 1; +} + +/* ------------------------------------------------------------------------- */ + +static int stucci(Tex *tex, float *texvec) +{ + float b2, vec[3]; + float ofs; + float (*noisefunc)(float, float, float, float); + + if(tex->nor == NULL) return 0; + + if(tex->noisetype==TEX_NOISESOFT) noisefunc= BLI_hnoise; + else noisefunc= BLI_hnoisep; + + ofs= tex->turbul/200.0; + + b2= noisefunc(tex->noisesize, texvec[0], texvec[1], texvec[2]); + if(tex->stype) ofs*=(b2*b2); + vec[0]= b2-noisefunc(tex->noisesize, texvec[0]+ofs, texvec[1], texvec[2]); + vec[1]= b2-noisefunc(tex->noisesize, texvec[0], texvec[1]+ofs, texvec[2]); + vec[2]= b2-noisefunc(tex->noisesize, texvec[0], texvec[1], texvec[2]+ofs); + + if(tex->stype==1) { + tex->nor[0]= vec[0]; + tex->nor[1]= vec[1]; + tex->nor[2]= vec[2]; + } + else { + tex->nor[0]= -vec[0]; + tex->nor[1]= -vec[1]; + tex->nor[2]= -vec[2]; + } + + return 2; +} + +/* ------------------------------------------------------------------------- */ + +static int texnoise(Tex *tex) +{ + float div=3.0; + int val, ran, loop; + + ran= BLI_rand(); + val= (ran & 3); + + loop= tex->noisedepth; + while(loop--) { + ran= (ran>>2); + val*= (ran & 3); + div*= 3.0; + } + + Tin= ((float)val)/div;; + + BRICON; + if(tex->flag & TEX_COLORBAND) return do_colorband(tex->coba); + + return 0; +} + +/* ------------------------------------------------------------------------- */ + +static int plugintex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex) +{ + PluginTex *pit; + int rgbnor=0; + + Tin= 0.0; + + pit= tex->plugin; + if(pit && pit->doit) { + VECCOPY(pit->result+5, tex->nor); + + if(osatex) rgbnor= ((TexDoit)pit->doit)(tex->stype, pit->data, texvec, dxt, dyt); + else rgbnor= ((TexDoit)pit->doit)(tex->stype, pit->data, texvec, 0, 0); + + Tin= pit->result[0]; + + if(rgbnor & TEX_NOR) { + if(tex->nor) { + VECCOPY(tex->nor, pit->result+5); + } + } + + if(rgbnor & TEX_RGB) { + Tr= pit->result[1]; + Tg= pit->result[2]; + Tb= pit->result[3]; + Ta= pit->result[4]; + + BRICONRGB; + } + + BRICON; + if(tex->flag & TEX_COLORBAND) rgbnor |= do_colorband(tex->coba); + } + + return rgbnor; +} + +/* *************** PROJECTIONS ******************* */ + +void tubemap(float x, float y, float z, float *adr1, float *adr2) +{ + float len; + + *adr2 = (z + 1.0) / 2.0; + + len= sqrt(x*x+y*y); + if(len>0) { + *adr1 = (1.0 - (atan2(x/len,y/len) / M_PI)) / 2.0; + } +} + +/* ------------------------------------------------------------------------- */ + +void spheremap(float x, float y, float z, float *adr1, float *adr2) +{ + float len; + + len= sqrt(x*x+y*y+z*z); + if(len>0.0) { + + if(x==0.0 && y==0.0) *adr1= 0.0; /* othwise domain error */ + else *adr1 = (1.0 - atan2(x,y)/M_PI )/2.0; + + z/=len; + *adr2 = 1.0- saacos(z)/M_PI; + } +} + +/* ------------------------------------------------------------------------- */ + +static int cubemap_glob(MTex *mtex, VlakRen *vlr, float x, float y, float z, float *adr1, float *adr2) +{ + float x1, y1, z1, nor[3]; + int ret; + + if(vlr==NULL) return 0; + + VECCOPY(nor, vlr->n); + MTC_Mat4Mul3Vecfl(R.viewinv, nor); + + x1= fabs(nor[0]); + y1= fabs(nor[1]); + z1= fabs(nor[2]); + + if(z1>=x1 && z1>=y1) { + *adr1 = (x + 1.0) / 2.0; + *adr2 = (y + 1.0) / 2.0; + ret= 0; + } + else if(y1>=x1 && y1>=z1) { + *adr1 = (x + 1.0) / 2.0; + *adr2 = (z + 1.0) / 2.0; + ret= 1; + } + else { + *adr1 = (y + 1.0) / 2.0; + *adr2 = (z + 1.0) / 2.0; + ret= 2; + } + return ret; +} + +/* ------------------------------------------------------------------------- */ + +static int cubemap(MTex *mtex, VlakRen *vlr, float x, float y, float z, float *adr1, float *adr2) +{ + int proj[4], ret= 0; + + if(vlr && vlr->mface) { + int index; + /* the mtex->proj{xyz} have type char. maybe this should be wider? */ + /* casting to int ensures that the index type is right. */ + index = (int) mtex->projx; + proj[index]= ME_PROJXY; + + index = (int) mtex->projy; + proj[index]= ME_PROJXZ; + + index = (int) mtex->projz; + proj[index]= ME_PROJYZ; + + if(vlr->mface->puno & proj[1]) { + *adr1 = (x + 1.0) / 2.0; + *adr2 = (y + 1.0) / 2.0; + } + else if(vlr->mface->puno & proj[2]) { + *adr1 = (x + 1.0) / 2.0; + *adr2 = (z + 1.0) / 2.0; + ret= 1; + } + else { + *adr1 = (y + 1.0) / 2.0; + *adr2 = (z + 1.0) / 2.0; + ret= 2; + } + } else + return cubemap_glob(mtex, vlr, x, y, z, adr1, adr2); + + return ret; +} + +/* ------------------------------------------------------------------------- */ + +static int cubemap_ob(MTex *mtex, VlakRen *vlr, float x, float y, float z, float *adr1, float *adr2) +{ + float x1, y1, z1, nor[3]; + int ret; + + if(vlr==NULL) return 0; + + VECCOPY(nor, vlr->n); + if(mtex->object) MTC_Mat4Mul3Vecfl(mtex->object->imat, nor); + + x1= fabs(nor[0]); + y1= fabs(nor[1]); + z1= fabs(nor[2]); + + if(z1>=x1 && z1>=y1) { + *adr1 = (x + 1.0) / 2.0; + *adr2 = (y + 1.0) / 2.0; + ret= 0; + } + else if(y1>=x1 && y1>=z1) { + *adr1 = (x + 1.0) / 2.0; + *adr2 = (z + 1.0) / 2.0; + ret= 1; + } + else { + *adr1 = (y + 1.0) / 2.0; + *adr2 = (z + 1.0) / 2.0; + ret= 2; + } + return ret; +} + +/* ------------------------------------------------------------------------- */ + +static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *dxt, float *dyt) +{ + Tex *tex; + float fx, fy, fac1, area[8]; + int ok, proj, areaflag= 0, wrap; + + wrap= mtex->mapping; + tex= mtex->tex; + + if(R.osa==0) { + + if(wrap==MTEX_FLAT) { + fx = (t[0] + 1.0) / 2.0; + fy = (t[1] + 1.0) / 2.0; + } + else if(wrap==MTEX_TUBE) tubemap(t[0], t[1], t[2], &fx, &fy); + else if(wrap==MTEX_SPHERE) spheremap(t[0], t[1], t[2], &fx, &fy); + else { + if(mtex->texco==TEXCO_OBJECT) cubemap_ob(mtex, vlr, t[0], t[1], t[2], &fx, &fy); + else if(mtex->texco==TEXCO_GLOB) cubemap_glob(mtex, vlr, t[0], t[1], t[2], &fx, &fy); + else cubemap(mtex, vlr, t[0], t[1], t[2], &fx, &fy); + } + + /* repeat */ + if(tex->xrepeat>1) { + fx *= tex->xrepeat; + if(fx>1.0) fx -= (int)(fx); + else if(fx<0.0) fx+= 1-(int)(fx); + } + if(tex->yrepeat>1) { + fy *= tex->yrepeat; + if(fy>1.0) fy -= (int)(fy); + else if(fy<0.0) fy+= 1-(int)(fy); + } + + /* crop */ + if(tex->cropxmin!=0.0 || tex->cropxmax!=1.0) { + fac1= tex->cropxmax - tex->cropxmin; + fx= tex->cropxmin+ fx*fac1; + } + if(tex->cropymin!=0.0 || tex->cropymax!=1.0) { + fac1= tex->cropymax - tex->cropymin; + fy= tex->cropymin+ fy*fac1; + } + + t[0]= fx; + t[1]= fy; + } + else { + + if(wrap==MTEX_FLAT) { + fx= (t[0] + 1.0) / 2.0; + fy= (t[1] + 1.0) / 2.0; + dxt[0]/= 2.0; + dxt[1]/= 2.0; + dyt[0]/= 2.0; + dyt[1]/= 2.0; + } + else if ELEM(wrap, MTEX_TUBE, MTEX_SPHERE) { + /* exception: the seam behind (y<0.0) */ + ok= 1; + if(t[1]<=0.0) { + fx= t[0]+dxt[0]; + fy= t[0]+dyt[0]; + if(fx>=0.0 && fy>=0.0 && t[0]>=0.0); + else if(fx<=0.0 && fy<=0.0 && t[0]<=0.0); + else ok= 0; + } + if(ok) { + if(wrap==MTEX_TUBE) { + tubemap(t[0], t[1], t[2], area, area+1); + tubemap(t[0]+dxt[0], t[1]+dxt[1], t[2]+dxt[2], area+2, area+3); + tubemap(t[0]+dyt[0], t[1]+dyt[1], t[2]+dyt[2], area+4, area+5); + } + else { + spheremap(t[0], t[1], t[2],area,area+1); + spheremap(t[0]+dxt[0], t[1]+dxt[1], t[2]+dxt[2], area+2, area+3); + spheremap(t[0]+dyt[0], t[1]+dyt[1], t[2]+dyt[2], area+4, area+5); + } + areaflag= 1; + } + else { + if(wrap==MTEX_TUBE) tubemap(t[0], t[1], t[2], &fx, &fy); + else spheremap(t[0], t[1], t[2], &fx, &fy); + dxt[0]/= 2.0; + dxt[1]/= 2.0; + dyt[0]/= 2.0; + dyt[1]/= 2.0; + } + } + else { + + if(mtex->texco==TEXCO_OBJECT) proj = cubemap_ob(mtex, vlr, t[0], t[1], t[2], &fx, &fy); + else if (mtex->texco==TEXCO_GLOB) proj = cubemap_glob(mtex, vlr, t[0], t[1], t[2], &fx, &fy); + else proj = cubemap(mtex, vlr, t[0], t[1], t[2], &fx, &fy); + + if(proj==1) { + dxt[1]= dxt[2]; + dyt[1]= dyt[2]; + } + else if(proj==2) { + dxt[0]= dxt[1]; + dyt[0]= dyt[1]; + dxt[1]= dxt[2]; + dyt[1]= dyt[2]; + } + dxt[0]/= 2.0; + dxt[1]/= 2.0; + dyt[0]/= 2.0; + dyt[1]/= 2.0; + } + + /* if area, then reacalculate dxt[] and dyt[] */ + if(areaflag) { + fx= area[0]; + fy= area[1]; + dxt[0]= area[2]-fx; + dxt[1]= area[3]-fy; + dyt[0]= area[4]-fx; + dyt[1]= area[5]-fy; + } + + /* repeat */ + if(tex->xrepeat>1) { + fx *= tex->xrepeat; + dxt[0]*= tex->xrepeat; + dyt[0]*= tex->xrepeat; + if(fx>1.0) fx -= (int)(fx); + else if(fx<0.0) fx+= 1-(int)(fx); + } + if(tex->yrepeat>1) { + fy *= tex->yrepeat; + dxt[1]*= tex->yrepeat; + dyt[1]*= tex->yrepeat; + if(fy>1.0) fy -= (int)(fy); + else if(fy<0.0) fy+= 1-(int)(fy); + } + + /* crop */ + if(tex->cropxmin!=0.0 || tex->cropxmax!=1.0) { + fac1= tex->cropxmax - tex->cropxmin; + fx= tex->cropxmin+ fx*fac1; + dxt[0]*= fac1; + dyt[0]*= fac1; + } + if(tex->cropymin!=0.0 || tex->cropymax!=1.0) { + fac1= tex->cropymax - tex->cropymin; + fy= tex->cropymin+ fy*fac1; + dxt[1]*= fac1; + dyt[1]*= fac1; + } + + t[0]= fx; + t[1]= fy; + + } +} + + +/* ************************************** */ + +int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex) +{ + + switch(tex->type) { + + case 0: + Tin= 0.0; + return 0; + case TEX_CLOUDS: + return clouds(tex, texvec); + case TEX_WOOD: + return wood(tex, texvec); + case TEX_MARBLE: + return marble(tex, texvec); + case TEX_MAGIC: + return magic(tex, texvec); + case TEX_BLEND: + return blend(tex, texvec); + case TEX_STUCCI: + Tin= 0.0; + return stucci(tex, texvec); + case TEX_NOISE: + return texnoise(tex); + case TEX_IMAGE: + if(osatex) return imagewraposa(tex, texvec, dxt, dyt); + else return imagewrap(tex, texvec); + break; + case TEX_PLUGIN: + return plugintex(tex, texvec, dxt, dyt, osatex); + break; + case TEX_ENVMAP: + return envmaptex(tex, texvec, dxt, dyt, osatex); + break; + } + return 0; +} + +/* ------------------------------------------------------------------------- */ + +void do_material_tex(ShadeInput *shi) +{ + Object *ob; + Material *mat_col, *mat_colspec, *mat_colmir, *mat_ref; + Material *mat_spec, *mat_har, *mat_emit, *mat_alpha, *mat_ray_mirr, *mat_translu; + MTex *mtex; + Tex *tex; + float *co = NULL, *dx = NULL, *dy = NULL, fact, + facm, factt, facmm, facmul = 0.0, stencilTin=1.0; + float texvec[3], dxt[3], dyt[3], tempvec[3], norvec[3], Tnor=1.0; + int tex_nr, rgbnor= 0; + + /* here: test flag if there's a tex (todo) */ + + mat_col=mat_colspec=mat_colmir=mat_ref=mat_spec=mat_har=mat_emit=mat_alpha=mat_ray_mirr=mat_translu= shi->mat; + + for(tex_nr=0; tex_nr<8; tex_nr++) { + + /* separate tex switching */ + if(shi->mat->septex & (1<mat->mtex[tex_nr]) { + mtex= shi->mat->mtex[tex_nr]; + + tex= mtex->tex; + if(tex==0) continue; + + /* which coords */ + if(mtex->texco==TEXCO_ORCO) { + co= shi->lo; dx= O.dxlo; dy= O.dylo; + } + else if(mtex->texco==TEXCO_STICKY) { + co= shi->sticky; dx= O.dxsticky; dy= O.dysticky; + } + else if(mtex->texco==TEXCO_OBJECT) { + ob= mtex->object; + if(ob) { + co= tempvec; + dx= dxt; + dy= dyt; + VECCOPY(tempvec, shi->co); + MTC_Mat4MulVecfl(ob->imat, tempvec); + if(shi->osatex) { + VECCOPY(dxt, O.dxco); + VECCOPY(dyt, O.dyco); + MTC_Mat4Mul3Vecfl(ob->imat, dxt); + MTC_Mat4Mul3Vecfl(ob->imat, dyt); + } + } + else { + /* if object doesn't exist, do not use orcos (not initialized) */ + co= shi->co; + dx= O.dxco; dy= O.dyco; + } + } + else if(mtex->texco==TEXCO_REFL) { + co= shi->ref; dx= O.dxref; dy= O.dyref; + } + else if(mtex->texco==TEXCO_NORM) { + co= shi->orn; dx= O.dxno; dy= O.dyno; + } + else if(mtex->texco==TEXCO_GLOB) { + co= shi->gl; dx= O.dxco; dy= O.dyco; + } + else if(mtex->texco==TEXCO_UV) { + co= shi->uv; dx= O.dxuv; dy= O.dyuv; + } + else if(mtex->texco==TEXCO_WINDOW) { + co= shi->winco; dx= O.dxwin; dy= O.dywin; + } + + /* de pointer defines if bumping happens */ + if(mtex->mapto & MAP_NORM) { + tex->nor= norvec; + norvec[0]= norvec[1]= norvec[2]= 0.0; + } + else tex->nor= 0; + + if(tex->type==TEX_IMAGE) { + + /* new: first swap coords, then map, then trans/scale */ + + /* placement */ + if(mtex->projx) texvec[0]= co[mtex->projx-1]; + else texvec[0]= 0.0; + if(mtex->projy) texvec[1]= co[mtex->projy-1]; + else texvec[1]= 0.0; + if(mtex->projz) texvec[2]= co[mtex->projz-1]; + else texvec[2]= 0.0; + + if(shi->osatex) { + + if(mtex->projx) { + dxt[0]= dx[mtex->projx-1]; + dyt[0]= dy[mtex->projx-1]; + } + else dxt[0]= 0.0; + if(mtex->projy) { + dxt[1]= dx[mtex->projy-1]; + dyt[1]= dy[mtex->projy-1]; + } + else dxt[1]= 0.0; + if(mtex->projx) { + dxt[2]= dx[mtex->projz-1]; + dyt[2]= dy[mtex->projz-1]; + } + else dxt[2]= 0.0; + } + + do_2d_mapping(mtex, texvec, shi->vlr, dxt, dyt); + + /* translate and scale */ + texvec[0]= mtex->size[0]*(texvec[0]-0.5) +mtex->ofs[0]+0.5; + texvec[1]= mtex->size[1]*(texvec[1]-0.5) +mtex->ofs[1]+0.5; + if(shi->osatex) { + dxt[0]= mtex->size[0]*dxt[0]; + dxt[1]= mtex->size[1]*dxt[1]; + dyt[0]= mtex->size[0]*dyt[0]; + dyt[1]= mtex->size[1]*dyt[1]; + } + } + else { + + /* placement */ + if(mtex->projx) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]); + else texvec[0]= mtex->size[0]*(mtex->ofs[0]); + + if(mtex->projy) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]); + else texvec[1]= mtex->size[1]*(mtex->ofs[1]); + + if(mtex->projz) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]); + else texvec[2]= mtex->size[2]*(mtex->ofs[2]); + + if(shi->osatex) { + if(mtex->projx) { + dxt[0]= mtex->size[0]*dx[mtex->projx-1]; + dyt[0]= mtex->size[0]*dy[mtex->projx-1]; + } + else dxt[0]= 0.0; + if(mtex->projy) { + dxt[1]= mtex->size[1]*dx[mtex->projy-1]; + dyt[1]= mtex->size[1]*dy[mtex->projy-1]; + } + else dxt[1]= 0.0; + if(mtex->projx) { + dxt[2]= mtex->size[2]*dx[mtex->projz-1]; + dyt[2]= mtex->size[2]*dy[mtex->projz-1]; + } + else dxt[2]= 0.0; + } + } + + rgbnor= multitex(tex, texvec, dxt, dyt, shi->osatex); + + /* texture output */ + + if( (rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) { + Tin= (0.35*Tr+0.45*Tg+0.2*Tb); + rgbnor-= 1; + } + if(mtex->texflag & MTEX_NEGATIVE) { + if(rgbnor & TEX_RGB) { + Tr= 1.0-Tr; + Tg= 1.0-Tg; + Tb= 1.0-Tb; + } + Tin= 1.0-Tin; + } + if(mtex->texflag & MTEX_STENCIL) { + if(rgbnor & TEX_RGB) { + fact= Ta; + Ta*= stencilTin; + stencilTin*= fact; + } + else { + fact= Tin; + Tin*= stencilTin; + stencilTin*= fact; + } + } + else { + Ta*= stencilTin; + Tnor*= stencilTin; + Tin*= stencilTin; + } + + if(tex->nor && (rgbnor & TEX_NOR)==0) { + /* make our own normal */ + if(rgbnor & TEX_RGB) { + tex->nor[0]= Tr; + tex->nor[1]= Tg; + tex->nor[2]= Tb; + } + else { + float co= 0.5*cos(Tin-0.5); + float si= 0.5*sin(Tin-0.5); + float f1, f2; + + f1= shi->vn[0]; + f2= shi->vn[1]; + tex->nor[0]= f1*co+f2*si; + tex->nor[1]= f2*co-f1*si; + f1= shi->vn[1]; + f2= shi->vn[2]; + tex->nor[1]= f1*co+f2*si; + tex->nor[2]= f2*co-f1*si; + } + } + + + /* mapping */ + if(mtex->mapto & (MAP_COL+MAP_COLSPEC+MAP_COLMIR)) { + + if((rgbnor & TEX_RGB)==0) { + Tr= mtex->r; + Tg= mtex->g; + Tb= mtex->b; + } + else if(mtex->mapto & MAP_ALPHA) { + if(mtex->texflag & MTEX_ALPHAMIX) Tin= Ta; + else Tin= stencilTin; + } + else Tin= Ta; + + fact= Tin*mtex->colfac; + facm= 1.0-fact; + if(mtex->blendtype==MTEX_MUL) facm= 1.0-mtex->colfac; + if(mtex->blendtype==MTEX_SUB) fact= -fact; + + if(mtex->mapto & MAP_COL) { + if(mtex->blendtype==MTEX_BLEND) { + shi->matren->r= (fact*Tr + facm*mat_col->r); + shi->matren->g= (fact*Tg + facm*mat_col->g); + shi->matren->b= (fact*Tb + facm*mat_col->b); + } + else if(mtex->blendtype==MTEX_MUL) { + shi->matren->r= (facm+fact*Tr)*mat_col->r; + shi->matren->g= (facm+fact*Tg)*mat_col->g; + shi->matren->b= (facm+fact*Tb)*mat_col->b; + } + else { + shi->matren->r= (fact*Tr + mat_col->r); + shi->matren->g= (fact*Tg + mat_col->g); + shi->matren->b= (fact*Tb + mat_col->b); + } + mat_col= shi->matren; + } + if(mtex->mapto & MAP_COLSPEC) { + if(mtex->blendtype==MTEX_BLEND) { + shi->matren->specr= (fact*Tr + facm*mat_colspec->specr); + shi->matren->specg= (fact*Tg + facm*mat_colspec->specg); + shi->matren->specb= (fact*Tb + facm*mat_colspec->specb); + } + else if(mtex->blendtype==MTEX_MUL) { + shi->matren->specr= (facm+fact*Tr)*mat_colspec->specr; + shi->matren->specg= (facm+fact*Tg)*mat_colspec->specg; + shi->matren->specb= (facm+fact*Tb)*mat_colspec->specb; + } + else { + shi->matren->specr= (fact*Tr + mat_colspec->specr); + shi->matren->specg= (fact*Tg + mat_colspec->specg); + shi->matren->specb= (fact*Tb + mat_colspec->specb); + } + mat_colspec= shi->matren; + } + if(mtex->mapto & MAP_COLMIR) { + if(mtex->blendtype==MTEX_BLEND) { + // exception for envmap only + if(tex->type==TEX_ENVMAP) { + shi->refcol[0]= fact + facm*shi->refcol[0]; + shi->refcol[1]= fact*Tr + facm*shi->refcol[1]; + shi->refcol[2]= fact*Tg + facm*shi->refcol[2]; + shi->refcol[3]= fact*Tb + facm*shi->refcol[3]; + } else { + shi->matren->mirr= fact*Tr + facm*mat_colmir->mirr; + shi->matren->mirg= fact*Tg + facm*mat_colmir->mirg; + shi->matren->mirb= fact*Tb + facm*mat_colmir->mirb; + } + } + else if(mtex->blendtype==MTEX_MUL) { + shi->matren->mirr= (facm+fact*Tr)*mat_colmir->mirr; + shi->matren->mirg= (facm+fact*Tg)*mat_colmir->mirg; + shi->matren->mirb= (facm+fact*Tb)*mat_colmir->mirb; + } + else { + shi->matren->mirr= (fact*Tr + mat_colmir->mirr); + shi->matren->mirg= (fact*Tg + mat_colmir->mirg); + shi->matren->mirb= (fact*Tb + mat_colmir->mirb); + } + mat_colmir= shi->matren; + } + } + if( (mtex->mapto & MAP_NORM) ) { + if(tex->nor) { + + if(mtex->maptoneg & MAP_NORM) tex->norfac= -mtex->norfac; + else tex->norfac= mtex->norfac; + + shi->vn[0]+= Tnor*tex->norfac*tex->nor[0]; + shi->vn[1]+= Tnor*tex->norfac*tex->nor[1]; + shi->vn[2]+= Tnor*tex->norfac*tex->nor[2]; + + Normalise(shi->vn); + + /* this makes sure the bump is passed on to the next texture */ + shi->orn[0]= shi->vn[0]; + shi->orn[1]= shi->vn[1]; + shi->orn[2]= shi->vn[2]; + + /* reflection vector */ + calc_R_ref(shi); + } + } + + if(mtex->mapto & MAP_VARS) { + if(rgbnor & TEX_RGB) { + if(Talpha) Tin= Ta; + else Tin= (0.35*Tr+0.45*Tg+0.2*Tb); + } + + fact= Tin*mtex->varfac; + facm= 1.0-fact; + if(mtex->blendtype==MTEX_MUL) facmul= 1.0-mtex->varfac; + if(mtex->blendtype==MTEX_SUB) fact= -fact; + + if(mtex->mapto & MAP_REF) { + if(mtex->maptoneg & MAP_REF) {factt= facm; facmm= fact;} + else {factt= fact; facmm= facm;} + + if(mtex->blendtype==MTEX_BLEND) + shi->matren->ref= factt*mtex->def_var+ facmm*mat_ref->ref; + else if(mtex->blendtype==MTEX_MUL) + shi->matren->ref= (facmul+factt)*mat_ref->ref; + else { + shi->matren->ref= factt+mat_ref->ref; + if(shi->matren->ref<0.0) shi->matren->ref= 0.0; + } + mat_ref= shi->matren; + } + if(mtex->mapto & MAP_SPEC) { + if(mtex->maptoneg & MAP_SPEC) {factt= facm; facmm= fact;} + else {factt= fact; facmm= facm;} + + if(mtex->blendtype==MTEX_BLEND) + shi->matren->spec= factt*mtex->def_var+ facmm*mat_spec->spec; + else if(mtex->blendtype==MTEX_MUL) + shi->matren->spec= (facmul+factt)*mat_spec->spec; + else { + shi->matren->spec= factt+mat_spec->spec; + if(shi->matren->spec<0.0) shi->matren->spec= 0.0; + } + mat_spec= shi->matren; + } + if(mtex->mapto & MAP_EMIT) { + if(mtex->maptoneg & MAP_EMIT) {factt= facm; facmm= fact;} + else {factt= fact; facmm= facm;} + + if(mtex->blendtype==MTEX_BLEND) + shi->matren->emit= factt*mtex->def_var+ facmm*mat_emit->emit; + else if(mtex->blendtype==MTEX_MUL) + shi->matren->emit= (facmul+factt)*mat_emit->emit; + else { + shi->matren->emit= factt+mat_emit->emit; + if(shi->matren->emit<0.0) shi->matren->emit= 0.0; + } + mat_emit= shi->matren; + } + if(mtex->mapto & MAP_ALPHA) { + if(mtex->maptoneg & MAP_ALPHA) {factt= facm; facmm= fact;} + else {factt= fact; facmm= facm;} + + if(mtex->blendtype==MTEX_BLEND) + shi->matren->alpha= factt*mtex->def_var+ facmm*mat_alpha->alpha; + else if(mtex->blendtype==MTEX_MUL) + shi->matren->alpha= (facmul+factt)*mat_alpha->alpha; + else { + shi->matren->alpha= factt+mat_alpha->alpha; + if(shi->matren->alpha<0.0) shi->matren->alpha= 0.0; + else if(shi->matren->alpha>1.0) shi->matren->alpha= 1.0; + } + mat_alpha= shi->matren; + } + if(mtex->mapto & MAP_HAR) { + if(mtex->maptoneg & MAP_HAR) {factt= facm; facmm= fact;} + else {factt= fact; facmm= facm;} + + if(mtex->blendtype==MTEX_BLEND) { + shi->matren->har= 128.0*factt*mtex->def_var+ facmm*mat_har->har; + } else if(mtex->blendtype==MTEX_MUL) { + shi->matren->har= (facmul+factt)*mat_har->har; + } else { + shi->matren->har= 128.0*factt+mat_har->har; + if(shi->matren->har<1) shi->matren->har= 1; + } + mat_har= shi->matren; + } + if(mtex->mapto & MAP_RAYMIRR) { + if(mtex->maptoneg & MAP_RAYMIRR) {factt= facm; facmm= fact;} + else {factt= fact; facmm= facm;} + + if(mtex->blendtype==MTEX_BLEND) + shi->matren->ray_mirror= factt*mtex->def_var+ facmm*mat_ray_mirr->ray_mirror; + else if(mtex->blendtype==MTEX_MUL) + shi->matren->ray_mirror= (facmul+factt)*mat_ray_mirr->ray_mirror; + else { + shi->matren->ray_mirror= factt+mat_ray_mirr->ray_mirror; + if(shi->matren->ray_mirror<0.0) shi->matren->ray_mirror= 0.0; + else if(shi->matren->ray_mirror>1.0) shi->matren->ray_mirror= 1.0; + } + mat_ray_mirr= shi->matren; + } + if(mtex->mapto & MAP_TRANSLU) { + if(mtex->maptoneg & MAP_TRANSLU) {factt= facm; facmm= fact;} + else {factt= fact; facmm= facm;} + + if(mtex->blendtype==MTEX_BLEND) + shi->matren->translucency= factt*mtex->def_var+ facmm*mat_translu->translucency; + else if(mtex->blendtype==MTEX_MUL) + shi->matren->translucency= (facmul+factt)*mat_translu->translucency; + else { + shi->matren->translucency= factt+mat_translu->translucency; + if(shi->matren->translucency<0.0) shi->matren->translucency= 0.0; + else if(shi->matren->translucency>1.0) shi->matren->translucency= 1.0; + } + mat_translu= shi->matren; + } + } + } + } +} + +/* ------------------------------------------------------------------------- */ + +void do_halo_tex(HaloRen *har, float xn, float yn, float *colf) +{ + MTex *mtex; + float texvec[3], dxt[3], dyt[3], fact, facm, dx; + int rgb, osatex; + + mtex= har->mat->mtex[0]; + if(mtex->tex==0) return; + /* no normal mapping */ + mtex->tex->nor= 0; + + texvec[0]= xn/har->rad; + texvec[1]= yn/har->rad; + texvec[2]= 0.0; + + osatex= (har->mat->texco & TEXCO_OSA); + + /* placement */ + if(mtex->projx) texvec[0]= mtex->size[0]*(texvec[mtex->projx-1]+mtex->ofs[0]); + else texvec[0]= mtex->size[0]*(mtex->ofs[0]); + + if(mtex->projy) texvec[1]= mtex->size[1]*(texvec[mtex->projy-1]+mtex->ofs[1]); + else texvec[1]= mtex->size[1]*(mtex->ofs[1]); + + if(mtex->projz) texvec[2]= mtex->size[2]*(texvec[mtex->projz-1]+mtex->ofs[2]); + else texvec[2]= mtex->size[2]*(mtex->ofs[2]); + + if(osatex) { + + dx= 1.0/har->rad; + + if(mtex->projx) { + dxt[0]= mtex->size[0]*dx; + dyt[0]= mtex->size[0]*dx; + } + else dxt[0]= 0.0; + if(mtex->projy) { + dxt[1]= mtex->size[1]*dx; + dyt[1]= mtex->size[1]*dx; + } + else dxt[1]= 0.0; + if(mtex->projz) { + dxt[2]= 0.0; + dyt[2]= 0.0; + } + else dxt[2]= 0.0; + + } + + if(mtex->tex->type==TEX_IMAGE) do_2d_mapping(mtex, texvec, NULL, dxt, dyt); + + rgb= multitex(mtex->tex, texvec, dxt, dyt, osatex); + + /* texture output */ + if(rgb && (mtex->texflag & MTEX_RGBTOINT)) { + Tin= (0.35*Tr+0.45*Tg+0.2*Tb); + rgb= 0; + } + if(mtex->texflag & MTEX_NEGATIVE) { + if(rgb) { + Tr= 1.0-Tr; + Tg= 1.0-Tg; + Tb= 1.0-Tb; + } + else Tin= 1.0-Tin; + } + + /* mapping */ + if(mtex->mapto & MAP_COL) { + + if(rgb==0) { + Tr= mtex->r; + Tg= mtex->g; + Tb= mtex->b; + } + else if(mtex->mapto & MAP_ALPHA) { + if(mtex->texflag & MTEX_ALPHAMIX) Tin= Ta; + else Tin= 1.0; + } + else Tin= Ta; + + fact= Tin*mtex->colfac; + facm= 1.0-fact; + + if(mtex->blendtype==MTEX_MUL) { + facm= 1.0-mtex->colfac; + } + else fact*= 256; + + if(mtex->blendtype==MTEX_SUB) fact= -fact; + + if(mtex->blendtype==MTEX_BLEND) { + colf[0]= (fact*Tr + facm*har->r); + colf[1]= (fact*Tg + facm*har->g); + colf[2]= (fact*Tb + facm*har->b); + } + else if(mtex->blendtype==MTEX_MUL) { + colf[0]= (facm+fact*Tr)*har->r; + colf[1]= (facm+fact*Tg)*har->g; + colf[2]= (facm+fact*Tb)*har->b; + } + else { + colf[0]= (fact*Tr + har->r); + colf[1]= (fact*Tg + har->g); + colf[2]= (fact*Tb + har->b); + + CLAMP(colf[0], 0.0, 1.0); + CLAMP(colf[1], 0.0, 1.0); + CLAMP(colf[2], 0.0, 1.0); + } + } + if(mtex->mapto & MAP_ALPHA) { + if(rgb) { + if(Talpha) Tin= Ta; + else Tin= (0.35*Tr+0.45*Tg+0.2*Tb); + } + + colf[3]*= Tin; + } +} + +/* ------------------------------------------------------------------------- */ + +void do_sky_tex(float *lo) +{ + World *wrld_hor, *wrld_zen; + MTex *mtex; + float *co, fact, facm, factt, facmm, facmul = 0.0, stencilTin=1.0; + float tempvec[3], texvec[3], dxt[3], dyt[3]; + int tex_nr, rgb= 0, ok; + + + /* todo: add flag to test if there's a tex */ + + wrld_hor= wrld_zen= G.scene->world; + + /* The 6 here is the max amount of channels for a world */ + for(tex_nr=0; tex_nr<6; tex_nr++) { + if(R.wrld.mtex[tex_nr]) { + mtex= R.wrld.mtex[tex_nr]; + + if(mtex->tex==0) continue; + /* if(mtex->mapto==0) continue; */ + + /* which coords */ + co= lo; + + /* Grab the mapping settings for this texture */ + if(mtex->texco==TEXCO_OBJECT) { + Object *ob= mtex->object; + if(ob) { + VECCOPY(tempvec, lo); + MTC_Mat4MulVecfl(ob->imat, tempvec); + co= tempvec; + } + } + + /* placement */ + if(mtex->projx) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]); + else texvec[0]= mtex->size[0]*(mtex->ofs[0]); + + if(mtex->projy) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]); + else texvec[1]= mtex->size[1]*(mtex->ofs[1]); + + if(mtex->projz) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]); + else texvec[2]= mtex->size[2]*(mtex->ofs[2]); + + /* texture */ + if(mtex->tex->type==TEX_IMAGE) do_2d_mapping(mtex, texvec, NULL, dxt, dyt); + + rgb= multitex(mtex->tex, texvec, dxt, dyt, 0); + + /* texture output */ + if(rgb && (mtex->texflag & MTEX_RGBTOINT)) { + Tin= (0.35*Tr+0.45*Tg+0.2*Tb); + rgb= 0; + } + if(mtex->texflag & MTEX_NEGATIVE) { + if(rgb) { + Tr= 1.0-Tr; + Tg= 1.0-Tg; + Tb= 1.0-Tb; + } + else Tin= 1.0-Tin; + } + if(mtex->texflag & MTEX_STENCIL) { + if(rgb) { + + } + else { + fact= Tin; + Tin*= stencilTin; + stencilTin*= fact; + } + } + else { + if(rgb) ; + else Tin*= stencilTin; + } + + /* colour mapping */ + if(mtex->mapto & (WOMAP_HORIZ+WOMAP_ZENUP+WOMAP_ZENDOWN)) { + + if(rgb==0) { + Tr= mtex->r; + Tg= mtex->g; + Tb= mtex->b; + } + else Tin= 1.0; + + fact= Tin*mtex->colfac; + facm= 1.0-fact; + if(mtex->blendtype==MTEX_MUL) facm= 1.0-mtex->colfac; + if(mtex->blendtype==MTEX_SUB) fact= -fact; + + if(mtex->mapto & WOMAP_HORIZ) { + if(mtex->blendtype==MTEX_BLEND) { + R.wrld.horr= (fact*Tr + facm*wrld_hor->horr); + R.wrld.horg= (fact*Tg + facm*wrld_hor->horg); + R.wrld.horb= (fact*Tb + facm*wrld_hor->horb); + } + else if(mtex->blendtype==MTEX_MUL) { + R.wrld.horr= (facm+fact*Tr)*wrld_hor->horr; + R.wrld.horg= (facm+fact*Tg)*wrld_hor->horg; + R.wrld.horb= (facm+fact*Tb)*wrld_hor->horb; + } + else { + R.wrld.horr= (fact*Tr + wrld_hor->horr); + R.wrld.horg= (fact*Tg + wrld_hor->horg); + R.wrld.horb= (fact*Tb + wrld_hor->horb); + } + wrld_hor= &R.wrld; + } + if(mtex->mapto & (WOMAP_ZENUP+WOMAP_ZENDOWN)) { + ok= 0; + if(R.wrld.skytype & WO_SKYREAL) { + if((R.wrld.skytype & WO_ZENUP)) { + if(mtex->mapto & WOMAP_ZENUP) ok= 1; + } + else if(mtex->mapto & WOMAP_ZENDOWN) ok= 1; + } + else ok= 1; + + if(ok) { + + if(mtex->blendtype==MTEX_BLEND) { + R.wrld.zenr= (fact*Tr + facm*wrld_zen->zenr); + R.wrld.zeng= (fact*Tg + facm*wrld_zen->zeng); + R.wrld.zenb= (fact*Tb + facm*wrld_zen->zenb); + } + else if(mtex->blendtype==MTEX_MUL) { + R.wrld.zenr= (facm+fact*Tr)*wrld_zen->zenr; + R.wrld.zeng= (facm+fact*Tg)*wrld_zen->zeng; + R.wrld.zenb= (facm+fact*Tb)*wrld_zen->zenb; + } + else { + R.wrld.zenr= (fact*Tr + wrld_zen->zenr); + R.wrld.zeng= (fact*Tg + wrld_zen->zeng); + R.wrld.zenb= (fact*Tb + wrld_zen->zenb); + } + wrld_zen= &R.wrld; + } + else { + /* otherwise zenRGB undefined */ + R.wrld.zenr= wrld_zen->zenr; + R.wrld.zeng= wrld_zen->zeng; + R.wrld.zenb= wrld_zen->zenb; + } + } + } + if(mtex->mapto & WOMAP_BLEND) { + if(rgb) Tin= (0.35*Tr+0.45*Tg+0.2*Tb); + + fact= Tin*mtex->varfac; + facm= 1.0-fact; + if(mtex->blendtype==MTEX_MUL) facmul= 1.0-mtex->varfac; + if(mtex->blendtype==MTEX_SUB) fact= -fact; + + factt= fact; facmm= facm; + + if(mtex->blendtype==MTEX_BLEND) + R.inprz= factt*mtex->def_var+ facmm*R.inprz; + else if(mtex->blendtype==MTEX_MUL) + R.inprz= (facmul+factt)*R.inprz; + else { + R.inprz= factt+R.inprz; + } + } + } + } +} + +/* ------------------------------------------------------------------------- */ +/* explicit lampren stuff should be factored out! or rather, the + texturing stuff might need to go...*/ +void do_lamp_tex(LampRen *la, float *lavec, ShadeInput *shi) +{ + Object *ob; + LampRen *la_col; + MTex *mtex; + Tex *tex; + float *co = NULL, *dx = NULL, *dy = NULL, fact, facm, stencilTin=1.0; + float texvec[3], dxt[3], dyt[3], tempvec[3]; + int tex_nr, rgb= 0; + + la_col= la->org; + + tex_nr= 0; + + for(; tex_nr<6; tex_nr++) { + + if(la->mtex[tex_nr]) { + mtex= la->mtex[tex_nr]; + + tex= mtex->tex; + if(tex==0) continue; + + /* which coords */ + if(mtex->texco==TEXCO_OBJECT) { + ob= mtex->object; + if(ob) { + co= tempvec; + dx= dxt; + dy= dyt; + VECCOPY(tempvec, shi->co); + MTC_Mat4MulVecfl(ob->imat, tempvec); + if(shi->osatex) { + VECCOPY(dxt, O.dxco); + VECCOPY(dyt, O.dyco); + MTC_Mat4Mul3Vecfl(ob->imat, dxt); + MTC_Mat4Mul3Vecfl(ob->imat, dyt); + } + } + else { + co= shi->co; + dx= O.dxco; dy= O.dyco; + } + } + else if(mtex->texco==TEXCO_GLOB) { + co= shi->gl; dx= O.dxco; dy= O.dyco; + VECCOPY(shi->gl, shi->co); + MTC_Mat4MulVecfl(R.viewinv, shi->gl); + } + else if(mtex->texco==TEXCO_VIEW) { + + VECCOPY(tempvec, lavec); + MTC_Mat3MulVecfl(la->imat, tempvec); + + tempvec[0]*= la->spottexfac; + tempvec[1]*= la->spottexfac; + co= tempvec; + + dx= dxt; dy= dyt; + if(shi->osatex) { + VECCOPY(dxt, O.dxlv); + VECCOPY(dyt, O.dylv); + /* need some matrix conversion here? la->imat is a [3][3] matrix!!! **/ + MTC_Mat3MulVecfl(la->imat, dxt); + MTC_Mat3MulVecfl(la->imat, dyt); + + VecMulf(dxt, la->spottexfac); + VecMulf(dyt, la->spottexfac); + } + } + + + /* placement */ + if(mtex->projx) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]); + else texvec[0]= mtex->size[0]*(mtex->ofs[0]); + + if(mtex->projy) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]); + else texvec[1]= mtex->size[1]*(mtex->ofs[1]); + + if(mtex->projz) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]); + else texvec[2]= mtex->size[2]*(mtex->ofs[2]); + + if(shi->osatex) { + if(mtex->projx) { + dxt[0]= mtex->size[0]*dx[mtex->projx-1]; + dyt[0]= mtex->size[0]*dy[mtex->projx-1]; + } + else dxt[0]= 0.0; + if(mtex->projy) { + dxt[1]= mtex->size[1]*dx[mtex->projy-1]; + dyt[1]= mtex->size[1]*dy[mtex->projy-1]; + } + else dxt[1]= 0.0; + if(mtex->projx) { + dxt[2]= mtex->size[2]*dx[mtex->projz-1]; + dyt[2]= mtex->size[2]*dy[mtex->projz-1]; + } + else dxt[2]= 0.0; + } + + /* texture */ + if(tex->type==TEX_IMAGE) { + do_2d_mapping(mtex, texvec, NULL, dxt, dyt); + + if(mtex->mapto & MAP_NORM) { + /* the pointer defines if bump happens */ + tex->nor= shi->vn; + if(mtex->maptoneg & MAP_NORM) tex->norfac= -mtex->norfac; + else tex->norfac= mtex->norfac; + } + else tex->nor= 0; + } + + rgb= multitex(tex, texvec, dxt, dyt, shi->osatex); + + + + /* texture output */ + if(rgb && (mtex->texflag & MTEX_RGBTOINT)) { + Tin= (0.35*Tr+0.45*Tg+0.2*Tb); + rgb= 0; + } + if(mtex->texflag & MTEX_NEGATIVE) { + if(rgb) { + Tr= 1.0-Tr; + Tg= 1.0-Tg; + Tb= 1.0-Tb; + } + else Tin= 1.0-Tin; + } + if(mtex->texflag & MTEX_STENCIL) { + if(rgb) { + fact= Ta; + Ta*= stencilTin; + stencilTin*= fact; + } + else { + fact= Tin; + Tin*= stencilTin; + stencilTin*= fact; + } + } + else { + if(rgb) Ta*= stencilTin; + else Tin*= stencilTin; + } + + /* mapping */ + if(mtex->mapto & LAMAP_COL) { + + if(rgb==0) { + Tr= mtex->r; + Tg= mtex->g; + Tb= mtex->b; + } + else if(mtex->mapto & MAP_ALPHA) { + if(mtex->texflag & MTEX_ALPHAMIX) Tin= Ta; + else Tin= stencilTin; + } + else Tin= Ta; + + Tr*= la->energy; + Tg*= la->energy; + Tb*= la->energy; + + fact= Tin*mtex->colfac; + facm= 1.0-fact; + if(mtex->blendtype==MTEX_MUL) facm= 1.0-mtex->colfac; + if(mtex->blendtype==MTEX_SUB) fact= -fact; + + if(mtex->blendtype==MTEX_BLEND) { + la->r= (fact*Tr + facm*la_col->r); + la->g= (fact*Tg + facm*la_col->g); + la->b= (fact*Tb + facm*la_col->b); + } + else if(mtex->blendtype==MTEX_MUL) { + la->r= (facm+fact*Tr)*la_col->r; + la->g= (facm+fact*Tg)*la_col->g; + la->b= (facm+fact*Tb)*la_col->b; + } + else { + la->r= (fact*Tr + la_col->r); + la->g= (fact*Tg + la_col->g); + la->b= (fact*Tb + la_col->b); + } + la_col= la; /* Is it just me or is this a useless statement? */ + } + + } + } +} + +/* ------------------------------------------------------------------------- */ + +void externtex(MTex *mtex, float *vec) +{ + Tex *tex; + float dxt[3], dyt[3], texvec[3], dummy[3]; + int rgb; + + tex= mtex->tex; + if(tex==0) return; + + /* placement */ + if(mtex->projx) texvec[0]= mtex->size[0]*(vec[mtex->projx-1]+mtex->ofs[0]); + else texvec[0]= mtex->size[0]*(mtex->ofs[0]); + + if(mtex->projy) texvec[1]= mtex->size[1]*(vec[mtex->projy-1]+mtex->ofs[1]); + else texvec[1]= mtex->size[1]*(mtex->ofs[1]); + + if(mtex->projz) texvec[2]= mtex->size[2]*(vec[mtex->projz-1]+mtex->ofs[2]); + else texvec[2]= mtex->size[2]*(mtex->ofs[2]); + + /* texture */ + if(tex->type==TEX_IMAGE) { + do_2d_mapping(mtex, texvec, NULL, dxt, dyt); + + if(mtex->mapto & MAP_NORM) { + /* the pointer defines if there's bump */ + tex->nor= dummy; + if(mtex->maptoneg & MAP_NORM) tex->norfac= -mtex->norfac; + else tex->norfac= mtex->norfac; + } + else tex->nor= 0; + } + + rgb= multitex(tex, texvec, dxt, dyt, 0); + + if(rgb) { + Tin= (0.35*Tr+0.45*Tg+0.2*Tb); + } + else { + Tr= mtex->r; + Tg= mtex->g; + Tb= mtex->b; + } +} + +/* ------------------------------------------------------------------------- */ + +void externtexcol(MTex *mtex, float *orco, char *col) +{ + int temp; + float b1; + + if(mtex->tex==0) return; + + externtex(mtex, orco); + + b1= 1.0-Tin; + + temp= 255*(Tin*Tr)+b1*col[0]; + if(temp>255) col[0]= 255; else col[0]= temp; + temp= 255*(Tin*Tg)+b1*col[1]; + if(temp>255) col[1]= 255; else col[1]= temp; + temp= 255*(Tin*Tb)+b1*col[2]; + if(temp>255) col[2]= 255; else col[2]= temp; + +} + +/* ------------------------------------------------------------------------- */ + +void render_realtime_texture(ShadeInput *shi) +{ + static Tex tex; + static int firsttime= 1; + float texvec[2], dx[2], dy[2]; + + if(firsttime) { + default_tex(&tex); + tex.type= TEX_IMAGE; + firsttime= 0; + } + + tex.ima = shi->vlr->tface->tpage; + if(tex.ima) { + + texvec[0]= 0.5+0.5*shi->uv[0]; + texvec[1]= 0.5+0.5*shi->uv[1]; + if(shi->osatex) { + dx[0]= 0.5*O.dxuv[0]; + dx[1]= 0.5*O.dxuv[1]; + dy[0]= 0.5*O.dyuv[0]; + dy[1]= 0.5*O.dyuv[1]; + } + + if(shi->osatex) imagewraposa(&tex, texvec, dx, dy); + else imagewrap(&tex, texvec); + + shi->vcol[0]*= Tr; + shi->vcol[1]*= Tg; + shi->vcol[2]*= Tb; + } + + +} + +/* eof */ diff --git a/source/blender/render/intern/source/vanillaRenderPipe.c b/source/blender/render/intern/source/vanillaRenderPipe.c index 584b012eedd..f585327bf60 100644 --- a/source/blender/render/intern/source/vanillaRenderPipe.c +++ b/source/blender/render/intern/source/vanillaRenderPipe.c @@ -122,7 +122,7 @@ extern char *centmask; /* compute its colour on a point _on_ the face. */ /* guarantee we use valid coordinates. */ /* unsorted */ -extern float holoofs, fmask[256]; +extern float fmask[256]; extern unsigned short usegamtab, shortcol[4], *mask1[9], *mask2[9],/* *igamtab1, */ *igamtab2/*, *gamtab */; @@ -225,7 +225,7 @@ void zBufShadeAdvanced() y = 0; while ( (y < bufferHeight) && keepLooping) { calcZBufLine(y); - R.vlaknr= -1; /* huh? why reset this counter? for shadePixel! */ + renderZBufLine(y); transferColourBufferToOutput(y); @@ -435,10 +435,10 @@ int composeStack(int zrow[RE_MAX_FACES_PER_PIXEL][RE_PIXELFIELDSIZE], ys= (float)y+centLut[i >> 4]; /* stack face ----------- */ - stack[ptr].data = renderPixel(xs, ys, zrow[totvlak]); + stack[ptr].mask = zrow[totvlak][RE_MASK]; + stack[ptr].data = renderPixel(xs, ys, zrow[totvlak], stack[ptr].mask); stack[ptr].faceType = zrow[totvlak][RE_TYPE]; cpFloatColV(collector, stack[ptr].colour); - stack[ptr].mask = zrow[totvlak][RE_MASK]; /* This is done so that spothalos are properly overlayed on halos */ /* maybe we need to check the colour here... */ @@ -1468,9 +1468,10 @@ void eraseColBuf(RE_COLBUFTYPE *buf) { /* ------------------------------------------------------------------------- */ -int calcDepth(float x, float y, void* data, int type) +int calcDepth(float x, float y, void *data, int type) { - + float view[3]; + if (type & RE_POLY) { VlakRen* vlr = (VlakRen*) data; VertRen* v1; @@ -1483,31 +1484,28 @@ int calcDepth(float x, float y, void* data, int type) dvlak= v1->co[0]*vlr->n[0]+v1->co[1]*vlr->n[1]+v1->co[2]*vlr->n[2]; /* jitter has been added to x, y ! */ - /* view vector R.view: screen coords */ - if( (G.special1 & G_HOLO) && - ((Camera *)G.scene->camera->data)->flag & CAM_HOLO2) { - R.view[0]= (x+(R.xstart) + 0.5 +holoofs); - } else R.view[0]= (x+(R.xstart) + 0.5 ); + /* view vector view: screen coords */ + view[0]= (x+(R.xstart) + 0.5 ); if(R.flag & R_SEC_FIELD) { - if(R.r.mode & R_ODDFIELD) R.view[1]= (y + R.ystart)*R.ycor; - else R.view[1]= (y+R.ystart + 1.0)*R.ycor; - } else R.view[1]= (y+R.ystart + 0.5 )*R.ycor; + if(R.r.mode & R_ODDFIELD) view[1]= (y + R.ystart)*R.ycor; + else view[1]= (y+R.ystart + 1.0)*R.ycor; + } else view[1]= (y+R.ystart + 0.5 )*R.ycor; /* for pano, another rotation in the xz plane is needed.... */ /* this is ok, in WCS */ - R.view[2]= -R.viewfac; /* distance to viewplane */ + view[2]= -R.viewfac; /* distance to viewplane */ /* face normal dot view vector: but how can this work? */ - deler = MTC_dot3Float(vlr->n, R.view); + deler = MTC_dot3Float(vlr->n, view); if (deler!=0.0) fac = dvlak/deler; else fac = 0.0; /* indices are wrong.... but gives almost the right value? */ - hoco_z = (fac*R.view[2]) * R.winmat[2][2] + R.winmat[3][2]; - hoco_w = (fac*R.view[2]) * R.winmat[2][3] + R.winmat[3][3]; + hoco_z = (fac*view[2]) * R.winmat[2][2] + R.winmat[3][2]; + hoco_w = (fac*view[2]) * R.winmat[2][3] + R.winmat[3][3]; zbuf_co = 0x7FFFFFFF*(hoco_z/hoco_w); diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c index 6410bd44fa5..df34757adeb 100644 --- a/source/blender/render/intern/source/zbuf.c +++ b/source/blender/render/intern/source/zbuf.c @@ -2170,25 +2170,24 @@ int vergzvlak(const void *a1, const void *a2) return 0; } -void shadetrapixel(float x, float y, int vlak, int mask) +void shadetrapixel(float x, float y, int vlak, int mask, unsigned short *shortcol) { if( (vlak & 0x7FFFFF) > R.totvlak) { printf("error in shadetrapixel nr: %d\n", (vlak & 0x7FFFFF)); return; } - shadepixel(x, y, vlak, mask); + shadepixel_short(x, y, vlak, mask, shortcol); } extern unsigned short usegamtab; -extern unsigned short shortcol[4]; void abufsetrow(int y) { APixstr *ap, *apn; float xs, ys; int x, part, a, b, zrow[100][3], totvlak, alpha[32], tempgam, nr, intcol[4]; int sval, tempRf; - unsigned short *col, tempcol[4], sampcol[16*4], *scol; + unsigned short *col, shortcol[4], tempcol[4], sampcol[16*4], *scol; if(y<0) return; if(R.osa>16) { @@ -2253,7 +2252,7 @@ void abufsetrow(int y) else { xs= x; ys= y; } - shadetrapixel(xs, ys, ap->p[0], ap->mask[0]); + shadetrapixel(xs, ys, ap->p[0], ap->mask[0], shortcol); nr= count_mask(ap->mask[0]); if( (R.r.mode & R_OSA) && nr0) ) { - a= count_mask(zrow[totvlak-1][2]); - if(a==R.osa) break; - totvlak--; - - b= centmask[ zrow[totvlak][2] ]; - - xs= (float)x+centLut[b & 15]; - ys= (float)y+centLut[b>>4]; - - shadetrapixel(xs, ys, zrow[totvlak][1], zrow[totvlak][2]); - sval= addtosampcol(sampcol, shortcol, zrow[totvlak][2]); - } + /* sval==0: alpha completely full */ + while( (sval != 0) && (totvlak>0) ) { + a= count_mask(zrow[totvlak-1][2]); + if(a==R.osa) break; + totvlak--; + + b= centmask[ zrow[totvlak][2] ]; + + xs= (float)x+centLut[b & 15]; + ys= (float)y+centLut[b>>4]; + + shadetrapixel(xs, ys, zrow[totvlak][1], zrow[totvlak][2], shortcol); + sval= addtosampcol(sampcol, shortcol, zrow[totvlak][2]); + } scol= sampcol; intcol[0]= scol[0]; intcol[1]= scol[1]; intcol[2]= scol[2]; intcol[3]= scol[3]; @@ -2345,7 +2344,7 @@ void abufsetrow(int y) } } else addAlphaUnderShort(col, shortcol); - + if(col[3]>=0xFFF0) break; } } @@ -2353,7 +2352,7 @@ void abufsetrow(int y) } usegamtab= tempgam; - R.flag= tempRf; + R.flag= tempRf; } /* end of zbuf.c */ diff --git a/source/blender/renderconverter/intern/convertBlenderScene.c b/source/blender/renderconverter/intern/convertBlenderScene.c index 310000b8624..525fe566056 100644 --- a/source/blender/renderconverter/intern/convertBlenderScene.c +++ b/source/blender/renderconverter/intern/convertBlenderScene.c @@ -1883,32 +1883,12 @@ void RE_add_render_lamp(Object *ob, int doshadbuf) } } } - - if( (R.r.mode & R_SHADOW) && (lar->mode & LA_SHAD) - && (la->type==LA_SPOT) && doshadbuf ) { + + if( (R.r.mode & R_SHADOW) && (lar->mode & LA_SHAD) && (la->type==LA_SPOT) && doshadbuf ) { /* Per lamp, one shadow buffer is made. */ - if (R.r.mode & R_UNIFIED) { - int mode; - /* For the UR, I want to stick to the cpp version. I can - * put a switch here for the different shadow buffers. At - * this point, the type of shadow buffer is - * determined. The actual calculations are done during the - * render pre operations. */ - if (lar->mode & LA_DEEP_SHADOW) { - mode = 0; /* dummy, for testing */ - } else if (2) { - mode = 2; /* old-style buffer */ - } - lar->shadowBufOb = (void*) RE_createShadowBuffer(lar, - ob->obmat, - mode); - } else { - RE_createShadowBuffer(lar, - ob->obmat, - 1); /* mode = 1 is old buffer */ - } + RE_initshadowbuf(lar, ob->obmat); } - + lar->org= MEM_dupallocN(lar); } @@ -2704,12 +2684,6 @@ void RE_freeRotateBlenderScene(void) /* FREE */ for(a=0; ashadowBufOb) { - RE_deleteShadowBuffer((RE_ShadowBufferHandle) R.la[a]->shadowBufOb); - } - if(R.la[a]->shb) { shb= R.la[a]->shb; v= (shb->size*shb->size)/256; @@ -2821,8 +2795,6 @@ void RE_rotateBlenderScene(void) ob= ob->id.next; } - if(G.special1 & G_HOLO) RE_holoview(); - /* because of optimal calculation tracking/lattices/etc: and extra where_is_ob here */ base= G.scene->base.first; diff --git a/source/blender/src/previewrender.c b/source/blender/src/previewrender.c index 6bce6da18bf..417b259c1fe 100644 --- a/source/blender/src/previewrender.c +++ b/source/blender/src/previewrender.c @@ -53,9 +53,6 @@ #include "MTC_matrixops.h" -#include "render.h" -#include "mydevice.h" - #include "DNA_texture_types.h" #include "DNA_world_types.h" #include "DNA_camera_types.h" @@ -85,6 +82,8 @@ #include "PIL_time.h" #include "RE_renderconverter.h" +#include "render.h" +#include "mydevice.h" #define PR_RECTX 141 #define PR_RECTY 141 @@ -102,12 +101,7 @@ static float pr_facx, pr_facy; /* implementation */ -static short snijpunt(float *v1, - float *v2, - float *v3, - float *rtlabda, - float *ray1, - float *ray2) +static short snijpunt(float *v1, float *v2, float *v3, float *rtlabda, float *ray1, float *ray2) { float x0,x1,x2,t00,t01,t02,t10,t11,t12,t20,t21,t22; float m0,m1,m2,deeldet,det1,det2,det3; @@ -172,9 +166,7 @@ static int rcubi[3][4]= { {3, 0, 2, 6} }; -static int ray_previewrender(int x, - int y, - float *vec) +static int ray_previewrender(int x, int y, float *vec, float *vn) { float scalef= 12.8/100.0; float ray1[3], ray2[3]; @@ -205,7 +197,7 @@ static int ray_previewrender(int x, if(hitface > -1) { - CalcNormFloat(rcubev[rcubi[hitface][0]], rcubev[rcubi[hitface][1]], rcubev[rcubi[hitface][2]], R.vn); + CalcNormFloat(rcubev[rcubi[hitface][0]], rcubev[rcubi[hitface][1]], rcubev[rcubi[hitface][2]], vn); vec[0]= (minlabda*(ray1[0]-ray2[0])+ray2[0])/3.7; vec[1]= (minlabda*(ray1[1]-ray2[1])+ray2[1])/3.7; @@ -375,37 +367,38 @@ void BIF_previewdraw(void) static void sky_preview_pixel(float lens, int x, int y, char *rect) { + float view[3]; if(R.wrld.skytype & WO_SKYPAPER) { - R.view[0]= (2*x)/(float)PR_RECTX; - R.view[1]= (2*y)/(float)PR_RECTY; - R.view[2]= 0.0; + view[0]= (2*x)/(float)PR_RECTX; + view[1]= (2*y)/(float)PR_RECTY; + view[2]= 0.0; } else { - R.view[0]= x; - R.view[1]= y; - R.view[2]= -lens*PR_RECTX/32.0; - Normalise(R.view); + view[0]= x; + view[1]= y; + view[2]= -lens*PR_RECTX/32.0; + Normalise(view); } - RE_sky(rect); + RE_sky(view, rect); } -static void lamp_preview_pixel(LampRen *la, int x, int y, char *rect) +static void lamp_preview_pixel(ShadeInput *shi, LampRen *la, int x, int y, char *rect) { float inpr, i, t, dist, distkw, vec[3]; int col; - R.co[0]= (float)x/(PR_RECTX/4); - R.co[1]= (float)y/(PR_RECTX/4); - R.co[2]= 0; + shi->co[0]= (float)x/(PR_RECTX/4); + shi->co[1]= (float)y/(PR_RECTX/4); + shi->co[2]= 0; vec[0]= 0.02*x; vec[1]= 0.02*y; vec[2]= 0.005*PR_RECTX; - VECCOPY(R.view, vec); - dist= Normalise(R.view); + VECCOPY(shi->view, vec); + dist= Normalise(shi->view); - if(la->mode & LA_TEXTURE) do_lamp_tex(la, vec); + if(la->mode & LA_TEXTURE) do_lamp_tex(la, vec, shi); if(la->type==LA_SUN || la->type==LA_HEMI) { dist= 1.0; @@ -433,10 +426,10 @@ static void lamp_preview_pixel(LampRen *la, int x, int y, char *rect) if(la->mode & LA_SQUARE) { /* slightly smaller... */ - inpr= 1.7*cos(MAX2(fabs(R.view[0]/R.view[2]) , fabs(R.view[1]/R.view[2]) )); + inpr= 1.7*cos(MAX2(fabs(shi->view[0]/shi->view[2]) , fabs(shi->view[1]/shi->view[2]) )); } else { - inpr= R.view[2]; + inpr= shi->view[2]; } t= la->spotsi; @@ -453,7 +446,7 @@ static void lamp_preview_pixel(LampRen *la, int x, int y, char *rect) } dist*=inpr; } - else if(la->type==LA_LOCAL) dist*= R.view[2]; + else if(la->type==LA_LOCAL) dist*= shi->view[2]; col= 255.0*dist*la->r; if(col<=0) rect[0]= 0; else if(col>=255) rect[0]= 255; else rect[0]= col; @@ -578,7 +571,7 @@ static void previewflare(SpaceButs *sbuts, HaloRen *har, unsigned int *rect) extern float Tin, Tr, Tg, Tb, Ta; /* texture.c */ static void texture_preview_pixel(Tex *tex, int x, int y, char *rect) { - float i, v1, xsq, ysq, texvec[3]; + float i, v1, xsq, ysq, texvec[3], dummy[3]; int rgbnor, tracol, skip=0; if(tex->type==TEX_IMAGE) { @@ -634,12 +627,12 @@ static void texture_preview_pixel(Tex *tex, int x, int y, char *rect) /* does not return Tin */ if(tex->type==TEX_STUCCI) { - tex->nor= R.vn; - R.vn[0]= 1.0; - R.vn[1]= R.vn[2]= 0.0; + tex->nor= dummy; + dummy[0]= 1.0; + dummy[1]= dummy[2]= 0.0; } - if(skip==0) rgbnor= multitex(tex, texvec, 0, 0); + if(skip==0) rgbnor= multitex(tex, texvec, NULL, NULL, 0); else rgbnor= 1; if(rgbnor & 1) { @@ -705,7 +698,7 @@ static void refraction_prv(int *x, int *y, float *n, float index) } -static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth) +static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y,char *rect, int smooth) { extern float fresnel_fac(float *view, float *vn, float fresnel); Material *mat; @@ -716,7 +709,7 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth) int temp, a; char tracol; - mat= R.matren; + mat= shi->matren; v1= 1.0/PR_RECTX; view[0]= v1*x; @@ -724,12 +717,12 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth) view[2]= 1.0; Normalise(view); - R.refcol[0]= R.refcol[1]= R.refcol[2]= R.refcol[3]= 0.0; + shi->refcol[0]= shi->refcol[1]= shi->refcol[2]= shi->refcol[3]= 0.0; /* texture handling */ if(mat->texco) { - VECCOPY(R.lo, vec); + VECCOPY(shi->lo, vec); if(mat->pr_type==MA_CUBE) { @@ -738,50 +731,54 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth) eul[2]= (45)*M_PI/180.0; EulToMat3(eul, tmat); - MTC_Mat3MulVecfl(tmat, R.lo); - MTC_Mat3MulVecfl(tmat, R.vn); + MTC_Mat3MulVecfl(tmat, shi->lo); + MTC_Mat3MulVecfl(tmat, shi->vn); /* hack for cubemap, why!!! */ - SWAP(float, R.vn[0], R.vn[1]); + SWAP(float, shi->vn[0], shi->vn[1]); } if(mat->texco & TEXCO_GLOB) { - VECCOPY(R.gl, R.lo); + VECCOPY(shi->gl, shi->lo); } if(mat->texco & TEXCO_WINDOW) { - VECCOPY(R.winco, R.lo); + VECCOPY(shi->winco, shi->lo); } if(mat->texco & TEXCO_STICKY) { - VECCOPY(R.sticky, R.lo); + VECCOPY(shi->sticky, shi->lo); } if(mat->texco & TEXCO_UV) { - VECCOPY(R.uv, R.lo); + VECCOPY(shi->uv, shi->lo); } if(mat->texco & TEXCO_OBJECT) { - VECCOPY(R.co, R.lo); + VECCOPY(shi->co, shi->lo); } if(mat->texco & TEXCO_NORM) { - R.orn[0]= R.vn[0]; - R.orn[1]= -R.vn[1]; - R.orn[2]= R.vn[2]; + shi->orn[0]= shi->vn[0]; + shi->orn[1]= shi->vn[1]; + shi->orn[2]= shi->vn[2]; } if(mat->texco & TEXCO_REFL) { /* for bump texture */ - VECCOPY(R.view, view); + VECCOPY(shi->view, view); - inp= -2.0*(R.vn[0]*view[0]+R.vn[1]*view[1]+R.vn[2]*view[2]); - R.ref[0]= (view[0]+inp*R.vn[0]); - R.ref[1]= (view[1]+inp*R.vn[1]); - if(smooth) R.ref[1]= -R.ref[1]; - R.ref[2]= (view[2]+inp*R.vn[2]); + inp= -2.0*(shi->vn[0]*view[0]+shi->vn[1]*view[1]+shi->vn[2]*view[2]); + shi->ref[0]= (view[0]+inp*shi->vn[0]); + shi->ref[1]= (view[1]+inp*shi->vn[1]); + shi->ref[2]= (view[2]+inp*shi->vn[2]); } - do_material_tex(); + do_material_tex(shi); + + if(mat->texco & TEXCO_REFL) { + /* normals in render are pointing different... rhm */ + if(smooth) shi->ref[1]= -shi->ref[1]; + } if(mat->pr_type==MA_CUBE) { /* rotate normal back for normals texture */ - SWAP(float, R.vn[0], R.vn[1]); + SWAP(float, shi->vn[0], shi->vn[1]); MTC_Mat3Inv(imat, tmat); - MTC_Mat3MulVecfl(imat, R.vn); + MTC_Mat3MulVecfl(imat, shi->vn); } } @@ -808,7 +805,7 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth) lv[2]= vec[2]-la[2]; Normalise(lv); - inp= R.vn[0]*lv[0]+R.vn[1]*lv[1]+R.vn[2]*lv[2]; + inp= shi->vn[0]*lv[0]+shi->vn[1]*lv[1]+shi->vn[2]*lv[2]; if(inp<0.0) inp= 0.0; if(mat->spec) { @@ -818,13 +815,13 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth) float specfac; if(mat->spec_shader==MA_SPEC_PHONG) - specfac= Phong_Spec(R.vn, lv, view, mat->har); + specfac= Phong_Spec(shi->vn, lv, view, mat->har); else if(mat->spec_shader==MA_SPEC_COOKTORR) - specfac= CookTorr_Spec(R.vn, lv, view, mat->har); + specfac= CookTorr_Spec(shi->vn, lv, view, mat->har); else if(mat->spec_shader==MA_SPEC_BLINN) - specfac= Blinn_Spec(R.vn, lv, view, mat->refrac, (float)mat->har); + specfac= Blinn_Spec(shi->vn, lv, view, mat->refrac, (float)mat->har); else - specfac= Toon_Spec(R.vn, lv, view, mat->param[2], mat->param[3]); + specfac= Toon_Spec(shi->vn, lv, view, mat->param[2], mat->param[3]); inprspec= specfac*mat->spec; @@ -835,8 +832,8 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth) } } /* diffuse shaders */ - if(mat->diff_shader==MA_DIFF_ORENNAYAR) inp= OrenNayar_Diff(R.vn, lv, view, mat->roughness); - else if(mat->diff_shader==MA_DIFF_TOON) inp= Toon_Diff(R.vn, lv, view, mat->param[0], mat->param[1]); + if(mat->diff_shader==MA_DIFF_ORENNAYAR) inp= OrenNayar_Diff(shi->vn, lv, view, mat->roughness); + else if(mat->diff_shader==MA_DIFF_TOON) inp= Toon_Diff(shi->vn, lv, view, mat->param[0], mat->param[1]); // else Lambert inp= (mat->ref*inp + mat->emit); @@ -855,33 +852,33 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth) int fac; /* rotate a bit in x */ - y= R.ref[1]; z= R.ref[2]; - R.ref[1]= 0.98*y - 0.17*z; - R.ref[2]= 0.17*y + 0.98*z; + y= shi->ref[1]; z= shi->ref[2]; + shi->ref[1]= 0.98*y - 0.17*z; + shi->ref[2]= 0.17*y + 0.98*z; /* scale */ - div= (0.85*R.ref[1]); + div= (0.85*shi->ref[1]); - R.refcol[0]= mat->ray_mirror*fresnel_fac(view, R.vn, mat->fresnel_mir); + shi->refcol[0]= mat->ray_mirror*fresnel_fac(view, shi->vn, mat->fresnel_mir); if(div<0.0) { /* minus 0.5 prevents too many small tiles in distance */ - fac= (int)(R.ref[0]/(div-0.1) ) + (int)(R.ref[2]/(div-0.1) ); + fac= (int)(shi->ref[0]/(div-0.1) ) + (int)(shi->ref[2]/(div-0.1) ); if(fac & 1) col= 0.8; else col= 0.3; - R.refcol[1]= R.refcol[0]*col; - R.refcol[2]= R.refcol[1]; - R.refcol[3]= R.refcol[2]; + shi->refcol[1]= shi->refcol[0]*col; + shi->refcol[2]= shi->refcol[1]; + shi->refcol[3]= shi->refcol[2]; } else { - R.refcol[1]= 0.0; - R.refcol[2]= R.refcol[0]*0.3*div; - R.refcol[3]= R.refcol[0]*0.8*div; + shi->refcol[1]= 0.0; + shi->refcol[2]= shi->refcol[0]*0.3*div; + shi->refcol[3]= shi->refcol[0]*0.8*div; } } - if(R.refcol[0]==0.0) { + if(shi->refcol[0]==0.0) { a= 255.0*( mat->r*ir +mat->ambr +isr); if(a>255) a=255; else if(a<0) a= 0; rect[0]= a; @@ -893,13 +890,13 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth) rect[2]= a; } else { - a= 255.0*( mat->mirr*R.refcol[1] + (1.0 - mat->mirr*R.refcol[0])*(mat->r*ir +mat->ambr) +isr); + a= 255.0*( mat->mirr*shi->refcol[1] + (1.0 - mat->mirr*shi->refcol[0])*(mat->r*ir +mat->ambr) +isr); if(a>255) a=255; else if(a<0) a= 0; rect[0]= a; - a= 255.0*( mat->mirg*R.refcol[2] + (1.0 - mat->mirg*R.refcol[0])*(mat->g*ig +mat->ambg) +isg); + a= 255.0*( mat->mirg*shi->refcol[2] + (1.0 - mat->mirg*shi->refcol[0])*(mat->g*ig +mat->ambg) +isg); if(a>255) a=255; else if(a<0) a= 0; rect[1]= a; - a= 255.0*( mat->mirb*R.refcol[3] + (1.0 - mat->mirb*R.refcol[0])*(mat->b*ib +mat->ambb) +isb); + a= 255.0*( mat->mirb*shi->refcol[3] + (1.0 - mat->mirb*shi->refcol[0])*(mat->b*ib +mat->ambb) +isb); if(a>255) a=255; else if(a<0) a= 0; rect[2]= a; } @@ -909,7 +906,7 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth) if(mat->mode & (MA_ZTRA|MA_RAYTRANSP)) if(mat->fresnel_tra!=0.0) - alpha*= fresnel_fac(view, R.vn, mat->fresnel_tra); + alpha*= fresnel_fac(view, shi->vn, mat->fresnel_tra); /* ztra shade */ if(mat->spectra!=0.0) { @@ -921,7 +918,7 @@ static void shade_preview_pixel(float *vec, int x, int y,char *rect, int smooth) if(alpha!=1.0) { if(mat->mode & MA_RAYTRANSP) { - refraction_prv(&x, &y, R.vn, mat->ang); + refraction_prv(&x, &y, shi->vn, mat->ang); } tracol= previewback(mat->pr_back, x, y) & 255; @@ -947,6 +944,7 @@ void BIF_previewrender(SpaceButs *sbuts) HaloRen har; Object *ob; uiBlock *block; + ShadeInput shi; float lens = 0.0, vec[3]; int x, y, starty, startx, endy, endx, radsq, xsq, ysq, last = 0; unsigned int *rect; @@ -994,7 +992,7 @@ void BIF_previewrender(SpaceButs *sbuts) MTC_Mat4One(R.viewmat); MTC_Mat4One(R.viewinv); - R.osatex= 0; + shi.osatex= 0; if(mat) { /* rendervars */ @@ -1014,9 +1012,9 @@ void BIF_previewrender(SpaceButs *sbuts) if(mat->mtex[x]->object) MTC_Mat4One(mat->mtex[x]->object->imat); } } - R.vlr= 0; - R.mat= mat; - R.matren= mat->ren; + shi.vlr= 0; + shi.mat= mat; + shi.matren= mat->ren; if(mat->mode & MA_HALO) init_previewhalo(&har, mat); } @@ -1123,25 +1121,25 @@ void BIF_previewrender(SpaceButs *sbuts) if(mat->pr_type==MA_SPHERE) { if(xsq+ysq <= radsq) { - R.vn[0]= x; - R.vn[1]= y; - R.vn[2]= sqrt( (float)(radsq-xsq-ysq) ); - Normalise(R.vn); + shi.vn[0]= x; + shi.vn[1]= y; + shi.vn[2]= sqrt( (float)(radsq-xsq-ysq) ); + Normalise(shi.vn); - vec[0]= R.vn[0]; - vec[1]= R.vn[2]; - vec[2]= -R.vn[1]; + vec[0]= shi.vn[0]; + vec[1]= shi.vn[2]; + vec[2]= -shi.vn[1]; - shade_preview_pixel(vec, x, y, (char *)rect, 1); + shade_preview_pixel(&shi, vec, x, y, (char *)rect, 1); } else { rect[0]= previewback(mat->pr_back, x, y); } } else if(mat->pr_type==MA_CUBE) { - if( ray_previewrender(x, y, vec) ) { + if( ray_previewrender(x, y, vec, shi.vn) ) { - shade_preview_pixel(vec, x, y, (char *)rect, 0); + shade_preview_pixel(&shi, vec, x, y, (char *)rect, 0); } else { rect[0]= previewback(mat->pr_back, x, y); @@ -1152,10 +1150,10 @@ void BIF_previewrender(SpaceButs *sbuts) vec[1]= y*(2.0/PR_RECTX); vec[2]= 0.0; - R.vn[0]= R.vn[1]= 0.0; - R.vn[2]= 1.0; + shi.vn[0]= shi.vn[1]= 0.0; + shi.vn[2]= 1.0; - shade_preview_pixel(vec, x, y, (char *)rect, 0); + shade_preview_pixel(&shi, vec, x, y, (char *)rect, 0); } } } @@ -1167,7 +1165,7 @@ void BIF_previewrender(SpaceButs *sbuts) } else if(la) { for(x=startx; xlens; @@ -615,21 +615,7 @@ void setwinmatrixview3d(rctf *rect) /* rect: for picking */ x2= -x1; y1= -dfac*(winy/fac); y2= -y1; - - if(G.vd->persp==2 && (G.special1 & G_HOLO)) { - if(cam && (cam->flag & CAM_HOLO2)) { - tfac= fac/4.0; /* the fac is 1280/640 corrected for obszoom */ - if(cam->netend==0.0) cam->netend= EFRA; - fac= (G.scene->r.cfra-1.0)/(cam->netend)-0.5; - - fac*= tfac*(x2-x1); - fac*= ( cam->hololen1 ); - x1-= fac; - x2-= fac; - } - } - orth= 0; } @@ -691,8 +677,6 @@ void setviewmatrixview3d() { Camera *cam; - if(G.special1 & G_HOLO) RE_holoview(); - if(G.vd->persp>=2) { /* obs/camera */ if(G.vd->camera) { diff --git a/source/blender/src/writeavicodec.c b/source/blender/src/writeavicodec.c index 1b6a9776515..a9d88fc6e50 100644 --- a/source/blender/src/writeavicodec.c +++ b/source/blender/src/writeavicodec.c @@ -53,7 +53,6 @@ #include "DNA_userdef_types.h" #include "render_types.h" -#include "render.h" #include "BKE_global.h" #include "BKE_scene.h" diff --git a/source/blender/src/writeimage.c b/source/blender/src/writeimage.c index 42ac7ae8e45..2b49a0f6fda 100644 --- a/source/blender/src/writeimage.c +++ b/source/blender/src/writeimage.c @@ -35,9 +35,9 @@ #include "DNA_scene_types.h" #include "DNA_texture_types.h" // EnvMap{} #include "DNA_image_types.h" // Image{} -#include "render.h" #include "BKE_utildefines.h" // ELEM #include "BIF_writeimage.h" +#include "render.h" #ifdef HAVE_CONFIG_H #include diff --git a/source/blender/src/writemovie.c b/source/blender/src/writemovie.c index b6d5b64de6f..9435e1dfbe4 100644 --- a/source/blender/src/writemovie.c +++ b/source/blender/src/writemovie.c @@ -56,8 +56,6 @@ #include "BIF_writemovie.h" #include "BIF_toolbox.h" -#include "render.h" - #define error(str) {perror(str) ; error("%s", str); G.afbreek= 1;} #define QUIT(str) {error(str); return;}