Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2011-06-06 00:54:04 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2011-06-06 00:54:04 +0400
commita1c22262fef25de91dbafd7b401e349538dc3d61 (patch)
treeeeb0092df131068785f7d0e03a5f47c111fb04a9 /source/blender/imbuf
parenta580b5ec80d5c0744b63f9b7e8048c0f16681a38 (diff)
Bake from multires mesh
======================= Added option to baked named "Bake From Multires" which is avaliable for normals baking and displacement baking. If this option is enabled, then no additional hi-res meshes and render structures would be created . This saves plenty of memory and meshes with millions of faces could be successfully baked in few minutes. Baking happens from highest level against viewport subdivision level, so workflow is following: - Set viewport level to level at which texture would be applied during final rendering. - Choose Displacement/Normals baking. - Enable "Bake From Multires" option. - You're ready to bake. Displacement baker had aditional option named "Low Resolution Mesh". This option is used to set if you want texture for realtime (games) usage. Internally it does the following: - If it's disabled, displacement is calculated from subdivided viewport level, so texture looks "smooth" (it's how default baked works). - If it's enabled, dispalcement is calculated against unsubdivided viewport levels. This leads to "scales". This isn;t useful for offline renders much, but very useful for creating game textures. Special thanks to Morten Mikkelsen (aka sparky) for all mathematics and other work he've done fr this patch!
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r--source/blender/imbuf/IMB_imbuf.h7
-rw-r--r--source/blender/imbuf/intern/filter.c64
2 files changed, 71 insertions, 0 deletions
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h
index 21249c9e8f7..1eefc58d4de 100644
--- a/source/blender/imbuf/IMB_imbuf.h
+++ b/source/blender/imbuf/IMB_imbuf.h
@@ -243,8 +243,15 @@ void IMB_free_anim(struct anim *anim);
*
* @attention Defined in filter.c
*/
+
+#define FILTER_MASK_NULL 0
+#define FILTER_MASK_MARGIN 1
+#define FILTER_MASK_USED 2
+
void IMB_filter(struct ImBuf *ibuf);
void IMB_filterN(struct ImBuf *out, struct ImBuf *in);
+void IMB_mask_filter_extend(char *mask, int width, int height);
+void IMB_mask_clear(struct ImBuf *ibuf, char *mask, int val);
void IMB_filter_extend(struct ImBuf *ibuf, char *mask);
void IMB_makemipmap(struct ImBuf *ibuf, int use_filter);
void IMB_remakemipmap(struct ImBuf *ibuf, int use_filter);
diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c
index 16fb1fdf4aa..d12360e5a7e 100644
--- a/source/blender/imbuf/intern/filter.c
+++ b/source/blender/imbuf/intern/filter.c
@@ -262,6 +262,70 @@ void IMB_filter(struct ImBuf *ibuf)
imb_filterx(ibuf);
}
+void IMB_mask_filter_extend(char *mask, int width, int height)
+{
+ char *row1, *row2, *row3;
+ int rowlen, x, y;
+ char *temprect;
+
+ rowlen= width;
+
+ /* make a copy, to prevent flooding */
+ temprect= MEM_dupallocN(mask);
+
+ for(y=1; y<=height; y++) {
+ /* setup rows */
+ row1= (char *)(temprect + (y-2)*rowlen);
+ row2= row1 + rowlen;
+ row3= row2 + rowlen;
+ if(y==1)
+ row1= row2;
+ else if(y==height)
+ row3= row2;
+
+ for(x=0; x<rowlen; x++) {
+ if (mask[((y-1)*rowlen)+x]==0) {
+ if (*row1 || *row2 || *row3 || *(row1+1) || *(row3+1) ) {
+ mask[((y-1)*rowlen)+x] = FILTER_MASK_MARGIN;
+ } else if((x!=rowlen-1) && (*(row1+2) || *(row2+2) || *(row3+2)) ) {
+ mask[((y-1)*rowlen)+x] = FILTER_MASK_MARGIN;
+ }
+ }
+
+ if(x!=0) {
+ row1++; row2++; row3++;
+ }
+ }
+ }
+
+ MEM_freeN(temprect);
+}
+
+void IMB_mask_clear(ImBuf *ibuf, char *mask, int val)
+{
+ int x,y;
+ if (ibuf->rect_float) {
+ for(x=0; x<ibuf->x; x++) {
+ for(y=0; y<ibuf->y; y++) {
+ if (mask[ibuf->x*y + x] == val) {
+ float *col= ibuf->rect_float + 4*(ibuf->x*y + x);
+ col[0] = col[1] = col[2] = col[3] = 0.0f;
+ }
+ }
+ }
+ } else {
+ /* char buffer */
+ for(x=0; x<ibuf->x; x++) {
+ for(y=0; y<ibuf->y; y++) {
+ if (mask[ibuf->x*y + x] == val) {
+ char *col= (char *)(ibuf->rect + ibuf->x*y + x);
+ col[0] = col[1] = col[2] = col[3] = 0;
+ }
+ }
+ }
+ }
+}
+
#define EXTEND_PIXEL(color, w) if((color)[3]) {r+= w*(color)[0]; g+= w*(color)[1]; b+= w*(color)[2]; a+= w*(color)[3]; tot+=w;}
/* if alpha is zero, it checks surrounding pixels and averages color. sets new alphas to 1.0