diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-09-23 22:50:56 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-09-23 22:50:56 +0400 |
commit | a42ba82f638e481d7fd3c3ed2ba05c331ef6717e (patch) | |
tree | 81a2b9221799707b49b74a5df8bb3ff964ba78bd /source/blender/render | |
parent | 7afbdff1b6c348227e652e1c3071ab7ba7c91c44 (diff) | |
parent | a73dd3476e7d180d3320afc04d218ce22f2f3bfc (diff) |
Merged changes in the trunk up to revision 50829.
Conflicts resolved:
source/blender/blenloader/intern/readfile.c
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/pipeline.c
Also addressed code inconsistency due to changes in the trunk revision 50628 (color
management with OCIO) and 50806 (UV project material). OCIO-related changes are marked
OCIO_TODO as in some other files modified in revision 50628.
Diffstat (limited to 'source/blender/render')
24 files changed, 316 insertions, 346 deletions
diff --git a/source/blender/render/extern/include/RE_pipeline.h b/source/blender/render/extern/include/RE_pipeline.h index 1510d9adb10..395fbf8f01c 100644 --- a/source/blender/render/extern/include/RE_pipeline.h +++ b/source/blender/render/extern/include/RE_pipeline.h @@ -226,7 +226,7 @@ void RE_PreviewRender(struct Render *re, struct Main *bmain, struct Scene *scene int RE_ReadRenderResult(struct Scene *scene, struct Scene *scenode); int RE_WriteRenderResult(struct ReportList *reports, RenderResult *rr, const char *filename, int compress); -struct RenderResult *RE_MultilayerConvert(void *exrhandle, int rectx, int recty); +struct RenderResult *RE_MultilayerConvert(void *exrhandle, const char *colorspace, int predivide, int rectx, int recty); extern const float default_envmap_layout[]; int RE_WriteEnvmapResult(struct ReportList *reports, struct Scene *scene, struct EnvMap *env, const char *relpath, const char imtype, float layout[12]); diff --git a/source/blender/render/extern/include/RE_render_ext.h b/source/blender/render/extern/include/RE_render_ext.h index c07ed42332f..2a9a1becc42 100644 --- a/source/blender/render/extern/include/RE_render_ext.h +++ b/source/blender/render/extern/include/RE_render_ext.h @@ -39,10 +39,11 @@ /* called by meshtools */ struct View3D; struct Scene; +struct LinkNode; -void RE_make_sticky(struct Scene *scene, struct View3D *v3d); - -/* for radiosity module */ +void RE_make_sticky(struct Scene *scene, struct Object *camera, struct LinkNode *objects); + +/* for radiosity module */ struct RadView; struct RNode; struct Render; diff --git a/source/blender/render/extern/include/RE_shader_ext.h b/source/blender/render/extern/include/RE_shader_ext.h index 26a1b9908b3..57fb80f11c0 100644 --- a/source/blender/render/extern/include/RE_shader_ext.h +++ b/source/blender/render/extern/include/RE_shader_ext.h @@ -134,7 +134,7 @@ typedef struct ShadeInput { int har; /* hardness */ /* texture coordinates */ - float lo[3], gl[3], ref[3], orn[3], winco[3], sticky[3], vcol[4]; + float lo[3], gl[3], ref[3], orn[3], winco[3], vcol[4]; float refcol[4], displace[3]; float strandco, tang[3], nmapnorm[3], nmaptang[4], stress, winspeed[4]; float duplilo[3], dupliuv[3]; @@ -150,7 +150,6 @@ typedef struct ShadeInput { float dxno[3], dyno[3], dxview, dyview; float dxlv[3], dylv[3]; float dxwin[3], dywin[3]; - float dxsticky[3], dysticky[3]; float dxrefract[3], dyrefract[3]; float dxstrand, dystrand; diff --git a/source/blender/render/intern/include/render_result.h b/source/blender/render/intern/include/render_result.h index 303d4094f8e..5d61417cbaf 100644 --- a/source/blender/render/intern/include/render_result.h +++ b/source/blender/render/intern/include/render_result.h @@ -47,6 +47,8 @@ struct RenderLayer; struct RenderResult; struct Scene; struct rcti; +struct ColorManagedDisplaySettings; +struct ColorManagedViewSettings; /* New */ @@ -55,7 +57,7 @@ struct RenderResult *render_result_new(struct Render *re, struct RenderResult *render_result_new_full_sample(struct Render *re, struct ListBase *lb, struct rcti *partrct, int crop, int savebuffers); -struct RenderResult *render_result_new_from_exr(void *exrhandle, int rectx, int recty); +struct RenderResult *render_result_new_from_exr(void *exrhandle, const char *colorspace, int predivide, int rectx, int recty); /* Merge */ @@ -90,7 +92,9 @@ void render_result_rect_from_ibuf(struct RenderResult *rr, struct RenderData *rd void render_result_rect_fill_zero(struct RenderResult *rr); void render_result_rect_get_pixels(struct RenderResult *rr, struct RenderData *rd, - unsigned int *rect, int rectx, int recty); + unsigned int *rect, int rectx, int recty, + const struct ColorManagedViewSettings *view_settings, + const struct ColorManagedDisplaySettings *display_settings); #endif /* __RENDER_RESULT_H__ */ diff --git a/source/blender/render/intern/include/renderdatabase.h b/source/blender/render/intern/include/renderdatabase.h index 584e56836fa..d116dfe7b17 100644 --- a/source/blender/render/intern/include/renderdatabase.h +++ b/source/blender/render/intern/include/renderdatabase.h @@ -55,7 +55,6 @@ struct RadFace; typedef struct VertTableNode { struct VertRen *vert; float *rad; - float *sticky; float *strand; float *tangent; float *stress; @@ -110,7 +109,6 @@ struct ObjectRen *RE_addRenderObject(struct Render *re, struct Object *ob, struc struct ObjectInstanceRen *RE_addRenderInstance(struct Render *re, struct ObjectRen *obr, struct Object *ob, struct Object *par, int index, int psysindex, float mat[][4], int lay); void RE_makeRenderInstances(struct Render *re); -float *RE_vertren_get_sticky(struct ObjectRen *obr, struct VertRen *ver, int verify); float *RE_vertren_get_stress(struct ObjectRen *obr, struct VertRen *ver, int verify); float *RE_vertren_get_rad(struct ObjectRen *obr, struct VertRen *ver, int verify); float *RE_vertren_get_strand(struct ObjectRen *obr, struct VertRen *ver, int verify); diff --git a/source/blender/render/intern/include/zbuf.h b/source/blender/render/intern/include/zbuf.h index e4ee19d8ed2..e873111e6bf 100644 --- a/source/blender/render/intern/include/zbuf.h +++ b/source/blender/render/intern/include/zbuf.h @@ -139,5 +139,10 @@ void zbufclipwire(struct ZSpan *zspan, int obi, int zvlnr, int ec, void zbuf_make_winmat(Render *re, float winmat[][4]); void zbuf_render_project(float winmat[][4], const float co[3], float ho[4]); +/* sould not really be exposed, bad! */ +void hoco_to_zco(ZSpan *zspan, float zco[3], const float hoco[4]); +void zspan_scanconvert_strand(ZSpan *zspan, void *handle, float *v1, float *v2, float *v3, void (*func)(void *, int, int, float, float, float) ); +void zbufsinglewire(ZSpan *zspan, int obi, int zvlnr, const float ho1[4], const float ho2[4]); + #endif diff --git a/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp b/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp index ddc84408e26..3926e8b8e51 100644 --- a/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp +++ b/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp @@ -185,7 +185,7 @@ RTBuilder *rtbuild_get_child(RTBuilder *b, int child, RTBuilder *tmp) return tmp; } -void rtbuild_calc_bb(RTBuilder *b) +static void rtbuild_calc_bb(RTBuilder *b) { if (b->bb[0] == 1.0e30f) { for (RTBuilder::Object **index = b->sorted_begin[0]; index != b->sorted_end[0]; index++) diff --git a/source/blender/render/intern/raytrace/rayobject_vbvh.cpp b/source/blender/render/intern/raytrace/rayobject_vbvh.cpp index 9e7075438cb..85c9d0d402f 100644 --- a/source/blender/render/intern/raytrace/rayobject_vbvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_vbvh.cpp @@ -152,7 +152,8 @@ void bvh_hint_bb(Tree *tree, LCTSHint *hint, float *UNUSED(min), float *UNUSED(m } } -void bfree(VBVHTree *tree) +#if 0 /* UNUSED */ +static void bfree(VBVHTree *tree) { if (tot_pushup + tot_pushdown + tot_hints + tot_moves) { if (G.debug & G_DEBUG) { @@ -169,6 +170,7 @@ void bfree(VBVHTree *tree) } bvh_free(tree); } +#endif /* the cast to pointer function is needed to workarround gcc bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11407 */ template<class Tree, int STACK_SIZE> diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index e0864533fed..9bc639515c2 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -41,6 +41,7 @@ #include "BLI_rand.h" #include "BLI_memarena.h" #include "BLI_ghash.h" +#include "BLI_linklist.h" #include "BLI_edgehash.h" #include "DNA_armature_types.h" @@ -118,6 +119,7 @@ #include "zbuf.h" #include "sunsky.h" +#include "RE_render_ext.h" /* 10 times larger than normal epsilon, test it on default nurbs sphere with ray_transp (for quad detection) */ /* or for checking vertex normal flips */ @@ -2260,14 +2262,6 @@ static void displace_render_vert(Render *re, ObjectRen *obr, ShadeInput *shi, Ve if ((texco & TEXCO_ORCO) && (vr->orco)) { copy_v3_v3(shi->lo, vr->orco); } - if (texco & TEXCO_STICKY) { - float *sticky= RE_vertren_get_sticky(obr, vr, 0); - if (sticky) { - shi->sticky[0]= sticky[0]; - shi->sticky[1]= sticky[1]; - shi->sticky[2]= 0.0f; - } - } if (texco & TEXCO_GLOB) { copy_v3_v3(shi->gl, shi->co); mul_m4_v3(re->viewinv, shi->gl); @@ -3267,7 +3261,6 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) VlakRen *vlr; //, *vlr1; VertRen *ver; Material *ma; - MSticky *ms = NULL; DerivedMesh *dm; CustomDataMask mask; float xn, yn, zn, imat[3][3], mat[4][4]; //nor[3], @@ -3352,8 +3345,6 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) if (do_autosmooth && me->totvert==totvert && me->totface==dm->getNumTessFaces(dm)) use_original_normals= TRUE; - ms = (totvert==me->totvert)?me->msticky:NULL; - ma= give_render_material(re, ob, 1); @@ -3372,16 +3363,11 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) normalize_v3(ver->n); negate_v3(ver->n); } - + if (orco) { ver->orco= orco; orco+=3; } - if (ms) { - float *sticky= RE_vertren_get_sticky(obr, ver, 1); - copy_v2_v2(sticky, ms->co); - ms++; - } } if (!timeoffset) { @@ -5301,11 +5287,11 @@ static void speedvector_project(Render *re, float zco[2], const float co[3], con /* size of 1 pixel mapped to viewplane coords */ float psize; - psize = BLI_RCT_SIZE_X(&re->viewplane) / (float)re->winx; + psize = BLI_rctf_size_x(&re->viewplane) / (float)re->winx; /* x angle of a pixel */ pixelphix = atan(psize / re->clipsta); - psize = BLI_RCT_SIZE_Y(&re->viewplane) / (float)re->winy; + psize = BLI_rctf_size_y(&re->viewplane) / (float)re->winy; /* y angle of a pixel */ pixelphiy = atan(psize / re->clipsta); } @@ -5873,76 +5859,3 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay, if (re->r.mode & R_SHADOW) make_occ_tree(re); } - -/* ------------------------------------------------------------------------- */ -/* Sticky texture coords */ -/* ------------------------------------------------------------------------- */ - -void RE_make_sticky(Scene *scene, View3D *v3d) -{ - Object *ob; - Base *base; - MVert *mvert; - Mesh *me; - MSticky *ms; - Render *re; - float ho[4], mat[4][4]; - int a; - Object *camera= NULL; - - if (v3d==NULL) { - printf("Need a 3d view to make sticky\n"); - return; - } - - if (v3d) camera= V3D_CAMERA_LOCAL(v3d); - if (camera == NULL) camera= scene->camera; - - if (camera==NULL) { - printf("Need camera to make sticky\n"); - return; - } - if (scene->obedit) { - printf("Unable to make sticky in Edit Mode\n"); - return; - } - - re= RE_NewRender("_make sticky_"); - RE_InitState(re, NULL, &scene->r, NULL, scene->r.xsch, scene->r.ysch, NULL); - - /* use renderdata and camera to set viewplane */ - RE_SetCamera(re, camera); - - /* and set view matrix */ - normalize_m4(camera->obmat); - invert_m4_m4(mat, camera->obmat); - RE_SetView(re, mat); - - for (base= FIRSTBASE; base; base= base->next) { - if (TESTBASELIB(v3d, base)) { - if (base->object->type==OB_MESH) { - ob= base->object; - - me= ob->data; - mvert= me->mvert; - if (me->msticky) - CustomData_free_layer_active(&me->vdata, CD_MSTICKY, me->totvert); - me->msticky= CustomData_add_layer(&me->vdata, CD_MSTICKY, - CD_CALLOC, NULL, me->totvert); - - BKE_object_where_is_calc(scene, ob); - mult_m4_m4m4(mat, re->viewmat, ob->obmat); - - ms= me->msticky; - for (a=0; a<me->totvert; a++, ms++, mvert++) { - copy_v3_v3(ho, mvert->co); - mul_m4_v3(mat, ho); - projectverto(ho, re->winmat, ho); - ms->co[0]= ho[0]/ho[3]; - ms->co[1]= ho[1]/ho[3]; - } - } - } - } -} - diff --git a/source/blender/render/intern/source/envmap.c b/source/blender/render/intern/source/envmap.c index 26bd482af69..03eb21dfa23 100644 --- a/source/blender/render/intern/source/envmap.c +++ b/source/blender/render/intern/source/envmap.c @@ -472,9 +472,6 @@ static void render_envmap(Render *re, EnvMap *env) ibuf = IMB_allocImBuf(envre->rectx, envre->recty, 24, IB_rect | IB_rectfloat); memcpy(ibuf->rect_float, rl->rectf, ibuf->channels * ibuf->x * ibuf->y * sizeof(float)); - if (re->scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) - ibuf->profile = IB_PROFILE_LINEAR_RGB; - /* envmap renders without alpha */ alpha = ibuf->rect_float + 3; for (y = ibuf->x * ibuf->y - 1; y >= 0; y--, alpha += 4) diff --git a/source/blender/render/intern/source/gammaCorrectionTables.c b/source/blender/render/intern/source/gammaCorrectionTables.c index 64925e16ae2..1c2613e8d18 100644 --- a/source/blender/render/intern/source/gammaCorrectionTables.c +++ b/source/blender/render/intern/source/gammaCorrectionTables.c @@ -38,7 +38,7 @@ /* result remain identical (ton) */ /* gamma is only used here for correcting adding colors or alpha */ -#define RE_DEFAULT_GAMMA 2.0 +// #define RE_DEFAULT_GAMMA 2.0 // UNUSED /* This 400 is sort of based on the number of intensity levels needed for */ /* the typical dynamic range of a medium, in this case CRTs. (Foley) */ diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c index 7f0484c8ee6..7a9df51e493 100644 --- a/source/blender/render/intern/source/imagetexture.c +++ b/source/blender/render/intern/source/imagetexture.c @@ -396,8 +396,8 @@ static float square_rctf(rctf *rf) { float x, y; - x = BLI_RCT_SIZE_X(rf); - y = BLI_RCT_SIZE_Y(rf); + x = BLI_rctf_size_x(rf); + y = BLI_rctf_size_y(rf); return x * y; } @@ -405,7 +405,7 @@ static float clipx_rctf(rctf *rf, float x1, float x2) { float size; - size = BLI_RCT_SIZE_X(rf); + size = BLI_rctf_size_x(rf); if (rf->xmin<x1) { rf->xmin = x1; @@ -417,8 +417,8 @@ static float clipx_rctf(rctf *rf, float x1, float x2) rf->xmin = rf->xmax; return 0.0; } - else if (size!=0.0f) { - return BLI_RCT_SIZE_X(rf) / size; + else if (size != 0.0f) { + return BLI_rctf_size_x(rf) / size; } return 1.0; } @@ -427,7 +427,7 @@ static float clipy_rctf(rctf *rf, float y1, float y2) { float size; - size = BLI_RCT_SIZE_Y(rf); + size = BLI_rctf_size_y(rf); if (rf->ymin<y1) { rf->ymin = y1; @@ -441,7 +441,7 @@ static float clipy_rctf(rctf *rf, float y1, float y2) return 0.0; } else if (size != 0.0f) { - return BLI_RCT_SIZE_Y(rf) / size; + return BLI_rctf_size_y(rf) / size; } return 1.0; diff --git a/source/blender/render/intern/source/initrender.c b/source/blender/render/intern/source/initrender.c index 66f230a40f5..88c64b44b64 100644 --- a/source/blender/render/intern/source/initrender.c +++ b/source/blender/render/intern/source/initrender.c @@ -610,8 +610,8 @@ void initparts(Render *re, int do_crop) } else disprect.ymax = ymaxb; - rectx = BLI_RCT_SIZE_X(&disprect); - recty = BLI_RCT_SIZE_Y(&disprect); + rectx = BLI_rcti_size_x(&disprect); + recty = BLI_rcti_size_y(&disprect); /* so, now can we add this part? */ if (rectx > 0 && recty > 0) { diff --git a/source/blender/render/intern/source/occlusion.c b/source/blender/render/intern/source/occlusion.c index 485dd005be7..c8aad21b322 100644 --- a/source/blender/render/intern/source/occlusion.c +++ b/source/blender/render/intern/source/occlusion.c @@ -61,7 +61,6 @@ /* ------------------------- Declarations --------------------------- */ -#define INVALID_INDEX ((int)(~0)) #define INVPI ((float)M_1_PI) #define TOTCHILD 8 #define CACHE_STEP 3 diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 720287510d0..ecd8524016d 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -68,6 +68,7 @@ #include "BLI_callbacks.h" #include "PIL_time.h" +#include "IMB_colormanagement.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" @@ -205,9 +206,9 @@ RenderLayer *RE_GetRenderLayer(RenderResult *rr, const char *name) } } -RenderResult *RE_MultilayerConvert(void *exrhandle, int rectx, int recty) +RenderResult *RE_MultilayerConvert(void *exrhandle, const char *colorspace, int predivide, int rectx, int recty) { - return render_result_new_from_exr(exrhandle, rectx, recty); + return render_result_new_from_exr(exrhandle, colorspace, predivide, rectx, recty); } RenderLayer *render_get_active_layer(Render *re, RenderResult *rr) @@ -336,7 +337,7 @@ void RE_ResultGet32(Render *re, unsigned int *rect) RenderResult rres; RE_AcquireResultImage(re, &rres); - render_result_rect_get_pixels(&rres, &re->r, rect, re->rectx, re->recty); + render_result_rect_get_pixels(&rres, &re->r, rect, re->rectx, re->recty, &re->scene->view_settings, &re->scene->display_settings); RE_ReleaseResultImage(re); } @@ -439,8 +440,8 @@ void RE_InitState(Render *re, Render *source, RenderData *rd, SceneRenderLayer * re->winy = winy; if (disprect) { re->disprect = *disprect; - re->rectx = BLI_RCT_SIZE_X(disprect); - re->recty = BLI_RCT_SIZE_Y(disprect); + re->rectx = BLI_rcti_size_x(disprect); + re->recty = BLI_rcti_size_y(disprect); } else { re->disprect.xmin = re->disprect.ymin = 0; @@ -672,15 +673,15 @@ static void *do_part_thread(void *pa_v) float panorama_pixel_rot(Render *re) { float psize, phi, xfac; - float borderfac = (float)BLI_RCT_SIZE_X(&re->disprect) / (float)re->winx; + float borderfac = (float)BLI_rcti_size_x(&re->disprect) / (float)re->winx; /* size of 1 pixel mapped to viewplane coords */ - psize = BLI_RCT_SIZE_X(&re->viewplane) / (float)re->winx; + psize = BLI_rctf_size_x(&re->viewplane) / (float)re->winx; /* angle of a pixel */ phi = atan(psize / re->clipsta); /* correction factor for viewplane shifting, first calculate how much the viewplane angle is */ - xfac = borderfac * BLI_RCT_SIZE_X(&re->viewplane) / (float)re->xparts; + xfac = borderfac * BLI_rctf_size_x(&re->viewplane) / (float)re->xparts; xfac = atan(0.5f * xfac / re->clipsta); /* and how much the same viewplane angle is wrapped */ psize = 0.5f * phi * ((float)re->partx); @@ -713,7 +714,7 @@ static RenderPart *find_next_pano_slice(Render *re, int *minx, rctf *viewplane) float phi = panorama_pixel_rot(re); R.panodxp = (re->winx - (best->disprect.xmin + best->disprect.xmax) ) / 2; - R.panodxv = (BLI_RCT_SIZE_X(viewplane) * R.panodxp) / (float)(re->winx); + R.panodxv = (BLI_rctf_size_x(viewplane) * R.panodxp) / (float)(re->winx); /* shift viewplane */ R.viewplane.xmin = viewplane->xmin + R.panodxv; @@ -740,8 +741,8 @@ static RenderPart *find_next_part(Render *re, int minx) /* find center of rendered parts, image center counts for 1 too */ for (pa = re->parts.first; pa; pa = pa->next) { if (pa->ready) { - centx += BLI_RCT_CENTER_X(&pa->disprect); - centy += BLI_RCT_CENTER_Y(&pa->disprect); + centx += BLI_rcti_cent_x(&pa->disprect); + centy += BLI_rcti_cent_y(&pa->disprect); tot++; } } @@ -751,8 +752,8 @@ static RenderPart *find_next_part(Render *re, int minx) /* closest of the non-rendering parts */ for (pa = re->parts.first; pa; pa = pa->next) { if (pa->ready == 0 && pa->nr == 0) { - long long int distx = centx - BLI_RCT_CENTER_X(&pa->disprect); - long long int disty = centy - BLI_RCT_CENTER_Y(&pa->disprect); + long long int distx = centx - BLI_rcti_cent_x(&pa->disprect); + long long int disty = centy - BLI_rcti_cent_y(&pa->disprect); distx = (long long int)sqrt(distx * distx + disty * disty); if (distx < mindist) { if (re->r.mode & R_PANORAMA) { @@ -1463,7 +1464,7 @@ static void free_all_freestyle_renders(Scene *scene) static void do_merge_fullsample(Render *re, bNodeTree *ntree) { float *rectf, filt[3][3]; - int sample; + int x, y, sample; /* interaction callbacks */ if (ntree) { @@ -1484,7 +1485,7 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) for (sample = 0; sample < re->r.osa; sample++) { Render *re1; RenderResult rres; - int x, y, mask; + int mask; /* enable full sample print */ R.i.curfsa = sample + 1; @@ -1513,7 +1514,7 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) ntreeCompositTagRender(re->scene); ntreeCompositTagAnimated(ntree); - ntreeCompositExecTree(ntree, &re->r, 1, G.background == 0); + ntreeCompositExecTree(ntree, &re->r, 1, G.background == 0, &re->scene->view_settings, &re->scene->display_settings); } /* ensure we get either composited result or the active layer */ @@ -1549,6 +1550,18 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) if (re->test_break(re->tbh)) break; } + + /* clamp alpha and RGB to 0..1 and 0..inf, can go outside due to filter */ + for (y = 0; y < re->recty; y++) { + float *rf = rectf + 4 * y * re->rectx; + + for (x = 0; x < re->rectx; x++, rf += 4) { + rf[0] = MAX2(rf[0], 0.0f); + rf[1] = MAX2(rf[1], 0.0f); + rf[2] = MAX2(rf[2], 0.0f); + CLAMP(rf[3], 0.0f, 1.0f); + } + } /* clear interaction callbacks */ if (ntree) { @@ -1677,7 +1690,7 @@ static void do_render_composite_fields_blur_3d(Render *re) if (re->r.scemode & R_FULL_SAMPLE) do_merge_fullsample(re, ntree); else { - ntreeCompositExecTree(ntree, &re->r, 1, G.background == 0); + ntreeCompositExecTree(ntree, &re->r, 1, G.background == 0, &re->scene->view_settings, &re->scene->display_settings); } ntree->stats_draw = NULL; @@ -1728,7 +1741,7 @@ int RE_seq_render_active(Scene *scene, RenderData *rd) static void do_render_seq(Render *re) { static int recurs_depth = 0; - struct ImBuf *ibuf; + struct ImBuf *ibuf, *out; RenderResult *rr; /* don't assign re->result here as it might change during give_ibuf_seq */ int cfra = re->r.cfra; SeqRenderData context; @@ -1755,7 +1768,16 @@ static void do_render_seq(Render *re) 100); } - ibuf = BKE_sequencer_give_ibuf(context, cfra, 0); + out = BKE_sequencer_give_ibuf(context, cfra, 0); + + if (out) { + ibuf = IMB_dupImBuf(out); + IMB_freeImBuf(out); + BKE_sequencer_imbuf_from_sequencer_space(re->scene, ibuf); + } + else { + ibuf = NULL; + } recurs_depth--; @@ -1789,6 +1811,9 @@ static void do_render_seq(Render *re) re->progress(re->prh, (float)(cfra - re->r.sfra) / (re->r.efra - re->r.sfra)); else re->progress(re->prh, 1.0f); + + /* would mark display buffers as invalid */ + re->display_draw(re->ddh, re->result, NULL); } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -2150,6 +2175,14 @@ void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, SceneRenderLayer *sr G.is_rendering = FALSE; } +static void colormanage_image_for_write(Scene *scene, ImBuf *ibuf) +{ + IMB_display_buffer_to_imbuf_rect(ibuf, &scene->view_settings, &scene->display_settings); + + if (ibuf) + imb_freerectfloatImBuf(ibuf); +} + void RE_RenderFreestyleStrokes(Render *re, Main *bmain, Scene *scene) { re->result_ok= 0; @@ -2171,19 +2204,27 @@ static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovie /* write movie or image */ if (BKE_imtype_is_movie(scene->r.im_format.imtype)) { int do_free = FALSE; - unsigned int *rect32 = (unsigned int *)rres.rect32; + ImBuf *ibuf = render_result_rect_to_ibuf(&rres, &scene->r); + /* note; the way it gets 32 bits rects is weak... */ - if (rres.rect32 == NULL) { - rect32 = MEM_mapallocN(sizeof(int) * rres.rectx * rres.recty, "temp 32 bits rect"); - RE_ResultGet32(re, rect32); + if (ibuf->rect == NULL) { + ibuf->rect = MEM_mapallocN(sizeof(int) * rres.rectx * rres.recty, "temp 32 bits rect"); + RE_ResultGet32(re, ibuf->rect); do_free = TRUE; } - ok = mh->append_movie(&re->r, scene->r.sfra, scene->r.cfra, (int *)rect32, - rres.rectx, rres.recty, re->reports); + colormanage_image_for_write(scene, ibuf); + + ok = mh->append_movie(&re->r, scene->r.sfra, scene->r.cfra, (int *) ibuf->rect, + ibuf->x, ibuf->y, re->reports); if (do_free) { - MEM_freeN(rect32); + MEM_freeN(ibuf->rect); + ibuf->rect = NULL; } + + /* imbuf knows which rects are not part of ibuf */ + IMB_freeImBuf(ibuf); + printf("Append frame %d", scene->r.cfra); } else { @@ -2200,6 +2241,12 @@ static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovie } else { ImBuf *ibuf = render_result_rect_to_ibuf(&rres, &scene->r); + int do_colormanagement; + + do_colormanagement = !BKE_imtype_supports_float(scene->r.im_format.imtype); + + if (do_colormanagement) + colormanage_image_for_write(scene, ibuf); ok = BKE_imbuf_write_stamp(scene, camera, ibuf, name, &scene->r.im_format); @@ -2217,6 +2264,9 @@ static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovie name[strlen(name) - 4] = 0; BKE_add_image_extension(name, R_IMF_IMTYPE_JPEG90); ibuf->planes = 24; + + colormanage_image_for_write(scene, ibuf); + BKE_imbuf_write_stamp(scene, camera, ibuf, name, &imf); printf("\nSaved: %s", name); } @@ -2471,7 +2521,8 @@ void RE_init_threadcount(Render *re) * x/y offsets are only used on a partial copy when dimensions don't match */ void RE_layer_load_from_file(RenderLayer *layer, ReportList *reports, const char *filename, int x, int y) { - ImBuf *ibuf = IMB_loadiffname(filename, IB_rect); + /* OCIO_TODO: assume layer was saved in defaule color space */ + ImBuf *ibuf = IMB_loadiffname(filename, IB_rect, NULL); if (ibuf && (ibuf->rect || ibuf->rect_float)) { if (ibuf->x == layer->rectx && ibuf->y == layer->recty) { @@ -2560,8 +2611,7 @@ int RE_WriteEnvmapResult(struct ReportList *reports, Scene *scene, EnvMap *env, return 0; } - if (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) - ibuf->profile = IB_PROFILE_LINEAR_RGB; + IMB_display_buffer_to_imbuf_rect(ibuf, &scene->view_settings, &scene->display_settings); /* to save, we first get absolute path */ BLI_strncpy(filepath, relpath, sizeof(filepath)); diff --git a/source/blender/render/intern/source/render_result.c b/source/blender/render/intern/source/render_result.c index fb1a7885390..a226556828e 100644 --- a/source/blender/render/intern/source/render_result.c +++ b/source/blender/render/intern/source/render_result.c @@ -50,6 +50,7 @@ #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" +#include "IMB_colormanagement.h" #include "intern/openexr/openexr_multi.h" @@ -423,8 +424,8 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf SceneRenderLayer *srl; int rectx, recty, nr; - rectx = BLI_RCT_SIZE_X(partrct); - recty = BLI_RCT_SIZE_Y(partrct); + rectx = BLI_rcti_size_x(partrct); + recty = BLI_rcti_size_y(partrct); if (rectx <= 0 || recty <= 0) return NULL; @@ -571,8 +572,8 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf } /* border render; calculate offset for use in compositor. compo is centralized coords */ - rr->xof = re->disprect.xmin + BLI_RCT_CENTER_X(&re->disprect) - (re->winx / 2); - rr->yof = re->disprect.ymin + BLI_RCT_CENTER_Y(&re->disprect) - (re->winy / 2); + rr->xof = re->disprect.xmin + BLI_rcti_cent_x(&re->disprect) - (re->winx / 2); + rr->yof = re->disprect.ymin + BLI_rcti_cent_y(&re->disprect) - (re->winy / 2); return rr; } @@ -629,12 +630,13 @@ static void ml_addpass_cb(void *UNUSED(base), void *lay, const char *str, float } /* from imbuf, if a handle was returned we convert this to render result */ -RenderResult *render_result_new_from_exr(void *exrhandle, int rectx, int recty) +RenderResult *render_result_new_from_exr(void *exrhandle, const char *colorspace, int predivide, int rectx, int recty) { RenderResult *rr = MEM_callocN(sizeof(RenderResult), __func__); RenderLayer *rl; RenderPass *rpass; - + const char *to_colorspace = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_SCENE_LINEAR); + rr->rectx = rectx; rr->recty = recty; @@ -647,6 +649,11 @@ RenderResult *render_result_new_from_exr(void *exrhandle, int rectx, int recty) for (rpass = rl->passes.first; rpass; rpass = rpass->next) { rpass->rectx = rectx; rpass->recty = recty; + + if (rpass->channels >= 3) { + IMB_colormanagement_transform(rpass->rect, rpass->rectx, rpass->recty, rpass->channels, + colorspace, to_colorspace, predivide); + } } } @@ -1084,16 +1091,12 @@ ImBuf *render_result_rect_to_ibuf(RenderResult *rr, RenderData *rd) /* float factor for random dither, imbuf takes care of it */ ibuf->dither = rd->dither_intensity; - /* prepare to gamma correct to sRGB color space */ - if (rd->color_mgt_flag & R_COLOR_MANAGEMENT) { - /* sequence editor can generate 8bpc render buffers */ - if (ibuf->rect) { - ibuf->profile = IB_PROFILE_SRGB; - if (BKE_imtype_valid_depths(rd->im_format.imtype) & (R_IMF_CHAN_DEPTH_12 | R_IMF_CHAN_DEPTH_16 | R_IMF_CHAN_DEPTH_24 | R_IMF_CHAN_DEPTH_32)) - IMB_float_from_rect(ibuf); - } - else { - ibuf->profile = IB_PROFILE_LINEAR_RGB; + /* prepare to gamma correct to sRGB color space + * note that sequence editor can generate 8bpc render buffers + */ + if (ibuf->rect) { + if (BKE_imtype_valid_depths(rd->im_format.imtype) & (R_IMF_CHAN_DEPTH_12 | R_IMF_CHAN_DEPTH_16 | R_IMF_CHAN_DEPTH_24 | R_IMF_CHAN_DEPTH_32)) { + IMB_float_from_rect(ibuf); } } @@ -1109,22 +1112,14 @@ ImBuf *render_result_rect_to_ibuf(RenderResult *rr, RenderData *rd) return ibuf; } -void render_result_rect_from_ibuf(RenderResult *rr, RenderData *rd, ImBuf *ibuf) +void render_result_rect_from_ibuf(RenderResult *rr, RenderData *UNUSED(rd), ImBuf *ibuf) { if (ibuf->rect_float) { - /* color management: when off ensure rectf is non-lin, since thats what the internal - * render engine delivers */ - int profile_to = (rd->color_mgt_flag & R_COLOR_MANAGEMENT) ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_SRGB; - int profile_from = (ibuf->profile == IB_PROFILE_LINEAR_RGB) ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_SRGB; - int predivide = (rd->color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE); - if (!rr->rectf) rr->rectf = MEM_mallocN(4 * sizeof(float) * rr->rectx * rr->recty, "render_seq rectf"); - IMB_buffer_float_from_float(rr->rectf, ibuf->rect_float, - 4, profile_to, profile_from, predivide, - rr->rectx, rr->recty, rr->rectx, rr->rectx); - + memcpy(rr->rectf, ibuf->rect_float, 4 * sizeof(float) * rr->rectx * rr->recty); + /* TSK! Since sequence render doesn't free the *rr render result, the old rect32 * can hang around when sequence render has rendered a 32 bits one before */ if (rr->rect32) { @@ -1156,19 +1151,17 @@ void render_result_rect_fill_zero(RenderResult *rr) rr->rect32 = MEM_callocN(sizeof(int) * rr->rectx * rr->recty, "render_seq rect"); } -void render_result_rect_get_pixels(RenderResult *rr, RenderData *rd, unsigned int *rect, int rectx, int recty) +void render_result_rect_get_pixels(RenderResult *rr, RenderData *rd, unsigned int *rect, int rectx, int recty, + const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings) { if (rr->rect32) { memcpy(rect, rr->rect32, sizeof(int) * rr->rectx * rr->recty); } else if (rr->rectf) { - int profile_from = (rd->color_mgt_flag & R_COLOR_MANAGEMENT) ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_SRGB; int predivide = (rd->color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE); - int dither = 0; - IMB_buffer_byte_from_float((unsigned char *)rect, rr->rectf, - 4, dither, IB_PROFILE_SRGB, profile_from, predivide, - rr->rectx, rr->recty, rr->rectx, rr->rectx); + IMB_display_buffer_transform_apply((unsigned char *) rect, rr->rectf, rr->rectx, rr->recty, 4, + view_settings, display_settings, predivide); } else /* else fill with black */ diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index cbe8cc81451..982f7e7d824 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -50,6 +50,7 @@ #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" +#include "IMB_colormanagement.h" #include "BKE_colortools.h" #include "BKE_image.h" @@ -82,6 +83,8 @@ #include "renderdatabase.h" /* needed for UV */ +#include "RE_render_ext.h" + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* defined in pipeline.c, is hardcopy of active dynamic allocated Render */ /* only to be used here in this file, it's for speed */ @@ -95,7 +98,7 @@ static void init_render_texture(Render *re, Tex *tex) { /* imap test */ if (tex->ima && ELEM(tex->ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) { - BKE_image_user_frame_calc(&tex->iuser, re->r.cfra, re?re->flag & R_SEC_FIELD:0); + BKE_image_user_frame_calc(&tex->iuser, re ? re->r.cfra : 0, re ? re->flag & R_SEC_FIELD:0); } else if (tex->type==TEX_ENVMAP) { @@ -1224,8 +1227,8 @@ int multitex_nodes(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, ImBuf *ibuf = BKE_image_get_ibuf(tex->ima, &tex->iuser); /* don't linearize float buffers, assumed to be linear */ - if (ibuf && !(ibuf->rect_float) && R.r.color_mgt_flag & R_COLOR_MANAGEMENT) - srgb_to_linearrgb_v3_v3(&texres->tr, &texres->tr); + if (ibuf && !(ibuf->rect_float)) + IMB_colormanagement_colorspace_to_scene_linear_v3(&texres->tr, ibuf->rect_colorspace); } } else { @@ -1259,18 +1262,19 @@ int multitex_nodes(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, } /* this is called for surface shading */ -int multitex_mtex(ShadeInput *shi, MTex *mtex, float *texvec, float *dxt, float *dyt, TexResult *texres) +static int multitex_mtex(ShadeInput *shi, MTex *mtex, float *texvec, float *dxt, float *dyt, TexResult *texres) { - Tex *tex= mtex->tex; + Tex *tex = mtex->tex; if (tex->use_nodes && tex->nodetree) { /* stupid exception here .. but we have to pass shi and mtex to * textures nodes for 2d mapping and color management for images */ return ntreeTexExecTree(tex->nodetree, texres, texvec, dxt, dyt, shi->osatex, shi->thread, - tex, mtex->which_output, R.r.cfra, (R.r.scemode & R_TEXNODE_PREVIEW) != 0, shi, mtex); + tex, mtex->which_output, R.r.cfra, (R.r.scemode & R_TEXNODE_PREVIEW) != 0, shi, mtex); } - else + else { return multitex(mtex->tex, texvec, dxt, dyt, shi->osatex, texres, shi->thread, mtex->which_output); + } } /* Warning, if the texres's values are not declared zero, check the return value to be sure @@ -2149,9 +2153,6 @@ void do_material_tex(ShadeInput *shi, Render *re) co= shi->lo; dx= shi->dxlo; dy= shi->dylo; } } - else if (mtex->texco==TEXCO_STICKY) { - co= shi->sticky; dx= shi->dxsticky; dy= shi->dysticky; - } else if (mtex->texco==TEXCO_OBJECT) { Object *ob= mtex->object; if (ob) { @@ -2376,8 +2377,8 @@ void do_material_tex(ShadeInput *shi, Render *re) ImBuf *ibuf = BKE_image_get_ibuf(ima, &tex->iuser); /* don't linearize float buffers, assumed to be linear */ - if (ibuf && !(ibuf->rect_float) && re->r.color_mgt_flag & R_COLOR_MANAGEMENT) - srgb_to_linearrgb_v3_v3(tcol, tcol); + if (ibuf && !(ibuf->rect_float)) + IMB_colormanagement_colorspace_to_scene_linear_v3(tcol, ibuf->rect_colorspace); } if (mtex->mapto & MAP_COL) { @@ -2756,11 +2757,9 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float col_ /* stencil maps on the texture control slider, not texture intensity value */ /* convert RGB to intensity if intensity info isn't provided */ - if (!(rgbnor & TEX_INT)) { - if (rgbnor & TEX_RGB) { - if (texres.talpha) texres.tin = texres.ta; - else texres.tin = rgb_to_grayscale(&texres.tr); - } + if (rgbnor & TEX_RGB) { + if (texres.talpha) texres.tin = texres.ta; + else texres.tin = rgb_to_grayscale(&texres.tr); } if ((mapto_flag & MAP_EMISSION) && (mtex->mapto & MAP_EMISSION)) { @@ -2888,8 +2887,8 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4]) ImBuf *ibuf = BKE_image_get_ibuf(ima, &mtex->tex->iuser); /* don't linearize float buffers, assumed to be linear */ - if (ibuf && !(ibuf->rect_float) && R.r.color_mgt_flag & R_COLOR_MANAGEMENT) - srgb_to_linearrgb_v3_v3(&texres.tr, &texres.tr); + if (ibuf && !(ibuf->rect_float)) + IMB_colormanagement_colorspace_to_scene_linear_v3(&texres.tr, ibuf->rect_colorspace); } fact= texres.tin*mtex->colfac; @@ -3103,8 +3102,8 @@ void do_sky_tex(const float rco[3], float lo[3], const float dxyview[2], float h ImBuf *ibuf = BKE_image_get_ibuf(ima, &tex->iuser); /* don't linearize float buffers, assumed to be linear */ - if (ibuf && !(ibuf->rect_float) && R.r.color_mgt_flag & R_COLOR_MANAGEMENT) - srgb_to_linearrgb_v3_v3(tcol, tcol); + if (ibuf && !(ibuf->rect_float)) + IMB_colormanagement_colorspace_to_scene_linear_v3(tcol, ibuf->rect_colorspace); } if (mtex->mapto & WOMAP_HORIZ) { @@ -3317,8 +3316,8 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r ImBuf *ibuf = BKE_image_get_ibuf(ima, &tex->iuser); /* don't linearize float buffers, assumed to be linear */ - if (ibuf && !(ibuf->rect_float) && R.r.color_mgt_flag & R_COLOR_MANAGEMENT) - srgb_to_linearrgb_v3_v3(&texres.tr, &texres.tr); + if (ibuf && !(ibuf->rect_float)) + IMB_colormanagement_colorspace_to_scene_linear_v3(&texres.tr, ibuf->rect_colorspace); } /* lamp colors were premultiplied with this */ diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index c009c7b7394..0d894073cee 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -62,6 +62,7 @@ #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" +#include "IMB_colormanagement.h" /* local include */ #include "rayintersection.h" @@ -108,10 +109,10 @@ void calc_view_vector(float *view, float x, float y) /* move x and y to real viewplane coords */ x = (x / (float)R.winx); - view[0] = R.viewplane.xmin + x * BLI_RCT_SIZE_X(&R.viewplane); + view[0] = R.viewplane.xmin + x * BLI_rctf_size_x(&R.viewplane); y = (y / (float)R.winy); - view[1] = R.viewplane.ymin + y * BLI_RCT_SIZE_Y(&R.viewplane); + view[1] = R.viewplane.ymin + y * BLI_rctf_size_y(&R.viewplane); // if (R.flag & R_SEC_FIELD) { // if (R.r.mode & R_ODDFIELD) view[1]= (y+R.ystart)*R.ycor; @@ -989,6 +990,30 @@ static void convert_to_key_alpha(RenderPart *pa, RenderLayer *rl) } } +/* clamp alpha and RGB to 0..1 and 0..inf, can go outside due to filter */ +static void clamp_alpha_rgb_range(RenderPart *pa, RenderLayer *rl) +{ + RenderLayer *rlpp[RE_MAX_OSA]; + int y, sample, totsample; + + totsample= get_sample_layers(pa, rl, rlpp); + + /* not for full sample, there we clamp after compositing */ + if (totsample > 1) + return; + + for (sample= 0; sample<totsample; sample++) { + float *rectf= rlpp[sample]->rectf; + + for (y= pa->rectx*pa->recty; y>0; y--, rectf+=4) { + rectf[0] = MAX2(rectf[0], 0.0f); + rectf[1] = MAX2(rectf[1], 0.0f); + rectf[2] = MAX2(rectf[2], 0.0f); + CLAMP(rectf[3], 0.0f, 1.0f); + } + } +} + /* adds only alpha values */ static void edge_enhance_tile(RenderPart *pa, float *rectf, int *rectz) { @@ -1269,6 +1294,9 @@ void zbufshadeDA_tile(RenderPart *pa) if (rl->passflag & SCE_PASS_VECTOR) reset_sky_speed(pa, rl); + + /* clamp alpha to 0..1 range, can go outside due to filter */ + clamp_alpha_rgb_range(pa, rl); /* de-premul alpha */ if (R.r.alphamode & R_ALPHAKEY) @@ -1993,6 +2021,8 @@ typedef struct BakeShade { float dxco[3], dyco[3]; short *do_update; + + struct ColorSpace *rect_colorspace; } BakeShade; static void bake_set_shade_input(ObjectInstanceRen *obi, VlakRen *vlr, ShadeInput *shi, int quad, int UNUSED(isect), int x, int y, float u, float v) @@ -2168,8 +2198,12 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua else { unsigned char *col= (unsigned char *)(bs->rect + bs->rectx*y + x); - if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE) && (R.r.color_mgt_flag & R_COLOR_MANAGEMENT)) { - linearrgb_to_srgb_uchar3(col, shr.combined); + if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE)) { + float rgb[3]; + + copy_v3_v3(rgb, shr.combined); + IMB_colormanagement_scene_linear_to_colorspace_v3(rgb, bs->rect_colorspace); + rgb_float_to_uchar(col, rgb); } else { rgb_float_to_uchar(col, shr.combined); @@ -2503,6 +2537,7 @@ static void shade_tface(BakeShade *bs) bs->rectx= bs->ibuf->x; bs->recty= bs->ibuf->y; bs->rect= bs->ibuf->rect; + bs->rect_colorspace= bs->ibuf->rect_colorspace; bs->rect_float= bs->ibuf->rect_float; bs->quad= 0; @@ -2613,8 +2648,6 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up ima->flag&= ~IMA_USED_FOR_RENDER; if (ibuf) { ibuf->userdata = NULL; /* use for masking if needed */ - if (ibuf->rect_float) - ibuf->profile = IB_PROFILE_LINEAR_RGB; } } diff --git a/source/blender/render/intern/source/renderdatabase.c b/source/blender/render/intern/source/renderdatabase.c index db045284d5b..6395a04b534 100644 --- a/source/blender/render/intern/source/renderdatabase.c +++ b/source/blender/render/intern/source/renderdatabase.c @@ -97,13 +97,10 @@ * the index */ /* NOTE! the hardcoded table size 256 is used still in code for going quickly over vertices/faces */ - -#define RE_STICKY_ELEMS 2 #define RE_STRESS_ELEMS 1 #define RE_RAD_ELEMS 4 #define RE_STRAND_ELEMS 1 #define RE_TANGENT_ELEMS 3 -#define RE_STRESS_ELEMS 1 #define RE_WINSPEED_ELEMS 4 #define RE_MTFACE_ELEMS 1 #define RE_MCOL_ELEMS 4 @@ -114,21 +111,6 @@ #define RE_FACE_ELEMS 1 #define RE_NMAP_TANGENT_ELEMS 16 -float *RE_vertren_get_sticky(ObjectRen *obr, VertRen *ver, int verify) -{ - float *sticky; - int nr= ver->index>>8; - - sticky= obr->vertnodes[nr].sticky; - if (sticky==NULL) { - if (verify) - sticky= obr->vertnodes[nr].sticky= MEM_mallocN(256*RE_STICKY_ELEMS*sizeof(float), "sticky table"); - else - return NULL; - } - return sticky + (ver->index & 255)*RE_STICKY_ELEMS; -} - float *RE_vertren_get_stress(ObjectRen *obr, VertRen *ver, int verify) { float *stress; @@ -218,12 +200,7 @@ VertRen *RE_vertren_copy(ObjectRen *obr, VertRen *ver) *v1= *ver; v1->index= index; - - fp1= RE_vertren_get_sticky(obr, ver, 0); - if (fp1) { - fp2= RE_vertren_get_sticky(obr, v1, 1); - memcpy(fp2, fp1, RE_STICKY_ELEMS*sizeof(float)); - } + fp1= RE_vertren_get_stress(obr, ver, 0); if (fp1) { fp2= RE_vertren_get_stress(obr, v1, 1); @@ -740,8 +717,6 @@ void free_renderdata_vertnodes(VertTableNode *vertnodes) if (vertnodes[a].rad) MEM_freeN(vertnodes[a].rad); - if (vertnodes[a].sticky) - MEM_freeN(vertnodes[a].sticky); if (vertnodes[a].strand) MEM_freeN(vertnodes[a].strand); if (vertnodes[a].tangent) diff --git a/source/blender/render/intern/source/shadbuf.c b/source/blender/render/intern/source/shadbuf.c index 2d7a64bad04..bed3fb5f754 100644 --- a/source/blender/render/intern/source/shadbuf.c +++ b/source/blender/render/intern/source/shadbuf.c @@ -72,6 +72,9 @@ # define ACOMP 3 #endif +#define RCT_SIZE_X(rct) ((rct)->xmax - (rct)->xmin) +#define RCT_SIZE_Y(rct) ((rct)->ymax - (rct)->ymin) + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* defined in pipeline.c, is hardcopy of active dynamic allocated Render */ /* only to be used here in this file, it's for speed */ @@ -1506,7 +1509,7 @@ static void isb_bsp_split_init(ISBBranch *root, MemArena *mem, int level) root->divider[1]= 0.5f*(root->box.ymin+root->box.ymax); /* find best splitpoint */ - if (BLI_RCT_SIZE_X(&root->box) > BLI_RCT_SIZE_Y(&root->box)) + if (RCT_SIZE_X(&root->box) > RCT_SIZE_Y(&root->box)) i = root->index = 0; else i = root->index = 1; @@ -1551,7 +1554,7 @@ static void isb_bsp_split(ISBBranch *root, MemArena *mem) root->divider[1]/= BSPMAX_SAMPLE; /* find best splitpoint */ - if (BLI_RCT_SIZE_X(&root->box) > BLI_RCT_SIZE_Y(&root->box)) + if (RCT_SIZE_X(&root->box) > RCT_SIZE_Y(&root->box)) i = root->index = 0; else i = root->index = 1; diff --git a/source/blender/render/intern/source/shadeinput.c b/source/blender/render/intern/source/shadeinput.c index bbdcfbb5a73..35ab06cc564 100644 --- a/source/blender/render/intern/source/shadeinput.c +++ b/source/blender/render/intern/source/shadeinput.c @@ -574,10 +574,6 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert shi->dywin[1] = 0.0f; } } - - if (texco & TEXCO_STICKY) { - /* not supported */ - } } if (shi->do_manage) { @@ -1124,50 +1120,113 @@ void shade_input_set_shade_texco(ShadeInput *shi) for (i = 0; (tface = RE_vlakren_get_tface(obr, vlr, i, &name, 0)); i++) { ShadeInputUV *suv = &shi->uv[i]; - float *uv1, *uv2, *uv3; + const float *uv1 = tface->uv[j1]; + const float *uv2 = tface->uv[j2]; + const float *uv3 = tface->uv[j3]; shi->totuv++; suv->name = name; - - uv1 = tface->uv[j1]; - uv2 = tface->uv[j2]; - uv3 = tface->uv[j3]; - suv->uv[0] = -1.0f + 2.0f * (l * uv3[0] - u * uv1[0] - v * uv2[0]); - suv->uv[1] = -1.0f + 2.0f * (l * uv3[1] - u * uv1[1] - v * uv2[1]); - suv->uv[2] = 0.0f; /* texture.c assumes there are 3 coords */ + if ((shi->mat->mapflag & MA_MAPFLAG_UVPROJECT) && (shi->depth == 0)) { + float x = shi->xs; + float y = shi->ys; + + float s1[2] = {-1.0f + 2.0f * uv1[0], -1.0f + 2.0f * uv1[1]}; + float s2[2] = {-1.0f + 2.0f * uv2[0], -1.0f + 2.0f * uv2[1]}; + float s3[2] = {-1.0f + 2.0f * uv3[0], -1.0f + 2.0f * uv3[1]}; + + + float obwinmat[4][4], winmat[4][4], ho1[4], ho2[4], ho3[4]; + float Zmulx, Zmuly; + float hox, hoy, l, dl, u, v; + float s00, s01, s10, s11, detsh; + + /* old globals, localized now */ + Zmulx = ((float)R.winx) / 2.0f; + Zmuly = ((float)R.winy) / 2.0f; + + zbuf_make_winmat(&R, winmat); + if (shi->obi->flag & R_TRANSFORMED) + mult_m4_m4m4(obwinmat, winmat, obi->mat); + else + copy_m4_m4(obwinmat, winmat); + + zbuf_render_project(obwinmat, v1->co, ho1); + zbuf_render_project(obwinmat, v2->co, ho2); + zbuf_render_project(obwinmat, v3->co, ho3); + + s00 = ho3[0] / ho3[3] - ho1[0] / ho1[3]; + s01 = ho3[1] / ho3[3] - ho1[1] / ho1[3]; + s10 = ho3[0] / ho3[3] - ho2[0] / ho2[3]; + s11 = ho3[1] / ho3[3] - ho2[1] / ho2[3]; + + detsh = s00 * s11 - s10 * s01; + detsh = (detsh != 0.0f) ? 1.0f / detsh : 0.0f; + s00 *= detsh; s01 *= detsh; + s10 *= detsh; s11 *= detsh; + + /* recalc u and v again */ + hox = x / Zmulx - 1.0f; + hoy = y / Zmuly - 1.0f; + u = (hox - ho3[0] / ho3[3]) * s11 - (hoy - ho3[1] / ho3[3]) * s10; + v = (hoy - ho3[1] / ho3[3]) * s00 - (hox - ho3[0] / ho3[3]) * s01; + l = 1.0f + u + v; + + suv->uv[0] = l * s3[0] - u * s1[0] - v * s2[0]; + suv->uv[1] = l * s3[1] - u * s1[1] - v * s2[1]; + suv->uv[2] = 0.0f; - if (shi->osatex) { - float duv[2]; - - dl = shi->dx_u + shi->dx_v; - duv[0] = shi->dx_u; - duv[1] = shi->dx_v; + if (shi->osatex) { + float dxuv[2], dyuv[2]; + dxuv[0] = s11 / Zmulx; + dxuv[1] = -s01 / Zmulx; + dyuv[0] = -s10 / Zmuly; + dyuv[1] = s00 / Zmuly; + + dl = dxuv[0] + dxuv[1]; + suv->dxuv[0] = dl * s3[0] - dxuv[0] * s1[0] - dxuv[1] * s2[0]; + suv->dxuv[1] = dl * s3[1] - dxuv[0] * s1[1] - dxuv[1] * s2[1]; + dl = dyuv[0] + dyuv[1]; + suv->dyuv[0] = dl * s3[0] - dyuv[0] * s1[0] - dyuv[1] * s2[0]; + suv->dyuv[1] = dl * s3[1] - dyuv[0] * s1[1] - dyuv[1] * s2[1]; + } + } + else { - suv->dxuv[0] = 2.0f * (dl * uv3[0] - duv[0] * uv1[0] - duv[1] * uv2[0]); - suv->dxuv[1] = 2.0f * (dl * uv3[1] - duv[0] * uv1[1] - duv[1] * uv2[1]); + suv->uv[0] = -1.0f + 2.0f * (l * uv3[0] - u * uv1[0] - v * uv2[0]); + suv->uv[1] = -1.0f + 2.0f * (l * uv3[1] - u * uv1[1] - v * uv2[1]); + suv->uv[2] = 0.0f; /* texture.c assumes there are 3 coords */ - dl = shi->dy_u + shi->dy_v; - duv[0] = shi->dy_u; - duv[1] = shi->dy_v; + if (shi->osatex) { + float duv[2]; - suv->dyuv[0] = 2.0f * (dl * uv3[0] - duv[0] * uv1[0] - duv[1] * uv2[0]); - suv->dyuv[1] = 2.0f * (dl * uv3[1] - duv[0] * uv1[1] - duv[1] * uv2[1]); - } + dl = shi->dx_u + shi->dx_v; + duv[0] = shi->dx_u; + duv[1] = shi->dx_v; - if ((mode & MA_FACETEXTURE) && i == obr->actmtface) { - if ((mode & (MA_VERTEXCOL | MA_VERTEXCOLP)) == 0) { - shi->vcol[0] = 1.0f; - shi->vcol[1] = 1.0f; - shi->vcol[2] = 1.0f; - shi->vcol[3] = 1.0f; + suv->dxuv[0] = 2.0f * (dl * uv3[0] - duv[0] * uv1[0] - duv[1] * uv2[0]); + suv->dxuv[1] = 2.0f * (dl * uv3[1] - duv[0] * uv1[1] - duv[1] * uv2[1]); + + dl = shi->dy_u + shi->dy_v; + duv[0] = shi->dy_u; + duv[1] = shi->dy_v; + + suv->dyuv[0] = 2.0f * (dl * uv3[0] - duv[0] * uv1[0] - duv[1] * uv2[0]); + suv->dyuv[1] = 2.0f * (dl * uv3[1] - duv[0] * uv1[1] - duv[1] * uv2[1]); } - if (tface->tpage) { - render_realtime_texture(shi, tface->tpage); + + if ((mode & MA_FACETEXTURE) && i == obr->actmtface) { + if ((mode & (MA_VERTEXCOL | MA_VERTEXCOLP)) == 0) { + shi->vcol[0] = 1.0f; + shi->vcol[1] = 1.0f; + shi->vcol[2] = 1.0f; + shi->vcol[3] = 1.0f; + } + if (tface->tpage) { + render_realtime_texture(shi, tface->tpage); + } } } - - } shi->dupliuv[0] = -1.0f + 2.0f * obi->dupliuv[0]; @@ -1236,70 +1295,6 @@ void shade_input_set_shade_texco(ShadeInput *shi) shi->dywin[0] = shi->dywin[2] = 0.0f; } } - - if (texco & TEXCO_STICKY) { - float *s1, *s2, *s3; - - s1 = RE_vertren_get_sticky(obr, v1, 0); - s2 = RE_vertren_get_sticky(obr, v2, 0); - s3 = RE_vertren_get_sticky(obr, v3, 0); - - if (s1 && s2 && s3) { - float obwinmat[4][4], winmat[4][4], ho1[4], ho2[4], ho3[4]; - float Zmulx, Zmuly; - float hox, hoy, l, dl, u, v; - float s00, s01, s10, s11, detsh; - - /* old globals, localized now */ - Zmulx = ((float)R.winx) / 2.0f; Zmuly = ((float)R.winy) / 2.0f; - - zbuf_make_winmat(&R, winmat); - if (shi->obi->flag & R_TRANSFORMED) - mult_m4_m4m4(obwinmat, winmat, obi->mat); - else - copy_m4_m4(obwinmat, winmat); - - zbuf_render_project(obwinmat, v1->co, ho1); - zbuf_render_project(obwinmat, v2->co, ho2); - zbuf_render_project(obwinmat, v3->co, ho3); - - s00 = ho3[0] / ho3[3] - ho1[0] / ho1[3]; - s01 = ho3[1] / ho3[3] - ho1[1] / ho1[3]; - s10 = ho3[0] / ho3[3] - ho2[0] / ho2[3]; - s11 = ho3[1] / ho3[3] - ho2[1] / ho2[3]; - - detsh = s00 * s11 - s10 * s01; - detsh = (detsh != 0.0f) ? 1.0f / detsh : 0.0f; - s00 *= detsh; s01 *= detsh; - s10 *= detsh; s11 *= detsh; - - /* recalc u and v again */ - hox = x / Zmulx - 1.0f; - hoy = y / Zmuly - 1.0f; - u = (hox - ho3[0] / ho3[3]) * s11 - (hoy - ho3[1] / ho3[3]) * s10; - v = (hoy - ho3[1] / ho3[3]) * s00 - (hox - ho3[0] / ho3[3]) * s01; - l = 1.0f + u + v; - - shi->sticky[0] = l * s3[0] - u * s1[0] - v * s2[0]; - shi->sticky[1] = l * s3[1] - u * s1[1] - v * s2[1]; - shi->sticky[2] = 0.0f; - - if (shi->osatex) { - float dxuv[2], dyuv[2]; - dxuv[0] = s11 / Zmulx; - dxuv[1] = -s01 / Zmulx; - dyuv[0] = -s10 / Zmuly; - dyuv[1] = s00 / Zmuly; - - dl = dxuv[0] + dxuv[1]; - shi->dxsticky[0] = dl * s3[0] - dxuv[0] * s1[0] - dxuv[1] * s2[0]; - shi->dxsticky[1] = dl * s3[1] - dxuv[0] * s1[1] - dxuv[1] * s2[1]; - dl = dyuv[0] + dyuv[1]; - shi->dysticky[0] = dl * s3[0] - dyuv[0] * s1[0] - dyuv[1] * s2[0]; - shi->dysticky[1] = dl * s3[1] - dyuv[0] * s1[1] - dyuv[1] * s2[1]; - } - } - } } /* else { * Note! For raytracing winco is not set, @@ -1325,7 +1320,14 @@ void shade_input_initialize(ShadeInput *shi, RenderPart *pa, RenderLayer *rl, in shi->sample = sample; shi->thread = pa->thread; shi->do_preview = (R.r.scemode & R_MATNODE_PREVIEW) != 0; - shi->do_manage = (R.r.color_mgt_flag & R_COLOR_MANAGEMENT); + + /* OCIO_TODO: for now assume color management is always enabled and vertes colors are in sRGB space + * probably would be nice to have this things configurable, but for now it should work + * also probably this flag could be removed (in separated commit) before the release + * since it's not actually meaningful anymore + */ + shi->do_manage = TRUE; + shi->lay = rl->lay; shi->layflag = rl->layflag; shi->passflag = rl->passflag; diff --git a/source/blender/render/intern/source/strand.c b/source/blender/render/intern/source/strand.c index 51be519d5b8..dc3225b7f09 100644 --- a/source/blender/render/intern/source/strand.c +++ b/source/blender/render/intern/source/strand.c @@ -61,11 +61,6 @@ #include "strand.h" #include "zbuf.h" -/* to be removed */ -void hoco_to_zco(ZSpan *zspan, float *zco, float *hoco); -void zspan_scanconvert_strand(ZSpan *zspan, void *handle, float *v1, float *v2, float *v3, void (*func)(void *, int, int, float, float, float) ); -void zbufsinglewire(ZSpan *zspan, int obi, int zvlnr, float *ho1, float *ho2); - /* *************** */ static float strand_eval_width(Material *ma, float strandco) diff --git a/source/blender/render/intern/source/texture_ocean.c b/source/blender/render/intern/source/texture_ocean.c index 8c9df496dd6..b2bc635cba7 100644 --- a/source/blender/render/intern/source/texture_ocean.c +++ b/source/blender/render/intern/source/texture_ocean.c @@ -42,6 +42,8 @@ #include "texture.h" +#include "texture_ocean.h" /* own include */ + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* defined in pipeline.c, is hardcopy of active dynamic allocated Render */ diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c index de9572bf57b..bf6962d0087 100644 --- a/source/blender/render/intern/source/zbuf.c +++ b/source/blender/render/intern/source/zbuf.c @@ -3476,7 +3476,7 @@ void zbuffer_abuf_shadow(Render *re, LampRen *lar, float winmat[][4], APixstr *A /* speed pointer NULL = sky, we clear */ /* else if either alpha is full or no solid was filled in: copy speed */ /* else fill in minimum speed */ -void add_transp_speed(RenderLayer *rl, int offset, float *speed, float alpha, intptr_t *rdrect) +static void add_transp_speed(RenderLayer *rl, int offset, float speed[4], float alpha, intptr_t *rdrect) { RenderPass *rpass; @@ -3525,7 +3525,7 @@ static void add_transp_obindex(RenderLayer *rl, int offset, Object *ob) /* ONLY OSA! merge all shaderesult samples to one */ /* target should have been cleared */ -void merge_transp_passes(RenderLayer *rl, ShadeResult *shr) +static void merge_transp_passes(RenderLayer *rl, ShadeResult *shr) { RenderPass *rpass; float weight= 1.0f/((float)R.osa); @@ -3627,7 +3627,7 @@ void merge_transp_passes(RenderLayer *rl, ShadeResult *shr) } -void add_transp_passes(RenderLayer *rl, int offset, ShadeResult *shr, float alpha) +static void add_transp_passes(RenderLayer *rl, int offset, ShadeResult *shr, float alpha) { RenderPass *rpass; |