diff options
Diffstat (limited to 'source/blender/render')
-rw-r--r-- | source/blender/render/extern/include/RE_bake.h | 18 | ||||
-rw-r--r-- | source/blender/render/extern/include/RE_pipeline.h | 2 | ||||
-rw-r--r-- | source/blender/render/intern/include/render_types.h | 4 | ||||
-rw-r--r-- | source/blender/render/intern/source/bake.c | 4 | ||||
-rw-r--r-- | source/blender/render/intern/source/bake_api.c | 51 | ||||
-rw-r--r-- | source/blender/render/intern/source/convertblender.c | 35 | ||||
-rw-r--r-- | source/blender/render/intern/source/envmap.c | 4 | ||||
-rw-r--r-- | source/blender/render/intern/source/external_engine.c | 11 | ||||
-rw-r--r-- | source/blender/render/intern/source/imagetexture.c | 181 | ||||
-rw-r--r-- | source/blender/render/intern/source/occlusion.c | 18 | ||||
-rw-r--r-- | source/blender/render/intern/source/pipeline.c | 55 | ||||
-rw-r--r-- | source/blender/render/intern/source/render_texture.c | 4 | ||||
-rw-r--r-- | source/blender/render/intern/source/shadbuf.c | 2 | ||||
-rw-r--r-- | source/blender/render/intern/source/shadeoutput.c | 14 | ||||
-rw-r--r-- | source/blender/render/intern/source/volumetric.c | 2 |
15 files changed, 163 insertions, 242 deletions
diff --git a/source/blender/render/extern/include/RE_bake.h b/source/blender/render/extern/include/RE_bake.h index 8f2a0e382a4..481da452529 100644 --- a/source/blender/render/extern/include/RE_bake.h +++ b/source/blender/render/extern/include/RE_bake.h @@ -39,7 +39,7 @@ typedef struct BakeImage { struct Image *image; int width; int height; - int offset; + size_t offset; } BakeImage; typedef struct BakeImages { @@ -72,35 +72,35 @@ bool RE_bake_has_engine(struct Render *re); bool RE_bake_engine( struct Render *re, struct Object *object, const BakePixel pixel_array[], - const int num_pixels, const int depth, const ScenePassType pass_type, float result[]); + const size_t num_pixels, const int depth, const ScenePassType pass_type, float result[]); /* bake.c */ int RE_pass_depth(const ScenePassType pass_type); bool RE_bake_internal( struct Render *re, struct Object *object, const BakePixel pixel_array[], - const int num_pixels, const int depth, const ScenePassType pass_type, float result[]); + const size_t num_pixels, const int depth, const ScenePassType pass_type, float result[]); bool RE_bake_pixels_populate_from_objects( struct Mesh *me_low, BakePixel pixel_array_from[], - BakeHighPolyData highpoly[], const int tot_highpoly, const int num_pixels, const bool is_custom_cage, + BakeHighPolyData highpoly[], const int tot_highpoly, const size_t num_pixels, const bool is_custom_cage, const float cage_extrusion, float mat_low[4][4], float mat_cage[4][4], struct Mesh *me_cage); void RE_bake_pixels_populate( struct Mesh *me, struct BakePixel *pixel_array, - const int num_pixels, const struct BakeImages *bake_images, const char *uv_layer); + const size_t num_pixels, const struct BakeImages *bake_images, const char *uv_layer); -void RE_bake_mask_fill(const BakePixel pixel_array[], const int num_pixels, char *mask); +void RE_bake_mask_fill(const BakePixel pixel_array[], const size_t num_pixels, char *mask); void RE_bake_margin(struct ImBuf *ibuf, char *mask, const int margin); void RE_bake_normal_world_to_object( - const BakePixel pixel_array[], const int num_pixels, const int depth, float result[], + const BakePixel pixel_array[], const size_t num_pixels, const int depth, float result[], struct Object *ob, const BakeNormalSwizzle normal_swizzle[3]); void RE_bake_normal_world_to_tangent( - const BakePixel pixel_array[], const int num_pixels, const int depth, float result[], + const BakePixel pixel_array[], const size_t num_pixels, const int depth, float result[], struct Mesh *me, const BakeNormalSwizzle normal_swizzle[3], float mat[4][4]); void RE_bake_normal_world_to_world( - const BakePixel pixel_array[], const int num_pixels, const int depth, float result[], + const BakePixel pixel_array[], const size_t num_pixels, const int depth, float result[], const BakeNormalSwizzle normal_swizzle[3]); void RE_bake_ibuf_clear(struct Image *image, const bool is_tangent); diff --git a/source/blender/render/extern/include/RE_pipeline.h b/source/blender/render/extern/include/RE_pipeline.h index 68ac0cd3073..3b54de4c943 100644 --- a/source/blender/render/extern/include/RE_pipeline.h +++ b/source/blender/render/extern/include/RE_pipeline.h @@ -194,6 +194,7 @@ void RE_InitState(struct Render *re, struct Render *source, struct RenderData *r struct SceneRenderLayer *srl, int winx, int winy, rcti *disprect); void RE_ChangeResolution(struct Render *re, int winx, int winy, rcti *disprect); +void RE_ChangeModeFlag(struct Render *re, int flag, bool clear); /* set up the viewplane/perspective matrix, three choices */ struct Object *RE_GetCamera(struct Render *re); /* return camera override if set */ @@ -234,6 +235,7 @@ void RE_BlenderAnim(struct Render *re, struct Main *bmain, struct Scene *scene, unsigned int lay_override, int sfra, int efra, int tfra); #ifdef WITH_FREESTYLE void RE_RenderFreestyleStrokes(struct Render *re, struct Main *bmain, struct Scene *scene, int render); +void RE_RenderFreestyleExternal(struct Render *re); #endif /* error reporting */ diff --git a/source/blender/render/intern/include/render_types.h b/source/blender/render/intern/include/render_types.h index 536a2b8a85f..b87b1e6f367 100644 --- a/source/blender/render/intern/include/render_types.h +++ b/source/blender/render/intern/include/render_types.h @@ -595,7 +595,9 @@ typedef struct LampRen { float imat[3][3]; float spottexfac; float sh_invcampos[3], sh_zfac; /* sh_= spothalo */ - + + float lampmat[4][4]; /* worls space lamp matrix, used for scene rotation */ + float mat[3][3]; /* 3x3 part from lampmat x viewmat */ float area[8][3], areasize; diff --git a/source/blender/render/intern/source/bake.c b/source/blender/render/intern/source/bake.c index f2793a9bc5b..15634c93491 100644 --- a/source/blender/render/intern/source/bake.c +++ b/source/blender/render/intern/source/bake.c @@ -174,7 +174,7 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua /* only do AO for a full bake (and obviously AO bakes) * AO for light bakes is a leftover and might not be needed */ - if (ELEM3(bs->type, RE_BAKE_ALL, RE_BAKE_AO, RE_BAKE_LIGHT)) + if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_AO, RE_BAKE_LIGHT)) shade_samples_do_AO(ssamp); if (shi->mat->nodetree && shi->mat->use_nodes) { @@ -303,7 +303,7 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua rgb_float_to_uchar(col, shr.combined); } - if (ELEM3(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE, RE_BAKE_VERTEX_COLORS)) { + if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE, RE_BAKE_VERTEX_COLORS)) { col[3] = FTOCHAR(shr.alpha); } else { diff --git a/source/blender/render/intern/source/bake_api.c b/source/blender/render/intern/source/bake_api.c index efa8c9b98f4..90deac2de32 100644 --- a/source/blender/render/intern/source/bake_api.c +++ b/source/blender/render/intern/source/bake_api.c @@ -120,7 +120,7 @@ static void store_bake_pixel(void *handle, int x, int y, float u, float v) BakePixel *pixel; const int width = bd->bk_image->width; - const int offset = bd->bk_image->offset; + const size_t offset = bd->bk_image->offset; const int i = offset + y * width + x; pixel = &bd->pixel_array[i]; @@ -134,9 +134,9 @@ static void store_bake_pixel(void *handle, int x, int y, float u, float v) pixel->dv_dy = bd->dv_dy; } -void RE_bake_mask_fill(const BakePixel pixel_array[], const int num_pixels, char *mask) +void RE_bake_mask_fill(const BakePixel pixel_array[], const size_t num_pixels, char *mask) { - int i; + size_t i; if (!mask) return; @@ -356,7 +356,7 @@ static void mesh_calc_tri_tessface( MFace *mface; MVert *mvert; TSpace *tspace; - float *precomputed_normals; + float *precomputed_normals = NULL; bool calculate_normal; mface = CustomData_get_layer(&me->fdata, CD_MFACE); @@ -379,7 +379,7 @@ static void mesh_calc_tri_tessface( p_id = -1; for (i = 0; i < me->totface; i++) { MFace *mf = &mface[i]; - TSpace *ts = &tspace[i * 4]; + TSpace *ts = tangent ? &tspace[i * 4] : NULL; p_id++; @@ -438,10 +438,10 @@ static void mesh_calc_tri_tessface( bool RE_bake_pixels_populate_from_objects( struct Mesh *me_low, BakePixel pixel_array_from[], - BakeHighPolyData highpoly[], const int tot_highpoly, const int num_pixels, const bool is_custom_cage, + BakeHighPolyData highpoly[], const int tot_highpoly, const size_t num_pixels, const bool is_custom_cage, const float cage_extrusion, float mat_low[4][4], float mat_cage[4][4], struct Mesh *me_cage) { - int i; + size_t i; int primitive_id; float u, v; float imat_low [4][4]; @@ -461,7 +461,7 @@ bool RE_bake_pixels_populate_from_objects( tris_high = MEM_callocN(sizeof(TriTessFace *) * tot_highpoly, "MVerts Highpoly Mesh Array"); /* assume all highpoly tessfaces are triangles */ - dm_highpoly = MEM_callocN(sizeof(DerivedMesh *) * tot_highpoly, "Highpoly Derived Meshes"); + dm_highpoly = MEM_mallocN(sizeof(DerivedMesh *) * tot_highpoly, "Highpoly Derived Meshes"); treeData = MEM_callocN(sizeof(BVHTreeFromMesh) * tot_highpoly, "Highpoly BVH Trees"); if (!is_cage) { @@ -594,11 +594,11 @@ static void bake_differentials(BakeDataZSpan *bd, const float *uv1, const float void RE_bake_pixels_populate( Mesh *me, BakePixel pixel_array[], - const int num_pixels, const BakeImages *bake_images, const char *uv_layer) + const size_t num_pixels, const BakeImages *bake_images, const char *uv_layer) { BakeDataZSpan bd; - int i, a; - int p_id; + size_t i; + int a, p_id; MTFace *mtface; MFace *mface; @@ -725,11 +725,11 @@ static void normal_compress(float out[3], const float in[3], const BakeNormalSwi * This function converts an object space normal map to a tangent space normal map for a given low poly mesh */ void RE_bake_normal_world_to_tangent( - const BakePixel pixel_array[], const int num_pixels, const int depth, + const BakePixel pixel_array[], const size_t num_pixels, const int depth, float result[], Mesh *me, const BakeNormalSwizzle normal_swizzle[3], float mat[4][4]) { - int i; + size_t i; TriTessFace *triangles; @@ -756,7 +756,7 @@ void RE_bake_normal_world_to_tangent( float tsm[3][3]; /* tangent space matrix */ float itsm[3][3]; - int offset; + size_t offset; float nor[3]; /* texture normal */ bool is_smooth; @@ -834,16 +834,16 @@ void RE_bake_normal_world_to_tangent( } void RE_bake_normal_world_to_object( - const BakePixel pixel_array[], const int num_pixels, const int depth, + const BakePixel pixel_array[], const size_t num_pixels, const int depth, float result[], struct Object *ob, const BakeNormalSwizzle normal_swizzle[3]) { - int i; + size_t i; float iobmat[4][4]; invert_m4_m4(iobmat, ob->obmat); for (i = 0; i < num_pixels; i++) { - int offset; + size_t offset; float nor[3]; if (pixel_array[i].primitive_id == -1) @@ -852,7 +852,8 @@ void RE_bake_normal_world_to_object( offset = i * depth; normal_uncompress(nor, &result[offset]); - mul_m4_v3(iobmat, nor); + /* rotates only without translation */ + mul_mat3_m4_v3(iobmat, nor); normalize_v3(nor); /* save back the values */ @@ -861,13 +862,13 @@ void RE_bake_normal_world_to_object( } void RE_bake_normal_world_to_world( - const BakePixel pixel_array[], const int num_pixels, const int depth, + const BakePixel pixel_array[], const size_t num_pixels, const int depth, float result[], const BakeNormalSwizzle normal_swizzle[3]) { - int i; + size_t i; for (i = 0; i < num_pixels; i++) { - int offset; + size_t offset; float nor[3]; if (pixel_array[i].primitive_id == -1) @@ -907,12 +908,12 @@ void RE_bake_ibuf_clear(Image *image, const bool is_tangent) /** * not the real UV, but the internal per-face UV instead * I'm using it to test if everything is correct */ -static bool bake_uv(const BakePixel pixel_array[], const int num_pixels, const int depth, float result[]) +static bool bake_uv(const BakePixel pixel_array[], const size_t num_pixels, const int depth, float result[]) { - int i; + size_t i; for (i=0; i < num_pixels; i++) { - int offset = i * depth; + size_t offset = i * depth; copy_v2_v2(&result[offset], pixel_array[i].uv); } @@ -921,7 +922,7 @@ static bool bake_uv(const BakePixel pixel_array[], const int num_pixels, const i bool RE_bake_internal( Render *UNUSED(re), Object *UNUSED(object), const BakePixel pixel_array[], - const int num_pixels, const int depth, const ScenePassType pass_type, float result[]) + const size_t num_pixels, const int depth, const ScenePassType pass_type, float result[]) { switch (pass_type) { case SCE_PASS_UV: diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 36fd1b2d6af..e6f054583b1 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -2930,8 +2930,7 @@ static struct edgesort *make_mesh_edge_lookup(DerivedMesh *dm, int *totedgesort) /* make sorted table with edges and face indices in it */ for (a= totface, mf= mface; a>0; a--, mf++) { - if (mf->v4) totedge+=4; - else if (mf->v3) totedge+=3; + totedge += mf->v4 ? 4 : 3; } if (totedge==0) @@ -2946,8 +2945,9 @@ static struct edgesort *make_mesh_edge_lookup(DerivedMesh *dm, int *totedgesort) to_edgesort(ed++, 2, 3, mf->v3, mf->v4, a); to_edgesort(ed++, 3, 0, mf->v4, mf->v1, a); } - else if (mf->v3) + else { to_edgesort(ed++, 2, 3, mf->v3, mf->v1, a); + } } qsort(edsort, totedge, sizeof(struct edgesort), vergedgesort); @@ -3650,6 +3650,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) mul_m4_m4m4(mat, re->viewmat, ob->obmat); invert_m4_m4(ob->imat, mat); + copy_m4_m4(lar->lampmat, ob->obmat); copy_m3_m4(lar->mat, mat); copy_m3_m4(lar->imat, ob->imat); @@ -3704,8 +3705,8 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) /* Annoying, lamp UI does this, but the UI might not have been used? - add here too. * make sure this matches buttons_shading.c's logic */ - if (ELEM4(la->type, LA_AREA, LA_SPOT, LA_SUN, LA_LOCAL) && (la->mode & LA_SHAD_RAY)) - if (ELEM3(la->type, LA_SPOT, LA_SUN, LA_LOCAL)) + if (ELEM(la->type, LA_AREA, LA_SPOT, LA_SUN, LA_LOCAL) && (la->mode & LA_SHAD_RAY)) + if (ELEM(la->type, LA_SPOT, LA_SUN, LA_LOCAL)) if (la->ray_samp_method == LA_SAMP_CONSTANT) la->ray_samp_method = LA_SAMP_HALTON; lar->ray_samp_method= la->ray_samp_method; @@ -4546,8 +4547,7 @@ static void set_dupli_tex_mat(Render *re, ObjectInstanceRen *obi, DupliObject *d obi->duplitexmat= BLI_memarena_alloc(re->memArena, sizeof(float)*4*4); invert_m4_m4(imat, dob->mat); - mul_serie_m4(obi->duplitexmat, re->viewmat, omat, imat, re->viewinv, - NULL, NULL, NULL, NULL); + mul_m4_series(obi->duplitexmat, re->viewmat, omat, imat, re->viewinv); } copy_v3_v3(obi->dupliorco, dob->orco); @@ -4791,13 +4791,12 @@ static int allow_render_object(Render *re, Object *ob, int nolamps, int onlysele { if (is_object_hidden(re, ob)) return 0; - - /* override not showing object when duplis are used with particles */ - if (ob->transflag & OB_DUPLIPARTS) { - /* pass */ /* let particle system(s) handle showing vs. not showing */ - } - else if ((ob->transflag & OB_DUPLI) && !(ob->transflag & OB_DUPLIFRAMES)) { - return 0; + + /* Only handle dupli-hiding here if there is no particle systems. Else, let those handle show/noshow. */ + if (!ob->particlesystem.first) { + if ((ob->transflag & OB_DUPLI) && !(ob->transflag & OB_DUPLIFRAMES)) { + return 0; + } } /* don't add non-basic meta objects, ends up having renderobjects with no geometry */ @@ -4832,7 +4831,7 @@ static int allow_render_dupli_instance(Render *UNUSED(re), DupliObject *dob, Obj } for (psys=obd->particlesystem.first; psys; psys=psys->next) - if (!ELEM5(psys->part->ren_as, PART_DRAW_BB, PART_DRAW_LINE, PART_DRAW_PATH, PART_DRAW_OB, PART_DRAW_GR)) + if (!ELEM(psys->part->ren_as, PART_DRAW_BB, PART_DRAW_LINE, PART_DRAW_PATH, PART_DRAW_OB, PART_DRAW_GR)) return 0; /* don't allow lamp, animated duplis, or radio render */ @@ -5834,8 +5833,8 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay, Object *camera; float mat[4][4]; float amb[3]; - const short onlyselected= !ELEM5(type, RE_BAKE_LIGHT, RE_BAKE_ALL, RE_BAKE_SHADOW, RE_BAKE_AO, RE_BAKE_VERTEX_COLORS); - const short nolamps= ELEM5(type, RE_BAKE_NORMALS, RE_BAKE_TEXTURE, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE, RE_BAKE_VERTEX_COLORS); + const short onlyselected= !ELEM(type, RE_BAKE_LIGHT, RE_BAKE_ALL, RE_BAKE_SHADOW, RE_BAKE_AO, RE_BAKE_VERTEX_COLORS); + const short nolamps= ELEM(type, RE_BAKE_NORMALS, RE_BAKE_TEXTURE, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE, RE_BAKE_VERTEX_COLORS); re->main= bmain; re->scene= scene; @@ -5859,7 +5858,7 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay, if (type==RE_BAKE_VERTEX_COLORS) re->flag |= R_NEED_VCOL; - if (!actob && ELEM6(type, RE_BAKE_LIGHT, RE_BAKE_NORMALS, RE_BAKE_TEXTURE, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE, RE_BAKE_VERTEX_COLORS)) { + if (!actob && ELEM(type, RE_BAKE_LIGHT, RE_BAKE_NORMALS, RE_BAKE_TEXTURE, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE, RE_BAKE_VERTEX_COLORS)) { re->r.mode &= ~R_SHADOW; re->r.mode &= ~R_RAYTRACE; } diff --git a/source/blender/render/intern/source/envmap.c b/source/blender/render/intern/source/envmap.c index 28b29261e4e..06be00a5a5e 100644 --- a/source/blender/render/intern/source/envmap.c +++ b/source/blender/render/intern/source/envmap.c @@ -329,9 +329,9 @@ void env_rotate_scene(Render *re, float mat[4][4], int do_rotate) /* copy from add_render_lamp */ if (do_rotate == 1) - mul_m4_m4m4(tmpmat, re->viewmat, go->ob->obmat); + mul_m4_m4m4(tmpmat, re->viewmat, lar->lampmat); else - mul_m4_m4m4(tmpmat, re->viewmat_orig, go->ob->obmat); + mul_m4_m4m4(tmpmat, re->viewmat_orig, lar->lampmat); invert_m4_m4(go->ob->imat, tmpmat); copy_m3_m4(lar->mat, tmpmat); diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c index 58e3038682c..888f1330373 100644 --- a/source/blender/render/intern/source/external_engine.c +++ b/source/blender/render/intern/source/external_engine.c @@ -425,7 +425,7 @@ bool RE_bake_has_engine(Render *re) bool RE_bake_engine( Render *re, Object *object, const BakePixel pixel_array[], - const int num_pixels, const int depth, + const size_t num_pixels, const int depth, const ScenePassType pass_type, float result[]) { RenderEngineType *type = RE_engines_find(re->r.engine); @@ -454,8 +454,8 @@ bool RE_bake_engine( engine->resolution_y = re->winy; RE_parts_init(re, false); - engine->tile_x = re->partx; - engine->tile_y = re->party; + engine->tile_x = re->r.tilex; + engine->tile_y = re->r.tiley; /* update is only called so we create the engine.session */ if (type->update) @@ -676,6 +676,11 @@ int RE_engine_render(Render *re, int do_all) if (BKE_reports_contain(re->reports, RPT_ERROR)) G.is_break = true; +#ifdef WITH_FREESTYLE + if (re->r.mode & R_EDGE_FRS) + RE_RenderFreestyleExternal(re); +#endif + return 1; } diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c index 7d4b70cea15..12701099e18 100644 --- a/source/blender/render/intern/source/imagetexture.c +++ b/source/blender/render/intern/source/imagetexture.c @@ -791,176 +791,39 @@ static void area_sample(TexResult *texr, ImBuf *ibuf, float fx, float fy, afdata texr->ta = texr->talpha ? texr->ta*xsd : (clip ? cw*xsd : 1.f); } -/* table of (exp(ar) - exp(a)) / (1 - exp(a)) for r in range [0, 1] and a = -2 - * used instead of actual gaussian, otherwise at high texture magnifications circular artifacts are visible */ -#define EWA_MAXIDX 255 -static const float EWA_WTS[EWA_MAXIDX + 1] = { - 1.f, 0.990965f, 0.982f, 0.973105f, 0.96428f, 0.955524f, 0.946836f, 0.938216f, 0.929664f, - 0.921178f, 0.912759f, 0.904405f, 0.896117f, 0.887893f, 0.879734f, 0.871638f, 0.863605f, - 0.855636f, 0.847728f, 0.839883f, 0.832098f, 0.824375f, 0.816712f, 0.809108f, 0.801564f, - 0.794079f, 0.786653f, 0.779284f, 0.771974f, 0.76472f, 0.757523f, 0.750382f, 0.743297f, - 0.736267f, 0.729292f, 0.722372f, 0.715505f, 0.708693f, 0.701933f, 0.695227f, 0.688572f, - 0.68197f, 0.67542f, 0.66892f, 0.662471f, 0.656073f, 0.649725f, 0.643426f, 0.637176f, - 0.630976f, 0.624824f, 0.618719f, 0.612663f, 0.606654f, 0.600691f, 0.594776f, 0.588906f, - 0.583083f, 0.577305f, 0.571572f, 0.565883f, 0.56024f, 0.55464f, 0.549084f, 0.543572f, - 0.538102f, 0.532676f, 0.527291f, 0.521949f, 0.516649f, 0.511389f, 0.506171f, 0.500994f, - 0.495857f, 0.490761f, 0.485704f, 0.480687f, 0.475709f, 0.470769f, 0.465869f, 0.461006f, - 0.456182f, 0.451395f, 0.446646f, 0.441934f, 0.437258f, 0.432619f, 0.428017f, 0.42345f, - 0.418919f, 0.414424f, 0.409963f, 0.405538f, 0.401147f, 0.39679f, 0.392467f, 0.388178f, - 0.383923f, 0.379701f, 0.375511f, 0.371355f, 0.367231f, 0.363139f, 0.359079f, 0.355051f, - 0.351055f, 0.347089f, 0.343155f, 0.339251f, 0.335378f, 0.331535f, 0.327722f, 0.323939f, - 0.320186f, 0.316461f, 0.312766f, 0.3091f, 0.305462f, 0.301853f, 0.298272f, 0.294719f, - 0.291194f, 0.287696f, 0.284226f, 0.280782f, 0.277366f, 0.273976f, 0.270613f, 0.267276f, - 0.263965f, 0.26068f, 0.257421f, 0.254187f, 0.250979f, 0.247795f, 0.244636f, 0.241502f, - 0.238393f, 0.235308f, 0.232246f, 0.229209f, 0.226196f, 0.223206f, 0.220239f, 0.217296f, - 0.214375f, 0.211478f, 0.208603f, 0.20575f, 0.20292f, 0.200112f, 0.197326f, 0.194562f, - 0.191819f, 0.189097f, 0.186397f, 0.183718f, 0.18106f, 0.178423f, 0.175806f, 0.17321f, - 0.170634f, 0.168078f, 0.165542f, 0.163026f, 0.16053f, 0.158053f, 0.155595f, 0.153157f, - 0.150738f, 0.148337f, 0.145955f, 0.143592f, 0.141248f, 0.138921f, 0.136613f, 0.134323f, - 0.132051f, 0.129797f, 0.12756f, 0.125341f, 0.123139f, 0.120954f, 0.118786f, 0.116635f, - 0.114501f, 0.112384f, 0.110283f, 0.108199f, 0.106131f, 0.104079f, 0.102043f, 0.100023f, - 0.0980186f, 0.09603f, 0.094057f, 0.0920994f, 0.0901571f, 0.08823f, 0.0863179f, 0.0844208f, - 0.0825384f, 0.0806708f, 0.0788178f, 0.0769792f, 0.0751551f, 0.0733451f, 0.0715493f, 0.0697676f, - 0.0679997f, 0.0662457f, 0.0645054f, 0.0627786f, 0.0610654f, 0.0593655f, 0.0576789f, 0.0560055f, - 0.0543452f, 0.0526979f, 0.0510634f, 0.0494416f, 0.0478326f, 0.0462361f, 0.0446521f, 0.0430805f, - 0.0415211f, 0.039974f, 0.0384389f, 0.0369158f, 0.0354046f, 0.0339052f, 0.0324175f, 0.0309415f, - 0.029477f, 0.0280239f, 0.0265822f, 0.0251517f, 0.0237324f, 0.0223242f, 0.020927f, 0.0195408f, - 0.0181653f, 0.0168006f, 0.0154466f, 0.0141031f, 0.0127701f, 0.0114476f, 0.0101354f, 0.00883339f, - 0.00754159f, 0.00625989f, 0.00498819f, 0.00372644f, 0.00247454f, 0.00123242f, 0.f -}; - /* test if a float value is 'nan' * there is a C99 function for this: isnan(), but blender seems to use C90 (according to gcc warns), * and may not be supported by other compilers either */ +/* TODO(sergey): Consider using isnan(), it's used in the other areas. */ #ifndef ISNAN -#define ISNAN(x) ((x) != (x)) +# define ISNAN(x) ((x) != (x)) #endif -//static int ISNAN(float x) { return (x != x); } -static void radangle2imp(float a2, float b2, float th, float *A, float *B, float *C, float *F) -{ - float ct2 = cosf(th); - const float st2 = 1.0f - ct2 * ct2; /* <- sin(th)^2 */ - ct2 *= ct2; - *A = a2*st2 + b2*ct2; - *B = (b2 - a2)*sinf(2.f*th); - *C = a2*ct2 + b2*st2; - *F = a2*b2; -} +typedef struct ReadEWAData { + ImBuf *ibuf; + afdata_t *AFD; +} ReadEWAData; -/* all tests here are done to make sure possible overflows are hopefully minimized */ -static void imp2radangle(float A, float B, float C, float F, float *a, float *b, float *th, float *ecc) +static void ewa_read_pixel_cb(void *userdata, int x, int y, float result[4]) { - if (F <= 1e-5f) { /* use arbitrary major radius, zero minor, infinite eccentricity */ - *a = sqrtf(A > C ? A : C); - *b = 0.f; - *ecc = 1e10f; - *th = 0.5f*(atan2f(B, A - C) + (float)M_PI); - } - else { - const float AmC = A - C, ApC = A + C, F2 = F*2.f; - const float r = sqrtf(AmC*AmC + B*B); - float d = ApC - r; - *a = (d <= 0.f) ? sqrtf(A > C ? A : C) : sqrtf(F2 / d); - d = ApC + r; - if (d <= 0.f) { - *b = 0.f; - *ecc = 1e10f; - } - else { - *b = sqrtf(F2 / d); - *ecc = *a / *b; - } - /* incr theta by 0.5*pi (angle of major axis) */ - *th = 0.5f*(atan2f(B, AmC) + (float)M_PI); - } + ReadEWAData *data = (ReadEWAData *) userdata; + ibuf_get_color_clip(result, data->ibuf, x, y, data->AFD->extflag); } static void ewa_eval(TexResult *texr, ImBuf *ibuf, float fx, float fy, afdata_t *AFD) { - /* scaling dxt/dyt by full resolution can cause overflow because of huge A/B/C and esp. F values, - * scaling by aspect ratio alone does the opposite, so try something in between instead... */ - const float ff2 = ibuf->x, ff = sqrtf(ff2), q = ibuf->y / ff; - const float Ux = AFD->dxt[0]*ff, Vx = AFD->dxt[1]*q, Uy = AFD->dyt[0]*ff, Vy = AFD->dyt[1]*q; - float A = Vx*Vx + Vy*Vy; - float B = -2.f*(Ux*Vx + Uy*Vy); - float C = Ux*Ux + Uy*Uy; - float F = A*C - B*B*0.25f; - float a, b, th, ecc, a2, b2, ue, ve, U0, V0, DDQ, U, ac1, ac2, BU, d; /* TXF alpha: cw = 0.f; */ - int u, v, u1, u2, v1, v2; /* TXF alpha: clip = 0; */ - - /* The so-called 'high' quality ewa method simply adds a constant of 1 to both A & C, - * so the ellipse always covers at least some texels. But since the filter is now always larger, - * it also means that everywhere else it's also more blurry then ideally should be the case. - * So instead here the ellipse radii are modified instead whenever either is too low. - * Use a different radius based on interpolation switch, just enough to anti-alias when interpolation is off, - * and slightly larger to make result a bit smoother than bilinear interpolation when interpolation is on - * (minimum values: const float rmin = intpol ? 1.f : 0.5f;) */ - const float rmin = (AFD->intpol ? 1.5625f : 0.765625f)/ff2; - imp2radangle(A, B, C, F, &a, &b, &th, &ecc); - if ((b2 = b*b) < rmin) { - if ((a2 = a*a) < rmin) { - B = 0.f; - A = C = rmin; - F = A*C; - } - else { - b2 = rmin; - radangle2imp(a2, b2, th, &A, &B, &C, &F); - } - } - - ue = ff*sqrtf(C); - ve = ff*sqrtf(A); - d = (float)(EWA_MAXIDX + 1) / (F*ff2); - A *= d; - B *= d; - C *= d; - - U0 = fx*ibuf->x; - V0 = fy*ibuf->y; - u1 = (int)(floorf(U0 - ue)); - u2 = (int)(ceilf(U0 + ue)); - v1 = (int)(floorf(V0 - ve)); - v2 = (int)(ceilf(V0 + ve)); - U0 -= 0.5f; - V0 -= 0.5f; - DDQ = 2.f*A; - U = u1 - U0; - ac1 = A*(2.f*U + 1.f); - ac2 = A*U*U; - BU = B*U; + ReadEWAData data; + float uv[2] = {fx, fy}; + data.ibuf = ibuf; + data.AFD = AFD; + BLI_ewa_filter(ibuf->x, ibuf->y, + AFD->intpol != 0, + texr->talpha, + uv, AFD->dxt, AFD->dyt, + ewa_read_pixel_cb, + &data, + &texr->tr); - d = texr->tr = texr->tb = texr->tg = texr->ta = 0.f; - for (v=v1; v<=v2; ++v) { - const float V = v - V0; - float DQ = ac1 + B*V; - float Q = (C*V + BU)*V + ac2; - for (u=u1; u<=u2; ++u) { - if (Q < (float)(EWA_MAXIDX + 1)) { - float tc[4]; - const float wt = EWA_WTS[(Q < 0.f) ? 0 : (unsigned int)Q]; - /*const int out =*/ ibuf_get_color_clip(tc, ibuf, u, v, AFD->extflag); - /* TXF alpha: clip |= out; - * TXF alpha: cw += out ? 0.f : wt; */ - texr->tr += tc[0]*wt; - texr->tg += tc[1]*wt; - texr->tb += tc[2]*wt; - texr->ta += texr->talpha ? tc[3]*wt : 0.f; - d += wt; - } - Q += DQ; - DQ += DDQ; - } - } - - /* d should hopefully never be zero anymore */ - d = 1.f/d; - texr->tr *= d; - texr->tg *= d; - texr->tb *= d; - /* clipping can be ignored if alpha used, texr->ta already includes filtered edge */ - texr->ta = texr->talpha ? texr->ta*d : 1.f; /* TXF alpha (clip ? cw*d : 1.f); */ } static void feline_eval(TexResult *texr, ImBuf *ibuf, float fx, float fy, afdata_t *AFD) @@ -1304,7 +1167,7 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex const float C = Ux*Ux + Uy*Uy; const float F = A*C - B*B*0.25f; float a, b, th, ecc; - imp2radangle(A, B, C, F, &a, &b, &th, &ecc); + BLI_ewa_imp2radangle(A, B, C, F, &a, &b, &th, &ecc); if (tex->texfilter == TXF_FELINE) { float fProbes; a *= ff; @@ -1408,7 +1271,7 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex const float C = Ux*Ux + Uy*Uy; const float F = A*C - B*B*0.25f; float a, b, th, ecc, fProbes; - imp2radangle(A, B, C, F, &a, &b, &th, &ecc); + BLI_ewa_imp2radangle(A, B, C, F, &a, &b, &th, &ecc); a *= ff; b *= ff; a = max_ff(a, 1.0f); diff --git a/source/blender/render/intern/source/occlusion.c b/source/blender/render/intern/source/occlusion.c index f0fe5d054f0..0c6341fe9e5 100644 --- a/source/blender/render/intern/source/occlusion.c +++ b/source/blender/render/intern/source/occlusion.c @@ -45,6 +45,7 @@ #include "BLF_translation.h" +#include "BKE_node.h" #include "BKE_scene.h" @@ -194,14 +195,19 @@ static void occ_shade(ShadeSample *ssamp, ObjectInstanceRen *obi, VlakRen *vlr, } /* init 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_input_init_material(shi); + /* render */ shade_input_set_shade_texco(shi); - shade_material_loop(shi, shr); /* todo: nodes */ - + + if (shi->mat->nodetree && shi->mat->use_nodes) { + ntreeShaderExecTree(shi->mat->nodetree, shi, shr); + shi->mat = vlr->mat; /* shi->mat is being set in nodetree */ + } + else { + shade_material_loop(shi, shr); + } + copy_v3_v3(rad, shr->combined); } diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 2131b820bd4..8469d8c74f0 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -728,6 +728,7 @@ static void render_result_rescale(Render *re) void RE_ChangeResolution(Render *re, int winx, int winy, rcti *disprect) { re_init_resolution(re, NULL, winx, winy, disprect); + RE_parts_clamp(re); if (re->result) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); @@ -736,6 +737,20 @@ void RE_ChangeResolution(Render *re, int winx, int winy, rcti *disprect) } } +/* TODO(sergey): This is a bit hackish, used to temporary disable freestyle when + * doing viewport render. Needs some better integration of BI viewport rendering + * into the pipeline. + */ +void RE_ChangeModeFlag(Render *re, int flag, bool clear) +{ + if (clear) { + re->r.mode &= ~flag; + } + else { + re->r.mode |= flag; + } +} + /* update some variables that can be animated, and otherwise wouldn't be due to * RenderData getting copied once at the start of animation render */ void render_update_anim_renderdata(Render *re, RenderData *rd) @@ -1713,7 +1728,7 @@ static int composite_needs_render(Scene *sce, int this_scene) if ((sce->r.scemode & R_DOCOMP) == 0) return 1; for (node = ntree->nodes.first; node; node = node->next) { - if (node->type == CMP_NODE_R_LAYERS) + if (node->type == CMP_NODE_R_LAYERS && (node->flag & NODE_MUTED) == 0) if (this_scene == 0 || node->id == NULL || node->id == &sce->id) return 1; } @@ -1852,7 +1867,7 @@ static void tag_scenes_for_render(Render *re) /* check for render-layers nodes using other scenes, we tag them LIB_DOIT */ for (node = re->scene->nodetree->nodes.first; node; node = node->next) { node->flag &= ~NODE_TEST; - if (node->type == CMP_NODE_R_LAYERS) { + if (node->type == CMP_NODE_R_LAYERS && (node->flag & NODE_MUTED) == 0) { if (node->id) { if (!MAIN_VERSION_ATLEAST(re->main, 265, 5)) { if (rlayer_node_uses_alpha(re->scene->nodetree, node)) { @@ -1901,7 +1916,7 @@ static void ntree_render_scenes(Render *re) /* now foreach render-result node tagged we do a full render */ /* results are stored in a way compisitor will find it */ for (node = re->scene->nodetree->nodes.first; node; node = node->next) { - if (node->type == CMP_NODE_R_LAYERS) { + if (node->type == CMP_NODE_R_LAYERS && (node->flag & NODE_MUTED) == 0) { if (node->id && node->id != (ID *)re->scene) { if (node->flag & NODE_TEST) { Scene *scene = (Scene *)node->id; @@ -1935,6 +1950,8 @@ static void add_freestyle(Render *re, int render) { SceneRenderLayer *srl, *actsrl; LinkData *link; + Render *r; + const bool do_link = (re->r.mode & R_MBLUR) == 0 || re->i.curblur == re->r.mblur_samples; actsrl = BLI_findlink(&re->r.layers, re->r.actlay); @@ -1951,15 +1968,17 @@ static void add_freestyle(Render *re, int render) FRS_init_stroke_rendering(re); - for (srl= (SceneRenderLayer *)re->r.layers.first; srl; srl= srl->next) { - - link = (LinkData *)MEM_callocN(sizeof(LinkData), "LinkData to Freestyle render"); - BLI_addtail(&re->freestyle_renders, link); - + for (srl = (SceneRenderLayer *)re->r.layers.first; srl; srl = srl->next) { + if (do_link) { + link = (LinkData *)MEM_callocN(sizeof(LinkData), "LinkData to Freestyle render"); + BLI_addtail(&re->freestyle_renders, link); + } if ((re->r.scemode & R_SINGLE_LAYER) && srl != actsrl) continue; if (FRS_is_freestyle_enabled(srl)) { - link->data = (void *)FRS_do_stroke_rendering(re, srl, render); + r = FRS_do_stroke_rendering(re, srl, render); + if (do_link) + link->data = (void *)r; } } @@ -2183,7 +2202,7 @@ void RE_MergeFullSample(Render *re, Main *bmain, Scene *sce, bNodeTree *ntree) #endif for (node = ntree->nodes.first; node; node = node->next) { - if (node->type == CMP_NODE_R_LAYERS) { + if (node->type == CMP_NODE_R_LAYERS && (node->flag & NODE_MUTED) == 0) { Scene *nodescene = (Scene *)node->id; if (nodescene == NULL) nodescene = sce; @@ -2478,7 +2497,7 @@ static bool check_valid_compositing_camera(Scene *scene, Object *camera_override bNode *node = scene->nodetree->nodes.first; while (node) { - if (node->type == CMP_NODE_R_LAYERS) { + if (node->type == CMP_NODE_R_LAYERS && (node->flag & NODE_MUTED) == 0) { Scene *sce = node->id ? (Scene *)node->id : scene; if (!sce->camera && !BKE_scene_camera_find(sce)) { @@ -2760,6 +2779,8 @@ void RE_SetReports(Render *re, ReportList *reports) void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, SceneRenderLayer *srl, Object *camera_override, unsigned int lay_override, int frame, const bool write_still) { + BLI_callback_exec(re->main, (ID *)scene, BLI_CB_EVT_RENDER_INIT); + /* ugly global still... is to prevent preview events and signal subsurfs etc to make full resol */ G.is_rendering = true; @@ -2806,6 +2827,16 @@ void RE_RenderFreestyleStrokes(Render *re, Main *bmain, Scene *scene, int render } re->result_ok = 1; } + +void RE_RenderFreestyleExternal(Render *re) +{ + if (!re->test_break(re->tbh)) { + RE_Database_FromScene(re, re->main, re->scene, re->lay, 1); + RE_Database_Preprocess(re); + add_freestyle(re, 1); + RE_Database_Free(re); + } +} #endif static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovieHandle *mh, const char *name_override) @@ -2924,6 +2955,8 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri int cfrao = scene->r.cfra; int nfra, totrendered = 0, totskipped = 0; + BLI_callback_exec(re->main, (ID *)scene, BLI_CB_EVT_RENDER_INIT); + /* do not fully call for each frame, it initializes & pops output window */ if (!render_initialize_from_main(re, &rd, bmain, scene, NULL, camera_override, lay_override, 0, 1)) return; diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index 253f8a1383f..dd14c2495e8 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -3564,7 +3564,7 @@ Material *RE_init_sample_material(Material *orig_mat, Scene *scene) /* depending of material type, strip non-compatible mapping modes */ if (mat->material_type == MA_TYPE_SURFACE) { - if (!ELEM4(mtex->texco, TEXCO_ORCO, TEXCO_OBJECT, TEXCO_GLOB, TEXCO_UV)) { + if (!ELEM(mtex->texco, TEXCO_ORCO, TEXCO_OBJECT, TEXCO_GLOB, TEXCO_UV)) { /* ignore this texture */ mtex->texco = 0; continue; @@ -3573,7 +3573,7 @@ Material *RE_init_sample_material(Material *orig_mat, Scene *scene) mtex->mapto = (mtex->mapto & MAP_COL) | (mtex->mapto & MAP_ALPHA); } else if (mat->material_type == MA_TYPE_VOLUME) { - if (!ELEM3(mtex->texco, TEXCO_OBJECT, TEXCO_ORCO, TEXCO_GLOB)) { + if (!ELEM(mtex->texco, TEXCO_OBJECT, TEXCO_ORCO, TEXCO_GLOB)) { /* ignore */ mtex->texco = 0; continue; diff --git a/source/blender/render/intern/source/shadbuf.c b/source/blender/render/intern/source/shadbuf.c index 9d337e542a1..aa420d7e7c8 100644 --- a/source/blender/render/intern/source/shadbuf.c +++ b/source/blender/render/intern/source/shadbuf.c @@ -784,7 +784,7 @@ void makeshadowbuf(Render *re, LampRen *lar) perspective_m4(shb->winmat, -wsize, wsize, -wsize, wsize, shb->d, shb->clipend); mul_m4_m4m4(shb->persmat, shb->winmat, shb->viewmat); - if (ELEM3(lar->buftype, LA_SHADBUF_REGULAR, LA_SHADBUF_HALFWAY, LA_SHADBUF_DEEP)) { + if (ELEM(lar->buftype, LA_SHADBUF_REGULAR, LA_SHADBUF_HALFWAY, LA_SHADBUF_DEEP)) { shb->totbuf= lar->buffers; /* jitter, weights - not threadsafe! */ diff --git a/source/blender/render/intern/source/shadeoutput.c b/source/blender/render/intern/source/shadeoutput.c index ebf88efb50b..427d0eeed11 100644 --- a/source/blender/render/intern/source/shadeoutput.c +++ b/source/blender/render/intern/source/shadeoutput.c @@ -1706,9 +1706,19 @@ static void wrld_exposure_correct(float diff[3]) void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) { + /* Passes which might need to know material color. + * + * It seems to be faster to just calculate material color + * even if the pass doesn't really need it than trying to + * figure out whether color is really needed or not. + */ + const int color_passes = + SCE_PASS_COMBINED | SCE_PASS_RGBA | SCE_PASS_DIFFUSE | SCE_PASS_SPEC | + SCE_PASS_REFLECT | SCE_PASS_NORMAL | SCE_PASS_REFRACT | SCE_PASS_EMIT; + Material *ma= shi->mat; int passflag= shi->passflag; - + memset(shr, 0, sizeof(ShadeResult)); if (!(shi->mode & MA_TRANSP)) shi->alpha = 1.0f; @@ -1723,7 +1733,7 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) shi->refcol[0]= shi->refcol[1]= shi->refcol[2]= shi->refcol[3]= 0.0f; /* material color itself */ - if (passflag & (SCE_PASS_COMBINED|SCE_PASS_RGBA)) { + if (passflag & color_passes) { if (ma->mode & (MA_FACETEXTURE)) { shi->r= shi->vcol[0]; shi->g= shi->vcol[1]; diff --git a/source/blender/render/intern/source/volumetric.c b/source/blender/render/intern/source/volumetric.c index fe3af5b840e..d5c4c407bf6 100644 --- a/source/blender/render/intern/source/volumetric.c +++ b/source/blender/render/intern/source/volumetric.c @@ -499,7 +499,7 @@ static void vol_shade_one_lamp(struct ShadeInput *shi, const float co[3], const if (shi->mat->vol.shade_type == MA_VOL_SHADE_SHADOWED) { mul_v3_fl(lacol, vol_get_shadow(shi, lar, co)); } - else if (ELEM3(shi->mat->vol.shade_type, MA_VOL_SHADE_SHADED, MA_VOL_SHADE_MULTIPLE, MA_VOL_SHADE_SHADEDPLUSMULTIPLE)) { + else if (ELEM(shi->mat->vol.shade_type, MA_VOL_SHADE_SHADED, MA_VOL_SHADE_MULTIPLE, MA_VOL_SHADE_SHADEDPLUSMULTIPLE)) { Isect is; if (shi->mat->vol.shadeflag & MA_VOL_RECV_EXT_SHADOW) { |