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:
Diffstat (limited to 'source/blender/render/intern/source/convertblender.c')
-rw-r--r--source/blender/render/intern/source/convertblender.c282
1 files changed, 43 insertions, 239 deletions
diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c
index 18f658fb169..fb9f96b0ef7 100644
--- a/source/blender/render/intern/source/convertblender.c
+++ b/source/blender/render/intern/source/convertblender.c
@@ -135,206 +135,11 @@
#endif
/* ------------------------------------------------------------------------- */
-
-/* Stuff for stars. This sits here because it uses gl-things. Part of
- * this code may move down to the converter. */
-/* ------------------------------------------------------------------------- */
-/* this is a bad beast, since it is misused by the 3d view drawing as well. */
-
-static HaloRen *initstar(Render *re, ObjectRen *obr, const float vec[3], float hasize)
-{
- HaloRen *har;
- float hoco[4];
-
- projectverto(vec, re->winmat, hoco);
-
- har= RE_findOrAddHalo(obr, obr->tothalo++);
-
- /* projectvert is done in function zbufvlaggen again, because of parts */
- copy_v3_v3(har->co, vec);
- har->hasize= hasize;
-
- har->zd= 0.0;
- har->pool = re->pool;
-
- return har;
-}
-
-/* there must be a 'fixed' amount of stars generated between
- * near and far
- * all stars must by preference lie on the far and solely
- * differ in clarity/color
- */
-
-void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void),
- void (*vertexfunc)(const float *), void (*termfunc)(void))
-{
- extern unsigned char hash[512];
- ObjectRen *obr= NULL;
- World *wrld= NULL;
- HaloRen *har;
- Scene *scene;
- Object *camera;
- Camera *cam;
- RNG *rng;
- double dblrand, hlfrand;
- float vec[4], fx, fy, fz;
- float fac, starmindist, clipend;
- float mat[4][4], stargrid, maxrand, maxjit, force, alpha;
- int x, y, z, sx, sy, sz, ex, ey, ez, done = FALSE;
- unsigned int totstar= 0;
-
- if (initfunc) {
- scene= scenev3d;
- wrld= scene->world;
- }
- else {
- scene= re->scene;
- wrld= &(re->wrld);
- }
-
- stargrid = wrld->stardist; /* distance between stars */
- maxrand = 2.0; /* amount a star can be shifted (in grid units) */
- maxjit = (wrld->starcolnoise); /* amount a color is being shifted */
-
- /* size of stars */
- force = ( wrld->starsize );
-
- /* minimal free space (starting at camera) */
- starmindist= wrld->starmindist;
-
- if (stargrid <= 0.10f) return;
-
- if (re) re->flag |= R_HALO;
- else stargrid *= 1.0f; /* then it draws fewer */
-
- if (re) invert_m4_m4(mat, re->viewmat);
- else unit_m4(mat);
-
- /* BOUNDING BOX CALCULATION
- * bbox goes from z = loc_near_var | loc_far_var,
- * x = -z | +z,
- * y = -z | +z
- */
-
- camera= re ? RE_GetCamera(re) : scene->camera;
-
- if (camera==NULL || camera->type != OB_CAMERA)
- return;
-
- cam = camera->data;
- clipend = cam->clipend;
-
- /* convert to grid coordinates */
-
- sx = ((mat[3][0] - clipend) / stargrid) - maxrand;
- sy = ((mat[3][1] - clipend) / stargrid) - maxrand;
- sz = ((mat[3][2] - clipend) / stargrid) - maxrand;
-
- ex = ((mat[3][0] + clipend) / stargrid) + maxrand;
- ey = ((mat[3][1] + clipend) / stargrid) + maxrand;
- ez = ((mat[3][2] + clipend) / stargrid) + maxrand;
-
- dblrand = maxrand * stargrid;
- hlfrand = 2.0 * dblrand;
-
- if (initfunc) {
- initfunc();
- }
-
- if (re) /* add render object for stars */
- obr= RE_addRenderObject(re, NULL, NULL, 0, 0, 0);
-
- rng = BLI_rng_new(0);
-
- for (x = sx, fx = sx * stargrid; x <= ex; x++, fx += stargrid) {
- for (y = sy, fy = sy * stargrid; y <= ey; y++, fy += stargrid) {
- for (z = sz, fz = sz * stargrid; z <= ez; z++, fz += stargrid) {
-
- BLI_rng_seed(rng, (hash[z & 0xff] << 24) + (hash[y & 0xff] << 16) + (hash[x & 0xff] << 8));
- vec[0] = fx + (hlfrand * BLI_rng_get_double(rng)) - dblrand;
- vec[1] = fy + (hlfrand * BLI_rng_get_double(rng)) - dblrand;
- vec[2] = fz + (hlfrand * BLI_rng_get_double(rng)) - dblrand;
- vec[3] = 1.0;
-
- if (vertexfunc) {
- if (done & 1) vertexfunc(vec);
- done++;
- }
- else {
- if (re)
- mul_m4_v3(re->viewmat, vec);
-
- /* in vec are global coordinates
- * calculate distance to camera
- * and using that, define the alpha
- */
- alpha = len_v3(vec);
-
- if (alpha >= clipend) alpha = 0.0;
- else if (alpha <= starmindist) alpha = 0.0;
- else if (alpha <= 2.0f * starmindist) {
- alpha = (alpha - starmindist) / starmindist;
- }
- else {
- alpha -= 2.0f * starmindist;
- alpha /= (clipend - 2.0f * starmindist);
- alpha = 1.0f - alpha;
- }
-
-
- if (alpha != 0.0f) {
- fac = force * BLI_rng_get_double(rng);
-
- har = initstar(re, obr, vec, fac);
-
- if (har) {
- har->alfa = sqrt(sqrt(alpha));
- har->add= 255;
- har->r = har->g = har->b = 1.0;
- if (maxjit) {
- har->r += ((maxjit * BLI_rng_get_double(rng)) ) - maxjit;
- har->g += ((maxjit * BLI_rng_get_double(rng)) ) - maxjit;
- har->b += ((maxjit * BLI_rng_get_double(rng)) ) - maxjit;
- }
- har->hard = 32;
- har->lay= -1;
- har->type |= HA_ONLYSKY;
- done++;
- }
- }
- }
-
- /* break out of the loop if generating stars takes too long */
- if (re && !(totstar % 1000000)) {
- if (re->test_break(re->tbh)) {
- x= ex + 1;
- y= ey + 1;
- z= ez + 1;
- }
- }
-
- totstar++;
- }
- /* do not call blender_test_break() here, since it is used in UI as well, confusing the callback system */
- /* main cause is G.is_break of course, a global again... (ton) */
- }
- }
- if (termfunc) termfunc();
-
- if (obr)
- re->tothalo += obr->tothalo;
-
- BLI_rng_free(rng);
-}
-
-
-/* ------------------------------------------------------------------------- */
/* tool functions/defines for ad hoc simplification and possible future
* cleanup */
/* ------------------------------------------------------------------------- */
-#define UVTOINDEX(u,v) (startvlak + (u) * sizev + (v))
+#define UVTOINDEX(u, v) (startvlak + (u) * sizev + (v))
/*
*
* NOTE THAT U/V COORDINATES ARE SOMETIMES SWAPPED !!
@@ -860,28 +665,13 @@ static void autosmooth(Render *UNUSED(re), ObjectRen *obr, float mat[4][4], int
/* Orco hash and Materials */
/* ------------------------------------------------------------------------- */
-static float *get_object_orco(Render *re, Object *ob)
+static float *get_object_orco(Render *re, void *ob)
{
- float *orco;
-
- if (!re->orco_hash)
- re->orco_hash = BLI_ghash_ptr_new("get_object_orco gh");
-
- orco = BLI_ghash_lookup(re->orco_hash, ob);
-
- if (!orco) {
- if (ELEM(ob->type, OB_CURVE, OB_FONT)) {
- orco = BKE_curve_make_orco(re->scene, ob, NULL);
- }
- else if (ob->type==OB_SURF) {
- orco = BKE_curve_surf_make_orco(ob);
- }
-
- if (orco)
- BLI_ghash_insert(re->orco_hash, ob, orco);
+ if (!re->orco_hash) {
+ return NULL;
}
- return orco;
+ return BLI_ghash_lookup(re->orco_hash, ob);
}
static void set_object_orco(Render *re, void *ob, float *orco)
@@ -1676,8 +1466,11 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
if (path_nbr) {
if (!ELEM(ma->material_type, MA_TYPE_HALO, MA_TYPE_WIRE)) {
- sd.orco = MEM_mallocN(3*sizeof(float)*(totpart+totchild), "particle orcos");
- set_object_orco(re, psys, sd.orco);
+ sd.orco = get_object_orco(re, psys);
+ if (!sd.orco) {
+ sd.orco = MEM_mallocN(3*sizeof(float)*(totpart+totchild), "particle orcos");
+ set_object_orco(re, psys, sd.orco);
+ }
}
}
@@ -1848,9 +1641,11 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
if (strandbuf) {
int orignum = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, cpa->num) : cpa->num;
- if (orignum > sbound - strandbuf->bound) {
- sbound= strandbuf->bound + orignum;
- sbound->start= sbound->end= obr->totstrand;
+ if ((orignum > sbound - strandbuf->bound) &&
+ (orignum < strandbuf->totbound))
+ {
+ sbound = &strandbuf->bound[orignum];
+ sbound->start = sbound->end = obr->totstrand;
}
}
}
@@ -2829,9 +2624,12 @@ static void init_render_surf(Render *re, ObjectRen *obr, int timeoffset)
if (dm) {
if (need_orco) {
- orco= BKE_displist_make_orco(re->scene, ob, dm, 1, 1);
- if (orco) {
- set_object_orco(re, ob, orco);
+ orco = get_object_orco(re, ob);
+ if (!orco) {
+ orco= BKE_displist_make_orco(re->scene, ob, dm, 1, 1);
+ if (orco) {
+ set_object_orco(re, ob, orco);
+ }
}
}
@@ -2840,7 +2638,11 @@ static void init_render_surf(Render *re, ObjectRen *obr, int timeoffset)
}
else {
if (need_orco) {
- orco= get_object_orco(re, ob);
+ orco = get_object_orco(re, ob);
+ if (!orco) {
+ orco = BKE_curve_surf_make_orco(ob);
+ set_object_orco(re, ob, orco);
+ }
}
/* walk along displaylist and create rendervertices/-faces */
@@ -2900,9 +2702,12 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset)
if (dm) {
if (need_orco) {
- orco= BKE_displist_make_orco(re->scene, ob, dm, 1, 1);
- if (orco) {
- set_object_orco(re, ob, orco);
+ orco = get_object_orco(re, ob);
+ if (!orco) {
+ orco = BKE_displist_make_orco(re->scene, ob, dm, 1, 1);
+ if (orco) {
+ set_object_orco(re, ob, orco);
+ }
}
}
@@ -2912,6 +2717,10 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset)
else {
if (need_orco) {
orco = get_object_orco(re, ob);
+ if (!orco) {
+ orco = BKE_curve_make_orco(re->scene, ob, NULL);
+ set_object_orco(re, ob, orco);
+ }
}
while (dl) {
@@ -3401,10 +3210,13 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
if (dm==NULL) return; /* in case duplicated object fails? */
if (mask & CD_MASK_ORCO) {
- orco= dm->getVertDataArray(dm, CD_ORCO);
- if (orco) {
- orco= MEM_dupallocN(orco);
- set_object_orco(re, ob, orco);
+ orco = get_object_orco(re, ob);
+ if (!orco) {
+ orco= dm->getVertDataArray(dm, CD_ORCO);
+ if (orco) {
+ orco= MEM_dupallocN(orco);
+ set_object_orco(re, ob, orco);
+ }
}
}
@@ -5361,15 +5173,7 @@ void RE_Database_Preprocess(Render *re)
if (!re->test_break(re->tbh)) {
int tothalo;
- /* don't sort stars */
tothalo= re->tothalo;
- if (!re->test_break(re->tbh)) {
- if (re->wrld.mode & WO_STARS) {
- re->i.infostr = IFACE_("Creating Starfield");
- re->stats_draw(re->sdh, &re->i);
- RE_make_stars(re, NULL, NULL, NULL, NULL);
- }
- }
sort_halos(re, tothalo);
init_camera_inside_volumes(re);