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/blenkernel
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/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_multires.h1
-rw-r--r--source/blender/blenkernel/intern/customdata.c2
-rw-r--r--source/blender/blenkernel/intern/multires.c58
3 files changed, 59 insertions, 2 deletions
diff --git a/source/blender/blenkernel/BKE_multires.h b/source/blender/blenkernel/BKE_multires.h
index ea34ff4aa07..ba23b2d79c0 100644
--- a/source/blender/blenkernel/BKE_multires.h
+++ b/source/blender/blenkernel/BKE_multires.h
@@ -91,6 +91,7 @@ void multires_topology_changed(struct Scene *scene, struct Object *ob);
void old_mdisps_bilinear(float out[3], float (*disps)[3], const int st, float u, float v);
void mdisp_rot_crn_to_face(const int S, const int corners, const int face_side, const float x, const float y, float *u, float *v);
int mdisp_rot_face_to_crn(const int corners, const int face_side, const float u, const float v, float *x, float *y);
+int mdisp_rot_face_to_quad_crn(const int corners, const int face_side, const float u, const float v, float *x, float *y);
void mdisp_apply_weight(const int S, const int corners, int x, int y, const int face_side, float crn_weight[4][2], float *u_r, float *v_r);
void mdisp_flip_disp(const int S, const int corners, const float axis_x[2], const float axis_y[2], float disp[3]);
void mdisp_join_tris(struct MDisps *dst, struct MDisps *tri1, struct MDisps *tri2);
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index f5f069767eb..45faba8439c 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -540,7 +540,7 @@ static void layerInterp_mdisps(void **sources, float *UNUSED(weights),
float face_u, face_v, crn_u, crn_v;
mdisp_apply_weight(S, dst_corners, x, y, st, crn_weight, &face_u, &face_v);
- crn = mdisp_rot_face_to_crn(src_corners, st, face_u, face_v, &crn_u, &crn_v);
+ crn = mdisp_rot_face_to_quad_crn(src_corners, st, face_u, face_v, &crn_u, &crn_v);
old_mdisps_bilinear((*out), &s->disps[crn*side*side], side, crn_u, crn_v);
mdisp_flip_disp(crn, dst_corners, axis_x, axis_y, *out);
diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c
index 13ab89200db..5802bb2b697 100644
--- a/source/blender/blenkernel/intern/multires.c
+++ b/source/blender/blenkernel/intern/multires.c
@@ -1997,6 +1997,7 @@ void mdisp_rot_crn_to_face(const int S, const int corners, const int face_side,
}
}
+/* Find per-corner coordinate with given per-face UV coord */
int mdisp_rot_face_to_crn(const int corners, const int face_side, const float u, const float v, float *x, float *y)
{
const float offset = face_side*0.5f - 0.5f;
@@ -2022,6 +2023,61 @@ int mdisp_rot_face_to_crn(const int corners, const int face_side, const float u,
*y = v - offset;
}
} else {
+ int grid_size = offset;
+ float w = (face_side - 1) - u - v;
+ float W1, W2;
+
+ if (u >= v && u >= w) {S = 0; W1= w; W2= v;}
+ else if (v >= u && v >= w) {S = 1; W1 = u; W2 = w;}
+ else {S = 2; W1 = v; W2 = u;}
+
+ W1 /= (face_side-1);
+ W2 /= (face_side-1);
+
+ *x = (1-(2*W1)/(1-W2)) * grid_size;
+ *y = (1-(2*W2)/(1-W1)) * grid_size;
+ }
+
+ return S;
+}
+
+/* Find per-corner coordinate with given per-face UV coord
+ Practically as the previous funciton but it assumes a bit different coordinate system for triangles
+ which is optimized for MDISP layer interpolation:
+
+ v
+ ^
+ | /|
+ | / |
+ | / |
+ |/______|___> u
+
+ */
+int mdisp_rot_face_to_quad_crn(const int corners, const int face_side, const float u, const float v, float *x, float *y)
+{
+ const float offset = face_side*0.5f - 0.5f;
+ int S = 0;
+
+ if (corners == 4) {
+ if(u <= offset && v <= offset) S = 0;
+ else if(u > offset && v <= offset) S = 1;
+ else if(u > offset && v > offset) S = 2;
+ else if(u <= offset && v >= offset) S = 3;
+
+ if(S == 0) {
+ *y = offset - u;
+ *x = offset - v;
+ } else if(S == 1) {
+ *x = u - offset;
+ *y = offset - v;
+ } else if(S == 2) {
+ *y = u - offset;
+ *x = v - offset;
+ } else if(S == 3) {
+ *x= offset - u;
+ *y = v - offset;
+ }
+ } else {
float crn[3][4][2];
float p[2] = {u, v};
@@ -2148,7 +2204,7 @@ void mdisp_join_tris(MDisps *dst, MDisps *tri1, MDisps *tri2)
face_v = st - 1 - face_v;
} else src = tri1;
- crn = mdisp_rot_face_to_crn(3, st, face_u, face_v, &crn_u, &crn_v);
+ crn = mdisp_rot_face_to_quad_crn(3, st, face_u, face_v, &crn_u, &crn_v);
old_mdisps_bilinear((*out), &src->disps[crn*side*side], side, crn_u, crn_v);
(*out)[0] = 0;