More render pipeline finishing up;
authorTon Roosendaal <ton@blender.org>
Sun, 28 May 2006 11:49:22 +0000 (11:49 +0000)
committerTon Roosendaal <ton@blender.org>
Sun, 28 May 2006 11:49:22 +0000 (11:49 +0000)
- Shaded drawmode is back (shift+z).
  Note it still only uses orco texture; but lighting/shading is using
  the internal render module entirely.

- "Make Sticky" option back.
  (Also fix in sticky texture render, was wrong scaled)

12 files changed:
source/blender/blenkernel/BKE_displist.h
source/blender/blenkernel/intern/blender.c
source/blender/blenkernel/intern/displist.c
source/blender/render/extern/include/RE_pipeline.h
source/blender/render/extern/include/RE_shader_ext.h
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/initrender.c
source/blender/render/intern/source/rendercore.c
source/blender/render/intern/source/texture.c
source/blender/src/buttons_shading.c
source/blender/src/usiblender.c
source/blender/src/vpaint.c

index 05a1cfc5376941c3025549e80da8d78c8a2257ff..42e1576d13761fff3d26ed6cc68422c7f6583395 100644 (file)
@@ -146,12 +146,14 @@ extern void makeDispListSurf(struct Object *ob, struct ListBase *dispbase, int f
 extern void makeDispListCurveTypes(struct Object *ob, int forOrco);
 extern void makeDispListMBall(struct Object *ob);
 extern void shadeDispList(struct Base *base);
-void freefastshade(void);
+
 void imagestodisplist(void);
 void reshadeall_displist(void);
 void filldisplist(struct ListBase *dispbase, struct ListBase *to);
 
-void mesh_create_shadedColors(struct Object *ob, int onlyForMesh, unsigned int **col1_r, unsigned int **col2_r);
+void fastshade_free_render(void);
+
+
 void displistmesh_add_edges(DispListMesh *dlm);
 
 #endif
index 992139a5120c107062cd53985ae2dbf9dba78ffe..1625db1a1e309e9c427c8666a01d1edc2bfe403b 100644 (file)
@@ -227,8 +227,8 @@ static void clear_global(void)
        extern short winqueue_break;    /* screen.c */
 
        freeAllRad();
-       free_main(G.main); /* free all lib data */
-       freefastshade();        /* othwerwise old lamp settings stay active */
+       fastshade_free_render();        /* lamps hang otherwise */
+       free_main(G.main);                      /* free all lib data */
 
        /* force all queues to be left */
        winqueue_break= 1;
index 3201a8b945bc67555877b7bf07f349b4330cfad9..de383ee06b71ca880316e09de529c8da7e19c661 100644 (file)
@@ -87,7 +87,8 @@
 #include "BKE_subsurf.h"
 #include "BKE_modifier.h"
 
-#include "nla.h" /* For __NLA: Please do not remove yet */
+#include "RE_pipeline.h"
+#include "RE_shader_ext.h"
 
 
 static void boundbox_displist(Object *ob);
@@ -265,20 +266,6 @@ void copy_displist(ListBase *lbn, ListBase *lb)
        }
 }
 
-void initfastshade(void)
-{
-}
-
-
-void freefastshade()
-{
-}
-
-
-static void fastshade(float *co, float *nor, float *orco, Material *ma, char *col1, char *col2, char *vertcol)
-{
-}
-
 void addnormalsDispList(Object *ob, ListBase *lb)
 {
        DispList *dl = NULL;
@@ -345,15 +332,191 @@ void addnormalsDispList(Object *ob, ListBase *lb)
        }
 }
 
