Render Baking:

- Bugfix: vertex normals were still flipped around, to match viewpoint
  rendering.
- New: option to bake a texture+material only
This commit is contained in:
2006-11-19 18:44:54 +00:00
parent 6e086d4cfe
commit 4ebf5223ba
5 changed files with 27 additions and 10 deletions

View File

@@ -192,6 +192,7 @@ void RE_zbuf_accumulate_vecblur(struct NodeBlurData *nbd, int xsize, int ysize,
#define RE_BAKE_ALL 1
#define RE_BAKE_AO 2
#define RE_BAKE_NORMALS 3
#define RE_BAKE_TEXTURE 4
void RE_Database_Baking(struct Render *re, struct Scene *scene, int type);
void RE_DataBase_GetView(struct Render *re, float mat[][4]);

View File

@@ -361,6 +361,7 @@ typedef struct LampRen
#define R_HALO 2
#define R_SEC_FIELD 4
#define R_LAMPHALO 8
#define R_GLOB_NOPUNOFLIP 16
/* vlakren->flag (vlak = face in dutch) char!!! */
#define R_SMOOTH 1

View File

@@ -533,6 +533,9 @@ static void calc_vertexnormals(Render *re, int startvert, int startvlak, int do_
float n1[3], n2[3], n3[3], n4[3];
float fac1, fac2, fac3, fac4=0.0f;
if(re->flag & R_GLOB_NOPUNOFLIP)
vlr->flag |= R_NOPUNOFLIP;
VecSubf(n1, v2->co, v1->co);
Normalise(n1);
VecSubf(n2, v3->co, v2->co);
@@ -666,6 +669,9 @@ static void calc_fluidsimnormals(Render *re, int startvert, int startvlak, int d
float n1[3], n2[3], n3[3], n4[3];
float fac1, fac2, fac3, fac4=0.0f;
if(re->flag & R_GLOB_NOPUNOFLIP)
vlr->flag |= R_NOPUNOFLIP;
VecSubf(n1, v2->co, v1->co);
Normalise(n1);
VecSubf(n2, v3->co, v2->co);
@@ -3897,7 +3903,8 @@ void RE_DataBase_ApplyWindow(Render *re)
RE_BAKE_LIGHT: for shaded view, only add lamps
RE_BAKE_ALL: for baking, all lamps and objects
RE_BAKE_NORMALS:for baking, no lamps and only selected objects
RE_BAKE_AO: for baking, no lamps, but all objects
RE_BAKE_AO: for baking, no lamps, but all objects
RE_BAKE_TEXTURE:for baking, no lamps, only selected objects
*/
void RE_Database_Baking(Render *re, Scene *scene, int type)
{
@@ -3913,8 +3920,9 @@ void RE_Database_Baking(Render *re, Scene *scene, int type)
/* renderdata setup and exceptions */
re->r= scene->r;
re->r.mode &= ~R_OSA;
re->flag |= R_GLOB_NOPUNOFLIP;
if( ELEM(type, RE_BAKE_LIGHT, RE_BAKE_NORMALS) ) {
if( ELEM3(type, RE_BAKE_LIGHT, RE_BAKE_NORMALS, RE_BAKE_TEXTURE) ) {
re->r.mode &= ~R_SHADOW;
re->r.mode &= ~R_RAYTRACE;
}
@@ -3970,11 +3978,11 @@ void RE_Database_Baking(Render *re, Scene *scene, int type)
if(ob->flag & OB_DONE);
else if( (base->lay & lay) || ((base->lay & re->scene->lay)) ) {
if(ob->type==OB_LAMP) {
if(type!=RE_BAKE_NORMALS && type!=RE_BAKE_AO)
if( ELEM(type, RE_BAKE_LIGHT, RE_BAKE_ALL) )
init_render_object(re, ob, NULL, 0, 0);
}
else if(type!=RE_BAKE_LIGHT) {
if(type!=RE_BAKE_NORMALS || (ob->flag & SELECT))
if( !ELEM(type, RE_BAKE_NORMALS, RE_BAKE_TEXTURE) || (ob->flag & SELECT))
init_render_object(re, ob, NULL, 0, 0);
}
}

View File

@@ -3718,7 +3718,7 @@ static void do_bake_shade(void *handle, int x, int y, float u, float v)
/* no face normal flip */
VECCOPY(shi->facenor, vlr->n);
shi->puno= vlr->puno;
shi->puno= 0;
if(bs->quad)
shade_input_set_coords(shi, -u, -v, 0, 3, 4);
@@ -3743,6 +3743,11 @@ static void do_bake_shade(void *handle, int x, int y, float u, float v)
shr.diff[1]= 0.5f - shi->vn[1]/2.0f;
shr.diff[2]= shi->vn[2]/2.0f + 0.5f;
}
else if(bs->type==RE_BAKE_TEXTURE) {
shr.diff[0]= shi->r;
shr.diff[1]= shi->g;
shr.diff[2]= shi->b;
}
}
if(bs->rect) {
@@ -3860,6 +3865,7 @@ void RE_bake_shade_all_selected(Render *re, int type)
ima->id.newid= NULL;
IMB_filter_extend(ima->ibuf);
IMB_filter_extend(ima->ibuf); /* 2nd pixel extra */
ima->ibuf->userflags |= IB_BITMAPDIRTY;
free_realtime_image(ima); /* force OpenGL reload */
}

View File

@@ -865,18 +865,19 @@ void objects_bake_render(void)
{
short event;
event= pupmenu("Bake Selected Meshes %t|Full Render %x1|Ambient Occlusion %x2|Normals %x3");
event= pupmenu("Bake Selected Meshes %t|Full Render %x1|Ambient Occlusion %x2|Normals %x3|Texture Only %x4");
if(event>0) {
Render *re= RE_NewRender("_Bake View_");
if(event==1) event= RE_BAKE_ALL;
else if(event==2) event= RE_BAKE_AO;
else event= RE_BAKE_NORMALS;
else if(event==3) event= RE_BAKE_NORMALS;
else event= RE_BAKE_TEXTURE;
if(event==RE_BAKE_AO) {
if((G.scene->r.mode & R_RAYTRACE)==0 || G.scene->world==NULL
|| (G.scene->world->mode & WO_AMB_OCC)==0) {
error("No AO set up");
error("No ray-trace or AO set up");
return;
}
}