-static void init_fastshade_for_ob(Object *ob, int *need_orco_r, float mat[4][4], float *imat)
+void count_displist(ListBase *lb, int *totvert, int *totface)
+{
+       DispList *dl;
+       
+       dl= lb->first;
+       while(dl) {
+               
+               switch(dl->type) {
+                       case DL_SURF:
+                               *totvert+= dl->nr*dl->parts;
+                               *totface+= (dl->nr-1)*(dl->parts-1);
+                               break;
+                       case DL_INDEX3:
+                       case DL_INDEX4:
+                               *totvert+= dl->nr;
+                               *totface+= dl->parts;
+                               break;
+                       case DL_POLY:
+                       case DL_SEGM:
+                               *totvert+= dl->nr*dl->parts;
+               }
+               
+               dl= dl->next;
+       }
+}
+
+
+/* ***************************** shade displist ******************** */
+
+/* create default shade input... save cpu cycles with ugly global */
+static ShadeInput shi;
+static void init_fastshade_shadeinput(void)
+{
+       
+       memset(&shi, 0, sizeof(ShadeInput));
+       shi.lay= G.scene->lay;
+       shi.view[2]= -1.0f;
+}
+
+static Render *fastshade_get_render(void)
 {
-       int x;
+       Render *re= RE_GetRender("_Shade View_");
+       if(re==NULL) {
+               re= RE_NewRender("_Shade View_");
+       
+               RE_Database_Shaded(re, G.scene);
+       }
+       return re;
+}
+
+/* called on file reading */
+void fastshade_free_render(void)
+{
+       Render *re= RE_GetRender("_Shade View_");
+       
+       if(re) {
+               RE_Database_Free(re);
+               RE_FreeRender(re);
+       }
+}
+
+static void fastshade(float *co, float *nor, float *orco, Material *ma, char *col1, char *col2, char *vertcol)
+{
+       ShadeResult shr;
+       int a;
+       
+       if(ma->mode & MA_VERTEXCOLP) {
+               if(vertcol) {
+                       shi.r= vertcol[3]/255.0f;
+                       shi.g= vertcol[2]/255.0f;
+                       shi.b= vertcol[1]/255.0f;
+               }
+       }
+       
+       VECCOPY(shi.co, co);
+       shi.vn[0]= -nor[0];
+       shi.vn[1]= -nor[1];
+       shi.vn[2]= -nor[2];
+       VECCOPY(shi.vno, shi.vn);
+       
+       if(ma->texco) {
+               VECCOPY(shi.lo, orco);
+               
+               if(ma->texco & TEXCO_GLOB) {
+                       VECCOPY(shi.gl, shi.lo);
+               }
+               if(ma->texco & TEXCO_WINDOW) {
+                       VECCOPY(shi.winco, shi.lo);
+               }
+               if(ma->texco & TEXCO_STICKY) {
+                       VECCOPY(shi.sticky, shi.lo);
+               }
+               if(ma->texco & TEXCO_UV) {
+                       VECCOPY(shi.uv, shi.lo);
+               }
+               if(ma->texco & TEXCO_OBJECT) {
+                       VECCOPY(shi.co, shi.lo);
+               }
+               if(ma->texco & TEXCO_NORM) {
+                       VECCOPY(shi.orn, shi.vn);
+               }
+               if(ma->texco & TEXCO_REFL) {
+                       float 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]);
+               }
+       }
+       
+       shi.mat= ma;    /* set each time... node shaders change it */
+       RE_shade_external(NULL, &shi, &shr);
+       
+       VECADD(shr.combined, shr.diff, shr.spec);
+       
+       a= 256.0f*(shr.combined[0]);
+       col1[3]= CLAMPIS(a, 0, 255);
+       a= 256.0f*(shr.combined[1]);
+       col1[2]= CLAMPIS(a, 0, 255);
+       a= 256.0f*(shr.combined[2]);
+       col1[1]= CLAMPIS(a, 0, 255);
+       
+       if(col2) {
+               shi.vn[0]= -shi.vn[0];
+               shi.vn[1]= -shi.vn[1];
+               shi.vn[2]= -shi.vn[2];
+               
+               shi.mat= ma;    /* set each time... node shaders change it */
+               RE_shade_external(NULL, &shi, &shr);
+               
+               VECADD(shr.combined, shr.diff, shr.spec);
+               
+               a= 256.0f*(shr.combined[0]);
+               col2[3]= CLAMPIS(a, 0, 255);
+               a= 256.0f*(shr.combined[1]);
+               col2[2]= CLAMPIS(a, 0, 255);
+               a= 256.0f*(shr.combined[2]);
+               col2[1]= CLAMPIS(a, 0, 255);
+       }
+}
+
+static void init_fastshade_for_ob(Render *re, Object *ob, int *need_orco_r, float mat[4][4], float imat[3][3])
+{
+       float tmat[4][4];
+       float amb[3]= {0.0f, 0.0f, 0.0f};
+       int a;
+       
+       /* initialize globals in render */
+       RE_shade_external(re, NULL, NULL);
+
+       /* initialize global here */
+       init_fastshade_shadeinput();
+       
+       RE_DataBase_GetView(re, tmat);
+       Mat4MulMat4(mat, ob->obmat, tmat);
+       
+       Mat4Invert(tmat, mat);
+       Mat3CpyMat4(imat, tmat);
+       if(ob->transflag & OB_NEG_SCALE) Mat3MulFloat((float *)imat, -1.0);
+       
+       if (need_orco_r) *need_orco_r= 0;
+       for(a=0; a<ob->totcol; a++) {
+               Material *ma= give_current_material(ob, a+1);
+               if(ma) {
+                       init_render_material(ma, 0, amb);
+
+                       if(ma->texco & TEXCO_ORCO) {
+                               if (need_orco_r) *need_orco_r= 1;
+                       }
+               }
+       }
+}
 
-       for(x=0;x<9;x++) imat[x] = 0;
-       need_orco_r=0;
+static void end_fastshade_for_ob(Object *ob)
+{
+       int a;
+       
+       for(a=0; a<ob->totcol; a++) {
+               Material *ma= give_current_material(ob, a+1);
+               if(ma)
+                       end_render_material(ma);
+       }
 }
 
-void mesh_create_shadedColors(Object *ob, int onlyForMesh, unsigned int **col1_r, unsigned int **col2_r)
+
+static void mesh_create_shadedColors(Render *re, Object *ob, int onlyForMesh, unsigned int **col1_r, unsigned int **col2_r)
 {
        Mesh *me= ob->data;
        int dmNeedsFree;
@@ -363,7 +526,7 @@ void mesh_create_shadedColors(Object *ob, int onlyForMesh, unsigned int **col1_r
        float *orco, *vnors, imat[3][3], mat[4][4], vec[3];
        int a, i, need_orco;
 
-       init_fastshade_for_ob(ob, &need_orco, mat, *imat);
+       init_fastshade_for_ob(re, ob, &need_orco, mat, imat);
 
        if (need_orco) {
                orco = mesh_create_orco(ob);
@@ -413,7 +576,7 @@ void mesh_create_shadedColors(Object *ob, int onlyForMesh, unsigned int **col1_r
                Material *ma= give_current_material(ob, mf->mat_nr+1);
                float nor[3], n1[3];
                
-               if(ma==0) ma= &defmaterial;
+               if(ma==NULL) ma= &defmaterial;
                
                if (dlm->tface) {
                        mcolbase = (unsigned char*) dlm->tface[i].col;
@@ -463,20 +626,25 @@ void mesh_create_shadedColors(Object *ob, int onlyForMesh, unsigned int **col1_r
 
        if (dmNeedsFree) dm->release(dm);
 
+       end_fastshade_for_ob(ob);
 }
 
 /* has base pointer, to check for layer */
+/* called from drawobject.c */
 void shadeDispList(Base *base)
 {
        Object *ob= base->object;
        DispList *dl, *dlob;
        Material *ma = NULL;
        Curve *cu;
+       Render *re;
        float imat[3][3], mat[4][4], vec[3];
        float *fp, *nor, n1[3];
        unsigned int *col1;
        int a, need_orco;
-
+       
+       re= fastshade_get_render();
+       
        dl = find_displist(&ob->disp, DL_VERTCOL);
        if (dl) {
                BLI_remlink(&ob->disp, dl);
@@ -488,128 +656,131 @@ void shadeDispList(Base *base)
                BLI_addtail(&ob->disp, dl);
                dl->type= DL_VERTCOL;
 
-               mesh_create_shadedColors(ob, 0, &dl->col1, &dl->col2);
-
-               return;
+               mesh_create_shadedColors(re, ob, 0, &dl->col1, &dl->col2);
        }
+       else {
 
-       init_fastshade_for_ob(ob, &need_orco, mat, *imat);
-       
-       if ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT) {
-       
-               /* now we need the normals */
-               cu= ob->data;
-               dl= cu->disp.first;
+               init_fastshade_for_ob(re, ob, &need_orco, mat, imat);
                
-               while(dl) {
-                       dlob= MEM_callocN(sizeof(DispList), "displistshade");
-                       BLI_addtail(&ob->disp, dlob);
-                       dlob->type= DL_VERTCOL;
-                       dlob->parts= dl->parts;
-                       dlob->nr= dl->nr;
+               if ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT) {
+               
+                       /* now we need the normals */
+                       cu= ob->data;
+                       dl= cu->disp.first;
                        
-                       if(dl->type==DL_INDEX3) {
-                               col1= dlob->col1= MEM_mallocN(sizeof(int)*dl->nr, "col1");
-                       }
-                       else {
-                               col1= dlob->col1= MEM_mallocN(sizeof(int)*dl->parts*dl->nr, "col1");
-                       }
+                       while(dl) {
+                               dlob= MEM_callocN(sizeof(DispList), "displistshade");
+                               BLI_addtail(&ob->disp, dlob);
+                               dlob->type= DL_VERTCOL;
+                               dlob->parts= dl->parts;
+                               dlob->nr= dl->nr;
+                               
+                               if(dl->type==DL_INDEX3) {
+                                       col1= dlob->col1= MEM_mallocN(sizeof(int)*dl->nr, "col1");
+                               }
+                               else {
+                                       col1= dlob->col1= MEM_mallocN(sizeof(int)*dl->parts*dl->nr, "col1");
+                               }
+                               
                        
-               
-                       ma= give_current_material(ob, dl->col+1);
-                       if(ma==0) ma= &defmaterial;
-
-                       if(dl->type==DL_INDEX3) {
-                               if(dl->nors) {
-                                       /* there's just one normal */
-                                       n1[0]= imat[0][0]*dl->nors[0]+imat[0][1]*dl->nors[1]+imat[0][2]*dl->nors[2];
-                                       n1[1]= imat[1][0]*dl->nors[0]+imat[1][1]*dl->nors[1]+imat[1][2]*dl->nors[2];
-                                       n1[2]= imat[2][0]*dl->nors[0]+imat[2][1]*dl->nors[1]+imat[2][2]*dl->nors[2];
-                                       Normalise(n1);
-                                       
-                                       fp= dl->verts;
-                                       
-                                       a= dl->nr;              
-                                       while(a--) {
-                                               VECCOPY(vec, fp);
-                                               Mat4MulVecfl(mat, vec);
+                               ma= give_current_material(ob, dl->col+1);
+                               if(ma==NULL) ma= &defmaterial;
+                               
+                               if(dl->type==DL_INDEX3) {
+                                       if(dl->nors) {
+                                               /* there's just one normal */
+                                               n1[0]= imat[0][0]*dl->nors[0]+imat[0][1]*dl->nors[1]+imat[0][2]*dl->nors[2];
+                                               n1[1]= imat[1][0]*dl->nors[0]+imat[1][1]*dl->nors[1]+imat[1][2]*dl->nors[2];
+                                               n1[2]= imat[2][0]*dl->nors[0]+imat[2][1]*dl->nors[1]+imat[2][2]*dl->nors[2];
+                                               Normalise(n1);
                                                
-                                               fastshade(vec, n1, fp, ma, (char *)col1, 0, 0);
+                                               fp= dl->verts;
                                                
-                                               fp+= 3; col1++;
+                                               a= dl->nr;              
+                                               while(a--) {
+                                                       VECCOPY(vec, fp);
+                                                       Mat4MulVecfl(mat, vec);
+                                                       
+                                                       fastshade(vec, n1, fp, ma, (char *)col1, 0, 0);
+                                                       
+                                                       fp+= 3; col1++;
+                                               }
                                        }
                                }
-                       }
-                       else if(dl->type==DL_SURF) {
-                               if(dl->nors) {
-                                       a= dl->nr*dl->parts;
-                                       fp= dl->verts;
-                                       nor= dl->nors;
-                                       
-                                       while(a--) {
-                                               VECCOPY(vec, fp);
-                                               Mat4MulVecfl(mat, vec);
+                               else if(dl->type==DL_SURF) {
+                                       if(dl->nors) {
+                                               a= dl->nr*dl->parts;
+                                               fp= dl->verts;
+                                               nor= dl->nors;
                                                
-                                               n1[0]= imat[0][0]*nor[0]+imat[0][1]*nor[1]+imat[0][2]*nor[2];
-                                               n1[1]= imat[1][0]*nor[0]+imat[1][1]*nor[1]+imat[1][2]*nor[2];
-                                               n1[2]= imat[2][0]*nor[0]+imat[2][1]*nor[1]+imat[2][2]*nor[2];
-                                               Normalise(n1);
-                       
-                                               fastshade(vec, n1, fp, ma, (char *)col1, 0, 0);
-                                               
-                                               fp+= 3; nor+= 3; col1++;
+                                               while(a--) {
+                                                       VECCOPY(vec, fp);
+                                                       Mat4MulVecfl(mat, vec);
+                                                       
+                                                       n1[0]= imat[0][0]*nor[0]+imat[0][1]*nor[1]+imat[0][2]*nor[2];
+                                                       n1[1]= imat[1][0]*nor[0]+imat[1][1]*nor[1]+imat[1][2]*nor[2];
+                                                       n1[2]= imat[2][0]*nor[0]+imat[2][1]*nor[1]+imat[2][2]*nor[2];
+                                                       Normalise(n1);
+                               
+                                                       fastshade(vec, n1, fp, ma, (char *)col1, 0, 0);
+                                                       
+                                                       fp+= 3; nor+= 3; col1++;
+                                               }
                                        }
                                }
+                               dl= dl->next;
                        }
-                       dl= dl->next;
                }
-       }
-       else if(ob->type==OB_MBALL) {
-               /* there are normals already */
-               dl= ob->disp.first;
-               
-               while(dl) {
+               else if(ob->type==OB_MBALL) {
+                       /* there are normals already */
+                       dl= ob->disp.first;
                        
-                       if(dl->type==DL_INDEX4) {
-                               if(dl->nors) {
-                                       
-                                       if(dl->col1) MEM_freeN(dl->col1);
-                                       col1= dl->col1= MEM_mallocN(sizeof(int)*dl->nr, "col1");
-                       
-                                       ma= give_current_material(ob, dl->col+1);
-                                       if(ma==0) ma= &defmaterial;
-       
-                                       fp= dl->verts;
-                                       nor= dl->nors;
-                                       
-                                       a= dl->nr;              
-                                       while(a--) {
-                                               VECCOPY(vec, fp);
-                                               Mat4MulVecfl(mat, vec);
+                       while(dl) {
+                               
+                               if(dl->type==DL_INDEX4) {
+                                       if(dl->nors) {
                                                
-                                               /* transpose ! */
-                                               n1[0]= imat[0][0]*nor[0]+imat[0][1]*nor[1]+imat[0][2]*nor[2];
-                                               n1[1]= imat[1][0]*nor[0]+imat[1][1]*nor[1]+imat[1][2]*nor[2];
-                                               n1[2]= imat[2][0]*nor[0]+imat[2][1]*nor[1]+imat[2][2]*nor[2];
-                                               Normalise(n1);
-                                       
-                                               fastshade(vec, n1, fp, ma, (char *)col1, 0, 0);
+                                               if(dl->col1) MEM_freeN(dl->col1);
+                                               col1= dl->col1= MEM_mallocN(sizeof(int)*dl->nr, "col1");
+                               
+                                               ma= give_current_material(ob, dl->col+1);
+                                               if(ma==NULL) ma= &defmaterial;
                                                
-                                               fp+= 3; col1++; nor+= 3;
+                                               fp= dl->verts;
+                                               nor= dl->nors;
+                                               
+                                               a= dl->nr;              
+                                               while(a--) {
+                                                       VECCOPY(vec, fp);
+                                                       Mat4MulVecfl(mat, vec);
+                                                       
+                                                       /* transpose ! */
+                                                       n1[0]= imat[0][0]*nor[0]+imat[0][1]*nor[1]+imat[0][2]*nor[2];
+                                                       n1[1]= imat[1][0]*nor[0]+imat[1][1]*nor[1]+imat[1][2]*nor[2];
+                                                       n1[2]= imat[2][0]*nor[0]+imat[2][1]*nor[1]+imat[2][2]*nor[2];
+                                                       Normalise(n1);
+                                               
+                                                       fastshade(vec, n1, fp, ma, (char *)col1, 0, 0);
+                                                       
+                                                       fp+= 3; col1++; nor+= 3;
+                                               }
                                        }
                                }
+                               dl= dl->next;
                        }
-                       dl= dl->next;
                }
+               
+               end_fastshade_for_ob(ob);
        }
 }
 
+/* frees render and shade part of displists */
 void reshadeall_displist(void)
 {
        Base *base;
        Object *ob;
        
-       freefastshade();
+       fastshade_free_render();
        
        for(base= G.scene->base.first; base; base= base->next) {
                ob= base->object;
@@ -621,31 +792,7 @@ void reshadeall_displist(void)
        }
 }
 
-void count_displist(ListBase *lb, int *totvert, int *totface)
-{
-       DispList *dl;
-       
-       dl= lb->first;
-       while(dl) {
-               
-               switch(dl->type) {
-               case DL_SURF:
-                       *totvert+= dl->nr*dl->parts;
-                       *totface+= (dl->nr-1)*(dl->parts-1);
-                       break;
-               case DL_INDEX3:
-               case DL_INDEX4:
-                       *totvert+= dl->nr;
-                       *totface+= dl->parts;
-                       break;
-               case DL_POLY:
-               case DL_SEGM:
-                       *totvert+= dl->nr*dl->parts;
-               }
-               
-               dl= dl->next;
-       }
-}
+/* ****************** make displists ********************* */
 
 static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase)
 {
index f0087ef6cce1f408551272558c5571fbea60cf8c..ae82ffb0128360c8ed3780a275fb46b68f450795 100644 (file)
@@ -182,5 +182,9 @@ float RE_filter_value(int type, float x);
 /* vector blur zbuffer method */
 void RE_zbuf_accumulate_vecblur(struct NodeBlurData *nbd, int xsize, int ysize, float *newrect, float *imgrect, float *vecbufrect, float *zbufrect);
 
+/* shaded view options */
+void RE_Database_Shaded(struct Render *re, struct Scene *scene);
+void RE_DataBase_GetView(struct Render *re, float mat[][4]);
+
 #endif /* RE_PIPELINE_H */
 
index 59f6da40f5ece93bc977033776915b8d220df495..f9015dc1161f3a11339c2fd89c5f951004ba4f4b 100644 (file)
@@ -114,5 +114,10 @@ typedef struct ShadeInput
 struct Tex;
 int    multitex_ext(struct Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, struct TexResult *texres);
 
+/* shaded view */
+struct Render;
+void RE_shade_external(struct Render *re, struct ShadeInput *shi, struct ShadeResult *shr);
+
+
 #endif /* RE_SHADER_EXT_H */
 
index 533e9830110b34aafb5724b9dbcf0cc7999d9193..f88a7bed33b1b4fed77aa8e6826af10e5603f4d9 100644 (file)
@@ -1972,7 +1972,7 @@ static void area_lamp_vectors(LampRen *lar)
 }
 
 /* If lar takes more lamp data, the decoupling will be better. */
-static void add_render_lamp(Render *re, Object *ob, int actual_render)
+static void add_render_lamp(Render *re, Object *ob)
 {
        Lamp *la= ob->data;
        LampRen *lar;
@@ -1980,12 +1980,10 @@ static void add_render_lamp(Render *re, Object *ob, int actual_render)
        float mat[4][4], hoek, xn, yn;
        int c;
 
-       /* prevent only shadow from rendering light, but only return on render, not preview */
-       if(actual_render) {
-               if(la->mode & LA_ONLYSHADOW)
-                       if((re->r.mode & R_SHADOW)==0)
-                               return;
-       }
+       /* prevent only shadow from rendering light */
+       if(la->mode & LA_ONLYSHADOW)
+               if((re->r.mode & R_SHADOW)==0)
+                       return;
        
        go= MEM_callocN(sizeof(GroupObject), "groupobject");
        BLI_addtail(&re->lights, go);
@@ -2150,7 +2148,7 @@ static void add_render_lamp(Render *re, Object *ob, int actual_render)
        }
 
        /* yafray: shadowbuffers and jitter only needed for internal render */
-       if (actual_render && re->r.renderer==R_INTERN) {
+       if (re->r.renderer==R_INTERN) {
                if(re->r.mode & R_SHADOW) {
                        if (la->type==LA_SPOT && (lar->mode & LA_SHAD) ) {
                                /* Per lamp, one shadow buffer is made. */
@@ -2670,7 +2668,7 @@ static void init_render_object(Render *re, Object *ob, Object *par, int index, i
        ob->flag |= OB_DONE;
 
        if(ob->type==OB_LAMP)
-               add_render_lamp(re, ob, 1);
+               add_render_lamp(re, ob);
        else if ELEM(ob->type, OB_FONT, OB_CURVE)
                init_render_curve(re, ob, only_verts);
        else if(ob->type==OB_SURF)
@@ -3586,6 +3584,132 @@ void RE_DataBase_ApplyWindow(Render *re)
        project_renderdata(re, projectverto, 0, 0);
 }
 
+/* setup for shaded view, so only lamps and materials are initialized */
+void RE_Database_Shaded(Render *re, Scene *scene)
+{
+       Base *base;
+       Object *ob;
+       Scene *sce;
+       float mat[4][4];
+       unsigned int lay;
+       
+       re->scene= scene;
+       
+       re->lights.first= re->lights.last= NULL;
+
+       /* in localview, lamps are using normal layers, objects only local bits */
+       if(re->scene->lay & 0xFF000000) lay= re->scene->lay & 0xFF000000;
+       else lay= re->scene->lay;
+       
+       /* if no camera, set unit */
+       if(re->scene->camera) {
+               Mat4Ortho(re->scene->camera->obmat);
+               Mat4Invert(mat, re->scene->camera->obmat);
+               RE_SetView(re, mat);
+       }
+       else {
+               Mat4One(mat);
+               RE_SetView(re, mat);
+       }
+       
+       /* initializes global */
+       set_node_shader_lamp_loop(shade_material_loop);
+
+       for(SETLOOPER(re->scene, base)) {
+               ob= base->object;
+               /* imat objects has to be done here, since displace can have texture using Object map-input */
+               MTC_Mat4MulMat4(mat, ob->obmat, re->viewmat);
+               MTC_Mat4Invert(ob->imat, mat);
+               /* each object should only be rendered once */
+               ob->flag &= ~OB_DONE;
+       }
+
+       /* MAKE RENDER DATA */
+       for(SETLOOPER(re->scene, base)) {
+               ob= base->object;
+               
+               /* OB_DONE means the object itself got duplicated, so was already converted */
+               if(ob->flag & OB_DONE);
+               else if(ob->type==OB_LAMP) {
+                       if( (base->lay & lay) || ((base->lay & re->scene->lay)) ) {
+                               init_render_object(re, ob, NULL, 0, 0);
+                       }
+               }
+       }
+       set_material_lightgroups(re);   
+}
+
+void RE_DataBase_GetView(Render *re, float mat[][4])
+{
+       Mat4CpyMat4(mat, re->viewmat);
+}
+
+
+
+
+/* **************************************************************** */
+/*                sticky texture coords                             */
+/* **************************************************************** */
+
+void RE_make_sticky(void)
+{
+       Object *ob;
+       Base *base;
+       MVert *mvert;
+       Mesh *me;
+       MSticky *ms;
+       Render *re;
+       float ho[4], mat[4][4];
+       int a;
+       
+       if(G.scene->camera==NULL) {
+               printf("Need camera to make sticky\n");
+               return;
+       }
+       if(G.obedit) {
+               printf("Unable to make sticky in Edit Mode\n");
+               return;
+       }
+       
+       re= RE_NewRender("_make sticky_");
+       RE_InitState(re, &G.scene->r, G.scene->r.xsch, G.scene->r.ysch, NULL);
+       
+       /* use renderdata and camera to set viewplane */
+       RE_SetCamera(re, G.scene->camera);
+
+       /* and set view matrix */
+       Mat4Ortho(G.scene->camera->obmat);
+       Mat4Invert(mat, G.scene->camera->obmat);
+       RE_SetView(re, mat);
+       
+       for(base= FIRSTBASE; base; base= base->next) {
+               if TESTBASELIB(base) {
+                       if(base->object->type==OB_MESH) {
+                               ob= base->object;
+                               
+                               me= ob->data;
+                               mvert= me->mvert;
+                               if(me->msticky) MEM_freeN(me->msticky);
+                               me->msticky= MEM_mallocN(me->totvert*sizeof(MSticky), "sticky");
+                               
+                               where_is_object(ob);
+                               Mat4MulMat4(mat, ob->obmat, re->viewmat);
+                               
+                               ms= me->msticky;
+                               for(a=0; a<me->totvert; a++, ms++, mvert++) {
+                                       VECCOPY(ho, mvert->co);
+                                       Mat4MulVecfl(mat, ho);
+                                       projectverto(ho, re->winmat, ho);
+                                       ms->co[0]= ho[0]/ho[3];
+                                       ms->co[1]= ho[1]/ho[3];
+                               }
+                       }
+               }
+       }
+}
+
+
+
 /* **************************************************************** */
 /*                Displacement mapping                              */
 /* **************************************************************** */
index 8f858e062de84a4ffc0fec6befc5101d4c57694f..1074fd3e36e4c80a2602cd1c69cb64706b27b842 100644 (file)
@@ -690,14 +690,3 @@ void initparts(Render *re)
 
 
 
-/* **************************************************************** */
-/*                sticky texture coords                             */
-/* **************************************************************** */
-
-void RE_make_sticky(void)
-{
-       /* oldfile.txt */
-}
-
-
-
index da9705411eacbc68dda438e2a39bad2a5b77cd13..49ec3d65be06d9d310456fd45f1bd4b448015fd0 100644 (file)
@@ -2528,8 +2528,8 @@ void *shadepixel(ShadePixelInfo *shpi, float x, float y, int z, volatile int fac
                                float hox, hoy, l, dl, u, v;
                                float s00, s01, s10, s11, detsh;
                                
-                               /* XXXX */
-                               Zmulx= R.winx; Zmuly= R.winy;
+                               /* old globals, localized now */
+                               Zmulx=  ((float)R.winx)/2.0; Zmuly=  ((float)R.winy)/2.0;
                                
                                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];
@@ -3471,10 +3471,34 @@ void add_halo_flare(void)
        }
 
        R.r.mode= mode; 
-
 }
 
-
-/* end of render.c */
+/* if *re, then initialize, otherwise execute */
+void RE_shade_external(Render *re, ShadeInput *shi, ShadeResult *shr)
+{
+       static VlakRen vlr;
+       
+       /* init */
+       if(re) {
+               R= *re;
+               
+               /* fake render face */
+               memset(&vlr, 0, sizeof(VlakRen));
+               vlr.lay= -1;
+               
+               return;
+       }
+       shi->vlr= &vlr;
+       
+       if(shi->mat->nodetree && shi->mat->use_nodes)
+               ntreeShaderExecTree(shi->mat->nodetree, shi, shr);
+       else {
+               /* copy all relevant material vars, note, keep this synced with render_types.h */
+               memcpy(&shi->r, &shi->mat->r, 23*sizeof(float));
+               shi->har= shi->mat->har;
+               
+               shade_material_loop(shi, shr);
+       }
+}
 
 
index 77c24374bc6dd15ec3e0292b1159f746cdfb9702..141bc44177d25f2fc467f996f38319f3c28768cf 100644 (file)
@@ -877,7 +877,8 @@ static int cubemap(MTex *mtex, VlakRen *vlr, float x, float y, float z, float *a
                
                /* Mesh vertices have such flags, for others we calculate it once based on orco */
                if((vlr->puno & (ME_PROJXY|ME_PROJXZ|ME_PROJYZ))==0) {
-                       if(vlr->v1->orco) {
+                       /* test for v1, vlr can be faked for baking */
+                       if(vlr->v1 && vlr->v1->orco) {
                                float nor[3];
                                CalcNormFloat(vlr->v1->orco, vlr->v2->orco, vlr->v3->orco, nor);
                                
index d917043ad234b9fe5c3084bc6d2de9d4ed8eab07..9e2fb54c1884e10f254f627d4ad99ab47288ad2d 100644 (file)
@@ -1978,8 +1978,6 @@ void do_lampbuts(unsigned short event)
                break;
                
        }
-       
-       if(event) freefastshade();
 }
 
 
index ec5a86471ec5a2479ced20a45061f3611ede1549..f912dabb014184b2bac2af3fd0609e7826e7b930 100644 (file)
@@ -779,10 +779,10 @@ void exit_usiblender(void)
        /* needed at least for a rare sigsegv that can happen in pydrivers */
        BPY_end_python();
 
-       free_blender(); /* blender.c, does entire library */
+       fastshade_free_render();        /* shaded view */
+       free_blender();                         /* blender.c, does entire library */
        free_matcopybuf();
        free_ipocopybuf();
-       freefastshade();
        free_vertexpaint();
        
        /* editnurb can remain to exist outside editmode */
index 08fbd778281e2ec5a05769711dfac1be8d0977f4..22ad81ee0e376aac5a9b976028e91ee56fe781c1 100644 (file)
@@ -235,7 +235,8 @@ void make_vertexcol()       /* single ob */
        if(me==0) return;
 
        if(me->mcol) MEM_freeN(me->mcol);
-       mesh_create_shadedColors(ob, 1, (unsigned int**) &me->mcol, NULL);
+       me->mcol = MEM_callocN(sizeof(int)*me->totface*4, "me->mcol");
+       // mesh_create_shadedColors(ob, 1, (unsigned int**) &me->mcol, NULL);
 
        for (i=0; i<me->totface*4; i++) {
                me->mcol[i].a = 255;
@@ -1648,7 +1649,6 @@ void set_wpaint(void)             /* toggle */
                }
        }
        else {
-               freefastshade();        /* to be sure */
                if(!(G.f & G_FACESELECT))
                        setcursor_space(SPACE_VIEW3D, CURSOR_STD);
                
@@ -1700,7 +1700,6 @@ void set_vpaint(void)             /* toggle */
                setcursor_space(SPACE_VIEW3D, CURSOR_VPAINT);
        }
        else {
-               freefastshade();        /* to be sure */
                if((G.f & G_FACESELECT)==0) setcursor_space(SPACE_VIEW3D, CURSOR_STD);
        }
 }