From a25c11fd8d602236f36c34c342453149bdc1d909 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 8 Jun 2018 08:07:48 +0200 Subject: Cleanup: trailing space Remove from blender/nodes, collada, blenfont & render. --- source/blender/blenfont/intern/blf.c | 2 +- source/blender/blenfont/intern/blf_dir.c | 16 +- source/blender/blenfont/intern/blf_font.c | 2 +- source/blender/blenfont/intern/blf_glyph.c | 18 +- .../blender/blenfont/intern/blf_internal_types.h | 2 +- source/blender/collada/AnimationExporter.cpp | 54 +- source/blender/collada/AnimationExporter.h | 22 +- source/blender/collada/AnimationImporter.cpp | 84 +-- source/blender/collada/AnimationImporter.h | 18 +- source/blender/collada/ArmatureExporter.cpp | 10 +- source/blender/collada/ArmatureImporter.cpp | 38 +- source/blender/collada/ArmatureImporter.h | 6 +- source/blender/collada/CameraExporter.cpp | 4 +- source/blender/collada/ControllerExporter.cpp | 24 +- source/blender/collada/DocumentExporter.cpp | 16 +- source/blender/collada/DocumentImporter.cpp | 106 ++-- source/blender/collada/DocumentImporter.h | 6 +- source/blender/collada/EffectExporter.cpp | 30 +- source/blender/collada/EffectExporter.h | 12 +- source/blender/collada/ErrorHandler.cpp | 2 +- source/blender/collada/ExtraHandler.cpp | 4 +- source/blender/collada/ExtraHandler.h | 18 +- source/blender/collada/ExtraTags.cpp | 2 +- source/blender/collada/ExtraTags.h | 16 +- source/blender/collada/GeometryExporter.cpp | 98 ++-- source/blender/collada/GeometryExporter.h | 6 +- source/blender/collada/ImageExporter.cpp | 10 +- source/blender/collada/ImageExporter.h | 4 +- source/blender/collada/LightExporter.cpp | 16 +- source/blender/collada/MaterialExporter.h | 2 +- source/blender/collada/MeshImporter.cpp | 108 ++-- source/blender/collada/MeshImporter.h | 10 +- source/blender/collada/SceneExporter.cpp | 18 +- source/blender/collada/SceneExporter.h | 2 +- source/blender/collada/SkinInfo.cpp | 8 +- source/blender/collada/SkinInfo.h | 4 +- source/blender/collada/TransformReader.cpp | 6 +- source/blender/collada/TransformReader.h | 2 +- source/blender/collada/TransformWriter.cpp | 2 +- source/blender/collada/collada_internal.h | 8 +- source/blender/collada/collada_utils.cpp | 26 +- source/blender/collada/collada_utils.h | 8 +- source/blender/datatoc/datatoc_icon.c | 2 +- source/blender/ikplugin/CMakeLists.txt | 2 +- source/blender/ikplugin/intern/ikplugin_api.c | 6 +- source/blender/ikplugin/intern/itasc_plugin.cpp | 2 +- .../blender/nodes/composite/node_composite_tree.c | 36 +- .../blender/nodes/composite/node_composite_util.c | 2 +- .../composite/nodes/node_composite_bokehblur.c | 2 +- .../composite/nodes/node_composite_bokehimage.c | 2 +- .../nodes/composite/nodes/node_composite_boxmask.c | 2 +- .../composite/nodes/node_composite_brightness.c | 2 +- .../composite/nodes/node_composite_colorSpill.c | 2 +- .../composite/nodes/node_composite_colorbalance.c | 4 +- .../nodes/composite/nodes/node_composite_common.c | 4 +- .../nodes/composite/nodes/node_composite_dilate.c | 2 +- .../composite/nodes/node_composite_ellipsemask.c | 2 +- .../nodes/composite/nodes/node_composite_gamma.c | 4 +- .../composite/nodes/node_composite_huecorrect.c | 6 +- .../nodes/composite/nodes/node_composite_image.c | 20 +- .../nodes/composite/nodes/node_composite_inpaint.c | 2 +- .../nodes/composite/nodes/node_composite_math.c | 2 +- .../nodes/node_composite_moviedistortion.c | 2 +- .../composite/nodes/node_composite_normalize.c | 4 +- .../composite/nodes/node_composite_outputFile.c | 34 +- .../composite/nodes/node_composite_splitViewer.c | 2 +- .../composite/nodes/node_composite_stabilize2d.c | 4 +- .../composite/nodes/node_composite_valToRgb.c | 4 +- .../nodes/composite/nodes/node_composite_viewer.c | 2 +- source/blender/nodes/intern/node_common.c | 100 ++-- source/blender/nodes/intern/node_exec.c | 62 +- source/blender/nodes/intern/node_exec.h | 6 +- source/blender/nodes/intern/node_socket.c | 84 +-- source/blender/nodes/intern/node_util.c | 38 +- source/blender/nodes/shader/node_shader_tree.c | 62 +- source/blender/nodes/shader/node_shader_util.c | 32 +- .../nodes/shader/nodes/node_shader_brightness.c | 4 +- .../blender/nodes/shader/nodes/node_shader_bump.c | 2 +- .../nodes/shader/nodes/node_shader_camera.c | 2 +- .../nodes/shader/nodes/node_shader_common.c | 42 +- .../nodes/shader/nodes/node_shader_curves.c | 4 +- .../nodes/shader/nodes/node_shader_fresnel.c | 2 +- .../blender/nodes/shader/nodes/node_shader_gamma.c | 4 +- .../blender/nodes/shader/nodes/node_shader_geom.c | 4 +- .../nodes/shader/nodes/node_shader_hueSatVal.c | 2 +- .../nodes/shader/nodes/node_shader_invert.c | 8 +- .../nodes/shader/nodes/node_shader_mapping.c | 6 +- .../nodes/shader/nodes/node_shader_material.c | 48 +- .../blender/nodes/shader/nodes/node_shader_math.c | 12 +- .../nodes/shader/nodes/node_shader_mixRgb.c | 2 +- .../nodes/shader/nodes/node_shader_normal.c | 10 +- .../nodes/shader/nodes/node_shader_output.c | 10 +- .../nodes/shader/nodes/node_shader_output_world.c | 2 +- .../nodes/shader/nodes/node_shader_sepcombHSV.c | 4 +- .../nodes/shader/nodes/node_shader_sepcombRGB.c | 4 +- .../nodes/shader/nodes/node_shader_squeeze.c | 4 +- .../nodes/shader/nodes/node_shader_tex_brick.c | 2 +- .../nodes/shader/nodes/node_shader_tex_coord.c | 4 +- .../shader/nodes/node_shader_tex_environment.c | 6 +- .../nodes/shader/nodes/node_shader_texture.c | 24 +- .../nodes/shader/nodes/node_shader_valToRgb.c | 2 +- .../nodes/shader/nodes/node_shader_vectMath.c | 24 +- .../nodes/shader/nodes/node_shader_vectTransform.c | 8 +- source/blender/nodes/texture/node_texture_tree.c | 58 +- source/blender/nodes/texture/node_texture_util.c | 16 +- .../blender/nodes/texture/nodes/node_texture_at.c | 6 +- .../nodes/texture/nodes/node_texture_bricks.c | 26 +- .../nodes/texture/nodes/node_texture_checker.c | 8 +- .../nodes/texture/nodes/node_texture_common.c | 28 +- .../nodes/texture/nodes/node_texture_compose.c | 6 +- .../nodes/texture/nodes/node_texture_coord.c | 4 +- .../nodes/texture/nodes/node_texture_curves.c | 14 +- .../nodes/texture/nodes/node_texture_decompose.c | 6 +- .../nodes/texture/nodes/node_texture_distance.c | 4 +- .../nodes/texture/nodes/node_texture_hueSatVal.c | 16 +- .../nodes/texture/nodes/node_texture_image.c | 16 +- .../nodes/texture/nodes/node_texture_invert.c | 10 +- .../nodes/texture/nodes/node_texture_mixRgb.c | 10 +- .../nodes/texture/nodes/node_texture_output.c | 26 +- .../nodes/texture/nodes/node_texture_proc.c | 38 +- .../nodes/texture/nodes/node_texture_rotate.c | 20 +- .../nodes/texture/nodes/node_texture_scale.c | 10 +- .../nodes/texture/nodes/node_texture_texture.c | 14 +- .../nodes/texture/nodes/node_texture_translate.c | 12 +- .../nodes/texture/nodes/node_texture_valToNor.c | 10 +- .../nodes/texture/nodes/node_texture_valToRgb.c | 10 +- .../nodes/texture/nodes/node_texture_viewer.c | 6 +- source/blender/physics/intern/BPH_mass_spring.cpp | 346 +++++------ .../physics/intern/ConstrainedConjugateGradient.h | 34 +- source/blender/physics/intern/eigen_utils.h | 42 +- source/blender/physics/intern/hair_volume.cpp | 278 ++++----- source/blender/physics/intern/implicit.h | 2 +- source/blender/physics/intern/implicit_blender.c | 436 +++++++------- source/blender/physics/intern/implicit_eigen.cpp | 326 +++++------ source/blender/render/CMakeLists.txt | 2 +- source/blender/render/extern/include/RE_pipeline.h | 22 +- .../blender/render/extern/include/RE_shader_ext.h | 28 +- source/blender/render/intern/include/envmap.h | 2 +- source/blender/render/intern/include/initrender.h | 2 +- .../blender/render/intern/include/pixelblending.h | 2 +- .../blender/render/intern/include/pixelshading.h | 2 +- .../blender/render/intern/include/pointdensity.h | 2 +- source/blender/render/intern/include/raycounter.h | 2 +- .../render/intern/include/rayintersection.h | 8 +- .../blender/render/intern/include/render_types.h | 94 +-- source/blender/render/intern/include/rendercore.h | 2 +- source/blender/render/intern/include/shading.h | 4 +- source/blender/render/intern/include/strand.h | 2 +- source/blender/render/intern/include/sunsky.h | 2 +- .../blender/render/intern/include/texture_ocean.h | 2 +- source/blender/render/intern/include/voxeldata.h | 2 +- source/blender/render/intern/include/zbuf.h | 12 +- source/blender/render/intern/raytrace/bvh.h | 26 +- .../blender/render/intern/raytrace/rayobject.cpp | 16 +- .../render/intern/raytrace/rayobject_hint.h | 2 +- .../render/intern/raytrace/rayobject_instance.cpp | 4 +- .../render/intern/raytrace/rayobject_octree.cpp | 136 ++--- .../render/intern/raytrace/rayobject_qbvh.cpp | 14 +- .../intern/raytrace/rayobject_raycounter.cpp | 2 +- .../render/intern/raytrace/rayobject_rtbuild.cpp | 66 +-- .../render/intern/raytrace/rayobject_rtbuild.h | 10 +- .../render/intern/raytrace/rayobject_svbvh.cpp | 14 +- .../render/intern/raytrace/rayobject_vbvh.cpp | 16 +- source/blender/render/intern/raytrace/reorganize.h | 68 +-- source/blender/render/intern/raytrace/svbvh.h | 26 +- source/blender/render/intern/raytrace/vbvh.h | 26 +- source/blender/render/intern/source/bake.c | 50 +- .../blender/render/intern/source/convertblender.c | 612 ++++++++++---------- source/blender/render/intern/source/envmap.c | 166 +++--- .../blender/render/intern/source/external_engine.c | 8 +- source/blender/render/intern/source/imagetexture.c | 134 ++--- source/blender/render/intern/source/initrender.c | 94 +-- .../blender/render/intern/source/multires_bake.c | 2 +- source/blender/render/intern/source/occlusion.c | 38 +- source/blender/render/intern/source/pipeline.c | 404 ++++++------- .../blender/render/intern/source/pixelblending.c | 68 +-- source/blender/render/intern/source/pixelshading.c | 156 ++--- source/blender/render/intern/source/pointdensity.c | 48 +- source/blender/render/intern/source/rayshade.c | 508 ++++++++--------- .../blender/render/intern/source/render_result.c | 84 +-- .../blender/render/intern/source/render_texture.c | 480 ++++++++-------- source/blender/render/intern/source/rendercore.c | 426 +++++++------- .../blender/render/intern/source/renderdatabase.c | 160 +++--- source/blender/render/intern/source/shadbuf.c | 500 ++++++++-------- source/blender/render/intern/source/shadeinput.c | 206 +++---- source/blender/render/intern/source/shadeoutput.c | 410 +++++++------- source/blender/render/intern/source/sss.c | 30 +- source/blender/render/intern/source/strand.c | 32 +- source/blender/render/intern/source/sunsky.c | 54 +- .../blender/render/intern/source/volume_precache.c | 172 +++--- source/blender/render/intern/source/volumetric.c | 208 +++---- source/blender/render/intern/source/voxeldata.c | 70 +-- source/blender/render/intern/source/zbuf.c | 630 ++++++++++----------- 193 files changed, 4922 insertions(+), 4922 deletions(-) (limited to 'source') diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index 38c1498d76b..2a8fc14f4ae 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -164,7 +164,7 @@ static int blf_search_available(void) for (i = 0; i < BLF_MAX_FONT; i++) if (!global_font[i]) return i; - + return -1; } diff --git a/source/blender/blenfont/intern/blf_dir.c b/source/blender/blenfont/intern/blf_dir.c index d3349a10834..ff5c1151a82 100644 --- a/source/blender/blenfont/intern/blf_dir.c +++ b/source/blender/blenfont/intern/blf_dir.c @@ -61,7 +61,7 @@ static ListBase global_font_dir = { NULL, NULL }; static DirBLF *blf_dir_find(const char *path) { DirBLF *p; - + p = global_font_dir.first; while (p) { if (BLI_path_cmp(p->path, path) == 0) @@ -74,11 +74,11 @@ static DirBLF *blf_dir_find(const char *path) void BLF_dir_add(const char *path) { DirBLF *dir; - + dir = blf_dir_find(path); if (dir) /* already in the list ? just return. */ return; - + dir = (DirBLF *)MEM_callocN(sizeof(DirBLF), "BLF_dir_add"); dir->path = BLI_strdup(path); BLI_addhead(&global_font_dir, dir); @@ -87,7 +87,7 @@ void BLF_dir_add(const char *path) void BLF_dir_rem(const char *path) { DirBLF *dir; - + dir = blf_dir_find(path); if (dir) { BLI_remlink(&global_font_dir, dir); @@ -102,11 +102,11 @@ char **BLF_dir_get(int *ndir) char **dirs; char *path; int i, count; - + count = BLI_listbase_count(&global_font_dir); if (!count) return NULL; - + dirs = (char **)MEM_callocN(sizeof(char *) * count, "BLF_dir_get"); p = global_font_dir.first; i = 0; @@ -123,7 +123,7 @@ void BLF_dir_free(char **dirs, int count) { char *path; int i; - + for (i = 0; i < count; i++) { path = dirs[i]; MEM_freeN(path); @@ -159,7 +159,7 @@ int blf_dir_split(const char *str, char *file, int *size) { int i, len; char *s; - + /* Window, Linux or Mac, this is always / */ s = strrchr(str, '/'); if (s) { diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index c82515ff41c..fe9769dd2d1 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -343,7 +343,7 @@ static void blf_font_draw_buffer_ex( width_clip -= chx + width_clip - buf_info->w; if (height_clip + pen_y > buf_info->h) height_clip -= pen_y + height_clip - buf_info->h; - + /* drawing below the image? */ if (pen_y < 0) { yb_start += (g->pitch < 0) ? -pen_y : pen_y; diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index b5fe29ae2d9..9af347908e1 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -245,11 +245,11 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c) if (font->flags & BLF_HINTING) flags &= ~FT_LOAD_NO_HINTING; - + if (is_sharp) err = FT_Load_Glyph(font->face, (FT_UInt)index, FT_LOAD_TARGET_MONO); else - err = FT_Load_Glyph(font->face, (FT_UInt)index, flags); + err = FT_Load_Glyph(font->face, (FT_UInt)index, flags); if (err) { BLI_spin_unlock(font->ft_lib_mutex); @@ -336,13 +336,13 @@ static void blf_texture_draw(float uv[2][2], float dx, float y1, float dx1, floa glBegin(GL_QUADS); glTexCoord2f(uv[0][0], uv[0][1]); glVertex2f(dx, y1); - + glTexCoord2f(uv[0][0], uv[1][1]); glVertex2f(dx, y2); - + glTexCoord2f(uv[1][0], uv[1][1]); glVertex2f(dx1, y2); - + glTexCoord2f(uv[1][0], uv[0][1]); glVertex2f(dx1, y1); glEnd(); @@ -355,7 +355,7 @@ static void blf_texture5_draw(const float shadow_col[4], float uv[2][2], float x 2 / 60.0f, 5 / 60.0f, 8 / 60.0f, 5 / 60.0f, 2 / 60.0f, 1 / 60.0f, 3 / 60.0f, 5 / 60.0f, 3 / 60.0f, 1 / 60.0f, 1 / 60.0f, 1 / 60.0f, 2 / 60.0f, 1 / 60.0f, 1 / 60.0f}; - + const float *fp = soft; float color[4]; float dx, dy; @@ -363,7 +363,7 @@ static void blf_texture5_draw(const float shadow_col[4], float uv[2][2], float x color[0] = shadow_col[0]; color[1] = shadow_col[1]; color[2] = shadow_col[2]; - + for (dx = -2; dx < 3; dx++) { for (dy = -2; dy < 3; dy++, fp++) { color[3] = *(fp) * shadow_col[3]; @@ -371,7 +371,7 @@ static void blf_texture5_draw(const float shadow_col[4], float uv[2][2], float x blf_texture_draw(uv, x1 + dx, y1 + dy, x2 + dx, y2 + dy); } } - + glColor4fv(color); } @@ -396,7 +396,7 @@ static void blf_texture3_draw(const float shadow_col[4], float uv[2][2], float x blf_texture_draw(uv, x1 + dx, y1 + dy, x2 + dx, y2 + dy); } } - + glColor4fv(color); } diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h index 17bafa81458..5723f08d44b 100644 --- a/source/blender/blenfont/intern/blf_internal_types.h +++ b/source/blender/blenfont/intern/blf_internal_types.h @@ -174,7 +174,7 @@ typedef struct FontBLF { /* angle in radians. */ float angle; - + /* blur: 3 or 5 large kernel */ int blur; diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp index c891414f088..bf371332fd0 100644 --- a/source/blender/collada/AnimationExporter.cpp +++ b/source/blender/collada/AnimationExporter.cpp @@ -270,7 +270,7 @@ void AnimationExporter::export_sampled_transrotloc_animation(Object *ob, std::ve create_sampled_animation(3, ctimes, baked_curves[SCALE], ob_name, "scale", "", false); create_sampled_animation(3, ctimes, baked_curves[LOC], ob_name, "location", "", false); - /* Not sure how to export rotation as a 3channel animation, + /* Not sure how to export rotation as a 3channel animation, * so separate into 3 single animations for now: */ @@ -314,7 +314,7 @@ void AnimationExporter::operator()(Object *ob) //This needs to be handled by extra profiles, so postponed for now //export_morph_animation(ob); - + //Export Lamp parameter animations if ( (ob->type == OB_LAMP) && ((Lamp *)ob->data)->adt && ((Lamp *)ob->data)->adt->action) { FCurve *fcu = (FCurve *)(((Lamp *)ob->data)->adt->action->curves.first); @@ -338,7 +338,7 @@ void AnimationExporter::operator()(Object *ob) if ((STREQ(transformName, "lens")) || (STREQ(transformName, "ortho_scale")) || - (STREQ(transformName, "clip_end")) || + (STREQ(transformName, "clip_end")) || (STREQ(transformName, "clip_start"))) { create_keyframed_animation(ob, fcu, transformName, true); @@ -380,7 +380,7 @@ void AnimationExporter::export_object_constraint_animation(Object *ob) } void AnimationExporter::export_morph_animation(Object *ob) -{ +{ FCurve *fcu; char *transformName; Key *key = BKE_key_from_object(ob); @@ -388,12 +388,12 @@ void AnimationExporter::export_morph_animation(Object *ob) if (key->adt && key->adt->action) { fcu = (FCurve *)key->adt->action->curves.first; - + while (fcu) { transformName = extract_transform_name(fcu->rna_path); create_keyframed_animation(ob, fcu, transformName, true); - + fcu = fcu->next; } } @@ -407,17 +407,17 @@ void AnimationExporter::make_anim_frames_from_targets(Object *ob, std::vectorfirst; con; con = con->next) { ListBase targets = {NULL, NULL}; - + const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); - + if (!validateConstraints(con)) continue; if (cti && cti->get_constraint_targets) { bConstraintTarget *ct; Object *obtar; - /* get targets + /* get targets * - constraints should use ct->matrix, not directly accessing values - * - ct->matrix members have not yet been calculated here! + * - ct->matrix members have not yet been calculated here! */ cti->get_constraint_targets(con, &targets); @@ -438,7 +438,7 @@ void AnimationExporter::make_anim_frames_from_targets(Object *ob, std::vectoradt->action->curves.first; - const int keys = fcu->totvert; + const int keys = fcu->totvert; float *quat = (float *)MEM_callocN(sizeof(float) * fcu->totvert * 4, "quat output source values"); float *eul = (float *)MEM_callocN(sizeof(float) * fcu->totvert * 3, "quat output source values"); float temp_quat[4]; @@ -520,11 +520,11 @@ void AnimationExporter::create_keyframed_animation(Object *ob, FCurve *fcu, char /* * Note: Handle transformation animations separately (to apply matrix inverse to fcurves) - * We will use the object to evaluate the animation on all keyframes and calculate the + * We will use the object to evaluate the animation on all keyframes and calculate the * resulting object matrix. We need this to incorporate the * effects of the parent inverse matrix (when it contains a rotation component) * - * TODO: try to combine exported fcurves into 3 channel animations like done + * TODO: try to combine exported fcurves into 3 channel animations like done * in export_sampled_animation(). For now each channel is exported as separate . */ @@ -648,7 +648,7 @@ void AnimationExporter::create_keyframed_animation(Object *ob, FCurve *fcu, char "/common/" /*profile common is only supported */ + get_transform_sid(fcu->rna_path, -1, axis_name, true); //if shape key animation, this is the main problem, how to define the channel targets. /*target = get_morph_id(ob) + - "/value" +*/ + "/value" +*/ } addChannel(COLLADABU::URI(empty, sampler_id), target); @@ -673,7 +673,7 @@ void AnimationExporter::write_bone_animation_matrix(Object *ob_arm, Bone *bone) } bool AnimationExporter::is_bone_deform_group(Bone *bone) -{ +{ bool is_def; //Check if current bone is deform if ((bone->flag & BONE_NO_DEFORM) == 0) return true; @@ -707,7 +707,7 @@ void AnimationExporter::sample_and_write_bone_animation_matrix(Object *ob_arm, B fcu = fcu->next; } - if (!(fcu)) return;*/ + if (!(fcu)) return;*/ bPoseChannel *pchan = BKE_pose_channel_find_name(ob_arm->pose, bone->name); if (!pchan) @@ -728,7 +728,7 @@ void AnimationExporter::sample_and_write_bone_animation_matrix(Object *ob_arm, B dae_baked_animation(fra, ob_arm, bone); } - if (flag & ARM_RESTPOS) + if (flag & ARM_RESTPOS) arm->flag = flag; BKE_pose_where_is(scene, ob_arm); } @@ -921,7 +921,7 @@ void AnimationExporter::add_source_parameters(COLLADASW::SourceBase::ParameterNa if (axis) { param.push_back(axis); } - else + else if (transform) { param.push_back("TRANSFORM"); } @@ -1307,7 +1307,7 @@ std::string AnimationExporter::create_4x4_source(std::vector &frames, Obj enable_fcurves(ob->adt->action, bone->name); } - + std::vector::iterator it; int j = 0; for (it = frames.begin(); it != frames.end(); it++) { @@ -1325,7 +1325,7 @@ std::string AnimationExporter::create_4x4_source(std::vector &frames, Obj else { BKE_pose_where_is_bone(scene, ob, pchan, ctime, 1); } - + // compute bone local mat if (bone->parent) { invert_m4_m4(ipar, parchan->pose_mat); @@ -1333,7 +1333,7 @@ std::string AnimationExporter::create_4x4_source(std::vector &frames, Obj } else copy_m4_m4(mat, pchan->pose_mat); - + /* OPEN_SIM_COMPATIBILITY * AFAIK animation to second life is via BVH, but no * reason to not have the collada-animation be correct @@ -1358,7 +1358,7 @@ std::string AnimationExporter::create_4x4_source(std::vector &frames, Obj else { copy_m4_m4(mat, ob->obmat); } - + UnitConverter converter; double outmat[4][4]; @@ -1514,7 +1514,7 @@ std::string AnimationExporter::get_light_param_sid(char *rna_path, int tm_type, if (tm_name.size()) { if (axis_name[0]) return tm_name + "." + std::string(axis_name); - else + else return tm_name; } @@ -1563,7 +1563,7 @@ std::string AnimationExporter::get_camera_param_sid(char *rna_path, int tm_type, if (tm_name.size()) { if (axis_name[0]) return tm_name + "." + std::string(axis_name); - else + else return tm_name; } @@ -1750,7 +1750,7 @@ void AnimationExporter::find_sampleframes(Object *ob, std::vector &fra) } while (true); } -/* +/* * find keyframes of all the objects animations */ void AnimationExporter::find_keyframes(Object *ob, std::vector &fra) @@ -1843,7 +1843,7 @@ void AnimationExporter::sample_and_write_bone_animation(Object *ob_arm, Bone *bo arm->flag &= ~ARM_RESTPOS; BKE_pose_where_is(scene, ob_arm); } - //v array will hold all values which will be exported. + //v array will hold all values which will be exported. if (fra.size()) { float *values = (float *)MEM_callocN(sizeof(float) * 3 * fra.size(), "temp. anim frames"); sample_animation(values, fra, transform_type, bone, ob_arm, pchan); @@ -1869,7 +1869,7 @@ void AnimationExporter::sample_and_write_bone_animation(Object *ob_arm, Bone *bo } // restore restpos - if (flag & ARM_RESTPOS) + if (flag & ARM_RESTPOS) arm->flag = flag; BKE_pose_where_is(scene, ob_arm); } diff --git a/source/blender/collada/AnimationExporter.h b/source/blender/collada/AnimationExporter.h index a739b2b6cbe..36968d3edef 100644 --- a/source/blender/collada/AnimationExporter.h +++ b/source/blender/collada/AnimationExporter.h @@ -23,7 +23,7 @@ #include #include #include -extern "C" +extern "C" { #include "DNA_scene_types.h" #include "DNA_object_types.h" @@ -99,8 +99,8 @@ public: bool exportAnimations(Scene *sce); // called for each exported object - void operator() (Object *ob); - + void operator() (Object *ob); + protected: const ExportSettings *export_settings; @@ -126,7 +126,7 @@ protected: // dae_bone_animation -> add_bone_animation // (blend this into dae_bone_animation) void dae_bone_animation(std::vector &fra, float *v, int tm_type, int axis, std::string ob_name, std::string bone_name); - + void dae_baked_animation(std::vector &fra, Object *ob_arm, Bone *bone); void dae_baked_object_animation(std::vector &fra, Object *ob); @@ -139,9 +139,9 @@ protected: void add_source_parameters(COLLADASW::SourceBase::ParameterNameList& param, COLLADASW::InputSemantic::Semantics semantic, bool is_rot, const char *axis, bool transform); - + void get_source_values(BezTriple *bezt, COLLADASW::InputSemantic::Semantics semantic, bool is_angle, float *values, int *length); - + float* get_eul_source_for_quat(Object *ob ); bool is_flat_line(std::vector &values, int channel_count); @@ -170,12 +170,12 @@ protected: std::string create_interpolation_source(FCurve *fcu, const std::string& anim_id, const char *axis_name, bool *has_tangents); std::string fake_interpolation_source(int tot, const std::string& anim_id, const char *axis_name); - + // for rotation, axis name is always appended and the value of append_axis is ignored std::string get_transform_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis); std::string get_light_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis); std::string get_camera_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis); - + void find_keyframes(Object *ob, std::vector &fra, const char *prefix, const char *tm_name); void find_keyframes(Object *ob, std::vector &fra); void find_sampleframes(Object *ob, std::vector &fra); @@ -184,13 +184,13 @@ protected: void make_anim_frames_from_targets(Object *ob, std::vector &frames ); void find_rotation_frames(Object *ob, std::vector &fra, const char *prefix, int rotmode); - + // enable fcurves driving a specific bone, disable all the rest // if bone_name = NULL enable all fcurves void enable_fcurves(bAction *act, char *bone_name); - + bool hasAnimations(Scene *sce); - + char *extract_transform_name(char *rna_path); std::string getObjectBoneName(Object *ob, const FCurve * fcu); diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index 13bd5c16053..3dda67abbba 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -118,7 +118,7 @@ void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve) // input, output - bez.vec[1][0] = bc_get_float_value(input, j) * fps; + bez.vec[1][0] = bc_get_float_value(input, j) * fps; bez.vec[1][1] = bc_get_float_value(output, j * dim + i); @@ -135,14 +135,14 @@ void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve) // outtangent bez.vec[2][0] = bc_get_float_value(outtan, (j * 2 * dim) + (2 * i)) * fps; bez.vec[2][1] = bc_get_float_value(outtan, (j * 2 * dim) + (2 * i) + 1); - if (curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER) + if (curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER) bez.ipo = BEZT_IPO_BEZ; - else + else bez.ipo = BEZT_IPO_CONST; //bez.h1 = bez.h2 = HD_AUTO; } else { - bez.h1 = bez.h2 = HD_AUTO; + bez.h1 = bez.h2 = HD_AUTO; bez.ipo = BEZT_IPO_LIN; } // bez.ipo = U.ipo_new; /* use default interpolation mode here... */ @@ -183,10 +183,10 @@ void AnimationImporter::fcurve_is_used(FCurve *fcu) void AnimationImporter::add_fcurves_to_object(Main *bmain, Object *ob, std::vector& curves, char *rna_path, int array_index, Animation *animated) { bAction *act; - + if (!ob->adt || !ob->adt->action) act = verify_adt_action(bmain, (ID *)&ob->id, 1); else act = ob->adt->action; - + std::vector::iterator it; int i; @@ -198,39 +198,39 @@ void AnimationImporter::add_fcurves_to_object(Main *bmain, Object *ob, std::vect if (is_rotation) fcurve_deg_to_rad(fcu); #endif - + for (it = curves.begin(), i = 0; it != curves.end(); it++, i++) { FCurve *fcu = *it; fcu->rna_path = BLI_strdupn(rna_path, strlen(rna_path)); - + if (array_index == -1) fcu->array_index = i; else fcu->array_index = array_index; - + if (ob->type == OB_ARMATURE) { bActionGroup *grp = NULL; const char *bone_name = bc_get_joint_name(animated->node); - + if (bone_name) { /* try to find group */ grp = BKE_action_group_find_name(act, bone_name); - + /* no matching groups, so add one */ if (grp == NULL) { /* Add a new group, and make it active */ grp = (bActionGroup *)MEM_callocN(sizeof(bActionGroup), "bActionGroup"); - + grp->flag = AGRP_SELECTED; BLI_strncpy(grp->name, bone_name, sizeof(grp->name)); - + BLI_addtail(&act->groups, grp); BLI_uniquename(&act->groups, grp, CTX_DATA_(BLT_I18NCONTEXT_ID_ACTION, "Group"), '.', offsetof(bActionGroup, name), 64); } - + /* add F-Curve to group */ action_groups_add_channel(act, grp, fcu); fcurve_is_used(fcu); - + } #if 0 if (is_rotation) { @@ -263,7 +263,7 @@ bool AnimationImporter::write_animation(const COLLADAFW::Animation *anim) { if (anim->getAnimationType() == COLLADAFW::Animation::ANIMATION_CURVE) { COLLADAFW::AnimationCurve *curve = (COLLADAFW::AnimationCurve *)anim; - + // XXX Don't know if it's necessary // Should we check outPhysicalDimension? if (curve->getInPhysicalDimension() != COLLADAFW::PHYSICAL_DIMENSION_TIME) { @@ -296,10 +296,10 @@ bool AnimationImporter::write_animation(const COLLADAFW::Animation *anim) else { fprintf(stderr, "FORMULA animation type is not supported yet.\n"); } - + return true; } - + // called on post-process stage after writeVisualScenes bool AnimationImporter::write_animation_list(const COLLADAFW::AnimationList *animlist) { @@ -340,16 +340,16 @@ virtual void AnimationImporter::change_eul_to_quat(Object *ob, bAction *act) { bActionGroup *grp; int i; - + for (grp = (bActionGroup *)act->groups.first; grp; grp = grp->next) { FCurve *eulcu[3] = {NULL, NULL, NULL}; - + if (fcurves_actionGroup_map.find(grp) == fcurves_actionGroup_map.end()) continue; std::vector &rot_fcurves = fcurves_actionGroup_map[grp]; - + if (rot_fcurves.size() > 3) continue; for (i = 0; i < rot_fcurves.size(); i++) @@ -437,7 +437,7 @@ void AnimationImporter::modify_fcurve(std::vector *curves, const char for (it = curves->begin(), i = 0; it != curves->end(); it++, i++) { FCurve *fcu = *it; fcu->rna_path = BLI_strdup(rna_path); - + if (array_index == -1) fcu->array_index = i; else fcu->array_index = array_index; @@ -674,7 +674,7 @@ void AnimationImporter:: Assign_float_animations(const COLLADAFW::UniqueId& list } } } - + } float AnimationImporter::convert_to_focal_length(float in_xfov, int fov_type, float aspect, float sensorx) @@ -711,7 +711,7 @@ void AnimationImporter::Assign_lens_animations(const COLLADAFW::UniqueId& listid //Add the curves of the current animation to the object for (iter = animcurves.begin(); iter != animcurves.end(); iter++) { FCurve *fcu = *iter; - + for (unsigned int i = 0; i < fcu->totvert; i++) { fcu->bezt[i].vec[0][1] = convert_to_focal_length(fcu->bezt[i].vec[0][1], fov_type, aspect, cam->sensor_x); fcu->bezt[i].vec[1][1] = convert_to_focal_length(fcu->bezt[i].vec[1][1], fov_type, aspect, cam->sensor_x); @@ -949,7 +949,7 @@ void AnimationImporter::translate_Animations(Main *bmain, COLLADAFW::Node *node, const COLLADAFW::TransformationPointerArray& nodeTransforms = node->getTransformations(); - //for each transformation in node + //for each transformation in node for (unsigned int i = 0; i < nodeTransforms.getCount(); i++) { COLLADAFW::Transformation *transform = nodeTransforms[i]; COLLADAFW::Transformation::TransformationType tm_type = transform->getTransformationType(); @@ -986,12 +986,12 @@ void AnimationImporter::translate_Animations(Main *bmain, COLLADAFW::Node *node, //Add the curves of the current animation to the object for (iter = animcurves.begin(); iter != animcurves.end(); iter++) { FCurve *fcu = *iter; - + BLI_addtail(AnimCurves, fcu); fcurve_is_used(fcu); } } - + } } } @@ -1017,7 +1017,7 @@ void AnimationImporter::translate_Animations(Main *bmain, COLLADAFW::Node *node, const COLLADAFW::Color *col = &(light->getColor()); const COLLADAFW::UniqueId& listid = col->getAnimationList(); - Assign_color_animations(listid, AnimCurves, "color"); + Assign_color_animations(listid, AnimCurves, "color"); } if ((animType->light & LIGHT_FOA) != 0) { const COLLADAFW::AnimatableFloat *foa = &(light->getFallOffAngle()); @@ -1051,14 +1051,14 @@ void AnimationImporter::translate_Animations(Main *bmain, COLLADAFW::Node *node, if ((animType->camera & CAMERA_XFOV) != 0) { const COLLADAFW::AnimatableFloat *xfov = &(camera->getXFov()); const COLLADAFW::UniqueId& listid = xfov->getAnimationList(); - double aspect = get_aspect_ratio(camera); + double aspect = get_aspect_ratio(camera); Assign_lens_animations(listid, AnimCurves, aspect, cam, "lens", CAMERA_XFOV); } else if ((animType->camera & CAMERA_YFOV) != 0) { const COLLADAFW::AnimatableFloat *yfov = &(camera->getYFov()); const COLLADAFW::UniqueId& listid = yfov->getAnimationList(); - double aspect = get_aspect_ratio(camera); + double aspect = get_aspect_ratio(camera); Assign_lens_animations(listid, AnimCurves, aspect, cam, "lens", CAMERA_YFOV); } @@ -1281,7 +1281,7 @@ AnimationImporter::AnimMix *AnimationImporter::get_animation_type(const COLLADAF const COLLADAFW::TransformationPointerArray& nodeTransforms = node->getTransformations(); - //for each transformation in node + //for each transformation in node for (unsigned int i = 0; i < nodeTransforms.getCount(); i++) { COLLADAFW::Transformation *transform = nodeTransforms[i]; const COLLADAFW::UniqueId& listid = transform->getAnimationList(); @@ -1369,7 +1369,7 @@ int AnimationImporter::setAnimType(const COLLADAFW::Animatable *prop, int types, anim_type = types; return anim_type; -} +} // Is not used anymore. void AnimationImporter::find_frames_old(std::vector *frames, COLLADAFW::Node *node, COLLADAFW::Transformation::TransformationType tm_type) @@ -1391,7 +1391,7 @@ void AnimationImporter::find_frames_old(std::vector *frames, COLLADAFW::N const COLLADAFW::UniqueId& listid = transform->getAnimationList(); //if transform is animated its animlist must exist. if (animlist_map.find(listid) != animlist_map.end()) { - + const COLLADAFW::AnimationList *animlist = animlist_map[listid]; const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings(); @@ -1441,11 +1441,11 @@ Object *AnimationImporter::translate_animation_OLD(Main *bmain, COLLADAFW::Node COLLADAFW::Transformation::TransformationType tm_type, Object *par_job) { - + bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE; bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX; bool is_joint = node->getType() == COLLADAFW::Node::JOINT; - + COLLADAFW::Node *root = root_map.find(node->getUniqueId()) == root_map.end() ? node : root_map[node->getUniqueId()]; Object *ob = is_joint ? armature_importer->get_armature_for_joint(node) : object_map[node->getUniqueId()]; const char *bone_name = is_joint ? bc_get_joint_name(node) : NULL; @@ -1456,11 +1456,11 @@ Object *AnimationImporter::translate_animation_OLD(Main *bmain, COLLADAFW::Node // frames at which to sample std::vector frames; - + find_frames_old(&frames, node, tm_type); - + unsigned int i; - + float irest_dae[4][4]; float rest[4][4], irest[4][4]; @@ -1731,9 +1731,9 @@ void AnimationImporter::evaluate_transform_at_frame(float mat[4][4], COLLADAFW:: } } -static void report_class_type_unsupported(const char *path, +static void report_class_type_unsupported(const char *path, const COLLADAFW::AnimationList::AnimationClass animclass, - const COLLADAFW::Transformation::TransformationType type) + const COLLADAFW::Transformation::TransformationType type) { if (animclass == COLLADAFW::AnimationList::UNKNOWN_CLASS) { fprintf(stderr, "%s: UNKNOWN animation class\n", path); @@ -1828,7 +1828,7 @@ bool AnimationImporter::evaluate_animation(COLLADAFW::Transformation *tm, float fprintf(stderr, "%s: expected 1 curve, got %d\n", path, (int)curves.size()); return false; } - + switch (animclass) { case COLLADAFW::AnimationList::POSITION_X: vec[0] = evaluate_fcurve(curves[0], fra); @@ -2010,7 +2010,7 @@ void AnimationImporter::add_bone_fcurve(Object *ob, COLLADAFW::Node *node, FCurv { const char *bone_name = bc_get_joint_name(node); bAction *act = ob->adt->action; - + /* try to find group */ bActionGroup *grp = BKE_action_group_find_name(act, bone_name); diff --git a/source/blender/collada/AnimationImporter.h b/source/blender/collada/AnimationImporter.h index 0957b1e6e06..f63329158f0 100644 --- a/source/blender/collada/AnimationImporter.h +++ b/source/blender/collada/AnimationImporter.h @@ -19,7 +19,7 @@ * * ***** END GPL LICENSE BLOCK ***** */ - + /** \file AnimationImporter.h * \ingroup collada */ @@ -75,9 +75,9 @@ private: std::map animlist_map; std::vector unused_curves; std::map joint_objects; - + FCurve *create_fcurve(int array_index, const char *rna_path); - + void add_bezt(FCurve *fcu, float frame, float value, eBezTriple_Interpolation ipo=BEZT_IPO_LIN); // create one or several fcurves depending on the number of parameters being animated @@ -89,7 +89,7 @@ private: void add_fcurves_to_object(Main *bmain, Object *ob, std::vector& curves, char *rna_path, int array_index, Animation *animated); - + int typeFlag; std::string import_from_version; @@ -121,7 +121,7 @@ private: MATERIAL_TRANSPARENCY = 1 << 4, MATERIAL_IOR = 1 << 5 }; - + enum AnimationType { INANIMATE = 0, @@ -144,7 +144,7 @@ public: void set_import_from_version(std::string import_from_version); bool write_animation(const COLLADAFW::Animation* anim); - + // called on post-process stage after writeVisualScenes bool write_animation_list(const COLLADAFW::AnimationList* animlist); @@ -163,7 +163,7 @@ public: void apply_matrix_curves(Main *bmain, Object *ob, std::vector& animcurves, COLLADAFW::Node* root, COLLADAFW::Node* node, COLLADAFW::Transformation * tm ); - + void add_bone_animation_sampled(Main *bmain, Object *ob, std::vector& animcurves, COLLADAFW::Node* root, COLLADAFW::Node* node, COLLADAFW::Transformation * tm); void Assign_transform_animations(COLLADAFW::Transformation* transform, @@ -175,7 +175,7 @@ public: void Assign_lens_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, const double aspect, Camera *cam, const char *anim_type, int fov_type); int setAnimType ( const COLLADAFW::Animatable * prop, int type, int addition); - + void modify_fcurve(std::vector* curves, const char *rna_path, int array_index ); void unused_fcurve(std::vector* curves ); // prerequisites: @@ -186,7 +186,7 @@ public: std::map& root_map, COLLADAFW::Transformation::TransformationType tm_type, Object *par_job = NULL); - + void find_frames( std::vector* frames, std::vector* curves ); void find_frames_old( std::vector* frames, COLLADAFW::Node * node, COLLADAFW::Transformation::TransformationType tm_type ); // internal, better make it private diff --git a/source/blender/collada/ArmatureExporter.cpp b/source/blender/collada/ArmatureExporter.cpp index 9afe4662f74..52f7c5627b9 100644 --- a/source/blender/collada/ArmatureExporter.cpp +++ b/source/blender/collada/ArmatureExporter.cpp @@ -117,11 +117,11 @@ bool ArmatureExporter::add_instance_controller(Object *ob) write_bone_URLs(ins, ob_arm, bone); } - InstanceWriter::add_material_bindings(ins.getBindMaterial(), - ob, + InstanceWriter::add_material_bindings(ins.getBindMaterial(), + ob, this->export_settings->active_uv_only, this->export_settings->export_texture_type); - + ins.add(); return true; } @@ -150,7 +150,7 @@ void ArmatureExporter::find_objects_using_armature(Object *ob_arm, std::vectorbase.first; while (base) { Object *ob = base->object; - + if (ob->type == OB_MESH && get_assigned_armature(ob) == ob_arm) { objects.push_back(ob); } @@ -268,7 +268,7 @@ void ArmatureExporter::add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW: if (!has_restmat) { /* Have no restpose matrix stored, try old style <= Blender 2.78 */ - + bc_create_restpose_mat(this->export_settings, bone, bone_rest_mat, bone->arm_mat, true); if (bone->parent) { diff --git a/source/blender/collada/ArmatureImporter.cpp b/source/blender/collada/ArmatureImporter.cpp index 964f1f6b9e4..cfb25f5d117 100644 --- a/source/blender/collada/ArmatureImporter.cpp +++ b/source/blender/collada/ArmatureImporter.cpp @@ -59,7 +59,7 @@ ArmatureImporter::ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, scene(sce), unit_converter(conv), import_settings(import_settings), - empty(NULL), + empty(NULL), mesh_importer(mesh) { } @@ -101,7 +101,7 @@ int ArmatureImporter::create_bone(SkinInfo *skin, COLLADAFW::Node *node, EditBon std::vector::iterator it; it = std::find(finished_joints.begin(), finished_joints.end(), node); if (it != finished_joints.end()) return chain_length; - + EditBone *bone = ED_armature_ebone_add(arm, bc_get_joint_name(node)); totbone++; @@ -139,7 +139,7 @@ int ArmatureImporter::create_bone(SkinInfo *skin, COLLADAFW::Node *node, EditBon if (parent) bone->parent = parent; - float loc[3], size[3], rot[3][3]; + float loc[3], size[3], rot[3][3]; BoneExtensionMap &extended_bones = bone_extension_manager.getExtensionMap(arm); BoneExtended &be = add_bone_extended(bone, node, totchild, layer_labels, extended_bones); int layer = be.get_bone_layers(); @@ -384,7 +384,7 @@ void ArmatureImporter::set_euler_rotmode() COLLADAFW::Node *joint = it->second; std::map::iterator sit; - + for (sit = skin_by_data_uid.begin(); sit != skin_by_data_uid.end(); sit++) { SkinInfo& skin = sit->second; @@ -408,7 +408,7 @@ void ArmatureImporter::set_euler_rotmode() Object *ArmatureImporter::get_empty_for_leaves() { if (empty) return empty; - + empty = bc_add_object(scene, OB_EMPTY, NULL); empty->empty_drawtype = OB_EMPTY_SPHERE; @@ -454,7 +454,7 @@ void ArmatureImporter::create_armature_bones(Main *bmain, std::vector //if there is an armature created for root_joint next root_joint for (ri = root_joints.begin(); ri != root_joints.end(); ri++) { if (get_armature_for_joint(*ri) != NULL) continue; - + Object *ob_arm = joint_parent_map[(*ri)->getUniqueId()]; if (!ob_arm) continue; @@ -570,8 +570,8 @@ Object *ArmatureImporter::create_armature_bones(Main *bmain, SkinInfo& skin) } if (!shared && this->joint_parent_map.size() > 0) { - // All armatures have been created while creating the Node tree. - // The Collada exporter currently does not create a + // All armatures have been created while creating the Node tree. + // The Collada exporter currently does not create a // strict relationship between geometries and armatures // So when we reimport a Blender collada file, then we have // to guess what is meant. @@ -655,12 +655,12 @@ void ArmatureImporter::set_pose(Object *ob_arm, COLLADAFW::Node *root_node, con } else { - + copy_m4_m4(mat, obmat); float invObmat[4][4]; invert_m4_m4(invObmat, ob_arm->obmat); mul_m4_m4m4(pchan->pose_mat, invObmat, mat); - + } //float angle = 0.0f; @@ -756,7 +756,7 @@ void ArmatureImporter::make_armatures(bContext *C, std::vector &object // free memory stolen from SkinControllerData skin.free(); } - + //for bones without skins create_armature_bones(bmain, ob_arms); @@ -806,9 +806,9 @@ bool ArmatureImporter::write_skin_controller_data(const COLLADAFW::SkinControlle // don't forget to call defgroup_unique_name before we copy - // controller data uid -> [armature] -> joint data, + // controller data uid -> [armature] -> joint data, // [mesh object] - // + // SkinInfo skin(unit_converter); skin.borrow_skin_controller_data(data); @@ -866,7 +866,7 @@ void ArmatureImporter::make_shape_keys() //Prereq: all the geometries must be imported and mesh objects must be made Object *source_ob = this->mesh_importer->get_object_by_geom_uid((*mc)->getSource()); - + if (source_ob) { Mesh *source_me = (Mesh *)source_ob->data; @@ -874,7 +874,7 @@ void ArmatureImporter::make_shape_keys() Key *key = source_me->key = BKE_key_add((ID *)source_me); key->type = KEY_RELATIVE; KeyBlock *kb; - + //insert basis key kb = BKE_keyblock_add_ctime(key, "Basis", false); BKE_keyblock_convert_from_mesh(source_me, kb); @@ -885,14 +885,14 @@ void ArmatureImporter::make_shape_keys() //This'll do for now since only mesh morphing is imported Mesh *me = this->mesh_importer->get_mesh_by_geom_uid(morphTargetIds[i]); - + if (me) { me->key = key; std::string morph_name = *this->mesh_importer->get_geometry_name(me->id.name); kb = BKE_keyblock_add_ctime(key, morph_name.c_str(), false); BKE_keyblock_convert_from_mesh(me, kb); - + //apply weights weight = morphWeights.getFloatValues()->getData()[i]; kb->curval = weight; @@ -988,14 +988,14 @@ BoneExtended &ArmatureImporter::add_bone_extended(EditBone *bone, COLLADAFW::Nod has_connect = et->setData("connect", &connect_type); bool has_roll = et->setData("roll", &roll); - + layers = et->setData("layer", layers); if (has_tail && !has_connect) { /* got a bone tail definition but no connect info -> bone is not connected */ has_connect = true; - connect_type = 0; + connect_type = 0; } be->set_bone_layers(layers, layer_labels); diff --git a/source/blender/collada/ArmatureImporter.h b/source/blender/collada/ArmatureImporter.h index fbce14f1b05..87a7ae73a24 100644 --- a/source/blender/collada/ArmatureImporter.h +++ b/source/blender/collada/ArmatureImporter.h @@ -157,16 +157,16 @@ public: bool write_controller(const COLLADAFW::Controller* controller); COLLADAFW::UniqueId *get_geometry_uid(const COLLADAFW::UniqueId& controller_uid); - + Object *get_armature_for_joint(COLLADAFW::Node *node); void get_rna_path_for_joint(COLLADAFW::Node *node, char *joint_path, size_t count); - + // gives a world-space mat bool get_joint_bind_mat(float m[4][4], COLLADAFW::Node *joint); void set_tags_map( TagsMap& tags_map); - + }; #endif diff --git a/source/blender/collada/CameraExporter.cpp b/source/blender/collada/CameraExporter.cpp index 649288c2db4..32bd24f1e0b 100644 --- a/source/blender/collada/CameraExporter.cpp +++ b/source/blender/collada/CameraExporter.cpp @@ -56,9 +56,9 @@ void forEachCameraObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set void CamerasExporter::exportCameras(Scene *sce) { openLibrary(); - + forEachCameraObjectInExportSet(sce, *this, this->export_settings->export_set); - + closeLibrary(); } void CamerasExporter::operator()(Object *ob, Scene *sce) diff --git a/source/blender/collada/ControllerExporter.cpp b/source/blender/collada/ControllerExporter.cpp index 14e8e0323a8..c89e0f1ec62 100644 --- a/source/blender/collada/ControllerExporter.cpp +++ b/source/blender/collada/ControllerExporter.cpp @@ -99,10 +99,10 @@ bool ControllerExporter::add_instance_controller(Object *ob) } InstanceWriter::add_material_bindings(ins.getBindMaterial(), - ob, + ob, this->export_settings->active_uv_only, this->export_settings->export_texture_type); - + ins.add(); return true; } @@ -150,7 +150,7 @@ void ArmatureExporter::find_objects_using_armature(Object *ob_arm, std::vectorbase.first; while (base) { Object *ob = base->object; - + if (ob->type == OB_MESH && get_assigned_armature(ob) == ob_arm) { objects.push_back(ob); } @@ -205,7 +205,7 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm) this->export_settings->export_mesh_type, this->export_settings->apply_modifiers, this->export_settings->triangulate); - + if (!me->dvert) return; std::string controller_name = id_name(ob_arm); @@ -248,7 +248,7 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm) for (j = 0; j < vert->totweight; j++) { int idx = vert->dw[j].def_nr; if (idx >= joint_index_by_def_index.size()) { - // XXX: Maybe better find out where and + // XXX: Maybe better find out where and // why the Out Of Bound indexes get created ? oob_counter += 1; } @@ -316,7 +316,7 @@ void ControllerExporter::export_morph_controller(Object *ob, Key *key) std::string targets_id = add_morph_targets(key, ob); std::string morph_weights_id = add_morph_weights(key, ob); - + COLLADASW::TargetsElement targets(mSW); COLLADASW::InputList &input = targets.getInputList(); @@ -378,7 +378,7 @@ std::string ControllerExporter::add_morph_weights(Key *key, Object *ob) COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList(); param.push_back("MORPH_WEIGHT"); - + source.prepareToAppendValues(); KeyBlock *kb = (KeyBlock *)key->block.first; @@ -398,7 +398,7 @@ void ControllerExporter::add_weight_extras(Key *key) { // can also try the base element and param alternative COLLADASW::BaseExtraTechnique extra; - + KeyBlock * kb = (KeyBlock *)key->block.first; //skip the basis kb = kb->next; @@ -449,7 +449,7 @@ std::string ControllerExporter::add_joints_source(Object *ob_arm, ListBase *defb source.setArrayId(source_id + ARRAY_ID_SUFFIX); source.setAccessorCount(totjoint); source.setAccessorStride(1); - + COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList(); param.push_back("JOINT"); @@ -482,7 +482,7 @@ std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm, ListBas source.setArrayId(source_id + ARRAY_ID_SUFFIX); source.setAccessorCount(totjoint); //BLI_listbase_count(defbase)); source.setAccessorStride(16); - + source.setParameterTypeName(&COLLADASW::CSWC::CSW_VALUE_TYPE_FLOAT4x4); COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList(); param.push_back("TRANSFORM"); @@ -511,7 +511,7 @@ std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm, ListBas float bind_mat[4][4]; /* derived from bone->arm_mat */ bool has_bindmat = bc_get_property_matrix(pchan->bone, "bind_mat", bind_mat); - + if (!has_bindmat) { /* Have no bind matrix stored, try old style <= Blender 2.78 */ @@ -573,7 +573,7 @@ std::string ControllerExporter::add_weights_source(Mesh *me, const std::string& source.setArrayId(source_id + ARRAY_ID_SUFFIX); source.setAccessorCount(weights.size()); source.setAccessorStride(1); - + COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList(); param.push_back("WEIGHT"); diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp index 472bd326205..f1838b9dbb6 100644 --- a/source/blender/collada/DocumentExporter.cpp +++ b/source/blender/collada/DocumentExporter.cpp @@ -62,7 +62,7 @@ #include "COLLADASWInstanceNode.h" #include "COLLADASWBaseInputElement.h" -extern "C" +extern "C" { #include "DNA_scene_types.h" #include "DNA_object_types.h" @@ -258,14 +258,14 @@ int DocumentExporter::exportCurrentScene(bContext *C, const EvaluationContext *e #endif asset.getContributor().mAuthoringTool = version_buf; asset.add(); - + LinkNode *export_set = this->export_settings->export_set; // if (bc_has_object_type(export_set, OB_CAMERA)) { CamerasExporter ce(writer, this->export_settings); ce.exportCameras(sce); } - + // if (bc_has_object_type(export_set, OB_LAMP)) { LightsExporter le(writer, this->export_settings); @@ -275,11 +275,11 @@ int DocumentExporter::exportCurrentScene(bContext *C, const EvaluationContext *e // ImagesExporter ie(writer, this->export_settings); ie.exportImages(sce); - + // EffectsExporter ee(writer, this->export_settings); ee.exportEffects(sce); - + // MaterialsExporter me(writer, this->export_settings); me.exportMaterials(sce); @@ -293,7 +293,7 @@ int DocumentExporter::exportCurrentScene(bContext *C, const EvaluationContext *e // ArmatureExporter arm_exporter(writer, this->export_settings); ControllerExporter controller_exporter(writer, this->export_settings); - if (bc_has_object_type(export_set, OB_ARMATURE) || this->export_settings->include_shapekeys) + if (bc_has_object_type(export_set, OB_ARMATURE) || this->export_settings->include_shapekeys) { controller_exporter.export_controllers(sce); } @@ -308,13 +308,13 @@ int DocumentExporter::exportCurrentScene(bContext *C, const EvaluationContext *e ae.exportAnimations(sce); } se.exportScene(C, sce); - + // std::string scene_name(translate_id(id_name(sce))); COLLADASW::Scene scene(writer, COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, scene_name)); scene.add(); - + // close writer->endDocument(); delete writer; diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 03fcc2e5037..4173a024552 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -126,7 +126,7 @@ bool DocumentImporter::import() COLLADASaxFWL::Loader loader(&errorHandler); COLLADAFW::Root root(&loader, this); ExtraHandler *ehandler = new ExtraHandler(this, &(this->anim_importer)); - + loader.registerExtraDataCallbackHandler(ehandler); // deselect all to select new objects @@ -139,19 +139,19 @@ bool DocumentImporter::import() delete ehandler; return false; } - + if (errorHandler.hasError()) { delete ehandler; return false; } - + /** TODO set up scene graph and such here */ - + mImportStage = Controller; - + COLLADASaxFWL::Loader loader2; COLLADAFW::Root root2(&loader2, this); - + if (!root2.loadDocument(encodedFilename)) { fprintf(stderr, "COLLADAFW::Root::loadDocument() returned false on 2nd pass\n"); delete ehandler; @@ -194,7 +194,7 @@ void DocumentImporter::finish() for (sit = vscenes.begin(); sit != vscenes.end(); sit++) { PointerRNA sceneptr, unit_settings; PropertyRNA *system, *scale; - + // for scene unit settings: system, scale_length RNA_id_pointer_create(&sce->id, &sceneptr); @@ -203,7 +203,7 @@ void DocumentImporter::finish() scale = RNA_struct_find_property(&unit_settings, "scale_length"); if (this->import_settings->import_units) { - + switch (unit_converter.isMetricSystem()) { case UnitConverter::Metric: RNA_property_enum_set(&unit_settings, system, USER_UNIT_METRIC); @@ -276,7 +276,7 @@ void DocumentImporter::finish() DAG_relations_tag_update(bmain); } - + bc_match_scale(objects_to_scale, unit_converter, !this->import_settings->import_units); delete objects_to_scale; @@ -477,7 +477,7 @@ void DocumentImporter::create_constraints(ExtraTags *et, Object *ob) short type = 0; et->setData("type", &type); BKE_constraint_add_for_object(ob, "Test_con", type); - + } } @@ -639,7 +639,7 @@ std::vector *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA root_objects->push_back(ob); } } - + // XXX: if there're multiple instances, only one is stored if (!ob) { @@ -705,7 +705,7 @@ bool DocumentImporter::writeVisualScene(const COLLADAFW::VisualScene *visualScen { if (mImportStage != General) return true; - + // this method called on post process after writeGeometry, writeMaterial, etc. // for each in : @@ -717,18 +717,18 @@ bool DocumentImporter::writeVisualScene(const COLLADAFW::VisualScene *visualScen // we link Objects with Meshes here vscenes.push_back(visualScene); - + return true; } -/** When this method is called, the writer must handle all nodes contained in the +/** When this method is called, the writer must handle all nodes contained in the * library nodes. * \return The writer should return true, if writing succeeded, false otherwise.*/ bool DocumentImporter::writeLibraryNodes(const COLLADAFW::LibraryNodes *libraryNodes) { if (mImportStage != General) return true; - + Scene *sce = CTX_data_scene(mContext); const COLLADAFW::NodePointerArray& nodes = libraryNodes->getNodes(); @@ -748,7 +748,7 @@ bool DocumentImporter::writeGeometry(const COLLADAFW::Geometry *geom) { if (mImportStage != General) return true; - + return mesh_importer.write_geometry(geom); } @@ -758,13 +758,13 @@ bool DocumentImporter::writeMaterial(const COLLADAFW::Material *cmat) { if (mImportStage != General) return true; - + const std::string& str_mat_id = cmat->getName().size() ? cmat->getName() : cmat->getOriginalId(); Material *ma = BKE_material_add(G.main, (char *)str_mat_id.c_str()); - + this->uid_effect_map[cmat->getInstantiatedEffect()] = ma; this->uid_material_map[cmat->getUniqueId()] = ma; - + return true; } @@ -774,29 +774,29 @@ MTex *DocumentImporter::create_texture(COLLADAFW::EffectCommon *ef, COLLADAFW::T { COLLADAFW::SamplerPointerArray& samp_array = ef->getSamplerPointerArray(); COLLADAFW::Sampler *sampler = samp_array[ctex.getSamplerId()]; - + const COLLADAFW::UniqueId& ima_uid = sampler->getSourceImage(); - + if (uid_image_map.find(ima_uid) == uid_image_map.end()) { fprintf(stderr, "Couldn't find an image by UID.\n"); return NULL; } - + ma->mtex[i] = BKE_texture_mtex_add(); ma->mtex[i]->texco = TEXCO_UV; ma->mtex[i]->tex = BKE_texture_add(G.main, "Texture"); ma->mtex[i]->tex->type = TEX_IMAGE; ma->mtex[i]->tex->ima = uid_image_map[ima_uid]; - + texindex_texarray_map[ctex.getTextureMapId()].push_back(ma->mtex[i]); - + return ma->mtex[i]; } void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Material *ma) { COLLADAFW::EffectCommon::ShaderType shader = ef->getShaderType(); - + // blinn if (shader == COLLADAFW::EffectCommon::SHADER_BLINN) { ma->spec_shader = MA_SPEC_BLINN; @@ -820,12 +820,12 @@ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Materia ma->ray_mirror = ef->getReflectivity().getFloatValue(); // index of refraction ma->ang = ef->getIndexOfRefraction().getFloatValue(); - + int i = 0; COLLADAFW::Color col; MTex *mtex = NULL; TexIndexTextureArrayMap texindex_texarray_map; - + // DIFFUSE // color if (ef->getDiffuse().isColor()) { @@ -840,7 +840,7 @@ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Materia } // texture else if (ef->getDiffuse().isTexture()) { - COLLADAFW::Texture ctex = ef->getDiffuse().getTexture(); + COLLADAFW::Texture ctex = ef->getDiffuse().getTexture(); mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); if (mtex != NULL) { mtex->mapto = MAP_COL; @@ -858,10 +858,10 @@ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Materia } // texture else if (ef->getAmbient().isTexture()) { - COLLADAFW::Texture ctex = ef->getAmbient().getTexture(); + COLLADAFW::Texture ctex = ef->getAmbient().getTexture(); mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); if (mtex != NULL) { - mtex->mapto = MAP_AMB; + mtex->mapto = MAP_AMB; i++; } } @@ -875,10 +875,10 @@ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Materia } // texture else if (ef->getSpecular().isTexture()) { - COLLADAFW::Texture ctex = ef->getSpecular().getTexture(); + COLLADAFW::Texture ctex = ef->getSpecular().getTexture(); mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); if (mtex != NULL) { - mtex->mapto = MAP_SPEC; + mtex->mapto = MAP_SPEC; i++; } } @@ -892,10 +892,10 @@ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Materia } // texture else if (ef->getReflective().isTexture()) { - COLLADAFW::Texture ctex = ef->getReflective().getTexture(); + COLLADAFW::Texture ctex = ef->getReflective().getTexture(); mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); if (mtex != NULL) { - mtex->mapto = MAP_REF; + mtex->mapto = MAP_REF; i++; } } @@ -908,10 +908,10 @@ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Materia } // texture else if (ef->getEmission().isTexture()) { - COLLADAFW::Texture ctex = ef->getEmission().getTexture(); + COLLADAFW::Texture ctex = ef->getEmission().getTexture(); mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); if (mtex != NULL) { - mtex->mapto = MAP_EMIT; + mtex->mapto = MAP_EMIT; i++; } } @@ -951,14 +951,14 @@ bool DocumentImporter::writeEffect(const COLLADAFW::Effect *effect) { if (mImportStage != General) return true; - + const COLLADAFW::UniqueId& uid = effect->getUniqueId(); - + if (uid_effect_map.find(uid) == uid_effect_map.end()) { fprintf(stderr, "Couldn't find a material by UID.\n"); return true; } - + Material *ma = uid_effect_map[uid]; std::map::iterator iter; for (iter = uid_material_map.begin(); iter != uid_material_map.end(); iter++) { @@ -977,7 +977,7 @@ bool DocumentImporter::writeEffect(const COLLADAFW::Effect *effect) COLLADAFW::EffectCommon *ef = common_efs[0]; write_profile_COMMON(ef, ma); this->FW_object_map[effect->getUniqueId()] = effect; - + return true; } @@ -988,16 +988,16 @@ bool DocumentImporter::writeCamera(const COLLADAFW::Camera *camera) { if (mImportStage != General) return true; - + Camera *cam = NULL; std::string cam_id, cam_name; - + ExtraTags *et=getExtraTags(camera->getUniqueId()); cam_id = camera->getOriginalId(); cam_name = camera->getName(); if (cam_name.size()) cam = (Camera *)BKE_camera_add(G.main, (char *)cam_name.c_str()); else cam = (Camera *)BKE_camera_add(G.main, (char *)cam_id.c_str()); - + if (!cam) { fprintf(stderr, "Cannot create camera.\n"); return true; @@ -1010,7 +1010,7 @@ bool DocumentImporter::writeCamera(const COLLADAFW::Camera *camera) } cam->clipsta = camera->getNearClippingPlane().getValue(); cam->clipend = camera->getFarClippingPlane().getValue(); - + COLLADAFW::Camera::CameraType type = camera->getCameraType(); switch (type) { case COLLADAFW::Camera::ORTHOGRAPHIC: @@ -1030,7 +1030,7 @@ bool DocumentImporter::writeCamera(const COLLADAFW::Camera *camera) } break; } - + switch (camera->getDescriptionType()) { case COLLADAFW::Camera::ASPECTRATIO_AND_Y: { @@ -1100,7 +1100,7 @@ bool DocumentImporter::writeCamera(const COLLADAFW::Camera *camera) // read nothing, use blender defaults. break; } - + this->uid_camera_map[camera->getUniqueId()] = cam; this->FW_object_map[camera->getUniqueId()] = camera; // XXX import camera options @@ -1113,7 +1113,7 @@ bool DocumentImporter::writeImage(const COLLADAFW::Image *image) { if (mImportStage != General) return true; - + const std::string& imagepath = image->getImageURI().toNativePath(); char dir[FILE_MAX]; @@ -1124,7 +1124,7 @@ bool DocumentImporter::writeImage(const COLLADAFW::Image *image) BLI_join_dirfile(absolute_path, sizeof(absolute_path), dir, imagepath.c_str()); if (BLI_exists(absolute_path)) { workpath = absolute_path; - } + } else { // Maybe imagepath was already absolute ? if (!BLI_exists(imagepath.c_str())) { @@ -1140,7 +1140,7 @@ bool DocumentImporter::writeImage(const COLLADAFW::Image *image) return true; } this->uid_image_map[image->getUniqueId()] = ima; - + return true; } @@ -1261,7 +1261,7 @@ bool DocumentImporter::writeLight(const COLLADAFW::Light *light) // assuming point light (const att = 1.0); att1 = 1.0f; } - + d *= (1.0f / unit_converter.getLinearMeter()); lamp->energy = e; @@ -1324,7 +1324,7 @@ bool DocumentImporter::writeAnimation(const COLLADAFW::Animation *anim) { if (mImportStage != General) return true; - + // return true; return anim_importer.write_animation(anim); } @@ -1334,7 +1334,7 @@ bool DocumentImporter::writeAnimationList(const COLLADAFW::AnimationList *animat { if (mImportStage != General) return true; - + // return true; return anim_importer.write_animation_list(animationList); } @@ -1351,7 +1351,7 @@ bool DocumentImporter::writeController(const COLLADAFW::Controller *controller) { if (mImportStage != General) return true; - + return armature_importer.write_controller(controller); } diff --git a/source/blender/collada/DocumentImporter.h b/source/blender/collada/DocumentImporter.h index 62f76dbc022..c5bc6907867 100644 --- a/source/blender/collada/DocumentImporter.h +++ b/source/blender/collada/DocumentImporter.h @@ -79,7 +79,7 @@ public: std::vector *write_node(COLLADAFW::Node*, COLLADAFW::Node*, Scene*, Object*, bool); MTex* create_texture(COLLADAFW::EffectCommon*, COLLADAFW::Texture&, Material*, int, TexIndexTextureArrayMap&); void write_profile_COMMON(COLLADAFW::EffectCommon*, Material*); - + void translate_anim_recursive(COLLADAFW::Node*, COLLADAFW::Node*, Object*); /** @@ -149,7 +149,7 @@ private: ArmatureImporter armature_importer; MeshImporter mesh_importer; AnimationImporter anim_importer; - + /** TagsMap typedef for uid_tags_map. */ typedef std::map TagsMap; /** Tags map of unique id as a string and ExtraTags instance. */ @@ -165,7 +165,7 @@ private: std::map node_map; std::vector vscenes; std::vector libnode_ob; - + std::map root_map; // find root joint by child joint uid, for bone tree evaluation during resampling std::map FW_object_map; diff --git a/source/blender/collada/EffectExporter.cpp b/source/blender/collada/EffectExporter.cpp index a4764cab67e..d33ce725e58 100644 --- a/source/blender/collada/EffectExporter.cpp +++ b/source/blender/collada/EffectExporter.cpp @@ -55,7 +55,7 @@ EffectsExporter::EffectsExporter(COLLADASW::StreamWriter *sw, const ExportSettin bool EffectsExporter::hasEffects(Scene *sce) { Base *base = (Base *)sce->base.first; - + while (base) { Object *ob = base->object; int a; @@ -75,7 +75,7 @@ bool EffectsExporter::hasEffects(Scene *sce) void EffectsExporter::exportEffects(Scene *sce) { this->scene = sce; - + if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT) { if (hasEffects(sce)) { MaterialFunctor mf; @@ -152,7 +152,7 @@ void EffectsExporter::writePhong(COLLADASW::EffectProfile &ep, Material *ma) void EffectsExporter::writeTextures( COLLADASW::EffectProfile &ep, std::string &key, - COLLADASW::Sampler *sampler, + COLLADASW::Sampler *sampler, MTex *t, Image *ima, std::string &uvname ) { @@ -184,7 +184,7 @@ void EffectsExporter::writeTextures( ep.setTransparent(createTexture(ima, uvname, sampler)); } // extension: - // Normal map --> Must be stored with tag as different technique, + // Normal map --> Must be stored with tag as different technique, // since COLLADA doesn't support normal maps, even in current COLLADA 1.5. if (t->mapto & MAP_NORM) { COLLADASW::Texture texture(key); @@ -205,7 +205,7 @@ void EffectsExporter::operator()(Material *ma, Object *ob) createTextureIndices(ma, tex_indices); openEffect(translate_id(id_name(ma)) + "-effect"); - + COLLADASW::EffectProfile ep(mSW); ep.setProfileType(COLLADASW::EffectProfile::COMMON); ep.openProfile(); @@ -229,7 +229,7 @@ void EffectsExporter::operator()(Material *ma, Object *ob) writePhong(ep, ma); } } - + // index of refraction if (ma->mode & MA_RAYTRANSP) { ep.setIndexOfRefraction(ma->ang, false, "index_of_refraction"); @@ -290,7 +290,7 @@ void EffectsExporter::operator()(Material *ma, Object *ob) //COLLADASW::Surface surfaces[MAX_MTEX]; //void *samp_surf[MAX_MTEX][2]; void *samp_surf[MAX_MTEX]; - + // image to index to samp_surf map // samp_surf[index] stores 2 pointers, sampler and surface std::map im_samp_map; @@ -299,10 +299,10 @@ void EffectsExporter::operator()(Material *ma, Object *ob) for (a = 0, b = 0; a < tex_indices.size(); a++) { MTex *t = ma->mtex[tex_indices[a]]; Image *ima = t->tex->ima; - + // Image not set for texture if (!ima) continue; - + std::string key(id_name(ima)); key = translate_id(key); @@ -317,7 +317,7 @@ void EffectsExporter::operator()(Material *ma, Object *ob) // COLLADASW::NewParamSurface surface(mSW); // surface->setParamType(COLLADASW::CSW_SURFACE_TYPE_2D); - + // COLLADASW::Sampler sampler(COLLADASW::Sampler::SAMPLER_TYPE_2D, key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX, @@ -326,11 +326,11 @@ void EffectsExporter::operator()(Material *ma, Object *ob) // copy values to arrays since they will live longer samplers[a] = sampler; //surfaces[a] = surface; - + // store pointers so they can be used later when we create s samp_surf[b] = &samplers[a]; //samp_surf[b][1] = &surfaces[a]; - + im_samp_map[key] = b; b++; } @@ -381,12 +381,12 @@ COLLADASW::ColorOrTexture EffectsExporter::createTexture(Image *ima, COLLADASW::Sampler *sampler /*COLLADASW::Surface *surface*/) { - + COLLADASW::Texture texture(translate_id(id_name(ima))); texture.setTexcoord(uv_layer_name); //texture.setSurface(*surface); texture.setSampler(*sampler); - + COLLADASW::ColorOrTexture cot(texture); return cot; } @@ -398,7 +398,7 @@ COLLADASW::ColorOrTexture EffectsExporter::getcol(float r, float g, float b, flo return cot; } -//returns the array of mtex indices which have image +//returns the array of mtex indices which have image //need this for exporting textures void EffectsExporter::createTextureIndices(Material *ma, std::vector &indices) { diff --git a/source/blender/collada/EffectExporter.h b/source/blender/collada/EffectExporter.h index 7d45a085777..278e1ebcfce 100644 --- a/source/blender/collada/EffectExporter.h +++ b/source/blender/collada/EffectExporter.h @@ -49,30 +49,30 @@ public: EffectsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings); void exportEffects(Scene *sce); void operator()(Material *ma, Object *ob); - + COLLADASW::ColorOrTexture createTexture(Image *ima, std::string& uv_layer_name, COLLADASW::Sampler *sampler /*COLLADASW::Surface *surface*/); - + COLLADASW::ColorOrTexture getcol(float r, float g, float b, float a); private: /** Fills the array of mtex indices which have image. Used for exporting images. */ void createTextureIndices(Material *ma, std::vector &indices); - + void writeBlinn(COLLADASW::EffectProfile &ep, Material *ma); void writeLambert(COLLADASW::EffectProfile &ep, Material *ma); void writePhong(COLLADASW::EffectProfile &ep, Material *ma); void writeTextures(COLLADASW::EffectProfile &ep, std::string &key, - COLLADASW::Sampler *sampler, + COLLADASW::Sampler *sampler, MTex *t, Image *ima, std::string &uvname ); bool hasEffects(Scene *sce); - + const ExportSettings *export_settings; - + Scene *scene; }; diff --git a/source/blender/collada/ErrorHandler.cpp b/source/blender/collada/ErrorHandler.cpp index 7e18328f000..26674445d98 100644 --- a/source/blender/collada/ErrorHandler.cpp +++ b/source/blender/collada/ErrorHandler.cpp @@ -53,7 +53,7 @@ bool ErrorHandler::handleError(const COLLADASaxFWL::IError *error) See https://github.com/KhronosGroup/OpenCOLLADA/issues/442 */ bool isWarning = false; - + if (error->getErrorClass() == COLLADASaxFWL::IError::ERROR_SAXPARSER) { COLLADASaxFWL::SaxParserError *saxParserError = (COLLADASaxFWL::SaxParserError *) error; const GeneratedSaxParser::ParserError& parserError = saxParserError->getError(); diff --git a/source/blender/collada/ExtraHandler.cpp b/source/blender/collada/ExtraHandler.cpp index bef7accd9f7..5d704bc9abc 100644 --- a/source/blender/collada/ExtraHandler.cpp +++ b/source/blender/collada/ExtraHandler.cpp @@ -54,9 +54,9 @@ bool ExtraHandler::elementEnd(const char *elementName) bool ExtraHandler::textData(const char *text, size_t textLength) { char buf[1024]; - + if (currentElement.length() == 0 || currentExtraTags == 0) return false; - + BLI_strncpy(buf, text, textLength + 1); currentExtraTags->addTag(currentElement, std::string(buf)); return true; diff --git a/source/blender/collada/ExtraHandler.h b/source/blender/collada/ExtraHandler.h index f380c3d6871..4dda862b3cc 100644 --- a/source/blender/collada/ExtraHandler.h +++ b/source/blender/collada/ExtraHandler.h @@ -50,31 +50,31 @@ public: /** Handle the beginning of an element. */ bool elementBegin( const char* elementName, const char** attributes); - + /** Handle the end of an element. */ bool elementEnd(const char* elementName ); - + /** Receive the data in text format. */ bool textData(const char* text, size_t textLength); /** Method to ask, if the current callback handler want to read the data of the given extra element. */ - bool parseElement ( - const char* profileName, - const unsigned long& elementHash, + bool parseElement ( + const char* profileName, + const unsigned long& elementHash, const COLLADAFW::UniqueId& uniqueId, COLLADAFW::Object* object); /** For backwards compatibility with older OpenCollada, new version added object parameter */ - bool parseElement ( - const char* profileName, - const unsigned long& elementHash, + bool parseElement ( + const char* profileName, + const unsigned long& elementHash, const COLLADAFW::UniqueId& uniqueId); private: /** Disable default copy constructor. */ ExtraHandler(const ExtraHandler& pre); /** Disable default assignment operator. */ const ExtraHandler& operator= ( const ExtraHandler& pre ); - + /** Handle to DocumentImporter for interface to extra element data saving. */ DocumentImporter* dimp; AnimationImporter* aimp; diff --git a/source/blender/collada/ExtraTags.cpp b/source/blender/collada/ExtraTags.cpp index ea225d8a4ae..fd249884c3f 100644 --- a/source/blender/collada/ExtraTags.cpp +++ b/source/blender/collada/ExtraTags.cpp @@ -50,7 +50,7 @@ bool ExtraTags::isProfile(std::string profile) bool ExtraTags::addTag(std::string tag, std::string data) { tags[tag] = data; - + return true; } diff --git a/source/blender/collada/ExtraTags.h b/source/blender/collada/ExtraTags.h index ad272dcba65..84857622ee8 100644 --- a/source/blender/collada/ExtraTags.h +++ b/source/blender/collada/ExtraTags.h @@ -41,35 +41,35 @@ public: /** Handle the beginning of an element. */ bool addTag(std::string tag, std::string data); - + /** Set given short pointer to value of tag, if it exists. */ bool setData(std::string tag, short *data); - + /** Set given int pointer to value of tag, if it exists. */ bool setData(std::string tag, int *data); - + /** Set given float pointer to value of tag, if it exists. */ bool setData(std::string tag, float *data); - + /** Set given char pointer to value of tag, if it exists. */ bool setData(std::string tag, char *data); std::string setData(std::string tag, std::string &data); /** Return true if the extra tags is for specified profile. */ bool isProfile(std::string profile); - + private: /** Disable default copy constructor. */ ExtraTags(const ExtraTags& pre); /** Disable default assignment operator. */ const ExtraTags& operator= ( const ExtraTags& pre ); - + /** The profile for which the tags are. */ std::string profile; - + /** Map of tag and text pairs. */ std::map tags; - + /** Get text data for tag as an int. */ int asInt(std::string tag, bool *ok); /** Get text data for tag as a float. */ diff --git a/source/blender/collada/GeometryExporter.cpp b/source/blender/collada/GeometryExporter.cpp index f09307c1891..4b693332715 100644 --- a/source/blender/collada/GeometryExporter.cpp +++ b/source/blender/collada/GeometryExporter.cpp @@ -70,14 +70,14 @@ void GeometryExporter::exportGeom(Scene *sce) } void GeometryExporter::operator()(Object *ob) -{ +{ // XXX don't use DerivedMesh, Mesh instead? -#if 0 +#if 0 DerivedMesh *dm = mesh_get_derived_final(mScene, ob, CD_MASK_BAREMESH); #endif bool use_instantiation = this->export_settings->use_object_instantiation; - Mesh *me = bc_get_mesh_copy( mScene, + Mesh *me = bc_get_mesh_copy( mScene, ob, this->export_settings->export_mesh_type, this->export_settings->apply_modifiers, @@ -88,7 +88,7 @@ void GeometryExporter::operator()(Object *ob) std::vector norind; // Skip if linked geometry was already exported from another reference - if (use_instantiation && + if (use_instantiation && exportedGeometry.find(geom_id) != exportedGeometry.end()) { return; @@ -104,15 +104,15 @@ void GeometryExporter::operator()(Object *ob) // openMesh(geoId, geoName, meshId) openMesh(geom_id, geom_name); - + // writes for vertex coords createVertsSource(geom_id, me); - + // writes for normal coords createNormalsSource(geom_id, me, nor); bool has_uvs = (bool)CustomData_has_layer(&me->fdata, CD_MTFACE); - + // writes for uv coords if mesh has uv coords if (has_uvs) { createTexcoordsSource(geom_id, me); @@ -153,9 +153,9 @@ void GeometryExporter::operator()(Object *ob) createPolylists(uv_image_set, has_uvs, has_color, ob, me, geom_id, norind); } } - + closeMesh(); - + if (me->flag & ME_TWOSIDED) { mSW->appendTextBlock("1"); } @@ -184,7 +184,7 @@ void GeometryExporter::export_key_mesh(Object *ob, Mesh *me, KeyBlock *kb) std::string geom_id = get_geometry_id(ob, false) + "_morph_" + translate_id(kb->name); std::vector nor; std::vector norind; - + if (exportedGeometry.find(geom_id) != exportedGeometry.end()) { return; @@ -200,15 +200,15 @@ void GeometryExporter::export_key_mesh(Object *ob, Mesh *me, KeyBlock *kb) // openMesh(geoId, geoName, meshId) openMesh(geom_id, geom_name); - + // writes for vertex coords createVertsSource(geom_id, me); - + // writes for normal coords createNormalsSource(geom_id, me, nor); bool has_uvs = (bool)CustomData_has_layer(&me->fdata, CD_MTFACE); - + // writes for uv coords if mesh has uv coords if (has_uvs) { createTexcoordsSource(geom_id, me); @@ -229,7 +229,7 @@ void GeometryExporter::export_key_mesh(Object *ob, Mesh *me, KeyBlock *kb) //createLooseEdgeList(ob, me, geom_id, norind); - // XXX slow + // XXX slow if (ob->totcol && this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT) { for (int a = 0; a < ob->totcol; a++) { createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind); @@ -240,9 +240,9 @@ void GeometryExporter::export_key_mesh(Object *ob, Mesh *me, KeyBlock *kb) std::set uv_images = bc_getUVImages(ob, all_uv_layers); createPolylists(uv_images, has_uvs, has_color, ob, me, geom_id, norind); } - + closeMesh(); - + if (me->flag & ME_TWOSIDED) { mSW->appendTextBlock("1"); } @@ -261,9 +261,9 @@ void GeometryExporter::createLooseEdgeList(Object *ob, std::vector edge_list; int index; - // Find all loose edges in Mesh + // Find all loose edges in Mesh // and save vertex indices in edge_list - for (index = 0; index < totedges; index++) + for (index = 0; index < totedges; index++) { MEdge *edge = &medges[index]; @@ -284,14 +284,14 @@ void GeometryExporter::createLooseEdgeList(Object *ob, COLLADASW::InputList &til = lines.getInputList(); - - // creates in for vertices + + // creates in for vertices COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX), 0); til.push_back(input1); lines.prepareToAppendValues(); - for (index = 0; index < edges_in_linelist; index++) + for (index = 0; index < edges_in_linelist; index++) { lines.appendValues(edge_list[2 * index + 1]); lines.appendValues(edge_list[2 * index]); @@ -366,7 +366,7 @@ void GeometryExporter::createPolylist(short material_index, // count faces with this material for (i = 0; i < totpolys; i++) { MPoly *p = &mpolys[i]; - + if (p->mat_nr == material_index) { faces_in_polylist++; vcount_list.push_back(p->totloop); @@ -381,14 +381,14 @@ void GeometryExporter::createPolylist(short material_index, fprintf(stderr, "%s: material with index %d is not used.\n", id_name(ob).c_str(), material_index); return; } - + Material *ma = ob->totcol ? give_current_material(ob, material_index + 1) : NULL; COLLADASW::PrimitivesBase *facelist = getFacelist(is_triangulated, mSW); - + // sets count attribute in facelist->setCount(faces_in_polylist); - + // sets material name if (ma) { std::string material_id = get_material_id(ma); @@ -398,22 +398,22 @@ void GeometryExporter::createPolylist(short material_index, } COLLADASW::InputList &til = facelist->getInputList(); - - // creates in for vertices + + // creates in for vertices COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX), 0); - + // creates in for normals COLLADASW::Input input2(COLLADASW::InputSemantic::NORMAL, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL), 1); - + til.push_back(input1); til.push_back(input2); - + // if mesh has uv coords writes for TEXCOORD int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE); int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE)-1; for (i = 0; i < num_layers; i++) { if (!this->export_settings->active_uv_only || i == active_uv_index) { - + std::string uv_name(bc_get_uvlayer_name(me, i)); std::string effective_id = geom_id; // (uv_name == "") ? geom_id : uv_name; std::string layer_id = makeTexcoordSourceId( @@ -421,7 +421,7 @@ void GeometryExporter::createPolylist(short material_index, i, this->export_settings->active_uv_only); /* Note: the third parameter denotes the offset of TEXCOORD in polylist elements - For now this is always 2 (This may change sometime/maybe) + For now this is always 2 (This may change sometime/maybe) */ COLLADASW::Input input3(COLLADASW::InputSemantic::TEXCOORD, makeUrl(layer_id), @@ -447,8 +447,8 @@ void GeometryExporter::createPolylist(short material_index, map_index++; } } - - + + // performs the actual writing prepareToAppendValues(is_triangulated, facelist, vcount_list); @@ -504,7 +504,7 @@ void GeometryExporter::createPolylists(std::set uv_images, norind); } - /* We msut add an additional collector for the case when + /* We msut add an additional collector for the case when * some parts of the object are not textured at all. * The next call creates a polylist for all untextured polygons */ @@ -580,7 +580,7 @@ void GeometryExporter::createPolylist(std::string imageid, } COLLADASW::InputList &til = facelist->getInputList(); - // creates in for vertices + // creates in for vertices COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX), 0); // creates in for normals @@ -670,7 +670,7 @@ void GeometryExporter::createVertsSource(std::string geom_id, Mesh *me) #endif int totverts = me->totvert; MVert *verts = me->mvert; - + COLLADASW::FloatSourceF source(mSW); source.setId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::POSITION)); source.setArrayId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::POSITION) + @@ -690,7 +690,7 @@ void GeometryExporter::createVertsSource(std::string geom_id, Mesh *me) for (i = 0; i < totverts; i++) { source.appendValues(verts[i].co[0], verts[i].co[1], verts[i].co[2]); } - + source.finish(); } @@ -742,7 +742,7 @@ void GeometryExporter::createVertexColorSource(std::string geom_id, Mesh *me) ); } } - + source.finish(); } } @@ -777,26 +777,26 @@ void GeometryExporter::createTexcoordsSource(std::string geom_id, Mesh *me) int layer_index = CustomData_get_layer_index_n(&me->ldata, CD_MLOOPUV, a); if (!this->export_settings->active_uv_only || layer_index == active_uv_index) { MLoopUV *mloops = (MLoopUV *)CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, a); - + COLLADASW::FloatSourceF source(mSW); std::string active_uv_name(bc_get_active_uvlayer_name(me)); std::string effective_id = geom_id; // (active_uv_name == "") ? geom_id : active_uv_name; std::string layer_id = makeTexcoordSourceId( - effective_id, - a, + effective_id, + a, this->export_settings->active_uv_only ); source.setId(layer_id); source.setArrayId(layer_id + ARRAY_ID_SUFFIX); - + source.setAccessorCount(totuv); source.setAccessorStride(2); COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList(); param.push_back("S"); param.push_back("T"); - + source.prepareToAppendValues(); - + for (int index = 0; index < totpoly; index++) { MPoly *mpoly = mpolys+index; MLoopUV *mloop = mloops+mpoly->loopstart; @@ -805,7 +805,7 @@ void GeometryExporter::createTexcoordsSource(std::string geom_id, Mesh *me) mloop[j].uv[1]); } } - + source.finish(); } } @@ -835,7 +835,7 @@ void GeometryExporter::createNormalsSource(std::string geom_id, Mesh *me, std::v param.push_back("X"); param.push_back("Y"); param.push_back("Z"); - + source.prepareToAppendValues(); std::vector::iterator it; @@ -920,10 +920,10 @@ std::string GeometryExporter::getIdBySemantics(std::string geom_id, COLLADASW::I COLLADASW::URI GeometryExporter::getUrlBySemantics(std::string geom_id, COLLADASW::InputSemantic::Semantics type, std::string other_suffix) { - + std::string id(getIdBySemantics(geom_id, type, other_suffix)); return COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, id); - + } COLLADASW::URI GeometryExporter::makeUrl(std::string id) diff --git a/source/blender/collada/GeometryExporter.h b/source/blender/collada/GeometryExporter.h index 890304f4568..8c536721e4b 100644 --- a/source/blender/collada/GeometryExporter.h +++ b/source/blender/collada/GeometryExporter.h @@ -127,7 +127,7 @@ public: void createNormalsSource(std::string geom_id, Mesh *me, std::vector& nor); void create_normals(std::vector &nor, std::vector &ind, Mesh *me); - + std::string getIdBySemantics(std::string geom_id, COLLADASW::InputSemantic::Semantics type, std::string other_suffix = ""); std::string makeVertexColorSourceId(std::string& geom_id, char *layer_name); @@ -136,10 +136,10 @@ public: COLLADASW::URI makeUrl(std::string id); void export_key_mesh(Object *ob, Mesh *me, KeyBlock *kb); - + private: std::set exportedGeometry; - + const ExportSettings *export_settings; Mesh * get_mesh(Scene *sce, Object *ob, int apply_modifiers); diff --git a/source/blender/collada/ImageExporter.cpp b/source/blender/collada/ImageExporter.cpp index a3b710abc66..87f1197e3af 100644 --- a/source/blender/collada/ImageExporter.cpp +++ b/source/blender/collada/ImageExporter.cpp @@ -34,7 +34,7 @@ extern "C" { #include "DNA_image_types.h" #include "DNA_meshdata_types.h" -#include "BKE_customdata.h" +#include "BKE_customdata.h" #include "BKE_global.h" #include "BKE_image.h" #include "BKE_main.h" @@ -53,7 +53,7 @@ ImagesExporter::ImagesExporter(COLLADASW::StreamWriter *sw, const ExportSettings { } -void ImagesExporter::export_UV_Image(Image *image, bool use_copies) +void ImagesExporter::export_UV_Image(Image *image, bool use_copies) { std::string id(id_name(image)); std::string translated_id(translate_id(id)); @@ -117,7 +117,7 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies) BLI_cleanup_path(NULL, source_path); if (use_copies) { - + // This image is already located on the file system. // But we want to create copies here. // To move images into the same export directory. @@ -144,7 +144,7 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies) } /* set name also to mNameNC. This helps other viewers import files exported from Blender better */ - COLLADASW::Image img(COLLADABU::URI(COLLADABU::URI::nativePathToUri(export_path)), translated_id, translated_id); + COLLADASW::Image img(COLLADABU::URI(COLLADABU::URI::nativePathToUri(export_path)), translated_id, translated_id); img.add(mSW); fprintf(stdout, "Collada export: Added image: %s\n", export_file); mImages.push_back(translated_id); @@ -200,7 +200,7 @@ void ImagesExporter::export_UV_Images() bool ImagesExporter::hasImages(Scene *sce) { LinkNode *node; - + for (node = this->export_settings->export_set; node; node = node->next) { Object *ob = (Object *)node->link; diff --git a/source/blender/collada/ImageExporter.h b/source/blender/collada/ImageExporter.h index 0eaebdd5cdd..524260891ae 100644 --- a/source/blender/collada/ImageExporter.h +++ b/source/blender/collada/ImageExporter.h @@ -45,13 +45,13 @@ class ImagesExporter: COLLADASW::LibraryImages { public: ImagesExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings); - + void exportImages(Scene *sce); void operator()(Material *ma, Object *ob); private: std::vector mImages; // contains list of written images, to avoid duplicates - void export_UV_Images(); + void export_UV_Images(); void export_UV_Image(Image *image, bool use_texture_copies); bool hasImages(Scene *sce); const ExportSettings *export_settings; diff --git a/source/blender/collada/LightExporter.cpp b/source/blender/collada/LightExporter.cpp index ff50abfedae..02c5438ec47 100644 --- a/source/blender/collada/LightExporter.cpp +++ b/source/blender/collada/LightExporter.cpp @@ -54,9 +54,9 @@ LightsExporter::LightsExporter(COLLADASW::StreamWriter *sw, const ExportSettings void LightsExporter::exportLights(Scene *sce) { openLibrary(); - + forEachLampObjectInExportSet(sce, *this, this->export_settings->export_set); - + closeLibrary(); } @@ -67,11 +67,11 @@ void LightsExporter::operator()(Object *ob) std::string la_name(id_name(la)); COLLADASW::Color col(la->r * la->energy, la->g * la->energy, la->b * la->energy); float d, constatt, linatt, quadatt; - + d = la->dist; - + constatt = 1.0f; - + if (la->falloff_type == LA_FALLOFF_INVLINEAR) { linatt = 1.0f / d; quadatt = 0.0f; @@ -80,7 +80,7 @@ void LightsExporter::operator()(Object *ob) linatt = 0.0f; quadatt = 1.0f / (d * d); } - + // sun if (la->type == LA_SUN) { COLLADASW::DirectionalLight cla(mSW, la_id, la_name); @@ -130,7 +130,7 @@ void LightsExporter::operator()(Object *ob) exportBlenderProfile(cla, la); addLight(cla); } - + } bool LightsExporter::exportBlenderProfile(COLLADASW::Light &cla, Lamp *la) @@ -190,6 +190,6 @@ bool LightsExporter::exportBlenderProfile(COLLADASW::Light &cla, Lamp *la) cla.addExtraTechniqueParameter("blender", "skyblendfac", la->skyblendfac); cla.addExtraTechniqueParameter("blender", "sky_exposure", la->sky_exposure); cla.addExtraTechniqueParameter("blender", "sky_colorspace", la->sky_colorspace); - + return true; } diff --git a/source/blender/collada/MaterialExporter.h b/source/blender/collada/MaterialExporter.h index ef44bf8a03e..e830a433432 100644 --- a/source/blender/collada/MaterialExporter.h +++ b/source/blender/collada/MaterialExporter.h @@ -65,7 +65,7 @@ class ForEachMaterialFunctor Functor *f; public: ForEachMaterialFunctor(Functor*f) : f(f) {} - + void operator ()(Object *ob) { int a; diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp index cd73742a2d6..604db646419 100644 --- a/source/blender/collada/MeshImporter.cpp +++ b/source/blender/collada/MeshImporter.cpp @@ -154,7 +154,7 @@ void UVDataWrapper::getUV(int uv_index, float *uv) if (values->empty()) return; uv[0] = (*values)[uv_index * stride]; uv[1] = (*values)[uv_index * stride + 1]; - + } break; case COLLADAFW::MeshVertexData::DATA_TYPE_DOUBLE: @@ -163,7 +163,7 @@ void UVDataWrapper::getUV(int uv_index, float *uv) if (values->empty()) return; uv[0] = (float)(*values)[uv_index * stride]; uv[1] = (float)(*values)[uv_index * stride + 1]; - + } break; case COLLADAFW::MeshVertexData::DATA_TYPE_UNKNOWN: @@ -316,7 +316,7 @@ bool MeshImporter::is_nice_mesh(COLLADAFW::Mesh *mesh) // checks if mesh has su return false; } } - + return true; } @@ -356,7 +356,7 @@ bool MeshImporter::primitive_has_useable_normals(COLLADAFW::MeshPrimitive *mp) { int normals_count = mp->getNormalIndices().getCount(); if (normals_count > 0) { int index_count = mp->getPositionIndices().getCount(); - if (index_count == normals_count) + if (index_count == normals_count) has_useable_normals = true; else { fprintf(stderr, @@ -387,7 +387,7 @@ bool MeshImporter::primitive_has_faces(COLLADAFW::MeshPrimitive *mp) { break; } default: { - has_faces = false; + has_faces = false; break; } } @@ -431,7 +431,7 @@ void MeshImporter::allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *me) size_t prim_poly_count = mpvc->getFaceCount(); size_t prim_loop_count = 0; - for (int index=0; index < prim_poly_count; index++) + for (int index=0; index < prim_poly_count; index++) { int vcount = get_vertex_count(mpvc, index); if (vcount > 0) { @@ -545,7 +545,7 @@ unsigned int MeshImporter::get_loose_edge_count(COLLADAFW::Mesh *mesh) { // This functin is copied from source/blender/editors/mesh/mesh_data.c // // TODO: (As discussed with sergey-) : -// Maybe move this function to blenderkernel/intern/mesh.c +// Maybe move this function to blenderkernel/intern/mesh.c // and add definition to BKE_mesh.c // ================================================================= void MeshImporter::mesh_add_edges(Mesh *mesh, int len) @@ -580,7 +580,7 @@ void MeshImporter::mesh_add_edges(Mesh *mesh, int len) // ================================================================= // Read all loose edges. -// Important: This function assumes that all edges from existing +// Important: This function assumes that all edges from existing // faces have allready been generated and added to me->medge // So this function MUST be called after read_faces() (see below) // ================================================================= @@ -591,21 +591,21 @@ void MeshImporter::read_lines(COLLADAFW::Mesh *mesh, Mesh *me) unsigned int face_edge_count = me->totedge; /* unsigned int total_edge_count = loose_edge_count + face_edge_count; */ /* UNUSED */ - + mesh_add_edges(me, loose_edge_count); MEdge *med = me->medge + face_edge_count; COLLADAFW::MeshPrimitiveArray& prim_arr = mesh->getMeshPrimitives(); for (int i = 0; i < prim_arr.getCount(); i++) { - + COLLADAFW::MeshPrimitive *mp = prim_arr[i]; int type = mp->getPrimitiveType(); if (type == COLLADAFW::MeshPrimitive::LINES) { unsigned int edge_count = mp->getFaceCount(); unsigned int *indices = mp->getPositionIndices().getData(); - + for (int j = 0; j < edge_count; j++, med++) { med->bweight = 0; med->crease = 0; @@ -622,7 +622,7 @@ void MeshImporter::read_lines(COLLADAFW::Mesh *mesh, Mesh *me) // ======================================================================= // Read all faces from TRIANGLES, TRIANGLE_FANS, POLYLIST, POLYGON -// Important: This function MUST be called before read_lines() +// Important: This function MUST be called before read_lines() // Otherwise we will loose all edges from faces (see read_lines() above) // // TODO: import uv set names @@ -630,7 +630,7 @@ void MeshImporter::read_lines(COLLADAFW::Mesh *mesh, Mesh *me) void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, Mesh *me) { unsigned int i; - + allocate_poly_data(collada_mesh, me); UVDataWrapper uvs(collada_mesh->getUVCoords()); @@ -646,7 +646,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, Mesh *me) COLLADAFW::MeshVertexData& nor = collada_mesh->getNormals(); for (i = 0; i < prim_arr.getCount(); i++) { - + COLLADAFW::MeshPrimitive *mp = prim_arr[i]; // faces @@ -659,7 +659,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, Mesh *me) bool mp_has_faces = primitive_has_faces(mp); int collada_meshtype = mp->getPrimitiveType(); - + // since we cannot set mpoly->mat_nr here, we store a portion of me->mpoly in Primitive Primitive prim = {mpoly, 0}; @@ -686,7 +686,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, Mesh *me) mpoly->flag |= ME_SMOOTH; normal_indices++; } - + mpoly++; mloop += 3; loop_index += 3; @@ -796,7 +796,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, Mesh *me) void MeshImporter::get_vector(float v[3], COLLADAFW::MeshVertexData& arr, int i, int stride) { i *= stride; - + switch (arr.getType()) { case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT: { @@ -884,33 +884,33 @@ MTex *MeshImporter::assign_textures_to_uvlayer(COLLADAFW::TextureCoordinateBindi const COLLADAFW::TextureMapId texture_index = ctexture.getTextureMapId(); size_t setindex = ctexture.getSetIndex(); std::string uvname = ctexture.getSemantic(); - + if (setindex == -1) return NULL; - + const CustomData *data = &me->fdata; int layer_index = CustomData_get_layer_index(data, CD_MTFACE); if (layer_index == -1) return NULL; CustomDataLayer *cdl = &data->layers[layer_index + setindex]; - + /* set uvname to bind_vertex_input semantic */ BLI_strncpy(cdl->name, uvname.c_str(), sizeof(cdl->name)); if (texindex_texarray_map.find(texture_index) == texindex_texarray_map.end()) { - + fprintf(stderr, "Cannot find texture array by texture index.\n"); return color_texture; } - + std::vector textures = texindex_texarray_map[texture_index]; - + std::vector::iterator it; - + for (it = textures.begin(); it != textures.end(); it++) { - + MTex *texture = *it; - + if (texture) { BLI_strncpy(texture->uvname, uvname.c_str(), sizeof(texture->uvname)); if (texture->mapto == MAP_COL) color_texture = texture; @@ -928,7 +928,7 @@ static bool bc_has_same_material_configuration(Object *ob1, Object *ob2) { if (ob1->totcol != ob2->totcol) return false; // not same number of materials if (ob1->totcol == 0) return false; // no material at all - + for (int index=0; index < ob1->totcol; index++) { if (ob1->matbits[index] != ob2->matbits[index]) return false; // shouldn't happen if (ob1->matbits[index] == 0) return false; // shouldn't happen @@ -1061,35 +1061,35 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri MTex *color_texture = NULL; Mesh *me = (Mesh *)ob->data; const COLLADAFW::UniqueId& ma_uid = cmaterial.getReferencedMaterial(); - + // do we know this material? if (uid_material_map.find(ma_uid) == uid_material_map.end()) { - + fprintf(stderr, "Cannot find material by UID.\n"); return NULL; } // first time we get geom_uid, ma_uid pair. Save for later check. materials_mapped_to_geom.insert(std::pair(*geom_uid, ma_uid)); - + Material *ma = uid_material_map[ma_uid]; // Attention! This temporaly assigns material to object on purpose! // See note above. ob->actcol=0; assign_material(G.main, ob, ma, mat_index + 1, BKE_MAT_ASSIGN_OBJECT); - - COLLADAFW::TextureCoordinateBindingArray& tex_array = + + COLLADAFW::TextureCoordinateBindingArray& tex_array = cmaterial.getTextureCoordinateBindingArray(); TexIndexTextureArrayMap texindex_texarray_map = material_texture_mapping_map[ma]; unsigned int i; // loop through for (i = 0; i < tex_array.getCount(); i++) { - + color_texture = assign_textures_to_uvlayer(tex_array[i], me, texindex_texarray_map, color_texture); } - + // set texture face if (color_texture && strlen((color_texture)->uvname) && @@ -1099,17 +1099,17 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri color_texture->uvname); strcpy(layername, color_texture->uvname); } - + MaterialIdPrimitiveArrayMap& mat_prim_map = geom_uid_mat_mapping_map[*geom_uid]; COLLADAFW::MaterialId mat_id = cmaterial.getMaterialId(); - + // assign material indices to mesh faces if (mat_prim_map.find(mat_id) != mat_prim_map.end()) { - + std::vector& prims = mat_prim_map[mat_id]; - + std::vector::iterator it; - + for (it = prims.begin(); it != prims.end(); it++) { Primitive& prim = *it; MPoly *mpoly = prim.mpoly; @@ -1123,7 +1123,7 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri } } } - } + } return texture_face; } @@ -1133,19 +1133,19 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta std::map& material_texture_mapping_map) { const COLLADAFW::UniqueId *geom_uid = &geom->getInstanciatedObjectId(); - + // check if node instanciates controller or geometry if (isController) { - + geom_uid = armature_importer->get_geometry_uid(*geom_uid); - + if (!geom_uid) { fprintf(stderr, "Couldn't find a mesh UID by controller's UID.\n"); return NULL; } } else { - + if (uid_mesh_map.find(*geom_uid) == uid_mesh_map.end()) { // this could happen if a mesh was not created // (e.g. if it contains unsupported geometry) @@ -1154,11 +1154,11 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta } } if (!uid_mesh_map[*geom_uid]) return NULL; - + // name Object const std::string& id = node->getName().size() ? node->getName() : node->getOriginalId(); const char *name = (id.length()) ? id.c_str() : NULL; - + // add object Object *ob = bc_add_object(scene, OB_MESH, name); bc_set_mark(ob); // used later for material assignement optimization @@ -1167,7 +1167,7 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta // store object pointer for ArmatureImporter uid_object_map[*geom_uid] = ob; imported_objects.push_back(ob); - + // replace ob->data freeing the old one Mesh *old_mesh = (Mesh *)ob->data; Mesh *new_mesh = uid_mesh_map[*geom_uid]; @@ -1181,13 +1181,13 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta char layername[100]; layername[0] = '\0'; MTFace *texture_face = NULL; - + COLLADAFW::MaterialBindingArray& mat_array = geom->getMaterialBindings(); - + // loop through geom's materials for (unsigned int i = 0; i < mat_array.getCount(); i++) { - + if (mat_array[i].getReferencedMaterial().isValid()) { texture_face = assign_material_to_geom(mat_array[i], uid_material_map, ob, geom_uid, layername, texture_face, @@ -1210,14 +1210,14 @@ bool MeshImporter::write_geometry(const COLLADAFW::Geometry *geom) fprintf(stderr, "Mesh type %s is not supported\n", bc_geomTypeToStr(geom->getType())); return true; } - + COLLADAFW::Mesh *mesh = (COLLADAFW::Mesh *)geom; - + if (!is_nice_mesh(mesh)) { fprintf(stderr, "Ignoring mesh %s\n", bc_get_dae_name(mesh).c_str()); return true; } - + const std::string& str_geom_id = mesh->getName().size() ? mesh->getName() : mesh->getOriginalId(); Mesh *me = BKE_mesh_add(G.main, (char *)str_geom_id.c_str()); id_us_min(&me->id); // is already 1 here, but will be set later in BKE_mesh_assign_object @@ -1226,7 +1226,7 @@ bool MeshImporter::write_geometry(const COLLADAFW::Geometry *geom) // mesh_geom_map needed to map mesh to its geometry name (for shape key naming) this->uid_mesh_map[mesh->getUniqueId()] = me; this->mesh_geom_map[std::string(me->id.name)] = str_geom_id; - + read_vertices(mesh, me); read_polys(mesh, me); diff --git a/source/blender/collada/MeshImporter.h b/source/blender/collada/MeshImporter.h index d6426fbaf56..f0da3cc21cf 100644 --- a/source/blender/collada/MeshImporter.h +++ b/source/blender/collada/MeshImporter.h @@ -108,7 +108,7 @@ private: typedef std::map > MaterialIdPrimitiveArrayMap; std::map geom_uid_mat_mapping_map; // crazy name! std::multimap materials_mapped_to_geom; //< materials that have already been mapped to a geometry. A pair of geom uid and mat uid, one geometry can have several materials - + bool set_poly_indices(MPoly *mpoly, MLoop *mloop, int loop_index, @@ -134,7 +134,7 @@ private: bool is_nice_mesh(COLLADAFW::Mesh *mesh); void read_vertices(COLLADAFW::Mesh *mesh, Mesh *me); - + bool primitive_has_useable_normals(COLLADAFW::MeshPrimitive *mp); bool primitive_has_faces(COLLADAFW::MeshPrimitive *mp); @@ -164,7 +164,7 @@ public: virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId& geom_uid); virtual Mesh *get_mesh_by_geom_uid(const COLLADAFW::UniqueId& geom_uid); - + MTex *assign_textures_to_uvlayer(COLLADAFW::TextureCoordinateBinding &ctexture, Mesh *me, TexIndexTextureArrayMap& texindex_texarray_map, MTex *color_texture); @@ -176,8 +176,8 @@ public: Object *ob, const COLLADAFW::UniqueId *geom_uid, char *layername, MTFace *texture_face, std::map& material_texture_mapping_map, short mat_index); - - + + Object *create_mesh_object(COLLADAFW::Node *node, COLLADAFW::InstanceGeometry *geom, bool isController, std::map& uid_material_map, diff --git a/source/blender/collada/SceneExporter.cpp b/source/blender/collada/SceneExporter.cpp index c195ecb4725..4e08548449f 100644 --- a/source/blender/collada/SceneExporter.cpp +++ b/source/blender/collada/SceneExporter.cpp @@ -49,7 +49,7 @@ void SceneExporter::exportScene(bContext *C, Scene *sce) } void SceneExporter::exportHierarchy(bContext *C, Scene *sce) -{ +{ LinkNode *node; std::vector base_objects; @@ -58,7 +58,7 @@ void SceneExporter::exportHierarchy(bContext *C, Scene *sce) Object *ob = (Object *) node->link; ob->id.tag |= LIB_TAG_DOIT; } - + // Now find all exportable base ojects (highest in export hierarchy) for (node = this->export_settings->export_set; node; node = node->next) { Object *ob = (Object *) node->link; @@ -146,9 +146,9 @@ void SceneExporter::writeNodes(bContext *C, Object *ob, Scene *sce) COLLADASW::InstanceGeometry instGeom(mSW); instGeom.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob, this->export_settings->use_object_instantiation))); instGeom.setName(translate_id(id_name(ob))); - InstanceWriter::add_material_bindings(instGeom.getBindMaterial(), - ob, - this->export_settings->active_uv_only, + InstanceWriter::add_material_bindings(instGeom.getBindMaterial(), + ob, + this->export_settings->active_uv_only, this->export_settings->export_texture_type); instGeom.add(); @@ -204,17 +204,17 @@ void SceneExporter::writeNodes(bContext *C, Object *ob, Scene *sce) colladaNode.addExtraTechniqueChildParameter("blender",con_tag,"rot_error",con->rot_error); colladaNode.addExtraTechniqueChildParameter("blender",con_tag,"tar_space",con->tarspace); colladaNode.addExtraTechniqueChildParameter("blender",con_tag,"lin_error",con->lin_error); - - //not ideal: add the target object name as another parameter. + + //not ideal: add the target object name as another parameter. //No real mapping in the .dae //Need support for multiple target objects also. const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); ListBase targets = {NULL, NULL}; if (cti && cti->get_constraint_targets) { - + bConstraintTarget *ct; Object *obtar; - + cti->get_constraint_targets(con, &targets); for (ct = (bConstraintTarget *)targets.first; ct; ct = ct->next) { diff --git a/source/blender/collada/SceneExporter.h b/source/blender/collada/SceneExporter.h index 60cb078d91b..6cf561749de 100644 --- a/source/blender/collada/SceneExporter.h +++ b/source/blender/collada/SceneExporter.h @@ -102,7 +102,7 @@ private: friend class ArmatureExporter; void exportHierarchy(bContext *C, Scene *sce); void writeNodes(bContext *C, Object *ob, Scene *sce); - + ArmatureExporter *arm_exporter; const ExportSettings *export_settings; }; diff --git a/source/blender/collada/SkinInfo.cpp b/source/blender/collada/SkinInfo.cpp index c48c060dc95..72d5c656920 100644 --- a/source/blender/collada/SkinInfo.cpp +++ b/source/blender/collada/SkinInfo.cpp @@ -121,7 +121,7 @@ void SkinInfo::borrow_skin_controller_data(const COLLADAFW::SkinControllerData * unit_converter->dae_matrix_to_mat4_(bind_shape_matrix, skin->getBindShapeMatrix()); } - + void SkinInfo::free() { joints_per_vertex.releaseMemory(); @@ -199,7 +199,7 @@ const COLLADAFW::UniqueId& SkinInfo::get_controller_uid() } // check if this skin controller references a joint or any descendant of it -// +// // some nodes may not be referenced by SkinController, // in this case to determine if the node belongs to this armature, // we need to search down the tree @@ -259,9 +259,9 @@ void SkinInfo::link_armature(bContext *C, Object *ob, std::mapgetTransformations().getCount(); i++) { COLLADAFW::Transformation *tm = node->getTransformations()[i]; @@ -87,11 +87,11 @@ void TransformReader::get_node_mat( copy_m4_m4(copy, mat); mul_m4_m4m4(mat, copy, cur); - + if (animation_map) { // AnimationList that drives this Transformation const COLLADAFW::UniqueId& anim_list_id = tm->getAnimationList(); - + // store this so later we can link animation data with ob Animation anim = {ob, node, tm}; (*animation_map)[anim_list_id] = anim; diff --git a/source/blender/collada/TransformReader.h b/source/blender/collada/TransformReader.h index 08bb17ccac1..6544aa1c040 100644 --- a/source/blender/collada/TransformReader.h +++ b/source/blender/collada/TransformReader.h @@ -19,7 +19,7 @@ * * ***** END GPL LICENSE BLOCK ***** */ - + /** \file TransformReader.h * \ingroup collada */ diff --git a/source/blender/collada/TransformWriter.cpp b/source/blender/collada/TransformWriter.cpp index b7eeff3b074..89653c139f3 100644 --- a/source/blender/collada/TransformWriter.cpp +++ b/source/blender/collada/TransformWriter.cpp @@ -116,7 +116,7 @@ void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob, B { float loc[3], rot[3], scale[3]; bc_decompose(f_obmat, loc, rot, NULL, scale); - add_transform(node, loc, rot, scale); + add_transform(node, loc, rot, scale); break; } } diff --git a/source/blender/collada/collada_internal.h b/source/blender/collada/collada_internal.h index fc848100b79..ff998a94685 100644 --- a/source/blender/collada/collada_internal.h +++ b/source/blender/collada/collada_internal.h @@ -51,7 +51,7 @@ private: float y_up_mat4[4][4]; float z_up_mat4[4][4]; float scale_mat4[4][4]; - + public: enum UnitSystem { @@ -66,11 +66,11 @@ public: void read_asset(const COLLADAFW::FileInfo *asset); void convertVector3(COLLADABU::Math::Vector3 &vec, float *v); - + UnitConverter::UnitSystem isMetricSystem(void); - + float getLinearMeter(void); - + // TODO need also for angle conversion, time conversion... void dae_matrix_to_mat4_(float out[4][4], const COLLADABU::Math::Matrix4& in); diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp index 27389990082..153bc8b28bd 100644 --- a/source/blender/collada/collada_utils.cpp +++ b/source/blender/collada/collada_utils.cpp @@ -74,7 +74,7 @@ float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray& array, unsigned in if (array.getType() == COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT) return array.getFloatValues()->getData()[index]; - else + else return array.getDoubleValues()->getData()[index]; } @@ -82,10 +82,10 @@ float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray& array, unsigned in int bc_test_parent_loop(Object *par, Object *ob) { /* test if 'ob' is a parent somewhere in par's parents */ - + if (par == NULL) return 0; if (ob == par) return 1; - + return bc_test_parent_loop(par->parent, ob); } @@ -95,7 +95,7 @@ int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space) { Object workob; Scene *sce = CTX_data_scene(C); - + if (!par || bc_test_parent_loop(par, ob)) return false; @@ -113,7 +113,7 @@ int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space) mul_m4_m4m4(mat, par->obmat, ob->obmat); copy_m4_m4(ob->obmat, mat); } - + // apply child obmat (i.e. decompose it into rot/loc/size) BKE_object_apply_mat4(ob, ob->obmat, 0, 0); @@ -224,7 +224,7 @@ Object *bc_get_assigned_armature(Object *ob) // IMPORTANT: This function expects that // all exported objects have set: // ob->id.tag & LIB_TAG_DOIT -Object *bc_get_highest_selected_ancestor_or_self(LinkNode *export_set, Object *ob) +Object *bc_get_highest_selected_ancestor_or_self(LinkNode *export_set, Object *ob) { Object *ancestor = ob; while (ob->parent && bc_is_marked(ob->parent)) { @@ -249,7 +249,7 @@ bool bc_is_in_Export_set(LinkNode *export_set, Object *ob) bool bc_has_object_type(LinkNode *export_set, short obtype) { LinkNode *node; - + for (node = export_set; node; node = node->next) { Object *ob = (Object *)node->link; /* XXX - why is this checking for ob->data? - we could be looking for empties */ @@ -283,7 +283,7 @@ void bc_bubble_sort_by_Object_name(LinkNode *export_set) for (node = export_set; node->next && !sorted; node = node->next) { sorted = true; - + LinkNode *current; for (current = export_set; current->next; current = current->next) { Object *a = (Object *)current->link; @@ -294,12 +294,12 @@ void bc_bubble_sort_by_Object_name(LinkNode *export_set) current->next->link = a; sorted = false; } - + } } } -/* Check if a bone is the top most exportable bone in the bone hierarchy. +/* Check if a bone is the top most exportable bone in the bone hierarchy. * When deform_bones_only == false, then only bones with NO parent * can be root bones. Otherwise the top most deform bones in the hierarchy * are root bones. @@ -360,13 +360,13 @@ void bc_match_scale(Object *ob, UnitConverter &bc_unit, bool scale_to_scene) BKE_object_apply_mat4(ob, ob->obmat, 0, 0); } -void bc_match_scale(std::vector *objects_done, +void bc_match_scale(std::vector *objects_done, UnitConverter &bc_unit, bool scale_to_scene) { for (std::vector::iterator it = objects_done->begin(); it != objects_done->end(); - ++it) + ++it) { Object *ob = *it; if (ob -> parent == NULL) { @@ -774,7 +774,7 @@ float bc_get_property(Bone *bone, std::string key, float def) /** * Read a custom bone property and convert to matrix * Return true if conversion was succesfull -* +* * Return false if: * - the property does not exist * - is not an array of size 16 diff --git a/source/blender/collada/collada_utils.h b/source/blender/collada/collada_utils.h index 0069b4d4871..cbce74485b7 100644 --- a/source/blender/collada/collada_utils.h +++ b/source/blender/collada/collada_utils.h @@ -90,8 +90,8 @@ extern void bc_bubble_sort_by_Object_name(LinkNode *export_set); extern bool bc_is_root_bone(Bone *aBone, bool deform_bones_only); extern int bc_get_active_UVLayer(Object *ob); -extern std::string bc_replace_string(std::string data, const std::string& pattern, const std::string& replacement); -extern std::string bc_url_encode(std::string data); +extern std::string bc_replace_string(std::string data, const std::string& pattern, const std::string& replacement); +extern std::string bc_url_encode(std::string data); extern void bc_match_scale(Object *ob, UnitConverter &bc_unit, bool scale_to_scene); extern void bc_match_scale(std::vector *objects_done, UnitConverter &unit_converter, bool scale_to_scene); @@ -141,8 +141,8 @@ class BCPolygonNormalsIndices normal_indices.push_back(index); } - unsigned int operator[](unsigned int i) { - return normal_indices[i]; + unsigned int operator[](unsigned int i) { + return normal_indices[i]; } }; diff --git a/source/blender/datatoc/datatoc_icon.c b/source/blender/datatoc/datatoc_icon.c index 92048f32a28..e5f82ae09c8 100644 --- a/source/blender/datatoc/datatoc_icon.c +++ b/source/blender/datatoc/datatoc_icon.c @@ -386,7 +386,7 @@ int main(int argc, char **argv) { const char *path_src; const char *file_dst; - + if (argc < 3) { printf("Usage: datatoc_icon \n"); diff --git a/source/blender/ikplugin/CMakeLists.txt b/source/blender/ikplugin/CMakeLists.txt index 8991e113410..eb34e50715e 100644 --- a/source/blender/ikplugin/CMakeLists.txt +++ b/source/blender/ikplugin/CMakeLists.txt @@ -25,7 +25,7 @@ remove_extra_strict_flags() -set(INC +set(INC . ../blenkernel ../blenlib diff --git a/source/blender/ikplugin/intern/ikplugin_api.c b/source/blender/ikplugin/intern/ikplugin_api.c index 8ce45a1c690..ca9dcdf198c 100644 --- a/source/blender/ikplugin/intern/ikplugin_api.c +++ b/source/blender/ikplugin/intern/ikplugin_api.c @@ -89,7 +89,7 @@ static IKPlugin *get_plugin(bPose *pose) /*----------------------------------------*/ /* Plugin API */ -void BIK_initialize_tree(Scene *scene, Object *ob, float ctime) +void BIK_initialize_tree(Scene *scene, Object *ob, float ctime) { IKPlugin *plugin = get_plugin(ob->pose); @@ -97,7 +97,7 @@ void BIK_initialize_tree(Scene *scene, Object *ob, float ctime) plugin->initialize_tree_func(scene, ob, ctime); } -void BIK_execute_tree(struct Scene *scene, Object *ob, bPoseChannel *pchan, float ctime) +void BIK_execute_tree(struct Scene *scene, Object *ob, bPoseChannel *pchan, float ctime) { IKPlugin *plugin = get_plugin(ob->pose); @@ -105,7 +105,7 @@ void BIK_execute_tree(struct Scene *scene, Object *ob, bPoseChannel *pchan, floa plugin->execute_tree_func(scene, ob, pchan, ctime); } -void BIK_release_tree(struct Scene *scene, Object *ob, float ctime) +void BIK_release_tree(struct Scene *scene, Object *ob, float ctime) { IKPlugin *plugin = get_plugin(ob->pose); diff --git a/source/blender/ikplugin/intern/itasc_plugin.cpp b/source/blender/ikplugin/intern/itasc_plugin.cpp index d58340965a7..59385670b9a 100644 --- a/source/blender/ikplugin/intern/itasc_plugin.cpp +++ b/source/blender/ikplugin/intern/itasc_plugin.cpp @@ -877,7 +877,7 @@ static int convert_channels(IK_Scene *ikscene, PoseTree *tree, float ctime) ikchan->owner = ikscene->blArmature; // the constraint and channels must be applied before we build the iTaSC scene, - // this is because some of the pose data (e.g. pose head) don't have corresponding + // this is because some of the pose data (e.g. pose head) don't have corresponding // joint angles and can't be applied to the iTaSC armature dynamically if (!(pchan->flag & POSE_DONE)) BKE_pose_where_is_bone(ikscene->blscene, ikscene->blArmature, pchan, ctime, 1); diff --git a/source/blender/nodes/composite/node_composite_tree.c b/source/blender/nodes/composite/node_composite_tree.c index 0e98418ffea..4779fdd33d2 100644 --- a/source/blender/nodes/composite/node_composite_tree.c +++ b/source/blender/nodes/composite/node_composite_tree.c @@ -59,7 +59,7 @@ static void composite_get_from_context(const bContext *C, bNodeTreeType *UNUSED(treetype), bNodeTree **r_ntree, ID **r_id, ID **r_from) { Scene *scene = CTX_data_scene(C); - + *r_from = NULL; *r_id = &scene->id; *r_ntree = scene->nodetree; @@ -83,7 +83,7 @@ static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCa static void free_node_cache(bNodeTree *UNUSED(ntree), bNode *node) { bNodeSocket *sock; - + for (sock = node->outputs.first; sock; sock = sock->next) { if (sock->cache) { sock->cache = NULL; @@ -103,15 +103,15 @@ static void localize(bNodeTree *UNUSED(localtree), bNodeTree *ntree) { bNode *node; bNodeSocket *sock; - + for (node = ntree->nodes.first; node; node = node->next) { /* ensure new user input gets handled ok */ node->need_exec = 0; node->new_node->original = node; - + /* move over the compbufs */ /* right after ntreeCopyTree() oldsock pointers are valid */ - + if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { if (node->id) { if (node->flag & NODE_DO_OUTPUT) @@ -120,7 +120,7 @@ static void localize(bNodeTree *UNUSED(localtree), bNodeTree *ntree) node->new_node->id = NULL; } } - + for (sock = node->outputs.first; sock; sock = sock->next) { sock->new_sock->cache = sock->cache; sock->cache = NULL; @@ -138,10 +138,10 @@ static void local_merge(bNodeTree *localtree, bNodeTree *ntree) { bNode *lnode; bNodeSocket *lsock; - + /* move over the compbufs and previews */ BKE_node_preview_merge_tree(ntree, localtree, true); - + for (lnode = localtree->nodes.first; lnode; lnode = lnode->next) { if (ntreeNodeExists(ntree, lnode->new_node)) { if (ELEM(lnode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { @@ -161,7 +161,7 @@ static void local_merge(bNodeTree *localtree, bNodeTree *ntree) lnode->new_node->storage = BKE_tracking_distortion_copy(lnode->storage); } } - + for (lsock = lnode->outputs.first; lsock; lsock = lsock->next) { if (ntreeOutputExists(lnode->new_node, lsock->new_sock)) { lsock->new_sock->cache = lsock->cache; @@ -176,9 +176,9 @@ static void local_merge(bNodeTree *localtree, bNodeTree *ntree) static void update(bNodeTree *ntree) { ntreeSetOutput(ntree); - + ntree_update_reroute_nodes(ntree); - + if (ntree->update & NTREE_UPDATE_NODES) { /* clean up preview cache, in case nodes have been removed */ BKE_node_preview_remove_unused(ntree); @@ -187,12 +187,12 @@ static void update(bNodeTree *ntree) static void composite_node_add_init(bNodeTree *UNUSED(bnodetree), bNode *bnode) { - /* Composite node will only show previews for input classes - * by default, other will be hidden + /* Composite node will only show previews for input classes + * by default, other will be hidden * but can be made visible with the show_preview option */ if (bnode->typeinfo->nclass != NODE_CLASS_INPUT) { bnode->flag &= ~NODE_PREVIEW; - } + } } bNodeTreeType *ntreeType_Composite; @@ -200,13 +200,13 @@ bNodeTreeType *ntreeType_Composite; void register_node_tree_type_cmp(void) { bNodeTreeType *tt = ntreeType_Composite = MEM_callocN(sizeof(bNodeTreeType), "compositor node tree type"); - + tt->type = NTREE_COMPOSIT; strcpy(tt->idname, "CompositorNodeTree"); strcpy(tt->ui_name, "Compositing"); tt->ui_icon = 0; /* defined in drawnode.c */ strcpy(tt->ui_description, "Compositing nodes"); - + tt->free_cache = free_cache; tt->free_node_cache = free_node_cache; tt->foreach_nodeclass = foreach_nodeclass; @@ -216,9 +216,9 @@ void register_node_tree_type_cmp(void) tt->update = update; tt->get_from_context = composite_get_from_context; tt->node_add_init = composite_node_add_init; - + tt->ext.srna = &RNA_CompositorNodeTree; - + ntreeTypeAdd(tt); } diff --git a/source/blender/nodes/composite/node_composite_util.c b/source/blender/nodes/composite/node_composite_util.c index faf3d994bf9..022794e8d42 100644 --- a/source/blender/nodes/composite/node_composite_util.c +++ b/source/blender/nodes/composite/node_composite_util.c @@ -52,7 +52,7 @@ void cmp_node_update_default(bNodeTree *UNUSED(ntree), bNode *node) void cmp_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag) { node_type_base(ntype, type, name, nclass, flag); - + ntype->poll = cmp_node_poll_default; ntype->updatefunc = cmp_node_update_default; ntype->insert_link = node_insert_link_default; diff --git a/source/blender/nodes/composite/nodes/node_composite_bokehblur.c b/source/blender/nodes/composite/nodes/node_composite_bokehblur.c index 503d1ad9a9d..acb5d100b0a 100644 --- a/source/blender/nodes/composite/nodes/node_composite_bokehblur.c +++ b/source/blender/nodes/composite/nodes/node_composite_bokehblur.c @@ -60,6 +60,6 @@ void register_node_type_cmp_bokehblur(void) cmp_node_type_base(&ntype, CMP_NODE_BOKEHBLUR, "Bokeh Blur", NODE_CLASS_OP_FILTER, 0); node_type_socket_templates(&ntype, cmp_node_bokehblur_in, cmp_node_bokehblur_out); node_type_init(&ntype, node_composit_init_bokehblur); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_bokehimage.c b/source/blender/nodes/composite/nodes/node_composite_bokehimage.c index 1473212f8e1..04cdd3367e6 100644 --- a/source/blender/nodes/composite/nodes/node_composite_bokehimage.c +++ b/source/blender/nodes/composite/nodes/node_composite_bokehimage.c @@ -54,7 +54,7 @@ static void node_composit_init_bokehimage(bNodeTree *UNUSED(ntree), bNode *node) void register_node_type_cmp_bokehimage(void) { static bNodeType ntype; - + cmp_node_type_base(&ntype, CMP_NODE_BOKEHIMAGE, "Bokeh Image", NODE_CLASS_INPUT, NODE_PREVIEW); node_type_socket_templates(&ntype, NULL, cmp_node_bokehimage_out); node_type_init(&ntype, node_composit_init_bokehimage); diff --git a/source/blender/nodes/composite/nodes/node_composite_boxmask.c b/source/blender/nodes/composite/nodes/node_composite_boxmask.c index 2a47c58c33f..611cf323873 100644 --- a/source/blender/nodes/composite/nodes/node_composite_boxmask.c +++ b/source/blender/nodes/composite/nodes/node_composite_boxmask.c @@ -32,7 +32,7 @@ #include "../node_composite_util.h" -/* **************** SCALAR MATH ******************** */ +/* **************** SCALAR MATH ******************** */ static bNodeSocketTemplate cmp_node_boxmask_in[] = { { SOCK_FLOAT, 1, N_("Mask"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, { SOCK_FLOAT, 1, N_("Value"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, diff --git a/source/blender/nodes/composite/nodes/node_composite_brightness.c b/source/blender/nodes/composite/nodes/node_composite_brightness.c index 845e9e20c81..d44b8cd63cb 100644 --- a/source/blender/nodes/composite/nodes/node_composite_brightness.c +++ b/source/blender/nodes/composite/nodes/node_composite_brightness.c @@ -54,7 +54,7 @@ static void node_composit_init_brightcontrast(bNodeTree *UNUSED(ntree), bNode *n void register_node_type_cmp_brightcontrast(void) { static bNodeType ntype; - + cmp_node_type_base(&ntype, CMP_NODE_BRIGHTCONTRAST, "Bright/Contrast", NODE_CLASS_OP_COLOR, 0); node_type_socket_templates(&ntype, cmp_node_brightcontrast_in, cmp_node_brightcontrast_out); node_type_init(&ntype, node_composit_init_brightcontrast); diff --git a/source/blender/nodes/composite/nodes/node_composite_colorSpill.c b/source/blender/nodes/composite/nodes/node_composite_colorSpill.c index a6a7f3aa5a3..641026c3aad 100644 --- a/source/blender/nodes/composite/nodes/node_composite_colorSpill.c +++ b/source/blender/nodes/composite/nodes/node_composite_colorSpill.c @@ -57,7 +57,7 @@ static void node_composit_init_color_spill(bNodeTree *UNUSED(ntree), bNode *node void register_node_type_cmp_color_spill(void) { static bNodeType ntype; - + cmp_node_type_base(&ntype, CMP_NODE_COLOR_SPILL, "Color Spill", NODE_CLASS_MATTE, 0); node_type_socket_templates(&ntype, cmp_node_color_spill_in, cmp_node_color_spill_out); node_type_init(&ntype, node_composit_init_color_spill); diff --git a/source/blender/nodes/composite/nodes/node_composite_colorbalance.c b/source/blender/nodes/composite/nodes/node_composite_colorbalance.c index 8370ace8cb3..f9ad8c0ea5f 100644 --- a/source/blender/nodes/composite/nodes/node_composite_colorbalance.c +++ b/source/blender/nodes/composite/nodes/node_composite_colorbalance.c @@ -52,7 +52,7 @@ void ntreeCompositColorBalanceSyncFromLGG(bNodeTree *UNUSED(ntree), bNode *node) { NodeColorBalance *n = node->storage; int c; - + for (c = 0; c < 3; ++c) { n->slope[c] = (2.0f - n->lift[c]) * n->gain[c]; n->offset[c] = (n->lift[c] - 1.0f) * n->gain[c]; @@ -64,7 +64,7 @@ void ntreeCompositColorBalanceSyncFromCDL(bNodeTree *UNUSED(ntree), bNode *node) { NodeColorBalance *n = node->storage; int c; - + for (c = 0; c < 3; ++c) { float d = n->slope[c] + n->offset[c]; n->lift[c] = (d != 0.0f ? n->slope[c] + 2.0f * n->offset[c] / d : 0.0f); diff --git a/source/blender/nodes/composite/nodes/node_composite_common.c b/source/blender/nodes/composite/nodes/node_composite_common.c index 57ec0f1c7ad..de97a5beac3 100644 --- a/source/blender/nodes/composite/nodes/node_composite_common.c +++ b/source/blender/nodes/composite/nodes/node_composite_common.c @@ -43,7 +43,7 @@ void register_node_type_cmp_group(void) { static bNodeType ntype; - + /* NB: cannot use sh_node_type_base for node group, because it would map the node type * to the shared NODE_GROUP integer type id. */ @@ -56,7 +56,7 @@ void register_node_type_cmp_group(void) ntype.ext.srna = RNA_struct_find("CompositorNodeGroup"); BLI_assert(ntype.ext.srna != NULL); RNA_struct_blender_type_set(ntype.ext.srna, &ntype); - + node_type_socket_templates(&ntype, NULL, NULL); node_type_size(&ntype, 140, 60, 400); node_type_label(&ntype, node_group_label); diff --git a/source/blender/nodes/composite/nodes/node_composite_dilate.c b/source/blender/nodes/composite/nodes/node_composite_dilate.c index 4efee112438..72d12e0a643 100644 --- a/source/blender/nodes/composite/nodes/node_composite_dilate.c +++ b/source/blender/nodes/composite/nodes/node_composite_dilate.c @@ -54,7 +54,7 @@ static void node_composit_init_dilateerode(bNodeTree *UNUSED(ntree), bNode *node void register_node_type_cmp_dilateerode(void) { static bNodeType ntype; - + cmp_node_type_base(&ntype, CMP_NODE_DILATEERODE, "Dilate/Erode", NODE_CLASS_OP_FILTER, 0); node_type_socket_templates(&ntype, cmp_node_dilateerode_in, cmp_node_dilateerode_out); node_type_init(&ntype, node_composit_init_dilateerode); diff --git a/source/blender/nodes/composite/nodes/node_composite_ellipsemask.c b/source/blender/nodes/composite/nodes/node_composite_ellipsemask.c index df8ae4931e5..b72a0fb82ae 100644 --- a/source/blender/nodes/composite/nodes/node_composite_ellipsemask.c +++ b/source/blender/nodes/composite/nodes/node_composite_ellipsemask.c @@ -32,7 +32,7 @@ #include "../node_composite_util.h" -/* **************** SCALAR MATH ******************** */ +/* **************** SCALAR MATH ******************** */ static bNodeSocketTemplate cmp_node_ellipsemask_in[] = { { SOCK_FLOAT, 1, N_("Mask"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, { SOCK_FLOAT, 1, N_("Value"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, diff --git a/source/blender/nodes/composite/nodes/node_composite_gamma.c b/source/blender/nodes/composite/nodes/node_composite_gamma.c index 81764c97aac..30d399d3f73 100644 --- a/source/blender/nodes/composite/nodes/node_composite_gamma.c +++ b/source/blender/nodes/composite/nodes/node_composite_gamma.c @@ -47,9 +47,9 @@ static bNodeSocketTemplate cmp_node_gamma_out[] = { void register_node_type_cmp_gamma(void) { static bNodeType ntype; - + cmp_node_type_base(&ntype, CMP_NODE_GAMMA, "Gamma", NODE_CLASS_OP_COLOR, 0); node_type_socket_templates(&ntype, cmp_node_gamma_in, cmp_node_gamma_out); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_huecorrect.c b/source/blender/nodes/composite/nodes/node_composite_huecorrect.c index 4ee1bccd726..70c73bcb46a 100644 --- a/source/blender/nodes/composite/nodes/node_composite_huecorrect.c +++ b/source/blender/nodes/composite/nodes/node_composite_huecorrect.c @@ -47,14 +47,14 @@ static void node_composit_init_huecorrect(bNodeTree *UNUSED(ntree), bNode *node) { CurveMapping *cumapping = node->storage = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); int c; - + cumapping->preset = CURVE_PRESET_MID9; - + for (c = 0; c < 3; c++) { CurveMap *cuma = &cumapping->cm[c]; curvemap_reset(cuma, &cumapping->clipr, cumapping->preset, CURVEMAP_SLOPE_POSITIVE); } - + /* default to showing Saturation */ cumapping->cur = 1; } diff --git a/source/blender/nodes/composite/nodes/node_composite_image.c b/source/blender/nodes/composite/nodes/node_composite_image.c index 4fd7434f632..bf50070e5cb 100644 --- a/source/blender/nodes/composite/nodes/node_composite_image.c +++ b/source/blender/nodes/composite/nodes/node_composite_image.c @@ -149,10 +149,10 @@ static void cmp_node_image_create_outputs(bNodeTree *ntree, bNode *node, LinkNod /* make sure ima->type is correct */ ibuf = BKE_image_acquire_ibuf(ima, &load_iuser, NULL); - + if (ima->rr) { RenderLayer *rl = BLI_findlink(&ima->rr->layers, iuser->layer); - + if (rl) { RenderPass *rpass; for (rpass = rl->passes.first; rpass; rpass = rpass->next) { @@ -250,7 +250,7 @@ static void cmp_node_image_verify_outputs(bNodeTree *ntree, bNode *node, bool rl bNodeSocket *sock, *sock_next; LinkNodePair available_sockets = {NULL, NULL}; int sock_index; - + /* XXX make callback */ if (rlayer) cmp_node_rlayer_create_outputs(ntree, node, &available_sockets); @@ -305,7 +305,7 @@ static void node_composit_init_image(bNodeTree *ntree, bNode *node) iuser->sfra = 1; iuser->fie_ima = 2; iuser->ok = 1; - + /* setup initial outputs */ cmp_node_image_verify_outputs(ntree, node, false); } @@ -313,20 +313,20 @@ static void node_composit_init_image(bNodeTree *ntree, bNode *node) static void node_composit_free_image(bNode *node) { bNodeSocket *sock; - + /* free extra socket info */ for (sock = node->outputs.first; sock; sock = sock->next) MEM_freeN(sock->storage); - + MEM_freeN(node->storage); } static void node_composit_copy_image(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, bNode *src_node) { bNodeSocket *sock; - + dest_node->storage = MEM_dupallocN(src_node->storage); - + /* copy extra socket info */ for (sock = src_node->outputs.first; sock; sock = sock->next) sock->new_sock->storage = MEM_dupallocN(sock->storage); @@ -392,7 +392,7 @@ static int node_composit_poll_rlayers(bNodeType *UNUSED(ntype), bNodeTree *ntree { if (STREQ(ntree->idname, "CompositorNodeTree")) { Scene *scene; - + /* XXX ugly: check if ntree is a local scene node tree. * Render layers node can only be used in local scene->nodetree, * since it directly links to the scene. @@ -400,7 +400,7 @@ static int node_composit_poll_rlayers(bNodeType *UNUSED(ntype), bNodeTree *ntree for (scene = G.main->scene.first; scene; scene = scene->id.next) if (scene->nodetree == ntree) break; - + return (scene != NULL); } return false; diff --git a/source/blender/nodes/composite/nodes/node_composite_inpaint.c b/source/blender/nodes/composite/nodes/node_composite_inpaint.c index a0d3531dabf..f97f366d0c4 100644 --- a/source/blender/nodes/composite/nodes/node_composite_inpaint.c +++ b/source/blender/nodes/composite/nodes/node_composite_inpaint.c @@ -47,7 +47,7 @@ static bNodeSocketTemplate cmp_node_inpaint_out[] = { void register_node_type_cmp_inpaint(void) { static bNodeType ntype; - + cmp_node_type_base(&ntype, CMP_NODE_INPAINT, "Inpaint", NODE_CLASS_OP_FILTER, 0); node_type_socket_templates(&ntype, cmp_node_inpaint_in, cmp_node_inpaint_out); diff --git a/source/blender/nodes/composite/nodes/node_composite_math.c b/source/blender/nodes/composite/nodes/node_composite_math.c index 276dab27f76..e40621d3210 100644 --- a/source/blender/nodes/composite/nodes/node_composite_math.c +++ b/source/blender/nodes/composite/nodes/node_composite_math.c @@ -32,7 +32,7 @@ #include "node_composite_util.h" -/* **************** SCALAR MATH ******************** */ +/* **************** SCALAR MATH ******************** */ static bNodeSocketTemplate cmp_node_math_in[] = { { SOCK_FLOAT, 1, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, { SOCK_FLOAT, 1, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, diff --git a/source/blender/nodes/composite/nodes/node_composite_moviedistortion.c b/source/blender/nodes/composite/nodes/node_composite_moviedistortion.c index 9c54009d2f1..4149a0eec9d 100644 --- a/source/blender/nodes/composite/nodes/node_composite_moviedistortion.c +++ b/source/blender/nodes/composite/nodes/node_composite_moviedistortion.c @@ -58,7 +58,7 @@ static void init(const bContext *C, PointerRNA *ptr) { bNode *node = ptr->data; Scene *scene = CTX_data_scene(C); - + node->id = (ID *)scene->clip; } diff --git a/source/blender/nodes/composite/nodes/node_composite_normalize.c b/source/blender/nodes/composite/nodes/node_composite_normalize.c index d93c62f8229..9a5cc84797e 100644 --- a/source/blender/nodes/composite/nodes/node_composite_normalize.c +++ b/source/blender/nodes/composite/nodes/node_composite_normalize.c @@ -46,9 +46,9 @@ static bNodeSocketTemplate cmp_node_normalize_out[] = { void register_node_type_cmp_normalize(void) { static bNodeType ntype; - + cmp_node_type_base(&ntype, CMP_NODE_NORMALIZE, "Normalize", NODE_CLASS_OP_VECTOR, 0); node_type_socket_templates(&ntype, cmp_node_normalize_in, cmp_node_normalize_out); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_outputFile.c b/source/blender/nodes/composite/nodes/node_composite_outputFile.c index 8b349ea8779..a2a25d5c515 100644 --- a/source/blender/nodes/composite/nodes/node_composite_outputFile.c +++ b/source/blender/nodes/composite/nodes/node_composite_outputFile.c @@ -107,16 +107,16 @@ bNodeSocket *ntreeCompositOutputFileAddSocket(bNodeTree *ntree, bNode *node, con { NodeImageMultiFile *nimf = node->storage; bNodeSocket *sock = nodeAddStaticSocket(ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, NULL, name); - + /* create format data for the input socket */ NodeImageMultiFileSocket *sockdata = MEM_callocN(sizeof(NodeImageMultiFileSocket), "socket image format"); sock->storage = sockdata; - + BLI_strncpy_utf8(sockdata->path, name, sizeof(sockdata->path)); ntreeCompositOutputFileUniquePath(&node->inputs, sock, name, '_'); BLI_strncpy_utf8(sockdata->layer, name, sizeof(sockdata->layer)); ntreeCompositOutputFileUniqueLayer(&node->inputs, sock, name, '_'); - + if (im_format) { sockdata->format = *im_format; if (BKE_imtype_is_movie(sockdata->format.imtype)) { @@ -129,7 +129,7 @@ bNodeSocket *ntreeCompositOutputFileAddSocket(bNodeTree *ntree, bNode *node, con sockdata->use_node_format = true; nimf->active_input = BLI_findindex(&node->inputs, sock); - + return sock; } @@ -138,16 +138,16 @@ int ntreeCompositOutputFileRemoveActiveSocket(bNodeTree *ntree, bNode *node) NodeImageMultiFile *nimf = node->storage; bNodeSocket *sock = BLI_findlink(&node->inputs, nimf->active_input); int totinputs = BLI_listbase_count(&node->inputs); - + if (!sock) return 0; - + if (nimf->active_input == totinputs - 1) --nimf->active_input; - + /* free format data */ MEM_freeN(sock->storage); - + nodeRemoveSocket(ntree, node, sock); return 1; } @@ -175,7 +175,7 @@ static void init_output_file(const bContext *C, PointerRNA *ptr) NodeImageMultiFile *nimf = MEM_callocN(sizeof(NodeImageMultiFile), "node image multi file"); ImageFormatData *format = NULL; node->storage = nimf; - + if (scene) { RenderData *rd = &scene->r; @@ -184,7 +184,7 @@ static void init_output_file(const bContext *C, PointerRNA *ptr) if (BKE_imtype_is_movie(nimf->format.imtype)) { nimf->format.imtype = R_IMF_IMTYPE_OPENEXR; } - + format = &nimf->format; } else @@ -197,21 +197,21 @@ static void init_output_file(const bContext *C, PointerRNA *ptr) static void free_output_file(bNode *node) { bNodeSocket *sock; - + /* free storage data in sockets */ for (sock = node->inputs.first; sock; sock = sock->next) { MEM_freeN(sock->storage); } - + MEM_freeN(node->storage); } static void copy_output_file(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, bNode *src_node) { bNodeSocket *src_sock, *dest_sock; - + dest_node->storage = MEM_dupallocN(src_node->storage); - + /* duplicate storage data in sockets */ for (src_sock = src_node->inputs.first, dest_sock = dest_node->inputs.first; src_sock && dest_sock; src_sock = src_sock->next, dest_sock = dest_sock->next) { dest_sock->storage = MEM_dupallocN(src_sock->storage); @@ -222,7 +222,7 @@ static void update_output_file(bNodeTree *ntree, bNode *node) { bNodeSocket *sock, *sock_next; PointerRNA ptr; - + /* XXX fix for #36706: remove invalid sockets added with bpy API. * This is not ideal, but prevents crashes from missing storage. * FileOutput node needs a redesign to support this properly. @@ -237,9 +237,9 @@ static void update_output_file(bNodeTree *ntree, bNode *node) sock_next = sock->next; nodeRemoveSocket(ntree, node, sock); } - + cmp_node_update_default(ntree, node); - + /* automatically update the socket type based on linked input */ for (sock = node->inputs.first; sock; sock = sock->next) { if (sock->link) { diff --git a/source/blender/nodes/composite/nodes/node_composite_splitViewer.c b/source/blender/nodes/composite/nodes/node_composite_splitViewer.c index 780ec1592bf..dbe47066f66 100644 --- a/source/blender/nodes/composite/nodes/node_composite_splitViewer.c +++ b/source/blender/nodes/composite/nodes/node_composite_splitViewer.c @@ -49,7 +49,7 @@ static void node_composit_init_splitviewer(bNodeTree *UNUSED(ntree), bNode *node iuser->fie_ima = 2; iuser->ok = 1; node->custom1 = 50; /* default 50% split */ - + node->id = (ID *)BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node"); } diff --git a/source/blender/nodes/composite/nodes/node_composite_stabilize2d.c b/source/blender/nodes/composite/nodes/node_composite_stabilize2d.c index 93ae6b6c4a4..16f5d340ddd 100644 --- a/source/blender/nodes/composite/nodes/node_composite_stabilize2d.c +++ b/source/blender/nodes/composite/nodes/node_composite_stabilize2d.c @@ -50,9 +50,9 @@ static void init(const bContext *C, PointerRNA *ptr) { bNode *node = ptr->data; Scene *scene = CTX_data_scene(C); - + node->id = (ID *)scene->clip; - + /* default to bilinear, see node_sampler_type_items in rna_nodetree.c */ node->custom1 = 1; } diff --git a/source/blender/nodes/composite/nodes/node_composite_valToRgb.c b/source/blender/nodes/composite/nodes/node_composite_valToRgb.c index 1b62f4e77d4..16fc98a5e85 100644 --- a/source/blender/nodes/composite/nodes/node_composite_valToRgb.c +++ b/source/blender/nodes/composite/nodes/node_composite_valToRgb.c @@ -77,10 +77,10 @@ static bNodeSocketTemplate cmp_node_rgbtobw_out[] = { void register_node_type_cmp_rgbtobw(void) { static bNodeType ntype; - + cmp_node_type_base(&ntype, CMP_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0); node_type_socket_templates(&ntype, cmp_node_rgbtobw_in, cmp_node_rgbtobw_out); node_type_size_preset(&ntype, NODE_SIZE_SMALL); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_viewer.c b/source/blender/nodes/composite/nodes/node_composite_viewer.c index 66f2e2bacbc..a10ba02b38e 100644 --- a/source/blender/nodes/composite/nodes/node_composite_viewer.c +++ b/source/blender/nodes/composite/nodes/node_composite_viewer.c @@ -52,7 +52,7 @@ static void node_composit_init_viewer(bNodeTree *UNUSED(ntree), bNode *node) iuser->ok = 1; node->custom3 = 0.5f; node->custom4 = 0.5f; - + node->id = (ID *)BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node"); } diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c index c465f7a9be5..4a47bf7035c 100644 --- a/source/blender/nodes/intern/node_common.c +++ b/source/blender/nodes/intern/node_common.c @@ -98,16 +98,16 @@ int nodeGroupPoll(bNodeTree *nodetree, bNodeTree *grouptree) { bNode *node; int valid = 1; - + /* unspecified node group, generally allowed * (if anything, should be avoided on operator level) */ if (grouptree == NULL) return 1; - + if (nodetree == grouptree) return 0; - + for (node = grouptree->nodes.first; node; node = node->next) { if (node->typeinfo->poll_instance && !node->typeinfo->poll_instance(node, nodetree)) { valid = 0; @@ -121,27 +121,27 @@ int nodeGroupPoll(bNodeTree *nodetree, bNodeTree *grouptree) static bNodeSocket *group_verify_socket(bNodeTree *ntree, bNode *gnode, bNodeSocket *iosock, ListBase *verify_lb, int in_out) { bNodeSocket *sock; - + for (sock = verify_lb->first; sock; sock = sock->next) { if (STREQ(sock->identifier, iosock->identifier)) break; } if (sock) { strcpy(sock->name, iosock->name); - + if (iosock->typeinfo->interface_verify_socket) iosock->typeinfo->interface_verify_socket(ntree, iosock, gnode, sock, "interface"); } else { sock = nodeAddSocket(ntree, gnode, in_out, iosock->idname, iosock->identifier, iosock->name); - + if (iosock->typeinfo->interface_init_socket) iosock->typeinfo->interface_init_socket(ntree, iosock, gnode, sock, "interface"); } - + /* remove from list temporarily, to distinguish from orphaned sockets */ BLI_remlink(verify_lb, sock); - + return sock; } @@ -150,9 +150,9 @@ static void group_verify_socket_list(bNodeTree *ntree, bNode *gnode, ListBase *iosock_lb, ListBase *verify_lb, int in_out) { bNodeSocket *iosock, *sock, *nextsock; - + /* step by step compare */ - + iosock = iosock_lb->first; for (; iosock; iosock = iosock->next) { /* abusing new_sock pointer for verification here! only used inside this function */ @@ -195,9 +195,9 @@ static void node_frame_init(bNodeTree *UNUSED(ntree), bNode *node) { NodeFrame *data = (NodeFrame *)MEM_callocN(sizeof(NodeFrame), "frame node storage"); node->storage = data; - + data->flag |= NODE_FRAME_SHRINK; - + data->label_size = 20; } @@ -211,7 +211,7 @@ void register_node_type_frame(void) node_type_storage(ntype, "NodeFrame", node_free_standard_storage, node_copy_standard_storage); node_type_size(ntype, 150, 100, 0); node_type_compatibility(ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); - + ntype->needs_free = 1; nodeRegisterType(ntype); } @@ -251,11 +251,11 @@ void register_node_type_reroute(void) { /* frame type is used for all tree types, needs dynamic allocation */ bNodeType *ntype = MEM_callocN(sizeof(bNodeType), "frame node type"); - + node_type_base(ntype, NODE_REROUTE, "Reroute", NODE_CLASS_LAYOUT, 0); node_type_init(ntype, node_reroute_init); node_type_internal_links(ntype, node_reroute_update_internal_links); - + ntype->needs_free = 1; nodeRegisterType(ntype); } @@ -267,14 +267,14 @@ static void node_reroute_inherit_type_recursive(bNodeTree *ntree, bNode *node, i bNodeLink *link; int type = SOCK_FLOAT; const char *type_idname = nodeStaticSocketType(type, PROP_NONE); - + /* XXX it would be a little bit more efficient to restrict actual updates * to rerout nodes connected to an updated node, but there's no reliable flag * to indicate updated nodes (node->update is not set on linking). */ - + node->done = 1; - + /* recursive update */ for (link = ntree->links.first; link; link = link->next) { bNode *fromnode = link->fromnode; @@ -283,7 +283,7 @@ static void node_reroute_inherit_type_recursive(bNodeTree *ntree, bNode *node, i continue; if (nodeLinkIsHidden(link)) continue; - + if (flag & REFINE_FORWARD) { if (tonode == node && fromnode->type == NODE_REROUTE && !fromnode->done) node_reroute_inherit_type_recursive(ntree, fromnode, REFINE_FORWARD); @@ -293,7 +293,7 @@ static void node_reroute_inherit_type_recursive(bNodeTree *ntree, bNode *node, i node_reroute_inherit_type_recursive(ntree, tonode, REFINE_BACKWARD); } } - + /* determine socket type from unambiguous input/output connection if possible */ if (input->limit == 1 && input->link) { type = input->link->fromsock->type; @@ -303,7 +303,7 @@ static void node_reroute_inherit_type_recursive(bNodeTree *ntree, bNode *node, i type = output->link->tosock->type; type_idname = nodeStaticSocketType(type, PROP_NONE); } - + if (input->type != type) { bNodeSocket *ninput = nodeAddSocket(ntree, node, SOCK_IN, type_idname, "input", "Input"); for (link = ntree->links.first; link; link = link->next) { @@ -314,7 +314,7 @@ static void node_reroute_inherit_type_recursive(bNodeTree *ntree, bNode *node, i } nodeRemoveSocket(ntree, node, input); } - + if (output->type != type) { bNodeSocket *noutput = nodeAddSocket(ntree, node, SOCK_OUT, type_idname, "output", "Output"); for (link = ntree->links.first; link; link = link->next) { @@ -324,7 +324,7 @@ static void node_reroute_inherit_type_recursive(bNodeTree *ntree, bNode *node, i } nodeRemoveSocket(ntree, node, output); } - + nodeUpdateInternalLinks(ntree, node); } @@ -334,11 +334,11 @@ static void node_reroute_inherit_type_recursive(bNodeTree *ntree, bNode *node, i void ntree_update_reroute_nodes(bNodeTree *ntree) { bNode *node; - + /* clear tags */ for (node = ntree->nodes.first; node; node = node->next) node->done = 0; - + for (node = ntree->nodes.first; node; node = node->next) if (node->type == NODE_REROUTE && !node->done) node_reroute_inherit_type_recursive(ntree, node, REFINE_FORWARD | REFINE_BACKWARD); @@ -411,7 +411,7 @@ void node_group_input_verify(bNodeTree *ntree, bNode *node, ID *id) if (id == (ID *)ntree) { /* value_in_out inverted for interface nodes to get correct socket value_property */ group_verify_socket_list(ntree, node, &ntree->inputs, &node->outputs, SOCK_OUT); - + /* add virtual extension socket */ nodeAddSocket(ntree, node, SOCK_OUT, "NodeSocketVirtual", "__extend__", ""); } @@ -426,23 +426,23 @@ static void node_group_input_update(bNodeTree *ntree, bNode *node) * so they can be recreated after verification. */ ListBase tmplinks; - + /* find links from the extension socket and store them */ BLI_listbase_clear(&tmplinks); for (link = ntree->links.first; link; link = linknext) { linknext = link->next; if (nodeLinkIsHidden(link)) continue; - + if (link->fromsock == extsock) { bNodeLink *tlink = MEM_callocN(sizeof(bNodeLink), "temporary link"); *tlink = *link; BLI_addtail(&tmplinks, tlink); - + nodeRemLink(ntree, link); } } - + /* find valid link to expose */ exposelink = NULL; for (link = tmplinks.first; link; link = link->next) { @@ -456,22 +456,22 @@ static void node_group_input_update(bNodeTree *ntree, bNode *node) break; } } - + if (exposelink) { bNodeSocket *gsock, *newsock; - + gsock = ntreeAddSocketInterfaceFromSocket(ntree, exposelink->tonode, exposelink->tosock); - + node_group_input_verify(ntree, node, (ID *)ntree); newsock = node_group_input_find_socket(node, gsock->identifier); - + /* redirect links from the extension socket */ for (link = tmplinks.first; link; link = link->next) { nodeAddLink(ntree, node, newsock, link->tonode, link->tosock); } - + } - + BLI_freelistN(&tmplinks); } @@ -479,13 +479,13 @@ void register_node_type_group_input(void) { /* used for all tree types, needs dynamic allocation */ bNodeType *ntype = MEM_callocN(sizeof(bNodeType), "node type"); - + node_type_base(ntype, NODE_GROUP_INPUT, "Group Input", NODE_CLASS_INTERFACE, 0); node_type_size(ntype, 140, 80, 400); node_type_init(ntype, node_group_input_init); node_type_update(ntype, node_group_input_update, node_group_input_verify); node_type_compatibility(ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); - + ntype->needs_free = 1; nodeRegisterType(ntype); } @@ -510,7 +510,7 @@ void node_group_output_verify(bNodeTree *ntree, bNode *node, ID *id) if (id == (ID *)ntree) { /* value_in_out inverted for interface nodes to get correct socket value_property */ group_verify_socket_list(ntree, node, &ntree->outputs, &node->inputs, SOCK_IN); - + /* add virtual extension socket */ nodeAddSocket(ntree, node, SOCK_IN, "NodeSocketVirtual", "__extend__", ""); } @@ -525,23 +525,23 @@ static void node_group_output_update(bNodeTree *ntree, bNode *node) * so they can be recreated after verification. */ ListBase tmplinks; - + /* find links to the extension socket and store them */ BLI_listbase_clear(&tmplinks); for (link = ntree->links.first; link; link = linknext) { linknext = link->next; if (nodeLinkIsHidden(link)) continue; - + if (link->tosock == extsock) { bNodeLink *tlink = MEM_callocN(sizeof(bNodeLink), "temporary link"); *tlink = *link; BLI_addtail(&tmplinks, tlink); - + nodeRemLink(ntree, link); } } - + /* find valid link to expose */ exposelink = NULL; for (link = tmplinks.first; link; link = link->next) { @@ -555,22 +555,22 @@ static void node_group_output_update(bNodeTree *ntree, bNode *node) break; } } - + if (exposelink) { bNodeSocket *gsock, *newsock; - + /* XXX what if connecting virtual to virtual socket?? */ gsock = ntreeAddSocketInterfaceFromSocket(ntree, exposelink->fromnode, exposelink->fromsock); - + node_group_output_verify(ntree, node, (ID *)ntree); newsock = node_group_output_find_socket(node, gsock->identifier); - + /* redirect links to the extension socket */ for (link = tmplinks.first; link; link = link->next) { nodeAddLink(ntree, link->fromnode, link->fromsock, node, newsock); } } - + BLI_freelistN(&tmplinks); } @@ -578,13 +578,13 @@ void register_node_type_group_output(void) { /* used for all tree types, needs dynamic allocation */ bNodeType *ntype = MEM_callocN(sizeof(bNodeType), "node type"); - + node_type_base(ntype, NODE_GROUP_OUTPUT, "Group Output", NODE_CLASS_INTERFACE, 0); node_type_size(ntype, 140, 80, 400); node_type_init(ntype, node_group_output_init); node_type_update(ntype, node_group_output_update, node_group_output_verify); node_type_compatibility(ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); - + ntype->needs_free = 1; nodeRegisterType(ntype); } diff --git a/source/blender/nodes/intern/node_exec.c b/source/blender/nodes/intern/node_exec.c index 9782c2f4a2c..a5be5dad534 100644 --- a/source/blender/nodes/intern/node_exec.c +++ b/source/blender/nodes/intern/node_exec.c @@ -61,14 +61,14 @@ bNodeStack *node_get_socket_stack(bNodeStack *stack, bNodeSocket *sock) void node_get_stack(bNode *node, bNodeStack *stack, bNodeStack **in, bNodeStack **out) { bNodeSocket *sock; - + /* build pointer stack */ if (in) { for (sock = node->inputs.first; sock; sock = sock->next) { *(in++) = node_get_socket_stack(stack, sock); } } - + if (out) { for (sock = node->outputs.first; sock; sock = sock->next) { *(out++) = node_get_socket_stack(stack, sock); @@ -127,13 +127,13 @@ static struct bNodeStack *setup_stack(bNodeStack *stack, bNodeTree *ntree, bNode bNodeStack *ns = node_get_socket_stack(stack, sock); if (!ns) return NULL; - + /* don't mess with remote socket stacks, these are initialized by other nodes! */ if (sock->link) return ns; - + ns->sockettype = sock->type; - + switch (sock->type) { case SOCK_FLOAT: ns->vec[0] = node_socket_get_float(ntree, node, sock); @@ -145,7 +145,7 @@ static struct bNodeStack *setup_stack(bNodeStack *stack, bNodeTree *ntree, bNode node_socket_get_color(ntree, node, sock, ns->vec); break; } - + return ns; } @@ -161,29 +161,29 @@ bNodeTreeExec *ntree_exec_begin(bNodeExecContext *context, bNodeTree *ntree, bNo bNode **nodelist; int totnodes, n; /* XXX texnodes have threading issues with muting, have to disable it there ... */ - + /* ensure all sock->link pointers and node levels are correct */ ntreeUpdateTree(G.main, ntree); - + /* get a dependency-sorted list of nodes */ ntreeGetDependencyList(ntree, &nodelist, &totnodes); - + /* XXX could let callbacks do this for specialized data */ exec = MEM_callocN(sizeof(bNodeTreeExec), "node tree execution data"); /* backpointer to node tree */ exec->nodetree = ntree; - + /* set stack indices */ index = 0; for (n = 0; n < totnodes; ++n) { node = nodelist[n]; - + node->stack_index = index; - + /* init node socket stack indexes */ for (sock = node->inputs.first; sock; sock = sock->next) node_init_input_index(sock, &index); - + if (node->flag & NODE_MUTED || node->type == NODE_REROUTE) { for (sock = node->outputs.first; sock; sock = sock->next) node_init_output_index(sock, &index, &node->internal_links); @@ -193,48 +193,48 @@ bNodeTreeExec *ntree_exec_begin(bNodeExecContext *context, bNodeTree *ntree, bNo node_init_output_index(sock, &index, NULL); } } - + /* allocated exec data pointers for nodes */ exec->totnodes = totnodes; exec->nodeexec = MEM_callocN(exec->totnodes * sizeof(bNodeExec), "node execution data"); /* allocate data pointer for node stack */ exec->stacksize = index; exec->stack = MEM_callocN(exec->stacksize * sizeof(bNodeStack), "bNodeStack"); - + /* all non-const results are considered inputs */ for (n = 0; n < exec->stacksize; ++n) exec->stack[n].hasinput = 1; - + /* prepare all nodes for execution */ for (n = 0, nodeexec = exec->nodeexec; n < totnodes; ++n, ++nodeexec) { node = nodeexec->node = nodelist[n]; nodeexec->freeexecfunc = node->typeinfo->freeexecfunc; - + /* tag inputs */ for (sock = node->inputs.first; sock; sock = sock->next) { /* disable the node if an input link is invalid */ if (sock->link && !(sock->link->flag & NODE_LINK_VALID)) node->need_exec = 0; - + ns = setup_stack(exec->stack, ntree, node, sock); if (ns) ns->hasoutput = 1; } - + /* tag all outputs */ for (sock = node->outputs.first; sock; sock = sock->next) { /* ns = */ setup_stack(exec->stack, ntree, node, sock); } - + nodekey = BKE_node_instance_key(parent_key, ntree, node); nodeexec->data.preview = context->previews ? BKE_node_instance_hash_lookup(context->previews, nodekey) : NULL; if (node->typeinfo->initexecfunc) nodeexec->data.data = node->typeinfo->initexecfunc(context, node, nodekey); } - + if (nodelist) MEM_freeN(nodelist); - + return exec; } @@ -242,18 +242,18 @@ void ntree_exec_end(bNodeTreeExec *exec) { bNodeExec *nodeexec; int n; - + if (exec->stack) MEM_freeN(exec->stack); - + for (n = 0, nodeexec = exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) { if (nodeexec->freeexecfunc) nodeexec->freeexecfunc(nodeexec->data.data); } - + if (exec->nodeexec) MEM_freeN(exec->nodeexec); - + MEM_freeN(exec); } @@ -263,14 +263,14 @@ bNodeThreadStack *ntreeGetThreadStack(bNodeTreeExec *exec, int thread) { ListBase *lb = &exec->threadstack[thread]; bNodeThreadStack *nts; - + for (nts = lb->first; nts; nts = nts->next) { if (!nts->used) { nts->used = true; break; } } - + if (!nts) { nts = MEM_callocN(sizeof(bNodeThreadStack), "bNodeThreadStack"); nts->stack = MEM_dupallocN(exec->stack); @@ -293,9 +293,9 @@ bool ntreeExecThreadNodes(bNodeTreeExec *exec, bNodeThreadStack *nts, void *call bNodeExec *nodeexec; bNode *node; int n; - + /* nodes are presorted, so exec is in order of list */ - + for (n = 0, nodeexec = exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) { node = nodeexec->node; if (node->need_exec) { @@ -310,7 +310,7 @@ bool ntreeExecThreadNodes(bNodeTreeExec *exec, bNodeThreadStack *nts, void *call node->typeinfo->execfunc(callerdata, thread, node, &nodeexec->data, nsin, nsout); } } - + /* signal to that all went OK, for render */ return true; } diff --git a/source/blender/nodes/intern/node_exec.h b/source/blender/nodes/intern/node_exec.h index bf4c29bad8e..6771df76bf9 100644 --- a/source/blender/nodes/intern/node_exec.h +++ b/source/blender/nodes/intern/node_exec.h @@ -51,17 +51,17 @@ struct bNodeStack; typedef struct bNodeExec { struct bNode *node; /* backpointer to node */ bNodeExecData data; - + NodeFreeExecFunction freeexecfunc; /* free function, stored in exec itself to avoid dangling node pointer access */ } bNodeExec; /* Execution Data for each instance of node tree execution */ typedef struct bNodeTreeExec { struct bNodeTree *nodetree; /* backpointer to node tree */ - + int totnodes; /* total node count */ struct bNodeExec *nodeexec; /* per-node execution data */ - + int stacksize; struct bNodeStack *stack; /* socket data stack */ /* only used by material and texture trees to keep one stack for each thread */ diff --git a/source/blender/nodes/intern/node_socket.c b/source/blender/nodes/intern/node_socket.c index 6e2cdb65a86..d1903a53334 100644 --- a/source/blender/nodes/intern/node_socket.c +++ b/source/blender/nodes/intern/node_socket.c @@ -52,9 +52,9 @@ struct Main; struct bNodeSocket *node_add_socket_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp, int in_out) { bNodeSocket *sock = nodeAddStaticSocket(ntree, node, in_out, stemp->type, stemp->subtype, stemp->identifier, stemp->name); - + sock->flag |= stemp->flag; - + /* initialize default_value */ switch (stemp->type) { case SOCK_FLOAT: @@ -99,14 +99,14 @@ struct bNodeSocket *node_add_socket_from_template(struct bNodeTree *ntree, struc break; } } - + return sock; } static bNodeSocket *verify_socket_template(bNodeTree *ntree, bNode *node, int in_out, ListBase *socklist, bNodeSocketTemplate *stemp) { bNodeSocket *sock; - + for (sock = socklist->first; sock; sock = sock->next) { if (STREQLEN(sock->name, stemp->name, NODE_MAXSTR)) break; @@ -127,7 +127,7 @@ static bNodeSocket *verify_socket_template(bNodeTree *ntree, bNode *node, int in /* remove the new socket from the node socket list first, * will be added back after verification. */ BLI_remlink(socklist, sock); - + return sock; } @@ -135,7 +135,7 @@ static void verify_socket_template_list(bNodeTree *ntree, bNode *node, int in_ou { bNodeSocket *sock, *nextsock; bNodeSocketTemplate *stemp; - + /* no inputs anymore? */ if (stemp_first == NULL) { for (sock = (bNodeSocket *)socklist->first; sock; sock = nextsock) { @@ -155,7 +155,7 @@ static void verify_socket_template_list(bNodeTree *ntree, bNode *node, int in_ou nextsock = sock->next; nodeRemoveSocket(ntree, node, sock); } - + /* and we put back the verified sockets */ stemp = stemp_first; if (socklist->first) { @@ -199,10 +199,10 @@ void node_socket_init_default_value(bNodeSocket *sock) { int type = sock->typeinfo->type; int subtype = sock->typeinfo->subtype; - + if (sock->default_value) return; /* already initialized */ - + switch (type) { case SOCK_FLOAT: { @@ -211,7 +211,7 @@ void node_socket_init_default_value(bNodeSocket *sock) dval->value = 0.0f; dval->min = -FLT_MAX; dval->max = FLT_MAX; - + sock->default_value = dval; break; } @@ -222,7 +222,7 @@ void node_socket_init_default_value(bNodeSocket *sock) dval->value = 0; dval->min = INT_MIN; dval->max = INT_MAX; - + sock->default_value = dval; break; } @@ -230,7 +230,7 @@ void node_socket_init_default_value(bNodeSocket *sock) { bNodeSocketValueBoolean *dval = MEM_callocN(sizeof(bNodeSocketValueBoolean), "node socket value bool"); dval->value = false; - + sock->default_value = dval; break; } @@ -242,7 +242,7 @@ void node_socket_init_default_value(bNodeSocket *sock) copy_v3_v3(dval->value, default_value); dval->min = -FLT_MAX; dval->max = FLT_MAX; - + sock->default_value = dval; break; } @@ -251,7 +251,7 @@ void node_socket_init_default_value(bNodeSocket *sock) static float default_value[] = { 0.0f, 0.0f, 0.0f, 1.0f }; bNodeSocketValueRGBA *dval = MEM_callocN(sizeof(bNodeSocketValueRGBA), "node socket value color"); copy_v4_v4(dval->value, default_value); - + sock->default_value = dval; break; } @@ -260,7 +260,7 @@ void node_socket_init_default_value(bNodeSocket *sock) bNodeSocketValueString *dval = MEM_callocN(sizeof(bNodeSocketValueString), "node socket value string"); dval->subtype = subtype; dval->value[0] = '\0'; - + sock->default_value = dval; break; } @@ -272,12 +272,12 @@ void node_socket_copy_default_value(bNodeSocket *to, bNodeSocket *from) /* sanity check */ if (to->type != from->type) return; - + /* make sure both exist */ if (!from->default_value) return; node_socket_init_default_value(to); - + switch (from->typeinfo->type) { case SOCK_FLOAT: { @@ -330,7 +330,7 @@ static void standard_node_socket_interface_init_socket(bNodeTree *UNUSED(ntree), { /* initialize the type value */ sock->type = sock->typeinfo->type; - + /* XXX socket interface 'type' value is not used really, * but has to match or the copy function will bail out */ @@ -345,12 +345,12 @@ static void standard_node_socket_interface_verify_socket(bNodeTree *UNUSED(ntree /* sanity check */ if (sock->type != stemp->typeinfo->type) return; - + /* make sure both exist */ if (!stemp->default_value) return; node_socket_init_default_value(sock); - + switch (stemp->typeinfo->type) { case SOCK_FLOAT: { @@ -389,65 +389,65 @@ static void standard_node_socket_interface_from_socket(bNodeTree *UNUSED(ntree), static bNodeSocketType *make_standard_socket_type(int type, int subtype) { extern void ED_init_standard_node_socket_type(bNodeSocketType *); - + const char *socket_idname = nodeStaticSocketType(type, subtype); const char *interface_idname = nodeStaticSocketInterfaceType(type, subtype); bNodeSocketType *stype; StructRNA *srna; - + stype = MEM_callocN(sizeof(bNodeSocketType), "node socket C type"); BLI_strncpy(stype->idname, socket_idname, sizeof(stype->idname)); - + /* set the RNA type * uses the exact same identifier as the socket type idname */ srna = stype->ext_socket.srna = RNA_struct_find(socket_idname); BLI_assert(srna != NULL); /* associate the RNA type with the socket type */ RNA_struct_blender_type_set(srna, stype); - + /* set the interface RNA type */ srna = stype->ext_interface.srna = RNA_struct_find(interface_idname); BLI_assert(srna != NULL); /* associate the RNA type with the socket type */ RNA_struct_blender_type_set(srna, stype); - + /* extra type info for standard socket types */ stype->type = type; stype->subtype = subtype; - + /* XXX bad-level call! needed for setting draw callbacks */ ED_init_standard_node_socket_type(stype); - + stype->interface_init_socket = standard_node_socket_interface_init_socket; stype->interface_from_socket = standard_node_socket_interface_from_socket; stype->interface_verify_socket = standard_node_socket_interface_verify_socket; - + return stype; } static bNodeSocketType *make_socket_type_virtual(void) { extern void ED_init_node_socket_type_virtual(bNodeSocketType *); - + const char *socket_idname = "NodeSocketVirtual"; bNodeSocketType *stype; StructRNA *srna; - + stype = MEM_callocN(sizeof(bNodeSocketType), "node socket C type"); BLI_strncpy(stype->idname, socket_idname, sizeof(stype->idname)); - + /* set the RNA type * uses the exact same identifier as the socket type idname */ srna = stype->ext_socket.srna = RNA_struct_find(socket_idname); BLI_assert(srna != NULL); /* associate the RNA type with the socket type */ RNA_struct_blender_type_set(srna, stype); - + /* extra type info for standard socket types */ stype->type = SOCK_CUSTOM; - + ED_init_node_socket_type_virtual(stype); - + return stype; } @@ -455,21 +455,21 @@ static bNodeSocketType *make_socket_type_virtual(void) void register_standard_node_socket_types(void) { /* draw callbacks are set in drawnode.c to avoid bad-level calls */ - + nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_NONE)); nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_UNSIGNED)); nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_PERCENTAGE)); nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_FACTOR)); nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_ANGLE)); nodeRegisterSocketType(make_standard_socket_type(SOCK_FLOAT, PROP_TIME)); - + nodeRegisterSocketType(make_standard_socket_type(SOCK_INT, PROP_NONE)); nodeRegisterSocketType(make_standard_socket_type(SOCK_INT, PROP_UNSIGNED)); nodeRegisterSocketType(make_standard_socket_type(SOCK_INT, PROP_PERCENTAGE)); nodeRegisterSocketType(make_standard_socket_type(SOCK_INT, PROP_FACTOR)); - + nodeRegisterSocketType(make_standard_socket_type(SOCK_BOOLEAN, PROP_NONE)); - + nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_NONE)); nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_TRANSLATION)); nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_DIRECTION)); @@ -477,12 +477,12 @@ void register_standard_node_socket_types(void) nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_ACCELERATION)); nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_EULER)); nodeRegisterSocketType(make_standard_socket_type(SOCK_VECTOR, PROP_XYZ)); - + nodeRegisterSocketType(make_standard_socket_type(SOCK_RGBA, PROP_NONE)); - + nodeRegisterSocketType(make_standard_socket_type(SOCK_STRING, PROP_NONE)); - + nodeRegisterSocketType(make_standard_socket_type(SOCK_SHADER, PROP_NONE)); - + nodeRegisterSocketType(make_socket_type_virtual()); } diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c index 45409a2dfad..19529794c7c 100644 --- a/source/blender/nodes/intern/node_util.c +++ b/source/blender/nodes/intern/node_util.c @@ -165,10 +165,10 @@ static int node_count_links(bNodeTree *ntree, bNodeSocket *sock) static bNodeSocket *node_find_linkable_socket(bNodeTree *ntree, bNode *node, bNodeSocket *cur) { /* link swapping: try to find a free slot with a matching name */ - + bNodeSocket *first = cur->in_out == SOCK_IN ? node->inputs.first : node->outputs.first; bNodeSocket *sock; - + sock = cur->next ? cur->next : first; /* wrap around the list end */ while (sock != cur) { if (!nodeSocketIsHidden(sock) && node_link_socket_match(sock, cur)) { @@ -177,7 +177,7 @@ static bNodeSocket *node_find_linkable_socket(bNodeTree *ntree, bNode *node, bNo if (link_count + 1 <= sock->limit) return sock; /* found a valid free socket we can swap to */ } - + sock = sock->next ? sock->next : first; /* wrap around the list end */ } return NULL; @@ -187,18 +187,18 @@ void node_insert_link_default(bNodeTree *ntree, bNode *node, bNodeLink *link) { bNodeSocket *sock = link->tosock; bNodeLink *tlink, *tlink_next; - + /* inputs can have one link only, outputs can have unlimited links */ if (node != link->tonode) return; - + for (tlink = ntree->links.first; tlink; tlink = tlink_next) { bNodeSocket *new_sock; tlink_next = tlink->next; - + if (sock != tlink->tosock) continue; - + new_sock = node_find_linkable_socket(ntree, node, sock); if (new_sock && new_sock != sock) { /* redirect existing link */ @@ -287,12 +287,12 @@ static bNodeSocket *select_internal_link_input(bNode *node, bNodeSocket *output) int i; int sel_priority = -1; bool sel_is_linked = false; - + for (input = node->inputs.first, i = 0; input; input = input->next, ++i) { int priority = node_datatype_priority(input->type, output->type); bool is_linked = (input->link != NULL); bool preferred; - + if (nodeSocketIsHidden(input) || /* ignore hidden sockets */ input->flag & SOCK_NO_INTERNAL_LINK || /* ignore if input is not allowed for internal connections */ priority < 0 || /* ignore incompatible types */ @@ -300,18 +300,18 @@ static bNodeSocket *select_internal_link_input(bNode *node, bNodeSocket *output) { continue; } - + /* determine if this input is preferred over the currently selected */ preferred = (priority > sel_priority) || /* prefer higher datatype priority */ (is_linked && !sel_is_linked); /* prefer linked over unlinked */ - + if (preferred) { selected = input; sel_is_linked = is_linked; sel_priority = priority; } } - + return selected; } @@ -319,29 +319,29 @@ void node_update_internal_links_default(bNodeTree *ntree, bNode *node) { bNodeLink *link; bNodeSocket *output, *input; - + /* sanity check */ if (!ntree) return; - + /* use link pointer as a tag for handled sockets (for outputs is unused anyway) */ for (output = node->outputs.first; output; output = output->next) output->link = NULL; - + for (link = ntree->links.first; link; link = link->next) { if (nodeLinkIsHidden(link)) continue; - + output = link->fromsock; if (link->fromnode != node || output->link) continue; if (nodeSocketIsHidden(output) || output->flag & SOCK_NO_INTERNAL_LINK) continue; output->link = link; /* not really used, just for tagging handled sockets */ - + /* look for suitable input */ input = select_internal_link_input(node, output); - + if (input) { bNodeLink *ilink = MEM_callocN(sizeof(bNodeLink), "internal node link"); ilink->fromnode = node; @@ -353,7 +353,7 @@ void node_update_internal_links_default(bNodeTree *ntree, bNode *node) BLI_addtail(&node->internal_links, ilink); } } - + /* clean up */ for (output = node->outputs.first; output; output = output->next) output->link = NULL; diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index 420dbc431d1..34ec76df710 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -80,7 +80,7 @@ static void shader_get_from_context(const bContext *C, bNodeTreeType *UNUSED(tre SpaceNode *snode = CTX_wm_space_node(C); Scene *scene = CTX_data_scene(C); Object *ob = OBACT; - + if ((snode->shaderfrom == SNODE_SHADER_OBJECT) || (BKE_scene_use_new_shading_nodes(scene) == false)) { @@ -127,7 +127,7 @@ static void foreach_nodeclass(Scene *scene, void *calldata, bNodeClassCallback f func(calldata, NODE_CLASS_SHADER, N_("Shader")); func(calldata, NODE_CLASS_TEXTURE, N_("Texture")); } - + func(calldata, NODE_CLASS_OP_COLOR, N_("Color")); func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector")); func(calldata, NODE_CLASS_CONVERTOR, N_("Convertor")); @@ -140,11 +140,11 @@ static void foreach_nodeclass(Scene *scene, void *calldata, bNodeClassCallback f static void localize(bNodeTree *localtree, bNodeTree *UNUSED(ntree)) { bNode *node, *node_next; - + /* replace muted nodes and reroute nodes by internal links */ for (node = localtree->nodes.first; node; node = node_next) { node_next = node->next; - + if (node->flag & NODE_MUTED || node->type == NODE_REROUTE) { nodeInternalRelink(localtree, node); nodeFreeNode(localtree, node); @@ -165,9 +165,9 @@ static void local_merge(bNodeTree *localtree, bNodeTree *ntree) static void update(bNodeTree *ntree) { ntreeSetOutput(ntree); - + ntree_update_reroute_nodes(ntree); - + if (ntree->update & NTREE_UPDATE_NODES) { /* clean up preview cache, in case nodes have been removed */ BKE_node_preview_remove_unused(ntree); @@ -179,13 +179,13 @@ bNodeTreeType *ntreeType_Shader; void register_node_tree_type_sh(void) { bNodeTreeType *tt = ntreeType_Shader = MEM_callocN(sizeof(bNodeTreeType), "shader node tree type"); - + tt->type = NTREE_SHADER; strcpy(tt->idname, "ShaderNodeTree"); strcpy(tt->ui_name, "Shader"); tt->ui_icon = 0; /* defined in drawnode.c */ strcpy(tt->ui_description, "Shader nodes"); - + tt->foreach_nodeclass = foreach_nodeclass; tt->localize = localize; tt->local_sync = local_sync; @@ -193,9 +193,9 @@ void register_node_tree_type_sh(void) tt->update = update; tt->poll = shader_tree_poll; tt->get_from_context = shader_get_from_context; - + tt->ext.srna = &RNA_ShaderNodeTree; - + ntreeTypeAdd(tt); } @@ -524,19 +524,19 @@ bNodeTreeExec *ntreeShaderBeginExecTree_internal(bNodeExecContext *context, bNod { bNodeTreeExec *exec; bNode *node; - + /* ensures only a single output node is enabled */ ntreeSetOutput(ntree); - + /* common base initialization */ exec = ntree_exec_begin(context, ntree, parent_key); - + /* allocate the thread stack listbase array */ exec->threadstack = MEM_callocN(BLENDER_MAX_THREADS * sizeof(ListBase), "thread stack array"); - + for (node = exec->nodetree->nodes.first; node; node = node->next) node->need_exec = 1; - + return exec; } @@ -544,22 +544,22 @@ bNodeTreeExec *ntreeShaderBeginExecTree(bNodeTree *ntree) { bNodeExecContext context; bNodeTreeExec *exec; - + /* XXX hack: prevent exec data from being generated twice. * this should be handled by the renderer! */ if (ntree->execdata) return ntree->execdata; - + context.previews = ntree->previews; - + exec = ntreeShaderBeginExecTree_internal(&context, ntree, NODE_INSTANCE_KEY_BASE); - + /* XXX this should not be necessary, but is still used for cmp/sha/tex nodes, * which only store the ntree pointer. Should be fixed at some point! */ ntree->execdata = exec; - + return exec; } @@ -567,18 +567,18 @@ void ntreeShaderEndExecTree_internal(bNodeTreeExec *exec) { bNodeThreadStack *nts; int a; - + if (exec->threadstack) { for (a = 0; a < BLENDER_MAX_THREADS; a++) { for (nts = exec->threadstack[a].first; nts; nts = nts->next) if (nts->stack) MEM_freeN(nts->stack); BLI_freelistN(&exec->threadstack[a]); } - + MEM_freeN(exec->threadstack); exec->threadstack = NULL; } - + ntree_exec_end(exec); } @@ -588,7 +588,7 @@ void ntreeShaderEndExecTree(bNodeTreeExec *exec) /* exec may get freed, so assign ntree */ bNodeTree *ntree = exec->nodetree; ntreeShaderEndExecTree_internal(exec); - + /* XXX clear nodetree backpointer to exec data, same problem as noted in ntreeBeginExecTree */ ntree->execdata = NULL; } @@ -606,14 +606,14 @@ bool ntreeShaderExecTree(bNodeTree *ntree, ShadeInput *shi, ShadeResult *shr) bNodeThreadStack *nts = NULL; bNodeTreeExec *exec = ntree->execdata; int compat; - + /* convert caller data to struct */ scd.shi = shi; scd.shr = shr; - + /* each material node has own local shaderesult, with optional copying */ memset(shr, 0, sizeof(ShadeResult)); - + /* ensure execdata is only initialized once */ if (!exec) { BLI_thread_lock(LOCK_NODES); @@ -623,19 +623,19 @@ bool ntreeShaderExecTree(bNodeTree *ntree, ShadeInput *shi, ShadeResult *shr) exec = ntree->execdata; } - + nts = ntreeGetThreadStack(exec, shi->thread); compat = ntreeExecThreadNodes(exec, nts, &scd, shi->thread); ntreeReleaseThreadStack(nts); - + // \note: set material back to preserved material shi->mat = mat; - + /* better not allow negative for now */ if (shr->combined[0] < 0.0f) shr->combined[0] = 0.0f; if (shr->combined[1] < 0.0f) shr->combined[1] = 0.0f; if (shr->combined[2] < 0.0f) shr->combined[2] = 0.0f; - + /* if compat is zero, it has been using non-compatible nodes */ return compat; } diff --git a/source/blender/nodes/shader/node_shader_util.c b/source/blender/nodes/shader/node_shader_util.c index da8b0ee42be..b25a6c2bba0 100644 --- a/source/blender/nodes/shader/node_shader_util.c +++ b/source/blender/nodes/shader/node_shader_util.c @@ -45,7 +45,7 @@ int sh_node_poll_default(bNodeType *UNUSED(ntype), bNodeTree *ntree) void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag) { node_type_base(ntype, type, name, nclass, flag); - + ntype->poll = sh_node_poll_default; ntype->insert_link = node_insert_link_default; ntype->update_internal_links = node_update_internal_links_default; @@ -56,11 +56,11 @@ void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, shor void nodestack_get_vec(float *in, short type_in, bNodeStack *ns) { const float *from = ns->vec; - + if (type_in == SOCK_FLOAT) { if (ns->sockettype == SOCK_FLOAT) *in = *from; - else + else *in = (from[0] + from[1] + from[2]) / 3.0f; } else if (type_in == SOCK_VECTOR) { @@ -98,7 +98,7 @@ void ntreeShaderGetTexcoMode(bNodeTree *ntree, int r_mode, short *texco, int *mo bNode *node; bNodeSocket *sock; int a; - + for (node = ntree->nodes.first; node; node = node->next) { if (node->type == SH_NODE_TEXTURE) { if ((r_mode & R_OSA) && node->id) { @@ -117,15 +117,15 @@ void ntreeShaderGetTexcoMode(bNodeTree *ntree, int r_mode, short *texco, int *mo for (a = 0, sock = node->outputs.first; sock; sock = sock->next, a++) { if (sock->flag & SOCK_IN_USE) { switch (a) { - case GEOM_OUT_GLOB: + case GEOM_OUT_GLOB: *texco |= TEXCO_GLOB | NEED_UV; break; - case GEOM_OUT_VIEW: + case GEOM_OUT_VIEW: *texco |= TEXCO_VIEW | NEED_UV; break; - case GEOM_OUT_ORCO: + case GEOM_OUT_ORCO: *texco |= TEXCO_ORCO | NEED_UV; break; - case GEOM_OUT_UV: + case GEOM_OUT_UV: *texco |= TEXCO_UV | NEED_UV; break; - case GEOM_OUT_NORMAL: + case GEOM_OUT_NORMAL: *texco |= TEXCO_NORM | NEED_UV; break; case GEOM_OUT_VCOL: *texco |= NEED_UV; *mode |= MA_VERTEXCOL; break; @@ -141,7 +141,7 @@ void ntreeShaderGetTexcoMode(bNodeTree *ntree, int r_mode, short *texco, int *mo void node_gpu_stack_from_data(struct GPUNodeStack *gs, int type, bNodeStack *ns) { memset(gs, 0, sizeof(*gs)); - + if (ns == NULL) { /* node_get_stack() will generate NULL bNodeStack pointers for unknown/unsuported types of sockets... */ zero_v4(gs->vec); @@ -155,7 +155,7 @@ void node_gpu_stack_from_data(struct GPUNodeStack *gs, int type, bNodeStack *ns) else { nodestack_get_vec(gs->vec, type, ns); gs->link = ns->data; - + if (type == SOCK_FLOAT) gs->type = GPU_FLOAT; else if (type == SOCK_VECTOR) @@ -189,10 +189,10 @@ static void gpu_stack_from_data_list(GPUNodeStack *gs, ListBase *sockets, bNodeS { bNodeSocket *sock; int i; - + for (sock = sockets->first, i = 0; sock; sock = sock->next, i++) node_gpu_stack_from_data(&gs[i], sock->type, ns[i]); - + gs[i].type = GPU_NONE; } @@ -241,7 +241,7 @@ bNode *nodeGetActiveTexture(bNodeTree *ntree) if (activetexnode) return activetexnode; - + if (hasgroup) { /* node active texture node in this tree, look inside groups */ for (node = ntree->nodes.first; node; node = node->next) { @@ -252,7 +252,7 @@ bNode *nodeGetActiveTexture(bNodeTree *ntree) } } } - + return inactivenode; } @@ -271,7 +271,7 @@ void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial *mat, int do_outputs, sh for (n = 0, nodeexec = exec->nodeexec; n < exec->totnodes; ++n, ++nodeexec) { node = nodeexec->node; - + do_it = false; /* for groups, only execute outputs for edited group */ if (node->typeinfo->nclass == NODE_CLASS_OUTPUT) { diff --git a/source/blender/nodes/shader/nodes/node_shader_brightness.c b/source/blender/nodes/shader/nodes/node_shader_brightness.c index 75a3f7ca5a2..75e258bd27d 100644 --- a/source/blender/nodes/shader/nodes/node_shader_brightness.c +++ b/source/blender/nodes/shader/nodes/node_shader_brightness.c @@ -50,13 +50,13 @@ static int gpu_shader_brightcontrast(GPUMaterial *mat, bNode *UNUSED(node), bNod void register_node_type_sh_brightcontrast(void) { static bNodeType ntype; - + sh_node_type_base(&ntype, SH_NODE_BRIGHTCONTRAST, "Bright/Contrast", NODE_CLASS_OP_COLOR, 0); node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_brightcontrast_in, sh_node_brightcontrast_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); node_type_gpu(&ntype, gpu_shader_brightcontrast); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_bump.c b/source/blender/nodes/shader/nodes/node_shader_bump.c index 65da3485fc3..41df17cef67 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bump.c +++ b/source/blender/nodes/shader/nodes/node_shader_bump.c @@ -31,7 +31,7 @@ #include "node_shader_util.h" -/* **************** BUMP ******************** */ +/* **************** BUMP ******************** */ static bNodeSocketTemplate sh_node_bump_in[] = { { SOCK_FLOAT, 1, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, { SOCK_FLOAT, 1, N_("Distance"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, diff --git a/source/blender/nodes/shader/nodes/node_shader_camera.c b/source/blender/nodes/shader/nodes/node_shader_camera.c index 869f24537ef..b1c3a817b84 100644 --- a/source/blender/nodes/shader/nodes/node_shader_camera.c +++ b/source/blender/nodes/shader/nodes/node_shader_camera.c @@ -45,7 +45,7 @@ static void node_shader_exec_camera(void *data, int UNUSED(thread), bNode *UNUSE { if (data) { ShadeInput *shi = ((ShaderCallData *)data)->shi; /* Data we need for shading. */ - + copy_v3_v3(out[0]->vec, shi->co); /* get view vector */ out[1]->vec[0] = fabsf(shi->co[2]); /* get view z-depth */ out[2]->vec[0] = normalize_v3(out[0]->vec); /* get view distance */ diff --git a/source/blender/nodes/shader/nodes/node_shader_common.c b/source/blender/nodes/shader/nodes/node_shader_common.c index 134319cb352..24de03dbda4 100644 --- a/source/blender/nodes/shader/nodes/node_shader_common.c +++ b/source/blender/nodes/shader/nodes/node_shader_common.c @@ -50,7 +50,7 @@ static void copy_stack(bNodeStack *to, bNodeStack *from) copy_v4_v4(to->vec, from->vec); to->data = from->data; to->datatype = from->datatype; - + /* tag as copy to prevent freeing */ to->is_copy = 1; } @@ -63,7 +63,7 @@ static void move_stack(bNodeStack *to, bNodeStack *from) to->data = from->data; to->datatype = from->datatype; to->is_copy = from->is_copy; - + from->data = NULL; from->is_copy = 0; } @@ -75,20 +75,20 @@ static void *group_initexec(bNodeExecContext *context, bNode *node, bNodeInstanc { bNodeTree *ngroup = (bNodeTree *)node->id; bNodeTreeExec *exec; - + if (!ngroup) return NULL; - + /* initialize the internal node tree execution */ exec = ntreeShaderBeginExecTree_internal(context, ngroup, key); - + return exec; } static void group_freeexec(void *nodedata) { bNodeTreeExec *gexec = (bNodeTreeExec *)nodedata; - + if (gexec) ntreeShaderEndExecTree_internal(gexec); } @@ -102,7 +102,7 @@ static void group_copy_inputs(bNode *gnode, bNodeStack **in, bNodeStack *gstack) bNodeSocket *sock; bNodeStack *ns; int a; - + for (node = ngroup->nodes.first; node; node = node->next) { if (node->type == NODE_GROUP_INPUT) { for (sock = node->outputs.first, a = 0; sock; sock = sock->next, ++a) { @@ -123,7 +123,7 @@ static void group_move_outputs(bNode *gnode, bNodeStack **out, bNodeStack *gstac bNodeSocket *sock; bNodeStack *ns; int a; - + for (node = ngroup->nodes.first; node; node = node->next) { if (node->type == NODE_GROUP_OUTPUT && (node->flag & NODE_DO_OUTPUT)) { for (sock = node->inputs.first, a = 0; sock; sock = sock->next, ++a) { @@ -140,10 +140,10 @@ static void group_execute(void *data, int thread, struct bNode *node, bNodeExecD { bNodeTreeExec *exec = execdata->data; bNodeThreadStack *nts; - + if (!exec) return; - + /* XXX same behavior as trunk: all nodes inside group are executed. * it's stupid, but just makes it work. compo redesign will do this better. */ @@ -152,13 +152,13 @@ static void group_execute(void *data, int thread, struct bNode *node, bNodeExecD for (inode = exec->nodetree->nodes.first; inode; inode = inode->next) inode->need_exec = 1; } - + nts = ntreeGetThreadStack(exec, thread); - + group_copy_inputs(node, in, nts->stack); ntreeExecThreadNodes(exec, nts, data, thread); group_move_outputs(node, out, nts->stack); - + ntreeReleaseThreadStack(nts); } @@ -169,7 +169,7 @@ static void group_gpu_copy_inputs(bNode *gnode, GPUNodeStack *in, bNodeStack *gs bNodeSocket *sock; bNodeStack *ns; int a; - + for (node = ngroup->nodes.first; node; node = node->next) { if (node->type == NODE_GROUP_INPUT) { for (sock = node->outputs.first, a = 0; sock; sock = sock->next, ++a) { @@ -192,7 +192,7 @@ static void group_gpu_move_outputs(bNode *gnode, GPUNodeStack *out, bNodeStack * bNodeSocket *sock; bNodeStack *ns; int a; - + for (node = ngroup->nodes.first; node; node = node->next) { if (node->type == NODE_GROUP_OUTPUT && (node->flag & NODE_DO_OUTPUT)) { for (sock = node->inputs.first, a = 0; sock; sock = sock->next, ++a) { @@ -210,10 +210,10 @@ static void group_gpu_move_outputs(bNode *gnode, GPUNodeStack *out, bNodeStack * static int gpu_group_execute(GPUMaterial *mat, bNode *node, bNodeExecData *execdata, GPUNodeStack *in, GPUNodeStack *out) { bNodeTreeExec *exec = execdata->data; - + if (!node->id) return 0; - + group_gpu_copy_inputs(node, in, exec->stack); #if 0 /* XXX NODE_GROUP_EDIT is deprecated, depends on node space */ ntreeExecGPUNodes(exec, mat, (node->flag & NODE_GROUP_EDIT)); @@ -221,14 +221,14 @@ static int gpu_group_execute(GPUMaterial *mat, bNode *node, bNodeExecData *execd ntreeExecGPUNodes(exec, mat, 0, NODE_NEW_SHADING | NODE_OLD_SHADING); #endif group_gpu_move_outputs(node, out, exec->stack); - + return 1; } void register_node_type_sh_group(void) { static bNodeType ntype; - + /* NB: cannot use sh_node_type_base for node group, because it would map the node type * to the shared NODE_GROUP integer type id. */ @@ -241,7 +241,7 @@ void register_node_type_sh_group(void) ntype.ext.srna = RNA_struct_find("ShaderNodeGroup"); BLI_assert(ntype.ext.srna != NULL); RNA_struct_blender_type_set(ntype.ext.srna, &ntype); - + node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, NULL, NULL); node_type_size(&ntype, 140, 60, 400); @@ -249,6 +249,6 @@ void register_node_type_sh_group(void) node_type_update(&ntype, NULL, node_group_verify); node_type_exec(&ntype, group_initexec, group_freeexec, group_execute); node_type_gpu(&ntype, gpu_group_execute); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_curves.c b/source/blender/nodes/shader/nodes/node_shader_curves.c index ab0dc91a9b7..0c583ced75f 100644 --- a/source/blender/nodes/shader/nodes/node_shader_curves.c +++ b/source/blender/nodes/shader/nodes/node_shader_curves.c @@ -48,7 +48,7 @@ static bNodeSocketTemplate sh_node_curve_vec_out[] = { static void node_shader_exec_curve_vec(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) { float vec[3]; - + /* stack order input: vec */ /* stack order output: vec */ nodestack_get_vec(vec, SOCK_VECTOR, in[1]); @@ -102,7 +102,7 @@ static void node_shader_exec_curve_rgb(void *UNUSED(data), int UNUSED(thread), b { float vec[3]; float fac; - + /* stack order input: vec */ /* stack order output: vec */ nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); diff --git a/source/blender/nodes/shader/nodes/node_shader_fresnel.c b/source/blender/nodes/shader/nodes/node_shader_fresnel.c index 010399aaedd..393d2c5fee0 100644 --- a/source/blender/nodes/shader/nodes/node_shader_fresnel.c +++ b/source/blender/nodes/shader/nodes/node_shader_fresnel.c @@ -47,7 +47,7 @@ static int node_shader_gpu_fresnel(GPUMaterial *mat, bNode *UNUSED(node), bNodeE else if (GPU_material_use_world_space_shading(mat)) { GPU_link(mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link); } - + return GPU_stack_link(mat, "node_fresnel", in, out, GPU_builtin(GPU_VIEW_POSITION)); } diff --git a/source/blender/nodes/shader/nodes/node_shader_gamma.c b/source/blender/nodes/shader/nodes/node_shader_gamma.c index 216fec856b8..8bf58682ef3 100644 --- a/source/blender/nodes/shader/nodes/node_shader_gamma.c +++ b/source/blender/nodes/shader/nodes/node_shader_gamma.c @@ -60,7 +60,7 @@ static int node_shader_gpu_gamma(GPUMaterial *mat, bNode *UNUSED(node), bNodeExe void register_node_type_sh_gamma(void) { static bNodeType ntype; - + sh_node_type_base(&ntype, SH_NODE_GAMMA, "Gamma", NODE_CLASS_OP_COLOR, 0); node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_gamma_in, sh_node_gamma_out); @@ -68,6 +68,6 @@ void register_node_type_sh_gamma(void) node_type_storage(&ntype, "", NULL, NULL); node_type_exec(&ntype, NULL, NULL, node_shader_exec_gamma); node_type_gpu(&ntype, node_shader_gpu_gamma); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_geom.c b/source/blender/nodes/shader/nodes/node_shader_geom.c index 1d7ddc5f226..0a51ee8dc68 100644 --- a/source/blender/nodes/shader/nodes/node_shader_geom.c +++ b/source/blender/nodes/shader/nodes/node_shader_geom.c @@ -103,7 +103,7 @@ static void node_shader_exec_geom(void *data, int UNUSED(thread), bNode *node, b memcpy(out[GEOM_OUT_VCOL]->vec, defaultvcol, sizeof(defaultvcol)); out[GEOM_OUT_VCOL_ALPHA]->vec[0] = 1.0f; } - + if (shi->osatex) { out[GEOM_OUT_GLOB]->data = shi->dxgl; out[GEOM_OUT_GLOB]->datatype = NS_OSA_VECTORS; @@ -118,7 +118,7 @@ static void node_shader_exec_geom(void *data, int UNUSED(thread), bNode *node, b out[GEOM_OUT_NORMAL]->data = shi->dxno; out[GEOM_OUT_NORMAL]->datatype = NS_OSA_VECTORS; } - + /* front/back, normal flipping was stored */ out[GEOM_OUT_FRONTBACK]->vec[0] = (shi->flippednor) ? 0.0f : 1.0f; } diff --git a/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c b/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c index c4a91cb4a0c..548b3970a89 100644 --- a/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c +++ b/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c @@ -52,7 +52,7 @@ static void do_hue_sat_fac(bNode *UNUSED(node), float *out, float hue, float sat { if (fac != 0.0f && (hue != 0.5f || sat != 1.0f || val != 1.0f)) { float col[3], hsv[3], mfac = 1.0f - fac; - + rgb_to_hsv(in[0], in[1], in[2], hsv, hsv + 1, hsv + 2); hsv[0] += (hue - 0.5f); if (hsv[0] > 1.0f) hsv[0] -= 1.0f; else if (hsv[0] < 0.0f) hsv[0] += 1.0f; diff --git a/source/blender/nodes/shader/nodes/node_shader_invert.c b/source/blender/nodes/shader/nodes/node_shader_invert.c index b0336ffd646..dc0817782e5 100644 --- a/source/blender/nodes/shader/nodes/node_shader_invert.c +++ b/source/blender/nodes/shader/nodes/node_shader_invert.c @@ -34,7 +34,7 @@ -/* **************** INVERT ******************** */ +/* **************** INVERT ******************** */ static bNodeSocketTemplate sh_node_invert_in[] = { { SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, @@ -46,18 +46,18 @@ static bNodeSocketTemplate sh_node_invert_out[] = { { -1, 0, "" } }; -static void node_shader_exec_invert(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, +static void node_shader_exec_invert(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) { float col[3], icol[3], fac; nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); nodestack_get_vec(col, SOCK_VECTOR, in[1]); - + icol[0] = 1.0f - col[0]; icol[1] = 1.0f - col[1]; icol[2] = 1.0f - col[2]; - + /* if fac, blend result against original input */ if (fac < 1.0f) interp_v3_v3v3(out[0]->vec, col, icol, fac); diff --git a/source/blender/nodes/shader/nodes/node_shader_mapping.c b/source/blender/nodes/shader/nodes/node_shader_mapping.c index c07d2e99785..95d0fa5c951 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mapping.c +++ b/source/blender/nodes/shader/nodes/node_shader_mapping.c @@ -56,7 +56,7 @@ static void node_shader_exec_mapping(void *UNUSED(data), int UNUSED(thread), bNo { TexMapping *texmap = node->storage; float *vec = out[0]->vec; - + /* stack order input: vector */ /* stack order output: vector */ nodestack_get_vec(vec, SOCK_VECTOR, in[0]); @@ -105,7 +105,7 @@ static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS void register_node_type_sh_mapping(void) { static bNodeType ntype; - + sh_node_type_base(&ntype, SH_NODE_MAPPING, "Mapping", NODE_CLASS_OP_VECTOR, 0); node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_mapping_in, sh_node_mapping_out); @@ -114,6 +114,6 @@ void register_node_type_sh_mapping(void) node_type_storage(&ntype, "TexMapping", node_free_standard_storage, node_copy_standard_storage); node_type_exec(&ntype, node_shader_initexec_mapping, NULL, node_shader_exec_mapping); node_type_gpu(&ntype, gpu_shader_mapping); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_material.c b/source/blender/nodes/shader/nodes/node_shader_material.c index 28380677ba5..8a73ddc1194 100644 --- a/source/blender/nodes/shader/nodes/node_shader_material.c +++ b/source/blender/nodes/shader/nodes/node_shader_material.c @@ -85,7 +85,7 @@ static void node_shader_exec_material(void *data, int UNUSED(thread), bNode *nod bNodeSocket *sock; char hasinput[NUM_MAT_IN] = {'\0'}; int i, mode; - + /* note: cannot use the in[]->hasinput flags directly, as these are not necessarily * the constant input stack values (e.g. in case material node is inside a group). * we just want to know if a node input uses external data or the material setting. @@ -93,24 +93,24 @@ static void node_shader_exec_material(void *data, int UNUSED(thread), bNode *nod */ for (sock = node->inputs.first, i = 0; sock; sock = sock->next, ++i) hasinput[i] = (sock->link != NULL); - + shi = shcd->shi; shi->mat = (Material *)node->id; - + /* copy all relevant material vars, note, keep this synced with render_types.h */ memcpy(&shi->r, &shi->mat->r, 23 * sizeof(float)); shi->har = shi->mat->har; - + /* write values */ if (hasinput[MAT_IN_COLOR]) nodestack_get_vec(&shi->r, SOCK_VECTOR, in[MAT_IN_COLOR]); - + if (hasinput[MAT_IN_SPEC]) nodestack_get_vec(&shi->specr, SOCK_VECTOR, in[MAT_IN_SPEC]); - + if (hasinput[MAT_IN_REFL]) nodestack_get_vec(&shi->refl, SOCK_FLOAT, in[MAT_IN_REFL]); - + /* retrieve normal */ if (hasinput[MAT_IN_NORMAL]) { nodestack_get_vec(shi->vn, SOCK_VECTOR, in[MAT_IN_NORMAL]); @@ -122,12 +122,12 @@ static void node_shader_exec_material(void *data, int UNUSED(thread), bNode *nod } else copy_v3_v3(shi->vn, shi->vno); - + /* custom option to flip normal */ if (node->custom1 & SH_NODE_MAT_NEG) { negate_v3(shi->vn); } - + if (node->type == SH_NODE_MATERIAL_EXT) { if (hasinput[MAT_IN_MIR]) nodestack_get_vec(&shi->mirr, SOCK_VECTOR, in[MAT_IN_MIR]); @@ -144,7 +144,7 @@ static void node_shader_exec_material(void *data, int UNUSED(thread), bNode *nod if (hasinput[MAT_IN_TRANSLUCENCY]) nodestack_get_vec(&shi->translucency, SOCK_FLOAT, in[MAT_IN_TRANSLUCENCY]); } - + /* make alpha output give results even if transparency is only enabled on * the material linked in this not and not on the parent material */ mode = shi->mode; @@ -154,7 +154,7 @@ static void node_shader_exec_material(void *data, int UNUSED(thread), bNode *nod shi->nodes = 1; /* temp hack to prevent trashadow recursion */ node_shader_lamp_loop(shi, &shrnode); /* clears shrnode */ shi->nodes = 0; - + shi->mode = mode; /* write to outputs */ @@ -169,21 +169,21 @@ static void node_shader_exec_material(void *data, int UNUSED(thread), bNode *nod } else col[0] = col[1] = col[2] = 0.0f; - + col[3] = shrnode.alpha; - + if (shi->do_preview) BKE_node_preview_set_pixel(execdata->preview, col, shi->xs, shi->ys, shi->do_manage); - + copy_v3_v3(out[MAT_OUT_COLOR]->vec, col); out[MAT_OUT_ALPHA]->vec[0] = shrnode.alpha; - + if (node->custom1 & SH_NODE_MAT_NEG) { shi->vn[0] = -shi->vn[0]; shi->vn[1] = -shi->vn[1]; shi->vn[2] = -shi->vn[2]; } - + copy_v3_v3(out[MAT_OUT_NORMAL]->vec, shi->vn); if (shi->use_world_space_shading) { @@ -198,7 +198,7 @@ static void node_shader_exec_material(void *data, int UNUSED(thread), bNode *nod copy_v3_v3(out[MAT_OUT_SPEC]->vec, shrnode.spec); copy_v3_v3(out[MAT_OUT_AO]->vec, shrnode.ao); } - + /* copy passes, now just active node */ if (node->flag & NODE_ACTIVE_ID) { float combined[4], alpha; @@ -254,7 +254,7 @@ static int gpu_shader_material(GPUMaterial *mat, bNode *node, bNodeExecData *UNU bNodeSocket *sock; char hasinput[NUM_MAT_IN] = {'\0'}; int i; - + /* note: cannot use the in[]->hasinput flags directly, as these are not necessarily * the constant input stack values (e.g. in case material node is inside a group). * we just want to know if a node input uses external data or the material setting. @@ -267,13 +267,13 @@ static int gpu_shader_material(GPUMaterial *mat, bNode *node, bNodeExecData *UNU /* write values */ if (hasinput[MAT_IN_COLOR]) shi.rgb = gpu_get_input_link(mat, &in[MAT_IN_COLOR]); - + if (hasinput[MAT_IN_SPEC]) shi.specrgb = gpu_get_input_link(mat, &in[MAT_IN_SPEC]); - + if (hasinput[MAT_IN_REFL]) shi.refl = gpu_get_input_link(mat, &in[MAT_IN_REFL]); - + /* retrieve normal */ if (hasinput[MAT_IN_NORMAL]) { GPUNodeLink *tmp; @@ -284,7 +284,7 @@ static int gpu_shader_material(GPUMaterial *mat, bNode *node, bNodeExecData *UNU } GPU_link(mat, "vec_math_normalize", shi.vn, &shi.vn, &tmp); } - + /* custom option to flip normal */ if (node->custom1 & SH_NODE_MAT_NEG) GPU_link(mat, "vec_math_negate", shi.vn, &shi.vn); @@ -303,7 +303,7 @@ static int gpu_shader_material(GPUMaterial *mat, bNode *node, bNodeExecData *UNU } GPU_shaderesult_set(&shi, &shr); /* clears shr */ - + /* write to outputs */ if (node->custom1 & SH_NODE_MAT_DIFF) { out[MAT_OUT_COLOR].link = shr.combined; @@ -322,7 +322,7 @@ static int gpu_shader_material(GPUMaterial *mat, bNode *node, bNodeExecData *UNU GPU_link(mat, "mtex_alpha_to_col", out[MAT_OUT_COLOR].link, shr.alpha, &out[MAT_OUT_COLOR].link); out[MAT_OUT_ALPHA].link = shr.alpha; // - + if (node->custom1 & SH_NODE_MAT_NEG) GPU_link(mat, "vec_math_negate", shi.vn, &shi.vn); out[MAT_OUT_NORMAL].link = shi.vn; diff --git a/source/blender/nodes/shader/nodes/node_shader_math.c b/source/blender/nodes/shader/nodes/node_shader_math.c index f74547ffe70..0a75a0f8bf0 100644 --- a/source/blender/nodes/shader/nodes/node_shader_math.c +++ b/source/blender/nodes/shader/nodes/node_shader_math.c @@ -33,7 +33,7 @@ #include "node_shader_util.h" -/* **************** SCALAR MATH ******************** */ +/* **************** SCALAR MATH ******************** */ static bNodeSocketTemplate sh_node_math_in[] = { { SOCK_FLOAT, 1, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, { SOCK_FLOAT, 1, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, @@ -45,15 +45,15 @@ static bNodeSocketTemplate sh_node_math_out[] = { { -1, 0, "" } }; -static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) { float a, b, r = 0.0f; - + nodestack_get_vec(&a, SOCK_FLOAT, in[0]); nodestack_get_vec(&b, SOCK_FLOAT, in[1]); - + switch (node->custom1) { - + case NODE_MATH_ADD: r = a + b; break; @@ -147,7 +147,7 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode } else { float y_mod_1 = fabsf(fmodf(b, 1.0f)); - + /* if input value is not nearly an integer, fall back to zero, nicer than straight rounding */ if (y_mod_1 > 0.999f || y_mod_1 < 0.001f) { r = powf(a, floorf(b + 0.5f)); diff --git a/source/blender/nodes/shader/nodes/node_shader_mixRgb.c b/source/blender/nodes/shader/nodes/node_shader_mixRgb.c index a0290697bcd..14a9f2c5ea5 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mixRgb.c +++ b/source/blender/nodes/shader/nodes/node_shader_mixRgb.c @@ -54,7 +54,7 @@ static void node_shader_exec_mix_rgb(void *UNUSED(data), int UNUSED(thread), bNo nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); CLAMP(fac, 0.0f, 1.0f); - + nodestack_get_vec(col, SOCK_VECTOR, in[1]); nodestack_get_vec(vec, SOCK_VECTOR, in[2]); diff --git a/source/blender/nodes/shader/nodes/node_shader_normal.c b/source/blender/nodes/shader/nodes/node_shader_normal.c index 25549fe0013..84d250eed7b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_normal.c +++ b/source/blender/nodes/shader/nodes/node_shader_normal.c @@ -48,12 +48,12 @@ static bNodeSocketTemplate sh_node_normal_out[] = { static void node_shader_exec_normal(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) { float vec[3]; - + /* stack order input: normal */ /* stack order output: normal, value */ - + nodestack_get_vec(vec, SOCK_VECTOR, in[0]); - + /* render normals point inside... the widget points outside */ out[1]->vec[0] = -dot_v3v3(vec, out[0]->vec); } @@ -72,12 +72,12 @@ static int gpu_shader_normal(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecDat void register_node_type_sh_normal(void) { static bNodeType ntype; - + sh_node_type_base(&ntype, SH_NODE_NORMAL, "Normal", NODE_CLASS_OP_VECTOR, 0); node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_normal_in, sh_node_normal_out); node_type_exec(&ntype, NULL, NULL, node_shader_exec_normal); node_type_gpu(&ntype, gpu_shader_normal); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_output.c b/source/blender/nodes/shader/nodes/node_shader_output.c index 21844e51486..5b1a68b4bf9 100644 --- a/source/blender/nodes/shader/nodes/node_shader_output.c +++ b/source/blender/nodes/shader/nodes/node_shader_output.c @@ -44,22 +44,22 @@ static void node_shader_exec_output(void *data, int UNUSED(thread), bNode *node, if (data) { ShadeInput *shi = ((ShaderCallData *)data)->shi; float col[4]; - + /* stack order input sockets: col, alpha, normal */ nodestack_get_vec(col, SOCK_VECTOR, in[0]); nodestack_get_vec(col + 3, SOCK_FLOAT, in[1]); - + if (shi->do_preview) { BKE_node_preview_set_pixel(execdata->preview, col, shi->xs, shi->ys, shi->do_manage); node->lasty = shi->ys; } - + if (node->flag & NODE_DO_OUTPUT) { ShadeResult *shr = ((ShaderCallData *)data)->shr; - + copy_v4_v4(shr->combined, col); shr->alpha = col[3]; - + // copy_v3_v3(shr->nor, in[3]->vec); } } diff --git a/source/blender/nodes/shader/nodes/node_shader_output_world.c b/source/blender/nodes/shader/nodes/node_shader_output_world.c index d8182ee3f77..9581153538b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_output_world.c +++ b/source/blender/nodes/shader/nodes/node_shader_output_world.c @@ -56,7 +56,7 @@ void register_node_type_sh_output_world(void) node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); node_type_gpu(&ntype, node_shader_gpu_output_world); - + /* Do not allow muting output node. */ node_type_internal_links(&ntype, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c b/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c index d6636956873..0a47978431f 100644 --- a/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c +++ b/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c @@ -48,7 +48,7 @@ static void node_shader_exec_sephsv(void *UNUSED(data), int UNUSED(thread), bNod { float col[3]; nodestack_get_vec(col, SOCK_VECTOR, in[0]); - + rgb_to_hsv(col[0], col[1], col[2], &out[0]->vec[0], &out[1]->vec[0], &out[2]->vec[0]); } @@ -90,7 +90,7 @@ static void node_shader_exec_combhsv(void *UNUSED(data), int UNUSED(thread), bNo nodestack_get_vec(&h, SOCK_FLOAT, in[0]); nodestack_get_vec(&s, SOCK_FLOAT, in[1]); nodestack_get_vec(&v, SOCK_FLOAT, in[2]); - + hsv_to_rgb(h, s, v, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2]); } diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c b/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c index 87a987a6053..8748abd5eb6 100644 --- a/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c +++ b/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c @@ -48,7 +48,7 @@ static void node_shader_exec_seprgb(void *UNUSED(data), int UNUSED(thread), bNod { float col[3]; nodestack_get_vec(col, SOCK_VECTOR, in[0]); - + out[0]->vec[0] = col[0]; out[1]->vec[0] = col[1]; out[2]->vec[0] = col[2]; @@ -92,7 +92,7 @@ static void node_shader_exec_combrgb(void *UNUSED(data), int UNUSED(thread), bNo nodestack_get_vec(&r, SOCK_FLOAT, in[0]); nodestack_get_vec(&g, SOCK_FLOAT, in[1]); nodestack_get_vec(&b, SOCK_FLOAT, in[2]); - + out[0]->vec[0] = r; out[0]->vec[1] = g; out[0]->vec[2] = b; diff --git a/source/blender/nodes/shader/nodes/node_shader_squeeze.c b/source/blender/nodes/shader/nodes/node_shader_squeeze.c index f9240b2d4b6..bba6a56d9e5 100644 --- a/source/blender/nodes/shader/nodes/node_shader_squeeze.c +++ b/source/blender/nodes/shader/nodes/node_shader_squeeze.c @@ -32,7 +32,7 @@ #include "node_shader_util.h" -/* **************** VALUE SQUEEZE ******************** */ +/* **************** VALUE SQUEEZE ******************** */ static bNodeSocketTemplate sh_node_squeeze_in[] = { { SOCK_FLOAT, 1, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, { SOCK_FLOAT, 1, N_("Width"), 1.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, @@ -48,7 +48,7 @@ static bNodeSocketTemplate sh_node_squeeze_out[] = { static void node_shader_exec_squeeze(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) { float vec[3]; - + nodestack_get_vec(vec, SOCK_FLOAT, in[0]); nodestack_get_vec(vec + 1, SOCK_FLOAT, in[1]); nodestack_get_vec(vec + 2, SOCK_FLOAT, in[2]); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_brick.c b/source/blender/nodes/shader/nodes/node_shader_tex_brick.c index b032ad74e84..ebfb3fc29a1 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_brick.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_brick.c @@ -54,7 +54,7 @@ static void node_shader_init_tex_brick(bNodeTree *UNUSED(ntree), bNode *node) NodeTexBrick *tex = MEM_callocN(sizeof(NodeTexBrick), "NodeTexBrick"); BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); BKE_texture_colormapping_default(&tex->base.color_mapping); - + tex->offset = 0.5f; tex->squash = 1.0f; tex->offset_freq = 2; diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_coord.c b/source/blender/nodes/shader/nodes/node_shader_tex_coord.c index 38e6fec36a1..f1721fe5567 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_coord.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_coord.c @@ -47,7 +47,7 @@ static int node_shader_gpu_tex_coord(GPUMaterial *mat, bNode *UNUSED(node), bNod GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, ""); GPUMatType type = GPU_Material_get_type(mat); - + if (type == GPU_MATERIAL_TYPE_MESH) { return GPU_stack_link(mat, "node_tex_coord", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL), @@ -57,7 +57,7 @@ static int node_shader_gpu_tex_coord(GPUMaterial *mat, bNode *UNUSED(node), bNod else { return GPU_stack_link(mat, "node_tex_coord_background", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL), - GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX), + GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX), GPU_builtin(GPU_CAMERA_TEXCO_FACTORS), orco, mtface); } } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c index 81ca08bd356..9b485a30083 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c @@ -66,20 +66,20 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, bNodeE if (!in[0].link) { GPUMatType type = GPU_Material_get_type(mat); - + if (type == GPU_MATERIAL_TYPE_MESH) in[0].link = GPU_builtin(GPU_VIEW_POSITION); else GPU_link(mat, "background_transform_to_world", GPU_builtin(GPU_VIEW_POSITION), &in[0].link); } - + node_shader_gpu_tex_mapping(mat, node, in, out); if (tex->projection == SHD_PROJ_EQUIRECTANGULAR) GPU_stack_link(mat, "node_tex_environment_equirectangular", in, out, GPU_image(ima, iuser, isdata)); else GPU_stack_link(mat, "node_tex_environment_mirror_ball", in, out, GPU_image(ima, iuser, isdata)); - + ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 && GPU_material_do_color_management(mat)) diff --git a/source/blender/nodes/shader/nodes/node_shader_texture.c b/source/blender/nodes/shader/nodes/node_shader_texture.c index 365319844a8..737ec7d1c4b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_texture.c +++ b/source/blender/nodes/shader/nodes/node_shader_texture.c @@ -56,19 +56,19 @@ static void node_shader_exec_texture(void *data, int UNUSED(thread), bNode *node float vec[3], nor[3] = {0.0f, 0.0f, 0.0f}; int retval; short which_output = node->custom1; - + short thread = shi->thread; - + /* out: value, color, normal */ - + /* we should find out if a normal as output is needed, for now we do all */ texres.nor = nor; texres.tr = texres.tg = texres.tb = 0.0f; - + /* don't use in[0]->hasinput, see material node for explanation */ if (sock_vector->link) { nodestack_get_vec(vec, SOCK_VECTOR, in[0]); - + if (in[0]->datatype == NS_OSA_VECTORS) { float *fp = in[0]->data; retval = multitex_nodes((Tex *)node->id, vec, fp, fp + 3, shi->osatex, &texres, thread, which_output, NULL, NULL, NULL); @@ -76,7 +76,7 @@ static void node_shader_exec_texture(void *data, int UNUSED(thread), bNode *node else if (in[0]->datatype == NS_OSA_VALUES) { const float *fp = in[0]->data; float dxt[3], dyt[3]; - + dxt[0] = fp[0]; dxt[1] = dxt[2] = 0.0f; dyt[0] = fp[1]; dyt[1] = dyt[2] = 0.0f; retval = multitex_nodes((Tex *)node->id, vec, dxt, dyt, shi->osatex, &texres, thread, which_output, NULL, NULL, NULL); @@ -88,19 +88,19 @@ static void node_shader_exec_texture(void *data, int UNUSED(thread), bNode *node copy_v3_v3(vec, shi->lo); retval = multitex_nodes((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output, NULL, NULL, NULL); } - + /* stupid exception */ if ( ((Tex *)node->id)->type == TEX_STUCCI) { texres.tin = 0.5f + 0.7f * texres.nor[0]; CLAMP(texres.tin, 0.0f, 1.0f); } - + /* intensity and color need some handling */ if (texres.talpha) out[0]->vec[0] = texres.ta; else out[0]->vec[0] = texres.tin; - + if ((retval & TEX_RGB) == 0) { copy_v3_fl(out[1]->vec, out[0]->vec[0]); out[1]->vec[3] = 1.0f; @@ -109,13 +109,13 @@ static void node_shader_exec_texture(void *data, int UNUSED(thread), bNode *node copy_v3_v3(out[1]->vec, &texres.tr); out[1]->vec[3] = 1.0f; } - + copy_v3_v3(out[2]->vec, nor); - + if (shi->do_preview) { BKE_node_preview_set_pixel(execdata->preview, out[1]->vec, shi->xs, shi->ys, shi->do_manage); } - + } } diff --git a/source/blender/nodes/shader/nodes/node_shader_valToRgb.c b/source/blender/nodes/shader/nodes/node_shader_valToRgb.c index 6a6c3b43ed9..5a1f0bd472d 100644 --- a/source/blender/nodes/shader/nodes/node_shader_valToRgb.c +++ b/source/blender/nodes/shader/nodes/node_shader_valToRgb.c @@ -48,7 +48,7 @@ static void node_shader_exec_valtorgb(void *UNUSED(data), int UNUSED(thread), bN { /* stack order in: fac */ /* stack order out: col, alpha */ - + if (node->storage) { float fac; nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); diff --git a/source/blender/nodes/shader/nodes/node_shader_vectMath.c b/source/blender/nodes/shader/nodes/node_shader_vectMath.c index 3114d7f3235..02cff52e1a0 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vectMath.c +++ b/source/blender/nodes/shader/nodes/node_shader_vectMath.c @@ -31,7 +31,7 @@ #include "node_shader_util.h" -/* **************** VECTOR MATH ******************** */ +/* **************** VECTOR MATH ******************** */ static bNodeSocketTemplate sh_node_vect_math_in[] = { { SOCK_VECTOR, 1, N_("Vector"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, { SOCK_VECTOR, 1, N_("Vector"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, @@ -44,32 +44,32 @@ static bNodeSocketTemplate sh_node_vect_math_out[] = { { -1, 0, "" } }; -static void node_shader_exec_vect_math(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) -{ +static void node_shader_exec_vect_math(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +{ float vec1[3], vec2[3]; - + nodestack_get_vec(vec1, SOCK_VECTOR, in[0]); nodestack_get_vec(vec2, SOCK_VECTOR, in[1]); - + if (node->custom1 == 0) { /* Add */ out[0]->vec[0] = vec1[0] + vec2[0]; out[0]->vec[1] = vec1[1] + vec2[1]; out[0]->vec[2] = vec1[2] + vec2[2]; - + out[1]->vec[0] = (fabsf(out[0]->vec[0]) + fabsf(out[0]->vec[1]) + fabsf(out[0]->vec[2])) / 3.0f; } else if (node->custom1 == 1) { /* Subtract */ out[0]->vec[0] = vec1[0] - vec2[0]; out[0]->vec[1] = vec1[1] - vec2[1]; out[0]->vec[2] = vec1[2] - vec2[2]; - + out[1]->vec[0] = (fabsf(out[0]->vec[0]) + fabsf(out[0]->vec[1]) + fabsf(out[0]->vec[2])) / 3.0f; } else if (node->custom1 == 2) { /* Average */ out[0]->vec[0] = vec1[0] + vec2[0]; out[0]->vec[1] = vec1[1] + vec2[1]; out[0]->vec[2] = vec1[2] + vec2[2]; - + out[1]->vec[0] = normalize_v3(out[0]->vec); } else if (node->custom1 == 3) { /* Dot product */ @@ -79,7 +79,7 @@ static void node_shader_exec_vect_math(void *UNUSED(data), int UNUSED(thread), b out[0]->vec[0] = (vec1[1] * vec2[2]) - (vec1[2] * vec2[1]); out[0]->vec[1] = (vec1[2] * vec2[0]) - (vec1[0] * vec2[2]); out[0]->vec[2] = (vec1[0] * vec2[1]) - (vec1[1] * vec2[0]); - + out[1]->vec[0] = normalize_v3(out[0]->vec); } else if (node->custom1 == 5) { /* Normalize */ @@ -93,10 +93,10 @@ static void node_shader_exec_vect_math(void *UNUSED(data), int UNUSED(thread), b out[0]->vec[1] = vec2[1]; out[0]->vec[2] = vec2[2]; } - + out[1]->vec[0] = normalize_v3(out[0]->vec); } - + } static int gpu_shader_vect_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) @@ -132,7 +132,7 @@ static int gpu_shader_vect_math(GPUMaterial *mat, bNode *node, bNodeExecData *UN default: return false; } - + return true; } diff --git a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c b/source/blender/nodes/shader/nodes/node_shader_vectTransform.c index ef78f1ecab0..af36e7cea22 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c +++ b/source/blender/nodes/shader/nodes/node_shader_vectTransform.c @@ -28,10 +28,10 @@ /** \file blender/nodes/shader/nodes/node_shader_vectTransform.c * \ingroup shdnodes */ - + #include "../node_shader_util.h" -/* **************** Vector Transform ******************** */ +/* **************** Vector Transform ******************** */ static bNodeSocketTemplate sh_node_vect_transform_in[] = { { SOCK_VECTOR, 1, N_("Vector"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, { -1, 0, "" } @@ -45,10 +45,10 @@ static bNodeSocketTemplate sh_node_vect_transform_out[] = { static void node_shader_init_vect_transform(bNodeTree *UNUSED(ntree), bNode *node) { NodeShaderVectTransform *vect = MEM_callocN(sizeof(NodeShaderVectTransform), "NodeShaderVectTransform"); - + /* Convert World into Object Space per default */ vect->convert_to = 1; - + node->storage = vect; } diff --git a/source/blender/nodes/texture/node_texture_tree.c b/source/blender/nodes/texture/node_texture_tree.c index bc48802a7ca..b77e0a32fbc 100644 --- a/source/blender/nodes/texture/node_texture_tree.c +++ b/source/blender/nodes/texture/node_texture_tree.c @@ -73,7 +73,7 @@ static void texture_get_from_context(const bContext *C, bNodeTreeType *UNUSED(tr *r_from = (ID *)ob->data; else *r_from = (ID *)give_current_material(ob, ob->actcol); - + /* from is not set fully for material nodes, should be ID + Node then */ *r_id = &tx->id; *r_ntree = tx->nodetree; @@ -92,7 +92,7 @@ static void texture_get_from_context(const bContext *C, bNodeTreeType *UNUSED(tr } else if (snode->texfrom == SNODE_TEX_BRUSH) { struct Brush *brush = NULL; - + if (ob && (ob->mode & OB_MODE_SCULPT)) brush = BKE_paint_brush(&scene->toolsettings->sculpt->paint); else @@ -141,11 +141,11 @@ static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCa static void localize(bNodeTree *localtree, bNodeTree *UNUSED(ntree)) { bNode *node, *node_next; - + /* replace muted nodes and reroute nodes by internal links */ for (node = localtree->nodes.first; node; node = node_next) { node_next = node->next; - + if (node->flag & NODE_MUTED || node->type == NODE_REROUTE) { nodeInternalRelink(localtree, node); nodeFreeNode(localtree, node); @@ -171,7 +171,7 @@ static void local_merge(bNodeTree *localtree, bNodeTree *ntree) static void update(bNodeTree *ntree) { ntree_update_reroute_nodes(ntree); - + if (ntree->update & NTREE_UPDATE_NODES) { /* clean up preview cache, in case nodes have been removed */ BKE_node_preview_remove_unused(ntree); @@ -183,31 +183,31 @@ bNodeTreeType *ntreeType_Texture; void register_node_tree_type_tex(void) { bNodeTreeType *tt = ntreeType_Texture = MEM_callocN(sizeof(bNodeTreeType), "texture node tree type"); - + tt->type = NTREE_TEXTURE; strcpy(tt->idname, "TextureNodeTree"); strcpy(tt->ui_name, "Texture"); tt->ui_icon = 0; /* defined in drawnode.c */ strcpy(tt->ui_description, "Texture nodes"); - + tt->foreach_nodeclass = foreach_nodeclass; tt->update = update; tt->localize = localize; tt->local_sync = local_sync; tt->local_merge = local_merge; tt->get_from_context = texture_get_from_context; - + tt->ext.srna = &RNA_TextureNodeTree; - + ntreeTypeAdd(tt); } int ntreeTexTagAnimated(bNodeTree *ntree) { bNode *node; - + if (ntree == NULL) return 0; - + for (node = ntree->nodes.first; node; node = node->next) { if (node->type == TEX_NODE_CURVE_TIME) { nodeUpdate(ntree, node); @@ -219,7 +219,7 @@ int ntreeTexTagAnimated(bNodeTree *ntree) } } } - + return 0; } @@ -227,16 +227,16 @@ bNodeTreeExec *ntreeTexBeginExecTree_internal(bNodeExecContext *context, bNodeTr { bNodeTreeExec *exec; bNode *node; - + /* common base initialization */ exec = ntree_exec_begin(context, ntree, parent_key); - + /* allocate the thread stack listbase array */ exec->threadstack = MEM_callocN(BLENDER_MAX_THREADS * sizeof(ListBase), "thread stack array"); - + for (node = exec->nodetree->nodes.first; node; node = node->next) node->need_exec = 1; - + return exec; } @@ -244,22 +244,22 @@ bNodeTreeExec *ntreeTexBeginExecTree(bNodeTree *ntree) { bNodeExecContext context; bNodeTreeExec *exec; - + /* XXX hack: prevent exec data from being generated twice. * this should be handled by the renderer! */ if (ntree->execdata) return ntree->execdata; - + context.previews = ntree->previews; - + exec = ntreeTexBeginExecTree_internal(&context, ntree, NODE_INSTANCE_KEY_BASE); - + /* XXX this should not be necessary, but is still used for cmp/sha/tex nodes, * which only store the ntree pointer. Should be fixed at some point! */ ntree->execdata = exec; - + return exec; } @@ -269,7 +269,7 @@ static void tex_free_delegates(bNodeTreeExec *exec) bNodeThreadStack *nts; bNodeStack *ns; int th, a; - + for (th = 0; th < BLENDER_MAX_THREADS; th++) for (nts = exec->threadstack[th].first; nts; nts = nts->next) for (ns = nts->stack, a = 0; a < exec->stacksize; a++, ns++) @@ -281,20 +281,20 @@ void ntreeTexEndExecTree_internal(bNodeTreeExec *exec) { bNodeThreadStack *nts; int a; - + if (exec->threadstack) { tex_free_delegates(exec); - + for (a = 0; a < BLENDER_MAX_THREADS; a++) { for (nts = exec->threadstack[a].first; nts; nts = nts->next) if (nts->stack) MEM_freeN(nts->stack); BLI_freelistN(&exec->threadstack[a]); } - + MEM_freeN(exec->threadstack); exec->threadstack = NULL; } - + ntree_exec_end(exec); } @@ -304,7 +304,7 @@ void ntreeTexEndExecTree(bNodeTreeExec *exec) /* exec may get freed, so assign ntree */ bNodeTree *ntree = exec->nodetree; ntreeTexEndExecTree_internal(exec); - + /* XXX clear nodetree backpointer to exec data, same problem as noted in ntreeBeginExecTree */ ntree->execdata = NULL; } @@ -342,7 +342,7 @@ int ntreeTexExecTree( data.cfra = cfra; data.mtex = mtex; data.shi = shi; - + /* ensure execdata is only initialized once */ if (!exec) { BLI_thread_lock(LOCK_NODES); @@ -352,7 +352,7 @@ int ntreeTexExecTree( exec = nodes->execdata; } - + nts = ntreeGetThreadStack(exec, thread); ntreeExecThreadNodes(exec, nts, &data, thread); ntreeReleaseThreadStack(nts); diff --git a/source/blender/nodes/texture/node_texture_util.c b/source/blender/nodes/texture/node_texture_util.c index 32720364f73..0682fa9f414 100644 --- a/source/blender/nodes/texture/node_texture_util.c +++ b/source/blender/nodes/texture/node_texture_util.c @@ -58,7 +58,7 @@ int tex_node_poll_default(bNodeType *UNUSED(ntype), bNodeTree *ntree) void tex_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag) { node_type_base(ntype, type, name, nclass, flag); - + ntype->poll = tex_node_poll_default; ntype->insert_link = node_insert_link_default; ntype->update_internal_links = node_update_internal_links_default; @@ -80,7 +80,7 @@ static void tex_input(float *out, int sz, bNodeStack *in, TexParams *params, sho TexDelegate *dg = in->data; if (dg) { tex_call_delegate(dg, in->vec, params, thread); - + if (in->hasoutput && in->sockettype == SOCK_FLOAT) in->vec[1] = in->vec[2] = in->vec[0]; } @@ -95,12 +95,12 @@ void tex_input_vec(float *out, bNodeStack *in, TexParams *params, short thread) void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread) { tex_input(out, 4, in, params, thread); - + if (in->hasoutput && in->sockettype == SOCK_FLOAT) { out[1] = out[2] = out[0]; out[3] = 1; } - + if (in->hasoutput && in->sockettype == SOCK_VECTOR) { out[0] = out[0] * 0.5f + 0.5f; out[1] = out[1] * 0.5f + 0.5f; @@ -133,7 +133,7 @@ void tex_do_preview(bNodePreview *preview, const float coord[2], const float col if (preview) { int xs = ((coord[0] + 1.0f) * 0.5f) * preview->xsize; int ys = ((coord[1] + 1.0f) * 0.5f) * preview->ysize; - + BKE_node_preview_set_pixel(preview, col, xs, ys, do_manage); } } @@ -141,7 +141,7 @@ void tex_do_preview(bNodePreview *preview, const float coord[2], const float col void tex_output(bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata) { TexDelegate *dg; - + if (node->flag & NODE_MUTED) { /* do not add a delegate if the node is muted */ return; @@ -176,9 +176,9 @@ void ntreeTexCheckCyclics(struct bNodeTree *ntree) } else { Tex *tex = (Tex *)node->id; - + node->custom2 = 0; - + node->custom1 = 1; if (tex->use_nodes && tex->nodetree) { ntreeTexCheckCyclics(tex->nodetree); diff --git a/source/blender/nodes/texture/nodes/node_texture_at.c b/source/blender/nodes/texture/nodes/node_texture_at.c index bd37a73c776..690d87b42a9 100644 --- a/source/blender/nodes/texture/nodes/node_texture_at.c +++ b/source/blender/nodes/texture/nodes/node_texture_at.c @@ -48,7 +48,7 @@ static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack ** TexParams np = *p; float new_co[3]; np.co = new_co; - + tex_input_vec(new_co, in[1], p, thread); tex_input_rgba(out, in[0], &np, thread); } @@ -61,11 +61,11 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe void register_node_type_tex_at(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_AT, "At", NODE_CLASS_DISTORT, 0); node_type_socket_templates(&ntype, inputs, outputs); node_type_size(&ntype, 140, 100, 320); node_type_exec(&ntype, NULL, NULL, exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_bricks.c b/source/blender/nodes/texture/nodes/node_texture_bricks.c index 802cfb97533..43af02acdf2 100644 --- a/source/blender/nodes/texture/nodes/node_texture_bricks.c +++ b/source/blender/nodes/texture/nodes/node_texture_bricks.c @@ -67,43 +67,43 @@ static float noise(int n) /* fast integer noise */ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) { const float *co = p->co; - + float x = co[0]; float y = co[1]; - + int bricknum, rownum; float offset = 0; float ins_x, ins_y; float tint; - + float bricks1[4]; float bricks2[4]; float mortar[4]; - + float mortar_thickness = tex_input_value(in[3], p, thread); float bias = tex_input_value(in[4], p, thread); float brick_width = tex_input_value(in[5], p, thread); float row_height = tex_input_value(in[6], p, thread); - + tex_input_rgba(bricks1, in[0], p, thread); tex_input_rgba(bricks2, in[1], p, thread); tex_input_rgba(mortar, in[2], p, thread); - + rownum = (int)floor(y / row_height); - + if (node->custom1 && node->custom2) { brick_width *= ((int)(rownum) % node->custom2) ? 1.0f : node->custom4; /* squash */ offset = ((int)(rownum) % node->custom1) ? 0 : (brick_width * node->custom3); /* offset */ } - + bricknum = (int)floor((x + offset) / brick_width); - + ins_x = (x + offset) - brick_width * bricknum; ins_y = y - row_height * rownum; - + tint = noise((rownum << 16) + (bricknum & 0xFFFF)) + bias; CLAMP(tint, 0.0f, 1.0f); - + if (ins_x < mortar_thickness || ins_y < mortar_thickness || ins_x > (brick_width - mortar_thickness) || ins_y > (row_height - mortar_thickness)) @@ -124,12 +124,12 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe void register_node_type_tex_bricks(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_BRICKS, "Bricks", NODE_CLASS_PATTERN, NODE_PREVIEW); node_type_socket_templates(&ntype, inputs, outputs); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, init); node_type_exec(&ntype, NULL, NULL, exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_checker.c b/source/blender/nodes/texture/nodes/node_texture_checker.c index b38c883e3b8..d7ad642d474 100644 --- a/source/blender/nodes/texture/nodes/node_texture_checker.c +++ b/source/blender/nodes/texture/nodes/node_texture_checker.c @@ -51,12 +51,12 @@ static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack ** float y = p->co[1]; float z = p->co[2]; float sz = tex_input_value(in[2], p, thread); - + /* 0.00001 because of unit sized stuff */ int xi = (int)fabs(floor(0.00001f + x / sz)); int yi = (int)fabs(floor(0.00001f + y / sz)); int zi = (int)fabs(floor(0.00001f + z / sz)); - + if ( (xi % 2 == yi % 2) == (zi % 2) ) { tex_input_rgba(out, in[0], p, thread); } @@ -73,10 +73,10 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe void register_node_type_tex_checker(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_CHECKER, "Checker", NODE_CLASS_PATTERN, NODE_PREVIEW); node_type_socket_templates(&ntype, inputs, outputs); node_type_exec(&ntype, NULL, NULL, exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_common.c b/source/blender/nodes/texture/nodes/node_texture_common.c index 6f9a39d7524..20b1815e436 100644 --- a/source/blender/nodes/texture/nodes/node_texture_common.c +++ b/source/blender/nodes/texture/nodes/node_texture_common.c @@ -50,7 +50,7 @@ static void copy_stack(bNodeStack *to, bNodeStack *from) copy_v4_v4(to->vec, from->vec); to->data = from->data; to->datatype = from->datatype; - + /* tag as copy to prevent freeing */ to->is_copy = 1; } @@ -62,20 +62,20 @@ static void *group_initexec(bNodeExecContext *context, bNode *node, bNodeInstanc { bNodeTree *ngroup = (bNodeTree *)node->id; void *exec; - + if (!ngroup) return NULL; - + /* initialize the internal node tree execution */ exec = ntreeTexBeginExecTree_internal(context, ngroup, key); - + return exec; } static void group_freeexec(void *nodedata) { bNodeTreeExec *gexec = (bNodeTreeExec *)nodedata; - + ntreeTexEndExecTree_internal(gexec); } @@ -89,7 +89,7 @@ static void group_copy_inputs(bNode *gnode, bNodeStack **in, bNodeStack *gstack) bNodeSocket *sock; bNodeStack *ns; int a; - + for (node = ngroup->nodes.first; node; node = node->next) { if (node->type == NODE_GROUP_INPUT) { for (sock = node->outputs.first, a = 0; sock; sock = sock->next, ++a) { @@ -113,7 +113,7 @@ static void group_copy_outputs(bNode *gnode, bNodeStack **out, bNodeStack *gstac bNodeSocket *sock; bNodeStack *ns; int a; - + for (node = ngroup->nodes.first; node; node = node->next) { if (node->type == NODE_GROUP_OUTPUT && (node->flag & NODE_DO_OUTPUT)) { for (sock = node->inputs.first, a = 0; sock; sock = sock->next, ++a) { @@ -133,10 +133,10 @@ static void group_execute(void *data, int thread, struct bNode *node, bNodeExecD { bNodeTreeExec *exec = execdata->data; bNodeThreadStack *nts; - + if (!exec) return; - + /* XXX same behavior as trunk: all nodes inside group are executed. * it's stupid, but just makes it work. compo redesign will do this better. */ @@ -145,13 +145,13 @@ static void group_execute(void *data, int thread, struct bNode *node, bNodeExecD for (inode = exec->nodetree->nodes.first; inode; inode = inode->next) inode->need_exec = 1; } - + nts = ntreeGetThreadStack(exec, thread); - + group_copy_inputs(node, in, nts->stack); ntreeExecThreadNodes(exec, nts, data, thread); group_copy_outputs(node, out, nts->stack); - + ntreeReleaseThreadStack(nts); } @@ -171,12 +171,12 @@ void register_node_type_tex_group(void) ntype.ext.srna = RNA_struct_find("TextureNodeGroup"); BLI_assert(ntype.ext.srna != NULL); RNA_struct_blender_type_set(ntype.ext.srna, &ntype); - + node_type_socket_templates(&ntype, NULL, NULL); node_type_size(&ntype, 140, 60, 400); node_type_label(&ntype, node_group_label); node_type_update(&ntype, NULL, node_group_verify); node_type_exec(&ntype, group_initexec, group_freeexec, group_execute); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_compose.c b/source/blender/nodes/texture/nodes/node_texture_compose.c index 092bf919a67..002da4428cc 100644 --- a/source/blender/nodes/texture/nodes/node_texture_compose.c +++ b/source/blender/nodes/texture/nodes/node_texture_compose.c @@ -30,7 +30,7 @@ */ -#include "node_texture_util.h" +#include "node_texture_util.h" #include "NOD_texture.h" static bNodeSocketTemplate inputs[] = { @@ -60,10 +60,10 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe void register_node_type_tex_compose(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_COMPOSE, "Combine RGBA", NODE_CLASS_OP_COLOR, 0); node_type_socket_templates(&ntype, inputs, outputs); node_type_exec(&ntype, NULL, NULL, exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_coord.c b/source/blender/nodes/texture/nodes/node_texture_coord.c index e76987da61b..e698ffd0a54 100644 --- a/source/blender/nodes/texture/nodes/node_texture_coord.c +++ b/source/blender/nodes/texture/nodes/node_texture_coord.c @@ -51,11 +51,11 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe void register_node_type_tex_coord(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_COORD, "Coordinates", NODE_CLASS_INPUT, 0); node_type_socket_templates(&ntype, NULL, outputs); node_type_storage(&ntype, "", NULL, NULL); node_type_exec(&ntype, NULL, NULL, exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_curves.c b/source/blender/nodes/texture/nodes/node_texture_curves.c index c25c312626e..cc734df9586 100644 --- a/source/blender/nodes/texture/nodes/node_texture_curves.c +++ b/source/blender/nodes/texture/nodes/node_texture_curves.c @@ -45,10 +45,10 @@ static void time_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **UNU { /* stack order output: fac */ float fac = 0.0f; - + if (node->custom1 < node->custom2) fac = (p->cfra - node->custom1) / (float)(node->custom2 - node->custom1); - + curvemapping_initialize(node->storage); fac = curvemapping_evaluateF(node->storage, 0, fac); out[0] = CLAMPIS(fac, 0.0f, 1.0f); @@ -70,14 +70,14 @@ static void time_init(bNodeTree *UNUSED(ntree), bNode *node) void register_node_type_tex_curve_time(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_CURVE_TIME, "Time", NODE_CLASS_INPUT, 0); node_type_socket_templates(&ntype, NULL, time_outputs); node_type_size_preset(&ntype, NODE_SIZE_LARGE); node_type_init(&ntype, time_init); node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); node_type_exec(&ntype, node_initexec_curves, NULL, time_exec); - + nodeRegisterType(&ntype); } @@ -96,7 +96,7 @@ static void rgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, { float cin[4]; tex_input_rgba(cin, in[0], p, thread); - + curvemapping_evaluateRGBF(node->storage, out, cin); out[3] = cin[3]; } @@ -114,13 +114,13 @@ static void rgb_init(bNodeTree *UNUSED(ntree), bNode *node) void register_node_type_tex_curve_rgb(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR, 0); node_type_socket_templates(&ntype, rgb_inputs, rgb_outputs); node_type_size_preset(&ntype, NODE_SIZE_LARGE); node_type_init(&ntype, rgb_init); node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); node_type_exec(&ntype, node_initexec_curves, NULL, rgb_exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_decompose.c b/source/blender/nodes/texture/nodes/node_texture_decompose.c index 16938bee8e4..392cff970e7 100644 --- a/source/blender/nodes/texture/nodes/node_texture_decompose.c +++ b/source/blender/nodes/texture/nodes/node_texture_decompose.c @@ -30,7 +30,7 @@ */ -#include "node_texture_util.h" +#include "node_texture_util.h" #include "NOD_texture.h" #include @@ -81,10 +81,10 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe void register_node_type_tex_decompose(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_DECOMPOSE, "Separate RGBA", NODE_CLASS_OP_COLOR, 0); node_type_socket_templates(&ntype, inputs, outputs); node_type_exec(&ntype, NULL, NULL, exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_distance.c b/source/blender/nodes/texture/nodes/node_texture_distance.c index 3fdcbe870a9..7cd032f7d59 100644 --- a/source/blender/nodes/texture/nodes/node_texture_distance.c +++ b/source/blender/nodes/texture/nodes/node_texture_distance.c @@ -64,11 +64,11 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe void register_node_type_tex_distance(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_DISTANCE, "Distance", NODE_CLASS_CONVERTOR, 0); node_type_socket_templates(&ntype, inputs, outputs); node_type_storage(&ntype, "", NULL, NULL); node_type_exec(&ntype, NULL, NULL, exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_hueSatVal.c b/source/blender/nodes/texture/nodes/node_texture_hueSatVal.c index 9c86f2d0a4c..8316579af93 100644 --- a/source/blender/nodes/texture/nodes/node_texture_hueSatVal.c +++ b/source/blender/nodes/texture/nodes/node_texture_hueSatVal.c @@ -51,7 +51,7 @@ static void do_hue_sat_fac(bNode *UNUSED(node), float *out, float hue, float sat { if (fac != 0 && (hue != 0.5f || sat != 1 || val != 1)) { float col[3], hsv[3], mfac = 1.0f - fac; - + rgb_to_hsv(in[0], in[1], in[2], hsv, hsv + 1, hsv + 2); hsv[0] += (hue - 0.5f); if (hsv[0] > 1.0f) hsv[0] -= 1.0f; else if (hsv[0] < 0.0f) hsv[0] += 1.0f; @@ -71,19 +71,19 @@ static void do_hue_sat_fac(bNode *UNUSED(node), float *out, float hue, float sat } static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread) -{ +{ float hue = tex_input_value(in[0], p, thread); float sat = tex_input_value(in[1], p, thread); float val = tex_input_value(in[2], p, thread); float fac = tex_input_value(in[3], p, thread); - + float col[4]; tex_input_rgba(col, in[4], p, thread); - + hue += 0.5f; /* [-0.5, 0.5] -> [0, 1] */ - + do_hue_sat_fac(node, out, hue, sat, val, col, fac); - + out[3] = col[3]; } @@ -95,11 +95,11 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe void register_node_type_tex_hue_sat(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, 0); node_type_socket_templates(&ntype, inputs, outputs); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_exec(&ntype, NULL, NULL, exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_image.c b/source/blender/nodes/texture/nodes/node_texture_image.c index 057c4f24256..d6881ca41f0 100644 --- a/source/blender/nodes/texture/nodes/node_texture_image.c +++ b/source/blender/nodes/texture/nodes/node_texture_image.c @@ -44,37 +44,37 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **UNUSED(i float y = p->co[1]; Image *ima = (Image *)node->id; ImageUser *iuser = (ImageUser *)node->storage; - + if (ima) { ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); if (ibuf) { float xsize, ysize; float xoff, yoff; int px, py; - + const float *result; xsize = ibuf->x / 2; ysize = ibuf->y / 2; xoff = yoff = -1; - + px = (int)( (x - xoff) * xsize); py = (int)( (y - yoff) * ysize); - + if ( (!xsize) || (!ysize) ) return; - + if (!ibuf->rect_float) { BLI_thread_lock(LOCK_IMAGE); if (!ibuf->rect_float) IMB_float_from_rect(ibuf); BLI_thread_unlock(LOCK_IMAGE); } - + while (px < 0) px += ibuf->x; while (py < 0) py += ibuf->y; while (px >= ibuf->x) px -= ibuf->x; while (py >= ibuf->y) py -= ibuf->y; - + result = ibuf->rect_float + py * ibuf->x * 4 + px * 4; copy_v4_v4(out, result); @@ -100,7 +100,7 @@ static void init(bNodeTree *UNUSED(ntree), bNode *node) void register_node_type_tex_image(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_IMAGE, "Image", NODE_CLASS_INPUT, NODE_PREVIEW); node_type_socket_templates(&ntype, NULL, outputs); node_type_init(&ntype, init); diff --git a/source/blender/nodes/texture/nodes/node_texture_invert.c b/source/blender/nodes/texture/nodes/node_texture_invert.c index 35f5072d8a2..8ef7a7a6ad2 100644 --- a/source/blender/nodes/texture/nodes/node_texture_invert.c +++ b/source/blender/nodes/texture/nodes/node_texture_invert.c @@ -33,7 +33,7 @@ #include "node_texture_util.h" #include "NOD_texture.h" -/* **************** INVERT ******************** */ +/* **************** INVERT ******************** */ static bNodeSocketTemplate inputs[] = { { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, { -1, 0, "" } @@ -47,13 +47,13 @@ static bNodeSocketTemplate outputs[] = { static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) { float col[4]; - + tex_input_rgba(col, in[0], p, thread); col[0] = 1.0f - col[0]; col[1] = 1.0f - col[1]; col[2] = 1.0f - col[2]; - + copy_v3_v3(out, col); out[3] = col[3]; } @@ -66,10 +66,10 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe void register_node_type_tex_invert(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR, 0); node_type_socket_templates(&ntype, inputs, outputs); node_type_exec(&ntype, NULL, NULL, exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_mixRgb.c b/source/blender/nodes/texture/nodes/node_texture_mixRgb.c index 835a49c24d4..9fb8332c61a 100644 --- a/source/blender/nodes/texture/nodes/node_texture_mixRgb.c +++ b/source/blender/nodes/texture/nodes/node_texture_mixRgb.c @@ -49,16 +49,16 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor { float fac = tex_input_value(in[0], p, thread); float col1[4], col2[4]; - + tex_input_rgba(col1, in[1], p, thread); tex_input_rgba(col2, in[2], p, thread); /* use alpha */ if (node->custom2 & 1) fac *= col2[3]; - + CLAMP(fac, 0.0f, 1.0f); - + copy_v4_v4(out, col1); ramp_blend(node->custom1, out, fac, col2); } @@ -71,11 +71,11 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe void register_node_type_tex_mix_rgb(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, 0); node_type_socket_templates(&ntype, inputs, outputs); node_type_label(&ntype, node_blend_label); node_type_exec(&ntype, NULL, NULL, exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_output.c b/source/blender/nodes/texture/nodes/node_texture_output.c index 664b7e4f507..412e3ffb56c 100644 --- a/source/blender/nodes/texture/nodes/node_texture_output.c +++ b/source/blender/nodes/texture/nodes/node_texture_output.c @@ -45,7 +45,7 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe { TexCallData *cdata = (TexCallData *)data; TexResult *target = cdata->target; - + if (cdata->do_preview) { TexParams params; params_from_cdata(¶ms, cdata); @@ -61,12 +61,12 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe if (cdata->which_output == node->custom1 || (cdata->which_output == 0 && node->custom1 == 1)) { TexParams params; params_from_cdata(¶ms, cdata); - + tex_input_rgba(&target->tr, in[0], ¶ms, cdata->thread); - + target->tin = (target->tr + target->tg + target->tb) / 3.0f; target->talpha = true; - + if (target->nor) { if (in[1] && in[1]->hasinput) tex_input_vec(target->nor, in[1], ¶ms, cdata->thread); @@ -85,7 +85,7 @@ static void unique_name(bNode *node) int suffix; bNode *i; const char *name = tno->name; - + new_name[0] = '\0'; i = node; while (i->prev) i = i->prev; @@ -114,7 +114,7 @@ static void unique_name(bNode *node) } sprintf(new_name + new_len - 4, ".%03d", ++suffix); } - + if (new_name[0] != '\0') { BLI_strncpy(tno->name, new_name, sizeof(tno->name)); } @@ -124,11 +124,11 @@ static void assign_index(struct bNode *node) { bNode *tnode; int index = 1; - + tnode = node; while (tnode->prev) tnode = tnode->prev; - + check_index: for (; tnode; tnode = tnode->next) if (tnode->type == TEX_NODE_OUTPUT && tnode != node) @@ -136,7 +136,7 @@ check_index: index++; goto check_index; } - + node->custom1 = index; } @@ -144,7 +144,7 @@ static void init(bNodeTree *UNUSED(ntree), bNode *node) { TexNodeOutput *tno = MEM_callocN(sizeof(TexNodeOutput), "TEX_output"); node->storage = tno; - + strcpy(tno->name, "Default"); unique_name(node); assign_index(node); @@ -160,16 +160,16 @@ static void copy(bNodeTree *dest_ntree, bNode *dest_node, bNode *src_node) void register_node_type_tex_output(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_OUTPUT, "Output", NODE_CLASS_OUTPUT, NODE_PREVIEW); node_type_socket_templates(&ntype, inputs, NULL); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, init); node_type_storage(&ntype, "TexNodeOutput", node_free_standard_storage, copy); node_type_exec(&ntype, NULL, NULL, exec); - + /* Do not allow muting output. */ node_type_internal_links(&ntype, NULL); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_proc.c b/source/blender/nodes/texture/nodes/node_texture_proc.c index ee270179e72..76f5e7d5c5b 100644 --- a/source/blender/nodes/texture/nodes/node_texture_proc.c +++ b/source/blender/nodes/texture/nodes/node_texture_proc.c @@ -35,7 +35,7 @@ #include "RE_shader_ext.h" -/* +/* * In this file: wrappers to use procedural textures as nodes */ @@ -61,19 +61,19 @@ static void do_proc(float *result, TexParams *p, const float col1[4], const floa { TexResult texres; int textype; - + if (is_normal) { texres.nor = result; } else texres.nor = NULL; - + textype = multitex_nodes(tex, p->co, p->dxt, p->dyt, p->osatex, &texres, thread, 0, p->shi, p->mtex, NULL); - + if (is_normal) return; - + if (textype & TEX_RGB) { copy_v4_v4(result, &texres.tr); } @@ -86,11 +86,11 @@ static void do_proc(float *result, TexParams *p, const float col1[4], const floa typedef void (*MapFn) (Tex *tex, bNodeStack **in, TexParams *p, const short thread); static void texfn( - float *result, + float *result, TexParams *p, - bNode *node, + bNode *node, bNodeStack **in, - char is_normal, + char is_normal, MapFn map_inputs, short thread) { @@ -98,9 +98,9 @@ static void texfn( float col1[4], col2[4]; tex_input_rgba(col1, in[0], p, thread); tex_input_rgba(col2, in[1], p, thread); - + map_inputs(&tex, in, p, thread); - + do_proc(result, p, col1, col2, is_normal, &tex, thread); } @@ -144,10 +144,10 @@ static bNodeSocketTemplate voronoi_inputs[] = { { SOCK_FLOAT, 1, N_("W2"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE }, { SOCK_FLOAT, 1, N_("W3"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE }, { SOCK_FLOAT, 1, N_("W4"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE }, - + { SOCK_FLOAT, 1, N_("iScale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.01f, 10.0f, PROP_UNSIGNED }, { SOCK_FLOAT, 1, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 4.0f, PROP_UNSIGNED }, - + { -1, 0, "" } }; static void voronoi_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread) @@ -156,7 +156,7 @@ static void voronoi_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short th tex->vn_w2 = tex_input_value(in[I + 1], p, thread); tex->vn_w3 = tex_input_value(in[I + 2], p, thread); tex->vn_w4 = tex_input_value(in[I + 3], p, thread); - + tex->ns_outscale = tex_input_value(in[I + 4], p, thread); tex->noisesize = tex_input_value(in[I + 5], p, thread); } @@ -242,7 +242,7 @@ static bNodeSocketTemplate musgrave_inputs[] = { { SOCK_FLOAT, 1, N_("H"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED }, { SOCK_FLOAT, 1, N_("Lacunarity"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 6.0f, PROP_UNSIGNED }, { SOCK_FLOAT, 1, N_("Octaves"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 8.0f, PROP_UNSIGNED }, - + { SOCK_FLOAT, 1, N_("iScale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f, PROP_UNSIGNED }, { SOCK_FLOAT, 1, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED }, { -1, 0, "" } @@ -285,13 +285,13 @@ static void init(bNodeTree *UNUSED(ntree), bNode *node) { Tex *tex = MEM_callocN(sizeof(Tex), "Tex"); node->storage = tex; - + BKE_texture_default(tex); tex->type = node->type - TEX_NODE_PROC; - + if (tex->type == TEX_WOOD) tex->stype = TEX_BANDNOISE; - + } /* Node type definitions */ @@ -309,10 +309,10 @@ void register_node_type_tex_proc_##name(void) \ \ nodeRegisterType(&ntype); \ } - + #define C outputs_color_only #define CV outputs_both - + TexDef(TEX_VORONOI, CV, voronoi, "Voronoi" ) TexDef(TEX_BLEND, C, blend, "Blend" ) TexDef(TEX_MAGIC, C, magic, "Magic" ) diff --git a/source/blender/nodes/texture/nodes/node_texture_rotate.c b/source/blender/nodes/texture/nodes/node_texture_rotate.c index 99648ec323f..bc4e56ea81d 100644 --- a/source/blender/nodes/texture/nodes/node_texture_rotate.c +++ b/source/blender/nodes/texture/nodes/node_texture_rotate.c @@ -52,18 +52,18 @@ static void rotate(float new_co[3], float a, float ax[3], const float co[3]) float para[3]; float perp[3]; float cp[3]; - + float cos_a = cosf(a * (float)(2 * M_PI)); float sin_a = sinf(a * (float)(2 * M_PI)); - + // x' = xcosa + n(n.x)(1-cosa) + (x*n)sina - + mul_v3_v3fl(perp, co, cos_a); mul_v3_v3fl(para, ax, dot_v3v3(co, ax) * (1 - cos_a)); - + cross_v3_v3v3(cp, ax, co); mul_v3_fl(cp, sin_a); - + new_co[0] = para[0] + perp[0] + cp[0]; new_co[1] = para[1] + perp[1] + cp[1]; new_co[2] = para[2] + perp[2] + cp[2]; @@ -72,7 +72,7 @@ static void rotate(float new_co[3], float a, float ax[3], const float co[3]) static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread) { float new_co[3], new_dxt[3], new_dyt[3], a, ax[3]; - + a = tex_input_value(in[1], p, thread); tex_input_vec(ax, in[2], p, thread); @@ -81,7 +81,7 @@ static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack ** rotate(new_dxt, a, ax, p->dxt); rotate(new_dyt, a, ax, p->dyt); } - + { TexParams np = *p; np.co = new_co; @@ -90,7 +90,7 @@ static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack ** tex_input_rgba(out, in[0], &np, thread); } } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) { tex_output(node, execdata, in, out[0], &colorfn, data); } @@ -98,10 +98,10 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe void register_node_type_tex_rotate(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_ROTATE, "Rotate", NODE_CLASS_DISTORT, 0); node_type_socket_templates(&ntype, inputs, outputs); node_type_exec(&ntype, NULL, NULL, exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_scale.c b/source/blender/nodes/texture/nodes/node_texture_scale.c index d623e8e159a..94ccfd01357 100644 --- a/source/blender/nodes/texture/nodes/node_texture_scale.c +++ b/source/blender/nodes/texture/nodes/node_texture_scale.c @@ -52,7 +52,7 @@ static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack ** np.co = new_co; np.dxt = new_dxt; np.dyt = new_dyt; - + tex_input_vec(scale, in[1], p, thread); mul_v3_v3v3(new_co, p->co, scale); @@ -60,10 +60,10 @@ static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack ** mul_v3_v3v3(new_dxt, p->dxt, scale); mul_v3_v3v3(new_dyt, p->dyt, scale); } - + tex_input_rgba(out, in[0], &np, thread); } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) { tex_output(node, execdata, in, out[0], &colorfn, data); } @@ -71,10 +71,10 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe void register_node_type_tex_scale(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_SCALE, "Scale", NODE_CLASS_DISTORT, 0); node_type_socket_templates(&ntype, inputs, outputs); node_type_exec(&ntype, NULL, NULL, exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_texture.c b/source/blender/nodes/texture/nodes/node_texture_texture.c index 04d007bbb2b..57703e3a044 100644 --- a/source/blender/nodes/texture/nodes/node_texture_texture.c +++ b/source/blender/nodes/texture/nodes/node_texture_texture.c @@ -52,7 +52,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor static float red[] = {1, 0, 0, 1}; static float white[] = {1, 1, 1, 1}; float co[3], dxt[3], dyt[3]; - + copy_v3_v3(co, p->co); if (p->osatex) { copy_v3_v3(dxt, p->dxt); @@ -62,7 +62,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor zero_v3(dxt); zero_v3(dyt); } - + if (node->custom2 || node->need_exec == 0) { /* this node refers to its own texture tree! */ copy_v4_v4(out, (fabsf(co[0] - co[1]) < 0.01f) ? white : red); @@ -72,14 +72,14 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor int textype; float nor[] = {0, 0, 0}; float col1[4], col2[4]; - + tex_input_rgba(col1, in[0], p, thread); tex_input_rgba(col2, in[1], p, thread); - + texres.nor = nor; textype = multitex_nodes(nodetex, co, dxt, dyt, p->osatex, &texres, thread, 0, p->shi, p->mtex, NULL); - + if (textype & TEX_RGB) { copy_v4_v4(out, &texres.tr); } @@ -98,10 +98,10 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe void register_node_type_tex_texture(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_TEXTURE, "Texture", NODE_CLASS_INPUT, NODE_PREVIEW); node_type_socket_templates(&ntype, inputs, outputs); node_type_exec(&ntype, NULL, NULL, exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_translate.c b/source/blender/nodes/texture/nodes/node_texture_translate.c index ec90029c0bf..fa8319d077b 100644 --- a/source/blender/nodes/texture/nodes/node_texture_translate.c +++ b/source/blender/nodes/texture/nodes/node_texture_translate.c @@ -50,16 +50,16 @@ static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack ** float offset[3], new_co[3]; TexParams np = *p; np.co = new_co; - + tex_input_vec(offset, in[1], p, thread); - + new_co[0] = p->co[0] + offset[0]; new_co[1] = p->co[1] + offset[1]; new_co[2] = p->co[2] + offset[2]; - + tex_input_rgba(out, in[0], &np, thread); } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) { tex_output(node, execdata, in, out[0], &colorfn, data); } @@ -67,10 +67,10 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe void register_node_type_tex_translate(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_TRANSLATE, "Translate", NODE_CLASS_DISTORT, 0); node_type_socket_templates(&ntype, inputs, outputs); node_type_exec(&ntype, NULL, NULL, exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_valToNor.c b/source/blender/nodes/texture/nodes/node_texture_valToNor.c index 995fb6c1782..b7d57b4d4cf 100644 --- a/source/blender/nodes/texture/nodes/node_texture_valToNor.c +++ b/source/blender/nodes/texture/nodes/node_texture_valToNor.c @@ -52,7 +52,7 @@ static void normalfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack * float nabla = tex_input_value(in[1], p, thread); float val; float nor[3]; - + TexParams np = *p; np.co = new_co; @@ -66,7 +66,7 @@ static void normalfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack * new_co[0] = co[0]; new_co[1] = co[1] + nabla; nor[1] = tex_input_value(in[0], &np, thread); - + new_co[1] = co[1]; new_co[2] = co[2] + nabla; nor[2] = tex_input_value(in[0], &np, thread); @@ -75,7 +75,7 @@ static void normalfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack * out[1] = val - nor[1]; out[2] = val - nor[2]; } -static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) { tex_output(node, execdata, in, out[0], &normalfn, data); } @@ -83,10 +83,10 @@ static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *exe void register_node_type_tex_valtonor(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_VALTONOR, "Value to Normal", NODE_CLASS_CONVERTOR, 0); node_type_socket_templates(&ntype, inputs, outputs); node_type_exec(&ntype, NULL, NULL, exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_valToRgb.c b/source/blender/nodes/texture/nodes/node_texture_valToRgb.c index 4041d666811..ad3c4344f34 100644 --- a/source/blender/nodes/texture/nodes/node_texture_valToRgb.c +++ b/source/blender/nodes/texture/nodes/node_texture_valToRgb.c @@ -53,7 +53,7 @@ static void valtorgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack * } } -static void valtorgb_exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) +static void valtorgb_exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) { tex_output(node, execdata, in, out[0], &valtorgb_colorfn, data); } @@ -66,14 +66,14 @@ static void valtorgb_init(bNodeTree *UNUSED(ntree), bNode *node) void register_node_type_tex_valtorgb(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, 0); node_type_socket_templates(&ntype, valtorgb_in, valtorgb_out); node_type_size_preset(&ntype, NODE_SIZE_LARGE); node_type_init(&ntype, valtorgb_init); node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); node_type_exec(&ntype, NULL, NULL, valtorgb_exec); - + nodeRegisterType(&ntype); } @@ -103,10 +103,10 @@ static void rgbtobw_exec(void *data, int UNUSED(thread), bNode *node, bNodeExecD void register_node_type_tex_rgbtobw(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0); node_type_socket_templates(&ntype, rgbtobw_in, rgbtobw_out); node_type_exec(&ntype, NULL, NULL, rgbtobw_exec); - + nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_viewer.c b/source/blender/nodes/texture/nodes/node_texture_viewer.c index fefa06b0078..69f4d3ca086 100644 --- a/source/blender/nodes/texture/nodes/node_texture_viewer.c +++ b/source/blender/nodes/texture/nodes/node_texture_viewer.c @@ -59,13 +59,13 @@ static void exec(void *data, int UNUSED(thread), bNode *UNUSED(node), bNodeExecD void register_node_type_tex_viewer(void) { static bNodeType ntype; - + tex_node_type_base(&ntype, TEX_NODE_VIEWER, "Viewer", NODE_CLASS_OUTPUT, NODE_PREVIEW); node_type_socket_templates(&ntype, inputs, outputs); node_type_exec(&ntype, NULL, NULL, exec); - + /* Do not allow muting viewer node. */ node_type_internal_links(&ntype, NULL); - + nodeRegisterType(&ntype); } diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp index 5b5639495da..750073dae1f 100644 --- a/source/blender/physics/intern/BPH_mass_spring.cpp +++ b/source/blender/physics/intern/BPH_mass_spring.cpp @@ -60,7 +60,7 @@ static int cloth_count_nondiag_blocks(Cloth *cloth) { LinkNode *link; int nondiag = 0; - + for (link = cloth->springs; link; link = link->next) { ClothSpring *spring = (ClothSpring *)link->link; switch (spring->type) { @@ -68,14 +68,14 @@ static int cloth_count_nondiag_blocks(Cloth *cloth) /* angular bending combines 3 vertices */ nondiag += 3; break; - + default: /* all other springs depend on 2 vertices only */ nondiag += 1; break; } } - + return nondiag; } @@ -86,25 +86,25 @@ int BPH_cloth_solver_init(Object *UNUSED(ob), ClothModifierData *clmd) const float ZERO[3] = {0.0f, 0.0f, 0.0f}; Implicit_Data *id; unsigned int i, nondiag; - + nondiag = cloth_count_nondiag_blocks(cloth); cloth->implicit = id = BPH_mass_spring_solver_create(cloth->mvert_num, nondiag); - + for (i = 0; i < cloth->mvert_num; i++) { BPH_mass_spring_set_vertex_mass(id, i, verts[i].mass); } - + for (i = 0; i < cloth->mvert_num; i++) { BPH_mass_spring_set_motion_state(id, i, verts[i].x, ZERO); } - + return 1; } void BPH_cloth_solver_free(ClothModifierData *clmd) { Cloth *cloth = clmd->clothObject; - + if (cloth->implicit) { BPH_mass_spring_solver_free(cloth->implicit); cloth->implicit = NULL; @@ -118,7 +118,7 @@ void BKE_cloth_solver_set_positions(ClothModifierData *clmd) unsigned int mvert_num = cloth->mvert_num, i; ClothHairData *cloth_hairdata = clmd->hairdata; Implicit_Data *id = cloth->implicit; - + for (i = 0; i < mvert_num; i++) { if (cloth_hairdata) { ClothHairData *root = &cloth_hairdata[i]; @@ -126,7 +126,7 @@ void BKE_cloth_solver_set_positions(ClothModifierData *clmd) } else BPH_mass_spring_set_rest_transform(id, i, I3); - + BPH_mass_spring_set_motion_state(id, i, verts[i].x, verts[i].v); } } @@ -136,22 +136,22 @@ static bool collision_response(ClothModifierData *clmd, CollisionModifierData *c Cloth *cloth = clmd->clothObject; int index = collpair->ap1; bool result = false; - + float v1[3], v2_old[3], v2_new[3], v_rel_old[3], v_rel_new[3]; float epsilon2 = BLI_bvhtree_get_epsilon(collmd->bvhtree); float margin_distance = (float)collpair->distance - epsilon2; float mag_v_rel; - + zero_v3(r_impulse); - + if (margin_distance > 0.0f) return false; /* XXX tested before already? */ - + /* only handle static collisions here */ if ( collpair->flag & COLLISION_IN_FUTURE ) return false; - + /* velocity */ copy_v3_v3(v1, cloth->verts[index].v); collision_get_collider_velocity(v2_old, v2_new, collmd, collpair); @@ -160,32 +160,32 @@ static bool collision_response(ClothModifierData *clmd, CollisionModifierData *c sub_v3_v3v3(v_rel_new, v1, v2_new); /* normal component of the relative velocity */ mag_v_rel = dot_v3v3(v_rel_old, collpair->normal); - + /* only valid when moving toward the collider */ if (mag_v_rel < -ALMOST_ZERO) { float v_nor_old, v_nor_new; float v_tan_old[3], v_tan_new[3]; float bounce, repulse; - + /* Collision response based on * "Simulating Complex Hair with Robust Collision Handling" (Choe, Choi, Ko, ACM SIGGRAPH 2005) * http://graphics.snu.ac.kr/publications/2005-choe-HairSim/Choe_2005_SCA.pdf */ - + v_nor_old = mag_v_rel; v_nor_new = dot_v3v3(v_rel_new, collpair->normal); - + madd_v3_v3v3fl(v_tan_old, v_rel_old, collpair->normal, -v_nor_old); madd_v3_v3v3fl(v_tan_new, v_rel_new, collpair->normal, -v_nor_new); - + bounce = -v_nor_old * restitution; - + repulse = -margin_distance / dt; /* base repulsion velocity in normal direction */ /* XXX this clamping factor is quite arbitrary ... * not sure if there is a more scientific approach, but seems to give good results */ CLAMP(repulse, 0.0f, 4.0f * bounce); - + if (margin_distance < -epsilon2) { mul_v3_v3fl(r_impulse, collpair->normal, max_ff(repulse, bounce) - v_nor_new); } @@ -193,10 +193,10 @@ static bool collision_response(ClothModifierData *clmd, CollisionModifierData *c bounce = 0.0f; mul_v3_v3fl(r_impulse, collpair->normal, repulse - v_nor_new); } - + result = true; } - + return result; } @@ -211,17 +211,17 @@ static void cloth_setup_constraints(ClothModifierData *clmd, ColliderContacts *c ClothVertex *verts = cloth->verts; int mvert_num = cloth->mvert_num; int i, j, v; - + const float ZERO[3] = {0.0f, 0.0f, 0.0f}; - + BPH_mass_spring_clear_constraints(data); - + for (v = 0; v < mvert_num; v++) { if (verts[v].flags & CLOTH_VERT_FLAG_PINNED) { /* pinned vertex constraints */ BPH_mass_spring_add_constraint_ndof0(data, v, ZERO); /* velocity is defined externally */ } - + verts[v].impulse_count = 0; } @@ -233,21 +233,21 @@ static void cloth_setup_constraints(ClothModifierData *clmd, ColliderContacts *c float restitution = 0.0f; int v = collpair->face1; float impulse[3]; - + /* pinned verts handled separately */ if (verts[v].flags & CLOTH_VERT_FLAG_PINNED) continue; - + /* XXX cheap way of avoiding instability from multiple collisions in the same step * this should eventually be supported ... */ if (verts[v].impulse_count > 0) continue; - + /* calculate collision response */ if (!collision_response(clmd, ct->collmd, collpair, dt, restitution, impulse)) continue; - + BPH_mass_spring_add_constraint_ndof2(data, v, collpair->normal, impulse); ++verts[v].impulse_count; } @@ -267,11 +267,11 @@ static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), ClothMo ClothSpring *spring; ClothVertex *cv; int i, steps; - + cv = cloth->verts; for (i = 0; i < cloth->mvert_num; i++, cv++) { copy_v3_v3(cos[i], cv->tx); - + if (cv->goal == 1.0f || len_squared_v3v3(initial_cos[i], cv->tx) != 0.0f) { masses[i] = 1e+10; } @@ -279,57 +279,57 @@ static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), ClothMo masses[i] = cv->mass; } } - + steps = 55; for (i=0; isprings; node; node=node->next) { /* ClothVertex *cv1, *cv2; */ /* UNUSED */ int v1, v2; float len, c, l, vec[3]; - + spring = (ClothSpring *)node->link; - if (spring->type != CLOTH_SPRING_TYPE_STRUCTURAL && spring->type != CLOTH_SPRING_TYPE_SHEAR) + if (spring->type != CLOTH_SPRING_TYPE_STRUCTURAL && spring->type != CLOTH_SPRING_TYPE_SHEAR) continue; - + v1 = spring->ij; v2 = spring->kl; /* cv1 = cloth->verts + v1; */ /* UNUSED */ /* cv2 = cloth->verts + v2; */ /* UNUSED */ len = len_v3v3(cos[v1], cos[v2]); - + sub_v3_v3v3(vec, cos[v1], cos[v2]); normalize_v3(vec); - + c = (len - spring->restlen); if (c == 0.0f) continue; - + l = c / ((1.0f / masses[v1]) + (1.0f / masses[v2])); - + mul_v3_fl(vec, -(1.0f / masses[v1]) * l); add_v3_v3(cos[v1], vec); - + sub_v3_v3v3(vec, cos[v2], cos[v1]); normalize_v3(vec); - + mul_v3_fl(vec, -(1.0f / masses[v2]) * l); add_v3_v3(cos[v2], vec); } } - + cv = cloth->verts; for (i = 0; i < cloth->mvert_num; i++, cv++) { float vec[3]; - + /*compute forces*/ sub_v3_v3v3(vec, cos[i], cv->tx); mul_v3_fl(vec, cv->mass*dt*20.0f); add_v3_v3(cv->tv, vec); //copy_v3_v3(cv->tx, cos[i]); } - + MEM_freeN(cos); MEM_freeN(masses); - + return 1; } @@ -338,21 +338,21 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s) Cloth *cloth = clmd->clothObject; ClothSimSettings *parms = clmd->sim_parms; Implicit_Data *data = cloth->implicit; - + bool no_compress = parms->flags & CLOTH_SIMSETTINGS_FLAG_NO_SPRING_COMPRESS; - + s->flags &= ~CLOTH_SPRING_FLAG_NEEDED; - + // calculate force of structural + shear springs if ((s->type & CLOTH_SPRING_TYPE_STRUCTURAL) || (s->type & CLOTH_SPRING_TYPE_SHEAR) || (s->type & CLOTH_SPRING_TYPE_SEWING) ) { #ifdef CLOTH_FORCE_SPRING_STRUCTURAL float k, scaling; - + s->flags |= CLOTH_SPRING_FLAG_NEEDED; - + scaling = parms->structural + s->stiffness * fabsf(parms->max_struct - parms->structural); k = scaling / (parms->avg_spring_len + FLT_EPSILON); - + if (s->type & CLOTH_SPRING_TYPE_SEWING) { // TODO: verify, half verified (couldn't see error) // sewing springs usually have a large distance at first so clamp the force so we don't get tunnelling through colission objects @@ -366,50 +366,50 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s) else if (s->type & CLOTH_SPRING_TYPE_BENDING) { /* calculate force of bending springs */ #ifdef CLOTH_FORCE_SPRING_BEND float kb, cb, scaling; - + s->flags |= CLOTH_SPRING_FLAG_NEEDED; - + scaling = parms->bending + s->stiffness * fabsf(parms->max_bend - parms->bending); kb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON)); - + // Fix for [#45084] for cloth stiffness must have cb proportional to kb cb = kb * parms->bending_damping; - + BPH_mass_spring_force_spring_bending(data, s->ij, s->kl, s->restlen, kb, cb); #endif } else if (s->type & CLOTH_SPRING_TYPE_BENDING_ANG) { #ifdef CLOTH_FORCE_SPRING_BEND float kb, cb, scaling; - + s->flags |= CLOTH_SPRING_FLAG_NEEDED; - + /* XXX WARNING: angular bending springs for hair apply stiffness factor as an overall factor, unlike cloth springs! * this is crap, but needed due to cloth/hair mixing ... * max_bend factor is not even used for hair, so ... */ scaling = s->stiffness * parms->bending; kb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON)); - + // Fix for [#45084] for cloth stiffness must have cb proportional to kb cb = kb * parms->bending_damping; - + /* XXX assuming same restlen for ij and jk segments here, this can be done correctly for hair later */ BPH_mass_spring_force_spring_bending_angular(data, s->ij, s->kl, s->mn, s->target, kb, cb); - + #if 0 { float x_kl[3], x_mn[3], v[3], d[3]; - + BPH_mass_spring_get_motion_state(data, s->kl, x_kl, v); BPH_mass_spring_get_motion_state(data, s->mn, x_mn, v); - + BKE_sim_debug_data_add_dot(clmd->debug_data, x_kl, 0.9, 0.9, 0.9, "target", 7980, s->kl); BKE_sim_debug_data_add_line(clmd->debug_data, x_kl, x_mn, 0.8, 0.8, 0.8, "target", 7981, s->kl); - + copy_v3_v3(d, s->target); BKE_sim_debug_data_add_vector(clmd->debug_data, x_kl, d, 0.8, 0.8, 0.2, "target", 7982, s->kl); - + // copy_v3_v3(d, s->target_ij); // BKE_sim_debug_data_add_vector(clmd->debug_data, x, d, 1, 0.4, 0.4, "target", 7983, s->kl); } @@ -424,7 +424,7 @@ static void hair_get_boundbox(ClothModifierData *clmd, float gmin[3], float gmax Implicit_Data *data = cloth->implicit; unsigned int mvert_num = cloth->mvert_num; int i; - + INIT_MINMAX(gmin, gmax); for (i = 0; i < mvert_num; i++) { float x[3]; @@ -444,7 +444,7 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB const MVertTri *tri = cloth->tri; unsigned int mvert_num = cloth->mvert_num; ClothVertex *vert; - + #ifdef CLOTH_FORCE_GRAVITY /* global acceleration (gravitation) */ if (clmd->scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) { @@ -477,7 +477,7 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB #ifdef CLOTH_FORCE_DRAG BPH_mass_spring_force_drag(data, drag); #endif - + /* handle external forces like wind */ if (effectors) { /* cache per-vertex forces to avoid redundant calculation */ @@ -485,12 +485,12 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB for (i = 0; i < cloth->mvert_num; i++) { float x[3], v[3]; EffectedPoint epoint; - + BPH_mass_spring_get_motion_state(data, i, x, v); pd_point_from_loc(clmd->scene, x, v, i, &epoint); pdDoEffectors(effectors, NULL, clmd->sim_parms->effector_weights, &epoint, winvec[i], NULL); } - + for (i = 0; i < cloth->tri_num; i++) { const MVertTri *vt = &tri[i]; BPH_mass_spring_force_face_wind(data, vt->tri[0], vt->tri[1], vt->tri[2], winvec); @@ -501,7 +501,7 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB #if 0 ClothHairData *hairdata = clmd->hairdata; ClothHairData *hair_ij, *hair_kl; - + for (LinkNode *link = cloth->springs; link; link = link->next) { ClothSpring *spring = (ClothSpring *)link->link; if (spring->type == CLOTH_SPRING_TYPE_STRUCTURAL) { @@ -516,7 +516,7 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB } #else ClothHairData *hairdata = clmd->hairdata; - + vert = cloth->verts; for (i = 0; i < cloth->mvert_num; i++, vert++) { if (hairdata) { @@ -531,7 +531,7 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB MEM_freeN(winvec); } - + // calculate spring forces for (LinkNode *link = cloth->springs; link; link = link->next) { ClothSpring *spring = (ClothSpring *)link->link; @@ -548,7 +548,7 @@ BLI_INLINE void cloth_get_grid_location(Implicit_Data *data, float cell_scale, c { BPH_mass_spring_get_position(data, index, x); BPH_mass_spring_get_new_velocity(data, index, v); - + mul_v3_fl(x, cell_scale); add_v3_v3(x, cell_offset); } @@ -582,41 +582,41 @@ static LinkNode *cloth_continuum_add_hair_segments(HairGrid *grid, const float c // ClothVertex *vert3, *vert4; float x1[3], v1[3], x2[3], v2[3], x3[3], v3[3], x4[3], v4[3]; float dir1[3], dir2[3], dir3[3]; - + spring1 = NULL; spring2 = NULL; spring3 = (ClothSpring *)spring_link->link; - + zero_v3(x1); zero_v3(v1); zero_v3(dir1); zero_v3(x2); zero_v3(v2); zero_v3(dir2); - + // vert3 = &verts[spring3->kl]; cloth_get_grid_location(data, cell_scale, cell_offset, spring3->kl, x3, v3); // vert4 = &verts[spring3->ij]; cloth_get_grid_location(data, cell_scale, cell_offset, spring3->ij, x4, v4); sub_v3_v3v3(dir3, x4, x3); normalize_v3(dir3); - + while (spring_link) { /* move on */ spring1 = spring2; spring2 = spring3; - + // vert3 = vert4; - + copy_v3_v3(x1, x2); copy_v3_v3(v1, v2); copy_v3_v3(x2, x3); copy_v3_v3(v2, v3); copy_v3_v3(x3, x4); copy_v3_v3(v3, v4); - + copy_v3_v3(dir1, dir2); copy_v3_v3(dir2, dir3); - + /* read next segment */ next_spring_link = spring_link->next; spring_link = hair_spring_next(spring_link); - + if (spring_link) { spring3 = (ClothSpring *)spring_link->link; // vert4 = &verts[spring3->ij]; @@ -630,13 +630,13 @@ static LinkNode *cloth_continuum_add_hair_segments(HairGrid *grid, const float c zero_v3(x4); zero_v3(v4); zero_v3(dir3); } - + BPH_hair_volume_add_segment(grid, x1, v1, x2, v2, x3, v3, x4, v4, spring1 ? dir1 : NULL, dir2, spring3 ? dir3 : NULL); } - + return next_spring_link; } @@ -647,17 +647,17 @@ static void cloth_continuum_fill_grid(HairGrid *grid, Cloth *cloth) int mvert_num = cloth->mvert_num; ClothVertex *vert; int i; - + for (i = 0, vert = cloth->verts; i < mvert_num; i++, vert++) { float x[3], v[3]; - + cloth_get_vertex_motion_state(data, vert, x, v); BPH_hair_volume_add_vertex(grid, x, v); } #else LinkNode *link; float cellsize, gmin[3], cell_scale, cell_offset[3]; - + /* scale and offset for transforming vertex locations into grid space * (cell size is 0..1, gmin becomes origin) */ @@ -665,7 +665,7 @@ static void cloth_continuum_fill_grid(HairGrid *grid, Cloth *cloth) cell_scale = cellsize > 0.0f ? 1.0f / cellsize : 0.0f; mul_v3_v3fl(cell_offset, gmin, cell_scale); negate_v3(cell_offset); - + link = cloth->springs; while (link) { ClothSpring *spring = (ClothSpring *)link->link; @@ -685,7 +685,7 @@ static void cloth_continuum_step(ClothModifierData *clmd, float dt) Implicit_Data *data = cloth->implicit; int mvert_num = cloth->mvert_num; ClothVertex *vert; - + const float fluid_factor = 0.95f; /* blend between PIC and FLIP methods */ float smoothfac = parms->velocity_smooth; /* XXX FIXME arbitrary factor!!! this should be based on some intuitive value instead, @@ -695,42 +695,42 @@ static void cloth_continuum_step(ClothModifierData *clmd, float dt) float density_strength = parms->density_strength; float gmin[3], gmax[3]; int i; - + /* clear grid info */ zero_v3_int(clmd->hair_grid_res); zero_v3(clmd->hair_grid_min); zero_v3(clmd->hair_grid_max); clmd->hair_grid_cellsize = 0.0f; - + hair_get_boundbox(clmd, gmin, gmax); - + /* gather velocities & density */ if (smoothfac > 0.0f || density_strength > 0.0f) { HairGrid *grid = BPH_hair_volume_create_vertex_grid(clmd->sim_parms->voxel_cell_size, gmin, gmax); - + cloth_continuum_fill_grid(grid, cloth); - + /* main hair continuum solver */ BPH_hair_volume_solve_divergence(grid, dt, density_target, density_strength); - + for (i = 0, vert = cloth->verts; i < mvert_num; i++, vert++) { float x[3], v[3], nv[3]; - + /* calculate volumetric velocity influence */ BPH_mass_spring_get_position(data, i, x); BPH_mass_spring_get_new_velocity(data, i, v); - + BPH_hair_volume_grid_velocity(grid, x, v, fluid_factor, nv); - + interp_v3_v3v3(nv, v, nv, smoothfac); - + /* apply on hair data */ BPH_mass_spring_set_new_velocity(data, i, nv); } - + /* store basic grid info in the modifier data */ BPH_hair_volume_grid_geometry(grid, &clmd->hair_grid_cellsize, clmd->hair_grid_res, clmd->hair_grid_min, clmd->hair_grid_max); - + #if 0 /* DEBUG hair velocity vector field */ { const int size = 64; @@ -738,26 +738,26 @@ static void cloth_continuum_step(ClothModifierData *clmd, float dt) float offset[3], a[3], b[3]; const int axis = 0; const float shift = 0.0f; - + copy_v3_v3(offset, clmd->hair_grid_min); zero_v3(a); zero_v3(b); - + offset[axis] = shift * clmd->hair_grid_cellsize; a[(axis+1) % 3] = clmd->hair_grid_max[(axis+1) % 3] - clmd->hair_grid_min[(axis+1) % 3]; b[(axis+2) % 3] = clmd->hair_grid_max[(axis+2) % 3] - clmd->hair_grid_min[(axis+2) % 3]; - + BKE_sim_debug_data_clear_category(clmd->debug_data, "grid velocity"); for (j = 0; j < size; ++j) { for (i = 0; i < size; ++i) { float x[3], v[3], gvel[3], gvel_smooth[3], gdensity; - + madd_v3_v3v3fl(x, offset, a, (float)i / (float)(size-1)); madd_v3_v3fl(x, b, (float)j / (float)(size-1)); zero_v3(v); - + BPH_hair_volume_grid_interpolate(grid, x, &gdensity, gvel, gvel_smooth, NULL, NULL); - + // BKE_sim_debug_data_add_circle(clmd->debug_data, x, gdensity, 0.7, 0.3, 1, "grid density", i, j, 3111); if (!is_zero_v3(gvel) || !is_zero_v3(gvel_smooth)) { float dvel[3]; @@ -770,7 +770,7 @@ static void cloth_continuum_step(ClothModifierData *clmd, float dt) float col0[3] = {0.0, 0.0, 0.0}; float col1[3] = {0.0, 1.0, 0.0}; float col[3]; - + interp_v3_v3v3(col, col0, col1, CLAMPIS(gdensity * clmd->sim_parms->density_strength, 0.0, 1.0)); // BKE_sim_debug_data_add_circle(clmd->debug_data, x, gdensity * clmd->sim_parms->density_strength, 0, 1, 0.4, "grid velocity", i, j, 3115); // BKE_sim_debug_data_add_dot(clmd->debug_data, x, col[0], col[1], col[2], "grid velocity", i, j, 3115); @@ -782,7 +782,7 @@ static void cloth_continuum_step(ClothModifierData *clmd, float dt) } } #endif - + BPH_hair_volume_free_vertex_grid(grid); } } @@ -795,7 +795,7 @@ static void cloth_calc_volume_force(ClothModifierData *clmd) Implicit_Data *data = cloth->implicit; int mvert_num = cloth->mvert_num; ClothVertex *vert; - + /* 2.0f is an experimental value that seems to give good results */ float smoothfac = 2.0f * parms->velocity_smooth; float collfac = 2.0f * parms->collider_friction; @@ -803,17 +803,17 @@ static void cloth_calc_volume_force(ClothModifierData *clmd) float minpress = parms->pressure_threshold; float gmin[3], gmax[3]; int i; - + hair_get_boundbox(clmd, gmin, gmax); - + /* gather velocities & density */ if (smoothfac > 0.0f || pressfac > 0.0f) { HairVertexGrid *vertex_grid = BPH_hair_volume_create_vertex_grid(clmd->sim_parms->voxel_res, gmin, gmax); - + vert = cloth->verts; for (i = 0; i < mvert_num; i++, vert++) { float x[3], v[3]; - + if (vert->solver_index < 0) { copy_v3_v3(x, vert->x); copy_v3_v3(v, vert->v); @@ -824,21 +824,21 @@ static void cloth_calc_volume_force(ClothModifierData *clmd) BPH_hair_volume_add_vertex(vertex_grid, x, v); } BPH_hair_volume_normalize_vertex_grid(vertex_grid); - + vert = cloth->verts; for (i = 0; i < mvert_num; i++, vert++) { float x[3], v[3], f[3], dfdx[3][3], dfdv[3][3]; - + if (vert->solver_index < 0) continue; - + /* calculate volumetric forces */ BPH_mass_spring_get_motion_state(data, vert->solver_index, x, v); BPH_hair_volume_vertex_grid_forces(vertex_grid, x, v, smoothfac, pressfac, minpress, f, dfdx, dfdv); /* apply on hair data */ BPH_mass_spring_force_extern(data, vert->solver_index, f, dfdx, dfdv); } - + BPH_hair_volume_free_vertex_grid(vertex_grid); } } @@ -854,33 +854,33 @@ static void cloth_collision_solve_extra(Object *ob, ClothModifierData *clmd, Lis ClothVertex *verts = cloth->verts; int mvert_num = cloth->mvert_num; const float spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale; - + bool do_extra_solve; int i; - + if (!(clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED)) return; if (!clmd->clothObject->bvhtree) return; - + // update verts to current positions for (i = 0; i < mvert_num; i++) { BPH_mass_spring_get_new_position(id, i, verts[i].tx); - + sub_v3_v3v3(verts[i].tv, verts[i].tx, verts[i].txold); copy_v3_v3(verts[i].v, verts[i].tv); } - + #if 0 /* unused */ for (i=0, cv=cloth->verts; imvert_num; i++, cv++) { copy_v3_v3(initial_cos[i], cv->tx); } #endif - + // call collision function // TODO: check if "step" or "step+dt" is correct - dg do_extra_solve = cloth_bvh_objcollision(ob, clmd, step / clmd->sim_parms->timescale, dt / clmd->sim_parms->timescale); - + // copy corrected positions back to simulation for (i = 0; i < mvert_num; i++) { float curx[3]; @@ -888,41 +888,41 @@ static void cloth_collision_solve_extra(Object *ob, ClothModifierData *clmd, Lis // correct velocity again, just to be sure we had to change it due to adaptive collisions sub_v3_v3v3(verts[i].tv, verts[i].tx, curx); } - + if (do_extra_solve) { // cloth_calc_helper_forces(ob, clmd, initial_cos, step/clmd->sim_parms->timescale, dt/clmd->sim_parms->timescale); - + for (i = 0; i < mvert_num; i++) { - + float newv[3]; - + if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) && (verts [i].flags & CLOTH_VERT_FLAG_PINNED)) continue; - + BPH_mass_spring_set_new_position(id, i, verts[i].tx); mul_v3_v3fl(newv, verts[i].tv, spf); BPH_mass_spring_set_new_velocity(id, i, newv); } } - + // X = Xnew; BPH_mass_spring_apply_result(id); - + if (do_extra_solve) { ImplicitSolverResult result; - + /* initialize forces to zero */ BPH_mass_spring_clear_forces(id); - + // calculate forces cloth_calc_force(clmd, frame, effectors, step); - + // calculate new velocity and position BPH_mass_spring_solve_velocities(id, dt, &result); // cloth_record_result(clmd, &result, clmd->sim_parms->stepsPerFrame); - + /* note: positions are advanced only once in the main solver step! */ - + BPH_mass_spring_apply_result(id); } } @@ -930,7 +930,7 @@ static void cloth_collision_solve_extra(Object *ob, ClothModifierData *clmd, Lis static void cloth_clear_result(ClothModifierData *clmd) { ClothSolverResult *sres = clmd->solver_result; - + sres->status = 0; sres->max_error = sres->min_error = sres->avg_error = 0.0f; sres->max_iterations = sres->min_iterations = 0; @@ -940,7 +940,7 @@ static void cloth_clear_result(ClothModifierData *clmd) static void cloth_record_result(ClothModifierData *clmd, ImplicitSolverResult *result, int steps) { ClothSolverResult *sres = clmd->solver_result; - + if (sres->status) { /* already initialized ? */ /* error only makes sense for successful iterations */ if (result->status == BPH_SOLVER_SUCCESS) { @@ -948,7 +948,7 @@ static void cloth_record_result(ClothModifierData *clmd, ImplicitSolverResult *r sres->max_error = max_ff(sres->max_error, result->error); sres->avg_error += result->error / (float)steps; } - + sres->min_iterations = min_ii(sres->min_iterations, result->iterations); sres->max_iterations = max_ii(sres->max_iterations, result->iterations); sres->avg_iterations += (float)result->iterations / (float)steps; @@ -959,11 +959,11 @@ static void cloth_record_result(ClothModifierData *clmd, ImplicitSolverResult *r sres->min_error = sres->max_error = result->error; sres->avg_error += result->error / (float)steps; } - + sres->min_iterations = sres->max_iterations = result->iterations; sres->avg_iterations += (float)result->iterations / (float)steps; } - + sres->status |= result->status; } @@ -974,7 +974,7 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase * * Bad design, TODO */ const bool is_hair = (clmd->hairdata != NULL); - + unsigned int i=0; float step=0.0f, tf=clmd->sim_parms->timescale; Cloth *cloth = clmd->clothObject; @@ -984,13 +984,13 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase * Implicit_Data *id = cloth->implicit; ColliderContacts *contacts = NULL; int totcolliders = 0; - + BKE_sim_debug_data_clear_category("collision"); - + if (!clmd->solver_result) clmd->solver_result = (ClothSolverResult *)MEM_callocN(sizeof(ClothSolverResult), "cloth solver result"); cloth_clear_result(clmd); - + if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) { /* do goal stuff */ for (i = 0; i < mvert_num; i++) { // update velocities with constrained velocities from pinned verts @@ -1004,22 +1004,22 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase * } } } - + while (step < tf) { ImplicitSolverResult result; - + /* copy velocities for collision */ for (i = 0; i < mvert_num; i++) { BPH_mass_spring_get_motion_state(id, i, NULL, verts[i].tv); copy_v3_v3(verts[i].v, verts[i].tv); } - + if (is_hair) { /* determine contact points */ if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED) { cloth_find_point_contacts(ob, clmd, 0.0f, tf, &contacts, &totcolliders); } - + /* setup vertex constraints for pinned vertices and contacts */ cloth_setup_constraints(clmd, contacts, totcolliders, dt); } @@ -1027,10 +1027,10 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase * /* setup vertex constraints for pinned vertices */ cloth_setup_constraints(clmd, NULL, 0, dt); } - + /* initialize forces to zero */ BPH_mass_spring_clear_forces(id); - + // damping velocity for artistic reasons // this is a bad way to do it, should be removed imo - lukas_t if (clmd->sim_parms->vel_damping != 1.0f) { @@ -1041,26 +1041,26 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase * BPH_mass_spring_set_velocity(id, i, v); } } - + // calculate forces cloth_calc_force(clmd, frame, effectors, step); - + // calculate new velocity and position BPH_mass_spring_solve_velocities(id, dt, &result); cloth_record_result(clmd, &result, clmd->sim_parms->stepsPerFrame); - + if (is_hair) { cloth_continuum_step(clmd, dt); } - + BPH_mass_spring_solve_positions(id, dt); - + if (!is_hair) { cloth_collision_solve_extra(ob, clmd, effectors, frame, step, dt); } - + BPH_mass_spring_apply_result(id); - + /* move pinned verts to correct position */ for (i = 0; i < mvert_num; i++) { if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) { @@ -1071,24 +1071,24 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase * BPH_mass_spring_set_position(id, i, x); } } - + BPH_mass_spring_get_motion_state(id, i, verts[i].txold, NULL); } - + /* free contact points */ if (contacts) { cloth_free_contacts(contacts, totcolliders); } - + step += dt; } - + /* copy results back to cloth data */ for (i = 0; i < mvert_num; i++) { BPH_mass_spring_get_motion_state(id, i, verts[i].x, verts[i].v); copy_v3_v3(verts[i].txold, verts[i].x); } - + return 1; } @@ -1097,18 +1097,18 @@ bool BPH_cloth_solver_get_texture_data(Object *UNUSED(ob), ClothModifierData *cl Cloth *cloth = clmd->clothObject; HairGrid *grid; float gmin[3], gmax[3]; - + if (!clmd->clothObject || !clmd->clothObject->implicit) return false; - + hair_get_boundbox(clmd, gmin, gmax); - + grid = BPH_hair_volume_create_vertex_grid(clmd->sim_parms->voxel_cell_size, gmin, gmax); cloth_continuum_fill_grid(grid, cloth); - + BPH_hair_volume_get_texture_data(grid, vd); - + BPH_hair_volume_free_vertex_grid(grid); - + return true; } diff --git a/source/blender/physics/intern/ConstrainedConjugateGradient.h b/source/blender/physics/intern/ConstrainedConjugateGradient.h index f9c6931fe8c..2d5fb41cc73 100644 --- a/source/blender/physics/intern/ConstrainedConjugateGradient.h +++ b/source/blender/physics/intern/ConstrainedConjugateGradient.h @@ -4,7 +4,7 @@ #include -namespace Eigen { +namespace Eigen { namespace internal { @@ -29,16 +29,16 @@ void constrained_conjugate_gradient(const MatrixType& mat, const Rhs& rhs, Dest& typedef typename Dest::RealScalar RealScalar; typedef typename Dest::Scalar Scalar; typedef Matrix VectorType; - + RealScalar tol = tol_error; int maxIters = iters; - + int n = mat.cols(); VectorType residual = filter * (rhs - mat * x); //initial residual RealScalar rhsNorm2 = (filter * rhs).squaredNorm(); - if(rhsNorm2 == 0) + if(rhsNorm2 == 0) { /* XXX TODO set constrained result here */ x.setZero(); @@ -54,7 +54,7 @@ void constrained_conjugate_gradient(const MatrixType& mat, const Rhs& rhs, Dest& tol_error = sqrt(residualNorm2 / rhsNorm2); return; } - + VectorType p(n); p = filter * precond.solve(residual); //initial search direction @@ -68,11 +68,11 @@ void constrained_conjugate_gradient(const MatrixType& mat, const Rhs& rhs, Dest& Scalar alpha = absNew / p.dot(tmp); // the amount we travel on dir x += alpha * p; // update solution residual -= alpha * tmp; // update residue - + residualNorm2 = residual.squaredNorm(); if(residualNorm2 < threshold) break; - + z = precond.solve(residual); // approximately solve for "A z = residual" RealScalar absOld = absNew; @@ -95,20 +95,20 @@ struct MatrixFilter m_cmat(NULL) { } - + MatrixFilter(const MatrixType &cmat) : m_cmat(&cmat) { } - + void setMatrix(const MatrixType &cmat) { m_cmat = &cmat; } - + template void apply(VectorType v) const { v = (*m_cmat) * v; } - + protected: const MatrixType *m_cmat; }; @@ -145,7 +145,7 @@ struct traits::epsilon() for the tolerance. - * + * * This class can be used as the direct solver classes. Here is a typical usage example: * \code * int n = 10000; @@ -160,7 +160,7 @@ struct traits @@ -206,10 +206,10 @@ public: ConstrainedConjugateGradient() : Base() {} /** Initialize the solver with matrix \a A for further \c Ax=b solving. - * + * * This constructor is a shortcut for the default constructor followed * by a call to compute(). - * + * * \warning this class stores a reference to the matrix A as well as some * precomputed values that depend on it. Therefore, if \a A is changed * this class becomes invalid. Call compute() to update it with the new @@ -258,7 +258,7 @@ public: m_isInitialized = true; m_info = m_error <= Base::m_tolerance ? Success : NoConvergence; } - + /** \internal */ template void _solve(const Rhs& b, Dest& x) const diff --git a/source/blender/physics/intern/eigen_utils.h b/source/blender/physics/intern/eigen_utils.h index 8a5a9dbf5e9..4598d3ad3a7 100644 --- a/source/blender/physics/intern/eigen_utils.h +++ b/source/blender/physics/intern/eigen_utils.h @@ -56,24 +56,24 @@ typedef float Scalar; class Vector3 : public Eigen::Vector3f { public: typedef float *ctype; - + Vector3() { } - + Vector3(const ctype &v) { for (int k = 0; k < 3; ++k) coeffRef(k) = v[k]; } - + Vector3& operator = (const ctype &v) { for (int k = 0; k < 3; ++k) coeffRef(k) = v[k]; return *this; } - + operator ctype() { return data(); @@ -86,18 +86,18 @@ public: class Matrix3 : public Eigen::Matrix3f { public: typedef float (*ctype)[3]; - + Matrix3() { } - + Matrix3(const ctype &v) { for (int k = 0; k < 3; ++k) for (int l = 0; l < 3; ++l) coeffRef(l, k) = v[k][l]; } - + Matrix3& operator = (const ctype &v) { for (int k = 0; k < 3; ++k) @@ -105,7 +105,7 @@ public: coeffRef(l, k) = v[k][l]; return *this; } - + operator ctype() { return (ctype)data(); @@ -120,23 +120,23 @@ typedef Eigen::VectorXf lVector; class lVector3f : public Eigen::VectorXf { public: typedef Eigen::VectorXf base_t; - + lVector3f() { } - + template lVector3f& operator = (T rhs) { base_t::operator=(rhs); return *this; } - + float* v3(int vertex) { return &coeffRef(3 * vertex); } - + const float* v3(int vertex) const { return &coeffRef(3 * vertex); @@ -157,18 +157,18 @@ struct lMatrix3fCtor { lMatrix3fCtor() { } - + void reset() { m_trips.clear(); } - + void reserve(int numverts) { /* reserve for diagonal entries */ m_trips.reserve(numverts * 9); } - + void add(int i, int j, const Matrix3 &m) { i *= 3; @@ -177,7 +177,7 @@ struct lMatrix3fCtor { for (int l = 0; l < 3; ++l) m_trips.push_back(Triplet(i + k, j + l, m.coeff(l, k))); } - + void sub(int i, int j, const Matrix3 &m) { i *= 3; @@ -186,13 +186,13 @@ struct lMatrix3fCtor { for (int l = 0; l < 3; ++l) m_trips.push_back(Triplet(i + k, j + l, -m.coeff(l, k))); } - + inline void construct(lMatrix &m) { m.setFromTriplets(m_trips.begin(), m_trips.end()); m_trips.clear(); } - + private: TripletList m_trips; }; @@ -206,7 +206,7 @@ BLI_INLINE void print_lvector(const lVector3f &v) for (int i = 0; i < v.rows(); ++i) { if (i > 0 && i % 3 == 0) printf("\n"); - + printf("%f,\n", v[i]); } } @@ -216,11 +216,11 @@ BLI_INLINE void print_lmatrix(const lMatrix &m) for (int j = 0; j < m.rows(); ++j) { if (j > 0 && j % 3 == 0) printf("\n"); - + for (int i = 0; i < m.cols(); ++i) { if (i > 0 && i % 3 == 0) printf(" "); - + implicit_print_matrix_elem(m.coeff(j, i)); } printf("\n"); diff --git a/source/blender/physics/intern/hair_volume.cpp b/source/blender/physics/intern/hair_volume.cpp index ad6fbed32e0..cd869046cc1 100644 --- a/source/blender/physics/intern/hair_volume.cpp +++ b/source/blender/physics/intern/hair_volume.cpp @@ -82,7 +82,7 @@ typedef struct HairGridVert { int samples; float velocity[3]; float density; - + float velocity_smooth[3]; } HairGridVert; @@ -107,20 +107,20 @@ BLI_INLINE int hair_grid_offset(const float vec[3], const int res[3], const floa BLI_INLINE int hair_grid_interp_weights(const int res[3], const float gmin[3], float scale, const float vec[3], float uvw[3]) { int i, j, k, offset; - + i = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 0); j = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 1); k = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 2); offset = i + (j + k*res[1])*res[0]; - + uvw[0] = (vec[0] - gmin[0]) * scale - (float)i; uvw[1] = (vec[1] - gmin[1]) * scale - (float)j; uvw[2] = (vec[2] - gmin[2]) * scale - (float)k; - + // BLI_assert(0.0f <= uvw[0] && uvw[0] <= 1.0001f); // BLI_assert(0.0f <= uvw[1] && uvw[1] <= 1.0001f); // BLI_assert(0.0f <= uvw[2] && uvw[2] <= 1.0001f); - + return offset; } @@ -131,12 +131,12 @@ BLI_INLINE void hair_grid_interpolate(const HairGridVert *grid, const int res[3] float uvw[3], muvw[3]; int res2 = res[1] * res[0]; int offset; - + offset = hair_grid_interp_weights(res, gmin, scale, vec, uvw); muvw[0] = 1.0f - uvw[0]; muvw[1] = 1.0f - uvw[1]; muvw[2] = 1.0f - uvw[2]; - + data[0] = grid[offset ]; data[1] = grid[offset +1]; data[2] = grid[offset +res[0] ]; @@ -145,14 +145,14 @@ BLI_INLINE void hair_grid_interpolate(const HairGridVert *grid, const int res[3] data[5] = grid[offset+res2 +1]; data[6] = grid[offset+res2+res[0] ]; data[7] = grid[offset+res2+res[0]+1]; - + if (density) { *density = muvw[2]*( muvw[1]*( muvw[0]*data[0].density + uvw[0]*data[1].density ) + uvw[1]*( muvw[0]*data[2].density + uvw[0]*data[3].density ) ) + uvw[2]*( muvw[1]*( muvw[0]*data[4].density + uvw[0]*data[5].density ) + uvw[1]*( muvw[0]*data[6].density + uvw[0]*data[7].density ) ); } - + if (velocity) { int k; for (k = 0; k < 3; ++k) { @@ -162,7 +162,7 @@ BLI_INLINE void hair_grid_interpolate(const HairGridVert *grid, const int res[3] uvw[1]*( muvw[0]*data[6].velocity[k] + uvw[0]*data[7].velocity[k] ) ); } } - + if (vel_smooth) { int k; for (k = 0; k < 3; ++k) { @@ -172,24 +172,24 @@ BLI_INLINE void hair_grid_interpolate(const HairGridVert *grid, const int res[3] uvw[1]*( muvw[0]*data[6].velocity_smooth[k] + uvw[0]*data[7].velocity_smooth[k] ) ); } } - + if (density_gradient) { density_gradient[0] = muvw[1] * muvw[2] * ( data[0].density - data[1].density ) + uvw[1] * muvw[2] * ( data[2].density - data[3].density ) + muvw[1] * uvw[2] * ( data[4].density - data[5].density ) + uvw[1] * uvw[2] * ( data[6].density - data[7].density ); - + density_gradient[1] = muvw[2] * muvw[0] * ( data[0].density - data[2].density ) + uvw[2] * muvw[0] * ( data[4].density - data[6].density ) + muvw[2] * uvw[0] * ( data[1].density - data[3].density ) + uvw[2] * uvw[0] * ( data[5].density - data[7].density ); - + density_gradient[2] = muvw[2] * muvw[0] * ( data[0].density - data[4].density ) + uvw[2] * muvw[0] * ( data[1].density - data[5].density ) + muvw[2] * uvw[0] * ( data[2].density - data[6].density ) + uvw[2] * uvw[0] * ( data[3].density - data[7].density ); } - + if (velocity_gradient) { /* XXX TODO */ zero_m3(velocity_gradient); @@ -201,21 +201,21 @@ void BPH_hair_volume_vertex_grid_forces(HairGrid *grid, const float x[3], const float f[3], float dfdx[3][3], float dfdv[3][3]) { float gdensity, gvelocity[3], ggrad[3], gvelgrad[3][3], gradlen; - + hair_grid_interpolate(grid->verts, grid->res, grid->gmin, grid->inv_cellsize, x, &gdensity, gvelocity, NULL, ggrad, gvelgrad); - + zero_v3(f); sub_v3_v3(gvelocity, v); mul_v3_v3fl(f, gvelocity, smoothfac); - + gradlen = normalize_v3(ggrad) - minpressure; if (gradlen > 0.0f) { mul_v3_fl(ggrad, gradlen); madd_v3_v3fl(f, ggrad, pressurefac); } - + zero_m3(dfdx); - + sub_m3_m3m3(dfdv, gvelgrad, I); mul_m3_fl(dfdv, smoothfac); } @@ -232,16 +232,16 @@ void BPH_hair_volume_grid_velocity(HairGrid *grid, const float x[3], const float { float gdensity, gvelocity[3], gvel_smooth[3], ggrad[3], gvelgrad[3][3]; float v_pic[3], v_flip[3]; - + hair_grid_interpolate(grid->verts, grid->res, grid->gmin, grid->inv_cellsize, x, &gdensity, gvelocity, gvel_smooth, ggrad, gvelgrad); - + /* velocity according to PIC method (Particle-in-Cell) */ copy_v3_v3(v_pic, gvel_smooth); - + /* velocity according to FLIP method (Fluid-Implicit-Particle) */ sub_v3_v3v3(v_flip, gvel_smooth, gvelocity); add_v3_v3(v_flip, v); - + interp_v3_v3v3(r_v, v_pic, v_flip, fluid_factor); } @@ -283,16 +283,16 @@ BLI_INLINE int hair_grid_weights(const int res[3], const float gmin[3], float sc { int i, j, k, offset; float uvw[3]; - + i = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 0); j = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 1); k = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 2); offset = i + (j + k*res[1])*res[0]; - + uvw[0] = (vec[0] - gmin[0]) * scale; uvw[1] = (vec[1] - gmin[1]) * scale; uvw[2] = (vec[2] - gmin[2]) * scale; - + weights[0] = dist_tent_v3f3(uvw, (float)i , (float)j , (float)k ); weights[1] = dist_tent_v3f3(uvw, (float)(i+1), (float)j , (float)k ); weights[2] = dist_tent_v3f3(uvw, (float)i , (float)(j+1), (float)k ); @@ -301,9 +301,9 @@ BLI_INLINE int hair_grid_weights(const int res[3], const float gmin[3], float sc weights[5] = dist_tent_v3f3(uvw, (float)(i+1), (float)j , (float)(k+1)); weights[6] = dist_tent_v3f3(uvw, (float)i , (float)(j+1), (float)(k+1)); weights[7] = dist_tent_v3f3(uvw, (float)(i+1), (float)(j+1), (float)(k+1)); - + // BLI_assert(fabsf(weights_sum(weights) - 1.0f) < 0.0001f); - + return offset; } @@ -320,18 +320,18 @@ void BPH_hair_volume_add_vertex(HairGrid *grid, const float x[3], const float v[ float weights[8]; int di, dj, dk; int offset; - + if (!hair_grid_point_valid(x, grid->gmin, grid->gmax)) return; - + offset = hair_grid_weights(res, grid->gmin, grid->inv_cellsize, x, weights); - + for (di = 0; di < 2; ++di) { for (dj = 0; dj < 2; ++dj) { for (dk = 0; dk < 2; ++dk) { int voffset = offset + di + (dj + dk*res[1])*res[0]; int iw = di + dj*2 + dk*4; - + grid->verts[voffset].density += weights[iw]; madd_v3_v3fl(grid->verts[voffset].velocity, v, weights[iw]); } @@ -344,15 +344,15 @@ BLI_INLINE void hair_volume_eval_grid_vertex(HairGridVert *vert, const float loc const float x2[3], const float v2[3], const float x3[3], const float v3[3]) { float closest[3], lambda, dist, weight; - + lambda = closest_to_line_v3(closest, loc, x2, x3); dist = len_v3v3(closest, loc); - + weight = (radius - dist) * dist_scale; - + if (weight > 0.0f) { float vel[3]; - + interp_v3_v3v3(vel, v2, v3, lambda); madd_v3_v3fl(vert->velocity, vel, weight); vert->density += weight; @@ -378,37 +378,37 @@ BLI_INLINE void hair_volume_add_segment_2D(HairGrid *grid, { const float radius = 1.5f; const float dist_scale = grid->inv_cellsize; - + int j, k; - + /* boundary checks to be safe */ CLAMP_MIN(jmin, 0); CLAMP_MAX(jmax, resj-1); CLAMP_MIN(kmin, 0); CLAMP_MAX(kmax, resk-1); - + HairGridVert *vert_j = vert + jmin * stride_j; float loc_j[3] = { loc[0], loc[1], loc[2] }; loc_j[axis_j] += (float)jmin; for (j = jmin; j <= jmax; ++j, vert_j += stride_j, loc_j[axis_j] += 1.0f) { - + HairGridVert *vert_k = vert_j + kmin * stride_k; float loc_k[3] = { loc_j[0], loc_j[1], loc_j[2] }; loc_k[axis_k] += (float)kmin; for (k = kmin; k <= kmax; ++k, vert_k += stride_k, loc_k[axis_k] += 1.0f) { - + hair_volume_eval_grid_vertex(vert_k, loc_k, radius, dist_scale, x2, v2, x3, v3); - + #if 0 { float wloc[3], x2w[3], x3w[3]; grid_to_world(grid, wloc, loc_k); grid_to_world(grid, x2w, x2); grid_to_world(grid, x3w, x3); - + if (vert_k->samples > 0) BKE_sim_debug_data_add_circle(wloc, 0.01f, 1.0, 1.0, 0.3, "grid", 2525, debug_i, j, k); - + if (grid->debug_value) { BKE_sim_debug_data_add_dot(wloc, 1, 0, 0, "grid", 93, debug_i, j, k); BKE_sim_debug_data_add_dot(x2w, 0.1, 0.1, 0.7, "grid", 649, debug_i, j, k); @@ -435,55 +435,55 @@ void BPH_hair_volume_add_segment(HairGrid *grid, const float dir1[3], const float dir2[3], const float dir3[3]) { const int res[3] = { grid->res[0], grid->res[1], grid->res[2] }; - + /* find the primary direction from the major axis of the direction vector */ const int axis0 = major_axis_v3(dir2); const int axis1 = (axis0 + 1) % 3; const int axis2 = (axis0 + 2) % 3; - + /* vertex buffer offset factors along cardinal axes */ const int strides[3] = { 1, res[0], res[0] * res[1] }; const int stride0 = strides[axis0]; const int stride1 = strides[axis1]; const int stride2 = strides[axis2]; - + /* increment of secondary directions per step in the primary direction * note: we always go in the positive direction along axis0, so the sign can be inverted */ const float inc1 = dir2[axis1] / dir2[axis0]; const float inc2 = dir2[axis2] / dir2[axis0]; - + /* start/end points, so increment along axis0 is always positive */ const float *start = x2[axis0] < x3[axis0] ? x2 : x3; const float *end = x2[axis0] < x3[axis0] ? x3 : x2; const float start0 = start[axis0], start1 = start[axis1], start2 = start[axis2]; const float end0 = end[axis0]; - + /* range along primary direction */ const int imin = max_ii(floor_int(start[axis0]) - 1, 0); const int imax = min_ii(floor_int(end[axis0]) + 2, res[axis0]-1); - + float h = 0.0f; HairGridVert *vert0; float loc0[3]; int j0, k0, j0_prev, k0_prev; int i; - + for (i = imin; i <= imax; ++i) { float shift1, shift2; /* fraction of a full cell shift [0.0, 1.0) */ int jmin, jmax, kmin, kmax; - + h = CLAMPIS((float)i, start0, end0); - + shift1 = start1 + (h - start0) * inc1; shift2 = start2 + (h - start0) * inc2; - + j0_prev = j0; j0 = floor_int(shift1); - + k0_prev = k0; k0 = floor_int(shift2); - + if (i > imin) { jmin = min_ii(j0, j0_prev); jmax = max_ii(j0, j0_prev); @@ -494,12 +494,12 @@ void BPH_hair_volume_add_segment(HairGrid *grid, jmin = jmax = j0; kmin = kmax = k0; } - + vert0 = grid->verts + i * stride0; loc0[axis0] = (float)i; loc0[axis1] = 0.0f; loc0[axis2] = 0.0f; - + hair_volume_add_segment_2D(grid, x1, v1, x2, v2, x3, v3, x4, v4, dir1, dir2, dir3, res[axis1], res[axis2], jmin-1, jmax+2, kmin-1, kmax+2, vert0, stride1, stride2, loc0, axis1, axis2, @@ -511,11 +511,11 @@ BLI_INLINE void hair_volume_eval_grid_vertex_sample(HairGridVert *vert, const fl const float x[3], const float v[3]) { float dist, weight; - + dist = len_v3v3(x, loc); - + weight = (radius - dist) * dist_scale; - + if (weight > 0.0f) { madd_v3_v3fl(vert->velocity, v, weight); vert->density += weight; @@ -533,34 +533,34 @@ void BPH_hair_volume_add_segment(HairGrid *grid, { const float radius = 1.5f; const float dist_scale = grid->inv_cellsize; - + const int res[3] = { grid->res[0], grid->res[1], grid->res[2] }; const int stride[3] = { 1, res[0], res[0] * res[1] }; const int num_samples = 10; - + int s; - + for (s = 0; s < num_samples; ++s) { float x[3], v[3]; int i, j, k; - + float f = (float)s / (float)(num_samples-1); interp_v3_v3v3(x, x2, x3, f); interp_v3_v3v3(v, v2, v3, f); - + int imin = max_ii(floor_int(x[0]) - 2, 0); int imax = min_ii(floor_int(x[0]) + 2, res[0]-1); int jmin = max_ii(floor_int(x[1]) - 2, 0); int jmax = min_ii(floor_int(x[1]) + 2, res[1]-1); int kmin = max_ii(floor_int(x[2]) - 2, 0); int kmax = min_ii(floor_int(x[2]) + 2, res[2]-1); - + for (k = kmin; k <= kmax; ++k) { for (j = jmin; j <= jmax; ++j) { for (i = imin; i <= imax; ++i) { float loc[3] = { (float)i, (float)j, (float)k }; HairGridVert *vert = grid->verts + i * stride[0] + j * stride[1] + k * stride[2]; - + hair_volume_eval_grid_vertex_sample(vert, loc, radius, dist_scale, x, v); } } @@ -598,25 +598,25 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target { const float flowfac = grid->cellsize; const float inv_flowfac = 1.0f / grid->cellsize; - + /*const int num_cells = hair_grid_size(grid->res);*/ const int res[3] = { grid->res[0], grid->res[1], grid->res[2] }; const int resA[3] = { grid->res[0] + 2, grid->res[1] + 2, grid->res[2] + 2 }; - + const int stride0 = 1; const int stride1 = grid->res[0]; const int stride2 = grid->res[1] * grid->res[0]; const int strideA0 = 1; const int strideA1 = grid->res[0] + 2; const int strideA2 = (grid->res[1] + 2) * (grid->res[0] + 2); - + const int num_cells = res[0] * res[1] * res[2]; const int num_cellsA = (res[0] + 2) * (res[1] + 2) * (res[2] + 2); - + HairGridVert *vert_start = grid->verts - (stride0 + stride1 + stride2); HairGridVert *vert; int i, j, k; - + #define MARGIN_i0 (i < 1) #define MARGIN_j0 (j < 1) #define MARGIN_k0 (k < 1) @@ -630,9 +630,9 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target #define NEIGHBOR_MARGIN_i1 (i >= resA[0]-2) #define NEIGHBOR_MARGIN_j1 (j >= resA[1]-2) #define NEIGHBOR_MARGIN_k1 (k >= resA[2]-2) - + BLI_assert(num_cells >= 1); - + /* Calculate divergence */ lVector B(num_cellsA); for (k = 0; k < resA[2]; ++k) { @@ -640,14 +640,14 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target for (i = 0; i < resA[0]; ++i) { int u = i * strideA0 + j * strideA1 + k * strideA2; bool is_margin = MARGIN_i0 || MARGIN_i1 || MARGIN_j0 || MARGIN_j1 || MARGIN_k0 || MARGIN_k1; - + if (is_margin) { B[u] = 0.0f; continue; } - + vert = vert_start + i * stride0 + j * stride1 + k * stride2; - + const float *v0 = vert->velocity; float dx = 0.0f, dy = 0.0f, dz = 0.0f; if (!NEIGHBOR_MARGIN_i0) @@ -662,19 +662,19 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target dz += v0[2] - (vert - stride2)->velocity[2]; if (!NEIGHBOR_MARGIN_k1) dz += (vert + stride2)->velocity[2] - v0[2]; - + float divergence = -0.5f * flowfac * (dx + dy + dz); - + /* adjustment term for target density */ float target = hair_volume_density_divergence(vert->density, target_density, target_strength); - + /* B vector contains the finite difference approximation of the velocity divergence. * Note: according to the discretized Navier-Stokes equation the rhs vector * and resulting pressure gradient should be multiplied by the (inverse) density; * however, this is already included in the weighting of hair velocities on the grid! */ B[u] = divergence - target; - + #if 0 { float wloc[3], loc[3]; @@ -683,12 +683,12 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target float coln[3] = {1.0, 0.0, 1.0}; float col[3]; float fac; - + loc[0] = (float)(i - 1); loc[1] = (float)(j - 1); loc[2] = (float)(k - 1); grid_to_world(grid, wloc, loc); - + if (divergence > 0.0f) { fac = CLAMPIS(divergence * target_strength, 0.0, 1.0); interp_v3_v3v3(col, col0, colp, fac); @@ -704,11 +704,11 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target } } } - + /* Main Poisson equation system: * This is derived from the discretezation of the Poisson equation * div(grad(p)) = div(v) - * + * * The finite difference approximation yields the linear equation system described here: * https://en.wikipedia.org/wiki/Discrete_Poisson_equation */ @@ -718,13 +718,13 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target * and up to 6 factors -1 on other places. */ A.reserve(Eigen::VectorXi::Constant(num_cellsA, 7)); - + for (k = 0; k < resA[2]; ++k) { for (j = 0; j < resA[1]; ++j) { for (i = 0; i < resA[0]; ++i) { int u = i * strideA0 + j * strideA1 + k * strideA2; bool is_margin = MARGIN_i0 || MARGIN_i1 || MARGIN_j0 || MARGIN_j1 || MARGIN_k0 || MARGIN_k1; - + vert = vert_start + i * stride0 + j * stride1 + k * stride2; if (!is_margin && vert->density > density_threshold) { int neighbors_lo = 0; @@ -733,7 +733,7 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target int neighbor_lo_index[3]; int neighbor_hi_index[3]; int n; - + /* check for upper bounds in advance * to get the correct number of neighbors, * needed for the diagonal element @@ -750,10 +750,10 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target neighbor_hi_index[neighbors_hi++] = u + strideA1; if (!NEIGHBOR_MARGIN_k1 && (vert + stride2)->density > density_threshold) neighbor_hi_index[neighbors_hi++] = u + strideA2; - + /*int liquid_neighbors = neighbors_lo + neighbors_hi;*/ non_solid_neighbors = 6; - + for (n = 0; n < neighbors_lo; ++n) A.insert(neighbor_lo_index[n], u) = -1.0f; A.insert(u, u) = (float)non_solid_neighbors; @@ -766,15 +766,15 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target } } } - + ConjugateGradient cg; cg.setMaxIterations(100); cg.setTolerance(0.01f); - + cg.compute(A); - + lVector p = cg.solve(B); - + if (cg.info() == Eigen::Success) { /* Calculate velocity = grad(p) */ for (k = 0; k < resA[2]; ++k) { @@ -784,7 +784,7 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target bool is_margin = MARGIN_i0 || MARGIN_i1 || MARGIN_j0 || MARGIN_j1 || MARGIN_k0 || MARGIN_k1; if (is_margin) continue; - + vert = vert_start + i * stride0 + j * stride1 + k * stride2; if (vert->density > density_threshold) { float p_left = p[u - strideA0]; @@ -793,14 +793,14 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target float p_up = p[u + strideA1]; float p_bottom = p[u - strideA2]; float p_top = p[u + strideA2]; - + /* finite difference estimate of pressure gradient */ float dvel[3]; dvel[0] = p_right - p_left; dvel[1] = p_up - p_down; dvel[2] = p_top - p_bottom; mul_v3_fl(dvel, -0.5f * inv_flowfac); - + /* pressure gradient describes velocity delta */ add_v3_v3v3(vert->velocity_smooth, vert->velocity, dvel); } @@ -810,14 +810,14 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target } } } - + #if 0 { int axis = 0; float offset = 0.0f; - + int slice = (offset - grid->gmin[axis]) / grid->cellsize; - + for (k = 0; k < resA[2]; ++k) { for (j = 0; j < resA[1]; ++j) { for (i = 0; i < resA[0]; ++i) { @@ -825,21 +825,21 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target bool is_margin = MARGIN_i0 || MARGIN_i1 || MARGIN_j0 || MARGIN_j1 || MARGIN_k0 || MARGIN_k1; if (i != slice) continue; - + vert = vert_start + i * stride0 + j * stride1 + k * stride2; - + float wloc[3], loc[3]; float col0[3] = {0.0, 0.0, 0.0}; float colp[3] = {0.0, 1.0, 1.0}; float coln[3] = {1.0, 0.0, 1.0}; float col[3]; float fac; - + loc[0] = (float)(i - 1); loc[1] = (float)(j - 1); loc[2] = (float)(k - 1); grid_to_world(grid, wloc, loc); - + float pressure = p[u]; if (pressure > 0.0f) { fac = CLAMPIS(pressure * grid->debug1, 0.0, 1.0); @@ -851,19 +851,19 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target } if (fac > 0.05f) BKE_sim_debug_data_add_circle(grid->debug_data, wloc, 0.01f, col[0], col[1], col[2], "grid", 5533, i, j, k); - + if (!is_margin) { float dvel[3]; sub_v3_v3v3(dvel, vert->velocity_smooth, vert->velocity); // BKE_sim_debug_data_add_vector(grid->debug_data, wloc, dvel, 1, 1, 1, "grid", 5566, i, j, k); } - + if (!is_margin) { float d = CLAMPIS(vert->density * grid->debug2, 0.0f, 1.0f); float col0[3] = {0.3, 0.3, 0.3}; float colp[3] = {0.0, 0.0, 1.0}; float col[3]; - + interp_v3_v3v3(col, col0, colp, d); // if (d > 0.05f) // BKE_sim_debug_data_add_dot(grid->debug_data, wloc, col[0], col[1], col[2], "grid", 5544, i, j, k); @@ -873,7 +873,7 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target } } #endif - + return true; } else { @@ -881,7 +881,7 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target for (i = 0, vert = grid->verts; i < num_cells; ++i, ++vert) { zero_v3(vert->velocity_smooth); } - + return false; } } @@ -901,20 +901,20 @@ BLI_INLINE void hair_volume_filter_box_convolute(HairVertexGrid *grid, float inv int offset, kernel_offset, kernel_dq, kernel_dr; HairGridVert *verts; float *vel_smooth; - + offset = i + (j + k*res)*res; verts = grid->verts; vel_smooth = verts[offset].velocity_smooth; - + kernel_offset = minp + (minq + minr*res)*res; kernel_dq = res; kernel_dr = res * res; for (r = minr; r <= maxr; ++r) { for (q = minq; q <= maxq; ++q) { for (p = minp; p <= maxp; ++p) { - + madd_v3_v3fl(vel_smooth, verts[kernel_offset].velocity, invD); - + kernel_offset += 1; } kernel_offset += kernel_dq; @@ -930,18 +930,18 @@ void BPH_hair_volume_vertex_grid_filter_box(HairVertexGrid *grid, int kernel_siz int tot; float invD; int i, j, k; - + if (kernel_size <= 0) return; - + tot = kernel_size * 2 + 1; invD = 1.0f / (float)(tot*tot*tot); - + /* clear values for convolution */ for (i = 0; i < size; ++i) { zero_v3(grid->verts[i].velocity_smooth); } - + for (i = 0; i < grid->res; ++i) { for (j = 0; j < grid->res; ++j) { for (k = 0; k < grid->res; ++k) { @@ -949,7 +949,7 @@ void BPH_hair_volume_vertex_grid_filter_box(HairVertexGrid *grid, int kernel_siz } } } - + /* apply as new velocity */ for (i = 0; i < size; ++i) { copy_v3_v3(grid->verts[i].velocity, grid->verts[i].velocity_smooth); @@ -966,21 +966,21 @@ HairGrid *BPH_hair_volume_create_vertex_grid(float cellsize, const float gmin[3] int size; HairGrid *grid; int i; - + /* sanity check */ if (cellsize <= 0.0f) cellsize = 1.0f; scale = 1.0f / cellsize; - + sub_v3_v3v3(extent, gmax, gmin); for (i = 0; i < 3; ++i) { resmin[i] = floor_int(gmin[i] * scale); resmax[i] = floor_int(gmax[i] * scale) + 1; - + /* add margin of 1 cell */ resmin[i] -= 1; resmax[i] += 1; - + res[i] = resmax[i] - resmin[i] + 1; /* sanity check: avoid null-sized grid */ if (res[i] < 4) { @@ -992,12 +992,12 @@ HairGrid *BPH_hair_volume_create_vertex_grid(float cellsize, const float gmin[3] res[i] = MAX_HAIR_GRID_RES; resmax[i] = resmin[i] + MAX_HAIR_GRID_RES; } - + gmin_margin[i] = (float)resmin[i] * cellsize; gmax_margin[i] = (float)resmax[i] * cellsize; } size = hair_grid_size(res); - + grid = (HairGrid *)MEM_callocN(sizeof(HairGrid), "hair grid"); grid->res[0] = res[0]; grid->res[1] = res[1]; @@ -1062,23 +1062,23 @@ static HairGridVert *hair_volume_create_collision_grid(ClothModifierData *clmd, float vel[3]; float weights[8]; int di, dj, dk; - + for (v=0; v < col->collmd->numverts; v++, loc0++, loc1++) { int offset; - + if (!hair_grid_point_valid(loc1->co, gmin, gmax)) continue; - + offset = hair_grid_weights(res, gmin, scale, lX[v], weights); - + sub_v3_v3v3(vel, loc1->co, loc0->co); - + for (di = 0; di < 2; ++di) { for (dj = 0; dj < 2; ++dj) { for (dk = 0; dk < 2; ++dk) { int voffset = offset + di + (dj + dk*res)*res; int iw = di + dj*2 + dk*4; - + collgrid[voffset].density += weights[iw]; madd_v3_v3fl(collgrid[voffset].velocity, vel, weights[iw]); } @@ -1095,7 +1095,7 @@ static HairGridVert *hair_volume_create_collision_grid(ClothModifierData *clmd, if (density > 0.0f) mul_v3_fl(collgrid[i].velocity, 1.0f/density); } - + return collgrid; } #endif @@ -1108,9 +1108,9 @@ bool BPH_hair_volume_get_texture_data(HairGrid *grid, VoxelData *vd) vd->resol[0] = grid->res[0]; vd->resol[1] = grid->res[1]; vd->resol[2] = grid->res[2]; - + totres = hair_grid_size(grid->res); - + if (vd->hair_type == TEX_VD_HAIRVELOCITY) { depth = 4; vd->data_type = TEX_VD_RGBA_PREMUL; @@ -1119,20 +1119,20 @@ bool BPH_hair_volume_get_texture_data(HairGrid *grid, VoxelData *vd) depth = 1; vd->data_type = TEX_VD_INTENSITY; } - + if (totres > 0) { vd->dataset = (float *)MEM_mapallocN(sizeof(float) * depth * (totres), "hair volume texture data"); - + for (i = 0; i < totres; ++i) { switch (vd->hair_type) { case TEX_VD_HAIRDENSITY: vd->dataset[i] = grid->verts[i].density; break; - + case TEX_VD_HAIRRESTDENSITY: vd->dataset[i] = 0.0f; // TODO break; - + case TEX_VD_HAIRVELOCITY: { vd->dataset[i + 0*totres] = grid->verts[i].velocity[0]; vd->dataset[i + 1*totres] = grid->verts[i].velocity[1]; @@ -1149,6 +1149,6 @@ bool BPH_hair_volume_get_texture_data(HairGrid *grid, VoxelData *vd) else { vd->dataset = NULL; } - + return true; } diff --git a/source/blender/physics/intern/implicit.h b/source/blender/physics/intern/implicit.h index 2f62ab98e12..e2ac6c306b6 100644 --- a/source/blender/physics/intern/implicit.h +++ b/source/blender/physics/intern/implicit.h @@ -62,7 +62,7 @@ struct Implicit_Data; typedef struct ImplicitSolverResult { int status; - + int iterations; float error; } ImplicitSolverResult; diff --git a/source/blender/physics/intern/implicit_blender.c b/source/blender/physics/intern/implicit_blender.c index 49798081cff..5fd9c6b50de 100644 --- a/source/blender/physics/intern/implicit_blender.c +++ b/source/blender/physics/intern/implicit_blender.c @@ -71,9 +71,9 @@ static float ZERO[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; /* #define C99 #ifdef C99 -#defineDO_INLINE inline -#else -#defineDO_INLINE static +#defineDO_INLINE inline +#else +#defineDO_INLINE static #endif */ struct Cloth; @@ -90,7 +90,7 @@ typedef struct fmatrix3x3 { /* int pinned; // is this vertex allowed to move? */ float n1, n2, n3; /* three normal vectors for collision constrains */ unsigned int vcount; /* vertex count */ - unsigned int scount; /* spring count */ + unsigned int scount; /* spring count */ } fmatrix3x3; /////////////////////////// @@ -115,9 +115,9 @@ DO_INLINE void mul_fvectorT_fvector(float to[3][3], float vectorA[3], float vect /* simple v^T * v product with scalar ("outer product") */ /* STATUS: HAS TO BE verified (*should* work) */ DO_INLINE void mul_fvectorT_fvectorS(float to[3][3], float vectorA[3], float vectorB[3], float aS) -{ +{ mul_fvectorT_fvector(to, vectorA, vectorB); - + mul_fvector_S(to[0], to[0], aS); mul_fvector_S(to[1], to[1], aS); mul_fvector_S(to[2], to[2], aS); @@ -288,7 +288,7 @@ static void print_lvector(lfVector *v, int numverts) for (i = 0; i < numverts; ++i) { if (i > 0) printf("\n"); - + printf("%f,\n", v[i][0]); printf("%f,\n", v[i][1]); printf("%f,\n", v[i][2]); @@ -303,11 +303,11 @@ static void print_bfmatrix(fmatrix3x3 *m) int size = m[0].vcount * 3; float *t = MEM_callocN(sizeof(float) * size*size, "bfmatrix"); int q, i, j; - + for (q = 0; q < tot; ++q) { int k = 3 * m[q].r; int l = 3 * m[q].c; - + for (j = 0; j < 3; ++j) { for (i = 0; i < 3; ++i) { // if (t[k + i + (l + j) * size] != 0.0f) { @@ -323,20 +323,20 @@ static void print_bfmatrix(fmatrix3x3 *m) } } } - + for (j = 0; j < size; ++j) { if (j > 0 && j % 3 == 0) printf("\n"); - + for (i = 0; i < size; ++i) { if (i > 0 && i % 3 == 0) printf(" "); - + implicit_print_matrix_elem(t[i + j * size]); } printf("\n"); } - + MEM_freeN(t); } #endif @@ -354,7 +354,7 @@ DO_INLINE void cp_fmatrix(float to[3][3], float from[3][3]) DO_INLINE void initdiag_fmatrixS(float to[3][3], float aS) { cp_fmatrix(to, ZERO); - + to[0][0] = aS; to[1][1] = aS; to[2][2] = aS; @@ -532,15 +532,15 @@ DO_INLINE fmatrix3x3 *create_bfmatrix(unsigned int verts, unsigned int springs) // TODO: check if memory allocation was successful */ fmatrix3x3 *temp = (fmatrix3x3 *)MEM_callocN(sizeof(fmatrix3x3) * (verts + springs), "cloth_implicit_alloc_matrix"); int i; - + temp[0].vcount = verts; temp[0].scount = springs; - + /* vertex part of the matrix is diagonal blocks */ for (i = 0; i < verts; ++i) { init_fmatrix(temp + i, i, i); } - + return temp; } /* delete big matrix */ @@ -565,7 +565,7 @@ DO_INLINE void init_bfmatrix(fmatrix3x3 *matrix, float m3[3][3]) unsigned int i; for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) { - cp_fmatrix(matrix[i].m, m3); + cp_fmatrix(matrix[i].m, m3); } } @@ -577,10 +577,10 @@ DO_INLINE void initdiag_bfmatrix(fmatrix3x3 *matrix, float m3[3][3]) float tmatrix[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; for (i = 0; i < matrix[0].vcount; i++) { - cp_fmatrix(matrix[i].m, m3); + cp_fmatrix(matrix[i].m, m3); } for (j = matrix[0].vcount; j < matrix[0].vcount+matrix[0].scount; j++) { - cp_fmatrix(matrix[j].m, tmatrix); + cp_fmatrix(matrix[j].m, tmatrix); } } @@ -591,7 +591,7 @@ DO_INLINE void mul_bfmatrix_lfvector( float (*to)[3], fmatrix3x3 *from, lfVector unsigned int i = 0; unsigned int vcount = from[0].vcount; lfVector *temp = create_lfvector(vcount); - + zero_lfvector(to, vcount); #pragma omp parallel sections private(i) if (vcount > CLOTH_OPENMP_LIMIT) @@ -610,10 +610,10 @@ DO_INLINE void mul_bfmatrix_lfvector( float (*to)[3], fmatrix3x3 *from, lfVector } } add_lfvector_lfvector(to, to, temp, from[0].vcount); - + del_lfvector(temp); - - + + } /* SPARSE SYMMETRIC sub big matrix with big matrix*/ @@ -642,15 +642,15 @@ typedef struct Implicit_Data { lfVector *F; /* forces */ fmatrix3x3 *dFdV, *dFdX; /* force jacobians */ int num_blocks; /* number of off-diagonal blocks (springs) */ - + /* motion state data */ lfVector *X, *Xnew; /* positions */ lfVector *V, *Vnew; /* velocities */ - + /* internal solver data */ lfVector *B; /* B for A*dV = B */ fmatrix3x3 *A; /* A for A*dV = B */ - + lfVector *dV; /* velocity change (solution of A*dV = B) */ lfVector *z; /* target velocity in constrained directions */ fmatrix3x3 *S; /* filtering matrix for constraints */ @@ -660,7 +660,7 @@ typedef struct Implicit_Data { Implicit_Data *BPH_mass_spring_solver_create(int numverts, int numsprings) { Implicit_Data *id = (Implicit_Data *)MEM_callocN(sizeof(Implicit_Data), "implicit vecmat"); - + /* process diagonal elements */ id->tfm = create_bfmatrix(numverts, 0); id->A = create_bfmatrix(numverts, numsprings); @@ -696,7 +696,7 @@ void BPH_mass_spring_solver_free(Implicit_Data *id) del_bfmatrix(id->Pinv); del_bfmatrix(id->bigI); del_bfmatrix(id->M); - + del_lfvector(id->X); del_lfvector(id->Xnew); del_lfvector(id->V); @@ -705,7 +705,7 @@ void BPH_mass_spring_solver_free(Implicit_Data *id) del_lfvector(id->B); del_lfvector(id->dV); del_lfvector(id->z); - + MEM_freeN(id); } @@ -752,7 +752,7 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z // Solves for unknown X in equation AX=B unsigned int conjgrad_loopcount=0, conjgrad_looplimit=100; float conjgrad_epsilon=0.0001f /* , conjgrad_lasterror=0 */ /* UNUSED */; - lfVector *q, *d, *tmp, *r; + lfVector *q, *d, *tmp, *r; float s, starget, a, s_prev; unsigned int numverts = lA[0].vcount; q = create_lfvector(numverts); @@ -818,7 +818,7 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z, // Solves for unknown X in equation AX=B unsigned int conjgrad_loopcount=0, conjgrad_looplimit=100; float conjgrad_epsilon=0.01f; - + unsigned int numverts = lA[0].vcount; lfVector *fB = create_lfvector(numverts); lfVector *AdV = create_lfvector(numverts); @@ -827,27 +827,27 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z, lfVector *q = create_lfvector(numverts); lfVector *s = create_lfvector(numverts); float bnorm2, delta_new, delta_old, delta_target, alpha; - + cp_lfvector(ldV, z, numverts); - + /* d0 = filter(B)^T * P * filter(B) */ cp_lfvector(fB, lB, numverts); filter(fB, S); bnorm2 = dot_lfvector(fB, fB, numverts); delta_target = conjgrad_epsilon*conjgrad_epsilon * bnorm2; - + /* r = filter(B - A * dV) */ mul_bfmatrix_lfvector(AdV, lA, ldV); sub_lfvector_lfvector(r, lB, AdV, numverts); filter(r, S); - + /* c = filter(P^-1 * r) */ cp_lfvector(c, r, numverts); filter(c, S); - + /* delta = r^T * c */ delta_new = dot_lfvector(r, c, numverts); - + #ifdef IMPLICIT_PRINT_SOLVER_INPUT_OUTPUT printf("==== A ====\n"); print_bfmatrix(lA); @@ -858,25 +858,25 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z, printf("==== S ====\n"); print_bfmatrix(S); #endif - + while (delta_new > delta_target && conjgrad_loopcount < conjgrad_looplimit) { mul_bfmatrix_lfvector(q, lA, c); filter(q, S); - + alpha = delta_new / dot_lfvector(c, q, numverts); - + add_lfvector_lfvectorS(ldV, ldV, c, alpha, numverts); - + add_lfvector_lfvectorS(r, r, q, -alpha, numverts); - + /* s = P^-1 * r */ cp_lfvector(s, r, numverts); delta_old = delta_new; delta_new = dot_lfvector(r, s, numverts); - + add_lfvector_lfvectorS(c, s, c, delta_new / delta_old, numverts); filter(c, S); - + conjgrad_loopcount++; } @@ -885,7 +885,7 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z, print_lvector(ldV, numverts); printf("========\n"); #endif - + del_lfvector(fB); del_lfvector(AdV); del_lfvector(r); @@ -906,14 +906,14 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z, DO_INLINE void BuildPPinv(fmatrix3x3 *lA, fmatrix3x3 *P, fmatrix3x3 *Pinv) { unsigned int i = 0; - + // Take only the diagonal blocks of A // #pragma omp parallel for private(i) if (lA[0].vcount > CLOTH_OPENMP_LIMIT) for (i = 0; i delta0) && (iterations < conjgrad_looplimit)) { iterations++; - + mul_bfmatrix_lfvector(s, lA, p); filter(s, S); - + alpha = deltaNew / dot_lfvector(p, s, numverts); - + add_lfvector_lfvectorS(dv, dv, p, alpha, numverts); - + add_lfvector_lfvectorS(r, r, s, -alpha, numverts); - + mul_prevfmatrix_lfvector(h, Pinv, r); filter(h, S); - + deltaOld = deltaNew; - + deltaNew = dot_lfvector(r, h, numverts); - + add_lfvector_lfvectorS(p, h, p, deltaNew / deltaOld, numverts); - + filter(p, S); - + } #ifdef DEBUG_TIME double end = PIL_check_seconds_timer(); printf("cg_filtered_pre time: %f\n", (float)(end - start)); #endif - + del_lfvector(h); del_lfvector(s); del_lfvector(p); del_lfvector(r); - + printf("iterations: %d\n", iterations); - + return iterations delta0*tol*tol) && (iterations < conjgrad_looplimit)) { iterations++; - + mul_bfmatrix_lfvector(s, lA, p); filter(s, S); - + alpha = deltaNew / dot_lfvector(p, s, numverts); - + add_lfvector_lfvectorS(dv, dv, p, alpha, numverts); - + add_lfvector_lfvectorS(r, r, s, -alpha, numverts); - + mul_prevfmatrix_lfvector(h, Pinv, r); filter(h, S); - + deltaOld = deltaNew; - + deltaNew = dot_lfvector(r, h, numverts); - + add_lfvector_lfvectorS(p, h, p, deltaNew / deltaOld, numverts); - + filter(p, S); - + } #ifdef DEBUG_TIME @@ -1090,9 +1090,9 @@ static int cg_filtered_pre(lfVector *dv, fmatrix3x3 *lA, lfVector *lB, lfVector del_lfvector(s); del_lfvector(p); del_lfvector(r); - + // printf("iterations: %d\n", iterations); - + return iterationsVnew, data->V, data->dV, numverts); del_lfvector(dFdXmV); - + return result->status == BPH_SOLVER_SUCCESS; } bool BPH_mass_spring_solve_positions(Implicit_Data *data, float dt) { int numverts = data->M[0].vcount; - + // advance positions add_lfvector_lfvectorS(data->Xnew, data->X, data->Vnew, dt, numverts); - + return true; } @@ -1219,7 +1219,7 @@ static int BPH_mass_spring_add_block(Implicit_Data *data, int v1, int v2) int s = data->M[0].vcount + data->num_blocks; /* index from array start */ BLI_assert(s < data->M[0].vcount + data->M[0].scount); ++data->num_blocks; - + /* tfm and S don't have spring entries (diagonal blocks only) */ init_fmatrix(data->bigI + s, v1, v2); init_fmatrix(data->M + s, v1, v2); @@ -1228,7 +1228,7 @@ static int BPH_mass_spring_add_block(Implicit_Data *data, int v1, int v2) init_fmatrix(data->A + s, v1, v2); init_fmatrix(data->P + s, v1, v2); init_fmatrix(data->Pinv + s, v1, v2); - + return s; } @@ -1244,26 +1244,26 @@ void BPH_mass_spring_clear_constraints(Implicit_Data *data) void BPH_mass_spring_add_constraint_ndof0(Implicit_Data *data, int index, const float dV[3]) { zero_m3(data->S[index].m); - + world_to_root_v3(data, index, data->z[index], dV); } void BPH_mass_spring_add_constraint_ndof1(Implicit_Data *data, int index, const float c1[3], const float c2[3], const float dV[3]) { float m[3][3], p[3], q[3], u[3], cmat[3][3]; - + world_to_root_v3(data, index, p, c1); mul_fvectorT_fvector(cmat, p, p); sub_m3_m3m3(m, I, cmat); - + world_to_root_v3(data, index, q, c2); mul_fvectorT_fvector(cmat, q, q); sub_m3_m3m3(m, m, cmat); - + /* XXX not sure but multiplication should work here */ copy_m3_m3(data->S[index].m, m); // mul_m3_m3m3(data->S[index].m, data->S[index].m, m); - + world_to_root_v3(data, index, u, dV); add_v3_v3(data->z[index], u); } @@ -1271,14 +1271,14 @@ void BPH_mass_spring_add_constraint_ndof1(Implicit_Data *data, int index, const void BPH_mass_spring_add_constraint_ndof2(Implicit_Data *data, int index, const float c1[3], const float dV[3]) { float m[3][3], p[3], u[3], cmat[3][3]; - + world_to_root_v3(data, index, p, c1); mul_fvectorT_fvector(cmat, p, p); sub_m3_m3m3(m, I, cmat); - + copy_m3_m3(data->S[index].m, m); // mul_m3_m3m3(data->S[index].m, data->S[index].m, m); - + world_to_root_v3(data, index, u, dV); add_v3_v3(data->z[index], u); } @@ -1289,7 +1289,7 @@ void BPH_mass_spring_clear_forces(Implicit_Data *data) zero_lfvector(data->F, numverts); init_bfmatrix(data->dFdX, ZERO); init_bfmatrix(data->dFdV, ZERO); - + data->num_blocks = 0; } @@ -1300,37 +1300,37 @@ void BPH_mass_spring_force_reference_frame(Implicit_Data *data, int index, const float f[3], dfdx[3][3], dfdv[3][3]; float euler[3], coriolis[3], centrifugal[3], rotvel[3]; float deuler[3][3], dcoriolis[3][3], dcentrifugal[3][3], drotvel[3][3]; - + world_to_root_v3(data, index, acc, acceleration); world_to_root_v3(data, index, w, omega); world_to_root_v3(data, index, dwdt, domega_dt); - + cross_v3_v3v3(euler, dwdt, data->X[index]); cross_v3_v3v3(coriolis, w, data->V[index]); mul_v3_fl(coriolis, 2.0f); cross_v3_v3v3(rotvel, w, data->X[index]); cross_v3_v3v3(centrifugal, w, rotvel); - + sub_v3_v3v3(f, acc, euler); sub_v3_v3(f, coriolis); sub_v3_v3(f, centrifugal); - + mul_v3_fl(f, mass); /* F = m * a */ - + cross_v3_identity(deuler, dwdt); cross_v3_identity(dcoriolis, w); mul_m3_fl(dcoriolis, 2.0f); cross_v3_identity(drotvel, w); cross_m3_v3m3(dcentrifugal, w, drotvel); - + add_m3_m3m3(dfdx, deuler, dcentrifugal); negate_m3(dfdx); mul_m3_fl(dfdx, mass); - + copy_m3_m3(dfdv, dcoriolis); negate_m3(dfdv); mul_m3_fl(dfdv, mass); - + add_v3_v3(data->F[index], f); add_m3_m3m3(data->dFdX[index].m, data->dFdX[index].m, dfdx); add_m3_m3m3(data->dFdV[index].m, data->dFdV[index].m, dfdv); @@ -1349,7 +1349,7 @@ void BPH_mass_spring_force_gravity(Implicit_Data *data, int index, float mass, c float f[3]; world_to_root_v3(data, index, f, g); mul_v3_fl(f, mass); - + add_v3_v3(data->F[index], f); } @@ -1358,10 +1358,10 @@ void BPH_mass_spring_force_drag(Implicit_Data *data, float drag) int i, numverts = data->M[0].vcount; for (i = 0; i < numverts; i++) { float tmp[3][3]; - + /* NB: uses root space velocity, no need to transform */ madd_v3_v3fl(data->F[i], data->V[i], -drag); - + copy_m3_m3(tmp, I); mul_m3_fl(tmp, -drag); add_m3_m3m3(data->dFdV[i].m, data->dFdV[i].m, tmp); @@ -1374,7 +1374,7 @@ void BPH_mass_spring_force_extern(struct Implicit_Data *data, int i, const float world_to_root_v3(data, i, tf, f); world_to_root_m3(data, i, tdfdx, dfdx); world_to_root_m3(data, i, tdfdv, dfdv); - + add_v3_v3(data->F[i], tf); add_m3_m3m3(data->dFdX[i].m, data->dFdX[i].m, tdfdx); add_m3_m3m3(data->dFdV[i].m, data->dFdV[i].m, tdfdv); @@ -1383,10 +1383,10 @@ void BPH_mass_spring_force_extern(struct Implicit_Data *data, int i, const float static float calc_nor_area_tri(float nor[3], const float v1[3], const float v2[3], const float v3[3]) { float n1[3], n2[3]; - + sub_v3_v3v3(n1, v1, v2); sub_v3_v3v3(n2, v2, v3); - + cross_v3_v3v3(nor, n1, n2); return normalize_v3(nor); } @@ -1397,17 +1397,17 @@ void BPH_mass_spring_force_face_wind(Implicit_Data *data, int v1, int v2, int v3 const float effector_scale = 0.02f; float win[3], nor[3], area; float factor; - + /* calculate face normal and area */ area = calc_nor_area_tri(nor, data->X[v1], data->X[v2], data->X[v3]); factor = effector_scale * area / 3.0f; - + world_to_root_v3(data, v1, win, winvec[v1]); madd_v3_v3fl(data->F[v1], nor, factor * dot_v3v3(win, nor)); - + world_to_root_v3(data, v2, win, winvec[v2]); madd_v3_v3fl(data->F[v2], nor, factor * dot_v3v3(win, nor)); - + world_to_root_v3(data, v3, win, winvec[v3]); madd_v3_v3fl(data->F[v3], nor, factor * dot_v3v3(win, nor)); } @@ -1417,17 +1417,17 @@ static void edge_wind_vertex(const float dir[3], float length, float radius, con const float density = 0.01f; /* XXX arbitrary value, corresponds to effect of air density */ float cos_alpha, sin_alpha, cross_section; float windlen = len_v3(wind); - + if (windlen == 0.0f) { zero_v3(f); return; } - + /* angle of wind direction to edge */ cos_alpha = dot_v3v3(wind, dir) / windlen; sin_alpha = sqrtf(1.0f - cos_alpha * cos_alpha); cross_section = radius * ((float)M_PI * radius * sin_alpha + length * cos_alpha); - + mul_v3_v3fl(f, wind, density * cross_section); } @@ -1435,14 +1435,14 @@ void BPH_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, float { float win[3], dir[3], length; float f[3], dfdx[3][3], dfdv[3][3]; - + sub_v3_v3v3(dir, data->X[v1], data->X[v2]); length = normalize_v3(dir); - + world_to_root_v3(data, v1, win, winvec[v1]); edge_wind_vertex(dir, length, radius1, win, f, dfdx, dfdv); add_v3_v3(data->F[v1], f); - + world_to_root_v3(data, v2, win, winvec[v2]); edge_wind_vertex(dir, length, radius2, win, f, dfdx, dfdv); add_v3_v3(data->F[v2], f); @@ -1451,10 +1451,10 @@ void BPH_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, float void BPH_mass_spring_force_vertex_wind(Implicit_Data *data, int v, float UNUSED(radius), const float (*winvec)[3]) { const float density = 0.01f; /* XXX arbitrary value, corresponds to effect of air density */ - + float wind[3]; float f[3]; - + world_to_root_v3(data, v, wind, winvec[v]); mul_v3_v3fl(f, wind, density); add_v3_v3(data->F[v], f); @@ -1466,8 +1466,8 @@ BLI_INLINE void dfdx_spring(float to[3][3], const float dir[3], float length, fl //return ( (I-outerprod(dir, dir))*Min(1.0f, rest/length) - I) * -k; outerproduct(to, dir, dir); sub_m3_m3m3(to, I, to); - - mul_m3_fl(to, (L/length)); + + mul_m3_fl(to, (L/length)); sub_m3_m3m3(to, to, I); mul_m3_fl(to, k); } @@ -1476,7 +1476,7 @@ BLI_INLINE void dfdx_spring(float to[3][3], const float dir[3], float length, fl #if 0 BLI_INLINE void dfdx_damp(float to[3][3], const float dir[3], float length, const float vel[3], float rest, float damping) { - // inner spring damping vel is the relative velocity of the endpoints. + // inner spring damping vel is the relative velocity of the endpoints. // return (I-outerprod(dir, dir)) * (-damping * -(dot(dir, vel)/Max(length, rest))); mul_fvectorT_fvector(to, dir, dir); sub_fmatrix_fmatrix(to, I, to); @@ -1512,7 +1512,7 @@ BLI_INLINE float fbstar(float length, float L, float kb, float cb) { float tempfb_fl = kb * fb(length, L); float fbstar_fl = cb * (length - L); - + if (tempfb_fl < fbstar_fl) return fbstar_fl; else @@ -1539,7 +1539,7 @@ BLI_INLINE bool spring_length(Implicit_Data *data, int i, int j, float r_extent[ sub_v3_v3v3(r_extent, data->X[j], data->X[i]); sub_v3_v3v3(r_vel, data->V[j], data->V[i]); *r_length = len_v3(r_extent); - + if (*r_length > ALMOST_ZERO) { /* if (length>L) { @@ -1557,21 +1557,21 @@ BLI_INLINE bool spring_length(Implicit_Data *data, int i, int j, float r_extent[ else { zero_v3(r_dir); } - + return true; } BLI_INLINE void apply_spring(Implicit_Data *data, int i, int j, const float f[3], float dfdx[3][3], float dfdv[3][3]) { int block_ij = BPH_mass_spring_add_block(data, i, j); - + add_v3_v3(data->F[i], f); sub_v3_v3(data->F[j], f); - + add_m3_m3m3(data->dFdX[i].m, data->dFdX[i].m, dfdx); add_m3_m3m3(data->dFdX[j].m, data->dFdX[j].m, dfdx); sub_m3_m3m3(data->dFdX[block_ij].m, data->dFdX[block_ij].m, dfdx); - + add_m3_m3m3(data->dFdV[i].m, data->dFdV[i].m, dfdv); add_m3_m3m3(data->dFdV[j].m, data->dFdV[j].m, dfdv); sub_m3_m3m3(data->dFdV[block_ij].m, data->dFdV[block_ij].m, dfdv); @@ -1581,7 +1581,7 @@ bool BPH_mass_spring_force_spring_linear(Implicit_Data *data, int i, int j, floa float stiffness, float damping, bool no_compress, float clamp_force) { float extent[3], length, dir[3], vel[3]; - + // calculate elonglation spring_length(data, i, j, extent, dir, &length, vel); @@ -1590,22 +1590,22 @@ bool BPH_mass_spring_force_spring_linear(Implicit_Data *data, int i, int j, floa Thus length > restlen makes cloth unconstrained at the start of simulation. */ if ((length >= restlen && length > 0) || no_compress) { float stretch_force, f[3], dfdx[3][3], dfdv[3][3]; - + stretch_force = stiffness * (length - restlen); if (clamp_force > 0.0f && stretch_force > clamp_force) { stretch_force = clamp_force; } mul_v3_v3fl(f, dir, stretch_force); - + // Ascher & Boxman, p.21: Damping only during elonglation // something wrong with it... madd_v3_v3fl(f, dir, damping * dot_v3v3(vel, dir)); - + dfdx_spring(dfdx, dir, length, restlen, stiffness); dfdv_damp(dfdv, dir, damping); - + apply_spring(data, i, j, f, dfdx, dfdv); - + return true; } else { @@ -1617,23 +1617,23 @@ bool BPH_mass_spring_force_spring_linear(Implicit_Data *data, int i, int j, floa bool BPH_mass_spring_force_spring_bending(Implicit_Data *data, int i, int j, float restlen, float kb, float cb) { float extent[3], length, dir[3], vel[3]; - + // calculate elonglation spring_length(data, i, j, extent, dir, &length, vel); - + if (length < restlen) { float f[3], dfdx[3][3], dfdv[3][3]; - + mul_v3_v3fl(f, dir, fbstar(length, restlen, kb, cb)); - + outerproduct(dfdx, dir, dir); mul_m3_fl(dfdx, fbstar_jacobi(length, restlen, kb, cb)); - + /* XXX damping not supported */ zero_m3(dfdv); - + apply_spring(data, i, j, f, dfdx, dfdv); - + return true; } else { @@ -1650,10 +1650,10 @@ bool BPH_mass_spring_force_spring_bending(Implicit_Data *data, int i, int j, flo BLI_INLINE void spring_grad_dir(Implicit_Data *data, int i, int j, float edge[3], float dir[3], float grad_dir[3][3]) { float length; - + sub_v3_v3v3(edge, data->X[j], data->X[i]); length = normalize_v3_v3(dir, edge); - + if (length > ALMOST_ZERO) { outerproduct(grad_dir, dir, dir); sub_m3_m3m3(grad_dir, I, grad_dir); @@ -1676,39 +1676,39 @@ BLI_INLINE void spring_angbend_forces(Implicit_Data *data, int i, int j, int k, float f_bend[3], f_damp[3]; float fk[3]; float dist[3]; - + zero_v3(fk); - + sub_v3_v3v3(edge_ij, data->X[j], data->X[i]); if (q == i) sub_v3_v3(edge_ij, dx); if (q == j) add_v3_v3(edge_ij, dx); normalize_v3_v3(dir_ij, edge_ij); - + sub_v3_v3v3(edge_jk, data->X[k], data->X[j]); if (q == j) sub_v3_v3(edge_jk, dx); if (q == k) add_v3_v3(edge_jk, dx); normalize_v3_v3(dir_jk, edge_jk); - + sub_v3_v3v3(vel_ij, data->V[j], data->V[i]); if (q == i) sub_v3_v3(vel_ij, dv); if (q == j) add_v3_v3(vel_ij, dv); - + sub_v3_v3v3(vel_jk, data->V[k], data->V[j]); if (q == j) sub_v3_v3(vel_jk, dv); if (q == k) add_v3_v3(vel_jk, dv); - + /* bending force */ sub_v3_v3v3(dist, goal, edge_jk); mul_v3_v3fl(f_bend, dist, stiffness); - + add_v3_v3(fk, f_bend); - + /* damping force */ madd_v3_v3v3fl(vel_ortho, vel_jk, dir_jk, -dot_v3v3(vel_jk, dir_jk)); mul_v3_v3fl(f_damp, vel_ortho, damping); - + sub_v3_v3(fk, f_damp); - + copy_v3_v3(r_f, fk); } @@ -1722,24 +1722,24 @@ BLI_INLINE void spring_angbend_estimate_dfdx(Implicit_Data *data, int i, int j, float dvec_null[3][3], dvec_pos[3][3], dvec_neg[3][3]; float f[3]; int a, b; - + zero_m3(dvec_null); unit_m3(dvec_pos); mul_m3_fl(dvec_pos, delta * 0.5f); copy_m3_m3(dvec_neg, dvec_pos); negate_m3(dvec_neg); - + /* XXX TODO offset targets to account for position dependency */ - + for (a = 0; a < 3; ++a) { spring_angbend_forces(data, i, j, k, goal, stiffness, damping, q, dvec_pos[a], dvec_null[a], f); copy_v3_v3(dfdx[a], f); - + spring_angbend_forces(data, i, j, k, goal, stiffness, damping, q, dvec_neg[a], dvec_null[a], f); sub_v3_v3(dfdx[a], f); - + for (b = 0; b < 3; ++b) { dfdx[a][b] /= delta; } @@ -1756,24 +1756,24 @@ BLI_INLINE void spring_angbend_estimate_dfdv(Implicit_Data *data, int i, int j, float dvec_null[3][3], dvec_pos[3][3], dvec_neg[3][3]; float f[3]; int a, b; - + zero_m3(dvec_null); unit_m3(dvec_pos); mul_m3_fl(dvec_pos, delta * 0.5f); copy_m3_m3(dvec_neg, dvec_pos); negate_m3(dvec_neg); - + /* XXX TODO offset targets to account for position dependency */ - + for (a = 0; a < 3; ++a) { spring_angbend_forces(data, i, j, k, goal, stiffness, damping, q, dvec_null[a], dvec_pos[a], f); copy_v3_v3(dfdv[a], f); - + spring_angbend_forces(data, i, j, k, goal, stiffness, damping, q, dvec_null[a], dvec_neg[a], f); sub_v3_v3(dfdv[a], f); - + for (b = 0; b < 3; ++b) { dfdv[a][b] /= delta; } @@ -1790,45 +1790,45 @@ bool BPH_mass_spring_force_spring_bending_angular(Implicit_Data *data, int i, in float fj[3], fk[3]; float dfj_dxi[3][3], dfj_dxj[3][3], dfk_dxi[3][3], dfk_dxj[3][3], dfk_dxk[3][3]; float dfj_dvi[3][3], dfj_dvj[3][3], dfk_dvi[3][3], dfk_dvj[3][3], dfk_dvk[3][3]; - + const float vecnull[3] = {0.0f, 0.0f, 0.0f}; - + int block_ij = BPH_mass_spring_add_block(data, i, j); int block_jk = BPH_mass_spring_add_block(data, j, k); int block_ik = BPH_mass_spring_add_block(data, i, k); - + world_to_root_v3(data, j, goal, target); - + spring_angbend_forces(data, i, j, k, goal, stiffness, damping, k, vecnull, vecnull, fk); negate_v3_v3(fj, fk); /* counterforce */ - + spring_angbend_estimate_dfdx(data, i, j, k, goal, stiffness, damping, i, dfk_dxi); spring_angbend_estimate_dfdx(data, i, j, k, goal, stiffness, damping, j, dfk_dxj); spring_angbend_estimate_dfdx(data, i, j, k, goal, stiffness, damping, k, dfk_dxk); copy_m3_m3(dfj_dxi, dfk_dxi); negate_m3(dfj_dxi); copy_m3_m3(dfj_dxj, dfk_dxj); negate_m3(dfj_dxj); - + spring_angbend_estimate_dfdv(data, i, j, k, goal, stiffness, damping, i, dfk_dvi); spring_angbend_estimate_dfdv(data, i, j, k, goal, stiffness, damping, j, dfk_dvj); spring_angbend_estimate_dfdv(data, i, j, k, goal, stiffness, damping, k, dfk_dvk); copy_m3_m3(dfj_dvi, dfk_dvi); negate_m3(dfj_dvi); copy_m3_m3(dfj_dvj, dfk_dvj); negate_m3(dfj_dvj); - + /* add forces and jacobians to the solver data */ - + add_v3_v3(data->F[j], fj); add_v3_v3(data->F[k], fk); - + add_m3_m3m3(data->dFdX[j].m, data->dFdX[j].m, dfj_dxj); add_m3_m3m3(data->dFdX[k].m, data->dFdX[k].m, dfk_dxk); - + add_m3_m3m3(data->dFdX[block_ij].m, data->dFdX[block_ij].m, dfj_dxi); add_m3_m3m3(data->dFdX[block_jk].m, data->dFdX[block_jk].m, dfk_dxj); add_m3_m3m3(data->dFdX[block_ik].m, data->dFdX[block_ik].m, dfk_dxi); - + add_m3_m3m3(data->dFdV[j].m, data->dFdV[j].m, dfj_dvj); add_m3_m3m3(data->dFdV[k].m, data->dFdV[k].m, dfk_dvk); - + add_m3_m3m3(data->dFdV[block_ij].m, data->dFdV[block_ij].m, dfj_dvi); add_m3_m3m3(data->dFdV[block_jk].m, data->dFdV[block_jk].m, dfk_dvj); add_m3_m3m3(data->dFdV[block_ik].m, data->dFdV[block_ik].m, dfk_dvi); @@ -1847,10 +1847,10 @@ bool BPH_mass_spring_force_spring_bending_angular(Implicit_Data *data, int i, in float fi[3], fj[3], fk[3]; float dfi_dxi[3][3], dfj_dxi[3][3], dfj_dxj[3][3], dfk_dxi[3][3], dfk_dxj[3][3], dfk_dxk[3][3]; float dfdvi[3][3]; - + // TESTING damping = 0.0f; - + zero_v3(fi); zero_v3(fj); zero_v3(fk); @@ -1859,68 +1859,68 @@ bool BPH_mass_spring_force_spring_bending_angular(Implicit_Data *data, int i, in zero_m3(dfk_dxi); zero_m3(dfk_dxj); zero_m3(dfk_dxk); - + /* jacobian of direction vectors */ spring_grad_dir(data, i, j, edge_ij, dir_ij, grad_dir_ij); spring_grad_dir(data, j, k, edge_jk, dir_jk, grad_dir_jk); - + sub_v3_v3v3(vel_jk, data->V[k], data->V[j]); - + /* bending force */ mul_v3_v3fl(target, dir_ij, restlen); sub_v3_v3v3(dist, target, edge_jk); mul_v3_v3fl(fk, dist, stiffness); - + /* damping force */ madd_v3_v3v3fl(vel_jk_ortho, vel_jk, dir_jk, -dot_v3v3(vel_jk, dir_jk)); madd_v3_v3fl(fk, vel_jk_ortho, damping); - + /* XXX this only holds true as long as we assume straight rest shape! * eventually will become a bit more involved since the opposite segment * gets its own target, under condition of having equal torque on both sides. */ copy_v3_v3(fi, fk); - + /* counterforce on the middle point */ sub_v3_v3(fj, fi); sub_v3_v3(fj, fk); - + /* === derivatives === */ - + madd_m3_m3fl(dfk_dxi, grad_dir_ij, stiffness * restlen); - + madd_m3_m3fl(dfk_dxj, grad_dir_ij, -stiffness * restlen); madd_m3_m3fl(dfk_dxj, I, stiffness); - + madd_m3_m3fl(dfk_dxk, I, -stiffness); - + copy_m3_m3(dfi_dxi, dfk_dxk); negate_m3(dfi_dxi); - + /* dfj_dfi == dfi_dfj due to symmetry, * dfi_dfj == dfk_dfj due to fi == fk * XXX see comment above on future bent rest shapes */ copy_m3_m3(dfj_dxi, dfk_dxj); - + /* dfj_dxj == -(dfi_dxj + dfk_dxj) due to fj == -(fi + fk) */ sub_m3_m3m3(dfj_dxj, dfj_dxj, dfj_dxi); sub_m3_m3m3(dfj_dxj, dfj_dxj, dfk_dxj); - + /* add forces and jacobians to the solver data */ add_v3_v3(data->F[i], fi); add_v3_v3(data->F[j], fj); add_v3_v3(data->F[k], fk); - + add_m3_m3m3(data->dFdX[i].m, data->dFdX[i].m, dfi_dxi); add_m3_m3m3(data->dFdX[j].m, data->dFdX[j].m, dfj_dxj); add_m3_m3m3(data->dFdX[k].m, data->dFdX[k].m, dfk_dxk); - + add_m3_m3m3(data->dFdX[block_ij].m, data->dFdX[block_ij].m, dfj_dxi); add_m3_m3m3(data->dFdX[block_jk].m, data->dFdX[block_jk].m, dfk_dxj); add_m3_m3m3(data->dFdX[block_ik].m, data->dFdX[block_ik].m, dfk_dxi); #endif - + return true; } @@ -1929,29 +1929,29 @@ bool BPH_mass_spring_force_spring_goal(Implicit_Data *data, int i, const float g { float root_goal_x[3], root_goal_v[3], extent[3], length, dir[3], vel[3]; float f[3], dfdx[3][3], dfdv[3][3]; - + /* goal is in world space */ world_to_root_v3(data, i, root_goal_x, goal_x); world_to_root_v3(data, i, root_goal_v, goal_v); - + sub_v3_v3v3(extent, root_goal_x, data->X[i]); sub_v3_v3v3(vel, root_goal_v, data->V[i]); length = normalize_v3_v3(dir, extent); - + if (length > ALMOST_ZERO) { mul_v3_v3fl(f, dir, stiffness * length); - + // Ascher & Boxman, p.21: Damping only during elonglation // something wrong with it... madd_v3_v3fl(f, dir, damping * dot_v3v3(vel, dir)); - + dfdx_spring(dfdx, dir, length, 0.0f, stiffness); dfdv_damp(dfdv, dir, damping); - + add_v3_v3(data->F[i], f); add_m3_m3m3(data->dFdX[i].m, data->dFdX[i].m, dfdx); add_m3_m3m3(data->dFdV[i].m, data->dFdV[i].m, dfdv); - + return true; } else { diff --git a/source/blender/physics/intern/implicit_eigen.cpp b/source/blender/physics/intern/implicit_eigen.cpp index d56525f2e93..eaac63893a6 100644 --- a/source/blender/physics/intern/implicit_eigen.cpp +++ b/source/blender/physics/intern/implicit_eigen.cpp @@ -99,24 +99,24 @@ static float I[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; class fVector : public Eigen::Vector3f { public: typedef float *ctype; - + fVector() { } - + fVector(const ctype &v) { for (int k = 0; k < 3; ++k) coeffRef(k) = v[k]; } - + fVector& operator = (const ctype &v) { for (int k = 0; k < 3; ++k) coeffRef(k) = v[k]; return *this; } - + operator ctype() { return data(); @@ -129,18 +129,18 @@ public: class fMatrix : public Eigen::Matrix3f { public: typedef float (*ctype)[3]; - + fMatrix() { } - + fMatrix(const ctype &v) { for (int k = 0; k < 3; ++k) for (int l = 0; l < 3; ++l) coeffRef(l, k) = v[k][l]; } - + fMatrix& operator = (const ctype &v) { for (int k = 0; k < 3; ++k) @@ -148,7 +148,7 @@ public: coeffRef(l, k) = v[k][l]; return *this; } - + operator ctype() { return (ctype)data(); @@ -161,23 +161,23 @@ public: class lVector : public Eigen::VectorXf { public: typedef Eigen::VectorXf base_t; - + lVector() { } - + template lVector& operator = (T rhs) { base_t::operator=(rhs); return *this; } - + float* v3(int vertex) { return &coeffRef(3 * vertex); } - + const float* v3(int vertex) const { return &coeffRef(3 * vertex); @@ -198,18 +198,18 @@ struct lMatrixCtor { lMatrixCtor() { } - + void reset() { m_trips.clear(); } - + void reserve(int numverts) { /* reserve for diagonal entries */ m_trips.reserve(numverts * 9); } - + void add(int i, int j, const fMatrix &m) { i *= 3; @@ -218,7 +218,7 @@ struct lMatrixCtor { for (int l = 0; l < 3; ++l) m_trips.push_back(Triplet(i + k, j + l, m.coeff(l, k))); } - + void sub(int i, int j, const fMatrix &m) { i *= 3; @@ -227,13 +227,13 @@ struct lMatrixCtor { for (int l = 0; l < 3; ++l) m_trips.push_back(Triplet(i + k, j + l, -m.coeff(l, k))); } - + inline void construct(lMatrix &m) { m.setFromTriplets(m_trips.begin(), m_trips.end()); m_trips.clear(); } - + private: TripletList m_trips; }; @@ -253,7 +253,7 @@ static void print_lvector(const lVector &v) for (int i = 0; i < v.rows(); ++i) { if (i > 0 && i % 3 == 0) printf("\n"); - + printf("%f,\n", v[i]); } } @@ -263,11 +263,11 @@ static void print_lmatrix(const lMatrix &m) for (int j = 0; j < m.rows(); ++j) { if (j > 0 && j % 3 == 0) printf("\n"); - + for (int i = 0; i < m.cols(); ++i) { if (i > 0 && i % 3 == 0) printf(" "); - + implicit_print_matrix_elem(m.coeff(j, i)); } printf("\n"); @@ -383,63 +383,63 @@ BLI_INLINE void madd_m3_m3m3fl(float r[3][3], float a[3][3], float b[3][3], floa struct Implicit_Data { typedef std::vector fMatrixVector; - + Implicit_Data(int numverts) { resize(numverts); } - + void resize(int numverts) { this->numverts = numverts; int tot = 3 * numverts; - + M.resize(tot, tot); F.resize(tot); dFdX.resize(tot, tot); dFdV.resize(tot, tot); - + tfm.resize(numverts, I); - + X.resize(tot); Xnew.resize(tot); V.resize(tot); Vnew.resize(tot); - + A.resize(tot, tot); B.resize(tot); - + dV.resize(tot); z.resize(tot); S.resize(tot, tot); - + iM.reserve(numverts); idFdX.reserve(numverts); idFdV.reserve(numverts); iS.reserve(numverts); } - + int numverts; - + /* inputs */ lMatrix M; /* masses */ lVector F; /* forces */ lMatrix dFdX, dFdV; /* force jacobians */ - + fMatrixVector tfm; /* local coordinate transform */ - + /* motion state data */ lVector X, Xnew; /* positions */ lVector V, Vnew; /* velocities */ - + /* internal solver data */ lVector B; /* B for A*dV = B */ lMatrix A; /* A for A*dV = B */ - + lVector dV; /* velocity change (solution of A*dV = B) */ lVector z; /* target velocity in constrained directions */ lMatrix S; /* filtering matrix for constraints */ - + /* temporary constructors */ lMatrixCtor iM; /* masses */ lMatrixCtor idFdX, idFdV; /* force jacobians */ @@ -502,25 +502,25 @@ bool BPH_mass_spring_solve_velocities(Implicit_Data *data, float dt, ImplicitSol #ifdef USE_EIGEN_CONSTRAINED_CG typedef ConstraintConjGrad solver_t; #endif - + data->iM.construct(data->M); data->idFdX.construct(data->dFdX); data->idFdV.construct(data->dFdV); data->iS.construct(data->S); - + solver_t cg; cg.setMaxIterations(100); cg.setTolerance(0.01f); - + #ifdef USE_EIGEN_CONSTRAINED_CG cg.filter() = data->S; #endif - + data->A = data->M - dt * data->dFdV - dt*dt * data->dFdX; cg.compute(data->A); - + data->B = dt * data->F + dt*dt * data->dFdX * data->V; - + #ifdef IMPLICIT_PRINT_SOLVER_INPUT_OUTPUT printf("==== A ====\n"); print_lmatrix(id->A); @@ -531,22 +531,22 @@ bool BPH_mass_spring_solve_velocities(Implicit_Data *data, float dt, ImplicitSol printf("==== S ====\n"); print_lmatrix(id->S); #endif - + #ifdef USE_EIGEN_CORE data->dV = cg.solve(data->B); #endif #ifdef USE_EIGEN_CONSTRAINED_CG data->dV = cg.solveWithGuess(data->B, data->z); #endif - + #ifdef IMPLICIT_PRINT_SOLVER_INPUT_OUTPUT printf("==== dV ====\n"); print_lvector(id->dV); printf("========\n"); #endif - + data->Vnew = data->V + data->dV; - + switch (cg.info()) { case Eigen::Success: result->status = BPH_SOLVER_SUCCESS; break; case Eigen::NoConvergence: result->status = BPH_SOLVER_NO_CONVERGENCE; break; @@ -556,7 +556,7 @@ bool BPH_mass_spring_solve_velocities(Implicit_Data *data, float dt, ImplicitSol result->iterations = cg.iterations(); result->error = cg.error(); - + return cg.info() == Eigen::Success; } @@ -641,26 +641,26 @@ void BPH_mass_spring_clear_constraints(Implicit_Data *data) void BPH_mass_spring_add_constraint_ndof0(Implicit_Data *data, int index, const float dV[3]) { data->iS.sub(index, index, I); - + world_to_root_v3(data, index, data->z.v3(index), dV); } void BPH_mass_spring_add_constraint_ndof1(Implicit_Data *data, int index, const float c1[3], const float c2[3], const float dV[3]) { float m[3][3], p[3], q[3], u[3], cmat[3][3]; - + world_to_root_v3(data, index, p, c1); outerproduct(cmat, p, p); copy_m3_m3(m, cmat); - + world_to_root_v3(data, index, q, c2); outerproduct(cmat, q, q); add_m3_m3m3(m, m, cmat); - + /* XXX not sure but multiplication should work here */ data->iS.sub(index, index, m); // mul_m3_m3m3(data->S[index].m, data->S[index].m, m); - + world_to_root_v3(data, index, u, dV); add_v3_v3(data->z.v3(index), u); } @@ -668,14 +668,14 @@ void BPH_mass_spring_add_constraint_ndof1(Implicit_Data *data, int index, const void BPH_mass_spring_add_constraint_ndof2(Implicit_Data *data, int index, const float c1[3], const float dV[3]) { float m[3][3], p[3], u[3], cmat[3][3]; - + world_to_root_v3(data, index, p, c1); outerproduct(cmat, p, p); copy_m3_m3(m, cmat); - + data->iS.sub(index, index, m); // mul_m3_m3m3(data->S[index].m, data->S[index].m, m); - + world_to_root_v3(data, index, u, dV); add_v3_v3(data->z.v3(index), u); } @@ -694,37 +694,37 @@ void BPH_mass_spring_force_reference_frame(Implicit_Data *data, int index, const float f[3], dfdx[3][3], dfdv[3][3]; float euler[3], coriolis[3], centrifugal[3], rotvel[3]; float deuler[3][3], dcoriolis[3][3], dcentrifugal[3][3], drotvel[3][3]; - + world_to_root_v3(data, index, acc, acceleration); world_to_root_v3(data, index, w, omega); world_to_root_v3(data, index, dwdt, domega_dt); - + cross_v3_v3v3(euler, dwdt, data->X.v3(index)); cross_v3_v3v3(coriolis, w, data->V.v3(index)); mul_v3_fl(coriolis, 2.0f); cross_v3_v3v3(rotvel, w, data->X.v3(index)); cross_v3_v3v3(centrifugal, w, rotvel); - + sub_v3_v3v3(f, acc, euler); sub_v3_v3(f, coriolis); sub_v3_v3(f, centrifugal); - + mul_v3_fl(f, mass); /* F = m * a */ - + cross_v3_identity(deuler, dwdt); cross_v3_identity(dcoriolis, w); mul_m3_fl(dcoriolis, 2.0f); cross_v3_identity(drotvel, w); cross_m3_v3m3(dcentrifugal, w, drotvel); - + add_m3_m3m3(dfdx, deuler, dcentrifugal); negate_m3(dfdx); mul_m3_fl(dfdx, mass); - + copy_m3_m3(dfdv, dcoriolis); negate_m3(dfdv); mul_m3_fl(dfdv, mass); - + add_v3_v3(data->F.v3(index), f); data->idFdX.add(index, index, dfdx); data->idFdV.add(index, index, dfdv); @@ -743,7 +743,7 @@ void BPH_mass_spring_force_gravity(Implicit_Data *data, int index, float mass, c float f[3]; world_to_root_v3(data, index, f, g); mul_v3_fl(f, mass); - + add_v3_v3(data->F.v3(index), f); } @@ -752,10 +752,10 @@ void BPH_mass_spring_force_drag(Implicit_Data *data, float drag) int numverts = data->numverts; for (int i = 0; i < numverts; i++) { float tmp[3][3]; - + /* NB: uses root space velocity, no need to transform */ madd_v3_v3fl(data->F.v3(i), data->V.v3(i), -drag); - + copy_m3_m3(tmp, I); mul_m3_fl(tmp, -drag); data->idFdV.add(i, i, tmp); @@ -768,7 +768,7 @@ void BPH_mass_spring_force_extern(struct Implicit_Data *data, int i, const float world_to_root_v3(data, i, tf, f); world_to_root_m3(data, i, tdfdx, dfdx); world_to_root_m3(data, i, tdfdv, dfdv); - + add_v3_v3(data->F.v3(i), tf); data->idFdX.add(i, i, tdfdx); data->idFdV.add(i, i, tdfdv); @@ -777,10 +777,10 @@ void BPH_mass_spring_force_extern(struct Implicit_Data *data, int i, const float static float calc_nor_area_tri(float nor[3], const float v1[3], const float v2[3], const float v3[3]) { float n1[3], n2[3]; - + sub_v3_v3v3(n1, v1, v2); sub_v3_v3v3(n2, v2, v3); - + cross_v3_v3v3(nor, n1, n2); return normalize_v3(nor); } @@ -791,17 +791,17 @@ void BPH_mass_spring_force_face_wind(Implicit_Data *data, int v1, int v2, int v3 const float effector_scale = 0.02f; float win[3], nor[3], area; float factor; - + // calculate face normal and area area = calc_nor_area_tri(nor, data->X.v3(v1), data->X.v3(v2), data->X.v3(v3)); factor = effector_scale * area / 3.0f; - + world_to_root_v3(data, v1, win, winvec[v1]); madd_v3_v3fl(data->F.v3(v1), nor, factor * dot_v3v3(win, nor)); - + world_to_root_v3(data, v2, win, winvec[v2]); madd_v3_v3fl(data->F.v3(v2), nor, factor * dot_v3v3(win, nor)); - + world_to_root_v3(data, v3, win, winvec[v3]); madd_v3_v3fl(data->F.v3(v3), nor, factor * dot_v3v3(win, nor)); } @@ -810,14 +810,14 @@ void BPH_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, const { const float effector_scale = 0.01; float win[3], dir[3], nor[3], length; - + sub_v3_v3v3(dir, data->X.v3(v1), data->X.v3(v2)); length = normalize_v3(dir); - + world_to_root_v3(data, v1, win, winvec[v1]); madd_v3_v3v3fl(nor, win, dir, -dot_v3v3(win, dir)); madd_v3_v3fl(data->F.v3(v1), nor, effector_scale * length); - + world_to_root_v3(data, v2, win, winvec[v2]); madd_v3_v3v3fl(nor, win, dir, -dot_v3v3(win, dir)); madd_v3_v3fl(data->F.v3(v2), nor, effector_scale * length); @@ -829,8 +829,8 @@ BLI_INLINE void dfdx_spring(float to[3][3], const float dir[3], float length, fl //return ( (I-outerprod(dir, dir))*Min(1.0f, rest/length) - I) * -k; outerproduct(to, dir, dir); sub_m3_m3m3(to, I, to); - - mul_m3_fl(to, (L/length)); + + mul_m3_fl(to, (L/length)); sub_m3_m3m3(to, to, I); mul_m3_fl(to, k); } @@ -839,7 +839,7 @@ BLI_INLINE void dfdx_spring(float to[3][3], const float dir[3], float length, fl #if 0 BLI_INLINE void dfdx_damp(float to[3][3], const float dir[3], float length, const float vel[3], float rest, float damping) { - // inner spring damping vel is the relative velocity of the endpoints. + // inner spring damping vel is the relative velocity of the endpoints. // return (I-outerprod(dir, dir)) * (-damping * -(dot(dir, vel)/Max(length, rest))); mul_fvectorT_fvector(to, dir, dir); sub_fmatrix_fmatrix(to, I, to); @@ -871,7 +871,7 @@ BLI_INLINE float fbstar(float length, float L, float kb, float cb) { float tempfb_fl = kb * fb(length, L); float fbstar_fl = cb * (length - L); - + if (tempfb_fl < fbstar_fl) return fbstar_fl; else @@ -898,7 +898,7 @@ BLI_INLINE bool spring_length(Implicit_Data *data, int i, int j, float r_extent[ sub_v3_v3v3(r_extent, data->X.v3(j), data->X.v3(i)); sub_v3_v3v3(r_vel, data->V.v3(j), data->V.v3(i)); *r_length = len_v3(r_extent); - + if (*r_length > ALMOST_ZERO) { /* if (length>L) { @@ -916,7 +916,7 @@ BLI_INLINE bool spring_length(Implicit_Data *data, int i, int j, float r_extent[ else { zero_v3(r_dir); } - + return true; } @@ -924,12 +924,12 @@ BLI_INLINE void apply_spring(Implicit_Data *data, int i, int j, const float f[3] { add_v3_v3(data->F.v3(i), f); sub_v3_v3(data->F.v3(j), f); - + data->idFdX.add(i, i, dfdx); data->idFdX.add(j, j, dfdx); data->idFdX.sub(i, j, dfdx); data->idFdX.sub(j, i, dfdx); - + data->idFdV.add(i, i, dfdv); data->idFdV.add(j, j, dfdv); data->idFdV.sub(i, j, dfdv); @@ -941,39 +941,39 @@ bool BPH_mass_spring_force_spring_linear(Implicit_Data *data, int i, int j, floa float r_f[3], float r_dfdx[3][3], float r_dfdv[3][3]) { float extent[3], length, dir[3], vel[3]; - + // calculate elonglation spring_length(data, i, j, extent, dir, &length, vel); - + if (length > restlen || no_compress) { float stretch_force, f[3], dfdx[3][3], dfdv[3][3]; - + stretch_force = stiffness * (length - restlen); if (clamp_force > 0.0f && stretch_force > clamp_force) { stretch_force = clamp_force; } mul_v3_v3fl(f, dir, stretch_force); - + // Ascher & Boxman, p.21: Damping only during elonglation // something wrong with it... madd_v3_v3fl(f, dir, damping * dot_v3v3(vel, dir)); - + dfdx_spring(dfdx, dir, length, restlen, stiffness); dfdv_damp(dfdv, dir, damping); - + apply_spring(data, i, j, f, dfdx, dfdv); - + if (r_f) copy_v3_v3(r_f, f); if (r_dfdx) copy_m3_m3(r_dfdx, dfdx); if (r_dfdv) copy_m3_m3(r_dfdv, dfdv); - + return true; } else { if (r_f) zero_v3(r_f); if (r_dfdx) zero_m3(r_dfdx); if (r_dfdv) zero_m3(r_dfdv); - + return false; } } @@ -984,34 +984,34 @@ bool BPH_mass_spring_force_spring_bending(Implicit_Data *data, int i, int j, flo float r_f[3], float r_dfdx[3][3], float r_dfdv[3][3]) { float extent[3], length, dir[3], vel[3]; - + // calculate elonglation spring_length(data, i, j, extent, dir, &length, vel); - + if (length < restlen) { float f[3], dfdx[3][3], dfdv[3][3]; - + mul_v3_v3fl(f, dir, fbstar(length, restlen, kb, cb)); - + outerproduct(dfdx, dir, dir); mul_m3_fl(dfdx, fbstar_jacobi(length, restlen, kb, cb)); - + /* XXX damping not supported */ zero_m3(dfdv); - + apply_spring(data, i, j, f, dfdx, dfdv); - + if (r_f) copy_v3_v3(r_f, f); if (r_dfdx) copy_m3_m3(r_dfdx, dfdx); if (r_dfdv) copy_m3_m3(r_dfdv, dfdv); - + return true; } else { if (r_f) zero_v3(r_f); if (r_dfdx) zero_m3(r_dfdx); if (r_dfdv) zero_m3(r_dfdv); - + return false; } } @@ -1025,10 +1025,10 @@ bool BPH_mass_spring_force_spring_bending(Implicit_Data *data, int i, int j, flo BLI_INLINE void spring_grad_dir(Implicit_Data *data, int i, int j, float edge[3], float dir[3], float grad_dir[3][3]) { float length; - + sub_v3_v3v3(edge, data->X.v3(j), data->X.v3(i)); length = normalize_v3_v3(dir, edge); - + if (length > ALMOST_ZERO) { outerproduct(grad_dir, dir, dir); sub_m3_m3m3(grad_dir, I, grad_dir); @@ -1051,39 +1051,39 @@ BLI_INLINE void spring_angbend_forces(Implicit_Data *data, int i, int j, int k, float f_bend[3], f_damp[3]; float fk[3]; float dist[3]; - + zero_v3(fk); - + sub_v3_v3v3(edge_ij, data->X.v3(j), data->X.v3(i)); if (q == i) sub_v3_v3(edge_ij, dx); if (q == j) add_v3_v3(edge_ij, dx); normalize_v3_v3(dir_ij, edge_ij); - + sub_v3_v3v3(edge_jk, data->X.v3(k), data->X.v3(j)); if (q == j) sub_v3_v3(edge_jk, dx); if (q == k) add_v3_v3(edge_jk, dx); normalize_v3_v3(dir_jk, edge_jk); - + sub_v3_v3v3(vel_ij, data->V.v3(j), data->V.v3(i)); if (q == i) sub_v3_v3(vel_ij, dv); if (q == j) add_v3_v3(vel_ij, dv); - + sub_v3_v3v3(vel_jk, data->V.v3(k), data->V.v3(j)); if (q == j) sub_v3_v3(vel_jk, dv); if (q == k) add_v3_v3(vel_jk, dv); - + /* bending force */ sub_v3_v3v3(dist, goal, edge_jk); mul_v3_v3fl(f_bend, dist, stiffness); - + add_v3_v3(fk, f_bend); - + /* damping force */ madd_v3_v3v3fl(vel_ortho, vel_jk, dir_jk, -dot_v3v3(vel_jk, dir_jk)); mul_v3_v3fl(f_damp, vel_ortho, damping); - + sub_v3_v3(fk, f_damp); - + copy_v3_v3(r_f, fk); } @@ -1097,24 +1097,24 @@ BLI_INLINE void spring_angbend_estimate_dfdx(Implicit_Data *data, int i, int j, float dvec_null[3][3], dvec_pos[3][3], dvec_neg[3][3]; float f[3]; int a, b; - + zero_m3(dvec_null); unit_m3(dvec_pos); mul_m3_fl(dvec_pos, delta * 0.5f); copy_m3_m3(dvec_neg, dvec_pos); negate_m3(dvec_neg); - + /* XXX TODO offset targets to account for position dependency */ - + for (a = 0; a < 3; ++a) { spring_angbend_forces(data, i, j, k, goal, stiffness, damping, q, dvec_pos[a], dvec_null[a], f); copy_v3_v3(dfdx[a], f); - + spring_angbend_forces(data, i, j, k, goal, stiffness, damping, q, dvec_neg[a], dvec_null[a], f); sub_v3_v3(dfdx[a], f); - + for (b = 0; b < 3; ++b) { dfdx[a][b] /= delta; } @@ -1131,24 +1131,24 @@ BLI_INLINE void spring_angbend_estimate_dfdv(Implicit_Data *data, int i, int j, float dvec_null[3][3], dvec_pos[3][3], dvec_neg[3][3]; float f[3]; int a, b; - + zero_m3(dvec_null); unit_m3(dvec_pos); mul_m3_fl(dvec_pos, delta * 0.5f); copy_m3_m3(dvec_neg, dvec_pos); negate_m3(dvec_neg); - + /* XXX TODO offset targets to account for position dependency */ - + for (a = 0; a < 3; ++a) { spring_angbend_forces(data, i, j, k, goal, stiffness, damping, q, dvec_null[a], dvec_pos[a], f); copy_v3_v3(dfdv[a], f); - + spring_angbend_forces(data, i, j, k, goal, stiffness, damping, q, dvec_null[a], dvec_neg[a], f); sub_v3_v3(dfdv[a], f); - + for (b = 0; b < 3; ++b) { dfdv[a][b] /= delta; } @@ -1165,44 +1165,44 @@ bool BPH_mass_spring_force_spring_bending_angular(Implicit_Data *data, int i, in float fj[3], fk[3]; float dfj_dxi[3][3], dfj_dxj[3][3], dfk_dxi[3][3], dfk_dxj[3][3], dfk_dxk[3][3]; float dfj_dvi[3][3], dfj_dvj[3][3], dfk_dvi[3][3], dfk_dvj[3][3], dfk_dvk[3][3]; - + const float vecnull[3] = {0.0f, 0.0f, 0.0f}; - + world_to_root_v3(data, j, goal, target); - + spring_angbend_forces(data, i, j, k, goal, stiffness, damping, k, vecnull, vecnull, fk); negate_v3_v3(fj, fk); /* counterforce */ - + spring_angbend_estimate_dfdx(data, i, j, k, goal, stiffness, damping, i, dfk_dxi); spring_angbend_estimate_dfdx(data, i, j, k, goal, stiffness, damping, j, dfk_dxj); spring_angbend_estimate_dfdx(data, i, j, k, goal, stiffness, damping, k, dfk_dxk); copy_m3_m3(dfj_dxi, dfk_dxi); negate_m3(dfj_dxi); copy_m3_m3(dfj_dxj, dfk_dxj); negate_m3(dfj_dxj); - + spring_angbend_estimate_dfdv(data, i, j, k, goal, stiffness, damping, i, dfk_dvi); spring_angbend_estimate_dfdv(data, i, j, k, goal, stiffness, damping, j, dfk_dvj); spring_angbend_estimate_dfdv(data, i, j, k, goal, stiffness, damping, k, dfk_dvk); copy_m3_m3(dfj_dvi, dfk_dvi); negate_m3(dfj_dvi); copy_m3_m3(dfj_dvj, dfk_dvj); negate_m3(dfj_dvj); - + /* add forces and jacobians to the solver data */ - + add_v3_v3(data->F.v3(j), fj); add_v3_v3(data->F.v3(k), fk); - + data->idFdX.add(j, j, dfj_dxj); data->idFdX.add(k, k, dfk_dxk); - + data->idFdX.add(i, j, dfj_dxi); data->idFdX.add(j, i, dfj_dxi); data->idFdX.add(j, k, dfk_dxj); data->idFdX.add(k, j, dfk_dxj); data->idFdX.add(i, k, dfk_dxi); data->idFdX.add(k, i, dfk_dxi); - + data->idFdV.add(j, j, dfj_dvj); data->idFdV.add(k, k, dfk_dvk); - + data->idFdV.add(i, j, dfj_dvi); data->idFdV.add(j, i, dfj_dvi); data->idFdV.add(j, k, dfk_dvj); @@ -1223,10 +1223,10 @@ bool BPH_mass_spring_force_spring_bending_angular(Implicit_Data *data, int i, in float fi[3], fj[3], fk[3]; float dfi_dxi[3][3], dfj_dxi[3][3], dfj_dxj[3][3], dfk_dxi[3][3], dfk_dxj[3][3], dfk_dxk[3][3]; float dfdvi[3][3]; - + // TESTING damping = 0.0f; - + zero_v3(fi); zero_v3(fj); zero_v3(fk); @@ -1235,68 +1235,68 @@ bool BPH_mass_spring_force_spring_bending_angular(Implicit_Data *data, int i, in zero_m3(dfk_dxi); zero_m3(dfk_dxj); zero_m3(dfk_dxk); - + /* jacobian of direction vectors */ spring_grad_dir(data, i, j, edge_ij, dir_ij, grad_dir_ij); spring_grad_dir(data, j, k, edge_jk, dir_jk, grad_dir_jk); - + sub_v3_v3v3(vel_jk, data->V[k], data->V[j]); - + /* bending force */ mul_v3_v3fl(target, dir_ij, restlen); sub_v3_v3v3(dist, target, edge_jk); mul_v3_v3fl(fk, dist, stiffness); - + /* damping force */ madd_v3_v3v3fl(vel_jk_ortho, vel_jk, dir_jk, -dot_v3v3(vel_jk, dir_jk)); madd_v3_v3fl(fk, vel_jk_ortho, damping); - + /* XXX this only holds true as long as we assume straight rest shape! * eventually will become a bit more involved since the opposite segment * gets its own target, under condition of having equal torque on both sides. */ copy_v3_v3(fi, fk); - + /* counterforce on the middle point */ sub_v3_v3(fj, fi); sub_v3_v3(fj, fk); - + /* === derivatives === */ - + madd_m3_m3fl(dfk_dxi, grad_dir_ij, stiffness * restlen); - + madd_m3_m3fl(dfk_dxj, grad_dir_ij, -stiffness * restlen); madd_m3_m3fl(dfk_dxj, I, stiffness); - + madd_m3_m3fl(dfk_dxk, I, -stiffness); - + copy_m3_m3(dfi_dxi, dfk_dxk); negate_m3(dfi_dxi); - + /* dfj_dfi == dfi_dfj due to symmetry, * dfi_dfj == dfk_dfj due to fi == fk * XXX see comment above on future bent rest shapes */ copy_m3_m3(dfj_dxi, dfk_dxj); - + /* dfj_dxj == -(dfi_dxj + dfk_dxj) due to fj == -(fi + fk) */ sub_m3_m3m3(dfj_dxj, dfj_dxj, dfj_dxi); sub_m3_m3m3(dfj_dxj, dfj_dxj, dfk_dxj); - + /* add forces and jacobians to the solver data */ add_v3_v3(data->F[i], fi); add_v3_v3(data->F[j], fj); add_v3_v3(data->F[k], fk); - + add_m3_m3m3(data->dFdX[i].m, data->dFdX[i].m, dfi_dxi); add_m3_m3m3(data->dFdX[j].m, data->dFdX[j].m, dfj_dxj); add_m3_m3m3(data->dFdX[k].m, data->dFdX[k].m, dfk_dxk); - + add_m3_m3m3(data->dFdX[block_ij].m, data->dFdX[block_ij].m, dfj_dxi); add_m3_m3m3(data->dFdX[block_jk].m, data->dFdX[block_jk].m, dfk_dxj); add_m3_m3m3(data->dFdX[block_ik].m, data->dFdX[block_ik].m, dfk_dxi); #endif - + return true; } @@ -1306,40 +1306,40 @@ bool BPH_mass_spring_force_spring_goal(Implicit_Data *data, int i, const float g { float root_goal_x[3], root_goal_v[3], extent[3], length, dir[3], vel[3]; float f[3], dfdx[3][3], dfdv[3][3]; - + /* goal is in world space */ world_to_root_v3(data, i, root_goal_x, goal_x); world_to_root_v3(data, i, root_goal_v, goal_v); - + sub_v3_v3v3(extent, root_goal_x, data->X.v3(i)); sub_v3_v3v3(vel, root_goal_v, data->V.v3(i)); length = normalize_v3_v3(dir, extent); - + if (length > ALMOST_ZERO) { mul_v3_v3fl(f, dir, stiffness * length); - + // Ascher & Boxman, p.21: Damping only during elonglation // something wrong with it... madd_v3_v3fl(f, dir, damping * dot_v3v3(vel, dir)); - + dfdx_spring(dfdx, dir, length, 0.0f, stiffness); dfdv_damp(dfdv, dir, damping); - + add_v3_v3(data->F.v3(i), f); data->idFdX.add(i, i, dfdx); data->idFdV.add(i, i, dfdv); - + if (r_f) copy_v3_v3(r_f, f); if (r_dfdx) copy_m3_m3(r_dfdx, dfdx); if (r_dfdv) copy_m3_m3(r_dfdv, dfdv); - + return true; } else { if (r_f) zero_v3(r_f); if (r_dfdx) zero_m3(r_dfdx); if (r_dfdv) zero_m3(r_dfdv); - + return false; } } diff --git a/source/blender/render/CMakeLists.txt b/source/blender/render/CMakeLists.txt index 27ec6bf8ba6..36e18da00c7 100644 --- a/source/blender/render/CMakeLists.txt +++ b/source/blender/render/CMakeLists.txt @@ -24,7 +24,7 @@ # ***** END GPL LICENSE BLOCK ***** -set(INC +set(INC extern/include intern/include ../blenkernel diff --git a/source/blender/render/extern/include/RE_pipeline.h b/source/blender/render/extern/include/RE_pipeline.h index 5c979be2cb6..71988394881 100644 --- a/source/blender/render/extern/include/RE_pipeline.h +++ b/source/blender/render/extern/include/RE_pipeline.h @@ -102,12 +102,12 @@ typedef struct RenderPass { /* after render, the Combined pass is in combined, for renderlayers read from files it is a real pass */ typedef struct RenderLayer { struct RenderLayer *next, *prev; - + /* copy of RenderData */ char name[RE_MAXNAME]; unsigned int lay, lay_zmask, lay_exclude; int layflag, passflag, pass_xor; - + struct Material *mat_override; struct Group *light_override; @@ -122,18 +122,18 @@ typedef struct RenderLayer { /* optional saved endresult on disk */ void *exrhandle; - + ListBase passes; - + } RenderLayer; typedef struct RenderResult { struct RenderResult *next, *prev; - + /* target image size */ int rectx, recty; short crop, sample_nr; - + /* the following rect32, rectf and rectz buffers are for temporary storage only, for RenderResult structs * created in #RE_AcquireResultImage - which do not have RenderView */ @@ -143,25 +143,25 @@ typedef struct RenderResult { float *rectf; /* if this exists, a copy of one of layers, or result of composited layers */ float *rectz; - + /* coordinates within final image (after cropping) */ rcti tilerect; /* offset to apply to get a border render in full image */ int xof, yof; - + /* the main buffers */ ListBase layers; - + /* multiView maps to a StringVector in OpenEXR */ ListBase views; /* RenderView */ /* allowing live updates: */ volatile rcti renrect; volatile RenderLayer *renlay; - + /* optional saved endresult on disk */ int do_exr_tile; - + /* for render results in Image, verify validity for sequences */ int framenr; diff --git a/source/blender/render/extern/include/RE_shader_ext.h b/source/blender/render/extern/include/RE_shader_ext.h index 81a0449d5b7..838f7031d14 100644 --- a/source/blender/render/extern/include/RE_shader_ext.h +++ b/source/blender/render/extern/include/RE_shader_ext.h @@ -66,7 +66,7 @@ typedef struct ShadeResult { /* only here for quick copy */ struct ShadeInputCopy { - + struct Material *mat; struct VlakRen *vlr; struct StrandRen *strand; @@ -98,7 +98,7 @@ typedef struct ShadeInputCol { typedef struct ShadeInput { /* copy from face, also to extract tria from quad */ /* note it mirrors a struct above for quick copy */ - + struct Material *mat; struct VlakRen *vlr; struct StrandRen *strand; @@ -114,26 +114,26 @@ typedef struct ShadeInput { float vn[3], vno[3]; /* actual render normal, and a copy to restore it */ float n1[3], n2[3], n3[3]; /* vertex normals, corrected */ int mode, mode2; /* base material mode (OR-ed result of entire node tree) */ - + /* internal face coordinates */ float u, v, dx_u, dx_v, dy_u, dy_v; float co[3], view[3], camera_co[3]; - + /* copy from material, keep synced so we can do memcopy */ /* current size: 23*4 */ float r, g, b; float specr, specg, specb; float mirr, mirg, mirb; float ambr, ambb, ambg; - + float amb, emit, ang, spectra, ray_mirror; float alpha, refl, spec, zoffs, add; float translucency; /* end direct copy from material */ - + /* individual copies: */ int har; /* hardness */ - + /* texture coordinates */ float lo[3], gl[3], ref[3], orn[3], winco[3], vcol[4]; float refcol[4], displace[3]; @@ -144,7 +144,7 @@ typedef struct ShadeInput { ShadeInputUV uv[8]; /* 8 = MAX_MTFACE */ ShadeInputCol col[8]; /* 8 = MAX_MCOL */ int totuv, totcol, actuv, actcol; - + /* dx/dy OSA coordinates */ float dxco[3], dyco[3]; float dxlo[3], dylo[3], dxgl[3], dygl[3]; @@ -154,18 +154,18 @@ typedef struct ShadeInput { float dxwin[3], dywin[3]; float dxrefract[3], dyrefract[3]; float dxstrand, dystrand; - + /* AO is a pre-process now */ float ao[3], indirect[3], env[3]; - + int xs, ys; /* pixel to be rendered */ int mask; /* subsample mask */ float scanco[3]; /* original scanline coordinate without jitter */ - + int samplenr; /* sample counter, to detect if we should do shadow again */ int depth; /* 1 or larger on raytrace shading */ int volume_depth; /* number of intersections through volumes */ - + /* for strand shading, normal at the surface */ float surfnor[3], surfdist; @@ -175,7 +175,7 @@ typedef struct ShadeInput { bool use_world_space_shading; short thread, sample; /* sample: ShadeSample array index */ short nodes; /* indicate node shading, temp hack to prevent recursion */ - + unsigned int lay; int layflag, passflag, combinedflag; short object_pass_index; @@ -185,7 +185,7 @@ typedef struct ShadeInput { #ifdef RE_RAYCOUNTER RayCounter raycounter; #endif - + } ShadeInput; typedef struct BakeImBufuserData { diff --git a/source/blender/render/intern/include/envmap.h b/source/blender/render/intern/include/envmap.h index 58bde7d2322..c66427ae788 100644 --- a/source/blender/render/intern/include/envmap.h +++ b/source/blender/render/intern/include/envmap.h @@ -34,7 +34,7 @@ #ifndef __ENVMAP_H__ -#define __ENVMAP_H__ +#define __ENVMAP_H__ /** * Make environment maps for all objects in the scene that have an diff --git a/source/blender/render/intern/include/initrender.h b/source/blender/render/intern/include/initrender.h index 87e2d2519d5..0f952baf257 100644 --- a/source/blender/render/intern/include/initrender.h +++ b/source/blender/render/intern/include/initrender.h @@ -31,7 +31,7 @@ #ifndef __INITRENDER_H__ -#define __INITRENDER_H__ +#define __INITRENDER_H__ /* Functions */ diff --git a/source/blender/render/intern/include/pixelblending.h b/source/blender/render/intern/include/pixelblending.h index fd647f96afe..022510c7132 100644 --- a/source/blender/render/intern/include/pixelblending.h +++ b/source/blender/render/intern/include/pixelblending.h @@ -29,7 +29,7 @@ #ifndef __PIXELBLENDING_H__ -#define __PIXELBLENDING_H__ +#define __PIXELBLENDING_H__ /** diff --git a/source/blender/render/intern/include/pixelshading.h b/source/blender/render/intern/include/pixelshading.h index 98da7eb037b..0e630eda475 100644 --- a/source/blender/render/intern/include/pixelshading.h +++ b/source/blender/render/intern/include/pixelshading.h @@ -44,7 +44,7 @@ * mask is pixel coverage in bits * \return pointer to the object */ -int shadeHaloFloat(HaloRen *har, +int shadeHaloFloat(HaloRen *har, float *col, int zz, float dist, float xn, float yn, short flarec); diff --git a/source/blender/render/intern/include/pointdensity.h b/source/blender/render/intern/include/pointdensity.h index 1d1e808e8d3..eadf714c1ba 100644 --- a/source/blender/render/intern/include/pointdensity.h +++ b/source/blender/render/intern/include/pointdensity.h @@ -31,7 +31,7 @@ #ifndef __POINTDENSITY_H__ -#define __POINTDENSITY_H__ +#define __POINTDENSITY_H__ /** * Make point density kd-trees for all point density textures in the scene diff --git a/source/blender/render/intern/include/raycounter.h b/source/blender/render/intern/include/raycounter.h index d9ae210048d..e16c6e13c7e 100644 --- a/source/blender/render/intern/include/raycounter.h +++ b/source/blender/render/intern/include/raycounter.h @@ -64,7 +64,7 @@ extern RayCounter re_rc_counter[]; #define RE_RC_INFO(rc) #define RE_RC_MERGE(dest,src) #define RE_RC_COUNT(var) - + #endif #ifdef __cplusplus diff --git a/source/blender/render/intern/include/rayintersection.h b/source/blender/render/intern/include/rayintersection.h index ae1db30575a..a303301ad3b 100644 --- a/source/blender/render/intern/include/rayintersection.h +++ b/source/blender/render/intern/include/rayintersection.h @@ -69,7 +69,7 @@ typedef struct Isect { /* for envmap and incremental view update renders */ float origstart[3]; float origdir[3]; - + /* precomputed values to accelerate bounding box intersection */ int bv_index[6]; float idot_axis[3]; @@ -84,12 +84,12 @@ typedef struct Isect { /* hit information */ float u, v; int isect; /* which half of quad */ - + struct { void *ob; void *face; } hit, orig; - + /* last hit optimization */ struct RayObject *last_hit; @@ -98,7 +98,7 @@ typedef struct Isect { RayTraceHint *hint, *hit_hint; #endif RayHint *hint; - + /* ray counter */ #ifdef RE_RAYCOUNTER RayCounter *raycounter; diff --git a/source/blender/render/intern/include/render_types.h b/source/blender/render/intern/include/render_types.h index 45206f21ae4..4753d65597a 100644 --- a/source/blender/render/intern/include/render_types.h +++ b/source/blender/render/intern/include/render_types.h @@ -72,7 +72,7 @@ typedef struct SampleTables { float centLut[16]; float *fmask1[9], *fmask2[9]; char cmask[256], *centmask; - + } SampleTables; typedef struct QMCSampler { @@ -91,10 +91,10 @@ typedef struct QMCSampler { /* this is handed over to threaded hiding/passes/shading engine */ typedef struct RenderPart { struct RenderPart *next, *prev; - + RenderResult *result; /* result of part rendering */ ListBase fullresult; /* optional full sample buffers */ - + int *recto; /* object table for objects */ int *rectp; /* polygon index table */ int *rectz; /* zbuffer */ @@ -111,7 +111,7 @@ typedef struct RenderPart { short crop, status; /* crop is amount of pixels we crop, for filter */ short sample; /* sample can be used by zbuffers */ short thread; /* thread id */ - + char *clipflag; /* clipflags for part zbuffering */ } RenderPart; @@ -127,13 +127,13 @@ struct Render { struct Render *next, *prev; char name[RE_MAXNAME]; int slot; - + /* state settings */ short flag, osa, ok, result_ok; - + /* due to performance issues, getting initialized from color management settings once on Render initialization */ bool scene_color_manage; - + /* result of rendering */ RenderResult *result; /* if render with single-layer option, other rendered layers are stored here */ @@ -144,7 +144,7 @@ struct Render { * write lock, all external code must use a read lock. internal code is assumed * to not conflict with writes, so no lock used for that */ ThreadRWMutex resultmutex; - + /* window size, display rect, viewplane */ int winx, winy; /* buffer width and height with percentage applied * without border & crop. convert to long before multiplying together to avoid overflow. */ @@ -152,40 +152,40 @@ struct Render { rctf viewplane; /* mapped on winx winy */ float viewdx, viewdy; /* size of 1 pixel */ float clipcrop; /* 2 pixel boundary to prevent clip when filter used */ - + /* final picture width and height (within disprect) */ int rectx, recty; - - /* real maximum size of parts after correction for minimum + + /* real maximum size of parts after correction for minimum * partx*xparts can be larger than rectx, in that case last part is smaller */ int partx, party; - + /* values for viewing */ float ycor; /* (scene->xasp / scene->yasp), multiplied with 'winy' */ - + float panophi, panosi, panoco, panodxp, panodxv; - + /* Matrices */ float grvec[3]; /* for world */ float imat[3][3]; /* copy of viewinv */ float viewmat[4][4], viewinv[4][4]; float viewmat_orig[4][4]; /* for incremental render */ float winmat[4][4]; - + /* clippping */ float clipsta; float clipend; - + /* samples */ SampleTables *samples; float jit[32][2]; float mblur_jit[32][2]; ListBase *qmcsamplers; int num_qmc_samplers; - + /* shadow counter, detect shadow-reuse for shaders */ int shadowsamplenr[BLENDER_MAX_THREADS]; - + /* main, scene, and its full copy of renderdata and world */ struct Main *main; Scene *scene; @@ -193,13 +193,13 @@ struct Render { World wrld; struct Object *camera_override; unsigned int lay, layer_override; - + ThreadRWMutex partsmutex; ListBase parts; - + /* render engine */ struct RenderEngine *engine; - + /* octree tables and variables for raytrace */ struct RayObject *raytree; struct RayFace *rayfaces; @@ -209,17 +209,17 @@ struct Render { /* occlusion tree */ void *occlusiontree; ListBase strandsurface; - + /* use this instead of R.r.cfra */ float mblur_offs, field_offs; - + /* render database */ int totvlak, totvert, tothalo, totstrand, totlamp; struct HaloRen **sortedhalos; ListBase lights; /* GroupObject pointers */ ListBase lampren; /* storage, for free */ - + ListBase objecttable; struct ObjectInstanceRen *objectinstance; @@ -227,7 +227,7 @@ struct Render { int totinstance; struct Image *bakebuf; - + struct GHash *orco_hash; struct GHash *sss_hash; @@ -249,7 +249,7 @@ struct Render { * example dynamic TFaces to go in the VlakRen structure. */ struct MemArena *memArena; - + /* callbacks */ void (*display_init)(void *handle, RenderResult *rr); void *dih; @@ -259,17 +259,17 @@ struct Render { void *duh; void (*current_scene_update)(void *handle, struct Scene *scene); void *suh; - + void (*stats_draw)(void *handle, RenderStats *ri); void *sdh; void (*progress)(void *handle, float i); void *prh; - + void (*draw_lock)(void *handle, int i); void *dlh; int (*test_break)(void *handle); void *tbh; - + RenderStats i; struct ReportList *reports; @@ -289,7 +289,7 @@ typedef struct DeepSample { int z; float v; } DeepSample; - + typedef struct ShadSampleBuf { struct ShadSampleBuf *next, *prev; intptr_t *zbuf; @@ -309,7 +309,7 @@ typedef struct ShadBuf { int co[3]; int size, bias; ListBase buffers; - + /* irregular shadowbufer, result stored per thread */ struct ISBData *isb_result[BLENDER_MAX_THREADS]; } ShadBuf; @@ -345,7 +345,7 @@ typedef struct ObjectRen { struct RayFace *rayfaces; struct VlakPrimitive *rayprimitives; struct ObjectInstanceRen *rayobi; - + } ObjectRen; typedef struct ObjectInstanceRen { @@ -365,12 +365,12 @@ typedef struct ObjectInstanceRen { float dupliorco[3], dupliuv[2]; float (*duplitexmat)[4]; - + struct VolumePrecache *volume_precache; - + float *vectors; /* (RE_WINSPEED_ELEMS * VertRen.index) */ int totvector; - + /* used on makeraytree */ struct RayObject *raytree; int transform_primitives; @@ -485,9 +485,9 @@ typedef struct StrandBuffer { int overrideuv; int flag, maxdepth; float adaptcos, minwidth, widthfade; - + float maxwidth; /* for cliptest of strands in blender unit */ - + float winmat[4][4]; int winx, winy; } StrandBuffer; @@ -559,7 +559,7 @@ typedef struct LampShadowSample { typedef struct LampRen { struct LampRen *next, *prev; - + float xs, ys, dist; float co[3]; short type; @@ -572,7 +572,7 @@ typedef struct LampRen { float vec[3]; float xsp, ysp, distkw, inpr; float halokw, halo; - + short falloff_type; float ld1, ld2; float coeff_const, coeff_lin, coeff_quad; @@ -601,7 +601,7 @@ typedef struct LampRen { float bias; /* Compression threshold for deep shadow maps */ float compressthresh; - + short ray_samp, ray_sampy, ray_sampz, ray_samp_method, ray_samp_type, area_shape, ray_totsamp; short xold[BLENDER_MAX_THREADS], yold[BLENDER_MAX_THREADS]; /* last jitter table for area lights */ float area_size, area_sizey, area_sizez; @@ -609,10 +609,10 @@ typedef struct LampRen { /* sun/sky */ struct SunSky *sunsky; - + struct ShadBuf *shb; float *jitter; - + float imat[3][3]; float spottexfac; float sh_invcampos[3], sh_zfac; /* sh_= spothalo */ @@ -621,13 +621,13 @@ typedef struct LampRen { float mat[3][3]; /* 3x3 part from lampmat x viewmat */ float area[8][3], areasize; - + /* passes & node shader support: all shadow info for a pixel */ LampShadowSample *shadsamp; - + /* ray optim */ struct RayObject *last_hit[BLENDER_MAX_THREADS]; - + struct MTex *mtex[MAX_MTEX]; /* threading */ @@ -658,9 +658,9 @@ typedef struct LampRen { #define R_FULL_OSA 8 #define R_FACE_SPLIT 16 /* Tells render to divide face other way. */ -#define R_DIVIDE_24 32 +#define R_DIVIDE_24 32 /* vertex normals are tangent or view-corrected vector, for hair strands */ -#define R_TANGENT 64 +#define R_TANGENT 64 #define R_TRACEBLE 128 /* vlakren->freestyle_edge_mark */ diff --git a/source/blender/render/intern/include/rendercore.h b/source/blender/render/intern/include/rendercore.h index f4c4a50ac27..aa3efca9e5b 100644 --- a/source/blender/render/intern/include/rendercore.h +++ b/source/blender/render/intern/include/rendercore.h @@ -26,7 +26,7 @@ */ #ifndef __RENDERCORE_H__ -#define __RENDERCORE_H__ +#define __RENDERCORE_H__ /** \file blender/render/intern/include/rendercore.h * \ingroup render diff --git a/source/blender/render/intern/include/shading.h b/source/blender/render/intern/include/shading.h index 3ef6e9d7476..e306c3c075c 100644 --- a/source/blender/render/intern/include/shading.h +++ b/source/blender/render/intern/include/shading.h @@ -44,9 +44,9 @@ struct Isect; /* needed to calculate shadow and AO for an entire pixel */ typedef struct ShadeSample { int tot; /* amount of shi in use, can be 1 for not FULL_OSA */ - + RenderLayer *rlpp[RE_MAX_OSA]; /* fast lookup from sample to renderlayer (fullsample buf) */ - + /* could be malloced once */ ShadeInput shi[RE_MAX_OSA]; ShadeResult shr[RE_MAX_OSA]; diff --git a/source/blender/render/intern/include/strand.h b/source/blender/render/intern/include/strand.h index 5687ef3c837..f4e22c78b42 100644 --- a/source/blender/render/intern/include/strand.h +++ b/source/blender/render/intern/include/strand.h @@ -26,7 +26,7 @@ #ifndef __STRAND_H__ -#define __STRAND_H__ +#define __STRAND_H__ struct StrandVert; struct StrandRen; diff --git a/source/blender/render/intern/include/sunsky.h b/source/blender/render/intern/include/sunsky.h index 53151ca17ac..c608f9fc48c 100644 --- a/source/blender/render/intern/include/sunsky.h +++ b/source/blender/render/intern/include/sunsky.h @@ -51,7 +51,7 @@ typedef struct SunSky { float backscattered_light; float skyblendfac; float sky_exposure; - + float atm_HGg; float atm_SunIntensity; diff --git a/source/blender/render/intern/include/texture_ocean.h b/source/blender/render/intern/include/texture_ocean.h index 4a71aff930a..6d7bc6fe7b0 100644 --- a/source/blender/render/intern/include/texture_ocean.h +++ b/source/blender/render/intern/include/texture_ocean.h @@ -1,4 +1,4 @@ -/* +/* * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or diff --git a/source/blender/render/intern/include/voxeldata.h b/source/blender/render/intern/include/voxeldata.h index dd2262e0357..041ca78a799 100644 --- a/source/blender/render/intern/include/voxeldata.h +++ b/source/blender/render/intern/include/voxeldata.h @@ -30,7 +30,7 @@ */ #ifndef __VOXELDATA_H__ -#define __VOXELDATA_H__ +#define __VOXELDATA_H__ struct Render; struct TexResult; diff --git a/source/blender/render/intern/include/zbuf.h b/source/blender/render/intern/include/zbuf.h index eb1af7ad89c..95c78e6d614 100644 --- a/source/blender/render/intern/include/zbuf.h +++ b/source/blender/render/intern/include/zbuf.h @@ -87,13 +87,13 @@ typedef struct APixstrMain { /* span fill in method, is also used to localize data for zbuffering */ typedef struct ZSpan { int rectx, recty; /* range for clipping */ - + int miny1, maxy1, miny2, maxy2; /* actual filled in range */ const float *minp1, *maxp1, *minp2, *maxp2; /* vertex pointers detect min/max range in */ float *span1, *span2; - + float zmulx, zmuly, zofsx, zofsy; /* transform from hoco to zbuf co */ - + int *rectz, *arectz; /* zbuffers, arectz is for transparent */ int *rectz1; /* secondary z buffer for shadowbuffer (2nd closest z) */ int *rectp; /* polygon index buffer */ @@ -102,7 +102,7 @@ typedef struct ZSpan { APixstr *apixbuf, *curpstr; /* apixbuf for transparent */ APixstrand *curpstrand; /* same for strands */ struct ListBase *apsmbase; - + int polygon_offset; /* offset in Z */ float shad_alpha; /* copy from material, used by irregular shadbuf */ int mask, apsmcounter; /* in use by apixbuf */ @@ -112,10 +112,10 @@ typedef struct ZSpan { void *sss_handle; /* used by sss */ void (*sss_func)(void *, int, int, int, int, int); - + void (*zbuffunc)(struct ZSpan *, int, int, const float *, const float *, const float *, const float *); void (*zbuflinefunc)(struct ZSpan *, int, int, const float *, const float *); - + } ZSpan; /* exported to shadbuf.c */ diff --git a/source/blender/render/intern/raytrace/bvh.h b/source/blender/render/intern/raytrace/bvh.h index e6e88714692..0f9a506762b 100644 --- a/source/blender/render/intern/raytrace/bvh.h +++ b/source/blender/render/intern/raytrace/bvh.h @@ -65,7 +65,7 @@ inline int test_bb_group4(__m128 *bb_group, const Isect *isec) const __m128 tmax2 = _mm_min_ps(tmax1, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[3]], _mm_set_ps1(start[1]) ), _mm_set_ps1(idot_axis[1])) ); const __m128 tmin3 = _mm_max_ps(tmin2, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[4]], _mm_set_ps1(start[2]) ), _mm_set_ps1(idot_axis[2])) ); const __m128 tmax3 = _mm_min_ps(tmax2, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[5]], _mm_set_ps1(start[2]) ), _mm_set_ps1(idot_axis[2])) ); - + return _mm_movemask_ps(_mm_cmpge_ps(tmax3, tmin3)); } #endif @@ -78,7 +78,7 @@ inline int test_bb_group4(__m128 *bb_group, const Isect *isec) static inline int rayobject_bb_intersect_test(const Isect *isec, const float *_bb) { const float *bb = _bb; - + float t1x = (bb[isec->bv_index[0]] - isec->start[0]) * isec->idot_axis[0]; float t2x = (bb[isec->bv_index[1]] - isec->start[0]) * isec->idot_axis[0]; float t1y = (bb[isec->bv_index[2]] - isec->start[1]) * isec->idot_axis[1]; @@ -87,7 +87,7 @@ static inline int rayobject_bb_intersect_test(const Isect *isec, const float *_b float t2z = (bb[isec->bv_index[5]] - isec->start[2]) * isec->idot_axis[2]; RE_RC_COUNT(isec->raycounter->bb.test); - + if (t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return 0; if (t2x < 0.0f || t2y < 0.0f || t2z < 0.0f) return 0; if (t1x > isec->dist || t1y > isec->dist || t1z > isec->dist) return 0; @@ -170,7 +170,7 @@ static int bvh_node_stack_raycast(Node *root, Isect *isec) { Node *stack[MAX_STACK_SIZE]; int hit = 0, stack_pos = 0; - + if (!TEST_ROOT && !is_leaf(root)) bvh_node_push_childs(root, isec, stack, stack_pos); else @@ -205,7 +205,7 @@ static int bvh_node_stack_raycast_simd(Node *root, Isect *isec) Node *stack[MAX_STACK_SIZE]; int hit = 0, stack_pos = 0; - + if (!TEST_ROOT) { if (!is_leaf(root)) { if (!is_leaf(root->child)) @@ -228,7 +228,7 @@ static int bvh_node_stack_raycast_simd(Node *root, Isect *isec) if (stack_pos >= 4) { __m128 t_bb[6]; Node *t_node[4]; - + stack_pos -= 4; /* prepare the 4BB for SIMD */ @@ -261,7 +261,7 @@ static int bvh_node_stack_raycast_simd(Node *root, Isect *isec) { Node *t = stack[stack_pos + i]; assert(!is_leaf(t)); - + float *bb = ((float *)t_bb) + i; bb[4 * 0] = t->bb[0]; bb[4 * 1] = t->bb[1]; @@ -293,7 +293,7 @@ static int bvh_node_stack_raycast_simd(Node *root, Isect *isec) else if (stack_pos > 0) { Node *node = stack[--stack_pos]; assert(!is_leaf(node)); - + if (bvh_node_hit_test(node, isec)) { if (!is_leaf(node->child)) { bvh_node_push_childs(node, isec, stack, stack_pos); @@ -328,7 +328,7 @@ static int bvh_node_raycast(Node *node, Isect *isec) if (!is_leaf(node->child[i])) { if (node->child[i] == 0) break; - + hit |= bvh_node_raycast(node->child[i], isec); if (hit && isec->mode == RE_RAY_SHADOW) return hit; } @@ -362,7 +362,7 @@ template static void bvh_dfs_make_hint(Node *node, LCTSHint *hint, int reserve_space, HintObject *hintObject) { assert(hint->size + reserve_space + 1 <= RE_RAY_LCTS_MAX_SIZE); - + if (is_leaf(node)) { hint->stack[hint->size++] = (RayObject *)node; } @@ -394,13 +394,13 @@ static inline RayObject *bvh_create_tree(int size) { Tree *obj = (Tree *)MEM_callocN(sizeof(Tree), "BVHTree"); assert(RE_rayobject_isAligned(obj)); /* RayObject API assumes real data to be 4-byte aligned */ - + obj->rayobj.api = bvh_get_api(DFS_STACK_SIZE); obj->root = NULL; - + obj->node_arena = NULL; obj->builder = rtbuild_create(size); - + return RE_rayobject_unalignRayAPI((RayObject *) obj); } diff --git a/source/blender/render/intern/raytrace/rayobject.cpp b/source/blender/render/intern/raytrace/rayobject.cpp index 04dc8505e70..fee877b311d 100644 --- a/source/blender/render/intern/raytrace/rayobject.cpp +++ b/source/blender/render/intern/raytrace/rayobject.cpp @@ -268,11 +268,11 @@ MALWAYS_INLINE int intersect_rayface(RayObject *hit_obj, RayFace *face, Isect *i { float dist, uv[2]; int ok = 0; - + /* avoid self-intersection */ if (is->orig.ob == face->ob && is->orig.face == face->face) return 0; - + /* check if we should intersect this face */ if (is->check == RE_CHECK_VLR_RENDER) { if (vlr_check_intersect(is, (ObjectInstanceRen *)face->ob, (VlakRen *)face->face) == 0) @@ -296,7 +296,7 @@ MALWAYS_INLINE int intersect_rayface(RayObject *hit_obj, RayFace *face, Isect *i ok = isec_tri_quad(is->start, &is->isect_precalc, face, uv, &dist); if (ok) { - + /* when a shadow ray leaves a face, it can be little outside the edges * of it, causing intersection to be detected in its neighbor face */ if (is->skip & RE_SKIP_VLR_NEIGHBOUR) { @@ -373,19 +373,19 @@ int RE_rayobject_raycast(RayObject *r, Isect *isec) /* setup vars used on raycast */ for (i = 0; i < 3; i++) { isec->idot_axis[i] = 1.0f / isec->dir[i]; - + isec->bv_index[2 * i] = isec->idot_axis[i] < 0.0f ? 1 : 0; isec->bv_index[2 * i + 1] = 1 - isec->bv_index[2 * i]; - + isec->bv_index[2 * i] = i + 3 * isec->bv_index[2 * i]; isec->bv_index[2 * i + 1] = i + 3 * isec->bv_index[2 * i + 1]; } -#ifdef RT_USE_LAST_HIT +#ifdef RT_USE_LAST_HIT /* last hit heuristic */ if (isec->mode == RE_RAY_SHADOW && isec->last_hit) { RE_RC_COUNT(isec->raycounter->rayshadow_last_hit.test); - + if (RE_rayobject_intersect(isec->last_hit, isec)) { RE_RC_COUNT(isec->raycounter->raycast.hit); RE_RC_COUNT(isec->raycounter->rayshadow_last_hit.hit); @@ -474,7 +474,7 @@ void RE_rayobject_merge_bb(RayObject *r, float min[3], float max[3]) { if (RE_rayobject_isRayFace(r)) { RayFace *face = (RayFace *) RE_rayobject_align(r); - + DO_MINMAX(face->v1, min, max); DO_MINMAX(face->v2, min, max); DO_MINMAX(face->v3, min, max); diff --git a/source/blender/render/intern/raytrace/rayobject_hint.h b/source/blender/render/intern/raytrace/rayobject_hint.h index b8cd186612b..88a32819bd2 100644 --- a/source/blender/render/intern/raytrace/rayobject_hint.h +++ b/source/blender/render/intern/raytrace/rayobject_hint.h @@ -64,7 +64,7 @@ inline int hint_test_bb(HintFrustum &obj, float *Nmin, float *Nmax) { return HINT_DISCARD; } - + return HINT_ACCEPT; } #endif diff --git a/source/blender/render/intern/raytrace/rayobject_instance.cpp b/source/blender/render/intern/raytrace/rayobject_instance.cpp index 9a8c1957894..361e7963d96 100644 --- a/source/blender/render/intern/raytrace/rayobject_instance.cpp +++ b/source/blender/render/intern/raytrace/rayobject_instance.cpp @@ -68,10 +68,10 @@ typedef struct InstanceRayObject { void *ob; //Object represented by this instance void *target_ob; //Object represented by the inner RayObject, needed to handle self-intersection - + float global2target[4][4]; float target2global[4][4]; - + } InstanceRayObject; diff --git a/source/blender/render/intern/raytrace/rayobject_octree.cpp b/source/blender/render/intern/raytrace/rayobject_octree.cpp index a45b3989e7b..4b73e64ca45 100644 --- a/source/blender/render/intern/raytrace/rayobject_octree.cpp +++ b/source/blender/render/intern/raytrace/rayobject_octree.cpp @@ -77,11 +77,11 @@ typedef struct Octree { int branchcount, nodecount; /* during building only */ - char *ocface; - + char *ocface; + RayFace **ro_nodes; int ro_nodes_size, ro_nodes_used; - + } Octree; static int RE_rayobject_octree_intersect(RayObject *o, Isect *isec); @@ -126,7 +126,7 @@ static void calc_ocval_face(float *v1, float *v2, float *v3, float *v4, short x, { float min[3], max[3]; int ocmin, ocmax; - + copy_v3_v3(min, v1); copy_v3_v3(max, v1); DO_MINMAX(v2, min, max); @@ -134,7 +134,7 @@ static void calc_ocval_face(float *v1, float *v2, float *v3, float *v4, short x, if (v4) { DO_MINMAX(v4, min, max); } - + ocmin = OCVALRES * (min[0] - x); ocmax = OCVALRES * (max[0] - x); ov->ocx = BROW16(ocmin, ocmax); @@ -152,7 +152,7 @@ static void calc_ocval_face(float *v1, float *v2, float *v3, float *v4, short x, static void calc_ocval_ray(OcVal *ov, float xo, float yo, float zo, float *vec1, float *vec2) { int ocmin, ocmax; - + if (vec1[0] < vec2[0]) { ocmin = OCVALRES * (vec1[0] - xo); ocmax = OCVALRES * (vec2[0] - xo); @@ -189,12 +189,12 @@ static void calc_ocval_ray(OcVal *ov, float xo, float yo, float zo, float *vec1, static Branch *addbranch(Octree *oc, Branch *br, short ocb) { int index; - + if (br->b[ocb]) return br->b[ocb]; - + oc->branchcount++; index = oc->branchcount >> 12; - + if (oc->adrbranch[index] == NULL) oc->adrbranch[index] = (Branch *)MEM_callocN(4096 * sizeof(Branch), "new oc branch"); @@ -202,17 +202,17 @@ static Branch *addbranch(Octree *oc, Branch *br, short ocb) printf("error; octree branches full\n"); oc->branchcount = 0; } - + return br->b[ocb] = oc->adrbranch[index] + (oc->branchcount & 4095); } static Node *addnode(Octree *oc) { int index; - + oc->nodecount++; index = oc->nodecount >> 12; - + if (oc->adrnode[index] == NULL) oc->adrnode[index] = (Node *)MEM_callocN(4096 * sizeof(Node), "addnode"); @@ -220,7 +220,7 @@ static Node *addnode(Octree *oc) printf("error; octree nodes full\n"); oc->nodecount = 0; } - + return oc->adrnode[index] + (oc->nodecount & 4095); } @@ -228,14 +228,14 @@ static bool face_in_node(RayFace *face, short x, short y, short z, float rtf[4][ { static float nor[3], d; float fx, fy, fz; - - // init static vars + + // init static vars if (face) { normal_tri_v3(nor, rtf[0], rtf[1], rtf[2]); d = -nor[0] * rtf[0][0] - nor[1] * rtf[0][1] - nor[2] * rtf[0][2]; return 0; } - + fx = x; fy = y; fz = z; @@ -260,7 +260,7 @@ static bool face_in_node(RayFace *face, short x, short y, short z, float rtf[4][ if ((fx ) * nor[0] + (fy + 1) * nor[1] + (fz + 1) * nor[2] + d > 0.0f) return 1; if ((fx + 1) * nor[0] + (fy + 1) * nor[1] + (fz + 1) * nor[2] + d > 0.0f) return 1; } - + return 0; } @@ -313,9 +313,9 @@ static void ocwrite(Octree *oc, RayFace *face, int quad, short x, short y, short else { while (no->v[a] != NULL) a++; } - + no->v[a] = (RayFace *) RE_rayobject_align(face); - + if (quad) calc_ocval_face(rtf[0], rtf[1], rtf[2], rtf[3], x >> 2, y >> 1, z, &no->ov[a]); else @@ -377,19 +377,19 @@ static void d2dda(Octree *oc, short b1, short b2, short c1, short c2, char *ocfa lambda_y = 1.0f; ldy = 0; } - + x = ocx1; y = ocy1; lambda = MIN2(lambda_x, lambda_y); - + while (true) { - + if (x < 0 || y < 0 || x >= oc->ocres || y >= oc->ocres) { /* pass*/ } else { ocface[oc->ocres * x + y] = 1; } - + lambda_o = lambda; if (lambda_x == lambda_y) { lambda_x += ldx; @@ -460,7 +460,7 @@ static void RE_rayobject_octree_free(RayObject *tree) oc->adrbranch = NULL; } oc->branchcount = 0; - + if (oc->adrnode) { int a = 0; while (oc->adrnode[a]) { @@ -481,16 +481,16 @@ RayObject *RE_rayobject_octree_create(int ocres, int size) { Octree *oc = (Octree *)MEM_callocN(sizeof(Octree), "Octree"); assert(RE_rayobject_isAligned(oc) ); /* RayObject API assumes real data to be 4-byte aligned */ - + oc->rayobj.api = &octree_api; - + oc->ocres = ocres; - + oc->ro_nodes = (RayFace **)MEM_callocN(sizeof(RayFace *) * size, "octree rayobject nodes"); oc->ro_nodes_size = size; oc->ro_nodes_used = 0; - + return RE_rayobject_unalignRayAPI((RayObject *) oc); } @@ -537,7 +537,7 @@ static void octree_fill_rayface(Octree *oc, RayFace *face) rts[3][c] = (short)rtf[3][c]; } } - + for (c = 0; c < 3; c++) { oc1 = rts[0][c]; oc2 = rts[1][c]; @@ -554,12 +554,12 @@ static void octree_fill_rayface(Octree *oc, RayFace *face) if (ocmax[c] > oc->ocres - 1) ocmax[c] = oc->ocres - 1; if (ocmin[c] < 0) ocmin[c] = 0; } - + if (ocmin[0] == ocmax[0] && ocmin[1] == ocmax[1] && ocmin[2] == ocmax[2]) { ocwrite(oc, face, RE_rayface_isQuad(face), ocmin[0], ocmin[1], ocmin[2], rtf); } else { - + d2dda(oc, 0, 1, 0, 1, ocface + ocres2, rts, rtf); d2dda(oc, 0, 1, 0, 2, ocface, rts, rtf); d2dda(oc, 0, 1, 1, 2, ocface + 2 * ocres2, rts, rtf); @@ -583,10 +583,10 @@ static void octree_fill_rayface(Octree *oc, RayFace *face) filltriangle(oc, 0, 1, ocface + ocres2, ocmin, ocmax); filltriangle(oc, 0, 2, ocface, ocmin, ocmax); filltriangle(oc, 1, 2, ocface + 2 * ocres2, ocmin, ocmax); - + /* init static vars here */ face_in_node(face, 0, 0, 0, rtf); - + for (x = ocmin[0]; x <= ocmax[0]; x++) { a = oc->ocres * x; for (y = ocmin[1]; y <= ocmax[1]; y++) { @@ -601,7 +601,7 @@ static void octree_fill_rayface(Octree *oc, RayFace *face) } } } - + /* same loops to clear octree, doubt it can be done smarter */ for (x = ocmin[0]; x <= ocmax[0]; x++) { a = oc->ocres * x; @@ -627,19 +627,19 @@ static void RE_rayobject_octree_done(RayObject *tree) int c; float t00, t01, t02; int ocres2 = oc->ocres * oc->ocres; - + INIT_MINMAX(oc->min, oc->max); - + /* Calculate Bounding Box */ for (c = 0; c < oc->ro_nodes_used; c++) RE_rayobject_merge_bb(RE_rayobject_unalignRayFace(oc->ro_nodes[c]), oc->min, oc->max); - + /* Alloc memory */ oc->adrbranch = (Branch **)MEM_callocN(sizeof(void *) * BRANCH_ARRAY, "octree branches"); oc->adrnode = (Node **)MEM_callocN(sizeof(void *) * NODE_ARRAY, "octree nodes"); - + oc->adrbranch[0] = (Branch *)MEM_callocN(4096 * sizeof(Branch), "makeoctree"); - + /* the lookup table, per face, for which nodes to fill in */ oc->ocface = (char *)MEM_callocN(3 * ocres2 + 8, "ocface"); memset(oc->ocface, 0, 3 * ocres2); @@ -652,12 +652,12 @@ static void RE_rayobject_octree_done(RayObject *tree) t00 = oc->max[0] - oc->min[0]; t01 = oc->max[1] - oc->min[1]; t02 = oc->max[2] - oc->min[2]; - + /* this minus 0.1 is old safety... seems to be needed? */ oc->ocfacx = (oc->ocres - 0.1f) / t00; oc->ocfacy = (oc->ocres - 0.1f) / t01; oc->ocfacz = (oc->ocres - 0.1f) / t02; - + oc->ocsize = sqrtf(t00 * t00 + t01 * t01 + t02 * t02); /* global, max size octree */ for (c = 0; c < oc->ro_nodes_used; c++) { @@ -690,7 +690,7 @@ static int testnode(Octree *UNUSED(oc), Isect *is, Node *no, OcVal ocval) /* return on any first hit */ if (is->mode == RE_RAY_SHADOW) { - + for (; no; no = no->next) { for (nr = 0; nr < 8; nr++) { RayFace *face = no->v[nr]; @@ -708,7 +708,7 @@ static int testnode(Octree *UNUSED(oc), Isect *is, Node *no, OcVal ocval) else { /* else mirror or glass or shadowtra, return closest face */ int found = 0; - + for (; no; no = no->next) { for (nr = 0; nr < 8; nr++) { RayFace *face = no->v[nr]; @@ -723,7 +723,7 @@ static int testnode(Octree *UNUSED(oc), Isect *is, Node *no, OcVal ocval) } } } - + return found; } @@ -735,12 +735,12 @@ static Node *ocread(Octree *oc, int x, int y, int z) { Branch *br; int oc1; - + x <<= 2; y <<= 1; - + br = oc->adrbranch[0]; - + if (oc->ocres == 512) { oc1 = ((x & 1024) + (y & 512) + (z & 256)) >> 8; br = br->b[oc1]; @@ -762,7 +762,7 @@ static Node *ocread(Octree *oc, int x, int y, int z) return NULL; } } - + oc1 = ((x & 128) + (y & 64) + (z & 32)) >> 5; br = br->b[oc1]; if (br) { @@ -785,7 +785,7 @@ static Node *ocread(Octree *oc, int x, int y, int z) } } } - + return NULL; } @@ -817,26 +817,26 @@ static int cliptest(float p, float q, float *u1, float *u2) /* extensive coherence checks/storage cancels out the benefit of it, and gives errors... we * need better methods, sample code commented out below (ton) */ - + #if 0 in top : static int coh_nodes[16 * 16 * 16][6]; in makeoctree : memset(coh_nodes, 0, sizeof(coh_nodes)); - + static void add_coherence_test(int ocx1, int ocx2, int ocy1, int ocy2, int ocz1, int ocz2) { short *sp; - + sp = coh_nodes[(ocx2 & 15) + 16 * (ocy2 & 15) + 256 * (ocz2 & 15)]; sp[0] = ocx1; sp[1] = ocy1; sp[2] = ocz1; sp[3] = ocx2; sp[4] = ocy2; sp[5] = ocz2; - + } static int do_coherence_test(int ocx1, int ocx2, int ocy1, int ocy2, int ocz1, int ocz2) { short *sp; - + sp = coh_nodes[(ocx2 & 15) + 16 * (ocy2 & 15) + 256 * (ocz2 & 15)]; if (sp[0] == ocx1 && sp[1] == ocy1 && sp[2] == ocz1 && sp[3] == ocx2 && sp[4] == ocy2 && sp[5] == ocz2) return 1; @@ -859,10 +859,10 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) int dx, dy, dz; int xo, yo, zo, c1 = 0; int ocx1, ocx2, ocy1, ocy2, ocz1, ocz2; - + /* clip with octree */ if (oc->branchcount == 0) return 0; - + /* do this before intersect calls */ #if 0 is->facecontr = NULL; /* to check shared edge */ @@ -877,7 +877,7 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) o_lambda = is->dist; u1 = 0.0f; u2 = 1.0f; - + /* clip with octree cube */ if (cliptest(-ldx, start[0] - oc->min[0], &u1, &u2)) { if (cliptest(ldx, oc->max[0] - start[0], &u1, &u2)) { @@ -925,7 +925,7 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) ocx2 = (int)ox2; ocy2 = (int)oy2; ocz2 = (int)oz2; - + if (ocx1 == ocx2 && ocy1 == ocy2 && ocz1 == ocz2) { no = ocread(oc, ocx1, ocy1, ocz1); if (no) { @@ -941,7 +941,7 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) //static int coh_ocx1, coh_ocx2, coh_ocy1, coh_ocy2, coh_ocz1, coh_ocz2; float dox, doy, doz; int eqval; - + /* calc lambda en ld */ dox = ox1 - ox2; doy = oy1 - oy2; @@ -994,14 +994,14 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) ldz = 0; dz = 0; } - + xo = ocx1; yo = ocy1; zo = ocz1; dda_lambda = min_fff(lambda_x, lambda_y, lambda_z); - + vec2[0] = ox1; vec2[1] = oy1; vec2[2] = oz1; - + /* this loop has been constructed to make sure the first and last node of ray * are always included, even when dda_lambda==1.0f or larger */ @@ -1009,7 +1009,7 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) no = ocread(oc, xo, yo, zo); if (no) { - + /* calculate ray intersection with octree node */ copy_v3_v3(vec1, vec2); // dox, y, z is negative @@ -1028,7 +1028,7 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) lambda_o = dda_lambda; - + /* traversing octree nodes need careful detection of smallest values, with proper * exceptions for equal lambdas */ eqval = (lambda_x == lambda_y); @@ -1073,7 +1073,7 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) eqval = (lambda_x < lambda_y); if (lambda_y < lambda_z) eqval += 2; if (lambda_x < lambda_z) eqval += 4; - + if (eqval == 7 || eqval == 5) { // x smallest xo += dx; lambda_x += ldx; } @@ -1083,7 +1083,7 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) else { // z smallest zo += dz; lambda_z += ldz; } - + } dda_lambda = min_fff(lambda_x, lambda_y, lambda_z); @@ -1092,10 +1092,10 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) if (lambda_o >= 1.0f) break; } } - + /* reached end, no intersections found */ return 0; -} +} diff --git a/source/blender/render/intern/raytrace/rayobject_qbvh.cpp b/source/blender/render/intern/raytrace/rayobject_qbvh.cpp index 712613506e5..8e3dd87efd1 100644 --- a/source/blender/render/intern/raytrace/rayobject_qbvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_qbvh.cpp @@ -57,7 +57,7 @@ template<> void bvh_done(QBVHTree *obj) { rtbuild_done(obj->builder, &obj->rayobj.control); - + //TODO find a away to exactly calculate the needed memory MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "qbvh arena"); BLI_memarena_use_malloc(arena1); @@ -75,17 +75,17 @@ void bvh_done(QBVHTree *obj) BLI_memarena_free(arena2); return; } - + if (root) { pushup_simd(root); obj->root = Reorganize_SVBVH(arena2).transform(root); } else obj->root = NULL; - + //Free data BLI_memarena_free(arena1); - + obj->node_arena = arena2; obj->cost = 1.0; @@ -120,7 +120,7 @@ static void bvh_hint_bb(Tree *tree, LCTSHint *hint, float *UNUSED(min), float *U template static RayObjectAPI make_api() { - static RayObjectAPI api = + static RayObjectAPI api = { (RE_rayobject_raycast_callback) ((int (*)(Tree *, Isect *)) & intersect), (RE_rayobject_add_callback) ((void (*)(Tree *, RayObject *)) & bvh_add), @@ -130,7 +130,7 @@ static RayObjectAPI make_api() (RE_rayobject_cost_callback) ((float (*)(Tree *)) & bvh_cost), (RE_rayobject_hint_bb_callback) ((void (*)(Tree *, LCTSHint *, float *, float *)) & bvh_hint_bb) }; - + return api; } @@ -138,7 +138,7 @@ template RayObjectAPI *bvh_get_api(int maxstacksize) { static RayObjectAPI bvh_api256 = make_api(); - + if (maxstacksize <= 1024) return &bvh_api256; assert(maxstacksize <= 256); return NULL; diff --git a/source/blender/render/intern/raytrace/rayobject_raycounter.cpp b/source/blender/render/intern/raytrace/rayobject_raycounter.cpp index 21161e63512..429c47f1c0f 100644 --- a/source/blender/render/intern/raytrace/rayobject_raycounter.cpp +++ b/source/blender/render/intern/raytrace/rayobject_raycounter.cpp @@ -80,7 +80,7 @@ void RE_RC_MERGE(RayCounter *dest, RayCounter *tmp) dest->raycast.test += tmp->raycast.test; dest->raycast.hit += tmp->raycast.hit; - + dest->rayshadow_last_hit.test += tmp->rayshadow_last_hit.test; dest->rayshadow_last_hit.hit += tmp->rayshadow_last_hit.hit; diff --git a/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp b/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp index a7402605301..51f89784674 100644 --- a/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp +++ b/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp @@ -60,13 +60,13 @@ static void rtbuild_init(RTBuilder *b) b->primitives.end = NULL; b->primitives.maxsize = 0; b->depth = 0; - + for (int i = 0; i < RTBUILD_MAX_CHILDS; i++) b->child_offset[i] = 0; for (int i = 0; i < 3; i++) b->sorted_begin[i] = b->sorted_end[i] = NULL; - + INIT_MINMAX(b->bb, b->bb + 3); } @@ -77,15 +77,15 @@ RTBuilder *rtbuild_create(int size) rtbuild_init(builder); - + builder->primitives.begin = builder->primitives.end = memblock; builder->primitives.maxsize = size; - + for (int i = 0; i < 3; i++) { builder->sorted_begin[i] = (RTBuilder::Object **)MEM_mallocN(sizeof(RTBuilder::Object *) * size, "RTBuilder.sorted_objects"); builder->sorted_end[i] = builder->sorted_begin[i]; } - + return builder; } @@ -124,12 +124,12 @@ void rtbuild_add(RTBuilder *b, RayObject *o) * will give problems in rtbuild_heuristic_object_split later */ if (bb[0] == bb[3] && bb[1] == bb[4] && bb[2] == bb[5]) return; - + copy_v3_v3(b->primitives.end->bb, bb); copy_v3_v3(b->primitives.end->bb + 3, bb + 3); b->primitives.end->obj = o; b->primitives.end->cost = RE_rayobject_cost(o); - + for (int i = 0; i < 3; i++) { *(b->sorted_end[i]) = b->primitives.end; b->sorted_end[i]++; @@ -190,7 +190,7 @@ RTBuilder *rtbuild_get_child(RTBuilder *b, int child, RTBuilder *tmp) tmp->sorted_begin[i] = NULL; tmp->sorted_end[i] = NULL; } - + return tmp; } @@ -227,17 +227,17 @@ int rtbuild_mean_split(RTBuilder *b, int nchilds, int axis) long long s; assert(nchilds <= RTBUILD_MAX_CHILDS); - + //TODO optimize calc of leafs_per_child for (s = nchilds; s < tot_leafs; s *= nchilds) ; Mleafs_per_child = s / nchilds; mleafs_per_child = Mleafs_per_child / nchilds; - + //split min leafs per child b->child_offset[0] = 0; for (i = 1; i <= nchilds; i++) b->child_offset[i] = mleafs_per_child; - + //split remaining leafs missing_leafs = tot_leafs - mleafs_per_child * nchilds; for (i = 1; i <= nchilds; i++) @@ -253,7 +253,7 @@ int rtbuild_mean_split(RTBuilder *b, int nchilds, int axis) break; } } - + //adjust for accumulative offsets for (i = 1; i <= nchilds; i++) b->child_offset[i] += b->child_offset[i - 1]; @@ -261,12 +261,12 @@ int rtbuild_mean_split(RTBuilder *b, int nchilds, int axis) //Count created childs for (i = nchilds; b->child_offset[i] == b->child_offset[i - 1]; i--) ; split_leafs(b, b->child_offset, i, axis); - + assert(b->child_offset[0] == 0 && b->child_offset[i] == tot_leafs); return i; } - - + + int rtbuild_mean_split_largest_axis(RTBuilder *b, int nchilds) { int axis = rtbuild_get_largest_axis(b); @@ -282,7 +282,7 @@ int rtbuild_mean_split_largest_axis(RTBuilder *b, int nchilds) int rtbuild_median_split(RTBuilder *b, float *separators, int nchilds, int axis) { int size = rtbuild_size(b); - + assert(nchilds <= RTBUILD_MAX_CHILDS); if (size <= nchilds) { @@ -292,17 +292,17 @@ int rtbuild_median_split(RTBuilder *b, float *separators, int nchilds, int axis) int i; b->split_axis = axis; - + //Calculate child offsets b->child_offset[0] = 0; for (i = 0; i < nchilds - 1; i++) b->child_offset[i + 1] = split_leafs_by_plane(b, b->child_offset[i], size, separators[i]); b->child_offset[nchilds] = size; - + for (i = 0; i < nchilds; i++) if (b->child_offset[i + 1] - b->child_offset[i] == size) return rtbuild_mean_split(b, nchilds, axis); - + return nchilds; } } @@ -311,13 +311,13 @@ int rtbuild_median_split_largest_axis(RTBuilder *b, int nchilds) { int la, i; float separators[RTBUILD_MAX_CHILDS]; - + rtbuild_calc_bb(b); la = bb_largest_axis(b->bb, b->bb + 3); for (i = 1; i < nchilds; i++) separators[i - 1] = (b->bb[la + 3] - b->bb[la]) * i / nchilds; - + return rtbuild_median_split(b, separators, nchilds, la); } #endif @@ -353,12 +353,12 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds) boffset = size / 2; SweepCost *sweep = (SweepCost *)MEM_mallocN(sizeof(SweepCost) * size, "RTBuilder.HeuristicSweep"); - + for (int axis = 0; axis < 3; axis++) { SweepCost sweep_left; RTBuilder::Object **obj = b->sorted_begin[axis]; - + // float right_cost = 0; for (int i = size - 1; i >= 0; i--) { if (i == size - 1) { @@ -377,7 +377,7 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds) } // right_cost += obj[i]->cost; } - + sweep_left.bb[0] = obj[0]->bb[0]; sweep_left.bb[1] = obj[0]->bb[1]; sweep_left.bb[2] = obj[0]->bb[2]; @@ -385,13 +385,13 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds) sweep_left.bb[4] = obj[0]->bb[4]; sweep_left.bb[5] = obj[0]->bb[5]; sweep_left.cost = obj[0]->cost; - + // right_cost -= obj[0]->cost; if (right_cost < 0) right_cost = 0; for (int i = 1; i < size; i++) { //Worst case heuristic (cost of each child is linear) float hcost, left_side, right_side; - + // not using log seems to have no impact on raytracing perf, but // makes tree construction quicker, left out for now to test (brecht) // left_side = bb_area(sweep_left.bb, sweep_left.bb + 3) * (sweep_left.cost + logf((float)i)); @@ -402,7 +402,7 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds) assert(left_side >= 0); assert(right_side >= 0); - + if (left_side > bcost) break; //No way we can find a better heuristic in this axis assert(hcost >= 0); @@ -418,13 +418,13 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds) sweep_left.cost += obj[i]->cost; // right_cost -= obj[i]->cost; if (right_cost < 0) right_cost = 0; } - + //assert(baxis >= 0 && baxis < 3); if (!(baxis >= 0 && baxis < 3)) baxis = 0; } - - + + MEM_freeN(sweep); } else if (size == 2) { @@ -436,11 +436,11 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds) b->child_offset[1] = 1; return 1; } - + b->child_offset[0] = 0; b->child_offset[1] = boffset; b->child_offset[2] = size; - + /* Adjust sorted arrays for childs */ for (int i = 0; i < boffset; i++) b->sorted_begin[baxis][i]->selected = true; @@ -498,7 +498,7 @@ float bb_area(const float min[3], const float max[3]) int bb_largest_axis(const float min[3], const float max[3]) { float sub[3]; - + sub[0] = max[0] - min[0]; sub[1] = max[1] - min[1]; sub[2] = max[2] - min[2]; diff --git a/source/blender/render/intern/raytrace/rayobject_rtbuild.h b/source/blender/render/intern/raytrace/rayobject_rtbuild.h index d62f853bc63..fc42bc36d92 100644 --- a/source/blender/render/intern/raytrace/rayobject_rtbuild.h +++ b/source/blender/render/intern/raytrace/rayobject_rtbuild.h @@ -60,24 +60,24 @@ typedef struct RTBuilder { float bb[6]; int selected; }; - + /* list to all primitives added in this tree */ struct { Object *begin, *end; int maxsize; } primitives; - + /* sorted list of rayobjects */ struct Object **sorted_begin[3], **sorted_end[3]; /* axis used (if any) on the split method */ int split_axis; - + /* child partitions calculated during splitting */ int child_offset[RTBUILD_MAX_CHILDS + 1]; - + // int child_sorted_axis; /* -1 if not sorted */ - + float bb[6]; /* current depth */ diff --git a/source/blender/render/intern/raytrace/rayobject_svbvh.cpp b/source/blender/render/intern/raytrace/rayobject_svbvh.cpp index 2caaabe7359..fcd692fac02 100644 --- a/source/blender/render/intern/raytrace/rayobject_svbvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_svbvh.cpp @@ -67,7 +67,7 @@ template<> void bvh_done(SVBVHTree *obj) { rtbuild_done(obj->builder, &obj->rayobj.control); - + //TODO find a away to exactly calculate the needed memory MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "svbvh arena"); BLI_memarena_use_malloc(arena1); @@ -85,7 +85,7 @@ void bvh_done(SVBVHTree *obj) BLI_memarena_free(arena2); return; } - + reorganize(root); remove_useless(root, &root); bvh_refit(root); @@ -114,10 +114,10 @@ void bvh_done(SVBVHTree *obj) else obj->root = NULL; } - + //Free data BLI_memarena_free(arena1); - + obj->node_arena = arena2; obj->cost = 1.0; @@ -152,7 +152,7 @@ static void bvh_hint_bb(Tree *tree, LCTSHint *hint, float *UNUSED(min), float *U template static RayObjectAPI make_api() { - static RayObjectAPI api = + static RayObjectAPI api = { (RE_rayobject_raycast_callback) ((int (*)(Tree *, Isect *)) & intersect), (RE_rayobject_add_callback) ((void (*)(Tree *, RayObject *)) & bvh_add), @@ -162,7 +162,7 @@ static RayObjectAPI make_api() (RE_rayobject_cost_callback) ((float (*)(Tree *)) & bvh_cost), (RE_rayobject_hint_bb_callback) ((void (*)(Tree *, LCTSHint *, float *, float *)) & bvh_hint_bb) }; - + return api; } @@ -170,7 +170,7 @@ template static RayObjectAPI *bvh_get_api(int maxstacksize) { static RayObjectAPI bvh_api256 = make_api(); - + if (maxstacksize <= 1024) return &bvh_api256; assert(maxstacksize <= 256); return NULL; diff --git a/source/blender/render/intern/raytrace/rayobject_vbvh.cpp b/source/blender/render/intern/raytrace/rayobject_vbvh.cpp index 55918f1d6f6..b63a11047dd 100644 --- a/source/blender/render/intern/raytrace/rayobject_vbvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_vbvh.cpp @@ -79,11 +79,11 @@ template<> void bvh_done(VBVHTree *obj) { rtbuild_done(obj->builder, &obj->rayobj.control); - + //TODO find a away to exactly calculate the needed memory MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "vbvh arena"); BLI_memarena_use_malloc(arena1); - + //Build and optimize the tree if (1) { VBVHNode *root = BuildBinaryVBVH(arena1, &obj->rayobj.control).transform(obj->builder); @@ -96,7 +96,7 @@ void bvh_done(VBVHTree *obj) reorganize(root); remove_useless(root, &root); bvh_refit(root); - + pushup(root); pushdown(root); obj->root = root; @@ -109,13 +109,13 @@ void bvh_done(VBVHTree *obj) #if 0 MemArena *arena2 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "vbvh arena2"); BLI_memarena_use_malloc(arena2); - + //Finds the optimal packing of this tree using a given cost model //TODO this uses quite a lot of memory, find ways to reduce memory usage during building OVBVHNode *root = BuildBinaryVBVH(arena2).transform(obj->builder); VBVH_optimalPackSIMD(PackCost()).transform(root); obj->root = Reorganize_VBVH(arena1).transform(root); - + BLI_memarena_free(arena2); #endif } @@ -176,7 +176,7 @@ static void bfree(VBVHTree *tree) template static RayObjectAPI make_api() { - static RayObjectAPI api = + static RayObjectAPI api = { (RE_rayobject_raycast_callback) ((int (*)(Tree *, Isect *)) & intersect), (RE_rayobject_add_callback) ((void (*)(Tree *, RayObject *)) & bvh_add), @@ -186,7 +186,7 @@ static RayObjectAPI make_api() (RE_rayobject_cost_callback) ((float (*)(Tree *)) & bvh_cost), (RE_rayobject_hint_bb_callback) ((void (*)(Tree *, LCTSHint *, float *, float *)) & bvh_hint_bb) }; - + return api; } @@ -194,7 +194,7 @@ template RayObjectAPI *bvh_get_api(int maxstacksize) { static RayObjectAPI bvh_api256 = make_api(); - + if (maxstacksize <= 1024) return &bvh_api256; assert(maxstacksize <= 256); return 0; diff --git a/source/blender/render/intern/raytrace/reorganize.h b/source/blender/render/intern/raytrace/reorganize.h index 3f2b4f72f69..3fdd3363edb 100644 --- a/source/blender/render/intern/raytrace/reorganize.h +++ b/source/blender/render/intern/raytrace/reorganize.h @@ -65,11 +65,11 @@ static void reorganize_find_fittest_parent(Node *tree, Node *node, std::pair q; q.push(tree); - + while (!q.empty()) { Node *parent = q.front(); q.pop(); - + if (parent == node) continue; if (node_fits_inside(node, parent) && RE_rayobject_isAligned(parent->child) ) { float pcost = bb_area(parent->bb, parent->bb + 3); @@ -89,7 +89,7 @@ static void reorganize(Node *root) while (!q.empty()) { Node *node = q.front(); q.pop(); - + if (RE_rayobject_isAligned(node->child)) { for (Node **prev = &node->child; *prev; ) { assert(RE_rayobject_isAligned(*prev)); @@ -105,12 +105,12 @@ static void reorganize(Node *root) else { Node *tmp = *prev; *prev = (*prev)->sibling; - + tmp->sibling = best.second->child; best.second->child = tmp; } - - + + } } if (node != root) { @@ -156,7 +156,7 @@ template static void pushup(Node *parent) { if (is_leaf(parent)) return; - + float p_area = bb_area(parent->bb, parent->bb + 3); Node **prev = &parent->child; for (Node *child = parent->child; RE_rayobject_isAligned(child) && child; ) { @@ -180,7 +180,7 @@ static void pushup(Node *parent) child = *prev; } } - + for (Node *child = parent->child; RE_rayobject_isAligned(child) && child; child = child->sibling) pushup(child); } @@ -192,9 +192,9 @@ template static void pushup_simd(Node *parent) { if (is_leaf(parent)) return; - + int n = count_childs(parent); - + Node **prev = &parent->child; for (Node *child = parent->child; RE_rayobject_isAligned(child) && child; ) { int cn = count_childs(child); @@ -210,7 +210,7 @@ static void pushup_simd(Node *parent) child = *prev; } } - + for (Node *child = parent->child; RE_rayobject_isAligned(child) && child; child = child->sibling) pushup_simd(child); } @@ -225,13 +225,13 @@ static void pushdown(Node *parent) { Node **s_child = &parent->child; Node *child = parent->child; - + while (child && RE_rayobject_isAligned(child)) { Node *next = child->sibling; Node **next_s_child = &child->sibling; - + //assert(bb_fits_inside(parent->bb, parent->bb+3, child->bb, child->bb+3)); - + for (Node *i = parent->child; RE_rayobject_isAligned(i) && i; i = i->sibling) if (child != i && bb_fits_inside(i->bb, i->bb + 3, child->bb, child->bb + 3) && RE_rayobject_isAligned(i->child)) { // todo optimize (should the one with the smallest area?) @@ -241,14 +241,14 @@ static void pushdown(Node *parent) child->sibling = i->child; i->child = child; next_s_child = s_child; - + tot_pushdown++; break; } child = next; s_child = next_s_child; } - + for (Node *i = parent->child; RE_rayobject_isAligned(i) && i; i = i->sibling) { pushdown(i); } @@ -264,12 +264,12 @@ static float bvh_refit(Node *node) { if (is_leaf(node)) return 0; if (is_leaf(node->child)) return 0; - + float total = 0; - + for (Node *child = node->child; child; child = child->sibling) total += bvh_refit(child); - + float old_area = bb_area(node->bb, node->bb + 3); INIT_MINMAX(node->bb, node->bb + 3); for (Node *child = node->child; child; child = child->sibling) { @@ -298,7 +298,7 @@ struct OVBVHNode { OVBVHNode *child; OVBVHNode *sibling; - + /* * Returns min cost to represent the subtree starting at the given node, * allowing it to have a given cutsize @@ -309,7 +309,7 @@ struct OVBVHNode { assert(CUT_SIZE_IS_VALID(cutsize - 1)); return cut_cost[cutsize - 1]; } - + /* * This saves the cut size of this child, when parent is reaching * its minimum cut with the given cut size @@ -320,7 +320,7 @@ struct OVBVHNode { assert(CUT_SIZE_IS_VALID(parent_cut_size - 1)); return cut_size[parent_cut_size - 1]; } - + /* * Reorganize the node based on calculated cut costs */ @@ -371,19 +371,19 @@ struct OVBVHNode { template struct VBVH_optimalPackSIMD { TestCost testcost; - + VBVH_optimalPackSIMD(TestCost testcost) { this->testcost = testcost; } - + /* * calc best cut on a node */ struct calc_best { Node *child[MAX_OPTIMIZE_CHILDS]; float child_hit_prob[MAX_OPTIMIZE_CHILDS]; - + calc_best(Node *node) { int nchilds = 0; @@ -398,12 +398,12 @@ struct VBVH_optimalPackSIMD { assert(nchilds >= 2 && nchilds <= MAX_OPTIMIZE_CHILDS); } - - + + //Build DP table to find minimum cost to represent this node with a given cutsize int bt[MAX_OPTIMIZE_CHILDS + 1][MAX_CUT_SIZE + 1]; //backtrace table float cost[MAX_OPTIMIZE_CHILDS + 1][MAX_CUT_SIZE + 1]; //cost table (can be reduced to float[2][MAX_CUT_COST]) - + for (int i = 0; i <= nchilds; i++) { for (int j = 0; j <= MAX_CUT_SIZE; j++) { cost[i][j] = INFINITY; @@ -411,7 +411,7 @@ struct VBVH_optimalPackSIMD { } cost[0][0] = 0; - + for (int i = 1; i <= nchilds; i++) { for (int size = i - 1; size /*+(nchilds-i)*/ <= MAX_CUT_SIZE; size++) { for (int cut = 1; cut + size /*+(nchilds-i)*/ <= MAX_CUT_SIZE; cut++) { @@ -423,7 +423,7 @@ struct VBVH_optimalPackSIMD { } } } - + /* Save the ways to archive the minimum cost with a given cutsize */ for (int i = nchilds; i <= MAX_CUT_SIZE; i++) { node->cut_cost[i - 1] = cost[nchilds][i]; @@ -437,10 +437,10 @@ struct VBVH_optimalPackSIMD { } } }; - + void calc_costs(Node *node) { - + if (RE_rayobject_isAligned(node->child) ) { int nchilds = 0; for (Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) { @@ -459,14 +459,14 @@ struct VBVH_optimalPackSIMD { for (Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) { cost += ((parent_area != 0.0f) ? (bb_area(child->bb, child->bb + 3) / parent_area) : 1.0f) * child->get_cost(1); } - + cost += testcost(nchilds); node->cut_cost[0] = cost; node->best_cutsize = nchilds; } else { calc_best calc(node); - + //calc expected cost if we optimaly pack this node for (int cutsize = nchilds; cutsize <= MAX_CUT_SIZE; cutsize++) { float m = node->get_cost(cutsize) + testcost(cutsize); diff --git a/source/blender/render/intern/raytrace/svbvh.h b/source/blender/render/intern/raytrace/svbvh.h index 565bba6876c..0a5690deb46 100644 --- a/source/blender/render/intern/raytrace/svbvh.h +++ b/source/blender/render/intern/raytrace/svbvh.h @@ -73,21 +73,21 @@ static int svbvh_bb_intersect_test_simd4(const Isect *isec, const __m128 *bb_gro const __m128 tmax2 = _mm_min_ps(tmax1, mul3); const __m128 tmin3 = _mm_max_ps(tmin2, mul4); const __m128 tmax3 = _mm_min_ps(tmax2, mul5); - + return _mm_movemask_ps(_mm_cmpge_ps(tmax3, tmin3)); } static int svbvh_bb_intersect_test(const Isect *isec, const float *_bb) { const float *bb = _bb; - + float t1x = (bb[isec->bv_index[0]] - isec->start[0]) * isec->idot_axis[0]; float t2x = (bb[isec->bv_index[1]] - isec->start[0]) * isec->idot_axis[0]; float t1y = (bb[isec->bv_index[2]] - isec->start[1]) * isec->idot_axis[1]; float t2y = (bb[isec->bv_index[3]] - isec->start[1]) * isec->idot_axis[1]; float t1z = (bb[isec->bv_index[4]] - isec->start[2]) * isec->idot_axis[2]; float t2z = (bb[isec->bv_index[5]] - isec->start[2]) * isec->idot_axis[2]; - + RE_RC_COUNT(isec->raycounter->bb.test); if (t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return 0; @@ -205,12 +205,12 @@ struct Reorganize_SVBVH { nodes = 0; childs_per_node = 0; useless_bb = 0; - + for (int i = 0; i < 16; i++) { nodes_with_childs[i] = 0; } } - + ~Reorganize_SVBVH() { #if 0 @@ -223,7 +223,7 @@ struct Reorganize_SVBVH { } #endif } - + SVBVHNode *create_node(int nchilds) { SVBVHNode *node = (SVBVHNode *)BLI_memarena_alloc(arena, sizeof(SVBVHNode)); @@ -231,12 +231,12 @@ struct Reorganize_SVBVH { return node; } - + void copy_bb(float bb[6], const float old_bb[6]) { std::copy(old_bb, old_bb + 6, bb); } - + void prepare_for_simd(SVBVHNode *node) { int i = 0; @@ -261,7 +261,7 @@ struct Reorganize_SVBVH { { return ((num + (amt - 1)) & ~(amt - 1)); } - + SVBVHNode *transform(OldNode *old) { if (is_leaf(old)) @@ -273,14 +273,14 @@ struct Reorganize_SVBVH { int alloc_childs = nchilds; if (nchilds % 4 > 2) alloc_childs = padup(nchilds, 4); - + SVBVHNode *node = create_node(alloc_childs); childs_per_node += nchilds; nodes++; if (nchilds < 16) nodes_with_childs[nchilds]++; - + useless_bb += alloc_childs - nchilds; while (alloc_childs > nchilds) { const static float def_bb[6] = {FLT_MAX, FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX}; @@ -288,7 +288,7 @@ struct Reorganize_SVBVH { node->child[alloc_childs] = NULL; copy_bb(node->child_bb + alloc_childs * 6, def_bb); } - + int i = nchilds; for (OldNode *o_child = old->child; o_child; o_child = o_child->sibling) { i--; @@ -307,7 +307,7 @@ struct Reorganize_SVBVH { assert(i == 0); prepare_for_simd(node); - + return node; } }; diff --git a/source/blender/render/intern/raytrace/vbvh.h b/source/blender/render/intern/raytrace/vbvh.h index 8ae9f8b5762..0b0bbd19116 100644 --- a/source/blender/render/intern/raytrace/vbvh.h +++ b/source/blender/render/intern/raytrace/vbvh.h @@ -87,7 +87,7 @@ static int count_childs(Node *parent) if (is_leaf(i)) break; } - + return n; } @@ -97,7 +97,7 @@ static void append_sibling(Node *node, Node *sibling) { while (node->sibling) node = node->sibling; - + node->sibling = sibling; } @@ -132,24 +132,24 @@ struct BuildBinaryVBVH { return node; } - + int rtbuild_split(RTBuilder *builder) { return ::rtbuild_heuristic_object_split(builder, 2); } - + Node *transform(RTBuilder *builder) { try { return _transform(builder); - + } catch (...) { } return NULL; } - + Node *_transform(RTBuilder *builder) { int size = rtbuild_size(builder); @@ -166,7 +166,7 @@ struct BuildBinaryVBVH { } else { test_break(); - + Node *node = create_node(); Node **child = &node->child; @@ -178,7 +178,7 @@ struct BuildBinaryVBVH { for (int i = 0; i < nc; i++) { RTBuilder tmp; rtbuild_get_child(builder, i, &tmp); - + *child = _transform(&tmp); DO_MIN((*child)->bb, node->bb); DO_MAX((*child)->bb + 3, node->bb + 3); @@ -195,23 +195,23 @@ struct BuildBinaryVBVH { template struct Reorganize_VBVH { Tree *tree; - + Reorganize_VBVH(Tree *t) { tree = t; } - + VBVHNode *create_node() { VBVHNode *node = (VBVHNode *)BLI_memarena_alloc(tree->node_arena, sizeof(VBVHNode)); return node; } - + void copy_bb(VBVHNode *node, OldNode *old) { std::copy(old->bb, old->bb + 6, node->bb); } - + VBVHNode *transform(OldNode *old) { if (is_leaf(old)) @@ -231,7 +231,7 @@ struct Reorganize_VBVH { child_ptr = &n_child->sibling; } *child_ptr = 0; - + return node; } }; diff --git a/source/blender/render/intern/source/bake.c b/source/blender/render/intern/source/bake.c index 12be60d5171..4a7962b1776 100644 --- a/source/blender/render/intern/source/bake.c +++ b/source/blender/render/intern/source/bake.c @@ -81,11 +81,11 @@ typedef struct BakeShade { ShadeSample ssamp; ObjectInstanceRen *obi; VlakRen *vlr; - + ZSpan *zspan; Image *ima; ImBuf *ibuf; - + int rectx, recty, quad, type, vdone; bool ready; @@ -97,7 +97,7 @@ typedef struct BakeShade { MPoly *mpoly; MLoop *mloop; MLoopCol *vcol; - + unsigned int *rect; float *rect_float; @@ -105,7 +105,7 @@ typedef struct BakeShade { bool use_displacement_buffer; float *displacement_buffer; float displacement_min, displacement_max; - + bool use_mask; char *rect_mask; /* bake pixel mask */ @@ -122,7 +122,7 @@ static void bake_set_shade_input(ObjectInstanceRen *obi, VlakRen *vlr, ShadeInpu shade_input_set_triangle_i(shi, obi, vlr, 0, 2, 3); else shade_input_set_triangle_i(shi, obi, vlr, 0, 1, 2); - + /* cache for shadow */ shi->samplenr = R.shadowsamplenr[shi->thread]++; @@ -172,12 +172,12 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua shi->r = shi->g = shi->b = 1.0f; shade_input_set_shade_texco(shi); - + /* only do AO for a full bake (and obviously AO bakes) * AO for light bakes is a leftover and might not be needed */ 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) { ntreeShaderExecTree(shi->mat->nodetree, shi, &shr); shi->mat = vlr->mat; /* shi->mat is being set in nodetree */ @@ -271,7 +271,7 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua shr.alpha = shi->vcol[3]; } } - + if (bs->rect_float && !bs->vcol) { float *col = bs->rect_float + 4 * (bs->rectx * y + x); copy_v3_v3(col, shr.combined); @@ -303,7 +303,7 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua else { rgb_float_to_uchar(col, shr.combined); } - + if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE, RE_BAKE_VERTEX_COLORS)) { col[3] = unit_float_to_uchar_clamp(shr.alpha); } @@ -324,7 +324,7 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua } } - + if (bs->rect_mask) { bs->rect_mask[bs->rectx * y + x] = FILTER_MASK_USED; } @@ -608,7 +608,7 @@ static int get_next_bake_face(BakeShade *bs) obi = R.instancetable.first; return 0; } - + BLI_thread_lock(LOCK_CUSTOM1); for (; obi; obi = obi->next, v = 0) { @@ -688,17 +688,17 @@ static int get_next_bake_face(BakeShade *bs) BKE_image_release_ibuf(ima, ibuf, NULL); continue; } - + if (ima->flag & IMA_USED_FOR_RENDER) { ima->id.tag &= ~LIB_TAG_DOIT; BKE_image_release_ibuf(ima, ibuf, NULL); continue; } - + /* find the image for the first time? */ if (ima->id.tag & LIB_TAG_DOIT) { ima->id.tag &= ~LIB_TAG_DOIT; - + /* we either fill in float or char, this ensures things go fine */ if (ibuf->rect_float) imb_freerectImBuf(ibuf); @@ -729,7 +729,7 @@ static int get_next_bake_face(BakeShade *bs) } } } - + BLI_thread_unlock(LOCK_CUSTOM1); return 0; } @@ -820,7 +820,7 @@ static void shade_tface(BakeShade *bs) /* per face fixed seed */ BLI_thread_srandom(bs->thread, vlr->index); - + /* check valid zspan */ if (ima != bs->ima) { BKE_image_release_ibuf(bs->ima, bs->ibuf, NULL); @@ -870,7 +870,7 @@ static void shade_tface(BakeShade *bs) bs->rect_mask = userdata->mask_buffer; bs->displacement_buffer = userdata->displacement_buffer; } - + /* get pixel level vertex coordinates */ for (a = 0; a < 4; a++) { /* Note, workaround for pixel aligned UVs which are common and can screw up our intersection tests @@ -886,7 +886,7 @@ static void shade_tface(BakeShade *bs) vlr_set_uv_indices(vlr, &i1, &i2, &i3); bake_set_vlr_dxyco(bs, vec[i1], vec[i2], vec[i3]); zspan_scanconvert(bs->zspan, bs, vec[i1], vec[i2], vec[i3], do_bake_shade); - + if (vlr->v4) { bs->quad = 1; bake_set_vlr_dxyco(bs, vec[0], vec[2], vec[3]); @@ -905,7 +905,7 @@ static void *do_bake_thread(void *bs_v) else { shade_tface(bs); } - + /* fast threadsafe break test */ if (R.test_break(R.tbh)) break; @@ -1000,14 +1000,14 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up } re->scene_color_manage = BKE_scene_check_color_management_enabled(re->scene); - + /* initialize render global */ R = *re; R.bakebuf = NULL; /* initialize static vars */ get_next_bake_face(NULL); - + /* do we need a mask? */ if (re->r.bake_filter) use_mask = true; @@ -1068,18 +1068,18 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up handles[a].zspan = NULL; else handles[a].zspan = MEM_callocN(sizeof(ZSpan), "zspan for bake"); - + handles[a].use_mask = use_mask; handles[a].use_displacement_buffer = use_displacement_buffer; handles[a].do_update = do_update; /* use to tell the view to update */ - + handles[a].displacement_min = FLT_MAX; handles[a].displacement_max = -FLT_MAX; BLI_threadpool_insert(&threads, &handles[a]); } - + /* wait for everything to be done */ a = 0; while (a != re->r.threads) { @@ -1150,7 +1150,7 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up } MEM_freeN(handles); - + BLI_threadpool_end(&threads); if (vdone == 0) { diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 0b68802decc..8675ffec313 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -111,7 +111,7 @@ #endif /* ------------------------------------------------------------------------- */ -/* tool functions/defines for ad hoc simplification and possible future +/* tool functions/defines for ad hoc simplification and possible future * cleanup */ /* ------------------------------------------------------------------------- */ @@ -178,11 +178,11 @@ static void calc_edge_stress_add(float *accum, VertRen *v1, VertRen *v2) { float len= len_v3v3(v1->co, v2->co)/len_v3v3(v1->orco, v2->orco); float *acc; - + acc= accum + 2*v1->index; acc[0]+= len; acc[1]+= 1.0f; - + acc= accum + 2*v2->index; acc[0]+= len; acc[1]+= 1.0f; @@ -192,13 +192,13 @@ static void calc_edge_stress(Render *UNUSED(re), ObjectRen *obr, Mesh *me) { float loc[3], size[3], *accum, *acc, *accumoffs, *stress; int a; - + if (obr->totvert==0) return; - + BKE_mesh_texspace_get(me, loc, NULL, size); - + accum= MEM_callocN(2*sizeof(float)*obr->totvert, "temp accum for stress"); - + /* de-normalize orco */ for (a=0; atotvert; a++) { VertRen *ver= RE_findOrAddVert(obr, a); @@ -208,7 +208,7 @@ static void calc_edge_stress(Render *UNUSED(re), ObjectRen *obr, Mesh *me) ver->orco[2]= ver->orco[2]*size[2] +loc[2]; } } - + /* add stress values */ accumoffs= accum; /* so we can use vertex index */ for (a=0; atotvlak; a++) { @@ -225,7 +225,7 @@ static void calc_edge_stress(Render *UNUSED(re), ObjectRen *obr, Mesh *me) } } } - + for (a=0; atotvert; a++) { VertRen *ver= RE_findOrAddVert(obr, a); if (ver->orco) { @@ -235,14 +235,14 @@ static void calc_edge_stress(Render *UNUSED(re), ObjectRen *obr, Mesh *me) acc[0]/= acc[1]; stress= RE_vertren_get_stress(obr, ver, 1); *stress= *acc; - + /* restore orcos */ ver->orco[0] = (ver->orco[0]-loc[0])/size[0]; ver->orco[1] = (ver->orco[1]-loc[1])/size[1]; ver->orco[2] = (ver->orco[2]-loc[2])/size[2]; } } - + MEM_freeN(accum); } @@ -254,7 +254,7 @@ static void calc_tangent_vector(ObjectRen *obr, VlakRen *vlr, int do_tangent) float tang[3], *tav; float *uv1, *uv2, *uv3, *uv4; float uv[4][2]; - + if (tface) { uv1= tface->uv[0]; uv2= tface->uv[1]; @@ -272,7 +272,7 @@ static void calc_tangent_vector(ObjectRen *obr, VlakRen *vlr, int do_tangent) else return; tangent_from_uv_v3(uv1, uv2, uv3, v1->co, v2->co, v3->co, vlr->n, tang); - + if (do_tangent) { tav= RE_vertren_get_tangent(obr, v1, 1); add_v3_v3(tav, tang); @@ -281,10 +281,10 @@ static void calc_tangent_vector(ObjectRen *obr, VlakRen *vlr, int do_tangent) tav= RE_vertren_get_tangent(obr, v3, 1); add_v3_v3(tav, tang); } - + if (v4) { tangent_from_uv_v3(uv1, uv3, uv4, v1->co, v3->co, v4->co, vlr->n, tang); - + if (do_tangent) { tav= RE_vertren_get_tangent(obr, v1, 1); add_v3_v3(tav, tang); @@ -339,7 +339,7 @@ static void GetTextureCoordinate(const SMikkTSpaceContext *pContext, float r_uv[ VlakRen *vlr= RE_findOrAddVlak(pMesh->obr, face_num); MTFace *tface= RE_vlakren_get_tface(pMesh->obr, vlr, pMesh->mtface_index, NULL, 0); const float *coord; - + if (tface != NULL) { coord= tface->uv[vert_index]; copy_v2_v2(r_uv, coord); @@ -419,7 +419,7 @@ static void calc_vertexnormals(Render *UNUSED(re), ObjectRen *obr, bool do_verte if (vlr->v4 && is_zero_v3(vlr->v4->n)) copy_v3_v3(vlr->v4->n, vlr->n); } } - + /* normalize vertex normals */ for (a=0; atotvert; a++) { VertRen *ver= RE_findOrAddVert(obr, a); @@ -642,7 +642,7 @@ static void autosmooth(Render *UNUSED(re), ObjectRen *obr, float mat[4][4], shor if (vlr->v2 != vlr->v3) { if (vlr->v4) normal_quad_v3(vlr->n, vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); - else + else normal_tri_v3(vlr->n, vlr->v3->co, vlr->v2->co, vlr->v1->co); } } @@ -665,11 +665,11 @@ static void set_object_orco(Render *re, void *ob, float *orco) { if (!re->orco_hash) re->orco_hash = BLI_ghash_ptr_new("set_object_orco gh"); - + BLI_ghash_insert(re->orco_hash, ob, orco); } -static void free_mesh_orco_hash(Render *re) +static void free_mesh_orco_hash(Render *re) { if (re->orco_hash) { BLI_ghash_free(re->orco_hash, NULL, MEM_freeN); @@ -681,11 +681,11 @@ static void check_material_mapto(Material *ma) { int a; ma->mapto_textured = 0; - + /* cache which inputs are actually textured. * this can avoid a bit of time spent iterating through all the texture slots, map inputs and map tos * every time a property which may or may not be textured is accessed */ - + for (a=0; amtex[a] && ma->mtex[a]->tex) { /* currently used only in volume render, so we'll check for those flags */ @@ -723,28 +723,28 @@ static Material *give_render_material(Render *re, Object *ob, short nr) { extern Material defmaterial; /* material.c */ Material *ma; - + ma= give_current_material(ob, nr); if (ma==NULL) ma= &defmaterial; - + if (re->r.mode & R_SPEED) ma->texco |= NEED_UV; - + if (ma->material_type == MA_TYPE_VOLUME) { ma->mode |= MA_TRANSP; ma->mode &= ~MA_SHADBUF; } if ((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP)) re->flag |= R_ZTRA; - + /* for light groups and SSS */ ma->flag |= MA_IS_USED; if (ma->nodetree && ma->use_nodes) flag_render_node_material(re, ma->nodetree); - + check_material_mapto(ma); - + return ma; } @@ -768,7 +768,7 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par static float anor[3], avec[3]; int flag, i; static int second=0; - + sub_v3_v3v3(nor, vec, vec1); normalize_v3(nor); /* nor needed as tangent */ cross_v3_v3v3(cross, vec, nor); @@ -778,7 +778,7 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par dx= re->winx*cross[0]*re->winmat[0][0]; dy= re->winy*cross[1]*re->winmat[1][1]; w = sqrtf(dx * dx + dy * dy) / w; - + if (w!=0.0f) { float fac; if (ma->strand_ease!=0.0f) { @@ -807,16 +807,16 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par mul_v3_fl(cross, width); } - + if (ma->mode & MA_TANGENT_STR) flag= R_SMOOTH|R_TANGENT; else flag= R_SMOOTH; - + /* only 1 pixel wide strands filled in as quads now, otherwise zbuf errors */ if (ma->strand_sta==1.0f) flag |= R_STRAND; - + /* single face line */ if (sd->line) { vlr= RE_findOrAddVlak(obr, obr->totvlak++); @@ -825,13 +825,13 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par vlr->v2= RE_findOrAddVert(obr, obr->totvert++); vlr->v3= RE_findOrAddVert(obr, obr->totvert++); vlr->v4= RE_findOrAddVert(obr, obr->totvert++); - + copy_v3_v3(vlr->v1->co, vec); add_v3_v3(vlr->v1->co, cross); copy_v3_v3(vlr->v1->n, nor); vlr->v1->orco= sd->orco; vlr->v1->accum = -1.0f; /* accum abuse for strand texco */ - + copy_v3_v3(vlr->v2->co, vec); sub_v3_v3v3(vlr->v2->co, vlr->v2->co, cross); copy_v3_v3(vlr->v2->n, nor); @@ -851,7 +851,7 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par vlr->v3->accum= vlr->v4->accum; normal_quad_v3(vlr->n, vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); - + vlr->mat= ma; vlr->ec= ME_V2V3; @@ -872,7 +872,7 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par if (sd->override_uv>=0) { MTFace *mtf; mtf=RE_vlakren_get_tface(obr, vlr, sd->override_uv, NULL, 0); - + mtf->uv[0][0]=mtf->uv[3][0]=0.0f; mtf->uv[1][0]=mtf->uv[2][0]=1.0f; @@ -899,13 +899,13 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par v1= RE_findOrAddVert(obr, obr->totvert++); v2= RE_findOrAddVert(obr, obr->totvert++); - + copy_v3_v3(v1->co, vec); add_v3_v3(v1->co, cross); copy_v3_v3(v1->n, nor); v1->orco= sd->orco; v1->accum = -1.0f; /* accum abuse for strand texco */ - + copy_v3_v3(v2->co, vec); sub_v3_v3v3(v2->co, v2->co, cross); copy_v3_v3(v2->n, nor); @@ -961,7 +961,7 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par vlr= RE_findOrAddVlak(obr, obr->totvlak-1); } } - + copy_v3_v3(vlr->v4->co, vec); add_v3_v3(vlr->v4->co, cross); copy_v3_v3(vlr->v4->n, nor); @@ -973,9 +973,9 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par copy_v3_v3(vlr->v3->n, nor); vlr->v3->orco= sd->orco; vlr->v3->accum= vlr->v4->accum; - + normal_quad_v3(vlr->n, vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); - + vlr->mat= ma; vlr->ec= ME_V2V3; @@ -996,7 +996,7 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par if (sd->override_uv>=0) { MTFace *mtf; mtf=RE_vlakren_get_tface(obr, vlr, sd->override_uv, NULL, 0); - + mtf->uv[0][0]=mtf->uv[3][0]=0.0f; mtf->uv[1][0]=mtf->uv[2][0]=1.0f; @@ -1026,15 +1026,15 @@ static void static_particle_wire(ObjectRen *obr, Material *ma, const float vec[3 vlr->v2= RE_findOrAddVert(obr, obr->totvert++); vlr->v3= vlr->v2; vlr->v4= NULL; - + copy_v3_v3(vlr->v1->co, vec); copy_v3_v3(vlr->v2->co, vec1); - + sub_v3_v3v3(vlr->n, vec, vec1); normalize_v3(vlr->n); copy_v3_v3(vlr->v1->n, vlr->n); copy_v3_v3(vlr->v2->n, vlr->n); - + vlr->mat= ma; vlr->ec= ME_V1V2; @@ -1049,14 +1049,14 @@ static void static_particle_wire(ObjectRen *obr, Material *ma, const float vec[3 vlr->v2= RE_findOrAddVert(obr, obr->totvert++); vlr->v3= vlr->v2; vlr->v4= NULL; - + v1= vlr->v2; /* cycle */ copy_v3_v3(v1->co, vec); - + sub_v3_v3v3(vlr->n, vec, vec1); normalize_v3(vlr->n); copy_v3_v3(v1->n, vlr->n); - + vlr->mat= ma; vlr->ec= ME_V1V2; } @@ -1117,7 +1117,7 @@ static void particle_billboard(Render *re, ObjectRen *obr, Material *ma, Particl copy_v3_v3(vlr->v2->n, vlr->n); copy_v3_v3(vlr->v3->n, vlr->n); copy_v3_v3(vlr->v4->n, vlr->n); - + vlr->mat= ma; vlr->ec= ME_V2V3; @@ -1145,9 +1145,9 @@ static void particle_billboard(Render *re, ObjectRen *obr, Material *ma, Particl zvec[bb->align] = 0.0f; normalize_v3(zvec); } - + time = saacos(dot_v3v3(zvec, axis1)) / (float)M_PI; - + if (dot_v3v3(zvec, axis2) < 0.0f) time = 1.0f - time / 2.0f; else @@ -1206,7 +1206,7 @@ static void particle_billboard(Render *re, ObjectRen *obr, Material *ma, Particl static void particle_normal_ren(short ren_as, ParticleSettings *part, Render *re, ObjectRen *obr, DerivedMesh *dm, Material *ma, ParticleStrandData *sd, ParticleBillboardData *bb, ParticleKey *state, int seed, float hasize, float *pa_co) { float loc[3], loc0[3], loc1[3], vel[3]; - + copy_v3_v3(loc, state->co); if (ren_as != PART_DRAW_BB) @@ -1245,7 +1245,7 @@ static void particle_normal_ren(short ren_as, ParticleSettings *part, Render *re HaloRen *har = NULL; har = RE_inithalo_particle(re, obr, dm, ma, loc, NULL, sd->orco, sd->uvco, hasize, 0.0, seed, pa_co); - + if (har) har->lay= obr->ob->lay; break; @@ -1263,7 +1263,7 @@ static void get_particle_uvco_mcol(short from, DerivedMesh *dm, float *fuv, int MFace *mface = dm->getTessFaceData(dm, num, CD_MFACE); MTFace *mtface = (MTFace*)CustomData_get_layer_n(&dm->faceData, CD_MTFACE, i); mtface += num; - + psys_interpolate_uvs(mtface, mface->v4, fuv, sd->uvco + 2 * i); } else { @@ -1332,7 +1332,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem if (part==NULL || pars==NULL || !psys_check_enabled(ob, psys, G.is_rendering)) return 0; - + if (part->ren_as==PART_DRAW_OB || part->ren_as==PART_DRAW_GR || part->ren_as==PART_DRAW_NOT) return 1; @@ -1384,7 +1384,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem /* 2.1 setup material stff */ ma= give_render_material(re, ob, part->omat); - + #if 0 /* XXX old animation system */ if (ma->ipo) { calc_ipo(ma->ipo, cfra); @@ -1441,7 +1441,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem bb.totnum = totpart+totchild; bb.uv_split = part->bb_uv_split; } - + /* 2.5 setup matrices */ mul_m4_m4m4(mat, re->viewmat, ob->obmat); invert_m4_m4(ob->imat, mat); /* need to be that way, for imat texture */ @@ -1590,7 +1590,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem max_k = (int)cache->segments; } - + pa_time = psys_get_child_time(psys, cpa, cfra, &pa_birthtime, &pa_dietime); pa_size = psys_get_child_size(psys, cpa, cfra, &pa_time); @@ -1868,13 +1868,13 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem if (sd.uvco) MEM_freeN(sd.uvco); - + if (sd.mcol) MEM_freeN(sd.mcol); if (states) MEM_freeN(states); - + BLI_rng_free(rng); psys->flag &= ~PSYS_DRAWING; @@ -1948,7 +1948,7 @@ static int verghalo(const void *a1, const void *a2) { const HaloRen *har1= *(const HaloRen**)a1; const HaloRen *har2= *(const HaloRen**)a2; - + if (har1->zs < har2->zs) return 1; else if (har1->zs > har2->zs) return -1; return 0; @@ -1986,7 +1986,7 @@ static short test_for_displace(Render *re, Object *ob) /* return 1 when this object uses displacement textures. */ Material *ma; int i; - + for (i=1; i<=ob->totcol; i++) { ma=give_render_material(re, ob, i); /* ma->mapto is ORed total of all mapto channels */ @@ -2051,10 +2051,10 @@ static void displace_render_vert(Render *re, ObjectRen *obr, ShadeInput *shi, Ve } shi->displace[0]= shi->displace[1]= shi->displace[2]= 0.0; - + do_material_tex(shi, re); - - //printf("no=%f, %f, %f\nbefore co=%f, %f, %f\n", vr->n[0], vr->n[1], vr->n[2], + + //printf("no=%f, %f, %f\nbefore co=%f, %f, %f\n", vr->n[0], vr->n[1], vr->n[2], //vr->co[0], vr->co[1], vr->co[2]); displace[0]= shi->displace[0] * scale[0]; @@ -2062,22 +2062,22 @@ static void displace_render_vert(Render *re, ObjectRen *obr, ShadeInput *shi, Ve displace[2]= shi->displace[2] * scale[2]; /* 0.5 could become button once? */ - vr->co[0] += displace[0]; + vr->co[0] += displace[0]; vr->co[1] += displace[1]; vr->co[2] += displace[2]; - - //printf("after co=%f, %f, %f\n", vr->co[0], vr->co[1], vr->co[2]); - + + //printf("after co=%f, %f, %f\n", vr->co[0], vr->co[1], vr->co[2]); + /* we just don't do this vertex again, bad luck for other face using same vertex with * different material... */ vr->flag |= 1; - + /* Pass sample back so displace_face can decide which way to split the quad */ sample = shi->displace[0]*shi->displace[0]; sample += shi->displace[1]*shi->displace[1]; sample += shi->displace[2]*shi->displace[2]; - - vr->accum=sample; + + vr->accum=sample; /* Should be sqrt(sample), but I'm only looking for "bigger". Save the cycles. */ return; } @@ -2088,11 +2088,11 @@ static void displace_render_face(Render *re, ObjectRen *obr, VlakRen *vlr, float /* Warning, This is not that nice, and possibly a bit slow, * however some variables were not initialized properly in, unless using shade_input_initialize(...), we need to do a memset */ - memset(&shi, 0, sizeof(ShadeInput)); + memset(&shi, 0, sizeof(ShadeInput)); /* end warning! - Campbell */ - + /* set up shadeinput struct for multitex() */ - + /* memset above means we don't need this */ /*shi.osatex= 0;*/ /* signal not to use dx[] and dy[] texture AA vectors */ @@ -2100,7 +2100,7 @@ static void displace_render_face(Render *re, ObjectRen *obr, VlakRen *vlr, float shi.vlr= vlr; /* current render face */ shi.mat= vlr->mat; /* current input material */ shi.thread= 0; - + /* TODO, assign these, displacement with new bumpmap is skipped without - campbell */ #if 0 /* order is not known ? */ @@ -2112,7 +2112,7 @@ static void displace_render_face(Render *re, ObjectRen *obr, VlakRen *vlr, float /* Displace the verts, flag is set when done */ if (!vlr->v1->flag) displace_render_vert(re, obr, &shi, vlr->v1, 0, scale); - + if (!vlr->v2->flag) displace_render_vert(re, obr, &shi, vlr->v2, 1, scale); @@ -2123,11 +2123,11 @@ static void displace_render_face(Render *re, ObjectRen *obr, VlakRen *vlr, float if (!vlr->v4->flag) displace_render_vert(re, obr, &shi, vlr->v4, 3, scale); - /* closest in displace value. This will help smooth edges. */ + /* closest in displace value. This will help smooth edges. */ if (fabsf(vlr->v1->accum - vlr->v3->accum) > fabsf(vlr->v2->accum - vlr->v4->accum)) vlr->flag |= R_DIVIDE_24; else vlr->flag &= ~R_DIVIDE_24; } - + /* Recalculate the face normal - if flipped before, flip now */ if (vlr->v4) { normal_quad_v3(vlr->n, vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); @@ -2145,7 +2145,7 @@ static void displace(Render *re, ObjectRen *obr) float scale[3]={1.0f, 1.0f, 1.0f}, temp[3];//, xn int i; //, texflag=0; Object *obt; - + /* Object Size with parenting */ obt=obr->ob; while (obt) { @@ -2153,7 +2153,7 @@ static void displace(Render *re, ObjectRen *obr) scale[0]*=temp[0]; scale[1]*=temp[1]; scale[2]*=temp[2]; obt=obt->parent; } - + /* Clear all flags */ for (i=0; itotvert; i++) { vr= RE_findOrAddVert(obr, i); @@ -2164,7 +2164,7 @@ static void displace(Render *re, ObjectRen *obr) vlr=RE_findOrAddVlak(obr, i); displace_render_face(re, obr, vlr, scale); } - + /* Recalc vertex normals */ calc_vertexnormals(re, obr, 1, 0, 0); } @@ -2232,7 +2232,7 @@ static void init_render_mball(Render *re, ObjectRen *obr) ver->n[2]= imat[2][0]*xn+imat[2][1]*yn+imat[2][2]*zn; normalize_v3(ver->n); //if (ob->transflag & OB_NEG_SCALE) negate_v3(ver->n); - + if (need_orco) { ver->orco= orco; orco+=3; @@ -2290,10 +2290,10 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, int p1, p2, p3, p4, a; int sizeu, nsizeu, sizev, nsizev; int startvert, startvlak; - + startvert= obr->totvert; - nsizeu = sizeu = dl->parts; nsizev = sizev = dl->nr; - + nsizeu = sizeu = dl->parts; nsizev = sizev = dl->nr; + data= dl->verts; for (u = 0; u < sizeu; u++) { v1 = RE_findOrAddVert(obr, obr->totvert++); /* save this for possible V wrapping */ @@ -2302,7 +2302,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, v1->orco= orco; orco+= 3; orcoret++; } mul_m4_v3(mat, v1->co); - + for (v = 1; v < sizev; v++) { ver= RE_findOrAddVert(obr, obr->totvert++); copy_v3_v3(ver->co, data); data += 3; @@ -2320,11 +2320,11 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, } } } - + /* Done before next loop to get corner vert */ if (dl->flag & DL_CYCL_U) nsizev++; if (dl->flag & DL_CYCL_V) nsizeu++; - + /* if U cyclic, add extra row at end of column */ if (dl->flag & DL_CYCL_V) { for (v = 0; v < nsizev; v++) { @@ -2336,47 +2336,47 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, } } } - + sizeu = nsizeu; sizev = nsizev; - + startvlak= obr->totvlak; - + for (u = 0; u < sizeu - 1; u++) { p1 = startvert + u * sizev; /* walk through face list */ p2 = p1 + 1; p3 = p2 + sizev; p4 = p3 - 1; - + for (v = 0; v < sizev - 1; v++) { v1= RE_findOrAddVert(obr, p1); v2= RE_findOrAddVert(obr, p2); v3= RE_findOrAddVert(obr, p3); v4= RE_findOrAddVert(obr, p4); - + vlr= RE_findOrAddVlak(obr, obr->totvlak++); vlr->v1= v1; vlr->v2= v2; vlr->v3= v3; vlr->v4= v4; - + normal_quad_v3(n1, vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); - + copy_v3_v3(vlr->n, n1); - + vlr->mat= matar[ dl->col]; vlr->ec= ME_V1V2+ME_V2V3; vlr->flag= dl->rt; - + add_v3_v3(v1->n, n1); add_v3_v3(v2->n, n1); add_v3_v3(v3->n, n1); add_v3_v3(v4->n, n1); - + p1++; p2++; p3++; p4++; } } /* fix normals for U resp. V cyclic faces */ sizeu--; sizev--; /* dec size for face array */ if (dl->flag & DL_CYCL_V) { - + for (v = 0; v < sizev; v++) { /* optimize! :*/ vlr= RE_findOrAddVlak(obr, UVTOINDEX(sizeu - 1, v)); @@ -2388,7 +2388,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, } } if (dl->flag & DL_CYCL_U) { - + for (u = 0; u < sizeu; u++) { /* optimize! :*/ vlr= RE_findOrAddVlak(obr, UVTOINDEX(u, 0)); @@ -2400,7 +2400,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, } } - /* last vertex is an extra case: + /* last vertex is an extra case: * * ^ ()----()----()----() * | | | || | @@ -2412,7 +2412,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, * | | || | * ()----()----()----() * v -> - * + * * vertex [] is no longer shared, therefore distribute * normals of the surrounding faces to all of the duplicates of [] */ @@ -2434,8 +2434,8 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, ver= RE_findOrAddVert(obr, a); normalize_v3(ver->n); } - - + + return orcoret; } @@ -2660,7 +2660,7 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) BKE_displist_make_curveTypes_forRender(re->scene, ob, &disp, &dm, false, true); dl= disp.first; if (dl==NULL) return; - + mul_m4_m4m4(mat, re->viewmat, ob->obmat); invert_m4_m4(ob->imat, mat); negative_scale = is_negative_m4(mat); @@ -3225,7 +3225,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) /* attempt to autsmooth on original mesh, only without subsurf */ if (do_autosmooth && me->totvert==totvert && me->totface==dm->getNumTessFaces(dm)) use_original_normals= true; - + ma= give_render_material(re, ob, 1); @@ -3273,7 +3273,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) *origindex = a; } } - + if (!timeoffset) { short (*lnp)[4][3] = NULL; #ifdef WITH_FREESTYLE @@ -3294,7 +3294,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) obr->tangent_mask = dm->tangent_mask; DM_generate_tangent_tessface_data(dm, need_nmap_tangent_concrete || need_tangent); } - + /* still to do for keys: the correct local texture coordinate */ /* faces in order of color blocks */ @@ -3320,7 +3320,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) } } } - + /* if wire material, and we got edges, don't do the faces */ if (ma->material_type == MA_TYPE_WIRE) { end= dm->getNumEdges(dm); @@ -3340,10 +3340,10 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) index_mp_to_orig= dm->getPolyDataArray(dm, CD_ORIGINDEX); ffa= CustomData_get_layer(&me->pdata, CD_FREESTYLE_FACE); #endif - + for (a=0; amat_nr==a1 ) { float len; bool reverse_verts = (negative_scale != 0 && do_autosmooth == false); @@ -3390,16 +3390,16 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) if (use_original_normals) { MFace *mf= me->mface+a; MVert *mv= me->mvert; - + if (vlr->v4) len= normal_quad_v3(vlr->n, mv[mf->v4].co, mv[mf->v3].co, mv[mf->v2].co, mv[mf->v1].co); - else + else len= normal_tri_v3(vlr->n, mv[mf->v3].co, mv[mf->v2].co, mv[mf->v1].co); } else { if (vlr->v4) len= normal_quad_v3(vlr->n, vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); - else + else len= normal_tri_v3(vlr->n, vlr->v3->co, vlr->v2->co, vlr->v1->co); } @@ -3419,7 +3419,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) for (index=0; indexfaceData.totlayer; index++) { layer= &dm->faceData.layers[index]; name= layer->name; - + if (layer->type == CD_MTFACE && mtfn < MAX_MTFACE) { int t; mtf= RE_vlakren_get_tface(obr, vlr, mtfn++, &name, 1); @@ -3494,7 +3494,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) if (edge_hash) BLI_edgehash_free(edge_hash, NULL); #endif - + /* exception... we do edges for wire mode. potential conflict when faces exist... */ end= dm->getNumEdges(dm); mvert= dm->getVertArray(dm); @@ -3504,12 +3504,12 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) struct edgesort *edgetable; int totedge= 0; recalc_normals= 1; - + medge= dm->getEdgeArray(dm); - + /* we want edges to have UV and vcol too... */ edgetable= make_mesh_edge_lookup(dm, &totedge); - + for (a1=0; a1flag&ME_EDGERENDER) { MVert *v0 = &mvert[medge->v1]; @@ -3520,10 +3520,10 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) vlr->v2= RE_findOrAddVert(obr, vertofs+medge->v2); vlr->v3= vlr->v2; vlr->v4= NULL; - + if (edgetable) use_mesh_edge_lookup(obr, dm, medge, vlr, edgetable, totedge); - + xn= -(v0->no[0]+v1->no[0]); yn= -(v0->no[1]+v1->no[1]); zn= -(v0->no[2]+v1->no[2]); @@ -3532,7 +3532,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) vlr->n[1]= imat[1][0]*xn+imat[1][1]*yn+imat[1][2]*zn; vlr->n[2]= imat[2][0]*xn+imat[2][1]*yn+imat[2][2]*zn; normalize_v3(vlr->n); - + vlr->mat= ma; vlr->flag= 0; vlr->ec= ME_V1V2; @@ -3543,7 +3543,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) } } } - + if (!timeoffset) { if (need_stress) calc_edge_stress(re, obr, me); @@ -3575,49 +3575,49 @@ static void initshadowbuf(Render *re, LampRen *lar, float mat[4][4]) { struct ShadBuf *shb; float viewinv[4][4]; - + /* if (la->spsi<16) return; */ - + /* memory alloc */ shb= (struct ShadBuf *)MEM_callocN(sizeof(struct ShadBuf), "initshadbuf"); lar->shb= shb; - + if (shb==NULL) return; - + VECCOPY(shb->co, lar->co); /* int copy */ - + /* percentage render: keep track of min and max */ shb->size= (lar->bufsize*re->r.size)/100; - + if (shb->size<512) shb->size= 512; else if (shb->size > lar->bufsize) shb->size= lar->bufsize; - + shb->size &= ~15; /* make sure its multiples of 16 */ - + shb->samp= lar->samp; shb->soft= lar->soft; shb->shadhalostep= lar->shadhalostep; - + normalize_m4(mat); invert_m4_m4(shb->winmat, mat); /* winmat is temp */ - + /* matrix: combination of inverse view and lampmat */ /* calculate again: the ortho-render has no correct viewinv */ invert_m4_m4(viewinv, re->viewmat); mul_m4_m4m4(shb->viewmat, shb->winmat, viewinv); - + /* projection */ shb->d= lar->clipsta; shb->clipend= lar->clipend; - + /* bias is percentage, made 2x larger because of correction for angle of incidence */ /* when a ray is closer to parallel of a face, bias value is increased during render */ shb->bias= (0.02f*lar->bias)*0x7FFFFFFF; - + /* halfway method (average of first and 2nd z) reduces bias issues */ if (ELEM(lar->buftype, LA_SHADBUF_HALFWAY, LA_SHADBUF_DEEP)) shb->bias= 0.1f*shb->bias; - + shb->compressthresh= lar->compressthresh; } @@ -3629,7 +3629,7 @@ void area_lamp_vectors(LampRen *lar) multifac= 1.0f/sqrtf((float)lar->ray_totsamp); xsize *= multifac; ysize *= multifac; - + /* corner vectors */ lar->area[0][0]= lar->co[0] - xsize*lar->mat[0][0] - ysize*lar->mat[1][0]; lar->area[0][1]= lar->co[1] - xsize*lar->mat[0][1] - ysize*lar->mat[1][1]; @@ -3665,14 +3665,14 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) /* previewrender sets this to zero... prevent accidents */ if (la==NULL) return NULL; - + /* prevent only shadow from rendering light */ if (la->mode & LA_ONLYSHADOW) if ((re->r.mode & R_SHADOW)==0) return NULL; - + re->totlamp++; - + /* groups is used to unify support for lightgroups, this is the global lightgroup */ go= MEM_callocN(sizeof(GroupObject), "groupobject"); BLI_addtail(&re->lights, go); @@ -3699,7 +3699,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) lar->shadhalostep = la->shadhalostep; lar->clipsta = la->clipsta; lar->clipend = la->clipend; - + lar->bias = la->bias; lar->compressthresh = la->compressthresh; @@ -3731,25 +3731,25 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) lar->ray_samp= la->ray_samp; lar->ray_sampy= la->ray_sampy; lar->ray_sampz= la->ray_sampz; - + lar->area_size= la->area_size; lar->area_sizey= la->area_sizey; lar->area_sizez= la->area_sizez; lar->area_shape= la->area_shape; - + /* 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 (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; lar->ray_samp_type= la->ray_samp_type; - + lar->adapt_thresh= la->adapt_thresh; lar->sunsky = NULL; - + if ( ELEM(lar->type, LA_SPOT, LA_LOCAL)) { lar->ray_totsamp= lar->ray_samp*lar->ray_samp; lar->area_shape = LA_AREA_SQUARE; @@ -3790,7 +3790,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) { lar->sunsky = (struct SunSky*)MEM_callocN(sizeof(struct SunSky), "sunskyren"); lar->sunsky->effect_type = la->sun_effect_type; - + copy_v3_v3(vec, ob->obmat[2]); normalize_v3(vec); @@ -3804,7 +3804,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) } } else lar->ray_totsamp= 0; - + lar->spotsi= la->spotsize; if (lar->mode & LA_HALO) { if (lar->spotsi > DEG2RADF(170.0f)) lar->spotsi = DEG2RADF(170.0f); @@ -3878,7 +3878,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) for (c=0; cmtex[c] && la->mtex[c]->tex) { - if (la->mtex[c]->mapto & LAMAP_COL) + if (la->mtex[c]->mapto & LAMAP_COL) lar->mode |= LA_TEXTURE; if (la->mtex[c]->mapto & LAMAP_SHAD) lar->mode |= LA_SHAD_TEX; @@ -3898,10 +3898,10 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) if ( (re->r.mode & R_RAYTRACE)==0) lar->mode &= ~LA_SHAD_RAY; } - + if (re->r.mode & R_SHADOW) { - + if (la->type==LA_AREA && (lar->mode & LA_SHAD_RAY) && (lar->ray_samp_method == LA_SAMP_CONSTANT)) { init_jitter_plane(lar); } @@ -3911,8 +3911,8 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) copy_m4_m4(mat, ob->obmat); initshadowbuf(re, lar, mat); /* mat is altered */ } - - + + /* this is the way used all over to check for shadow */ if (lar->shb || (lar->mode & LA_SHAD_RAY)) { LampShadowSample *ls; @@ -3920,7 +3920,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) int a, b; memset(re->shadowsamplenr, 0, sizeof(re->shadowsamplenr)); - + lar->shadsamp= MEM_mallocN(re->r.threads*sizeof(LampShadowSample), "lamp shadow sample"); ls= lar->shadsamp; @@ -3938,7 +3938,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) } } } - + return go; } @@ -3954,7 +3954,7 @@ static bool is_object_hidden(Render *re, Object *ob) { if (is_object_restricted(re, ob)) return true; - + if (re->r.scemode & R_VIEWPORT_PREVIEW) { /* Mesh deform cages and so on mess up the preview. To avoid the problem, * viewport doesn't show mesh object if its draw type is bounding box or wireframe. @@ -3978,7 +3978,7 @@ static bool is_object_hidden(Render *re, Object *ob) static void add_lightgroup(Render *re, Group *group, int exclusive) { GroupObject *go, *gol; - + group->id.tag &= ~LIB_TAG_DOIT; /* it's a bit too many loops in loops... but will survive */ @@ -3988,7 +3988,7 @@ static void add_lightgroup(Render *re, Group *group, int exclusive) if (is_object_hidden(re, go->ob)) continue; - + if (go->ob->lay & re->lay) { if (go->ob && go->ob->type==OB_LAMP) { for (gol= re->lights.first; gol; gol= gol->next) { @@ -4012,14 +4012,14 @@ static void set_material_lightgroups(Render *re) { Group *group; Material *ma; - + /* not for preview render */ if (re->scene->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW)) return; - + for (group= re->main->group.first; group; group=group->id.next) group->id.tag |= LIB_TAG_DOIT; - + /* it's a bit too many loops in loops... but will survive */ /* hola! materials not in use...? */ for (ma= re->main->mat.first; ma; ma=ma->id.next) { @@ -4031,7 +4031,7 @@ static void set_material_lightgroups(Render *re) static void set_renderlayer_lightgroups(Render *re, Scene *sce) { SceneRenderLayer *srl; - + for (srl= sce->r.layers.first; srl; srl= srl->next) { if (srl->light_override) add_lightgroup(re, srl->light_override, 0); @@ -4050,17 +4050,17 @@ void init_render_world(Render *re) }; int a; - + if (re->scene && re->scene->world) { re->wrld = *(re->scene->world); copy_v3_v3(re->grvec, re->viewmat[2]); normalize_v3(re->grvec); copy_m3_m4(re->imat, re->viewinv); - + for (a=0; awrld.mtex[a] && re->wrld.mtex[a]->tex) re->wrld.skytype |= WO_SKYTEX; - + /* AO samples should be OSA minimum */ if (re->osa) while (re->wrld.aosamp*re->wrld.aosamp < re->osa) @@ -4072,13 +4072,13 @@ void init_render_world(Render *re) memset(&re->wrld, 0, sizeof(World)); re->wrld.exp= 0.0f; re->wrld.range= 1.0f; - + /* for mist pass */ re->wrld.miststa= re->clipsta; re->wrld.mistdist= re->clipend-re->clipsta; re->wrld.misi= 1.0f; } - + re->wrld.linfac= 1.0f + powf((2.0f*re->wrld.exp + 0.5f), -10); re->wrld.logfac= logf((re->wrld.linfac-1.0f)/re->wrld.linfac) / re->wrld.range; @@ -4100,11 +4100,11 @@ static void set_phong_threshold(ObjectRen *obr) VlakRen *vlr; float thresh= 0.0, dot; int tot=0, i; - - /* Added check for 'pointy' situations, only dotproducts of 0.9 and larger + + /* Added check for 'pointy' situations, only dotproducts of 0.9 and larger * are taken into account. This threshold is meant to work on smooth geometry, not * for extreme cases (ton) */ - + for (i=0; itotvlak; i++) { vlr= RE_findOrAddVlak(obr, i); if ((vlr->flag & R_SMOOTH) && (vlr->flag & R_STRAND)==0) { @@ -4134,7 +4134,7 @@ static void set_phong_threshold(ObjectRen *obr) } } } - + if (tot) { thresh/= (float)tot; obr->ob->smoothresh= cosf(0.5f*(float)M_PI-saacos(thresh)); @@ -4150,14 +4150,14 @@ static void set_fullsample_trace_flag(Render *re, ObjectRen *obr) osa= re->osa; trace= re->r.mode & R_RAYTRACE; - + for (a=obr->totvlak-1; a>=0; a--) { vlr= RE_findOrAddVlak(obr, a); mode= vlr->mat->mode; if (trace && (mode & MA_TRACEBLE)) vlr->flag |= R_TRACEBLE; - + if (osa) { if (mode & MA_FULL_OSA) { vlr->flag |= R_FULL_OSA; @@ -4170,7 +4170,7 @@ static void set_fullsample_trace_flag(Render *re, ObjectRen *obr) /* pass */ } else if ((mode & MA_RAYMIRROR) || ((mode & MA_TRANSP) && (mode & MA_RAYTRANSP))) { - /* for blurry reflect/refract, better to take more samples + /* for blurry reflect/refract, better to take more samples * inside the raytrace than as OSA samples */ if ((vlr->mat->gloss_mir == 1.0f) && (vlr->mat->gloss_tra == 1.0f)) vlr->flag |= R_FULL_OSA; @@ -4183,22 +4183,22 @@ static void set_fullsample_trace_flag(Render *re, ObjectRen *obr) /* split quads for predictable baking * dir 1 == (0, 1, 2) (0, 2, 3), 2 == (1, 3, 0) (1, 2, 3) */ -static void split_quads(ObjectRen *obr, int dir) +static void split_quads(ObjectRen *obr, int dir) { VlakRen *vlr, *vlr1; int a; for (a=obr->totvlak-1; a>=0; a--) { vlr= RE_findOrAddVlak(obr, a); - + /* test if rendering as a quad or triangle, skip wire */ if ((vlr->flag & R_STRAND)==0 && (vlr->mat->material_type != MA_TYPE_WIRE)) { - + if (vlr->v4) { vlr1= RE_vlakren_copy(obr, vlr); vlr1->flag |= R_FACE_SPLIT; - + if ( dir==2 ) vlr->flag |= R_DIVIDE_24; else vlr->flag &= ~R_DIVIDE_24; @@ -4209,18 +4209,18 @@ static void split_quads(ObjectRen *obr, int dir) vlr1->v3= vlr->v4; vlr->v3 = vlr->v4; - + vlr1->flag |= R_DIVIDE_24; } else { vlr1->v1= vlr->v1; vlr1->v2= vlr->v3; vlr1->v3= vlr->v4; - + vlr1->flag &= ~R_DIVIDE_24; } vlr->v4 = vlr1->v4 = NULL; - + #ifdef WITH_FREESTYLE /* Freestyle edge marks */ if (vlr->flag & R_DIVIDE_24) { @@ -4260,10 +4260,10 @@ static void check_non_flat_quads(ObjectRen *obr) for (a=obr->totvlak-1; a>=0; a--) { vlr= RE_findOrAddVlak(obr, a); - + /* test if rendering as a quad or triangle, skip wire */ if (vlr->v4 && (vlr->flag & R_STRAND)==0 && (vlr->mat->material_type != MA_TYPE_WIRE)) { - + /* check if quad is actually triangle */ v1= vlr->v1; v2= vlr->v2; @@ -4298,20 +4298,20 @@ static void check_non_flat_quads(ObjectRen *obr) } } } - + if (vlr->v4) { - + /* Face is divided along edge with the least gradient */ /* Flagged with R_DIVIDE_24 if divide is from vert 2 to 4 */ /* 4---3 4---3 */ /* |\ 1| or |1 /| */ /* |0\ | |/ 0| */ /* 1---2 1---2 0 = orig face, 1 = new face */ - + /* render normals are inverted in render! we calculate normal of single tria here */ flen= normal_tri_v3(nor, vlr->v4->co, vlr->v3->co, vlr->v1->co); if (flen==0.0f) normal_tri_v3(nor, vlr->v4->co, vlr->v2->co, vlr->v1->co); - + xn = dot_v3v3(nor, vlr->n); if (ABS(xn) < 0.999995f ) { /* checked on noisy fractal grid */ @@ -4320,7 +4320,7 @@ static void check_non_flat_quads(ObjectRen *obr) vlr1= RE_vlakren_copy(obr, vlr); vlr1->flag |= R_FACE_SPLIT; - + /* split direction based on vnorms */ normal_tri_v3(nor, vlr->v1->co, vlr->v2->co, vlr->v3->co); d1 = dot_v3v3(nor, vlr->v1->n); @@ -4338,18 +4338,18 @@ static void check_non_flat_quads(ObjectRen *obr) vlr1->v3= vlr->v4; vlr->v3 = vlr->v4; - + vlr1->flag |= R_DIVIDE_24; } else { vlr1->v1= vlr->v1; vlr1->v2= vlr->v3; vlr1->v3= vlr->v4; - + vlr1->flag &= ~R_DIVIDE_24; } vlr->v4 = vlr1->v4 = NULL; - + /* new normals */ normal_tri_v3(vlr->n, vlr->v3->co, vlr->v2->co, vlr->v1->co); normal_tri_v3(vlr1->n, vlr1->v3->co, vlr1->v2->co, vlr1->v1->co); @@ -4391,19 +4391,19 @@ static void finalize_render_object(Render *re, ObjectRen *obr, int timeoffset) int a, b; if (obr->totvert || obr->totvlak || obr->tothalo || obr->totstrand) { - /* the exception below is because displace code now is in init_render_mesh call, + /* the exception below is because displace code now is in init_render_mesh call, * I will look at means to have autosmooth enabled for all object types * and have it as general postprocess, like displace */ if (ob->type!=OB_MESH && test_for_displace(re, ob)) displace(re, obr); - + if (!timeoffset) { /* phong normal interpolation can cause error in tracing * (terminator problem) */ ob->smoothresh= 0.0; if ((re->r.mode & R_RAYTRACE) && (re->r.mode & R_SHADOW)) set_phong_threshold(obr); - + if (re->flag & R_BAKING && re->r.bake_quad_split != 0) { /* Baking lets us define a quad split order */ split_quads(obr, re->r.bake_quad_split); @@ -4414,7 +4414,7 @@ static void finalize_render_object(Render *re, ObjectRen *obr, int timeoffset) if ((re->r.mode & R_SIMPLIFY && re->r.simplify_flag & R_SIMPLE_NO_TRIANGULATE) == 0) check_non_flat_quads(obr); } - + set_fullsample_trace_flag(re, obr); /* compute bounding boxes for clipping */ @@ -4428,17 +4428,17 @@ static void finalize_render_object(Render *re, ObjectRen *obr, int timeoffset) if (obr->strandbuf) { float width; - + /* compute average bounding box of strandpoint itself (width) */ if (obr->strandbuf->flag & R_STRAND_B_UNITS) obr->strandbuf->maxwidth = max_ff(obr->strandbuf->ma->strand_sta, obr->strandbuf->ma->strand_end); else obr->strandbuf->maxwidth= 0.0f; - + width= obr->strandbuf->maxwidth; sbound= obr->strandbuf->bound; for (b=0; bstrandbuf->totbound; b++, sbound++) { - + INIT_MINMAX(smin, smax); for (a=sbound->start; aend; a++) { @@ -4556,7 +4556,7 @@ static ObjectRen *find_dupligroup_dupli(Render *re, Object *ob, int psysindex) for (obr=re->objecttable.first; obr; obr=obr->next) if (obr->ob == ob && obr->psysindex == psysindex && (obr->flag & R_INSTANCEABLE)) return obr; - + return NULL; } @@ -4697,7 +4697,7 @@ static void add_render_object(Render *re, Object *ob, Object *par, DupliObject * } else find_dupli_instances(re, obr, dob); - + for (i=1; i<=ob->totcol; i++) { Material* ma = give_render_material(re, ob, i); if (ma && ma->material_type == MA_TYPE_VOLUME) @@ -4711,7 +4711,7 @@ static void add_render_object(Render *re, Object *ob, Object *par, DupliObject * for (psys=ob->particlesystem.first; psys; psys=psys->next, psysindex++) { if (!psys_check_enabled(ob, psys, G.is_rendering)) continue; - + obr= RE_addRenderObject(re, ob, par, index, psysindex, ob->lay); if ((dob && !dob->animated) || (ob->transflag & OB_RENDER_DUPLI)) { obr->flag |= R_INSTANCEABLE; @@ -4752,7 +4752,7 @@ static void init_render_object(Render *re, Object *ob, Object *par, DupliObject mul_m4_m4m4(mat, re->viewmat, ob->obmat); invert_m4_m4(ob->imat, mat); } - + time= PIL_check_seconds_timer(); if (time - lasttime > 1.0) { lasttime= time; @@ -4785,7 +4785,7 @@ void RE_Database_Free(Render *re) } /* FREE */ - + for (lar= re->lampren.first; lar; lar= lar->next) { freeshadowbuf(lar); if (lar->jitter) MEM_freeN(lar->jitter); @@ -4793,9 +4793,9 @@ void RE_Database_Free(Render *re) if (lar->sunsky) MEM_freeN(lar->sunsky); curvemapping_free(lar->curfalloff); } - + free_volume_precache(re); - + BLI_freelistN(&re->lampren); BLI_freelistN(&re->lights); @@ -4809,9 +4809,9 @@ void RE_Database_Free(Render *re) end_render_textures(re); free_pointdensities(re); } - + free_camera_inside_volumes(re); - + if (re->wrld.aosphere) { MEM_freeN(re->wrld.aosphere); re->wrld.aosphere= NULL; @@ -4826,13 +4826,13 @@ void RE_Database_Free(Render *re) } if (re->r.mode & R_RAYTRACE) free_render_qmcsampler(re); - + if (re->r.mode & R_RAYTRACE) freeraytree(re); free_sss(re); free_occ(re); free_strand_surface(re); - + re->totvlak=re->totvert=re->totstrand=re->totlamp=re->tothalo= 0; re->i.convertdone = false; @@ -4860,17 +4860,17 @@ static int allow_render_object(Render *re, Object *ob, int nolamps, int onlysele return 0; } } - + /* don't add non-basic meta objects, ends up having renderobjects with no geometry */ if (ob->type == OB_MBALL && ob!=BKE_mball_basis_find(re->eval_ctx, re->scene, ob)) return 0; - + if (nolamps && (ob->type==OB_LAMP)) return 0; - + if (onlyselected && (ob!=actob && !(ob->flag & SELECT))) return 0; - + return 1; } @@ -4915,7 +4915,7 @@ static void dupli_render_particle_set(Render *re, Object *ob, int timeoffset, in if (level >= MAX_DUPLI_RECUR) return; - + if (ob->transflag & OB_DUPLIPARTS) { for (psys=ob->particlesystem.first; psys; psys=psys->next) { if (ELEM(psys->part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) { @@ -5006,7 +5006,7 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp * See bug: [#28744] - campbell */ for (ob= re->main->object.first; ob; ob= ob->id.next) { float mat[4][4]; - + /* imat objects has to be done here, since displace can have texture using Object map-input */ mul_m4_m4m4(mat, re->viewmat, ob->obmat); invert_m4_m4(ob->imat_ren, mat); @@ -5134,7 +5134,7 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp if (obi==NULL) /* can't instance, just create the object */ init_render_object(re, obd, ob, dob, dob_extra->obmat, timeoffset); - + if (dob->type != OB_DUPLIGROUP) { obd->flag |= OB_DONE; obd->transflag |= OB_RENDER_DUPLI; @@ -5142,7 +5142,7 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp } else init_render_object(re, obd, ob, dob, dob_extra->obmat, timeoffset); - + if (re->test_break(re->tbh)) break; } @@ -5188,34 +5188,34 @@ void RE_Database_FromScene(Render *re, Main *bmain, Scene *scene, unsigned int l if (re->r.scemode & R_VIEWPORT_PREVIEW) re->scene_color_manage = BKE_scene_check_color_management_enabled(scene); - + /* scene needs to be set to get camera */ camera= RE_GetCamera(re); - + /* per second, per object, stats print this */ re->i.infostr= "Preparing Scene data"; re->i.cfra= scene->r.cfra; BLI_strncpy(re->i.scene_name, scene->id.name + 2, sizeof(re->i.scene_name)); - + /* XXX add test if dbase was filled already? */ - + re->memArena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "render db arena"); re->totvlak=re->totvert=re->totstrand=re->totlamp=re->tothalo= 0; re->lights.first= re->lights.last= NULL; re->lampren.first= re->lampren.last= NULL; re->i.partsdone = false; /* signal now in use for previewrender */ - + /* in localview, lamps are using normal layers, objects only local bits */ if (re->lay & 0xFF000000) lay &= 0xFF000000; - + /* applies changes fully */ if ((re->r.scemode & (R_NO_FRAME_UPDATE|R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))==0) { BKE_scene_update_for_newframe(re->eval_ctx, re->main, re->scene, lay); render_update_anim_renderdata(re, &re->scene->r); } - + /* if no camera, viewmat should have been set! */ if (use_camera_view && camera) { /* called before but need to call again in case of lens animation from the @@ -5229,10 +5229,10 @@ void RE_Database_FromScene(Render *re, Main *bmain, Scene *scene, unsigned int l /* force correct matrix for scaled cameras */ DAG_id_tag_update_ex(re->main, &camera->id, OB_RECALC_OB); } - + /* store for incremental render, viewmat rotates dbase */ copy_m4_m4(re->viewmat_orig, re->viewmat); - + init_render_world(re); /* do first, because of ambient. also requires re->osa set correct */ if (re->r.mode & R_RAYTRACE) { init_render_qmcsampler(re); @@ -5241,7 +5241,7 @@ void RE_Database_FromScene(Render *re, Main *bmain, Scene *scene, unsigned int l if (re->wrld.ao_samp_method == WO_AOSAMP_CONSTANT) init_ao_sphere(re, &re->wrld); } - + /* still bad... doing all */ init_render_textures(re); copy_v3_v3(amb, &re->wrld.ambr); @@ -5250,12 +5250,12 @@ void RE_Database_FromScene(Render *re, Main *bmain, Scene *scene, unsigned int l /* MAKE RENDER DATA */ database_init_objects(re, lay, 0, 0, NULL, 0); - + if (!re->test_break(re->tbh)) { set_material_lightgroups(re); for (sce= re->scene; sce; sce= sce->set) set_renderlayer_lightgroups(re, sce); - + /* for now some clumsy copying still */ re->i.totvert= re->totvert; re->i.totface= re->totvlak; @@ -5273,9 +5273,9 @@ void RE_Database_Preprocess(Render *re) tothalo= re->tothalo; sort_halos(re, tothalo); - + init_camera_inside_volumes(re); - + re->i.infostr = IFACE_("Creating Shadowbuffers"); re->stats_draw(re->sdh, &re->i); @@ -5293,7 +5293,7 @@ void RE_Database_Preprocess(Render *re) /* ENVIRONMENT MAPS */ if (!re->test_break(re->tbh)) make_envmaps(re); - + /* point density texture */ if (!re->test_break(re->tbh)) make_pointdensities(re); @@ -5301,10 +5301,10 @@ void RE_Database_Preprocess(Render *re) if (!re->test_break(re->tbh)) make_voxeldata(re); } - + if (!re->test_break(re->tbh)) project_renderdata(re, projectverto, (re->r.mode & R_PANORAMA) != 0, 0, 1); - + /* Occlusion */ if ((re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) && !re->test_break(re->tbh)) if (re->wrld.ao_gather_method == WO_AOGATHER_APPROX) @@ -5314,17 +5314,17 @@ void RE_Database_Preprocess(Render *re) /* SSS */ if ((re->r.mode & R_SSS) && !re->test_break(re->tbh)) make_sss_tree(re); - + if (!re->test_break(re->tbh)) if (re->r.mode & R_RAYTRACE) volume_precache(re); } - + re->i.convertdone = true; if (re->test_break(re->tbh)) RE_Database_Free(re); - + re->i.infostr = NULL; re->stats_draw(re->sdh, &re->i); } @@ -5339,15 +5339,15 @@ void RE_DataBase_ApplyWindow(Render *re) void RE_DataBase_IncrementalView(Render *re, float viewmat[4][4], int restore) { float oldviewinv[4][4], tmat[4][4]; - + invert_m4_m4(oldviewinv, re->viewmat_orig); - + /* we have to correct for the already rotated vertexcoords */ mul_m4_m4m4(tmat, viewmat, oldviewinv); - + copy_m4_m4(re->viewmat, viewmat); invert_m4_m4(re->viewinv, re->viewmat); - + init_camera_inside_volumes(re); env_rotate_scene(re, tmat, !restore); @@ -5371,25 +5371,25 @@ static void database_fromscene_vectors(Render *re, Scene *scene, unsigned int la { Object *camera= RE_GetCamera(re); float mat[4][4]; - + re->scene= scene; re->lay= lay; - + /* XXX add test if dbase was filled already? */ - + re->memArena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "vector render db arena"); re->totvlak=re->totvert=re->totstrand=re->totlamp=re->tothalo= 0; re->i.totface=re->i.totvert=re->i.totstrand=re->i.totlamp=re->i.tothalo= 0; re->lights.first= re->lights.last= NULL; - + /* in localview, lamps are using normal layers, objects only local bits */ if (re->lay & 0xFF000000) lay &= 0xFF000000; - + /* applies changes fully */ scene->r.cfra += timeoffset; BKE_scene_update_for_newframe(re->eval_ctx, re->main, re->scene, lay); - + /* if no camera, viewmat should have been set! */ if (camera) { RE_GetCameraModelMatrix(re, camera, mat); @@ -5397,10 +5397,10 @@ static void database_fromscene_vectors(Render *re, Scene *scene, unsigned int la invert_m4(mat); RE_SetView(re, mat); } - + /* MAKE RENDER DATA */ database_init_objects(re, lay, 0, 0, NULL, timeoffset); - + if (!re->test_break(re->tbh)) project_renderdata(re, projectverto, (re->r.mode & R_PANORAMA) != 0, 0, 1); @@ -5414,11 +5414,11 @@ static void speedvector_project(Render *re, float zco[2], const float co[3], con static float pixelphix=0.0f, pixelphiy=0.0f, zmulx=0.0f, zmuly=0.0f; static int pano= 0; float div; - + /* initialize */ if (re) { pano= re->r.mode & R_PANORAMA; - + /* precalculate amount of radians 1 pixel rotates */ if (pano) { /* size of 1 pixel mapped to viewplane coords */ @@ -5427,21 +5427,21 @@ static void speedvector_project(Render *re, float zco[2], const float co[3], con psize = BLI_rctf_size_x(&re->viewplane) / (float)re->winx; /* x angle of a pixel */ pixelphix = atan(psize / re->clipsta); - + psize = BLI_rctf_size_y(&re->viewplane) / (float)re->winy; /* y angle of a pixel */ pixelphiy = atan(psize / re->clipsta); } zmulx= re->winx/2; zmuly= re->winy/2; - + return; } - + /* now map hocos to screenspace, uses very primitive clip still */ if (ho[3]<0.1f) div= 10.0f; else div= 1.0f/ho[3]; - + /* use cylinder projection */ if (pano) { float vec[3], ang; @@ -5451,10 +5451,10 @@ static void speedvector_project(Render *re, float zco[2], const float co[3], con ang= saacos(-vec[2]/sqrtf(vec[0]*vec[0] + vec[2]*vec[2])); if (vec[0]<0.0f) ang= -ang; zco[0]= ang/pixelphix + zmulx; - + ang= 0.5f*(float)M_PI - saacos(vec[1] / len_v3(vec)); zco[1]= ang/pixelphiy + zmuly; - + } else { zco[0]= zmulx*(1.0f+ho[0]*div); @@ -5467,16 +5467,16 @@ static void calculate_speedvector(const float vectors[2], int step, float winsq, float zco[2], len; speedvector_project(NULL, zco, co, ho); - + zco[0]= vectors[0] - zco[0]; zco[1]= vectors[1] - zco[1]; - + /* enable nice masks for hardly moving stuff or float inaccuracy */ if (zco[0]<0.1f && zco[0]>-0.1f && zco[1]<0.1f && zco[1]>-0.1f ) { zco[0]= 0.0f; zco[1]= 0.0f; } - + /* maximize speed for image width, otherwise it never looks good */ len= zco[0]*zco[0] + zco[1]*zco[1]; if (len > winsq) { @@ -5484,7 +5484,7 @@ static void calculate_speedvector(const float vectors[2], int step, float winsq, zco[0]*= len; zco[1]*= len; } - + /* note; in main vecblur loop speedvec is negated again */ if (step) { speed[2]= -zco[0]; @@ -5619,44 +5619,44 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(fsob, eModifierType_Fluidsim); FluidsimSettings *fss; FluidVertexVelocity *velarray = NULL; - + /* only one step needed */ if (step) return 1; - + if (fluidmd) fss = fluidmd->fss; else return 0; - + copy_m4_m4(mat, re->viewmat); invert_m4_m4(imat, mat); /* set first vertex OK */ if (!fss->meshVelocities) return 0; - + if ( obr->totvert != fss->totvert) { //fprintf(stderr, "load_fluidsimspeedvectors - modified fluidsim mesh, not using speed vectors (%d,%d)...\n", obr->totvert, fsob->fluidsimSettings->meshSurface->totvert); // DEBUG return 0; } - + velarray = fss->meshVelocities; if (obi->flag & R_TRANSFORMED) mul_m4_m4m4(winmat, re->winmat, obi->mat); else copy_m4_m4(winmat, re->winmat); - + /* (bad) HACK calculate average velocity */ /* better solution would be fixing getVelocityAt() in intern/elbeem/intern/solver_util.cpp * so that also small drops/little water volumes return a velocity != 0. * But I had no luck in fixing that function - DG */ for (a=0; atotvert; a++) { for (j=0;j<3;j++) avgvel[j] += velarray[a].vel[j]; - + } for (j=0;j<3;j++) avgvel[j] /= (float)(obr->totvert); - - + + for (a=0; atotvert; a++, vectors+=2) { if ((a & 255)==0) ver= obr->vertnodes[a>>8].vert; @@ -5667,14 +5667,14 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * fsvec[3] = 0.0f; //fsvec[0] = fsvec[1] = fsvec[2] = fsvec[3] = 0.0; fsvec[2] = 2.0f; // NT fixed test for (j=0;j<3;j++) fsvec[j] = velarray[a].vel[j]; - + /* (bad) HACK insert average velocity if none is there (see previous comment) */ if ((fsvec[0] == 0.0f) && (fsvec[1] == 0.0f) && (fsvec[2] == 0.0f)) { fsvec[0] = avgvel[0]; fsvec[1] = avgvel[1]; fsvec[2] = avgvel[2]; } - + /* transform (=rotate) to cam space */ camco[0] = dot_v3v3(imat[0], fsvec); camco[1] = dot_v3v3(imat[1], fsvec); @@ -5683,14 +5683,14 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * /* get homogeneous coordinates */ projectvert(camco, winmat, hoco); projectvert(ver->co, winmat, ho); - + /* now map hocos to screenspace, uses very primitive clip still */ /* use ho[3] of original vertex, xy component of vel. direction */ if (ho[3]<0.1f) div= 10.0f; else div= 1.0f/ho[3]; zco[0]= zmulx*hoco[0]*div; zco[1]= zmuly*hoco[1]*div; - + /* maximize speed as usual */ len= zco[0]*zco[0] + zco[1]*zco[1]; if (len > winsq) { @@ -5738,7 +5738,7 @@ static void copy_dbase_object_vectors(Render *re, ListBase *lb) for (a=0; atotvert; a++, vec+=2) { if ((a & 255)==0) ver= obr->vertnodes[a>>8].vert; else ver++; - + projectvert(ver->co, winmat, ho); speedvector_project(NULL, vec, ver->co, ho); } @@ -5749,7 +5749,7 @@ static void copy_dbase_object_vectors(Render *re, ListBase *lb) static void free_dbase_object_vectors(ListBase *lb) { ObjectInstanceRen *obi; - + for (obi= lb->first; obi; obi= obi->next) if (obi->vectors) MEM_freeN(obi->vectors); @@ -5764,56 +5764,56 @@ void RE_Database_FromScene_Vectors(Render *re, Main *bmain, Scene *sce, unsigned ListBase oldtable= {NULL, NULL}, newtable= {NULL, NULL}; ListBase strandsurface; int step; - + re->i.infostr = IFACE_("Calculating previous frame vectors"); re->r.mode |= R_SPEED; - + speedvector_project(re, NULL, NULL, NULL); /* initializes projection code */ - + /* creates entire dbase */ database_fromscene_vectors(re, sce, lay, -1); - + /* copy away vertex info */ copy_dbase_object_vectors(re, &oldtable); - + /* free dbase and make the future one */ strandsurface= re->strandsurface; memset(&re->strandsurface, 0, sizeof(ListBase)); re->i.convertdone = true; RE_Database_Free(re); re->strandsurface= strandsurface; - + if (!re->test_break(re->tbh)) { /* creates entire dbase */ re->i.infostr = IFACE_("Calculating next frame vectors"); - + database_fromscene_vectors(re, sce, lay, +1); } /* copy away vertex info */ copy_dbase_object_vectors(re, &newtable); - + /* free dbase and make the real one */ strandsurface= re->strandsurface; memset(&re->strandsurface, 0, sizeof(ListBase)); re->i.convertdone = true; RE_Database_Free(re); re->strandsurface= strandsurface; - + if (!re->test_break(re->tbh)) { RE_Database_FromScene(re, bmain, sce, lay, 1); RE_Database_Preprocess(re); } - + if (!re->test_break(re->tbh)) { int vectorlay= get_vector_renderlayers(re->scene); for (step= 0; step<2; step++) { - + if (step) table= &newtable; else table= &oldtable; - + oldobi= table->first; for (obi= re->instancetable.first; obi && oldobi; obi= obi->next) { int ok= 1; @@ -5859,7 +5859,7 @@ void RE_Database_FromScene_Vectors(Render *re, Main *bmain, Scene *sce, unsigned } } } - + free_dbase_object_vectors(&oldtable); free_dbase_object_vectors(&newtable); @@ -5873,7 +5873,7 @@ void RE_Database_FromScene_Vectors(Render *re, Main *bmain, Scene *sce, unsigned mesh->nextco= NULL; } } - + re->i.infostr = NULL; re->stats_draw(re->sdh, &re->i); } @@ -5911,7 +5911,7 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay, render_copy_renderdata(&re->r, &scene->r); RE_init_threadcount(re); - + re->flag |= R_BAKING; re->excludeob= actob; if (actob) @@ -5927,14 +5927,14 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay, re->r.mode &= ~R_SHADOW; re->r.mode &= ~R_RAYTRACE; } - + if (!actob && (type==RE_BAKE_SHADOW)) { re->r.mode |= R_SHADOW; } - + /* setup render stuff */ re->memArena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "bake db arena"); - + re->totvlak=re->totvert=re->totstrand=re->totlamp=re->tothalo= 0; re->lights.first= re->lights.last= NULL; re->lampren.first= re->lampren.last= NULL; @@ -5942,9 +5942,9 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay, /* in localview, lamps are using normal layers, objects only local bits */ if (re->lay & 0xFF000000) lay &= 0xFF000000; - + camera= RE_GetCamera(re); - + /* if no camera, set unit */ if (camera) { normalize_m4_m4(mat, camera->obmat); @@ -5967,25 +5967,25 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay, init_render_world(re); /* do first, because of ambient. also requires re->osa set correct */ if (re->r.mode & R_RAYTRACE) { init_render_qmcsampler(re); - + if (re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) if (re->wrld.ao_samp_method == WO_AOSAMP_CONSTANT) init_ao_sphere(re, &re->wrld); } - + /* still bad... doing all */ init_render_textures(re); - + copy_v3_v3(amb, &re->wrld.ambr); init_render_materials(re->main, re->r.mode, amb, true); - + set_node_shader_lamp_loop(shade_material_loop); - + /* MAKE RENDER DATA */ database_init_objects(re, lay, nolamps, onlyselected, actob, 0); set_material_lightgroups(re); - + /* SHADOW BUFFER */ if (type!=RE_BAKE_LIGHT) if (re->r.mode & R_SHADOW) @@ -5995,7 +5995,7 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay, if (!re->test_break(re->tbh)) if (re->r.mode & R_RAYTRACE) makeraytree(re); - + /* point density texture */ if (!re->test_break(re->tbh)) make_pointdensities(re); diff --git a/source/blender/render/intern/source/envmap.c b/source/blender/render/intern/source/envmap.c index 40b249192f9..85a6af92a28 100644 --- a/source/blender/render/intern/source/envmap.c +++ b/source/blender/render/intern/source/envmap.c @@ -68,13 +68,13 @@ static void envmap_split_ima(EnvMap *env, ImBuf *ibuf) { int dx, part; - + /* after lock we test cube[1], if set the other thread has done it fine */ BLI_thread_lock(LOCK_IMAGE); if (env->cube[1] == NULL) { BKE_texture_envmap_free_data(env); - + dx = ibuf->y; dx /= 2; if (3 * dx == ibuf->x) { @@ -90,27 +90,27 @@ static void envmap_split_ima(EnvMap *env, ImBuf *ibuf) env->ok = 0; env->ima->ok = 0; } - + if (env->ok) { if (env->type == ENV_CUBE) { for (part = 0; part < 6; part++) { env->cube[part] = IMB_allocImBuf(dx, dx, 24, IB_rect | IB_rectfloat); } IMB_float_from_rect(ibuf); - - IMB_rectcpy(env->cube[0], ibuf, + + IMB_rectcpy(env->cube[0], ibuf, 0, 0, 0, 0, dx, dx); - IMB_rectcpy(env->cube[1], ibuf, + IMB_rectcpy(env->cube[1], ibuf, 0, 0, dx, 0, dx, dx); - IMB_rectcpy(env->cube[2], ibuf, + IMB_rectcpy(env->cube[2], ibuf, 0, 0, 2 * dx, 0, dx, dx); - IMB_rectcpy(env->cube[3], ibuf, + IMB_rectcpy(env->cube[3], ibuf, 0, 0, 0, dx, dx, dx); - IMB_rectcpy(env->cube[4], ibuf, + IMB_rectcpy(env->cube[4], ibuf, 0, 0, dx, dx, dx, dx); - IMB_rectcpy(env->cube[5], ibuf, + IMB_rectcpy(env->cube[5], ibuf, 0, 0, 2 * dx, dx, dx, dx); - + } else { /* ENV_PLANE */ env->cube[1] = IMB_dupImBuf(ibuf); @@ -130,16 +130,16 @@ static Render *envmap_render_copy(Render *re, EnvMap *env) Render *envre; float viewscale; int cuberes; - + envre = RE_NewRender("Envmap"); - + env->lastsize = re->r.size; cuberes = (env->cuberes * re->r.size) / 100; cuberes &= 0xFFFC; - + /* this flag has R_ZTRA in it for example */ envre->flag = re->flag; - + /* set up renderdata */ render_copy_renderdata(&envre->r, &re->r); envre->r.mode &= ~(R_BORDER | R_PANORAMA | R_ORTHO | R_MBLUR); @@ -150,7 +150,7 @@ static Render *envmap_render_copy(Render *re, EnvMap *env) envre->r.tiley = envre->r.ysch / 2; envre->r.size = 100; envre->r.yasp = envre->r.xasp = 1; - + RE_InitState(envre, NULL, &envre->r, NULL, cuberes, cuberes, NULL); envre->main = re->main; envre->scene = re->scene; /* unsure about this... */ @@ -161,7 +161,7 @@ static Render *envmap_render_copy(Render *re, EnvMap *env) viewscale = (env->type == ENV_PLANE) ? env->viewscale : 1.0f; RE_SetEnvmapCamera(envre, env->object, viewscale, env->clipsta, env->clipend); copy_m4_m4(envre->viewmat_orig, re->viewmat_orig); - + /* callbacks */ envre->display_update = re->display_update; envre->duh = re->duh; @@ -169,7 +169,7 @@ static Render *envmap_render_copy(Render *re, EnvMap *env) envre->tbh = re->tbh; envre->current_scene_update = re->current_scene_update; envre->suh = re->suh; - + /* and for the evil stuff; copy the database... */ envre->totvlak = re->totvlak; envre->totvert = re->totvert; @@ -185,7 +185,7 @@ static Render *envmap_render_copy(Render *re, EnvMap *env) envre->instancetable = re->instancetable; envre->objectinstance = re->objectinstance; envre->qmcsamplers = re->qmcsamplers; - + return envre; } @@ -206,7 +206,7 @@ static void envmap_free_render_copy(Render *envre) BLI_listbase_clear(&envre->instancetable); envre->objectinstance = NULL; envre->qmcsamplers = NULL; - + RE_FreeRender(envre); } @@ -215,9 +215,9 @@ static void envmap_free_render_copy(Render *envre) static void envmap_transmatrix(float mat[4][4], int part) { float tmat[4][4], eul[3], rotmat[4][4]; - + eul[0] = eul[1] = eul[2] = 0.0; - + if (part == 0) { /* neg z */ /* pass */ } @@ -239,7 +239,7 @@ static void envmap_transmatrix(float mat[4][4], int part) eul[0] = M_PI / 2.0; eul[2] = -M_PI / 2.0; } - + copy_m4_m4(tmat, mat); eul_to_mat4(rotmat, eul); mul_m4_m4m4(mat, tmat, rotmat); @@ -250,15 +250,15 @@ static void env_set_imats(Render *re) { Base *base; float mat[4][4]; - + base = re->scene->base.first; while (base) { mul_m4_m4m4(mat, re->viewmat, base->object->obmat); invert_m4_m4(base->object->imat, mat); - + base = base->next; } - + } /* ------------------------------------------------------------------------- */ @@ -271,17 +271,17 @@ void env_rotate_scene(Render *re, float mat[4][4], int do_rotate) HaloRen *har = NULL; float imat[3][3], mat_inverse[4][4], smat[4][4], tmat[4][4], cmat[3][3], tmpmat[4][4]; int a; - + if (do_rotate == 0) { invert_m4_m4(tmat, mat); copy_m3_m4(imat, tmat); - + copy_m4_m4(mat_inverse, mat); } else { copy_m4_m4(tmat, mat); copy_m3_m4(imat, mat); - + invert_m4_m4(mat_inverse, tmat); } @@ -308,13 +308,13 @@ void env_rotate_scene(Render *re, float mat[4][4], int do_rotate) copy_m4_m4(obi->imat, mat_inverse); } } - + for (obr = re->objecttable.first; obr; obr = obr->next) { for (a = 0; a < obr->tothalo; a++) { if ((a & 255) == 0) har = obr->bloha[a >> 8]; else har++; - + mul_m4_v3(tmat, har->co); } @@ -322,7 +322,7 @@ void env_rotate_scene(Render *re, float mat[4][4], int do_rotate) mul_m4_m4m4(obr->ob->imat_ren, re->viewmat, obr->ob->obmat); invert_m4(obr->ob->imat_ren); } - + for (lar = re->lampren.first; lar; lar = lar->next) { float lamp_imat[4][4]; @@ -351,13 +351,13 @@ void env_rotate_scene(Render *re, float mat[4][4], int do_rotate) normalize_v3(lar->imat[0]); normalize_v3(lar->imat[1]); normalize_v3(lar->imat[2]); - + lar->sh_invcampos[0] = -lar->co[0]; lar->sh_invcampos[1] = -lar->co[1]; lar->sh_invcampos[2] = -lar->co[2]; mul_m3_v3(lar->imat, lar->sh_invcampos); lar->sh_invcampos[2] *= lar->sh_zfac; - + if (lar->shb) { if (do_rotate == 1) { mul_m4_m4m4(smat, lar->shb->viewmat, mat_inverse); @@ -367,7 +367,7 @@ void env_rotate_scene(Render *re, float mat[4][4], int do_rotate) } } } - + if (do_rotate) { init_render_world(re); env_set_imats(re); @@ -381,7 +381,7 @@ static void env_layerflags(Render *re, unsigned int notlay) ObjectRen *obr; VlakRen *vlr = NULL; int a; - + /* invert notlay, so if face is in multiple layers it will still be visible, * unless all 'notlay' bits match the face bits. * face: 0110 @@ -389,9 +389,9 @@ static void env_layerflags(Render *re, unsigned int notlay) * ~not: 1011 * now (face & ~not) is true */ - + notlay = ~notlay; - + for (obr = re->objecttable.first; obr; obr = obr->next) { if ((obr->lay & notlay) == 0) { for (a = 0; a < obr->totvlak; a++) { @@ -409,7 +409,7 @@ static void env_hideobject(Render *re, Object *ob) ObjectRen *obr; VlakRen *vlr = NULL; int a; - + for (obr = re->objecttable.first; obr; obr = obr->next) { for (a = 0; a < obr->totvlak; a++) { if ((a & 255) == 0) vlr = obr->vlaknodes[a >> 8].vlak; @@ -426,7 +426,7 @@ static void env_showobjects(Render *re) ObjectRen *obr; VlakRen *vlr = NULL; int a; - + for (obr = re->objecttable.first; obr; obr = obr->next) { for (a = 0; a < obr->totvlak; a++) { if ((a & 255) == 0) vlr = obr->vlaknodes[a >> 8].vlak; @@ -447,16 +447,16 @@ static void render_envmap(Render *re, EnvMap *env) float orthmat[4][4]; float oldviewinv[4][4], mat[4][4], tmat[4][4]; short part; - + /* need a recalc: ortho-render has no correct viewinv */ invert_m4_m4(oldviewinv, re->viewmat); envre = envmap_render_copy(re, env); - + /* precalc orthmat for object */ copy_m4_m4(orthmat, env->object->obmat); normalize_m4(orthmat); - + /* need imat later for texture imat */ mul_m4_m4m4(mat, re->viewmat, orthmat); invert_m4_m4(tmat, mat); @@ -465,9 +465,9 @@ static void render_envmap(Render *re, EnvMap *env) for (part = 0; part < 6; part++) { if (env->type == ENV_PLANE && part != 1) continue; - + re->display_clear(re->dch, envre->result); - + copy_m4_m4(tmat, orthmat); envmap_transmatrix(tmat, part); invert_m4_m4(mat, tmat); @@ -475,20 +475,20 @@ static void render_envmap(Render *re, EnvMap *env) copy_m4_m4(envre->viewmat, mat); copy_m4_m4(envre->viewinv, tmat); - + /* we have to correct for the already rotated vertexcoords */ mul_m4_m4m4(tmat, envre->viewmat, oldviewinv); invert_m4_m4(env->imat, tmat); - + env_rotate_scene(envre, tmat, 1); project_renderdata(envre, projectverto, 0, 0, 1); env_layerflags(envre, env->notlay); env_hideobject(envre, env->object); - + if (re->test_break(re->tbh) == 0) { RE_TileProcessor(envre); } - + /* rotate back */ env_showobjects(envre); env_rotate_scene(envre, tmat, 0); @@ -510,26 +510,26 @@ static void render_envmap(Render *re, EnvMap *env) rect = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, ""); ibuf = IMB_allocImBuf(envre->rectx, envre->recty, 24, IB_rect | IB_rectfloat); memcpy(ibuf->rect_float, rect, ibuf->channels * ibuf->x * ibuf->y * sizeof(float)); - + /* envmap renders without alpha */ alpha = ibuf->rect_float + 3; for (y = ibuf->x * ibuf->y - 1; y >= 0; y--, alpha += 4) *alpha = 1.0; - + env->cube[part] = ibuf; } - + if (re->test_break(re->tbh)) break; } - + if (re->test_break(re->tbh)) BKE_texture_envmap_free_data(env); else { if (envre->r.mode & R_OSA) env->ok = ENV_OSA; else env->ok = ENV_NORMAL; env->lastframe = re->scene->r.cfra; } - + /* restore */ envmap_free_render_copy(envre); env_set_imats(re); @@ -543,16 +543,16 @@ void make_envmaps(Render *re) Tex *tex; bool do_init = false; int depth = 0, trace; - + if (!(re->r.mode & R_ENVMAP)) return; - + /* we don't raytrace, disabling the flag will cause ray_transp render solid */ trace = (re->r.mode & R_RAYTRACE); re->r.mode &= ~R_RAYTRACE; re->i.infostr = IFACE_("Creating Environment maps"); re->stats_draw(re->sdh, &re->i); - + /* 5 = hardcoded max recursion level */ while (depth < 5) { tex = re->main->tex.first; @@ -560,27 +560,27 @@ void make_envmaps(Render *re) if (tex->id.us && tex->type == TEX_ENVMAP) { if (tex->env && tex->env->object) { EnvMap *env = tex->env; - + if (env->object->lay & re->lay) { if (env->stype == ENV_LOAD) { float orthmat[4][4], mat[4][4], tmat[4][4]; - + /* precalc orthmat for object */ copy_m4_m4(orthmat, env->object->obmat); normalize_m4(orthmat); - + /* need imat later for texture imat */ mul_m4_m4m4(mat, re->viewmat, orthmat); invert_m4_m4(tmat, mat); copy_m3_m4(env->obimat, tmat); } else { - + /* decide if to render an envmap (again) */ if (env->depth >= depth) { - + /* set 'recalc' to make sure it does an entire loop of recalcs */ - + if (env->ok) { /* free when OSA, and old one isn't OSA */ if ((re->r.mode & R_OSA) && env->ok == ENV_NORMAL) @@ -592,13 +592,13 @@ void make_envmaps(Render *re) else if (env->recalc) BKE_texture_envmap_free_data(env); } - + if (env->ok == 0 && depth == 0) env->recalc = 1; - + if (env->ok == 0) { do_init = true; render_envmap(re, env); - + if (depth == env->depth) env->recalc = 0; } } @@ -627,10 +627,10 @@ static int envcube_isect(EnvMap *env, const float vec[3], float answ[2]) { float lambda; int face; - + if (env->type == ENV_PLANE) { face = 1; - + lambda = 1.0f / vec[2]; answ[0] = env->viewscale * lambda * vec[0]; answ[1] = -env->viewscale * lambda * vec[1]; @@ -674,7 +674,7 @@ static int envcube_isect(EnvMap *env, const float vec[3], float answ[2]) answ[1] = lambda * vec[2]; } } - + answ[0] = 0.5f + 0.5f * answ[0]; answ[1] = 0.5f + 0.5f * answ[1]; return face; @@ -714,13 +714,13 @@ int envmaptex(Tex *tex, const float texvec[3], float dxt[3], float dyt[3], int o ImBuf *ibuf; float fac, vec[3], sco[3], dxts[3], dyts[3]; int face, face1; - + env = tex->env; if (env == NULL || (env->stype != ENV_LOAD && env->object == NULL)) { texres->tin = 0.0; return 0; } - + if (env->stype == ENV_LOAD) { env->ima = tex->ima; if (env->ima && env->ima->ok) { @@ -743,7 +743,7 @@ int envmaptex(Tex *tex, const float texvec[3], float dxt[3], float dyt[3], int o texres->tin = 0.0; return 0; } - + /* rotate to envmap space, if object is set */ copy_v3_v3(vec, texvec); if (env->object) { @@ -763,46 +763,46 @@ int envmaptex(Tex *tex, const float texvec[3], float dxt[3], float dyt[3], int o } } } - + face = envcube_isect(env, vec, sco); ibuf = env->cube[face]; - + if (osatex) { set_dxtdyt(dxts, dyts, dxt, dyt, face); imagewraposa(tex, NULL, ibuf, sco, dxts, dyts, texres, pool, skip_load_image); - + /* edges? */ - + if (texres->ta < 1.0f) { TexResult texr1, texr2; - + texr1.nor = texr2.nor = NULL; texr1.talpha = texr2.talpha = texres->talpha; /* boxclip expects this initialized */ add_v3_v3(vec, dxt); face1 = envcube_isect(env, vec, sco); sub_v3_v3(vec, dxt); - + if (face != face1) { ibuf = env->cube[face1]; set_dxtdyt(dxts, dyts, dxt, dyt, face1); imagewraposa(tex, NULL, ibuf, sco, dxts, dyts, &texr1, pool, skip_load_image); } else texr1.tr = texr1.tg = texr1.tb = texr1.ta = 0.0; - + /* here was the nasty bug! results were not zero-ed. FPE! */ - + add_v3_v3(vec, dyt); face1 = envcube_isect(env, vec, sco); sub_v3_v3(vec, dyt); - + if (face != face1) { ibuf = env->cube[face1]; set_dxtdyt(dxts, dyts, dxt, dyt, face1); imagewraposa(tex, NULL, ibuf, sco, dxts, dyts, &texr2, pool, skip_load_image); } else texr2.tr = texr2.tg = texr2.tb = texr2.ta = 0.0; - + fac = (texres->ta + texr1.ta + texr2.ta); if (fac != 0.0f) { fac = 1.0f / fac; @@ -817,6 +817,6 @@ int envmaptex(Tex *tex, const float texvec[3], float dxt[3], float dyt[3], int o else { imagewrap(tex, NULL, ibuf, sco, texres, pool, skip_load_image); } - + return 1; } diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c index fdf914102b0..b99ab611458 100644 --- a/source/blender/render/intern/source/external_engine.c +++ b/source/blender/render/intern/source/external_engine.c @@ -114,11 +114,11 @@ void RE_engines_exit(void) RenderEngineType *RE_engines_find(const char *idname) { RenderEngineType *type; - + type = BLI_findstring(&R_engines, idname, offsetof(RenderEngineType, idname)); if (!type) type = &internal_render_type; - + return type; } @@ -315,7 +315,7 @@ int RE_engine_test_break(RenderEngine *engine) if (re) return re->test_break(re->tbh); - + return 0; } @@ -769,7 +769,7 @@ 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); diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c index 1a7d9aeddf2..1f1e900ba04 100644 --- a/source/blender/render/intern/source/imagetexture.c +++ b/source/blender/render/intern/source/imagetexture.c @@ -32,7 +32,7 @@ #include #include #include -#ifndef WIN32 +#ifndef WIN32 #include #else #include @@ -72,7 +72,7 @@ static void boxsample(ImBuf *ibuf, float minx, float miny, float maxx, float max static void ibuf_get_color(float col[4], struct ImBuf *ibuf, int x, int y) { int ofs = y * ibuf->x + x; - + if (ibuf->rect_float) { if (ibuf->channels==4) { const float *fp= ibuf->rect_float + 4*ofs; @@ -110,15 +110,15 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul int xi, yi; /* original values */ texres->tin= texres->ta= texres->tr= texres->tg= texres->tb= 0.0f; - + /* we need to set retval OK, otherwise texture code generates normals itself... */ retval= texres->nor ? 3 : 1; - + /* quick tests */ if (ibuf==NULL && ima==NULL) return retval; if (ima) { - + /* hack for icon render */ if (skip_load_image && !BKE_image_has_loaded_ibuf(ima)) return retval; @@ -132,7 +132,7 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul BKE_image_pool_release_ibuf(ima, ibuf, pool); return retval; } - + /* setup mapping */ if (tex->imaflag & TEX_IMAROT) { fy= texvec[0]; @@ -142,10 +142,10 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul fx= texvec[0]; fy= texvec[1]; } - + if (tex->extend == TEX_CHECKER) { int xs, ys; - + xs= (int)floor(fx); ys= (int)floor(fy); fx-= xs; @@ -210,7 +210,7 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul if (y<0) y+= ibuf->y; } } - + /* warning, no return before setting back! */ if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) { ibuf->rect+= (ibuf->x*ibuf->y); @@ -242,7 +242,7 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul else { /* no filtering */ ibuf_get_color(&texres->tr, ibuf, x, y); } - + if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) { ibuf->rect-= (ibuf->x*ibuf->y); } @@ -297,7 +297,7 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul else { texres->ta = texres->tin = 1.0; } - + if (tex->flag & TEX_NEGALPHA) { texres->ta = 1.0f - texres->ta; } @@ -315,7 +315,7 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul BKE_image_pool_release_ibuf(ima, ibuf, pool); BRICONTRGB; - + return retval; } @@ -341,9 +341,9 @@ static void clipx_rctf_swap(rctf *stack, short *count, float x1, float x2) newrct->xmin = rf->xmin+(x2-x1); newrct->ymin = rf->ymin; newrct->ymax = rf->ymax; - + if (newrct->xmin ==newrct->xmax) (*count)--; - + rf->xmin = x1; } } @@ -503,7 +503,7 @@ static void boxsampleclip(struct ImBuf *ibuf, rctf *rf, TexResult *texres) else { div= texres->tr= texres->tg= texres->tb= texres->ta= 0.0; for (y=starty; y<=endy; y++) { - + muly= 1.0; if (starty==endy) { @@ -513,10 +513,10 @@ static void boxsampleclip(struct ImBuf *ibuf, rctf *rf, TexResult *texres) if (y==starty) muly= 1.0f-(rf->ymin - y); if (y==endy) muly= (rf->ymax - y); } - + if (startx==endx) { mulx= muly; - + ibuf_get_color(col, ibuf, startx, y); texres->ta+= mulx*col[3]; @@ -532,7 +532,7 @@ static void boxsampleclip(struct ImBuf *ibuf, rctf *rf, TexResult *texres) if (x==endx) mulx*= (rf->xmax - x); ibuf_get_color(col, ibuf, x, y); - + if (mulx==1.0f) { texres->ta+= col[3]; texres->tr+= col[0]; @@ -587,7 +587,7 @@ static void boxsample(ImBuf *ibuf, float minx, float miny, float maxx, float max rf->ymax = maxy*(ibuf->y); texr.talpha= texres->talpha; /* is read by boxsample_clip */ - + if (imapextend) { CLAMP(rf->xmin, 0.0f, ibuf->x-1); CLAMP(rf->xmax, 0.0f, ibuf->x-1); @@ -622,7 +622,7 @@ static void boxsample(ImBuf *ibuf, float minx, float miny, float maxx, float max tot= texres->tr= texres->tb= texres->tg= texres->ta= 0.0; while (count--) { boxsampleclip(ibuf, rf, &texr); - + opp= square_rctf(rf); tot+= opp; @@ -643,7 +643,7 @@ static void boxsample(ImBuf *ibuf, float minx, float miny, float maxx, float max boxsampleclip(ibuf, rf, texres); if (texres->talpha==0) texres->ta= 1.0; - + if (alphaclip!=1.0f) { /* premul it all */ texres->tr*= alphaclip; @@ -651,7 +651,7 @@ static void boxsample(ImBuf *ibuf, float minx, float miny, float maxx, float max texres->tb*= alphaclip; texres->ta*= alphaclip; } -} +} /*----------------------------------------------------------------------------------------------------------------- * from here, some functions only used for the new filtering */ @@ -888,7 +888,7 @@ static void image_mipmap_test(Tex *tex, ImBuf *ibuf) { if (tex->imaflag & TEX_MIPMAP) { if ((ibuf->flags & IB_fields) == 0) { - + if (ibuf->mipmap[0] && (ibuf->userflags & IB_MIPMAP_INVALID)) { BLI_thread_lock(LOCK_IMAGE); if (ibuf->userflags & IB_MIPMAP_INVALID) { @@ -899,7 +899,7 @@ static void image_mipmap_test(Tex *tex, ImBuf *ibuf) } if (ibuf->mipmap[0] == NULL) { BLI_thread_lock(LOCK_IMAGE); - if (ibuf->mipmap[0] == NULL) + if (ibuf->mipmap[0] == NULL) IMB_makemipmap(ibuf, tex->imaflag & TEX_GAUSS_MIP); BLI_thread_unlock(LOCK_IMAGE); } @@ -909,7 +909,7 @@ static void image_mipmap_test(Tex *tex, ImBuf *ibuf) } } } - + } static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], float dxt[2], float dyt[2], TexResult *texres, struct ImagePool *pool, const bool skip_load_image) @@ -960,7 +960,7 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex /* mipmap test */ image_mipmap_test(tex, ibuf); - + if (ima) { if ((tex->imaflag & TEX_USEALPHA) && (ima->flag & IMA_IGNORE_ALPHA) == 0) { if ((tex->imaflag & TEX_CALCALPHA) == 0) { @@ -1310,7 +1310,7 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex else texres->tin = texres->ta; if (tex->flag & TEX_NEGALPHA) texres->ta = 1.f - texres->ta; - + if ((R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields)) ibuf->rect -= ibuf->x*ibuf->y; @@ -1344,7 +1344,7 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex BKE_image_pool_release_ibuf(ima, ibuf, pool); BRICONTRGB; - + return retval; } @@ -1366,10 +1366,10 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const return imagewraposa_aniso(tex, ima, ibuf, texvec, dxt, dyt, texres, pool, skip_load_image); texres->tin= texres->ta= texres->tr= texres->tg= texres->tb= 0.0f; - + /* we need to set retval OK, otherwise texture code generates normals itself... */ retval = texres->nor ? 3 : 1; - + /* quick tests */ if (ibuf==NULL && ima==NULL) return retval; @@ -1378,7 +1378,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const /* hack for icon render */ if (skip_load_image && !BKE_image_has_loaded_ibuf(ima)) return retval; - + ibuf = BKE_image_pool_acquire_ibuf(ima, &tex->iuser, pool); ima->flag|= IMA_USED_FOR_RENDER; @@ -1388,7 +1388,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const BKE_image_pool_release_ibuf(ima, ibuf, pool); return retval; } - + /* mipmap test */ image_mipmap_test(tex, ibuf); @@ -1399,9 +1399,9 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const } } } - + texr.talpha= texres->talpha; - + if (tex->imaflag & TEX_IMAROT) { fy= texvec[0]; fx= texvec[1]; @@ -1410,7 +1410,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const fx= texvec[0]; fy= texvec[1]; } - + if (ibuf->flags & IB_fields) { if (R.r.mode & R_FIELDS) { /* field render */ if (R.flag & R_SEC_FIELD) { /* correction for 2nd field */ @@ -1422,7 +1422,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const } } } - + /* pixel coordinates */ minx = min_fff(dxt[0], dyt[0], dxt[0] + dyt[0]); @@ -1433,7 +1433,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const /* tex_sharper has been removed */ minx= (maxx-minx)/2.0f; miny= (maxy-miny)/2.0f; - + if (tex->imaflag & TEX_FILTER_MIN) { /* make sure the filtersize is minimal in pixels (normal, ref map can have miniature pixel dx/dy) */ float addval= (0.5f * tex->filtersize) / (float) MIN2(ibuf->x, ibuf->y); @@ -1446,7 +1446,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const else if (tex->filtersize!=1.0f) { minx*= tex->filtersize; miny*= tex->filtersize; - + dxt[0]*= tex->filtersize; dxt[1]*= tex->filtersize; dyt[0]*= tex->filtersize; @@ -1454,13 +1454,13 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const } if (tex->imaflag & TEX_IMAROT) SWAP(float, minx, miny); - + if (minx>0.25f) minx= 0.25f; else if (minx<0.00001f) minx= 0.00001f; /* side faces of unit-cube */ if (miny>0.25f) miny= 0.25f; else if (miny<0.00001f) miny= 0.00001f; - + /* repeat and clip */ imaprepeat= (tex->extend==TEX_REPEAT); imapextend= (tex->extend==TEX_EXTEND); @@ -1474,10 +1474,10 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const if (tex->extend == TEX_CHECKER) { int xs, ys, xs1, ys1, xs2, ys2, boundary; - + xs= (int)floor(fx); ys= (int)floor(fy); - + /* both checkers available, no boundary exceptions, checkerdist will eat aliasing */ if ( (tex->flag & TEX_CHECKER_ODD) && (tex->flag & TEX_CHECKER_EVEN) ) { fx-= xs; @@ -1491,7 +1491,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const return retval; } else { - + xs1= (int)floor(fx-minx); ys1= (int)floor(fy-miny); xs2= (int)floor(fx+minx); @@ -1523,14 +1523,14 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const if (tex->flag & TEX_CHECKER_ODD) { if ((xs1+ys) & 1) fx-= xs2; else fx-= xs1; - + if ((ys1+xs) & 1) fy-= ys2; else fy-= ys1; } if (tex->flag & TEX_CHECKER_EVEN) { if ((xs1+ys) & 1) fx-= xs1; else fx-= xs2; - + if ((ys1+xs) & 1) fy-= ys1; else fy-= ys2; } @@ -1569,7 +1569,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const if (fx>1.0f) fx -= (int)(fx); else if (fx<0.0f) fx+= 1-(int)(fx); } - + if (imapextend) { if (fy>1.0f) fy = 1.0f; else if (fy<0.0f) fy= 0.0f; @@ -1589,18 +1589,18 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const if (tex->imaflag & TEX_MIPMAP) { ImBuf *previbuf, *curibuf; float bumpscale; - + dx = minx; dy = miny; maxd = max_ff(dx, dy); if (maxd > 0.5f) maxd = 0.5f; pixsize = 1.0f / (float) MIN2(ibuf->x, ibuf->y); - + bumpscale= pixsize/maxd; if (bumpscale>1.0f) bumpscale= 1.0f; else bumpscale*=bumpscale; - + curmap= 0; previbuf= curibuf= ibuf; while (curmap < IMB_MIPMAP_LEVELS && ibuf->mipmap[curmap]) { @@ -1616,12 +1616,12 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const if (minx < 0.5f / ibuf->x) minx = 0.5f / ibuf->x; if (miny < 0.5f / ibuf->y) miny = 0.5f / ibuf->y; } - + if (texres->nor && (tex->imaflag & TEX_NORMALMAP)==0) { /* a bit extra filter */ //minx*= 1.35f; //miny*= 1.35f; - + boxsample(curibuf, fx-minx, fy-miny, fx+minx, fy+miny, texres, imaprepeat, imapextend); val1= texres->tr+texres->tg+texres->tb; boxsample(curibuf, fx-minx+dxt[0], fy-miny+dxt[1], fx+minx+dxt[0], fy+miny+dxt[1], &texr, imaprepeat, imapextend); @@ -1632,11 +1632,11 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const /* don't switch x or y! */ texres->nor[0]= (val1-val2); texres->nor[1]= (val1-val3); - + if (previbuf!=curibuf) { /* interpolate */ - + boxsample(previbuf, fx-minx, fy-miny, fx+minx, fy+miny, &texr, imaprepeat, imapextend); - + /* calc rgb */ dx= 2.0f*(pixsize-maxd)/pixsize; if (dx>=1.0f) { @@ -1650,16 +1650,16 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const texres->tr= dy*texres->tr+ dx*texr.tr; texres->ta= dy*texres->ta+ dx*texr.ta; } - + val1= dy*val1+ dx*(texr.tr + texr.tg + texr.tb); boxsample(previbuf, fx-minx+dxt[0], fy-miny+dxt[1], fx+minx+dxt[0], fy+miny+dxt[1], &texr, imaprepeat, imapextend); val2= dy*val2+ dx*(texr.tr + texr.tg + texr.tb); boxsample(previbuf, fx-minx+dyt[0], fy-miny+dyt[1], fx+minx+dyt[0], fy+miny+dyt[1], &texr, imaprepeat, imapextend); val3= dy*val3+ dx*(texr.tr + texr.tg + texr.tb); - + texres->nor[0]= (val1-val2); /* vals have been interpolated above! */ texres->nor[1]= (val1-val3); - + if (dx<1.0f) { dy= 1.0f-dx; texres->tb= dy*texres->tb+ dx*texr.tb; @@ -1681,9 +1681,9 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const if (previbuf!=curibuf) { /* interpolate */ boxsample(previbuf, minx, miny, maxx, maxy, &texr, imaprepeat, imapextend); - + fx= 2.0f*(pixsize-maxd)/pixsize; - + if (fx>=1.0f) { texres->ta= texr.ta; texres->tb= texr.tb; texres->tg= texr.tg; texres->tr= texr.tr; @@ -1721,7 +1721,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const else boxsample(ibuf, fx-minx, fy-miny, fx+minx, fy+miny, texres, imaprepeat, imapextend); } - + if (tex->imaflag & TEX_CALCALPHA) { texres->ta = texres->tin = texres->ta * max_fff(texres->tr, texres->tg, texres->tb); } @@ -1730,7 +1730,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const } if (tex->flag & TEX_NEGALPHA) texres->ta= 1.0f-texres->ta; - + if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) { ibuf->rect-= (ibuf->x*ibuf->y); } @@ -1758,7 +1758,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const BKE_image_pool_release_ibuf(ima, ibuf, pool); BRICONTRGB; - + return retval; } @@ -1766,19 +1766,19 @@ void image_sample(Image *ima, float fx, float fy, float dx, float dy, float resu { TexResult texres; ImBuf *ibuf = BKE_image_pool_acquire_ibuf(ima, NULL, pool); - + if (UNLIKELY(ibuf == NULL)) { zero_v4(result); return; } - + if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) ibuf->rect+= (ibuf->x*ibuf->y); texres.talpha = true; /* boxsample expects to be initialized */ boxsample(ibuf, fx, fy, fx + dx, fy + dy, &texres, 0, 1); copy_v4_v4(result, &texres.tr); - + if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) ibuf->rect-= (ibuf->x*ibuf->y); @@ -1796,11 +1796,11 @@ void ibuf_sample(ImBuf *ibuf, float fx, float fy, float dx, float dy, float resu AFD.dyt[0] = dy; AFD.dyt[1] = dy; //copy_v2_v2(AFD.dxt, dx); //copy_v2_v2(AFD.dyt, dy); - + AFD.intpol = 1; AFD.extflag = TXC_EXTD; ewa_eval(&texres, ibuf, fx, fy, &AFD); - + copy_v4_v4(result, &texres.tr); } diff --git a/source/blender/render/intern/source/initrender.c b/source/blender/render/intern/source/initrender.c index ce3331e9a92..34e47a00c7a 100644 --- a/source/blender/render/intern/source/initrender.c +++ b/source/blender/render/intern/source/initrender.c @@ -64,18 +64,18 @@ static void init_render_jit(Render *re) static float mblur_jit[32][2]; /* simple caching */ static int lastjit = 0; static int last_mblur_jit = 0; - + if (lastjit != re->r.osa || last_mblur_jit != re->r.mblur_samples) { memset(jit, 0, sizeof(jit)); BLI_jitter_init(jit, re->r.osa); - + memset(mblur_jit, 0, sizeof(mblur_jit)); BLI_jitter_init(mblur_jit, re->r.mblur_samples); } - + lastjit = re->r.osa; memcpy(re->jit, jit, sizeof(jit)); - + last_mblur_jit = re->r.mblur_samples; memcpy(re->mblur_jit, mblur_jit, sizeof(mblur_jit)); } @@ -95,9 +95,9 @@ static float filt_quadratic(float x) static float filt_cubic(float x) { float x2 = x * x; - + if (x < 0.0f) x = -x; - + if (x < 1.0f) return 0.5f * x * x2 - x2 + 2.0f / 3.0f; if (x < 2.0f) return (2.0f - x) * (2.0f - x) * (2.0f - x) / 6.0f; return 0.0f; @@ -107,7 +107,7 @@ static float filt_cubic(float x) static float filt_catrom(float x) { float x2 = x * x; - + if (x < 0.0f) x = -x; if (x < 1.0f) return 1.5f * x2 * x - 2.5f * x2 + 1.0f; if (x < 2.0f) return -0.5f * x2 * x + 2.5f * x2 - 4.0f * x + 2.0f; @@ -137,34 +137,34 @@ static float filt_mitchell(float x) /* Mitchell & Netravali's two-param cubic */ float RE_filter_value(int type, float x) { float gaussfac = 1.6f; - + x = ABS(x); - + switch (type) { case R_FILTER_BOX: if (x > 1.0f) return 0.0f; return 1.0f; - + case R_FILTER_TENT: if (x > 1.0f) return 0.0f; return 1.0f - x; - + case R_FILTER_GAUSS: { const float two_gaussfac2 = 2.0f * gaussfac * gaussfac; x *= 3.0f * gaussfac; return 1.0f / sqrtf((float)M_PI * two_gaussfac2) * expf(-x*x / two_gaussfac2); } - + case R_FILTER_MITCH: return filt_mitchell(x * gaussfac); - + case R_FILTER_QUAD: return filt_quadratic(x * gaussfac); - + case R_FILTER_CUBIC: return filt_cubic(x * gaussfac); - + case R_FILTER_CATROM: return filt_catrom(x * gaussfac); } @@ -188,35 +188,35 @@ static float calc_weight(Render *re, float *weight, int i, int j) case R_FILTER_BOX: if (i == 0 && j == 0) weight[a] = 1.0; break; - + case R_FILTER_TENT: if (dist < re->r.gauss) weight[a] = re->r.gauss - dist; break; - + case R_FILTER_GAUSS: x = dist * re->r.gauss; weight[a] = (1.0f / expf(x * x) - 1.0f / expf(re->r.gauss * re->r.gauss * 2.25f)); break; - + case R_FILTER_MITCH: weight[a] = filt_mitchell(dist * re->r.gauss); break; - + case R_FILTER_QUAD: weight[a] = filt_quadratic(dist * re->r.gauss); break; - + case R_FILTER_CUBIC: weight[a] = filt_cubic(dist * re->r.gauss); break; - + case R_FILTER_CATROM: weight[a] = filt_catrom(dist * re->r.gauss); break; - + } - + totw += weight[a]; } @@ -226,13 +226,13 @@ static float calc_weight(Render *re, float *weight, int i, int j) void free_sample_tables(Render *re) { int a; - + if (re->samples) { for (a = 0; a < 9; a++) { MEM_freeN(re->samples->fmask1[a]); MEM_freeN(re->samples->fmask2[a]); } - + MEM_freeN(re->samples->centmask); MEM_freeN(re->samples); re->samples = NULL; @@ -252,19 +252,19 @@ void make_sample_tables(Render *re) if (firsttime) { firsttime = 0; } - + free_sample_tables(re); - + init_render_jit(re); /* needed for mblur too */ - + if (re->osa == 0) { /* just prevents cpu cycles for larger render and copying */ re->r.filtertype = 0; return; } - + st = re->samples = MEM_callocN(sizeof(SampleTables), "sample tables"); - + for (a = 0; a < 9; a++) { st->fmask1[a] = MEM_callocN(256 * sizeof(float), "initfilt"); st->fmask2[a] = MEM_callocN(256 * sizeof(float), "initfilt"); @@ -280,10 +280,10 @@ void make_sample_tables(Render *re) if (a & 64) st->cmask[a]++; if (a & 128) st->cmask[a]++; } - + centmasksize = (1 << re->osa); st->centmask = MEM_mallocN(centmasksize, "Initfilt3"); - + for (a = 0; a < 16; a++) { st->centLut[a] = -0.45f + ((float)a) / 16.0f; } @@ -457,7 +457,7 @@ void RE_SetEnvmapCamera(Render *re, Object *cam_ob, float viewscale, float clips params.sensor_fit = CAMERA_SENSOR_FIT_AUTO; params.clipsta = clipsta; params.clipend = clipend; - + /* compute matrix, viewplane, .. */ BKE_camera_params_compute_viewplane(¶ms, re->winx, re->winy, 1.0f, 1.0f); BKE_camera_params_compute_matrix(¶ms); @@ -523,7 +523,7 @@ void RE_GetCameraModelMatrix(Render *re, struct Object *camera, float r_mat[4][4 void RE_parts_free(Render *re) { RenderPart *part = re->parts.first; - + while (part) { if (part->rectp) MEM_freeN(part->rectp); if (part->rectz) MEM_freeN(part->rectz); @@ -543,20 +543,20 @@ void RE_parts_init(Render *re, bool do_crop) { int nr, xd, yd, partx, party, xparts, yparts; int xminb, xmaxb, yminb, ymaxb; - + RE_parts_free(re); - + /* this is render info for caller, is not reset when parts are freed! */ re->i.totpart = 0; re->i.curpart = 0; re->i.partsdone = 0; - + /* just for readable code.. */ xminb = re->disprect.xmin; yminb = re->disprect.ymin; xmaxb = re->disprect.xmax; ymaxb = re->disprect.ymax; - + RE_parts_clamp(re); partx = re->partx; @@ -564,21 +564,21 @@ void RE_parts_init(Render *re, bool do_crop) /* part count */ xparts = (re->rectx + partx - 1) / partx; yparts = (re->recty + party - 1) / party; - + /* calculate rotation factor of 1 pixel */ if (re->r.mode & R_PANORAMA) re->panophi = panorama_pixel_rot(re); - + for (nr = 0; nr < xparts * yparts; nr++) { rcti disprect; int rectx, recty; - + xd = (nr % xparts); yd = (nr - xd) / xparts; - + disprect.xmin = xminb + xd * partx; disprect.ymin = yminb + yd * party; - + /* ensure we cover the entire picture, so last parts go to end */ if (xd < xparts - 1) { disprect.xmax = disprect.xmin + partx; @@ -586,21 +586,21 @@ void RE_parts_init(Render *re, bool do_crop) disprect.xmax = xmaxb; } else disprect.xmax = xmaxb; - + if (yd < yparts - 1) { disprect.ymax = disprect.ymin + party; if (disprect.ymax > ymaxb) disprect.ymax = ymaxb; } else disprect.ymax = ymaxb; - + rectx = BLI_rcti_size_x(&disprect); recty = BLI_rcti_size_y(&disprect); - + /* so, now can we add this part? */ if (rectx > 0 && recty > 0) { RenderPart *pa = MEM_callocN(sizeof(RenderPart), "new part"); - + /* Non-box filters need 2 pixels extra to work */ if (do_crop && (re->r.filtertype || (re->r.mode & R_EDGE))) { pa->crop = 2; diff --git a/source/blender/render/intern/source/multires_bake.c b/source/blender/render/intern/source/multires_bake.c index d85cc87dfe3..6f66f6d3520 100644 --- a/source/blender/render/intern/source/multires_bake.c +++ b/source/blender/render/intern/source/multires_bake.c @@ -1283,7 +1283,7 @@ static void finish_images(MultiresBakeRender *bkr, MultiresBakeResult *result) } BKE_image_release_ibuf(ima, ibuf, NULL); - DAG_id_tag_update(&ima->id, 0); + DAG_id_tag_update(&ima->id, 0); } } diff --git a/source/blender/render/intern/source/occlusion.c b/source/blender/render/intern/source/occlusion.c index 42200a8278c..8aa90a390b3 100644 --- a/source/blender/render/intern/source/occlusion.c +++ b/source/blender/render/intern/source/occlusion.c @@ -99,7 +99,7 @@ typedef struct OcclusionTree { OccFace *face; /* instance and face indices */ float *occlusion; /* occlusion for faces */ float (*rad)[3]; /* radiance for faces */ - + OccNode *root; OccNode **stack[BLENDER_MAX_THREADS]; @@ -144,7 +144,7 @@ static void occ_shade(ShadeSample *ssamp, ObjectInstanceRen *obi, VlakRen *vlr, ShadeInput *shi = ssamp->shi; ShadeResult *shr = ssamp->shr; float l, u, v, *v1, *v2, *v3; - + /* init */ if (vlr->v4) { shi->u = u = 0.5f; @@ -159,10 +159,10 @@ static void occ_shade(ShadeSample *ssamp, ObjectInstanceRen *obi, VlakRen *vlr, v1 = vlr->v1->co; v2 = vlr->v2->co; v3 = vlr->v3->co; - + /* renderco */ l = 1.0f - u - v; - + shi->co[0] = l * v3[0] + u * v1[0] + v * v2[0]; shi->co[1] = l * v3[1] + u * v1[1] + v * v2[1]; shi->co[2] = l * v3[2] + u * v1[2] + v * v2[2]; @@ -172,13 +172,13 @@ static void occ_shade(ShadeSample *ssamp, ObjectInstanceRen *obi, VlakRen *vlr, /* set up view vector */ copy_v3_v3(shi->view, shi->co); normalize_v3(shi->view); - + /* cache for shadow */ shi->samplenr++; shi->xs = 0; /* TODO */ shi->ys = 0; - + shade_input_set_normals(shi); /* no normal flip */ @@ -324,7 +324,7 @@ static void occ_face(const OccFace *face, float co[3], float normal[3], float *a obi = &R.objectinstance[face->obi]; vlr = RE_findOrAddVlak(obi->obr, face->facenr); - + if (co) { if (vlr->v4) mid_v3_v3v3(co, vlr->v1->co, vlr->v3->co); @@ -334,7 +334,7 @@ static void occ_face(const OccFace *face, float co[3], float normal[3], float *a if (obi->flag & R_TRANSFORMED) mul_m4_v3(obi->mat, co); } - + if (normal) { normal[0] = -vlr->n[0]; normal[1] = -vlr->n[1]; @@ -397,7 +397,7 @@ static void occ_sum_occlusion(OcclusionTree *tree, OccNode *node) occ /= totarea; if (indirect) mul_v3_fl(rad, 1.0f / totarea); } - + node->occlusion = occ; if (indirect) copy_v3_v3(node->rad, rad); } @@ -668,7 +668,7 @@ static OcclusionTree *occ_tree_build(Render *re) if (totface == 0) return NULL; - + tree = MEM_callocN(sizeof(OcclusionTree), "OcclusionTree"); tree->totface = totface; @@ -704,7 +704,7 @@ static OcclusionTree *occ_tree_build(Render *re) tree->face[b].obi = c; tree->face[b].facenr = a; tree->occlusion[b] = 1.0f; - occ_face(&tree->face[b], tree->co[b], NULL, NULL); + occ_face(&tree->face[b], tree->co[b], NULL, NULL); b++; } } @@ -726,7 +726,7 @@ static OcclusionTree *occ_tree_build(Render *re) if (!(re->test_break(re->tbh))) occ_sum_occlusion(tree, tree->root); } - + MEM_freeN(tree->co); tree->co = NULL; @@ -773,7 +773,7 @@ static float occ_solid_angle(OccNode *node, const float v[3], float d2, float in CLAMP(dotemit, 0.0f, 1.0f); CLAMP(dotreceive, 0.0f, 1.0f); - + return ((node->area * dotemit * dotreceive) / (d2 + node->area * INVPI)) * INVPI; } @@ -827,7 +827,7 @@ static void occ_lookup(OcclusionTree *tree, int thread, OccFace *exclude, if (bentn) copy_v3_v3(bentn, n); - + error = tree->error; distfac = tree->distfac; @@ -883,7 +883,7 @@ static void occ_lookup(OcclusionTree *tree, int thread, OccFace *exclude, /* accumulate occlusion with face form factor */ if (!exclude || !(face->obi == exclude->obi && face->facenr == exclude->facenr)) { if (bentn || distfac != 0.0f) { - occ_face(face, co, NULL, NULL); + occ_face(face, co, NULL, NULL); sub_v3_v3v3(v, co, p); d2 = dot_v3v3(v, v) + 1e-16f; @@ -977,7 +977,7 @@ static void occ_compute_passes(Render *re, OcclusionTree *tree, int totpass) { float *occ, co[3], n[3]; int pass, i; - + occ = MEM_callocN(sizeof(float) * tree->totface, "OcclusionPassOcc"); for (pass = 0; pass < totpass; pass++) { @@ -1095,7 +1095,7 @@ static int sample_occ_cache(OcclusionTree *tree, float *co, float *n, int x, int if (!tree->cache) return 0; - + /* first try to find a sample in the same pixel */ cache = &tree->cache[thread]; @@ -1278,9 +1278,9 @@ void make_occ_tree(Render *re) re->i.infostr = IFACE_("Occlusion preprocessing"); re->stats_draw(re->sdh, &re->i); - + re->occlusiontree = tree = occ_tree_build(re); - + if (tree && !re->test_break(re->tbh)) { if (re->wrld.ao_approx_passes > 0) occ_compute_passes(re, tree, re->wrld.ao_approx_passes); diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 9e93a30d212..707f126b202 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -136,7 +136,7 @@ /* here we store all renders */ static struct { ListBase renderlist; -} RenderGlobal = {{NULL, NULL}}; +} RenderGlobal = {{NULL, NULL}}; /* hardcopy of current render, used while rendering for speed */ Render R; @@ -288,7 +288,7 @@ RenderLayer *render_get_active_layer(Render *re, RenderResult *rr) static int render_scene_needs_vector(Render *re) { SceneRenderLayer *srl; - + for (srl = re->r.layers.first; srl; srl = srl->next) if (!(srl->layflag & SCE_LAY_DISABLE)) if (srl->passflag & SCE_PASS_VECTOR) @@ -440,10 +440,10 @@ void RE_AcquireResultImage(Render *re, RenderResult *rr, const int view_id) if (re->result) { RenderLayer *rl; RenderView *rv; - + rr->rectx = re->result->rectx; rr->recty = re->result->recty; - + /* actview view */ rv = RE_RenderViewGetById(re->result, view_id); rr->have_combined = (rv->rectf != NULL); @@ -510,7 +510,7 @@ Render *RE_NewRender(const char *name) /* only one render per name exists */ re = RE_GetRender(name); if (re == NULL) { - + /* new render data struct */ re = MEM_callocN(sizeof(Render), "new render"); BLI_addtail(&RenderGlobal.renderlist, re); @@ -519,12 +519,12 @@ Render *RE_NewRender(const char *name) BLI_rw_mutex_init(&re->partsmutex); re->eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER); } - + RE_InitRenderCB(re); /* init some variables */ re->ycor = 1.0f; - + return re; } @@ -594,13 +594,13 @@ void RE_FreeRender(Render *re) /* main dbase can already be invalid now, some database-free code checks it */ re->main = NULL; re->scene = NULL; - + RE_Database_Free(re); /* view render can still have full database */ free_sample_tables(re); - + render_result_free(re->result); render_result_free(re->pushedresult); - + BLI_remlink(&RenderGlobal.renderlist, re); MEM_freeN(re->eval_ctx); MEM_freeN(re); @@ -750,7 +750,7 @@ void RE_InitState(Render *re, Render *source, RenderData *rd, bool had_freestyle = (re->r.mode & R_EDGE_FRS) != 0; re->ok = true; /* maybe flag */ - + re->i.starttime = PIL_check_seconds_timer(); /* copy render data and render layers for thread safety */ @@ -785,7 +785,7 @@ void RE_InitState(Render *re, Render *source, RenderData *rd, } re->r.scemode = check_mode_full_sample(&re->r); - + /* fullsample wants uniform osa levels */ if (source && (re->r.scemode & R_FULL_SAMPLE)) { /* but, if source has no full sample we disable it */ @@ -802,7 +802,7 @@ void RE_InitState(Render *re, Render *source, RenderData *rd, } else re->osa = 0; } - + if (srl) { int index = BLI_findindex(&rd->layers, srl); if (index != -1) { @@ -810,10 +810,10 @@ void RE_InitState(Render *re, Render *source, RenderData *rd, re->r.scemode |= R_SINGLE_LAYER; } } - + /* always call, checks for gamma, gamma tables and jitter too */ make_sample_tables(re); - + /* if preview render, we try to keep old result */ BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); @@ -846,7 +846,7 @@ void RE_InitState(Render *re, Render *source, RenderData *rd, } } else { - + /* make empty render result, so display callbacks can initialize */ render_result_free(re->result); re->result = MEM_callocN(sizeof(RenderResult), "new render result"); @@ -854,19 +854,19 @@ void RE_InitState(Render *re, Render *source, RenderData *rd, re->result->recty = re->recty; render_result_view_new(re->result, ""); } - + if (re->r.scemode & R_VIEWPORT_PREVIEW) re->eval_ctx->mode = DAG_EVAL_PREVIEW; else re->eval_ctx->mode = DAG_EVAL_RENDER; - + /* ensure renderdatabase can use part settings correct */ RE_parts_clamp(re); BLI_rw_mutex_unlock(&re->resultmutex); - + re->mblur_offs = re->field_offs = 0.f; - + RE_init_threadcount(re); } @@ -979,7 +979,7 @@ void render_update_anim_renderdata(Render *re, RenderData *rd) void RE_SetWindow(Render *re, const rctf *viewplane, float clipsta, float clipend) { /* re->ok flag? */ - + re->viewplane = *viewplane; re->clipsta = clipsta; re->clipend = clipend; @@ -988,13 +988,13 @@ void RE_SetWindow(Render *re, const rctf *viewplane, float clipsta, float clipen perspective_m4(re->winmat, re->viewplane.xmin, re->viewplane.xmax, re->viewplane.ymin, re->viewplane.ymax, re->clipsta, re->clipend); - + } void RE_SetOrtho(Render *re, const rctf *viewplane, float clipsta, float clipend) { /* re->ok flag? */ - + re->viewplane = *viewplane; re->clipsta = clipsta; re->clipend = clipend; @@ -1015,7 +1015,7 @@ void RE_SetView(Render *re, float mat[4][4]) void RE_GetViewPlane(Render *re, rctf *r_viewplane, rcti *r_disprect) { *r_viewplane = re->viewplane; - + /* make disprect zero when no border render, is needed to detect changes in 3d view render */ if (re->r.mode & R_BORDER) { *r_disprect = re->disprect; @@ -1082,7 +1082,7 @@ void RE_test_break_cb(Render *re, void *handle, int (*f)(void *handle)) #if 0 void RE_AddObject(Render *UNUSED(re), Object *UNUSED(ob)) { - + } #endif @@ -1106,7 +1106,7 @@ static void *do_part_thread(void *pa_v) /* need to return nicely all parts on esc */ if (R.test_break(R.tbh) == 0) { - + if (!R.sss_points && (R.r.scemode & R_FULL_SAMPLE)) pa->result = render_result_new_full_sample(&R, &pa->fullresult, &pa->disprect, pa->crop, RR_USE_MEM, R.viewname); else @@ -1126,11 +1126,11 @@ static void *do_part_thread(void *pa_v) zbufshadeDA_tile(pa); else zbufshade_tile(pa); - + /* we do actually write pixels, but don't allocate/deallocate anything, * so it is safe with other threads reading at the same time */ BLI_rw_mutex_lock(&R.resultmutex, THREAD_LOCK_READ); - + /* merge too on break! */ if (R.result->do_exr_tile) { render_result_exr_file_merge(R.result, pa->result, R.viewname); @@ -1144,12 +1144,12 @@ static void *do_part_thread(void *pa_v) render_result_merge(R.result, pa->result); } } - + BLI_rw_mutex_unlock(&R.resultmutex); } - + pa->status = PART_STATUS_MERGED; - + return NULL; } @@ -1161,21 +1161,21 @@ float panorama_pixel_rot(Render *re) float psize, phi, xfac; float borderfac = (float)BLI_rcti_size_x(&re->disprect) / (float)re->winx; int xparts = (re->rectx + re->partx - 1) / re->partx; - + /* size of 1 pixel mapped to viewplane coords */ 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_rctf_size_x(&re->viewplane) / (float)xparts; xfac = atan(0.5f * xfac / re->clipsta); /* and how much the same viewplane angle is wrapped */ psize = 0.5f * phi * ((float)re->partx); - + /* the ratio applied to final per-pixel angle */ phi *= xfac / psize; - + return phi; } @@ -1185,9 +1185,9 @@ static bool find_next_pano_slice(Render *re, int *slice, int *minx, rctf *viewpl { RenderPart *pa, *best = NULL; bool found = false; - + *minx = re->winx; - + if (!(re->r.mode & R_PANORAMA)) { /* for regular render, just one 'slice' */ found = (*slice == 0); @@ -1205,7 +1205,7 @@ static bool find_next_pano_slice(Render *re, int *slice, int *minx, rctf *viewpl } } } - + if (best) { float phi = panorama_pixel_rot(re); @@ -1217,15 +1217,15 @@ static bool find_next_pano_slice(Render *re, int *slice, int *minx, rctf *viewpl R.viewplane.xmax = viewplane->xmax + R.panodxv; RE_SetWindow(re, &R.viewplane, R.clipsta, R.clipend); copy_m4_m4(R.winmat, re->winmat); - + /* rotate database according to part coordinates */ project_renderdata(re, projectverto, 1, -R.panodxp * phi, 1); R.panosi = sinf(R.panodxp * phi); R.panoco = cosf(R.panodxp * phi); } - + (*slice)++; - + return found; } @@ -1251,7 +1251,7 @@ static int sort_and_queue_parts(Render *re, int minx, ThreadQueue *workqueue) /* long long int's needed because of overflow [#24414] */ long long int centx = re->winx / 2, centy = re->winy / 2, tot = 1; int totsort = 0; - + /* find center of rendered parts, image center counts for 1 too */ for (pa = re->parts.first; pa; pa = pa->next) { if (pa->status >= PART_STATUS_RENDERED) { @@ -1267,7 +1267,7 @@ static int sort_and_queue_parts(Render *re, int minx, ThreadQueue *workqueue) } centx /= tot; centy /= tot; - + if (totsort > 0) { SortRenderPart *sortlist = MEM_mallocN(sizeof(*sortlist) * totsort, "renderpartsort"); long int i = 0; @@ -1306,7 +1306,7 @@ static int sort_and_queue_parts(Render *re, int minx, ThreadQueue *workqueue) static void print_part_stats(Render *re, RenderPart *pa) { char str[64]; - + BLI_snprintf(str, sizeof(str), IFACE_("%s, Part %d-%d"), re->scene->id.name + 2, pa->nr, re->i.totpart); re->i.infostr = str; re->stats_draw(re->sdh, &re->i); @@ -1316,7 +1316,7 @@ static void print_part_stats(Render *re, RenderPart *pa) typedef struct RenderThread { ThreadQueue *workqueue; ThreadQueue *donequeue; - + int number; void (*display_update)(void *handle, RenderResult *rr, volatile rcti *rect); @@ -1327,7 +1327,7 @@ static void *do_render_thread(void *thread_v) { RenderThread *thread = thread_v; RenderPart *pa; - + while ((pa = BLI_thread_queue_pop(thread->workqueue))) { pa->thread = thread->number; do_part_thread(pa); @@ -1337,11 +1337,11 @@ static void *do_render_thread(void *thread_v) } BLI_thread_queue_push(thread->donequeue, pa); - + if (R.test_break(R.tbh)) break; } - + return NULL; } @@ -1395,33 +1395,33 @@ static void threaded_tile_processor(Render *re) rctf viewplane = re->viewplane; double lastdraw, elapsed, redrawtime = 1.0f; int totpart = 0, minx = 0, slice = 0, a, wait; - + if (re->result == NULL) return; /* warning; no return here without closing exr file */ RE_parts_init(re, true); - + /* assuming no new data gets added to dbase... */ R = *re; - + /* set threadsafe break */ R.test_break = thread_break; - + /* create and fill work queue */ workqueue = BLI_thread_queue_init(); donequeue = BLI_thread_queue_init(); - + /* for panorama we loop over slices */ while (find_next_pano_slice(re, &slice, &minx, &viewplane)) { /* gather parts into queue */ totpart = sort_and_queue_parts(re, minx, workqueue); - + BLI_thread_queue_nowait(workqueue); - + /* start all threads */ BLI_threadpool_init(&threads, do_render_thread, re->r.threads); - + for (a = 0; a < re->r.threads; a++) { thread[a].workqueue = workqueue; thread[a].donequeue = donequeue; @@ -1438,36 +1438,36 @@ static void threaded_tile_processor(Render *re) BLI_threadpool_insert(&threads, &thread[a]); } - + /* wait for results to come back */ lastdraw = PIL_check_seconds_timer(); - + while (1) { elapsed = PIL_check_seconds_timer() - lastdraw; wait = (redrawtime - elapsed)*1000; - + /* handle finished part */ if ((pa=BLI_thread_queue_pop_timeout(donequeue, wait))) { if (pa->result) { print_part_stats(re, pa); - + render_result_free_list(&pa->fullresult, pa->result); pa->result = NULL; re->i.partsdone++; re->progress(re->prh, re->i.partsdone / (float)re->i.totpart); } - + totpart--; } - + /* check for render cancel */ if ((g_break=re->test_break(re->tbh))) break; - + /* or done with parts */ if (totpart == 0) break; - + /* redraw in progress parts */ elapsed = PIL_check_seconds_timer() - lastdraw; if (elapsed > redrawtime) { @@ -1475,13 +1475,13 @@ static void threaded_tile_processor(Render *re) for (pa = re->parts.first; pa; pa = pa->next) if ((pa->status == PART_STATUS_IN_PROGRESS) && pa->nr && pa->result) re->display_update(re->duh, pa->result, &pa->result->renrect); - + lastdraw = PIL_check_seconds_timer(); } } - + BLI_threadpool_end(&threads); - + if ((g_break=re->test_break(re->tbh))) break; } @@ -1527,7 +1527,7 @@ void RE_TileProcessor(Render *re) { main_render_result_new(re); threaded_tile_processor(re); - + re->i.lastframetime = PIL_check_seconds_timer() - re->i.starttime; re->stats_draw(re->sdh, &re->i); @@ -1538,7 +1538,7 @@ void RE_TileProcessor(Render *re) init_freestyle(re); add_freestyle(re, 1); free_all_freestyle_renders(); - + re->i.lastframetime = PIL_check_seconds_timer() - re->i.starttime; re->stats_draw(re->sdh, &re->i); } @@ -1561,7 +1561,7 @@ static void do_render_3d(Render *re) /* internal */ RE_parts_clamp(re); - + /* add motion blur and fields offset to frames */ const int cfra_backup = re->scene->r.cfra; const float subframe_backup = re->scene->r.subframe; @@ -1599,20 +1599,20 @@ static void do_render_3d(Render *re) RE_Database_FromScene(re, re->main, re->scene, re->lay, 1); RE_Database_Preprocess(re); } - + /* clear UI drawing locks */ if (re->draw_lock) re->draw_lock(re->dlh, 0); - + threaded_tile_processor(re); - + #ifdef WITH_FREESTYLE /* Freestyle */ if (re->r.mode & R_EDGE_FRS) if (!re->test_break(re->tbh)) add_freestyle(re, 1); #endif - + /* do left-over 3d post effects (flares) */ if (re->flag & R_HALO) if (!re->test_break(re->tbh)) @@ -1634,14 +1634,14 @@ static void addblur_rect_key(RenderResult *rr, float *rectf, float *rectf1, floa float mfac = 1.0f - blurfac; int a, b, stride = 4 * rr->rectx; int len = stride * sizeof(float); - + for (a = 0; a < rr->recty; a++) { if (blurfac == 1.0f) { memcpy(rectf, rectf1, len); } else { float *rf = rectf, *rf1 = rectf1; - + for (b = rr->rectx; b > 0; b--, rf += 4, rf1 += 4) { if (rf1[3] < 0.01f) rf[3] = mfac * rf[3]; @@ -1670,14 +1670,14 @@ static void addblur_rect(RenderResult *rr, float *rectf, float *rectf1, float bl float mfac = 1.0f - blurfac; int a, b, stride = channels * rr->rectx; int len = stride * sizeof(float); - + for (a = 0; a < rr->recty; a++) { if (blurfac == 1.0f) { memcpy(rectf, rectf1, len); } else { float *rf = rectf, *rf1 = rectf1; - + for (b = rr->rectx * channels; b > 0; b--, rf++, rf1++) { rf[0] = mfac * rf[0] + blurfac * rf1[0]; } @@ -1693,7 +1693,7 @@ static void merge_renderresult_blur(RenderResult *rr, RenderResult *brr, float b { RenderLayer *rl, *rl1; RenderPass *rpass, *rpass1; - + rl1 = brr->layers.first; for (rl = rr->layers.first; rl && rl1; rl = rl->next, rl1 = rl1->next) { /* passes are allocated in sync */ @@ -1713,38 +1713,38 @@ static void do_render_blur_3d(Render *re) RenderResult *rres; float blurfac; int blur = re->r.mblur_samples; - + /* create accumulation render result */ rres = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS, RR_ALL_VIEWS); - + /* do the blur steps */ while (blur--) { re->mblur_offs = re->r.blurfac * ((float)(re->r.mblur_samples - blur)) / (float)re->r.mblur_samples; - + re->i.curblur = re->r.mblur_samples - blur; /* stats */ - + do_render_3d(re); - + blurfac = 1.0f / (float)(re->r.mblur_samples - blur); - + merge_renderresult_blur(rres, re->result, blurfac, false); if (re->test_break(re->tbh)) break; } - + /* swap results */ BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_free(re->result); re->result = rres; BLI_rw_mutex_unlock(&re->resultmutex); - + re->mblur_offs = 0.0f; re->i.curblur = 0; /* stats */ - + /* make sure motion blur changes get reset to current frame */ if ((re->r.scemode & (R_NO_FRAME_UPDATE|R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))==0) { BKE_scene_update_for_newframe(re->eval_ctx, re->main, re->scene, re->lay); } - + /* weak... the display callback wants an active renderlayer pointer... */ re->result->renlay = render_get_active_layer(re, re->result); re->display_update(re->duh, re->result, NULL); @@ -1756,7 +1756,7 @@ static void interleave_rect(RenderResult *rr, float *rectf, float *rectf1, float { int a, stride = channels * rr->rectx; int len = stride * sizeof(float); - + for (a = 0; a < rr->recty; a += 2) { memcpy(rectf, rectf1, len); rectf += stride; @@ -1772,11 +1772,11 @@ static void merge_renderresult_fields(RenderResult *rr, RenderResult *rr1, Rende { RenderLayer *rl, *rl1, *rl2; RenderPass *rpass, *rpass1, *rpass2; - + rl1 = rr1->layers.first; rl2 = rr2->layers.first; for (rl = rr->layers.first; rl && rl1 && rl2; rl = rl->next, rl1 = rl1->next, rl2 = rl2->next) { - + /* passes are allocated in sync */ rpass1 = rl1->passes.first; rpass2 = rl2->passes.first; @@ -1795,15 +1795,15 @@ static void do_render_fields_3d(Render *re) { Object *camera = RE_GetCamera(re); RenderResult *rr1, *rr2 = NULL; - + /* no render result was created, we can safely halve render y */ re->winy /= 2; re->recty /= 2; re->disprect.ymin /= 2; re->disprect.ymax /= 2; - + re->i.curfield = 1; /* stats */ - + /* first field, we have to call camera routine for correct aspect and subpixel offset */ RE_SetCamera(re, camera); if (re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE) == 0) @@ -1815,12 +1815,12 @@ static void do_render_fields_3d(Render *re) rr1 = re->result; re->result = NULL; BLI_rw_mutex_unlock(&re->resultmutex); - + /* second field */ if (!re->test_break(re->tbh)) { - + re->i.curfield = 2; /* stats */ - + re->flag |= R_SEC_FIELD; if ((re->r.mode & R_FIELDSTILL) == 0) { re->field_offs = 0.5f; @@ -1831,12 +1831,12 @@ static void do_render_fields_3d(Render *re) else do_render_3d(re); re->flag &= ~R_SEC_FIELD; - + re->field_offs = 0.0f; - + rr2 = re->result; } - + /* allocate original height new buffers */ re->winy *= 2; re->recty *= 2; @@ -1851,14 +1851,14 @@ static void do_render_fields_3d(Render *re) merge_renderresult_fields(re->result, rr2, rr1); else merge_renderresult_fields(re->result, rr1, rr2); - + render_result_free(rr2); } render_result_free(rr1); - + re->i.curfield = 0; /* stats */ - + /* weak... the display callback wants an active renderlayer pointer... */ re->result->renlay = render_get_active_layer(re, re->result); @@ -1939,14 +1939,14 @@ static void do_render_fields_blur_3d(Render *re) /* now use renderdata and camera to set viewplane */ RE_SetCamera(re, camera); - + if (re->r.mode & R_FIELDS) do_render_fields_3d(re); else if (re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE) == 0) do_render_blur_3d(re); else do_render_3d(re); - + /* when border render, check if we have to insert it in black */ render_result_uncrop(re); } @@ -1959,7 +1959,7 @@ static void render_scene(Render *re, Scene *sce, int cfra) { Render *resc = RE_NewSceneRender(sce); int winx = re->winx, winy = re->winy; - + sce->r.cfra = cfra; BKE_scene_camera_switch_update(sce); @@ -1969,7 +1969,7 @@ static void render_scene(Render *re, Scene *sce, int cfra) winx = (sce->r.size * sce->r.xsch) / 100; winy = (sce->r.size * sce->r.ysch) / 100; } - + /* initial setup */ RE_InitState(resc, re, &sce->r, NULL, winx, winy, &re->disprect); @@ -1981,7 +1981,7 @@ static void render_scene(Render *re, Scene *sce, int cfra) resc->scene = sce; resc->lay = sce->lay; resc->scene_color_manage = BKE_scene_check_color_management_enabled(sce); - + /* ensure scene has depsgraph, base flags etc OK */ BKE_scene_set_background(re->main, sce); @@ -1994,7 +1994,7 @@ static void render_scene(Render *re, Scene *sce, int cfra) resc->sdh = re->sdh; resc->current_scene_update = re->current_scene_update; resc->suh = re->suh; - + do_render_fields_blur_3d(resc); } @@ -2003,11 +2003,11 @@ static int composite_needs_render(Scene *sce, int this_scene) { bNodeTree *ntree = sce->nodetree; bNode *node; - + if (ntree == NULL) return 1; if (sce->use_nodes == false) return 1; 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 && (node->flag & NODE_MUTED) == 0) if (this_scene == 0 || node->id == NULL || node->id == &sce->id) @@ -2165,14 +2165,14 @@ static void tag_scenes_for_render(Render *re) #ifdef DEPSGRAPH_WORKAROUND_HACK int renderlay = re->lay; #endif - + for (sce = re->main->scene.first; sce; sce = sce->id.next) { sce->id.tag &= ~LIB_TAG_DOIT; #ifdef DEPSGRAPH_WORKAROUND_HACK tag_dependend_objects_for_render(re->main, sce, renderlay); #endif } - + #ifdef WITH_FREESTYLE if (re->freestyle_bmain) { for (sce = re->freestyle_bmain->scene.first; sce; sce = sce->id.next) { @@ -2190,9 +2190,9 @@ static void tag_scenes_for_render(Render *re) tag_dependend_objects_for_render(re->main, re->scene, renderlay); #endif } - + if (re->scene->nodetree == NULL) return; - + /* check for render-layers nodes using other scenes, we tag them LIB_TAG_DOIT */ for (node = re->scene->nodetree->nodes.first; node; node = node->next) { node->flag &= ~NODE_TEST; @@ -2228,7 +2228,7 @@ static void tag_scenes_for_render(Render *re) } } } - + } static void ntree_render_scenes(Render *re) @@ -2237,11 +2237,11 @@ static void ntree_render_scenes(Render *re) int cfra = re->scene->r.cfra; Scene *restore_scene = re->scene; bool scene_changed = false; - + if (re->scene->nodetree == NULL) return; - + tag_scenes_for_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) { @@ -2253,7 +2253,7 @@ static void ntree_render_scenes(Render *re) scene_changed |= scene != restore_scene; render_scene(re, scene, cfra); node->flag &= ~NODE_TEST; - + nodeUpdate(restore_scene->nodetree, node); } } @@ -2399,7 +2399,7 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) float *rectf, filt[3][3]; int x, y, sample; int nr, numviews; - + /* interaction callbacks */ if (ntree) { ntree->stats_draw = render_composit_stats; @@ -2409,10 +2409,10 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) ntree->tbh = re->tbh; ntree->prh = re->prh; } - + /* filtmask needs it */ R = *re; - + /* temporary storage of the acccumulation buffers */ rectfs = MEM_callocN(sizeof(ListBase), "fullsample accumulation buffers"); @@ -2430,13 +2430,13 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) Render *re1; RenderResult rres; int mask; - + /* enable full sample print */ R.i.curfsa = sample + 1; - + /* set all involved renders on the samplebuffers (first was done by render itself, but needs tagged) */ /* also function below assumes this */ - + tag_scenes_for_render(re); for (sce = re->main->scene.first; sce; sce = sce->id.next) { if (sce->id.tag & LIB_TAG_DOIT) { @@ -2457,7 +2457,7 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) } } } - + /* composite */ if (ntree) { ntreeCompositTagRender(re->scene); @@ -2481,17 +2481,17 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) for (y = 0; y < re->result->recty; y++) { float *rf = rectf + 4 * y * re->result->rectx; float *col = rres.rectf + 4 * y * re->result->rectx; - + for (x = 0; x < re->result->rectx; x++, rf += 4, col += 4) { /* clamping to 1.0 is needed for correct AA */ CLAMP(col[0], 0.0f, 1.0f); CLAMP(col[1], 0.0f, 1.0f); CLAMP(col[2], 0.0f, 1.0f); - + add_filt_fmask_coord(filt, col, rf, re->result->rectx, x, y, &filter_mask); } } - + RE_ReleaseResultImage(re); /* show stuff */ @@ -2510,7 +2510,7 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) /* clamp alpha and RGB to 0..1 and 0..inf, can go outside due to filter */ for (y = 0; y < re->result->recty; y++) { float *rf = rectf + 4 * y * re->result->rectx; - + for (x = 0; x < re->result->rectx; x++, rf += 4) { rf[0] = MAX2(rf[0], 0.0f); rf[1] = MAX2(rf[1], 0.0f); @@ -2527,7 +2527,7 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) rv->rectf = rectf; BLI_rw_mutex_unlock(&re->resultmutex); } - + /* clear interaction callbacks */ if (ntree) { ntree->stats_draw = NULL; @@ -2535,7 +2535,7 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) ntree->progress = NULL; ntree->tbh = ntree->sdh = ntree->prh = NULL; } - + /* disable full sample print */ R.i.curfsa = 0; @@ -2556,17 +2556,17 @@ void RE_MergeFullSample(Render *re, Main *bmain, Scene *sce, bNodeTree *ntree) /* default start situation */ G.is_break = false; - + re->main = bmain; re->scene = sce; re->scene_color_manage = BKE_scene_check_color_management_enabled(sce); - + /* first call RE_ReadRenderResult on every renderlayer scene. this creates Render structs */ - + /* tag scenes unread */ for (scene = re->main->scene.first; scene; scene = scene->id.next) scene->id.tag |= LIB_TAG_DOIT; - + #ifdef WITH_FREESTYLE if (re->freestyle_bmain) { for (scene = re->freestyle_bmain->scene.first; scene; scene = scene->id.next) @@ -2577,7 +2577,7 @@ void RE_MergeFullSample(Render *re, Main *bmain, Scene *sce, bNodeTree *ntree) for (node = ntree->nodes.first; node; node = node->next) { if (node->type == CMP_NODE_R_LAYERS && (node->flag & NODE_MUTED) == 0) { Scene *nodescene = (Scene *)node->id; - + if (nodescene == NULL) nodescene = sce; if (nodescene->id.tag & LIB_TAG_DOIT) { nodescene->r.mode |= R_OSA; /* render struct needs tables */ @@ -2586,17 +2586,17 @@ void RE_MergeFullSample(Render *re, Main *bmain, Scene *sce, bNodeTree *ntree) } } } - + /* own render result should be read/allocated */ if (re->scene->id.tag & LIB_TAG_DOIT) { RE_ReadRenderResult(re->scene, re->scene); re->scene->id.tag &= ~LIB_TAG_DOIT; } - + /* and now we can draw (result is there) */ re->display_init(re->dih, re->result); re->display_clear(re->dch, re->result); - + #ifdef WITH_FREESTYLE if (re->r.mode & R_EDGE_FRS) { init_freestyle(re); @@ -2616,10 +2616,10 @@ static void do_render_composite_fields_blur_3d(Render *re) { bNodeTree *ntree = re->scene->nodetree; int update_newframe = 0; - + /* INIT seeding, compositor can use random texture */ BLI_srandom(re->r.cfra); - + if (composite_needs_render(re->scene, 1)) { /* save memory... free all cached images */ ntreeFreeCache(ntree); @@ -2635,7 +2635,7 @@ static void do_render_composite_fields_blur_3d(Render *re) /* ensure new result gets added, like for regular renders */ BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); - + render_result_free(re->result); if ((re->r.mode & R_CROP) == 0) { render_result_disprect_to_full_resolution(re); @@ -2643,30 +2643,30 @@ static void do_render_composite_fields_blur_3d(Render *re) re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS, RR_ALL_VIEWS); BLI_rw_mutex_unlock(&re->resultmutex); - + /* scene render process already updates animsys */ update_newframe = 1; } - + /* swap render result */ if (re->r.scemode & R_SINGLE_LAYER) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_single_layer_end(re); BLI_rw_mutex_unlock(&re->resultmutex); } - + if (!re->test_break(re->tbh)) { - + if (ntree) { ntreeCompositTagRender(re->scene); ntreeCompositTagAnimated(ntree); } - + if (ntree && re->scene->use_nodes && re->r.scemode & R_DOCOMP) { /* checks if there are render-result nodes that need scene */ if ((re->r.scemode & R_SINGLE_LAYER) == 0) ntree_render_scenes(re); - + if (!re->test_break(re->tbh)) { ntree->stats_draw = render_composit_stats; ntree->test_break = re->test_break; @@ -2674,16 +2674,16 @@ static void do_render_composite_fields_blur_3d(Render *re) ntree->sdh = re->sdh; ntree->tbh = re->tbh; ntree->prh = re->prh; - + /* in case it was never initialized */ R.sdh = re->sdh; R.stats_draw = re->stats_draw; R.i.starttime = re->i.starttime; R.i.cfra = re->i.cfra; - + if (update_newframe) BKE_scene_update_for_newframe(re->eval_ctx, re->main, re->scene, re->lay); - + if (re->r.scemode & R_FULL_SAMPLE) do_merge_fullsample(re, ntree); else { @@ -2692,7 +2692,7 @@ static void do_render_composite_fields_blur_3d(Render *re) ntreeCompositExecTree(re->scene, ntree, &re->r, true, G.background == 0, &re->scene->view_settings, &re->scene->display_settings, rv->name); } } - + ntree->stats_draw = NULL; ntree->test_break = NULL; ntree->progress = NULL; @@ -2742,15 +2742,15 @@ int RE_seq_render_active(Scene *scene, RenderData *rd) Sequence *seq; ed = scene->ed; - + if (!(rd->scemode & R_DOSEQ) || !ed || !ed->seqbase.first) return 0; - + for (seq = ed->seqbase.first; seq; seq = seq->next) { if (seq->type != SEQ_TYPE_SOUND_RAM) return 1; } - + return 0; } @@ -2891,7 +2891,7 @@ static void do_render_all_options(Render *re) do_render_seq(re); render_seq = true; } - + re->stats_draw(re->sdh, &re->i); re->display_update(re->duh, re->result, NULL); } @@ -2903,11 +2903,11 @@ static void do_render_all_options(Render *re) BKE_image_pool_free(re->pool); re->pool = NULL; } - + re->i.lastframetime = PIL_check_seconds_timer() - re->i.starttime; - + re->stats_draw(re->sdh, &re->i); - + /* save render result stamp if needed */ if (re->result != NULL) { camera = RE_GetCamera(re); @@ -3073,7 +3073,7 @@ static int check_composite_output(Scene *scene) bool RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *reports) { int scemode = check_mode_full_sample(&scene->r); - + if (scene->r.mode & R_BORDER) { if (scene->r.border.xmax <= scene->r.border.xmin || scene->r.border.ymax <= scene->r.border.ymin) @@ -3082,37 +3082,37 @@ bool RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList * return 0; } } - + if (scemode & (R_EXR_TILE_FILE | R_FULL_SAMPLE)) { char str[FILE_MAX]; - + render_result_exr_file_path(scene, "", 0, str); - + if (!BLI_file_is_writable(str)) { BKE_report(reports, RPT_ERROR, "Cannot save render buffers, check the temp default path"); return 0; } - + /* no fullsample and edge */ if ((scemode & R_FULL_SAMPLE) && (scene->r.mode & R_EDGE)) { BKE_report(reports, RPT_ERROR, "Full sample does not support edge enhance"); return 0; } - + } - + if (scemode & R_DOCOMP) { if (scene->use_nodes) { if (!scene->nodetree) { BKE_report(reports, RPT_ERROR, "No node tree in scene"); return 0; } - + if (!check_composite_output(scene)) { BKE_report(reports, RPT_ERROR, "No render output node in scene"); return 0; } - + if (scemode & R_FULL_SAMPLE) { if (composite_needs_render(scene, 0) == 0) { BKE_report(reports, RPT_ERROR, "Full sample AA not supported without 3D rendering"); @@ -3121,12 +3121,12 @@ bool RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList * } } } - + /* check valid camera, without camera render is OK (compo, seq) */ if (!check_valid_camera(scene, camera_override, reports)) { return 0; } - + /* get panorama & ortho, only after camera is set */ BKE_camera_object_mode(&scene->r, camera_override ? camera_override : scene->camera); @@ -3216,19 +3216,19 @@ static int render_initialize_from_main(Render *re, RenderData *rd, Main *bmain, { int winx, winy; rcti disprect; - + /* r.xsch and r.ysch has the actual view window size * r.border is the clipping rect */ - + /* calculate actual render result and display size */ winx = (rd->size * rd->xsch) / 100; winy = (rd->size * rd->ysch) / 100; - + /* we always render smaller part, inserting it in larger image is compositor bizz, it uses disprect for it */ if (scene->r.mode & R_BORDER) { disprect.xmin = rd->border.xmin * winx; disprect.xmax = rd->border.xmax * winx; - + disprect.ymin = rd->border.ymin * winy; disprect.ymax = rd->border.ymax * winy; } @@ -3237,7 +3237,7 @@ static int render_initialize_from_main(Render *re, RenderData *rd, Main *bmain, disprect.xmax = winx; disprect.ymax = winy; } - + re->main = bmain; re->scene = scene; re->scene_color_manage = BKE_scene_check_color_management_enabled(scene); @@ -3253,7 +3253,7 @@ static int render_initialize_from_main(Render *re, RenderData *rd, Main *bmain, re->disprect = disprect; return 1; } - + /* check all scenes involved */ tag_scenes_for_render(re); @@ -3266,17 +3266,17 @@ static int render_initialize_from_main(Render *re, RenderData *rd, Main *bmain, /* make sure dynamics are up to date */ update_physics_cache(re, scene, anim_init); } - + if (srl || scene->r.scemode & R_SINGLE_LAYER) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_single_layer_begin(re); BLI_rw_mutex_unlock(&re->resultmutex); } - + RE_InitState(re, NULL, &scene->r, srl, winx, winy, &disprect); if (!re->ok) /* if an error was printed, abort */ return 0; - + /* initstate makes new result, have to send changed tags around */ ntreeCompositTagRender(re->scene); @@ -3284,7 +3284,7 @@ static int render_initialize_from_main(Render *re, RenderData *rd, Main *bmain, re->display_init(re->dih, re->result); re->display_clear(re->dch, re->result); - + return 1; } @@ -3301,9 +3301,9 @@ void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, SceneRenderLayer *sr /* ugly global still... is to prevent preview events and signal subsurfs etc to make full resol */ G.is_rendering = true; - + scene->r.cfra = frame; - + if (render_initialize_from_main(re, &scene->r, bmain, scene, srl, camera_override, lay_override, 0, 0)) { MEM_reset_peak_memory(); @@ -3565,12 +3565,12 @@ static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovie /* write images as individual images or stereo */ ok = RE_WriteRenderViewsImage(re->reports, &rres, scene, true, name); } - + RE_ReleaseResultImageViews(re, &rres); render_time = re->i.lastframetime; re->i.lastframetime = PIL_check_seconds_timer() - re->i.starttime; - + BLI_timecode_string_from_time_simple(name, sizeof(name), re->i.lastframetime); printf(" Time: %s", name); @@ -3581,7 +3581,7 @@ static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovie BLI_timecode_string_from_time_simple(name, sizeof(name), re->i.lastframetime - render_time); printf(" (Saving: %s)\n", name); - + fputc('\n', stdout); fflush(stdout); /* needed for renderd !! (not anymore... (ton)) */ @@ -3820,10 +3820,10 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri /* run callbacs before rendering, before the scene is updated */ BLI_callback_exec(re->main, (ID *)scene, BLI_CB_EVT_RENDER_PRE); - + do_render_all_options(re); totrendered++; - + if (re->test_break(re->tbh) == 0) { if (!G.is_break) if (!do_write_image_or_movie(re, bmain, scene, mh, totvideos, NULL)) @@ -3831,7 +3831,7 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri } else G.is_break = true; - + if (G.is_break == true) { /* remove touched file */ if (is_movie == false) { @@ -3860,7 +3860,7 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri } } } - + break; } @@ -3870,12 +3870,12 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri } } } - + /* end movie */ if (is_movie) { re_movie_free_all(re, mh, totvideos); } - + if (totskipped && totrendered == 0) BKE_report(re->reports, RPT_INFO, "No frames rendered, skipped to not overwrite"); @@ -3925,16 +3925,16 @@ bool RE_ReadRenderResult(Scene *scene, Scene *scenode) int winx, winy; bool success; rcti disprect; - + /* calculate actual render result and display size */ winx = (scene->r.size * scene->r.xsch) / 100; winy = (scene->r.size * scene->r.ysch) / 100; - + /* only in movie case we render smaller part */ if (scene->r.mode & R_BORDER) { disprect.xmin = scene->r.border.xmin * winx; disprect.xmax = scene->r.border.xmax * winx; - + disprect.ymin = scene->r.border.ymin * winy; disprect.ymax = scene->r.border.ymax * winy; } @@ -3943,10 +3943,10 @@ bool RE_ReadRenderResult(Scene *scene, Scene *scenode) disprect.xmax = winx; disprect.ymax = winy; } - + if (scenode) scene = scenode; - + /* get render: it can be called from UI with draw callbacks */ re = RE_GetSceneRender(scene); if (re == NULL) @@ -3954,7 +3954,7 @@ bool RE_ReadRenderResult(Scene *scene, Scene *scenode) RE_InitState(re, NULL, &scene->r, NULL, winx, winy, &disprect); re->scene = scene; re->scene_color_manage = BKE_scene_check_color_management_enabled(scene); - + BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); success = render_result_exr_file_cache_read(re); BLI_rw_mutex_unlock(&re->resultmutex); @@ -3964,7 +3964,7 @@ bool RE_ReadRenderResult(Scene *scene, Scene *scenode) return success; } -void RE_init_threadcount(Render *re) +void RE_init_threadcount(Render *re) { re->r.threads = BKE_render_num_threads(&re->r); } @@ -4190,7 +4190,7 @@ RenderPass *RE_create_gp_pass(RenderResult *rr, const char *layername, const cha rl->rectx = rr->rectx; rl->recty = rr->recty; } - + /* clear previous pass if exist or the new image will be over previous one*/ RenderPass *rp = RE_pass_find_by_name(rl, RE_PASSNAME_COMBINED, viewname); if (rp) { diff --git a/source/blender/render/intern/source/pixelblending.c b/source/blender/render/intern/source/pixelblending.c index fc79786e5c7..c7cfe765f5b 100644 --- a/source/blender/render/intern/source/pixelblending.c +++ b/source/blender/render/intern/source/pixelblending.c @@ -96,7 +96,7 @@ void addAlphaUnderFloat(float dest[4], const float source[4]) dest[1] += (mul * source[1]); dest[2] += (mul * source[2]); dest[3] += (mul * source[3]); -} +} /* ------------------------------------------------------------------------- */ @@ -112,29 +112,29 @@ void addalphaAddfacFloat(float dest[4], const float source[4], char addfac) /* blend colors*/ c = (m * dest[0]) + source[0]; #ifdef RE_FLOAT_COLOR_CLIPPING - if (c >= RE_FULL_COLOR_FLOAT) dest[0] = RE_FULL_COLOR_FLOAT; - else + if (c >= RE_FULL_COLOR_FLOAT) dest[0] = RE_FULL_COLOR_FLOAT; + else #endif dest[0] = c; c = (m * dest[1]) + source[1]; #ifdef RE_FLOAT_COLOR_CLIPPING - if (c >= RE_FULL_COLOR_FLOAT) dest[1] = RE_FULL_COLOR_FLOAT; - else + if (c >= RE_FULL_COLOR_FLOAT) dest[1] = RE_FULL_COLOR_FLOAT; + else #endif dest[1] = c; c = (m * dest[2]) + source[2]; #ifdef RE_FLOAT_COLOR_CLIPPING - if (c >= RE_FULL_COLOR_FLOAT) dest[2] = RE_FULL_COLOR_FLOAT; - else + if (c >= RE_FULL_COLOR_FLOAT) dest[2] = RE_FULL_COLOR_FLOAT; + else #endif dest[2] = c; c = (m * dest[3]) + source[3]; #ifdef RE_ALPHA_CLIPPING - if (c >= RE_FULL_COLOR_FLOAT) dest[3] = RE_FULL_COLOR_FLOAT; - else + if (c >= RE_FULL_COLOR_FLOAT) dest[3] = RE_FULL_COLOR_FLOAT; + else #endif dest[3] = c; @@ -152,7 +152,7 @@ void add_filt_fmask(unsigned int mask, const float col[4], float *rowbuf, int ro float val, r, g, b, al; unsigned int a, maskand, maskshift; int j; - + r = col[0]; g = col[1]; b = col[2]; @@ -177,7 +177,7 @@ void add_filt_fmask(unsigned int mask, const float col[4], float *rowbuf, int ro rb1[3] += val * al; } a += 3; - + val = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift); if (val != 0.0f) { rb2[0] += val * r; @@ -186,7 +186,7 @@ void add_filt_fmask(unsigned int mask, const float col[4], float *rowbuf, int ro rb2[3] += val * al; } a += 3; - + val = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift); if (val != 0.0f) { rb3[0] += val * r; @@ -194,7 +194,7 @@ void add_filt_fmask(unsigned int mask, const float col[4], float *rowbuf, int ro rb3[2] += val * b; rb3[3] += val * al; } - + rb1 += 4; rb2 += 4; rb3 += 4; @@ -208,19 +208,19 @@ void mask_array(unsigned int mask, float filt[3][3]) unsigned int maskand = (mask & 255); unsigned int maskshift = (mask >> 8); int a, j; - + for (j = 2; j >= 0; j--) { - + a = j; - + filt[2][2 - j] = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift); a += 3; - + filt[1][2 - j] = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift); - + a += 3; - + filt[0][2 - j] = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift); } } @@ -244,14 +244,14 @@ void add_filt_fmask_coord(float filt[3][3], const float col[4], float *rowbuf, i { float *fpoin[3][3]; float val, r, g, b, al, lfilt[3][3]; - + r = col[0]; g = col[1]; b = col[2]; al = col[3]; - + memcpy(lfilt, filt, sizeof(lfilt)); - + fpoin[0][1] = rowbuf - 4 * row_stride; fpoin[1][1] = rowbuf; fpoin[2][1] = rowbuf + 4 * row_stride; @@ -284,7 +284,7 @@ void add_filt_fmask_coord(float filt[3][3], const float col[4], float *rowbuf, i lfilt[2][1] = filt[0][1]; lfilt[2][2] = filt[0][2]; } - + if (x <= mask->xmin) { fpoin[2][0] = fpoin[2][1]; fpoin[1][0] = fpoin[1][1]; @@ -303,8 +303,8 @@ void add_filt_fmask_coord(float filt[3][3], const float col[4], float *rowbuf, i lfilt[1][2] = filt[1][0]; lfilt[0][2] = filt[0][0]; } - - + + /* loop unroll */ #define MASKFILT(i, j) \ val = lfilt[i][j]; \ @@ -315,7 +315,7 @@ void add_filt_fmask_coord(float filt[3][3], const float col[4], float *rowbuf, i fp[2] += val * b; \ fp[3] += val * al; \ } (void)0 - + MASKFILT(0, 0); MASKFILT(0, 1); MASKFILT(0, 2); @@ -337,38 +337,38 @@ void add_filt_fmask_pixsize(unsigned int mask, float *in, float *rowbuf, int row float val; unsigned int a, maskand, maskshift; int i, j; - + rb2 = rowbuf - pixsize; rb3 = rb2 - pixsize * row_w; rb1 = rb2 + pixsize * row_w; - + maskand = (mask & 255); maskshift = (mask >> 8); - + for (j = 2; j >= 0; j--) { - + a = j; - + val = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift); if (val != 0.0f) { for (i = 0; i < pixsize; i++) rb1[i] += val * in[i]; } a += 3; - + val = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift); if (val != 0.0f) { for (i = 0; i < pixsize; i++) rb2[i] += val * in[i]; } a += 3; - + val = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift); if (val != 0.0f) { for (i = 0; i < pixsize; i++) rb3[i] += val * in[i]; } - + rb1 += pixsize; rb2 += pixsize; rb3 += pixsize; diff --git a/source/blender/render/intern/source/pixelshading.c b/source/blender/render/intern/source/pixelshading.c index f1323af2826..7f202629ce4 100644 --- a/source/blender/render/intern/source/pixelshading.c +++ b/source/blender/render/intern/source/pixelshading.c @@ -71,20 +71,20 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) LampRen *lar; float i, inp, inpr, rco[3], dco[3], lv[3], lampdist, ld, t, *vn; float ir, ig, ib, shadfac, soft, lacol[3]; - + ir= ig= ib= 0.0; - + copy_v3_v3(rco, har->co); dco[0]=dco[1]=dco[2]= 1.0f/har->rad; - + vn= har->no; - + for (go=R.lights.first; go; go= go->next) { lar= go->lampren; - + /* test for lamplayer */ if (lar->mode & LA_LAYER) if ((lar->lay & har->lay)==0) continue; - + /* lampdist cacluation */ if (lar->type==LA_SUN || lar->type==LA_HEMI) { copy_v3_v3(lv, lar->vec); @@ -98,63 +98,63 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) lv[0]/= ld; lv[1]/= ld; lv[2]/= ld; - + /* ld is re-used further on (texco's) */ - + if (lar->mode & LA_QUAD) { t= 1.0; if (lar->ld1>0.0f) t= lar->dist/(lar->dist+lar->ld1*ld); if (lar->ld2>0.0f) t*= lar->distkw/(lar->distkw+lar->ld2*ld*ld); - + lampdist= t; } else { lampdist= (lar->dist/(lar->dist+ld)); } - + if (lar->mode & LA_SPHERE) { t= lar->dist - ld; if (t<0.0f) continue; - + t/= lar->dist; lampdist*= (t); } - + } - + lacol[0]= lar->r; lacol[1]= lar->g; lacol[2]= lar->b; - + if (lar->mode & LA_TEXTURE) { ShadeInput shi; - + /* Warning, This is not that nice, and possibly a bit slow, * however some variables were not initialized properly in, unless using shade_input_initialize(...), * we need to do a memset */ - memset(&shi, 0, sizeof(ShadeInput)); + memset(&shi, 0, sizeof(ShadeInput)); /* end warning! - Campbell */ - + copy_v3_v3(shi.co, rco); shi.osatex= 0; do_lamp_tex(lar, lv, &shi, lacol, LA_TEXTURE); } - + if (lar->type==LA_SPOT) { - + if (lar->mode & LA_SQUARE) { if (lv[0]*lar->vec[0]+lv[1]*lar->vec[1]+lv[2]*lar->vec[2]>0.0f) { float x, lvrot[3]; - + /* rotate view to lampspace */ copy_v3_v3(lvrot, lv); mul_m3_v3(lar->imat, lvrot); - + x = max_ff(fabsf(lvrot[0]/lvrot[2]), fabsf(lvrot[1]/lvrot[2])); /* 1.0/(sqrt(1+x*x)) is equivalent to cos(atan(x)) */ - + inpr = 1.0f / (sqrtf(1.0f + x * x)); } else inpr= 0.0; @@ -162,7 +162,7 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) else { inpr= lv[0]*lar->vec[0]+lv[1]*lar->vec[1]+lv[2]*lar->vec[2]; } - + t= lar->spotsi; if (inprmode & LA_ONLYSHADOW) continue; - + } - + /* dot product and reflectivity*/ - + inp = 1.0f - fabsf(dot_v3v3(vn, lv)); - + /* inp= cos(0.5*M_PI-acos(inp)); */ - + i= inp; - + if (lar->type==LA_HEMI) { i= 0.5f*i+0.5f; } if (i>0.0f) { i*= lampdist; } - + /* shadow */ if (i> -0.41f) { /* heuristic valua! */ if (lar->shb) { @@ -222,14 +222,14 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) i*= shadfac; } } - + if (i>0.0f) { ir+= i*lacol[0]; ig+= i*lacol[1]; ib+= i*lacol[2]; } } - + if (ir<0.0f) ir= 0.0f; if (ig<0.0f) ig= 0.0f; if (ib<0.0f) ib= 0.0f; @@ -237,7 +237,7 @@ static void render_lighting_halo(HaloRen *har, float col_r[3]) col_r[0]*= ir; col_r[1]*= ig; col_r[2]*= ib; - + } @@ -287,14 +287,14 @@ int shadeHaloFloat(HaloRen *har, float col[4], int zz, } } else alpha= har->alfa; - + if (alpha==0.0f) return 0; /* soften the halo if it intersects geometry */ if (har->mat && har->mat->mode & MA_HALO_SOFT) { float segment_length, halo_depth, distance_from_z /* , visible_depth */ /* UNUSED */, soften; - + /* calculate halo depth */ segment_length= har->hasize*sasqrt(1.0f - dist/(har->rad*har->rad)); halo_depth= 2.0f*segment_length; @@ -333,16 +333,16 @@ int shadeHaloFloat(HaloRen *har, float col[4], int zz, const float *rc; float fac; int ofs; - + /* per ring an antialised circle */ ofs= har->seed; - + for (a= har->ringc; a>0; a--, ofs+=2) { - + rc= hashvectf + (ofs % 768); - + fac = fabsf(rc[1] * (har->rad * fabsf(rc[0]) - radist)); - + if (fac< 1.0f) { ringf+= (1.0f-fac); } @@ -379,25 +379,25 @@ int shadeHaloFloat(HaloRen *har, float col[4], int zz, dist= (1.0f-dist); else dist= 0.0f; - + if (har->linec) { const float *rc; float fac; int ofs; - + /* per starpoint an antialiased line */ ofs= har->seed; - + for (a= har->linec; a>0; a--, ofs+=3) { - + rc= hashvectf + (ofs % 768); - + fac = fabsf((xn) * rc[0] + (yn) * rc[1]); - + if (fac< 1.0f ) linef+= (1.0f-fac); } - + linef*= dist; } @@ -406,16 +406,16 @@ int shadeHaloFloat(HaloRen *har, float col[4], int zz, /* rotation */ angle = atan2f(yn, xn); angle *= (1.0f+0.25f*har->starpoints); - + co= cosf(angle); si= sinf(angle); - + angle= (co*xn+si*yn)*(co*yn-si*xn); - + ster = fabsf(angle); if (ster>1.0f) { ster= (har->rad)/(ster); - + if (ster<1.0f) dist*= sqrtf(ster); } } @@ -423,25 +423,25 @@ int shadeHaloFloat(HaloRen *har, float col[4], int zz, /* disputable optimize... (ton) */ if (dist<=0.00001f) return 0; - + dist*= alpha; ringf*= dist; linef*= alpha; - + /* The color is either the rgb spec-ed by the user, or extracted from */ /* the texture */ if (har->tex) { - col[0]= har->r; - col[1]= har->g; + col[0]= har->r; + col[1]= har->g; col[2]= har->b; col[3]= dist; - + do_halo_tex(har, xn, yn, col); - + col[0]*= col[3]; col[1]*= col[3]; col[2]*= col[3]; - + } else { col[0]= dist*har->r; @@ -460,11 +460,11 @@ int shadeHaloFloat(HaloRen *har, float col[4], int zz, /* Next, we do the line and ring factor modifications. */ if (linef!=0.0f) { Material *ma= har->mat; - + col[0]+= linef * ma->specr; col[1]+= linef * ma->specg; col[2]+= linef * ma->specb; - + if (har->type & HA_XALPHA) col[3]+= linef*linef; else col[3]+= linef; } @@ -474,12 +474,12 @@ int shadeHaloFloat(HaloRen *har, float col[4], int zz, col[0]+= ringf * ma->mirr; col[1]+= ringf * ma->mirg; col[2]+= ringf * ma->mirb; - + if (har->type & HA_XALPHA) col[3]+= ringf*ringf; else col[3]+= ringf; } } - + /* alpha requires clip, gives black dots */ if (col[3] > 1.0f) col[3]= 1.0f; @@ -494,17 +494,17 @@ void shadeSkyView(float col_r[3], const float rco[3], const float view[3], const { float zen[3], hor[3], blend, blendm; int skyflag; - + /* flag indicating if we render the top hemisphere */ skyflag = WO_ZENUP; - + /* Some view vector stuff. */ if (R.wrld.skytype & WO_SKYREAL) { - + blend = dot_v3v3(view, R.grvec); - + if (blend<0.0f) skyflag= 0; - + blend = fabsf(blend); } else if (R.wrld.skytype & WO_SKYPAPER) { @@ -532,10 +532,10 @@ void shadeSkyView(float col_r[3], const float rco[3], const float view[3], const } do_sky_tex(rco, view, lo, dxyview, hor, zen, &blend, skyflag, thread); } - + if (blend>1.0f) blend= 1.0f; blendm= 1.0f-blend; - + /* No clipping, no conversion! */ if (R.wrld.skytype & WO_SKYBLEND) { col_r[0] = (blendm*hor[0] + blend*zen[0]); @@ -557,13 +557,13 @@ void shadeSunView(float col_r[3], const float view[3]) LampRen *lar; float sview[3]; bool do_init = true; - + for (go=R.lights.first; go; go= go->next) { lar= go->lampren; if (lar->type==LA_SUN && lar->sunsky && (lar->sunsky->effect_type & LA_SUN_EFFECT_SKY)) { float sun_collector[3]; float colorxyz[3]; - + if (do_init) { normalize_v3_v3(sview, view); @@ -573,11 +573,11 @@ void shadeSunView(float col_r[3], const float view[3]) normalize_v3(sview); do_init = false; } - + GetSkyXYZRadiancef(lar->sunsky, sview, colorxyz); xyz_to_rgb(colorxyz[0], colorxyz[1], colorxyz[2], &sun_collector[0], &sun_collector[1], &sun_collector[2], lar->sunsky->sky_colorspace); - + ramp_blend(lar->sunsky->skyblendtype, col_r, lar->sunsky->skyblendfac, sun_collector); } } @@ -613,25 +613,25 @@ void shadeSkyPixel(float collector[4], float fx, float fy, short thread) view[0]= -1.0f + 2.0f*(fx/(float)R.winx); view[1]= -1.0f + 2.0f*(fy/(float)R.winy); view[2]= 0.0; - + dxyview[0]= 1.0f/(float)R.winx; dxyview[1]= 1.0f/(float)R.winy; } else { calc_view_vector(view, fx, fy); fac= normalize_v3(view); - + if (R.wrld.skytype & WO_SKYTEX) { dxyview[0]= -R.viewdx/fac; dxyview[1]= -R.viewdy/fac; } } - + /* get sky color in the collector */ shadeSkyView(collector, NULL, view, dxyview, thread); collector[3] = 0.0f; } - + calc_view_vector(view, fx, fy); shadeSunView(collector, view); } diff --git a/source/blender/render/intern/source/pointdensity.c b/source/blender/render/intern/source/pointdensity.c index b75d996ff27..635bfc58425 100644 --- a/source/blender/render/intern/source/pointdensity.c +++ b/source/blender/render/intern/source/pointdensity.c @@ -107,7 +107,7 @@ static void point_data_pointers(PointDensity *pd, const int totpoint = pd->totpoints; float *data = pd->point_data; int offset = 0; - + if (data_used & POINT_DATA_VEL) { if (r_data_velocity) *r_data_velocity = data + offset; @@ -117,7 +117,7 @@ static void point_data_pointers(PointDensity *pd, if (r_data_velocity) *r_data_velocity = NULL; } - + if (data_used & POINT_DATA_LIFE) { if (r_data_life) *r_data_life = data + offset; @@ -127,7 +127,7 @@ static void point_data_pointers(PointDensity *pd, if (r_data_life) *r_data_life = NULL; } - + if (data_used & POINT_DATA_COLOR) { if (r_data_color) *r_data_color = data + offset; @@ -318,19 +318,19 @@ static void pointdensity_cache_vertex_color(PointDensity *pd, Object *UNUSED(ob) const MLoopCol *mcol; char layername[MAX_CUSTOMDATA_LAYER_NAME]; int i; - + BLI_assert(data_color); - + if (!CustomData_has_layer(&dm->loopData, CD_MLOOPCOL)) return; CustomData_validate_layer_name(&dm->loopData, CD_MLOOPCOL, pd->vertex_attribute_name, layername); mcol = CustomData_get_layer_named(&dm->loopData, CD_MLOOPCOL, layername); if (!mcol) return; - + /* Stores the number of MLoops using the same vertex, so we can normalize colors. */ int *mcorners = MEM_callocN(sizeof(int) * pd->totpoints, "point density corner count"); - + for (i = 0; i < totloop; i++) { int v = mloop[i].v; @@ -345,7 +345,7 @@ static void pointdensity_cache_vertex_color(PointDensity *pd, Object *UNUSED(ob) ++mcorners[v]; } - + /* Normalize colors by averaging over mcorners. * All the corners share the same vertex, ie. occupy the same point in space. */ @@ -353,7 +353,7 @@ static void pointdensity_cache_vertex_color(PointDensity *pd, Object *UNUSED(ob) if (mcorners[i] > 0) mul_v3_fl(&data_color[i*3], 1.0f / mcorners[i]); } - + MEM_freeN(mcorners); } @@ -363,9 +363,9 @@ static void pointdensity_cache_vertex_weight(PointDensity *pd, Object *ob, Deriv const MDeformVert *mdef, *dv; int mdef_index; int i; - + BLI_assert(data_color); - + mdef = CustomData_get_layer(&dm->vertData, CD_MDEFORMVERT); if (!mdef) return; @@ -374,11 +374,11 @@ static void pointdensity_cache_vertex_weight(PointDensity *pd, Object *ob, Deriv mdef_index = ob->actdef - 1; if (mdef_index < 0) return; - + for (i = 0, dv = mdef; i < totvert; ++i, ++dv, data_color += 3) { MDeformWeight *dw; int j; - + for (j = 0, dw = dv->dw; j < dv->totweight; ++j, ++dw) { if (dw->def_nr == mdef_index) { copy_v3_fl(data_color, dw->weight); @@ -392,9 +392,9 @@ static void pointdensity_cache_vertex_normal(PointDensity *pd, Object *UNUSED(ob { MVert *mvert = dm->getVertArray(dm), *mv; int i; - + BLI_assert(data_color); - + for (i = 0, mv = mvert; i < pd->totpoints; i++, mv++, data_color += 3) { normal_short_to_float_v3(data_color, mv->no); } @@ -457,7 +457,7 @@ static void pointdensity_cache_object(Scene *scene, BLI_bvhtree_insert(pd->point_tree, i, co, 1); } - + switch (pd->ob_color_source) { case TEX_PD_COLOR_VERTCOL: pointdensity_cache_vertex_color(pd, ob, dm, data_color); @@ -601,7 +601,7 @@ static float density_falloff(PointDensityRangeData *pdr, int index, float square { const float dist = (pdr->squared_radius - squared_dist) / pdr->squared_radius * 0.5f; float density = 0.0f; - + switch (pdr->falloff_type) { case TEX_PD_FALLOFF_STD: density = dist; @@ -631,12 +631,12 @@ static float density_falloff(PointDensityRangeData *pdr, int index, float square density = dist; break; } - + if (pdr->density_curve && dist != 0.0f) { curvemapping_initialize(pdr->density_curve); density = curvemapping_evaluateF(pdr->density_curve, 0, density / dist) * dist; } - + return density; } @@ -777,7 +777,7 @@ static int pointdensity_color(PointDensity *pd, TexResult *texres, float age, co if (pd->source == TEX_PD_PSYS) { float rgba[4]; - + switch (pd->color_source) { case TEX_PD_COLOR_PARTAGE: if (pd->coba) { @@ -792,7 +792,7 @@ static int pointdensity_color(PointDensity *pd, TexResult *texres, float age, co case TEX_PD_COLOR_PARTSPEED: { float speed = len_v3(vec) * pd->speed_scale; - + if (pd->coba) { if (BKE_colorband_evaluate(pd->coba, speed, rgba)) { texres->talpha = true; @@ -817,7 +817,7 @@ static int pointdensity_color(PointDensity *pd, TexResult *texres, float age, co } else { float rgba[4]; - + switch (pd->ob_color_source) { case TEX_PD_COLOR_VERTCOL: texres->talpha = true; @@ -847,7 +847,7 @@ static int pointdensity_color(PointDensity *pd, TexResult *texres, float age, co break; } } - + return retval; } @@ -861,7 +861,7 @@ int pointdensitytex(Tex *tex, const float texvec[3], TexResult *texres) retval |= pointdensity_color(pd, texres, age, vec, col); BRICONTRGB; - + return retval; #if 0 diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c index 2ee0ce22c23..df1cb868230 100644 --- a/source/blender/render/intern/source/rayshade.c +++ b/source/blender/render/intern/source/rayshade.c @@ -99,15 +99,15 @@ RayObject *RE_rayobject_create(int type, int size, int octree_resolution) type = R_RAYSTRUCTURE_VBVH; #endif } - + #ifndef __SSE__ if (type == R_RAYSTRUCTURE_SIMD_SVBVH || type == R_RAYSTRUCTURE_SIMD_QBVH) { puts("Warning: Using VBVH (SSE was disabled at compile time)"); type = R_RAYSTRUCTURE_VBVH; } #endif - - + + if (type == R_RAYSTRUCTURE_OCTREE) //TODO dynamic ocres res = RE_rayobject_octree_create(octree_resolution, size); else if (type == R_RAYSTRUCTURE_VBVH) @@ -118,7 +118,7 @@ RayObject *RE_rayobject_create(int type, int size, int octree_resolution) res = RE_rayobject_qbvh_create(size); else res = RE_rayobject_vbvh_create(size); //Fallback - + return res; } @@ -127,7 +127,7 @@ static RayObject* rayobject_create(Render *re, int type, int size) RayObject * res = NULL; res = RE_rayobject_create(type, size, re->r.ocres); - + if (res) RE_rayobject_config_control(res, re); @@ -142,7 +142,7 @@ RayCounter re_rc_counter[BLENDER_MAX_THREADS]; void freeraytree(Render *re) { ObjectInstanceRen *obi; - + if (re->raytree) { RE_rayobject_free(re->raytree); re->raytree = NULL; @@ -171,7 +171,7 @@ void freeraytree(Render *re) obi->raytree = NULL; } } - + #ifdef RE_RAYCOUNTER { const int num_threads = re->r.threads; @@ -226,7 +226,7 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi) RayFace *face = NULL; VlakPrimitive *vlakprimitive = NULL; int v; - + //Count faces int faces = 0; for (v=0;vtotvlak;v++) { @@ -234,7 +234,7 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi) if (is_raytraceable_vlr(re, vlr)) faces++; } - + if (faces == 0) return NULL; @@ -246,7 +246,7 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi) face = obr->rayfaces = (RayFace *)MEM_callocN(faces * sizeof(RayFace), "ObjectRen faces"); obr->rayobi = obi; - + for (v=0;vtotvlak;v++) { VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255); if (is_raytraceable_vlr(re, vlr)) { @@ -276,7 +276,7 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi) obi->raytree = RE_rayobject_instance_create( obr->raytree, obi->mat, obi, obi->obr->rayobi ); } } - + if (obi->raytree) return obi->raytree; return obi->obr->raytree; } @@ -286,7 +286,7 @@ static bool has_special_rayobject(Render *re, ObjectInstanceRen *obi) if ( (obi->flag & R_TRANSFORMED) && (re->r.raytrace_options & R_RAYTRACE_USE_INSTANCES) ) { ObjectRen *obr = obi->obr; int v, faces = 0; - + for (v=0;vtotvlak;v++) { VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255); if (is_raytraceable_vlr(re, vlr)) { @@ -327,12 +327,12 @@ static void makeraytree_single(Render *re) } } } - + if (faces + special == 0) { re->raytree = RE_rayobject_empty_create(); return; } - + //Create raytree raytree = re->raytree = rayobject_create( re, re->r.raytrace_structure, faces+special ); @@ -342,7 +342,7 @@ static void makeraytree_single(Render *re) else { face = re->rayfaces = (RayFace *)MEM_callocN(faces * sizeof(RayFace), "Render ray faces"); } - + for (obi=re->instancetable.first; obi; obi=obi->next) if (is_raytraceable(re, obi)) { if (test_break(re)) @@ -360,7 +360,7 @@ static void makeraytree_single(Render *re) else { int v; ObjectRen *obr = obi->obr; - + if (obi->flag & R_TRANSFORMED) { obi->transform_primitives = 1; } @@ -390,7 +390,7 @@ static void makeraytree_single(Render *re) } } } - + if (!test_break(re)) { re->i.infostr = IFACE_("Raytree.. building"); re->stats_draw(re->sdh, &re->i); @@ -403,7 +403,7 @@ void makeraytree(Render *re) { float min[3], max[3], sub[3]; int i; - + re->i.infostr = IFACE_("Raytree.. preparing"); re->stats_draw(re->sdh, &re->i); @@ -479,14 +479,14 @@ static void shade_ray_set_derivative(ShadeInput *shi) } detsh= 1.0f/(t00*t11-t10*t01); - t00*= detsh; t01*=detsh; + t00*= detsh; t01*=detsh; t10*=detsh; t11*=detsh; - + shi->dx_u= shi->dxco[axis1]*t11- shi->dxco[axis2]*t10; shi->dx_v= shi->dxco[axis2]*t00- shi->dxco[axis1]*t01; shi->dy_u= shi->dyco[axis1]*t11- shi->dyco[axis2]*t10; shi->dy_v= shi->dyco[axis2]*t00- shi->dyco[axis1]*t01; - + } /* main ray shader */ @@ -494,7 +494,7 @@ void shade_ray(Isect *is, ShadeInput *shi, ShadeResult *shr) { ObjectInstanceRen *obi = (ObjectInstanceRen *)is->hit.ob; VlakRen *vlr = (VlakRen *)is->hit.face; - + /* set up view vector */ copy_v3_v3(shi->view, is->dir); @@ -502,7 +502,7 @@ void shade_ray(Isect *is, ShadeInput *shi, ShadeResult *shr) shi->co[0]= is->start[0]+is->dist*(shi->view[0]); shi->co[1]= is->start[1]+is->dist*(shi->view[1]); shi->co[2]= is->start[2]+is->dist*(shi->view[2]); - + normalize_v3(shi->view); shi->obi= obi; @@ -510,8 +510,8 @@ void shade_ray(Isect *is, ShadeInput *shi, ShadeResult *shr) shi->vlr= vlr; shi->mat= vlr->mat; shade_input_init_material(shi); - - if (is->isect==2) + + if (is->isect==2) shade_input_set_triangle_i(shi, obi, vlr, 0, 2, 3); else shade_input_set_triangle_i(shi, obi, vlr, 0, 1, 2); @@ -550,7 +550,7 @@ void shade_ray(Isect *is, ShadeInput *shi, ShadeResult *shr) else { shade_material_loop(shi, shr); } - + /* raytrace likes to separate the spec color */ sub_v3_v3v3(shr->diff, shr->combined, shr->spec); copy_v3_v3(shr->diffshad, shr->diff); @@ -563,7 +563,7 @@ static int refraction(float refract[3], const float n[3], const float view[3], f float dot, fac; copy_v3_v3(refract, view); - + dot = dot_v3v3(view, n); if (dot>0.0f) { @@ -612,7 +612,7 @@ static void reflection(float ref[3], float n[3], const float view[3], const floa static void color_combine(float *result, float fac1, float fac2, float col1[3], float col2[3]) { float col1t[3], col2t[3]; - + col1t[0]= sqrt(col1[0]); col1t[1]= sqrt(col1[1]); col1t[2]= sqrt(col1[2]); @@ -634,7 +634,7 @@ static float shade_by_transmission(Isect *is, ShadeInput *shi, ShadeResult *shr) float d; if (0 == (shi->mat->mode & MA_TRANSP)) return -1; - + if (shi->mat->tx_limit <= 0.0f) { d= 1.0f; } @@ -670,7 +670,7 @@ static void ray_fadeout_endcolor(float col[3], ShadeInput *origshi, ShadeInput * else if (origshi->mat->fadeto_mir == MA_RAYMIR_FADETOSKY) { copy_v3_v3(shi->view, vec); normalize_v3(shi->view); - + shadeSkyView(col, isec->start, shi->view, NULL, shi->thread); shadeSunView(col, shi->view); } @@ -682,7 +682,7 @@ static void ray_fadeout(Isect *is, ShadeInput *shi, float col[3], const float bl float blendfac; blendfac = 1.0f - len_v3v3(shi->co, is->start)/dist_mir; - + col[0] = col[0]*blendfac + (1.0f - blendfac)*blendcol[0]; col[1] = col[1]*blendfac + (1.0f - blendfac)*blendcol[1]; col[2] = col[2]*blendfac + (1.0f - blendfac)*blendcol[2]; @@ -704,7 +704,7 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, con zero_v4(col); return; } - + copy_v3_v3(isec.start, start); copy_v3_v3(isec.dir, dir); isec.dist = dist_mir > 0 ? dist_mir : RE_RAYTRACE_MAXDIST; @@ -716,7 +716,7 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, con isec.orig.ob = obi; isec.orig.face = vlr; RE_RC_INIT(isec, shi); - + /* database is in original view, obi->imat transforms current position back to original */ RE_instance_rotate_ray(origshi->obi, &isec); @@ -725,11 +725,11 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, con float d= 1.0f; RE_instance_rotate_ray_restore(origshi->obi, &isec); - + /* for as long we don't have proper dx/dy transform for rays we copy over original */ copy_v3_v3(shi.dxco, origshi->dxco); copy_v3_v3(shi.dyco, origshi->dyco); - + shi.mask= origshi->mask; shi.osatex= origshi->osatex; shi.depth= origshi->depth + 1; /* only used to indicate tracing */ @@ -744,18 +744,18 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, con //shi.do_preview = false; // memset above, so don't need this shi.light_override= origshi->light_override; shi.mat_override= origshi->mat_override; - + shade_ray(&isec, &shi, &shr); /* ray has traveled inside the material, so shade by transmission */ if (traflag & RAY_INSIDE) d= shade_by_transmission(&isec, &shi, &shr); - + if (depth>0) { float fr, fg, fb, f1; if ((shi.mat->mode_l & MA_TRANSP) && shr.alpha < 1.0f && (shi.mat->mode_l & (MA_ZTRANSP | MA_RAYTRANSP))) { float nf, f, refract[3], tracol[4]; - + tracol[0]= shi.r; tracol[1]= shi.g; tracol[2]= shi.b; @@ -764,7 +764,7 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, con if ((shi.mat->mode & MA_TRANSP) && (shi.mat->mode & MA_RAYTRANSP)) { /* don't overwrite traflag, it's value is used in mirror reflection */ int new_traflag = traflag; - + if (new_traflag & RAY_INSIDE) { /* inside the material, so use inverse normal */ float norm[3]; @@ -795,7 +795,7 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, con } else traceray(origshi, origshr, depth-1, shi.co, shi.view, tracol, shi.obi, shi.vlr, 0); - + f= shr.alpha; f1= 1.0f-f; nf= (shi.mat->mode & MA_RAYTRANSP) ? d * shi.mat->filter : 0.0f; fr= 1.0f+ nf*(shi.r-1.0f); @@ -804,7 +804,7 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, con shr.diff[0]= f*shr.diff[0] + f1*fr*tracol[0]; shr.diff[1]= f*shr.diff[1] + f1*fg*tracol[1]; shr.diff[2]= f*shr.diff[2] + f1*fb*tracol[2]; - + shr.spec[0] *=f; shr.spec[1] *=f; shr.spec[2] *=f; @@ -821,14 +821,14 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, con if (f!=0.0f) f*= fresnel_fac(shi.view, shi.vn, shi.mat->fresnel_mir_i, shi.mat->fresnel_mir); } else f= 0.0f; - + if (f!=0.0f) { float mircol[4]; float ref[3]; - + reflection_simple(ref, shi.vn, shi.view); traceray(origshi, origshr, depth-1, shi.co, ref, mircol, shi.obi, shi.vlr, traflag); - + f1= 1.0f-f; /* combine */ @@ -836,11 +836,11 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, con //col[0]+= shr.spec[0]; //col[1]+= shr.spec[1]; //col[2]+= shr.spec[2]; - + fr= shi.mirr; fg= shi.mirg; fb= shi.mirb; - + col[0]= f*fr*(1.0f-shr.spec[0])*mircol[0] + f1*shr.diff[0] + shr.spec[0]; col[1]= f*fg*(1.0f-shr.spec[1])*mircol[1] + f1*shr.diff[1] + shr.spec[1]; col[2]= f*fb*(1.0f-shr.spec[2])*mircol[2] + f1*shr.diff[2] + shr.spec[2]; @@ -850,10 +850,10 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, con col[1]= shr.diff[1] + shr.spec[1]; col[2]= shr.diff[2] + shr.spec[2]; } - + if (dist_mir > 0.0f) { float blendcol[3]; - + /* max ray distance set, but found an intersection, so fade this color * out towards the sky/material color for a smooth transition */ ray_fadeout_endcolor(blendcol, origshi, &shi, origshr, &isec, dir); @@ -865,7 +865,7 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, con col[1]= shr.diff[1] + shr.spec[1]; col[2]= shr.diff[2] + shr.spec[2]; } - + } else { ray_fadeout_endcolor(col, origshi, &shi, origshr, &isec, dir); @@ -882,11 +882,11 @@ static void DP_energy(float *table, float vec[2], int tot, float xsize, float ys int x, y, a; float *fp, force[3], result[3]; float dx, dy, dist, min; - + min= MIN2(xsize, ysize); min*= min; result[0]= result[1]= 0.0f; - + for (y= -1; y<2; y++) { dy= ysize*y; for (x= -1; x<2; x++) { @@ -917,7 +917,7 @@ static void jitter_plane_offset(float *jitter1, float *jitter2, int tot, float s float dsizey= sizey*ofsy; float hsizex= 0.5f*sizex, hsizey= 0.5f*sizey; int x; - + for (x=tot; x>0; x--, jitter1+=2, jitter2+=2) { jitter2[0]= jitter1[0] + dsizex; jitter2[1]= jitter1[1] + dsizey; @@ -932,15 +932,15 @@ void init_jitter_plane(LampRen *lar) { float *fp; int x, tot= lar->ray_totsamp; - + /* test if already initialized */ if (lar->jitter) return; - + /* at least 4, or max threads+1 tables */ if (BLENDER_MAX_THREADS < 4) x= 4; else x= BLENDER_MAX_THREADS+1; fp= lar->jitter= MEM_callocN(x*tot*2*sizeof(float), "lamp jitter tab"); - + /* if 1 sample, we leave table to be zero's */ if (tot>1) { /* set per-lamp fixed seed */ @@ -952,7 +952,7 @@ void init_jitter_plane(LampRen *lar) fp[0]= (BLI_rng_get_float(rng)-0.5f)*lar->area_size; fp[1]= (BLI_rng_get_float(rng)-0.5f)*lar->area_sizey; } - + while (iter--) { fp= lar->jitter; for (x=tot; x>0; x--, fp+=2) { @@ -972,15 +972,15 @@ void init_jitter_plane(LampRen *lar) static float *give_jitter_plane(LampRen *lar, int thread, int xs, int ys) { int tot; - + tot= lar->ray_totsamp; - + if (lar->ray_samp_type & LA_SAMP_JITTER) { /* made it threadsafe */ - + if (lar->xold[thread]!=xs || lar->yold[thread]!=ys) { jitter_plane_offset(lar->jitter, lar->jitter+2*(thread+1)*tot, tot, lar->area_size, lar->area_sizey, BLI_thread_frand(thread), BLI_thread_frand(thread)); - lar->xold[thread]= xs; + lar->xold[thread]= xs; lar->yold[thread]= ys; } return lar->jitter+2*(thread+1)*tot; @@ -988,7 +988,7 @@ static float *give_jitter_plane(LampRen *lar, int thread, int xs, int ys) if (lar->ray_samp_type & LA_SAMP_DITHER) { return lar->jitter + 2*tot*((xs & 1)+2*(ys & 1)); } - + return lar->jitter; } @@ -1003,21 +1003,21 @@ static void halton_sample(double *ht_invprimes, double *ht_nums, double *v) for (i = 0; i < 2; i++) { double r = fabs((1.0 - ht_nums[i]) - 1e-10); - + if (ht_invprimes[i] >= r) { double lasth; double h = ht_invprimes[i]; - + do { lasth = h; h *= ht_invprimes[i]; } while (h >= r); - + ht_nums[i] += ((lasth + h) - 1.0); } else ht_nums[i] += ht_invprimes[i]; - + v[i] = (float)ht_nums[i]; } } @@ -1036,23 +1036,23 @@ static void hammersley_create(double *out, int n) t += p; } } - + out[2 * k + 0] = (double)k / (double)n; out[2 * k + 1] = t; } } static struct QMCSampler *QMC_initSampler(int type, int tot) -{ +{ QMCSampler *qsa = MEM_callocN(sizeof(QMCSampler), "qmc sampler"); qsa->samp2d = MEM_callocN(2*sizeof(double)*tot, "qmc sample table"); qsa->tot = tot; qsa->type = type; - - if (qsa->type==SAMP_TYPE_HAMMERSLEY) + + if (qsa->type==SAMP_TYPE_HAMMERSLEY) hammersley_create(qsa->samp2d, qsa->tot); - + return qsa; } @@ -1065,19 +1065,19 @@ static void QMC_initPixel(QMCSampler *qsa, int thread) qsa->offs[thread][1] = 0.5f * BLI_thread_frand(thread); } else { /* SAMP_TYPE_HALTON */ - + /* generate a new randomized halton sequence per pixel - * to alleviate qmc artifacts and make it reproducible + * to alleviate qmc artifacts and make it reproducible * between threads/frames */ double ht_invprimes[2], ht_nums[2]; double r[2]; int i; - + ht_nums[0] = BLI_thread_frand(thread); ht_nums[1] = BLI_thread_frand(thread); ht_invprimes[0] = 0.5; ht_invprimes[1] = 1.0/3.0; - + for (i=0; i< qsa->tot; i++) { halton_sample(ht_invprimes, ht_nums, r); qsa->samp2d[2*i+0] = r[0]; @@ -1109,7 +1109,7 @@ static void QMC_samplePhong(float vec[3], QMCSampler *qsa, int thread, int num, { double s[2]; float phi, pz, sqr; - + QMC_getSample(s, qsa, thread, num); phi = s[0]*2*M_PI; @@ -1127,7 +1127,7 @@ static void QMC_sampleRect(float vec[3], QMCSampler *qsa, int thread, int num, f double s[2]; QMC_getSample(s, qsa, thread, num); - + vec[0] = (float)(s[0] - 0.5) * sizex; vec[1] = (float)(s[1] - 0.5) * sizey; vec[2] = 0.0f; @@ -1138,9 +1138,9 @@ static void QMC_sampleDisc(float vec[3], QMCSampler *qsa, int thread, int num, f { double s[2]; float phi, sqr; - + QMC_getSample(s, qsa, thread, num); - + phi = s[0]*2*M_PI; sqr = sqrt(s[1]); @@ -1154,9 +1154,9 @@ static void QMC_sampleHemi(float vec[3], QMCSampler *qsa, int thread, int num) { double s[2]; float phi, sqr; - + QMC_getSample(s, qsa, thread, num); - + phi = s[0]*2.0*M_PI; sqr = sqrt(s[1]); @@ -1171,9 +1171,9 @@ static void QMC_sampleHemiCosine(float vec[3], QMCSampler *qsa, int thread, int { double s[2]; float phi, sqr; - + QMC_getSample(s, qsa, thread, num); - + phi = s[0]*2.f*M_PI; sqr = s[1]*sqrt(2-s[1]*s[1]); @@ -1241,10 +1241,10 @@ static int adaptive_sample_variance(int samples, const float col[3], const float { float var[3], mean[3]; - /* scale threshold just to give a bit more precision in input rather than dealing with + /* scale threshold just to give a bit more precision in input rather than dealing with * tiny tiny numbers in the UI */ thresh /= 2; - + mean[0] = col[0] / (float)samples; mean[1] = col[1] / (float)samples; mean[2] = col[2] / (float)samples; @@ -1252,7 +1252,7 @@ static int adaptive_sample_variance(int samples, const float col[3], const float var[0] = (colsq[0] / (float)samples) - (mean[0]*mean[0]); var[1] = (colsq[1] / (float)samples) - (mean[1]*mean[1]); var[2] = (colsq[2] / (float)samples) - (mean[2]*mean[2]); - + if ((var[0] * 0.4f < thresh) && (var[1] * 0.3f < thresh) && (var[2] * 0.6f < thresh)) return 1; else @@ -1262,7 +1262,7 @@ static int adaptive_sample_variance(int samples, const float col[3], const float static int adaptive_sample_contrast_val(int samples, float prev, float val, float thresh) { /* if the last sample's contribution to the total value was below a small threshold - * (i.e. the samples taken are very similar), then taking more samples that are probably + * (i.e. the samples taken are very similar), then taking more samples that are probably * going to be the same is wasting effort */ if (fabsf(prev / (float)(samples - 1) - val / (float)samples ) < thresh) { return 1; @@ -1274,14 +1274,14 @@ static int adaptive_sample_contrast_val(int samples, float prev, float val, floa static float get_avg_speed(ShadeInput *shi) { float pre_x, pre_y, post_x, post_y, speedavg; - + pre_x = (shi->winspeed[0] == PASS_VECTOR_MAX)?0.0f:shi->winspeed[0]; pre_y = (shi->winspeed[1] == PASS_VECTOR_MAX)?0.0f:shi->winspeed[1]; post_x = (shi->winspeed[2] == PASS_VECTOR_MAX)?0.0f:shi->winspeed[2]; post_y = (shi->winspeed[3] == PASS_VECTOR_MAX)?0.0f:shi->winspeed[3]; - + speedavg = (sqrtf(pre_x * pre_x + pre_y * pre_y) + sqrtf(post_x * post_x + post_y * post_y)) / 2.0f; - + return speedavg; } @@ -1293,17 +1293,17 @@ static void trace_refract(float col[4], ShadeInput *shi, ShadeResult *shr) QMCSampler *qsa=NULL; int samp_type; int traflag=0; - + float samp3d[3], orthx[3], orthy[3]; float v_refract[3], v_refract_new[3]; float sampcol[4], colsq[4]; - + float blur = pow3f(1.0f - shi->mat->gloss_tra); short max_samples = shi->mat->samp_gloss_tra; float adapt_thresh = shi->mat->adapt_thresh_tra; - + int samples=0; - + colsq[0] = colsq[1] = colsq[2] = 0.0; col[0] = col[1] = col[2] = 0.0; col[3]= shr->alpha; @@ -1311,14 +1311,14 @@ static void trace_refract(float col[4], ShadeInput *shi, ShadeResult *shr) if (blur > 0.0f) { if (adapt_thresh != 0.0f) samp_type = SAMP_TYPE_HALTON; else samp_type = SAMP_TYPE_HAMMERSLEY; - + /* all samples are generated per pixel */ qsa = get_thread_qmcsampler(&R, shi->thread, samp_type, max_samples); QMC_initPixel(qsa, shi->thread); } else max_samples = 1; - + while (samples < max_samples) { if (refraction(v_refract, shi->vn, shi->view, shi->ang)) { @@ -1326,7 +1326,7 @@ static void trace_refract(float col[4], ShadeInput *shi, ShadeResult *shr) } else { /* total external reflection can happen for materials with IOR < 1.0 */ - if ((shi->vlr->flag & R_SMOOTH)) + if ((shi->vlr->flag & R_SMOOTH)) reflection(v_refract, shi->vn, shi->view, shi->facenor); else reflection_simple(v_refract, shi->vn, shi->view); @@ -1334,58 +1334,58 @@ static void trace_refract(float col[4], ShadeInput *shi, ShadeResult *shr) /* can't blur total external reflection */ max_samples = 1; } - + if (max_samples > 1) { /* get a quasi-random vector from a phong-weighted disc */ QMC_samplePhong(samp3d, qsa, shi->thread, samples, blur); - + ortho_basis_v3v3_v3(orthx, orthy, v_refract); mul_v3_fl(orthx, samp3d[0]); mul_v3_fl(orthy, samp3d[1]); - + /* and perturb the refraction vector in it */ add_v3_v3v3(v_refract_new, v_refract, orthx); add_v3_v3(v_refract_new, orthy); - + normalize_v3(v_refract_new); } else { /* no blurriness, use the original normal */ copy_v3_v3(v_refract_new, v_refract); } - + sampcol[0]= sampcol[1]= sampcol[2]= sampcol[3]= 0.0f; traceray(shi, shr, shi->mat->ray_depth_tra, shi->co, v_refract_new, sampcol, shi->obi, shi->vlr, traflag); - + col[0] += sampcol[0]; col[1] += sampcol[1]; col[2] += sampcol[2]; col[3] += sampcol[3]; - + /* for variance calc */ colsq[0] += sampcol[0]*sampcol[0]; colsq[1] += sampcol[1]*sampcol[1]; colsq[2] += sampcol[2]*sampcol[2]; - + samples++; - + /* adaptive sampling */ if (adapt_thresh < 1.0f && samples > max_samples/2) { if (adaptive_sample_variance(samples, col, colsq, adapt_thresh)) break; - + /* if the pixel so far is very dark, we can get away with less samples */ if ( (col[0] + col[1] + col[2])/3.0f/(float)samples < 0.01f ) max_samples--; } } - + col[0] /= (float)samples; col[1] /= (float)samples; col[2] /= (float)samples; col[3] /= (float)samples; - + if (qsa) release_thread_qmcsampler(&R, shi->thread, qsa); } @@ -1394,34 +1394,34 @@ static void trace_reflect(float col[3], ShadeInput *shi, ShadeResult *shr, float { QMCSampler *qsa=NULL; int samp_type; - + float samp3d[3], orthx[3], orthy[3]; float v_nor_new[3], v_reflect[3]; float sampcol[4], colsq[4]; - + float blur = pow3f(1.0f - shi->mat->gloss_mir); short max_samples = shi->mat->samp_gloss_mir; float adapt_thresh = shi->mat->adapt_thresh_mir; float aniso = 1.0f - shi->mat->aniso_gloss_mir; - + int samples=0; - + col[0] = col[1] = col[2] = 0.0; colsq[0] = colsq[1] = colsq[2] = 0.0; - + if (blur > 0.0f) { if (adapt_thresh != 0.0f) samp_type = SAMP_TYPE_HALTON; else samp_type = SAMP_TYPE_HAMMERSLEY; - + /* all samples are generated per pixel */ qsa = get_thread_qmcsampler(&R, shi->thread, samp_type, max_samples); QMC_initPixel(qsa, shi->thread); } else max_samples = 1; - + while (samples < max_samples) { - + if (max_samples > 1) { /* get a quasi-random vector from a phong-weighted disc */ QMC_samplePhong(samp3d, qsa, shi->thread, samples, blur); @@ -1449,53 +1449,53 @@ static void trace_reflect(float col[3], ShadeInput *shi, ShadeResult *shr, float /* no blurriness, use the original normal */ copy_v3_v3(v_nor_new, shi->vn); } - - if ((shi->vlr->flag & R_SMOOTH)) + + if ((shi->vlr->flag & R_SMOOTH)) reflection(v_reflect, v_nor_new, shi->view, shi->facenor); else reflection_simple(v_reflect, v_nor_new, shi->view); - + sampcol[0]= sampcol[1]= sampcol[2]= sampcol[3]= 0.0f; traceray(shi, shr, shi->mat->ray_depth, shi->co, v_reflect, sampcol, shi->obi, shi->vlr, 0); - + col[0] += sampcol[0]; col[1] += sampcol[1]; col[2] += sampcol[2]; - + /* for variance calc */ colsq[0] += sampcol[0]*sampcol[0]; colsq[1] += sampcol[1]*sampcol[1]; colsq[2] += sampcol[2]*sampcol[2]; - + samples++; /* adaptive sampling */ if (adapt_thresh > 0.0f && samples > max_samples/3) { if (adaptive_sample_variance(samples, col, colsq, adapt_thresh)) break; - + /* if the pixel so far is very dark, we can get away with less samples */ if ( (col[0] + col[1] + col[2])/3.0f/(float)samples < 0.01f ) max_samples--; - + /* reduce samples when reflection is dim due to low ray mirror blend value or fresnel factor * and when reflection is blurry */ if (fresnelfac < 0.1f * (blur+1)) { max_samples--; - + /* even more for very dim */ if (fresnelfac < 0.05f * (blur+1)) max_samples--; } } } - + col[0] /= (float)samples; col[1] /= (float)samples; col[2] /= (float)samples; - + if (qsa) release_thread_qmcsampler(&R, shi->thread, qsa); } @@ -1507,48 +1507,48 @@ void ray_trace(ShadeInput *shi, ShadeResult *shr) float mircol[4], tracol[4]; float diff[3]; int do_tra, do_mir; - + do_tra = ((shi->mode & MA_TRANSP) && (shi->mode & MA_RAYTRANSP) && shr->alpha != 1.0f && (shi->depth <= shi->mat->ray_depth_tra)); do_mir = ((shi->mat->mode & MA_RAYMIRROR) && shi->ray_mirror != 0.0f && (shi->depth <= shi->mat->ray_depth)); - + /* raytrace mirror and refract like to separate the spec color */ if (shi->combinedflag & SCE_PASS_SPEC) sub_v3_v3v3(diff, shr->combined, shr->spec); else copy_v3_v3(diff, shr->combined); - + if (do_tra) { float olddiff[3], f; - + trace_refract(tracol, shi, shr); - + f= shr->alpha; f1= 1.0f-f; fr= 1.0f+ shi->mat->filter*(shi->r-1.0f); fg= 1.0f+ shi->mat->filter*(shi->g-1.0f); fb= 1.0f+ shi->mat->filter*(shi->b-1.0f); - + /* for refract pass */ copy_v3_v3(olddiff, diff); - + diff[0]= f*diff[0] + f1*fr*tracol[0]; diff[1]= f*diff[1] + f1*fg*tracol[1]; diff[2]= f*diff[2] + f1*fb*tracol[2]; - + if (shi->passflag & SCE_PASS_REFRACT) sub_v3_v3v3(shr->refr, diff, olddiff); - + if (!(shi->combinedflag & SCE_PASS_REFRACT)) sub_v3_v3v3(diff, diff, shr->refr); - + shr->alpha = min_ff(1.0f, tracol[3]); } - + if (do_mir) { const float i= shi->ray_mirror*fresnel_fac(shi->view, shi->vn, shi->mat->fresnel_mir_i, shi->mat->fresnel_mir); if (i!=0.0f) { - + trace_reflect(mircol, shi, shr, i); - + fr= i*shi->mirr; fg= i*shi->mirg; fb= i*shi->mirb; @@ -1559,19 +1559,19 @@ void ray_trace(ShadeInput *shi, ShadeResult *shr) shr->refl[1]= fg*mircol[1] - fg*diff[1]; shr->refl[2]= fb*mircol[2] - fb*diff[2]; } - + if (shi->combinedflag & SCE_PASS_REFLECT) { /* values in shr->spec can be greater than 1.0. * In this case the mircol uses a zero blending factor, so ignoring it is ok. * Fixes bug #18837 - when the spec is higher then 1.0, * diff can become a negative color - Campbell */ - + f1= 1.0f-i; - + diff[0] *= f1; diff[1] *= f1; diff[2] *= f1; - + if (shr->spec[0]<1.0f) diff[0] += mircol[0] * (fr*(1.0f-shr->spec[0])); if (shr->spec[1]<1.0f) diff[1] += mircol[1] * (fg*(1.0f-shr->spec[1])); if (shr->spec[2]<1.0f) diff[2] += mircol[2] * (fb*(1.0f-shr->spec[2])); @@ -1590,15 +1590,15 @@ void ray_trace(ShadeInput *shi, ShadeResult *shr) static void addAlphaLight(float shadfac[4], const float col[3], float alpha, float filter) { float fr, fg, fb; - + fr= 1.0f+ filter*(col[0]-1.0f); fg= 1.0f+ filter*(col[1]-1.0f); fb= 1.0f+ filter*(col[2]-1.0f); - + shadfac[0]= alpha*col[0] + fr*(1.0f-alpha)*shadfac[0]; shadfac[1]= alpha*col[1] + fg*(1.0f-alpha)*shadfac[1]; shadfac[2]= alpha*col[2] + fb*(1.0f-alpha)*shadfac[2]; - + shadfac[3]= (1.0f-alpha)*shadfac[3]; } @@ -1625,13 +1625,13 @@ static void ray_trace_shadow_tra(Isect *is, ShadeInput *origshi, int depth, int shi.thread= origshi->thread; shi.passflag= SCE_PASS_COMBINED; shi.combinedflag= 0xFFFFFF; /* ray trace does all options */ - + shi.xs= origshi->xs; shi.ys= origshi->ys; shi.do_manage= origshi->do_manage; shi.lay= origshi->lay; shi.nodes= origshi->nodes; - + RE_instance_rotate_ray_restore(origshi->obi, is); shade_ray(is, &shi, &shr); @@ -1644,16 +1644,16 @@ static void ray_trace_shadow_tra(Isect *is, ShadeInput *origshi, int depth, int } else if (shi.mat->material_type == MA_TYPE_VOLUME) { const float a = col[3]; - + col[0] = a*col[0] + shr.alpha*shr.combined[0]; col[1] = a*col[1] + shr.alpha*shr.combined[1]; col[2] = a*col[2] + shr.alpha*shr.combined[2]; - + col[3] = (1.0f - shr.alpha)*a; } - + if (depth>0 && col[3]>0.0f) { - + /* adapt isect struct */ copy_v3_v3(is->start, shi.co); is->dist = initial_dist-is->dist; @@ -1662,7 +1662,7 @@ static void ray_trace_shadow_tra(Isect *is, ShadeInput *origshi, int depth, int ray_trace_shadow_tra(is, origshi, depth-1, traflag | RAY_TRA, col); } - + RE_RC_MERGE(&origshi->raycounter, &shi.raycounter); } } @@ -1675,9 +1675,9 @@ static void DS_energy(float *sphere, int tot, float vec[3]) { float *fp, fac, force[3], res[3]; int a; - + res[0]= res[1]= res[2]= 0.0f; - + for (a=0, fp=sphere; aaosamp*wrld->aosamp; - + wrld->aosphere= MEM_mallocN(3*tot*sizeof(float), "AO sphere"); rng = BLI_rng_new_srandom(tot); - + /* init */ fp= wrld->aosphere; for (a=0; aaosphere; aaosphere, tot, fp); } } - + /* tables */ wrld->aotables= MEM_mallocN(num_threads*3*tot*sizeof(float), "AO tables"); @@ -1735,13 +1735,13 @@ static float *threadsafe_table_sphere(int test, int thread, int xs, int ys, int { static int xso[BLENDER_MAX_THREADS], yso[BLENDER_MAX_THREADS]; static int firsttime= 1; - + if (firsttime) { memset(xso, 255, sizeof(xso)); memset(yso, 255, sizeof(yso)); firsttime= 0; } - + if (xs==xso[thread] && ys==yso[thread]) return R.wrld.aotables+ thread*tot*3; if (test) return NULL; xso[thread]= xs; yso[thread]= ys; @@ -1752,7 +1752,7 @@ static float *sphere_sampler(int type, int resol, int thread, int xs, int ys, in { int tot; float *vec; - + tot= 2*resol*resol; if (type & WO_AORNDSMP) { @@ -1760,7 +1760,7 @@ static float *sphere_sampler(int type, int resol, int thread, int xs, int ys, in RNG *rng = BLI_rng_new(BLI_thread_rand(thread)); float *sphere; int a; - + /* always returns table */ sphere= threadsafe_table_sphere(0, thread, xs, ys, tot); @@ -1770,13 +1770,13 @@ static float *sphere_sampler(int type, int resol, int thread, int xs, int ys, in } BLI_rng_free(rng); - + return sphere; } else { float *sphere; float *vec1; - + /* returns table if xs and ys were equal to last call, and not resetting */ sphere= (reset)? NULL: threadsafe_table_sphere(1, thread, xs, ys, tot); if (sphere==NULL) { @@ -1785,13 +1785,13 @@ static float *sphere_sampler(int type, int resol, int thread, int xs, int ys, in int a; sphere= threadsafe_table_sphere(0, thread, xs, ys, tot); - + /* random rotation */ ang = BLI_thread_frand(thread); sinfi = sinf(ang); cosfi = cosf(ang); ang = BLI_thread_frand(thread); sint = sinf(ang); cost = cosf(ang); - + vec= R.wrld.aosphere; vec1= sphere; for (a=0; aobi; isec.orig.face = shi->vlr; @@ -1834,31 +1834,31 @@ static void ray_ao_qmc(ShadeInput *shi, float ao[3], float env[3]) isec.hit.face = NULL; isec.last_hit = NULL; - + isec.mode= (R.wrld.aomode & WO_AODIST)?RE_RAY_SHADOW_TRA:RE_RAY_SHADOW; isec.lay= -1; - + copy_v3_v3(isec.start, shi->co); - + RE_instance_rotate_ray_start(shi->obi, &isec); - + RE_rayobject_hint_bb(R.raytree, &point_hint, isec.start, isec.start); isec.hint = &point_hint; zero_v3(ao); zero_v3(env); - + /* prevent sky colors to be added for only shadow (shadow becomes alpha) */ envcolor= R.wrld.aocolor; if (shi->mat->mode & MA_ONLYSHADOW) envcolor= WO_AOPLAIN; - + if (envcolor == WO_AOSKYTEX) { dxyview[0]= 1.0f/(float)R.wrld.aosamp; dxyview[1]= 1.0f/(float)R.wrld.aosamp; dxyview[2]= 0.0f; } - + if (shi->vlr->flag & R_SMOOTH) { copy_v3_v3(nrm, shi->vn); } @@ -1867,23 +1867,23 @@ static void ray_ao_qmc(ShadeInput *shi, float ao[3], float env[3]) } ortho_basis_v3v3_v3(up, side, nrm); - + /* sampling init */ if (R.wrld.ao_samp_method==WO_AOSAMP_HALTON) { float speedfac; - + speedfac = get_avg_speed(shi) * adapt_speed_fac; CLAMP(speedfac, 1.0f, 1000.0f); max_samples /= speedfac; if (max_samples < 5) max_samples = 5; - + qsa = get_thread_qmcsampler(&R, shi->thread, SAMP_TYPE_HALTON, max_samples); } else if (R.wrld.ao_samp_method==WO_AOSAMP_HAMMERSLEY) qsa = get_thread_qmcsampler(&R, shi->thread, SAMP_TYPE_HAMMERSLEY, max_samples); QMC_initPixel(qsa, shi->thread); - + while (samples < max_samples) { /* sampling, returns quasi-random vector in unit hemisphere */ @@ -1892,18 +1892,18 @@ static void ray_ao_qmc(ShadeInput *shi, float ao[3], float env[3]) dir[0] = (samp3d[0]*up[0] + samp3d[1]*side[0] + samp3d[2]*nrm[0]); dir[1] = (samp3d[0]*up[1] + samp3d[1]*side[1] + samp3d[2]*nrm[1]); dir[2] = (samp3d[0]*up[2] + samp3d[1]*side[2] + samp3d[2]*nrm[2]); - + normalize_v3(dir); - + isec.dir[0] = -dir[0]; isec.dir[1] = -dir[1]; isec.dir[2] = -dir[2]; isec.dist = maxdist; - + RE_instance_rotate_ray_dir(shi->obi, &isec); - + prev = fac; - + if (RE_rayobject_raycast(R.raytree, &isec)) { if (R.wrld.aomode & WO_AODIST) fac+= expf(-isec.dist*R.wrld.aodistfac); else fac+= 1.0f; @@ -1911,12 +1911,12 @@ static void ray_ao_qmc(ShadeInput *shi, float ao[3], float env[3]) else if (envcolor!=WO_AOPLAIN) { float skycol[4]; float view[3]; - + view[0]= -dir[0]; view[1]= -dir[1]; view[2]= -dir[2]; normalize_v3(view); - + if (envcolor==WO_AOSKYCOL) { const float skyfac= 0.5f * (1.0f + dot_v3v3(view, R.grvec)); env[0]+= (1.0f-skyfac)*R.wrld.horr + skyfac*R.wrld.zenr; @@ -1932,20 +1932,20 @@ static void ray_ao_qmc(ShadeInput *shi, float ao[3], float env[3]) } skyadded++; } - + samples++; - + if (qsa && qsa->type == SAMP_TYPE_HALTON) { /* adaptive sampling - consider samples below threshold as in shadow (or vice versa) and exit early */ if (adapt_thresh > 0.0f && (samples > max_samples/2) ) { - + if (adaptive_sample_contrast_val(samples, prev, fac, adapt_thresh)) { break; } } } } - + /* average color times distances/hits formula */ ao[0]= ao[1]= ao[2]= 1.0f - fac/(float)samples; @@ -1953,7 +1953,7 @@ static void ray_ao_qmc(ShadeInput *shi, float ao[3], float env[3]) mul_v3_fl(env, (1.0f - fac/(float)samples)/((float)skyadded)); else copy_v3_v3(env, ao); - + if (qsa) release_thread_qmcsampler(&R, shi->thread, qsa); } @@ -1967,7 +1967,7 @@ static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3]) float maxdist = R.wrld.aodist; float dxyview[3]; int j= -1, tot, actual=0, skyadded=0, envcolor, resol= R.wrld.aosamp; - + RE_RC_INIT(isec, *shi); isec.orig.ob = shi->obi; isec.orig.face = shi->vlr; @@ -1977,9 +1977,9 @@ static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3]) isec.hit.ob = NULL; isec.hit.face = NULL; - + isec.last_hit = NULL; - + isec.mode= (R.wrld.aomode & WO_AODIST)?RE_RAY_SHADOW_TRA:RE_RAY_SHADOW; isec.lay= -1; @@ -2006,13 +2006,13 @@ static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3]) envcolor= R.wrld.aocolor; if (shi->mat->mode & MA_ONLYSHADOW) envcolor= WO_AOPLAIN; - + if (resol>32) resol= 32; /* get sphere samples. for faces we get the same samples for sample x/y values, * for strand render we always require a new sampler because x/y are not set */ vec= sphere_sampler(R.wrld.aomode, resol, shi->thread, shi->xs, shi->ys, shi->strand != NULL); - + /* warning: since we use full sphere now, and dotproduct is below, we do twice as much */ tot= 2*resol*resol; @@ -2021,9 +2021,9 @@ static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3]) dxyview[1]= 1.0f/(float)resol; dxyview[2]= 0.0f; } - + while (tot--) { - + if (dot_v3v3(vec, nrm) > bias) { /* only ao samples for mask */ if (R.r.mode & R_OSA) { @@ -2034,15 +2034,15 @@ static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3]) continue; } } - + actual++; - + /* always set start/vec/dist */ isec.dir[0] = -vec[0]; isec.dir[1] = -vec[1]; isec.dir[2] = -vec[2]; isec.dist = maxdist; - + RE_instance_rotate_ray_dir(shi->obi, &isec); /* do the trace */ @@ -2053,12 +2053,12 @@ static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3]) else if (envcolor!=WO_AOPLAIN) { float skycol[4]; float view[3]; - + view[0]= -vec[0]; view[1]= -vec[1]; view[2]= -vec[2]; normalize_v3(view); - + if (envcolor==WO_AOSKYCOL) { const float fac = 0.5f * (1.0f + dot_v3v3(view, R.grvec)); env[0]+= (1.0f-fac)*R.wrld.horr + fac*R.wrld.zenr; @@ -2078,10 +2078,10 @@ static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3]) /* samples */ vec+= 3; } - + if (actual==0) sh= 1.0f; else sh = 1.0f - sh/((float)actual); - + /* average color times distances/hits formula */ ao[0]= ao[1]= ao[2]= sh; @@ -2169,10 +2169,10 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], } else shadfac[3]= 1.0f; - + if (lar->ray_totsamp < 2) do_soft = false; if ((R.r.mode & R_OSA) && (R.osa > 0) && (shi->vlr->flag & R_FULL_OSA)) full_osa = true; - + if (full_osa) { if (do_soft) max_samples = max_samples/R.osa + 1; else max_samples = 1; @@ -2182,7 +2182,7 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], else if (shi->depth == 0) max_samples = (R.osa > 4)?R.osa:5; else max_samples = 1; } - + ray_shadow_jittered_coords(shi, max_samples, jitco, &totjitco); /* sampling init */ @@ -2190,7 +2190,7 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], qsa = get_thread_qmcsampler(&R, shi->thread, SAMP_TYPE_HALTON, max_samples); else if (lar->ray_samp_method==LA_SAMP_HAMMERSLEY) qsa = get_thread_qmcsampler(&R, shi->thread, SAMP_TYPE_HAMMERSLEY, max_samples); - + QMC_initPixel(qsa, shi->thread); INIT_MINMAX(min, max); @@ -2202,19 +2202,19 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], mul_m4_v3(shi->obi->imat, max); } RE_rayobject_hint_bb(R.raytree, &bb_hint, min, max); - + isec->hint = &bb_hint; isec->check = RE_CHECK_VLR_RENDER; isec->skip = RE_SKIP_VLR_NEIGHBOUR; copy_v3_v3(vec, lampco); - + while (samples < max_samples) { isec->orig.ob = shi->obi; isec->orig.face = shi->vlr; /* manually jitter the start shading co-ord per sample - * based on the pre-generated OSA texture sampling offsets, + * based on the pre-generated OSA texture sampling offsets, * for anti-aliasing sharp shadow edges. */ copy_v3_v3(start, jitco[samples % totjitco]); @@ -2222,12 +2222,12 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], /* sphere shadow source */ if (lar->type == LA_LOCAL) { float ru[3], rv[3], v[3], s[3]; - + /* calc tangent plane vectors */ sub_v3_v3v3(v, start, lampco); normalize_v3(v); ortho_basis_v3v3_v3(ru, rv, v); - + /* sampling, returns quasi-random vector in area_size disc */ QMC_sampleDisc(samp3d, qsa, shi->thread, samples, lar->area_size); @@ -2235,13 +2235,13 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], s[0] = samp3d[0]*ru[0] + samp3d[1]*rv[0]; s[1] = samp3d[0]*ru[1] + samp3d[1]*rv[1]; s[2] = samp3d[0]*ru[2] + samp3d[1]*rv[2]; - + copy_v3_v3(samp3d, s); } else { /* sampling, returns quasi-random vector in [sizex,sizey]^2 plane */ QMC_sampleRect(samp3d, qsa, shi->thread, samples, lar->area_size, lar->area_sizey); - + /* align samples to lamp vector */ mul_m3_v3(lar->mat, samp3d); } @@ -2265,23 +2265,23 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], start[1] -= jitbias*v[1]; start[2] -= jitbias*v[2]; } - + copy_v3_v3(isec->start, start); sub_v3_v3v3(isec->dir, end, start); isec->dist = normalize_v3(isec->dir); - + RE_instance_rotate_ray(shi->obi, isec); /* trace the ray */ if (isec->mode==RE_RAY_SHADOW_TRA) { float col[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - + ray_trace_shadow_tra(isec, shi, DEPTH_SHADOW_TRA, 0, col); shadfac[0] += col[0]; shadfac[1] += col[1]; shadfac[2] += col[2]; shadfac[3] += col[3]; - + /* for variance calc */ colsq[0] += col[0]*col[0]; colsq[1] += col[1]*col[1]; @@ -2290,11 +2290,11 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], else { if ( RE_rayobject_raycast(R.raytree, isec) ) fac+= 1.0f; } - + samples++; - + if (lar->ray_samp_method == LA_SAMP_HALTON) { - + /* adaptive sampling - consider samples below threshold as in shadow (or vice versa) and exit early */ if ((max_samples > min_adapt_samples) && (adapt_thresh > 0.0f) && (samples > max_samples / 3)) { if (isec->mode==RE_RAY_SHADOW_TRA) { @@ -2310,7 +2310,7 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], } } } - + if (isec->mode==RE_RAY_SHADOW_TRA) { shadfac[0] /= samples; shadfac[1] /= samples; @@ -2331,32 +2331,32 @@ static void ray_shadow_jitter(ShadeInput *shi, LampRen *lar, const float lampco[ float fac=0.0f, div=0.0f, vec[3]; int a, j= -1, mask; RayHint point_hint; - + if (isec->mode==RE_RAY_SHADOW_TRA) { shadfac[0]= shadfac[1]= shadfac[2]= shadfac[3]= 0.0f; } else shadfac[3]= 1.0f; - + fac= 0.0f; jitlamp= give_jitter_plane(lar, shi->thread, shi->xs, shi->ys); a= lar->ray_totsamp; - + /* this correction to make sure we always take at least 1 sample */ mask= shi->mask; if (a==4) mask |= (mask>>4)|(mask>>8); else if (a==9) mask |= (mask>>9); - + copy_v3_v3(isec->start, shi->co); RE_instance_rotate_ray_start(shi->obi, isec); - + isec->orig.ob = shi->obi; isec->orig.face = shi->vlr; RE_rayobject_hint_bb(R.raytree, &point_hint, isec->start, isec->start); isec->hint = &point_hint; - + while (a--) { - + if (R.r.mode & R_OSA) { j++; if (j>=R.osa) j= 0; @@ -2365,27 +2365,27 @@ static void ray_shadow_jitter(ShadeInput *shi, LampRen *lar, const float lampco[ continue; } } - + vec[0]= jitlamp[0]; vec[1]= jitlamp[1]; vec[2]= 0.0f; mul_m3_v3(lar->mat, vec); - + /* set start and vec */ isec->dir[0] = vec[0]+lampco[0]-shi->co[0]; isec->dir[1] = vec[1]+lampco[1]-shi->co[1]; isec->dir[2] = vec[2]+lampco[2]-shi->co[2]; - + RE_instance_rotate_ray_dir(shi->obi, isec); - + isec->dist = 1.0f; isec->check = RE_CHECK_VLR_RENDER; isec->skip = RE_SKIP_VLR_NEIGHBOUR; - + if (isec->mode==RE_RAY_SHADOW_TRA) { /* isec.col is like shadfac, so defines amount of light (0.0 is full shadow) */ float col[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - + ray_trace_shadow_tra(isec, shi, DEPTH_SHADOW_TRA, 0, col); shadfac[0] += col[0]; shadfac[1] += col[1]; @@ -2393,11 +2393,11 @@ static void ray_shadow_jitter(ShadeInput *shi, LampRen *lar, const float lampco[ shadfac[3] += col[3]; } else if ( RE_rayobject_raycast(R.raytree, isec) ) fac+= 1.0f; - + div+= 1.0f; jitlamp+= 2; } - + if (isec->mode==RE_RAY_SHADOW_TRA) { shadfac[0] /= div; shadfac[1] /= div; @@ -2423,7 +2423,7 @@ void ray_shadow(ShadeInput *shi, LampRen *lar, float shadfac[4]) if (shi->mat->mode & MA_SHADOW_TRA) isec.mode= RE_RAY_SHADOW_TRA; else isec.mode= RE_RAY_SHADOW; isec.hint = NULL; - + if (lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) isec.lay= lar->lay; else @@ -2436,7 +2436,7 @@ void ray_shadow(ShadeInput *shi, LampRen *lar, float shadfac[4]) else { isec.last_hit = NULL; } - + if (lar->type==LA_SUN || lar->type==LA_HEMI) { /* jitter and QMC sampling add a displace vector to the lamp position * that's incorrect because a SUN lamp does not has an exact position @@ -2444,10 +2444,10 @@ void ray_shadow(ShadeInput *shi, LampRen *lar, float shadfac[4]) * lamp position. * This is easily verified by noticing that shadows of SUN lights change * with the scene BB. - * + * * This was detected during SoC 2009 - Raytrace Optimization, but to keep * consistency with older render code it wasn't removed. - * + * * If the render code goes through some recode/serious bug-fix then this * is something to consider! */ @@ -2458,18 +2458,18 @@ void ray_shadow(ShadeInput *shi, LampRen *lar, float shadfac[4]) else { copy_v3_v3(lampco, lar->co); } - + if (ELEM(lar->ray_samp_method, LA_SAMP_HALTON, LA_SAMP_HAMMERSLEY)) { - + ray_shadow_qmc(shi, lar, lampco, shadfac, &isec); - + } else { if (lar->ray_totsamp<2) { - + isec.orig.ob = shi->obi; isec.orig.face = shi->vlr; - + shadfac[3]= 1.0f; /* 1.0=full light */ /* set up isec.dir */ @@ -2493,7 +2493,7 @@ void ray_shadow(ShadeInput *shi, LampRen *lar, float shadfac[4]) ray_shadow_jitter(shi, lar, lampco, shadfac, &isec); } } - + /* for first hit optim, set last interesected shadow face */ if (shi->depth==0) { lar->last_hit[shi->thread] = isec.last_hit; diff --git a/source/blender/render/intern/source/render_result.c b/source/blender/render/intern/source/render_result.c index 1531d60c83b..d9e83b209b8 100644 --- a/source/blender/render/intern/source/render_result.c +++ b/source/blender/render/intern/source/render_result.c @@ -95,7 +95,7 @@ void render_result_free(RenderResult *res) if (rl->acolrect) MEM_freeN(rl->acolrect); if (rl->scolrect) MEM_freeN(rl->scolrect); if (rl->display_buffer) MEM_freeN(rl->display_buffer); - + while (rl->passes.first) { RenderPass *rpass = rl->passes.first; if (rpass->rect) MEM_freeN(rpass->rect); @@ -128,13 +128,13 @@ void render_result_free(RenderResult *res) void render_result_free_list(ListBase *lb, RenderResult *rr) { RenderResult *rrnext; - + for (; rr; rr = rrnext) { rrnext = rr->next; - + if (lb && lb->first) BLI_remlink(lb, rr); - + render_result_free(rr); } } @@ -206,7 +206,7 @@ static RenderPass *render_layer_add_pass(RenderResult *rr, RenderLayer *rl, int const int view_id = BLI_findstringindex(&rr->views, viewname, offsetof(RenderView, name)); RenderPass *rpass = MEM_callocN(sizeof(RenderPass), name); size_t rectsize = ((size_t)rr->rectx) * rr->recty * channels; - + rpass->channels = channels; rpass->rectx = rl->rectx; rpass->recty = rl->recty; @@ -216,7 +216,7 @@ static RenderPass *render_layer_add_pass(RenderResult *rr, RenderLayer *rl, int BLI_strncpy(rpass->chan_id, chan_id, sizeof(rpass->chan_id)); BLI_strncpy(rpass->view, viewname, sizeof(rpass->view)); set_pass_full_name(rpass->fullname, rpass->name, -1, rpass->view, rpass->chan_id); - + if (rl->exrhandle) { int a; for (a = 0; a < channels; a++) { @@ -227,13 +227,13 @@ static RenderPass *render_layer_add_pass(RenderResult *rr, RenderLayer *rl, int else { float *rect; int x; - + rpass->rect = MEM_mapallocN(sizeof(float) * rectsize, name); if (rpass->rect == NULL) { MEM_freeN(rpass); return NULL; } - + if (STREQ(rpass->name, RE_PASSNAME_VECTOR)) { /* initialize to max speed */ rect = rpass->rect; @@ -269,13 +269,13 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf SceneRenderLayer *srl; int rectx, recty; int nr; - + rectx = BLI_rcti_size_x(partrct); recty = BLI_rcti_size_y(partrct); - + if (rectx <= 0 || recty <= 0) return NULL; - + rr = MEM_callocN(sizeof(RenderResult), "new render result"); rr->rectx = rectx; rr->recty = recty; @@ -288,7 +288,7 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf rr->tilerect.xmax = partrct->xmax - re->disprect.xmin; rr->tilerect.ymin = partrct->ymin - re->disprect.ymin; rr->tilerect.ymax = partrct->ymax - re->disprect.ymin; - + if (savebuffers) { rr->do_exr_tile = true; } @@ -310,10 +310,10 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf if (srl->layflag & SCE_LAY_DISABLE) continue; } - + rl = MEM_callocN(sizeof(RenderLayer), "new render layer"); BLI_addtail(&rr->layers, rl); - + BLI_strncpy(rl->name, srl->name, sizeof(rl->name)); rl->lay = srl->lay; rl->lay_zmask = srl->lay_zmask; @@ -325,7 +325,7 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf rl->mat_override = srl->mat_override; rl->rectx = rectx; rl->recty = recty; - + if (rr->do_exr_tile) { rl->display_buffer = MEM_mapallocN((size_t)rectx * recty * sizeof(unsigned int), "Combined display space rgba"); @@ -424,7 +424,7 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf if (BLI_listbase_is_empty(&rr->layers) && !(layername && layername[0])) { rl = MEM_callocN(sizeof(RenderLayer), "new render layer"); BLI_addtail(&rr->layers, rl); - + rl->rectx = rectx; rl->recty = recty; @@ -452,15 +452,15 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf rl->lay = (1 << 20) - 1; rl->layflag = 0x7FFF; /* solid ztra halo strand */ rl->passflag = SCE_PASS_COMBINED; - + re->r.actlay = 0; } - + /* border render; calculate offset for use in compositor. compo is centralized coords */ /* XXX obsolete? I now use it for drawing border render offset (ton) */ 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; } @@ -522,16 +522,16 @@ void render_result_add_pass(RenderResult *rr, const char *name, int channels, co RenderResult *render_result_new_full_sample(Render *re, ListBase *lb, rcti *partrct, int crop, int savebuffers, const char *viewname) { int a; - + if (re->osa == 0) return render_result_new(re, partrct, crop, savebuffers, RR_ALL_LAYERS, viewname); - + for (a = 0; a < re->osa; a++) { RenderResult *rr = render_result_new(re, partrct, crop, savebuffers, RR_ALL_LAYERS, viewname); BLI_addtail(lb, rr); rr->sample_nr = a; } - + return lb->first; } @@ -584,7 +584,7 @@ static void *ml_addlayer_cb(void *base, const char *str) { RenderResult *rr = base; RenderLayer *rl; - + rl = MEM_callocN(sizeof(RenderLayer), "new render layer"); BLI_addtail(&rr->layers, rl); @@ -706,7 +706,7 @@ RenderResult *render_result_new_from_exr(void *exrhandle, const char *colorspace rr->rectx = rectx; rr->recty = recty; - + IMB_exr_multilayer_convert(exrhandle, rr, ml_addview_cb, ml_addlayer_cb, ml_addpass_cb); for (rl = rr->layers.first; rl; rl = rl->next) { @@ -725,7 +725,7 @@ RenderResult *render_result_new_from_exr(void *exrhandle, const char *colorspace } } } - + return rr; } @@ -770,16 +770,16 @@ static void do_merge_tile(RenderResult *rr, RenderResult *rrpart, float *target, { int y, tilex, tiley; size_t ofs, copylen; - + copylen = tilex = rrpart->rectx; tiley = rrpart->recty; - + if (rrpart->crop) { /* filters add pixel extra */ tile += pixsize * (rrpart->crop + ((size_t)rrpart->crop) * tilex); - + copylen = tilex - 2 * rrpart->crop; tiley -= 2 * rrpart->crop; - + ofs = (((size_t)rrpart->tilerect.ymin) + rrpart->crop) * rr->rectx + (rrpart->tilerect.xmin + rrpart->crop); target += pixsize * ofs; } @@ -806,7 +806,7 @@ void render_result_merge(RenderResult *rr, RenderResult *rrpart) { RenderLayer *rl, *rlp; RenderPass *rpass, *rpassp; - + for (rl = rr->layers.first; rl; rl = rl->next) { rlp = RE_GetRenderLayer(rrpart, rl->name); if (rlp) { @@ -986,7 +986,7 @@ void render_result_single_layer_begin(Render *re) /* officially pushed result should be NULL... error can happen with do_seq */ RE_FreeRenderResult(re->pushedresult); - + re->pushedresult = re->result; re->result = NULL; } @@ -1010,10 +1010,10 @@ void render_result_single_layer_end(Render *re) if (re->pushedresult->rectx == re->result->rectx && re->pushedresult->recty == re->result->recty) { /* find which layer in re->pushedresult should be replaced */ rl = re->result->layers.first; - + /* render result should be empty after this */ BLI_remlink(&re->result->layers, rl); - + /* reconstruct render result layers */ for (nr = 0, srl = re->r.layers.first; srl; srl = srl->next, nr++) { if (nr == re->r.actlay) { @@ -1040,9 +1040,9 @@ static void save_render_result_tile(RenderResult *rr, RenderResult *rrpart, cons RenderLayer *rlp, *rl; RenderPass *rpassp; int offs, partx, party; - + BLI_thread_lock(LOCK_IMAGE); - + for (rlp = rrpart->layers.first; rlp; rlp = rlp->next) { rl = RE_GetRenderLayer(rr, rlp->name); @@ -1072,7 +1072,7 @@ static void save_render_result_tile(RenderResult *rr, RenderResult *rrpart, cons xstride, xstride * rrpart->rectx, rpassp->rect + a + xstride * offs); } } - + } party = rrpart->tilerect.ymin + rrpart->crop; @@ -1098,7 +1098,7 @@ void render_result_save_empty_result_tiles(Render *re) RenderPart *pa; RenderResult *rr; RenderLayer *rl; - + for (rr = re->result; rr; rr = rr->next) { for (rl = rr->layers.first; rl; rl = rl->next) { for (pa = re->parts.first; pa; pa = pa->next) { @@ -1142,7 +1142,7 @@ void render_result_exr_file_end(Render *re) rr->do_exr_tile = false; } - + render_result_free_list(&re->fullresult, re->result); re->result = NULL; @@ -1161,7 +1161,7 @@ void render_result_exr_file_path(Scene *scene, const char *layname, int sample, { char name[FILE_MAXFILE + MAX_ID_NAME + MAX_ID_NAME + 100]; const char *fi = BLI_path_basename(BKE_main_blendfile_path_from_global()); - + if (sample == 0) { BLI_snprintf(name, sizeof(name), "%s_%s_%s.exr", fi, scene->id.name + 2, layname); } @@ -1224,7 +1224,7 @@ int render_result_exr_file_read_path(RenderResult *rr, RenderLayer *rl_single, c for (rl = rr->layers.first; rl; rl = rl->next) { if (rl_single && rl_single != rl) continue; - + /* passes are allocated in sync */ for (rpass = rl->passes.first; rpass; rpass = rpass->next) { const int xstride = rpass->channels; @@ -1322,7 +1322,7 @@ ImBuf *render_result_rect_to_ibuf(RenderResult *rr, RenderData *rd, const int vi /* float factor for random dither, imbuf takes care of it */ ibuf->dither = rd->dither_intensity; - + /* prepare to gamma correct to sRGB color space * note that sequence editor can generate 8bpc render buffers */ @@ -1363,7 +1363,7 @@ void RE_render_result_rect_from_ibuf(RenderResult *rr, RenderData *UNUSED(rd), I if (!rv->rectf) rv->rectf = MEM_mallocN(4 * sizeof(float) * rr->rectx * rr->recty, "render_seq rectf"); - + memcpy(rv->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 diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index e66dd86a75a..8450098d733 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -103,16 +103,16 @@ static void init_render_texture(Render *re, Tex *tex) if (tex->ima && BKE_image_is_animated(tex->ima)) { 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) { /* just in case */ tex->imaflag |= TEX_INTERPOL | TEX_MIPMAP; tex->extend= TEX_CLIP; - + if (tex->env) { if (tex->env->type==ENV_PLANE) tex->extend= TEX_EXTEND; - + /* only free envmap when rendermode was set to render envmaps, for previewrender */ if (G.is_rendering && re) { if (re->r.mode & R_ENVMAP) @@ -121,7 +121,7 @@ static void init_render_texture(Render *re, Tex *tex) } } } - + if (tex->nodetree && tex->use_nodes) { ntreeTexBeginExecTree(tex->nodetree); /* has internal flag to detect it only does it once */ } @@ -132,7 +132,7 @@ static void init_render_texture(Render *re, Tex *tex) void init_render_textures(Render *re) { Tex *tex; - + tex= re->main->tex.first; while (tex) { if (tex->id.us) init_render_texture(re, tex); @@ -164,7 +164,7 @@ static void tex_normal_derivate(Tex *tex, TexResult *texres) float col[4]; if (BKE_colorband_evaluate(tex->coba, texres->tin, col)) { float fac0, fac1, fac2, fac3; - + fac0= (col[0]+col[1]+col[2]); BKE_colorband_evaluate(tex->coba, texres->nor[0], col); fac1= (col[0]+col[1]+col[2]); @@ -172,11 +172,11 @@ static void tex_normal_derivate(Tex *tex, TexResult *texres) fac2= (col[0]+col[1]+col[2]); BKE_colorband_evaluate(tex->coba, texres->nor[2], col); fac3= (col[0]+col[1]+col[2]); - + texres->nor[0]= (fac0 - fac1) / 3.0f; texres->nor[1]= (fac0 - fac2) / 3.0f; texres->nor[2]= (fac0 - fac3) / 3.0f; - + return; } } @@ -242,7 +242,7 @@ static int blend(Tex *tex, const float texvec[3], TexResult *texres) static int clouds(Tex *tex, const float texvec[3], TexResult *texres) { int rv = TEX_INT; - + texres->tin = BLI_gTurbulence(tex->noisesize, texvec[0], texvec[1], texvec[2], tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); if (texres->nor!=NULL) { @@ -250,7 +250,7 @@ static int clouds(Tex *tex, const float texvec[3], TexResult *texres) texres->nor[0] = BLI_gTurbulence(tex->noisesize, texvec[0] + tex->nabla, texvec[1], texvec[2], tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); texres->nor[1] = BLI_gTurbulence(tex->noisesize, texvec[0], texvec[1] + tex->nabla, texvec[2], tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); texres->nor[2] = BLI_gTurbulence(tex->noisesize, texvec[0], texvec[1], texvec[2] + tex->nabla, tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); - + tex_normal_derivate(tex, texres); rv |= TEX_NOR; } @@ -284,7 +284,7 @@ static float tex_sin(float a) static float tex_saw(float a) { const float b = 2*M_PI; - + int n = (int)(a / b); a -= n*b; if (a < 0) a += b; @@ -296,9 +296,9 @@ static float tex_tri(float a) { const float b = 2*M_PI; const float rmax = 1.0; - + a = rmax - 2.0f*fabsf(floorf((a*(1.0f/b))+0.5f) - (a*(1.0f/b))); - + return a; } @@ -313,9 +313,9 @@ static float wood_int(Tex *tex, float x, float y, float z) waveform[0] = tex_sin; /* assign address of tex_sin() function to pointer array */ waveform[1] = tex_saw; waveform[2] = tex_tri; - + if ((wf>TEX_TRI) || (wfturbul*BLI_gNoise(tex->noisesize, x, y, z, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); wi = waveform[wf](sqrtf(x*x + y*y + z*z)*20.0f + wi); } - + return wi; } @@ -344,7 +344,7 @@ static int wood(Tex *tex, const float texvec[3], TexResult *texres) texres->nor[0] = wood_int(tex, texvec[0] + tex->nabla, texvec[1], texvec[2]); texres->nor[1] = wood_int(tex, texvec[0], texvec[1] + tex->nabla, texvec[2]); texres->nor[2] = wood_int(tex, texvec[0], texvec[1], texvec[2] + tex->nabla); - + tex_normal_derivate(tex, texres); rv |= TEX_NOR; } @@ -360,16 +360,16 @@ static float marble_int(Tex *tex, float x, float y, float z) float n, mi; short wf = tex->noisebasis2; /* wave form: TEX_SIN=0, TEX_SAW=1, TEX_TRI=2 */ short mt = tex->stype; /* marble type: TEX_SOFT=0, TEX_SHARP=1,TEX_SHAPER=2 */ - + float (*waveform[3])(float); /* create array of pointers to waveform functions */ waveform[0] = tex_sin; /* assign address of tex_sin() function to pointer array */ waveform[1] = tex_saw; waveform[2] = tex_tri; - + if ((wf>TEX_TRI) || (wfturbul * BLI_gTurbulence(tex->noisesize, x, y, z, tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); if (mt>=TEX_SOFT) { /* TEX_SOFT always true */ @@ -396,9 +396,9 @@ static int marble(Tex *tex, const float texvec[3], TexResult *texres) texres->nor[0] = marble_int(tex, texvec[0] + tex->nabla, texvec[1], texvec[2]); texres->nor[1] = marble_int(tex, texvec[0], texvec[1] + tex->nabla, texvec[2]); texres->nor[2] = marble_int(tex, texvec[0], texvec[1], texvec[2] + tex->nabla); - + tex_normal_derivate(tex, texres); - + rv |= TEX_NOR; } @@ -466,8 +466,8 @@ static int magic(Tex *tex, const float texvec[3], TexResult *texres) if (turb!=0.0f) { turb*= 2.0f; - x/= turb; - y/= turb; + x/= turb; + y/= turb; z/= turb; } texres->tr = 0.5f - x; @@ -475,10 +475,10 @@ static int magic(Tex *tex, const float texvec[3], TexResult *texres) texres->tb = 0.5f - z; texres->tin= (1.0f / 3.0f) * (texres->tr + texres->tg + texres->tb); - + BRICONTRGB; texres->ta = 1.0f; - + return TEX_RGB; } @@ -489,9 +489,9 @@ static int stucci(Tex *tex, const float texvec[3], TexResult *texres) { float nor[3], b2, ofs; int retval= TEX_INT; - + b2= BLI_gNoise(tex->noisesize, texvec[0], texvec[1], texvec[2], (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); - + ofs= tex->turbul/200.0f; if (tex->stype) ofs*=(b2*b2); @@ -500,27 +500,27 @@ static int stucci(Tex *tex, const float texvec[3], TexResult *texres) nor[2] = BLI_gNoise(tex->noisesize, texvec[0], texvec[1], texvec[2]+ofs, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis); texres->tin= nor[2]; - + if (texres->nor) { - + copy_v3_v3(texres->nor, nor); tex_normal_derivate(tex, texres); - + if (tex->stype==TEX_WALLOUT) { texres->nor[0]= -texres->nor[0]; texres->nor[1]= -texres->nor[1]; texres->nor[2]= -texres->nor[2]; } - + retval |= TEX_NOR; } - + if (tex->stype==TEX_WALLOUT) texres->tin= 1.0f-texres->tin; - + if (texres->tin<0.0f) texres->tin= 0.0f; - + return retval; } @@ -546,7 +546,7 @@ static float mg_mFractalOrfBmTex(Tex *tex, const float texvec[3], TexResult *tex texres->nor[0] = tex->ns_outscale*mgravefunc(texvec[0] + offs, texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->noisebasis); texres->nor[1] = tex->ns_outscale*mgravefunc(texvec[0], texvec[1] + offs, texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->noisebasis); texres->nor[2] = tex->ns_outscale*mgravefunc(texvec[0], texvec[1], texvec[2] + offs, tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->noisebasis); - + tex_normal_derivate(tex, texres); rv |= TEX_NOR; } @@ -576,7 +576,7 @@ static float mg_ridgedOrHybridMFTex(Tex *tex, const float texvec[3], TexResult * texres->nor[0] = tex->ns_outscale*mgravefunc(texvec[0] + offs, texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->mg_gain, tex->noisebasis); texres->nor[1] = tex->ns_outscale*mgravefunc(texvec[0], texvec[1] + offs, texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->mg_gain, tex->noisebasis); texres->nor[2] = tex->ns_outscale*mgravefunc(texvec[0], texvec[1], texvec[2] + offs, tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->mg_gain, tex->noisebasis); - + tex_normal_derivate(tex, texres); rv |= TEX_NOR; } @@ -601,7 +601,7 @@ static float mg_HTerrainTex(Tex *tex, const float texvec[3], TexResult *texres) texres->nor[0] = tex->ns_outscale*mg_HeteroTerrain(texvec[0] + offs, texvec[1], texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->noisebasis); texres->nor[1] = tex->ns_outscale*mg_HeteroTerrain(texvec[0], texvec[1] + offs, texvec[2], tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->noisebasis); texres->nor[2] = tex->ns_outscale*mg_HeteroTerrain(texvec[0], texvec[1], texvec[2] + offs, tex->mg_H, tex->mg_lacunarity, tex->mg_octaves, tex->mg_offset, tex->noisebasis); - + tex_normal_derivate(tex, texres); rv |= TEX_NOR; } @@ -699,7 +699,7 @@ static float voronoiTex(Tex *tex, const float texvec[3], TexResult *texres) texres->nor[1] = sc * fabsf(tex->vn_w1*da[0] + tex->vn_w2*da[1] + tex->vn_w3*da[2] + tex->vn_w4*da[3]); voronoi(texvec[0], texvec[1], texvec[2] + offs, da, pa, tex->vn_mexp, tex->vn_distm); texres->nor[2] = sc * fabsf(tex->vn_w1*da[0] + tex->vn_w2*da[1] + tex->vn_w3*da[2] + tex->vn_w4*da[3]); - + tex_normal_derivate(tex, texres); rv |= TEX_NOR; } @@ -709,7 +709,7 @@ static float voronoiTex(Tex *tex, const float texvec[3], TexResult *texres) texres->ta = 1.0; return (rv | TEX_RGB); } - + BRICONT; return rv; @@ -722,20 +722,20 @@ static int texnoise(Tex *tex, TexResult *texres, int thread) { float div=3.0; int val, ran, loop, shift = 29; - + ran= BLI_rng_thread_rand(random_tex_array, thread); - + loop= tex->noisedepth; /* start from top bits since they have more variance */ val= ((ran >> shift) & 3); - + while (loop--) { - shift -= 2; + shift -= 2; val *= ((ran >> shift) & 3); div *= 3.0f; } - + texres->tin= ((float)val)/div; BRICONT; @@ -748,7 +748,7 @@ static int cubemap_glob(const float n[3], float x, float y, float z, float *adr1 { float x1, y1, z1, nor[3]; int ret; - + if (n==NULL) { nor[0]= x; nor[1]= y; nor[2]= z; /* use local render coord */ } @@ -760,7 +760,7 @@ static int cubemap_glob(const float n[3], float x, float y, float z, float *adr1 x1 = fabsf(nor[0]); y1 = fabsf(nor[1]); z1 = fabsf(nor[2]); - + if (z1>=x1 && z1>=y1) { *adr1 = (x + 1.0f) / 2.0f; *adr2 = (y + 1.0f) / 2.0f; @@ -786,24 +786,24 @@ static int cubemap( const MTex *mtex, VlakRen *vlr, const float n[3], float x, float y, float z, float *adr1, float *adr2) { int proj[4]={0, ME_PROJXY, ME_PROJXZ, ME_PROJYZ}, ret= 0; - + if (vlr) { int index; - + /* Mesh vertices have such flags, for others we calculate it once based on orco */ if ((vlr->puno & (ME_PROJXY|ME_PROJXZ|ME_PROJYZ))==0) { /* test for v1, vlr can be faked for baking */ if (vlr->v1 && vlr->v1->orco) { float nor[3]; normal_tri_v3(nor, vlr->v1->orco, vlr->v2->orco, vlr->v3->orco); - + if (fabsf(nor[0]) < fabsf(nor[2]) && fabsf(nor[1]) < fabsf(nor[2])) vlr->puno |= ME_PROJXY; else if (fabsf(nor[0]) < fabsf(nor[1]) && fabsf(nor[2]) < fabsf(nor[1])) vlr->puno |= ME_PROJXZ; else vlr->puno |= ME_PROJYZ; } else return cubemap_glob(n, x, y, z, adr1, adr2); } - + if (mtex) { /* the mtex->proj{xyz} have type char. maybe this should be wider? */ /* casting to int ensures that the index type is right. */ @@ -816,7 +816,7 @@ static int cubemap( index = (int) mtex->projz; proj[index]= ME_PROJYZ; } - + if (vlr->puno & proj[1]) { *adr1 = (x + 1.0f) / 2.0f; *adr2 = (y + 1.0f) / 2.0f; @@ -835,7 +835,7 @@ static int cubemap( else { return cubemap_glob(n, x, y, z, adr1, adr2); } - + return ret; } @@ -845,16 +845,16 @@ static int cubemap_ob(Object *ob, const float n[3], float x, float y, float z, f { float x1, y1, z1, nor[3]; int ret; - + if (n==NULL) return 0; - + copy_v3_v3(nor, n); if (ob) mul_mat3_m4_v3(ob->imat, nor); - + x1 = fabsf(nor[0]); y1 = fabsf(nor[1]); z1 = fabsf(nor[2]); - + if (z1>=x1 && z1>=y1) { *adr1 = (x + 1.0f) / 2.0f; *adr2 = (y + 1.0f) / 2.0f; @@ -882,7 +882,7 @@ static void do_2d_mapping( Object *ob= NULL; float fx, fy, fac1, area[8]; int ok, proj, areaflag= 0, wrap, texco; - + /* mtex variables localized, only cubemap doesn't cooperate yet... */ wrap= mtex->mapping; tex= mtex->tex; @@ -890,7 +890,7 @@ static void do_2d_mapping( texco= mtex->texco; if (R.osa==0) { - + if (wrap==MTEX_FLAT) { fx = (texvec[0] + 1.0f) / 2.0f; fy = (texvec[1] + 1.0f) / 2.0f; @@ -902,15 +902,15 @@ static void do_2d_mapping( else if (texco == TEXCO_GLOB) cubemap_glob(n, texvec[0], texvec[1], texvec[2], &fx, &fy); else cubemap(mtex, vlr, n, texvec[0], texvec[1], texvec[2], &fx, &fy); } - + /* repeat */ if (tex->extend==TEX_REPEAT) { if (tex->xrepeat>1) { float origf= fx *= tex->xrepeat; - + if (fx>1.0f) fx -= (int)(fx); else if (fx<0.0f) fx+= 1-(int)(fx); - + if (tex->flag & TEX_REPEAT_XMIR) { int orig= (int)floor(origf); if (orig & 1) @@ -919,10 +919,10 @@ static void do_2d_mapping( } if (tex->yrepeat>1) { float origf= fy *= tex->yrepeat; - + if (fy>1.0f) fy -= (int)(fy); else if (fy<0.0f) fy+= 1-(int)(fy); - + if (tex->flag & TEX_REPEAT_YMIR) { int orig= (int)floor(origf); if (orig & 1) @@ -944,7 +944,7 @@ static void do_2d_mapping( texvec[1]= fy; } else { - + if (wrap==MTEX_FLAT) { fx= (texvec[0] + 1.0f) / 2.0f; fy= (texvec[1] + 1.0f) / 2.0f; @@ -1023,55 +1023,55 @@ static void do_2d_mapping( dyt[2] *= 0.5f; } - + /* if area, then reacalculate dxt[] and dyt[] */ if (areaflag) { - fx= area[0]; + fx= area[0]; fy= area[1]; dxt[0]= area[2]-fx; dxt[1]= area[3]-fy; dyt[0]= area[4]-fx; dyt[1]= area[5]-fy; } - + /* repeat */ if (tex->extend==TEX_REPEAT) { float max= 1.0f; if (tex->xrepeat>1) { float origf= fx *= tex->xrepeat; - + /* TXF: omit mirror here, see comments in do_material_tex() after do_2d_mapping() call */ if (tex->texfilter == TXF_BOX) { if (fx>1.0f) fx -= (int)(fx); else if (fx<0.0f) fx+= 1-(int)(fx); - + if (tex->flag & TEX_REPEAT_XMIR) { int orig= (int)floor(origf); if (orig & 1) fx= 1.0f-fx; } } - + max= tex->xrepeat; - + dxt[0]*= tex->xrepeat; dyt[0]*= tex->xrepeat; } if (tex->yrepeat>1) { float origf= fy *= tex->yrepeat; - + /* TXF: omit mirror here, see comments in do_material_tex() after do_2d_mapping() call */ if (tex->texfilter == TXF_BOX) { if (fy>1.0f) fy -= (int)(fy); else if (fy<0.0f) fy+= 1-(int)(fy); - + if (tex->flag & TEX_REPEAT_YMIR) { int orig= (int)floor(origf); if (orig & 1) fy= 1.0f-fy; } } - + if (maxyrepeat) max= tex->yrepeat; @@ -1082,7 +1082,7 @@ static void do_2d_mapping( dxt[2]*= max; dyt[2]*= max; } - + } /* crop */ if (tex->cropxmin!=0.0f || tex->cropxmax!=1.0f) { @@ -1097,7 +1097,7 @@ static void do_2d_mapping( dxt[1]*= fac1; dyt[1]*= fac1; } - + texvec[0]= fx; texvec[1]= fy; @@ -1122,7 +1122,7 @@ static int multitex(Tex *tex, int retval = 0; /* return value, int:0, col:1, nor:2, everything:3 */ texres->talpha = false; /* is set when image texture returns alpha (considered premul) */ - + if (use_nodes && tex->use_nodes && tex->nodetree) { retval = ntreeTexExecTree(tex->nodetree, texres, texvec, dxt, dyt, osatex, thread, tex, which_output, R.r.cfra, texnode_preview, NULL, NULL); @@ -1253,7 +1253,7 @@ static int multitex_nodes_intern(Tex *tex, if (mtex) which_output= mtex->which_output; - + if (tex->type==TEX_IMAGE) { int rgbnor; @@ -1274,7 +1274,7 @@ static int multitex_nodes_intern(Tex *tex, if (mtex->mapto & (MAP_COL+MAP_COLSPEC+MAP_COLMIR)) { ImBuf *ibuf = BKE_image_pool_acquire_ibuf(tex->ima, &tex->iuser, pool); - + /* don't linearize float buffers, assumed to be linear */ if (ibuf != NULL && ibuf->rect_float == NULL && @@ -1291,12 +1291,12 @@ static int multitex_nodes_intern(Tex *tex, /* we don't have mtex, do default flat 2d projection */ MTex localmtex; float texvec_l[3], dxt_l[3], dyt_l[3]; - + localmtex.mapping= MTEX_FLAT; localmtex.tex= tex; localmtex.object= NULL; localmtex.texco= TEXCO_ORCO; - + copy_v3_v3(texvec_l, texvec); if (dxt && dyt) { copy_v3_v3(dxt_l, dxt); @@ -1306,7 +1306,7 @@ static int multitex_nodes_intern(Tex *tex, zero_v3(dxt_l); zero_v3(dyt_l); } - + do_2d_mapping(&localmtex, texvec_l, NULL, NULL, dxt_l, dyt_l); rgbnor = multitex(tex, texvec_l, @@ -1451,7 +1451,7 @@ int multitex_ext_safe(Tex *tex, float texvec[3], TexResult *texres, struct Image void texture_rgb_blend(float in[3], const float tex[3], const float out[3], float fact, float facg, int blendtype) { float facm; - + switch (blendtype) { case MTEX_BLEND: fact*= facg; @@ -1461,7 +1461,7 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa in[1]= (fact*tex[1] + facm*out[1]); in[2]= (fact*tex[2] + facm*out[2]); break; - + case MTEX_MUL: fact*= facg; facm= 1.0f-fact; @@ -1481,7 +1481,7 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa case MTEX_OVERLAY: fact*= facg; facm= 1.0f-fact; - + if (out[0] < 0.5f) in[0] = out[0] * (facm + 2.0f*fact*tex[0]); else @@ -1495,7 +1495,7 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa else in[2] = 1.0f - (facm + 2.0f*fact*(1.0f - tex[2])) * (1.0f - out[2]); break; - + case MTEX_SUB: fact= -fact; ATTR_FALLTHROUGH; @@ -1509,7 +1509,7 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa case MTEX_DIV: fact*= facg; facm= 1.0f-fact; - + if (tex[0]!=0.0f) in[0]= facm*out[0] + fact*out[0]/tex[0]; if (tex[1]!=0.0f) @@ -1530,7 +1530,7 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa case MTEX_DARK: fact*= facg; facm= 1.0f-fact; - + in[0] = min_ff(out[0], tex[0])*fact + out[0]*facm; in[1] = min_ff(out[1], tex[1])*fact + out[1]*facm; in[2] = min_ff(out[2], tex[2])*fact + out[2]*facm; @@ -1543,7 +1543,7 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa in[1] = max_ff(fact * tex[1], out[1]); in[2] = max_ff(fact * tex[2], out[2]); break; - + case MTEX_BLEND_HUE: fact*= facg; copy_v3_v3(in, out); @@ -1564,16 +1564,16 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa copy_v3_v3(in, out); ramp_blend(MA_RAMP_COLOR, in, fact, tex); break; - case MTEX_SOFT_LIGHT: - fact*= facg; + case MTEX_SOFT_LIGHT: + fact*= facg; copy_v3_v3(in, out); ramp_blend(MA_RAMP_SOFT, in, fact, tex); - break; - case MTEX_LIN_LIGHT: - fact*= facg; + break; + case MTEX_LIN_LIGHT: + fact*= facg; copy_v3_v3(in, out); ramp_blend(MA_RAMP_LINEAR, in, fact, tex); - break; + break; } } @@ -1583,7 +1583,7 @@ float texture_value_blend(float tex, float out, float fact, float facg, int blen int flip= (facg < 0.0f); facg= fabsf(facg); - + fact*= facg; facm= 1.0f-fact; if (flip) SWAP(float, fact, facm); @@ -1636,19 +1636,19 @@ float texture_value_blend(float tex, float out, float fact, float facg, int blen if (col > out) in= col; else in= out; break; - case MTEX_SOFT_LIGHT: + case MTEX_SOFT_LIGHT: scf=1.0f - (1.0f - tex) * (1.0f - out); in= facm*out + fact * ((1.0f - out) * tex * out) + (out * scf); - break; + break; - case MTEX_LIN_LIGHT: + case MTEX_LIN_LIGHT: if (tex > 0.5f) in = out + fact*(2.0f*(tex - 0.5f)); - else + else in = out + fact*(2.0f*tex - 1.0f); break; } - + return in; } @@ -1690,7 +1690,7 @@ static void texco_mapping(ShadeInput *shi, Tex *tex, MTex *mtex, dyt[0] = mtex->size[0] * dyt[0]; dyt[1] = mtex->size[1] * dyt[1]; } - + /* problem: repeat-mirror is not a 'repeat' but 'extend' in imagetexture.c */ /* TXF: bug was here, only modify texvec when repeat mode set, old code affected other modes too. * New texfilters solve mirroring differently so that it also works correctly when @@ -1714,7 +1714,7 @@ static void texco_mapping(ShadeInput *shi, Tex *tex, MTex *mtex, if (texvec[1] > 1.f) texvec[1] = 2.f - texvec[1]; } } - + } else { /* procedural */ /* placement */ @@ -2036,7 +2036,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T copy_v3_v3(ntap_bump->vNorg, shi->vn); ntap_bump->fPrevMagnitude = 1.0f; ntap_bump->iPrevBumpSpace = 0; - + ntap_bump->init_done = true; } @@ -2050,7 +2050,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T } BKE_image_pool_release_ibuf(tex->ima, ibuf, pool); } - + if (found_deriv_map) { float dBdu, dBdv, auto_bump = 1.0f; float s = 1; /* negate this if flipped texture coordinate */ @@ -2178,7 +2178,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T copy_v3_v3(dPdx, shi->dxco); copy_v3_v3(dPdy, shi->dyco); copy_v3_v3(vN, ntap_bump->vNorg); - + if ( mtex->texflag & MTEX_BUMP_OBJECTSPACE ) { /* TODO: these calculations happen for every pixel! * -> move to shi->obi */ @@ -2193,7 +2193,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T mul_transposed_m3_v3(obj2view, vN); normalize_v3(vN); } - + cross_v3_v3v3(ntap_bump->vR1, dPdy, vN); cross_v3_v3v3(ntap_bump->vR2, vN, dPdx); fDet = dot_v3v3(dPdx, ntap_bump->vR1); @@ -2208,21 +2208,21 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T abs_fDet = 1.0f; } } - + fMagnitude = abs_fDet; if ( mtex->texflag & MTEX_BUMP_OBJECTSPACE ) { /* pre do transform of texres->nor by the inverse transposed of obj2view */ mul_transposed_m3_v3(view2obj, vN); mul_transposed_m3_v3(view2obj, ntap_bump->vR1); mul_transposed_m3_v3(view2obj, ntap_bump->vR2); - + fMagnitude *= len_v3(vN); } - + if (ntap_bump->fPrevMagnitude > 0.0f) for (xyz=0; xyz<3; xyz++) ntap_bump->vNacc[xyz] *= fMagnitude / ntap_bump->fPrevMagnitude; - + ntap_bump->fPrevMagnitude = fMagnitude; ntap_bump->iPrevBumpSpace = iBumpSpace; } @@ -2232,7 +2232,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T /* crazy hack solution that gives results similar to normal mapping - part 2 */ float vec[2]; const float imag_tspace_dimension_y = aspect*imag_tspace_dimension_x; - + vec[0] = imag_tspace_dimension_x*dxt[0]; vec[1] = imag_tspace_dimension_y*dxt[1]; dHdx *= 1.0f/len_v2(vec); @@ -2241,7 +2241,7 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T dHdy *= 1.0f/len_v2(vec); } } - + /* subtract the surface gradient from vNacc */ for (c=0; c<3; c++) { float vSurfGrad_compi = ntap_bump->sgn_det * (dHdx * ntap_bump->vR1[c] + dHdy * ntap_bump->vR2[c]); @@ -2276,13 +2276,13 @@ void do_material_tex(ShadeInput *shi, Render *re) /* here: test flag if there's a tex (todo) */ for (tex_nr=0; tex_nrmat->septex & (1<mat->mtex[tex_nr]) { mtex= shi->mat->mtex[tex_nr]; - + tex= mtex->tex; if (tex == NULL) continue; @@ -2295,13 +2295,13 @@ void do_material_tex(ShadeInput *shi, Render *re) use_compat_bump = false; use_ntap_bump = false; } - + /* case displacement mapping */ if (shi->osatex == 0 && use_ntap_bump) { use_ntap_bump = false; use_compat_bump = true; } - + /* case ocean */ if (tex->type == TEX_OCEAN) { use_ntap_bump = false; @@ -2377,7 +2377,7 @@ void do_material_tex(ShadeInput *shi, Render *re) co= suv->uv; dx= suv->dxuv; - dy= suv->dyuv; + dy= suv->dyuv; compatible_bump_uv_derivs(&compat_bump, shi, mtex, i); } @@ -2413,7 +2413,7 @@ void do_material_tex(ShadeInput *shi, Render *re) norvec[0]= norvec[1]= norvec[2]= 0.0; } else texres.nor= NULL; - + if (warp_done) { add_v3_v3v3(tempvec, co, warpvec); co= tempvec; @@ -2470,7 +2470,7 @@ void do_material_tex(ShadeInput *shi, Render *re) else { Tnor*= stencilTin; } - + if (texres.nor) { if ((rgbnor & TEX_NOR)==0) { /* make our own normal */ @@ -2494,7 +2494,7 @@ void do_material_tex(ShadeInput *shi, Render *re) /* warping, local space */ if (mtex->mapto & MAP_WARP) { float *warpnor= texres.nor, warpnor_[3]; - + if (use_ntap_bump) { copy_v3_v3(warpnor_, texres.nor); warpnor= warpnor_; @@ -2505,7 +2505,7 @@ void do_material_tex(ShadeInput *shi, Render *re) warpvec[2]= mtex->warpfac*warpnor[2]; warp_done = true; } -#if 0 +#if 0 if (mtex->texflag & MTEX_VIEWSPACE) { /* rotate to global coords */ if (mtex->texco==TEXCO_ORCO || mtex->texco==TEXCO_UV) { @@ -2524,7 +2524,7 @@ void do_material_tex(ShadeInput *shi, Render *re) /* mapping */ if (mtex->mapto & (MAP_COL | MAP_COLSPEC | MAP_COLMIR)) { float tcol[3]; - + /* stencil maps on the texture control slider, not texture intensity value */ copy_v3_v3(tcol, &texres.tr); @@ -2537,12 +2537,12 @@ void do_material_tex(ShadeInput *shi, Render *re) else { texres.tin = texres.ta; } - + /* inverse gamma correction */ if (tex->type==TEX_IMAGE) { Image *ima = tex->ima; ImBuf *ibuf = BKE_image_pool_acquire_ibuf(ima, &tex->iuser, re->pool); - + /* don't linearize float buffers, assumed to be linear */ if (ibuf != NULL && ibuf->rect_float == NULL && @@ -2583,13 +2583,13 @@ void do_material_tex(ShadeInput *shi, Render *re) if ( (mtex->mapto & MAP_NORM) ) { if (texres.nor) { float norfac= mtex->norfac; - + /* we need to code blending modes for normals too once.. now 1 exception hardcoded */ - + if ((tex->type==TEX_IMAGE) && (tex->imaflag & TEX_NORMALMAP)) { - + found_nmapping = 1; - + /* qdn: for normalmaps, to invert the normalmap vector, * it is better to negate x & y instead of subtracting the vector as was done before */ if (norfac < 0.0f) { @@ -2648,27 +2648,27 @@ void do_material_tex(ShadeInput *shi, Render *re) } else { float nor[3], dot; - + if (shi->mat->mode & MA_TANGENT_V) { shi->tang[0]+= Tnor*norfac*texres.nor[0]; shi->tang[1]+= Tnor*norfac*texres.nor[1]; shi->tang[2]+= Tnor*norfac*texres.nor[2]; } - + /* prevent bump to become negative normal */ nor[0]= Tnor*norfac*texres.nor[0]; nor[1]= Tnor*norfac*texres.nor[1]; nor[2]= Tnor*norfac*texres.nor[2]; - + dot= 0.5f + 0.5f * dot_v3v3(nor, shi->vn); - + shi->vn[0]+= dot*nor[0]; shi->vn[1]+= dot*nor[1]; shi->vn[2]+= dot*nor[2]; } } normalize_v3(shi->vn); - + /* this makes sure the bump is passed on to the next texture */ shi->orn[0]= -shi->vn[0]; shi->orn[1]= -shi->vn[1]; @@ -2686,7 +2686,7 @@ void do_material_tex(ShadeInput *shi, Render *re) shi->displace[1]+= 0.2f*Tnor*norfac*texres.nor[1]; shi->displace[2]+= 0.2f*Tnor*norfac*texres.nor[2]; } - + if (rgbnor & TEX_RGB) { texres.tin = IMB_colormanagement_get_luminance(&texres.tr); } @@ -2713,7 +2713,7 @@ void do_material_tex(ShadeInput *shi, Render *re) if (mtex->mapto & MAP_VARS) { /* stencil maps on the texture control slider, not texture intensity value */ - + if (rgbnor & TEX_RGB) { if (texres.talpha) texres.tin = texres.ta; else texres.tin = IMB_colormanagement_get_luminance(&texres.tr); @@ -2727,7 +2727,7 @@ void do_material_tex(ShadeInput *shi, Render *re) } if (mtex->mapto & MAP_SPEC) { float specfac= mtex->specfac*stencilTin; - + shi->spec= texture_value_blend(mtex->def_var, shi->spec, texres.tin, specfac, mtex->blendtype); if (shi->spec<0.0f) shi->spec= 0.0f; } @@ -2747,10 +2747,10 @@ void do_material_tex(ShadeInput *shi, Render *re) if (mtex->mapto & MAP_HAR) { float har; /* have to map to 0-1 */ float hardfac= mtex->hardfac*stencilTin; - + har= ((float)shi->har)/128.0f; har= 128.0f*texture_value_blend(mtex->def_var, har, texres.tin, hardfac, mtex->blendtype); - + if (har<1.0f) shi->har= 1; else if (har>511) shi->har= 511; else shi->har= (int)har; @@ -2775,7 +2775,7 @@ void do_material_tex(ShadeInput *shi, Render *re) shi->amb= texture_value_blend(mtex->def_var, shi->amb, texres.tin, ambfac, mtex->blendtype); if (shi->amb<0.0f) shi->amb= 0.0f; else if (shi->amb>1.0f) shi->amb= 1.0f; - + shi->ambr= shi->amb*re->wrld.ambr; shi->ambg= shi->amb*re->wrld.ambg; shi->ambb= shi->amb*re->wrld.ambb; @@ -2802,23 +2802,23 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float col_ int tex_nr, rgbnor= 0; float co[3], texvec[3]; float fact, stencilTin=1.0; - + if (re->r.scemode & R_NO_TEX) return; /* here: test flag if there's a tex (todo) */ - + for (tex_nr=0; tex_nrmat->septex & (1<mat->mtex[tex_nr]) { mtex= shi->mat->mtex[tex_nr]; tex= mtex->tex; if (tex == NULL) continue; - - /* only process if this texture is mapped + + /* only process if this texture is mapped * to one that we're interested in */ if (!(mtex->mapto & mapto_flag)) continue; - + /* which coords */ if (mtex->texco==TEXCO_OBJECT) { Object *ob= mtex->object; @@ -2840,7 +2840,7 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float col_ } /* not really orco, but 'local' */ else if (mtex->texco==TEXCO_ORCO) { - + if (mtex->texflag & MTEX_DUPLI_MAPTO) { copy_v3_v3(co, shi->duplilo); } @@ -2866,7 +2866,7 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float col_ } texres.nor= NULL; - + if (tex->type == TEX_IMAGE) { continue; /* not supported yet */ //do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt); @@ -2882,7 +2882,7 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float col_ if (mtex->projz) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]); else texvec[2]= mtex->size[2]*(mtex->ofs[2]); } - + rgbnor = multitex(tex, texvec, NULL, NULL, @@ -2894,7 +2894,7 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float col_ skip_load_image, texnode_preview, true); /* NULL = dxt/dyt, 0 = shi->osatex - not supported */ - + /* texture output */ if ((rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) { @@ -2921,13 +2921,13 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float col_ stencilTin*= fact; } } - - + + if ((mapto_flag & (MAP_EMISSION_COL+MAP_TRANSMISSION_COL+MAP_REFLECTION_COL)) && (mtex->mapto & (MAP_EMISSION_COL+MAP_TRANSMISSION_COL+MAP_REFLECTION_COL))) { float tcol[3]; - + /* stencil maps on the texture control slider, not texture intensity value */ - + if ((rgbnor & TEX_RGB) == 0) { copy_v3_v3(tcol, &mtex->r); } @@ -2943,33 +2943,33 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float col_ texres.tin= texres.ta; } } - + /* used for emit */ if ((mapto_flag & MAP_EMISSION_COL) && (mtex->mapto & MAP_EMISSION_COL)) { float colemitfac= mtex->colemitfac*stencilTin; texture_rgb_blend(col_r, tcol, col_r, texres.tin, colemitfac, mtex->blendtype); } - + if ((mapto_flag & MAP_REFLECTION_COL) && (mtex->mapto & MAP_REFLECTION_COL)) { float colreflfac= mtex->colreflfac*stencilTin; texture_rgb_blend(col_r, tcol, col_r, texres.tin, colreflfac, mtex->blendtype); } - + if ((mapto_flag & MAP_TRANSMISSION_COL) && (mtex->mapto & MAP_TRANSMISSION_COL)) { float coltransfac= mtex->coltransfac*stencilTin; texture_rgb_blend(col_r, tcol, col_r, texres.tin, coltransfac, mtex->blendtype); } } - + if ((mapto_flag & MAP_VARS) && (mtex->mapto & MAP_VARS)) { /* stencil maps on the texture control slider, not texture intensity value */ - + /* convert RGB to intensity if intensity info isn't provided */ if (rgbnor & TEX_RGB) { if (texres.talpha) texres.tin = texres.ta; else texres.tin = IMB_colormanagement_get_luminance(&texres.tr); } - + if ((mapto_flag & MAP_EMISSION) && (mtex->mapto & MAP_EMISSION)) { float emitfac= mtex->emitfac*stencilTin; @@ -2984,13 +2984,13 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float col_ } if ((mapto_flag & MAP_SCATTERING) && (mtex->mapto & MAP_SCATTERING)) { float scatterfac= mtex->scatterfac*stencilTin; - + *val = texture_value_blend(mtex->def_var, *val, texres.tin, scatterfac, mtex->blendtype); CLAMP(*val, 0.0f, 1.0f); } if ((mapto_flag & MAP_REFLECTION) && (mtex->mapto & MAP_REFLECTION)) { float reflfac= mtex->reflfac*stencilTin; - + *val = texture_value_blend(mtex->def_var, *val, texres.tin, reflfac, mtex->blendtype); CLAMP(*val, 0.0f, 1.0f); } @@ -3012,46 +3012,46 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4]) int rgb, osatex; if (R.r.scemode & R_NO_TEX) return; - + mtex= har->mat->mtex[0]; if (har->mat->septex & (1<<0)) return; if (mtex->tex==NULL) return; - + /* no normal mapping */ texres.nor= NULL; - + texvec[0]= xn/har->rad; texvec[1]= yn/har->rad; texvec[2]= 0.0; - + osatex= (har->mat->texco & TEXCO_OSA); /* placement */ if (mtex->projx) texvec[0]= mtex->size[0]*(texvec[mtex->projx-1]+mtex->ofs[0]); else texvec[0]= mtex->size[0]*(mtex->ofs[0]); - + if (mtex->projy) texvec[1]= mtex->size[1]*(texvec[mtex->projy-1]+mtex->ofs[1]); else texvec[1]= mtex->size[1]*(mtex->ofs[1]); - + if (mtex->projz) texvec[2]= mtex->size[2]*(texvec[mtex->projz-1]+mtex->ofs[2]); else texvec[2]= mtex->size[2]*(mtex->ofs[2]); - + if (osatex) { - + dx= 1.0f/har->rad; - + if (mtex->projx) { dxt[0]= mtex->size[0]*dx; dyt[0]= mtex->size[0]*dx; } else dxt[0]= dyt[0]= 0.0; - + if (mtex->projy) { dxt[1]= mtex->size[1]*dx; dyt[1]= mtex->size[1]*dx; } else dxt[1]= dyt[1]= 0.0; - + if (mtex->projz) { dxt[2]= 0.0; dyt[2]= 0.0; @@ -3061,7 +3061,7 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4]) } if (mtex->tex->type==TEX_IMAGE) do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt); - + rgb = multitex(mtex->tex, texvec, dxt, dyt, @@ -3090,7 +3090,7 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4]) /* mapping */ if (mtex->mapto & MAP_COL) { - + if (rgb==0) { texres.tr= mtex->r; texres.tg= mtex->g; @@ -3105,7 +3105,7 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4]) if (mtex->tex->type==TEX_IMAGE) { Image *ima = mtex->tex->ima; ImBuf *ibuf = BKE_image_pool_acquire_ibuf(ima, &mtex->tex->iuser, har->pool); - + /* don't linearize float buffers, assumed to be linear */ if (ibuf && !(ibuf->rect_float) && R.scene_color_manage) IMB_colormanagement_colorspace_to_scene_linear_v3(&texres.tr, ibuf->rect_colorspace); @@ -3115,11 +3115,11 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4]) fact= texres.tin*mtex->colfac; facm= 1.0f-fact; - + if (mtex->blendtype==MTEX_MUL) { facm= 1.0f-mtex->colfac; } - + if (mtex->blendtype==MTEX_SUB) fact= -fact; if (mtex->blendtype==MTEX_BLEND) { @@ -3136,7 +3136,7 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4]) col_r[0]= (fact*texres.tr + har->r); col_r[1]= (fact*texres.tg + har->g); col_r[2]= (fact*texres.tb + har->b); - + CLAMP(col_r[0], 0.0f, 1.0f); CLAMP(col_r[1], 0.0f, 1.0f); CLAMP(col_r[2], 0.0f, 1.0f); @@ -3171,24 +3171,24 @@ void do_sky_tex( float fact, stencilTin=1.0; float tempvec[3], texvec[3], dxt[3], dyt[3]; int tex_nr, rgb= 0; - + if (R.r.scemode & R_NO_TEX) return; /* todo: add flag to test if there's a tex */ texres.nor= NULL; - + for (tex_nr=0; tex_nrtex; if (tex == NULL) continue; /* if (mtex->mapto==0) continue; */ - + /* which coords */ co= lo; - + /* dxt dyt just from 1 value */ if (dxyview) { dxt[0]= dxt[1]= dxt[2]= dxyview[0]; @@ -3198,7 +3198,7 @@ void do_sky_tex( dxt[0]= dxt[1]= dxt[2]= 0.0; dyt[0]= dyt[1]= dyt[2]= 0.0; } - + /* Grab the mapping settings for this texture */ switch (mtex->texco) { case TEXCO_ANGMAP: @@ -3219,7 +3219,7 @@ void do_sky_tex( } co= tempvec; break; - + case TEXCO_H_SPHEREMAP: case TEXCO_H_TUBEMAP: if (skyflag & WO_ZENUP) { @@ -3253,7 +3253,7 @@ void do_sky_tex( co= tempvec; } break; - + case TEXCO_GLOB: if (rco) { copy_v3_v3(tempvec, rco); @@ -3262,7 +3262,7 @@ void do_sky_tex( } else co= lo; - + // copy_v3_v3(shi->dxgl, shi->dxco); // mul_m3_v3(R.imat, shi->dxco); // copy_v3_v3(shi->dygl, shi->dyco); @@ -3272,20 +3272,20 @@ void do_sky_tex( co = view; break; } - + /* placement */ if (mtex->projx) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]); else texvec[0]= mtex->size[0]*(mtex->ofs[0]); - + if (mtex->projy) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]); else texvec[1]= mtex->size[1]*(mtex->ofs[1]); - + if (mtex->projz) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]); else texvec[2]= mtex->size[2]*(mtex->ofs[2]); - + /* texture */ if (tex->type==TEX_IMAGE) do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt); - + rgb = multitex(mtex->tex, texvec, dxt, dyt, @@ -3297,7 +3297,7 @@ void do_sky_tex( skip_load_image, texnode_preview, true); - + /* texture output */ if (rgb && (mtex->texflag & MTEX_RGBTOINT)) { texres.tin = IMB_colormanagement_get_luminance(&texres.tr); @@ -3327,25 +3327,25 @@ void do_sky_tex( if (rgb) texres.ta *= stencilTin; else texres.tin*= stencilTin; } - + /* color mapping */ if (mtex->mapto & (WOMAP_HORIZ+WOMAP_ZENUP+WOMAP_ZENDOWN)) { float tcol[3]; - + if (rgb==0) { texres.tr= mtex->r; texres.tg= mtex->g; texres.tb= mtex->b; } else texres.tin= texres.ta; - + tcol[0]= texres.tr; tcol[1]= texres.tg; tcol[2]= texres.tb; /* inverse gamma correction */ if (tex->type==TEX_IMAGE) { Image *ima = tex->ima; ImBuf *ibuf = BKE_image_pool_acquire_ibuf(ima, &tex->iuser, R.pool); - + /* don't linearize float buffers, assumed to be linear */ if (ibuf && !(ibuf->rect_float) && R.scene_color_manage) IMB_colormanagement_colorspace_to_scene_linear_v3(tcol, ibuf->rect_colorspace); @@ -3369,14 +3369,14 @@ void do_sky_tex( if (mtex->mapto & WOMAP_ZENUP) zenfac= mtex->zenupfac; else if (mtex->mapto & WOMAP_ZENDOWN) zenfac= mtex->zendownfac; } - + if (zenfac != 0.0f) texture_rgb_blend(zen, tcol, zen, texres.tin, zenfac, mtex->blendtype); } } if (mtex->mapto & WOMAP_BLEND) { if (rgb) texres.tin = IMB_colormanagement_get_luminance(&texres.tr); - + *blend= texture_value_blend(mtex->def_var, *blend, texres.tin, mtex->blendfac, mtex->blendtype); } } @@ -3397,19 +3397,19 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r float *co = NULL, *dx = NULL, *dy = NULL, fact, stencilTin=1.0; float texvec[3], dxt[3], dyt[3], tempvec[3]; int i, tex_nr, rgb= 0; - + if (R.r.scemode & R_NO_TEX) return; tex_nr= 0; - + for (; tex_nrmtex[tex_nr]) { mtex= la->mtex[tex_nr]; - + tex= mtex->tex; if (tex==NULL) continue; texres.nor= NULL; - + /* which coords */ if (mtex->texco==TEXCO_OBJECT) { ob= mtex->object; @@ -3437,10 +3437,10 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r mul_m4_v3(R.viewinv, shi->gl); } else if (mtex->texco==TEXCO_VIEW) { - + copy_v3_v3(tempvec, lavec); mul_m3_v3(la->imat, tempvec); - + if (la->type==LA_SPOT) { tempvec[0]*= la->spottexfac; tempvec[1]*= la->spottexfac; @@ -3448,8 +3448,8 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r tempvec[0] /= -tempvec[2]; tempvec[1] /= -tempvec[2]; } - co= tempvec; - + co= tempvec; + dx= dxt; dy= dyt; if (shi->osatex) { copy_v3_v3(dxt, shi->dxlv); @@ -3457,23 +3457,23 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r /* need some matrix conversion here? la->imat is a [3][3] matrix!!! **/ mul_m3_v3(la->imat, dxt); mul_m3_v3(la->imat, dyt); - + mul_v3_fl(dxt, la->spottexfac); mul_v3_fl(dyt, la->spottexfac); } } - - + + /* placement */ if (mtex->projx && co) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]); else texvec[0]= mtex->size[0]*(mtex->ofs[0]); - + if (mtex->projy && co) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]); else texvec[1]= mtex->size[1]*(mtex->ofs[1]); - + if (mtex->projz && co) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]); else texvec[2]= mtex->size[2]*(mtex->ofs[2]); - + if (shi->osatex) { if (!dx) { for (i=0;i<2;i++) { @@ -3507,12 +3507,12 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r } } } - + /* texture */ if (tex->type==TEX_IMAGE) { do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt); } - + rgb = multitex(tex, texvec, dxt, dyt, @@ -3554,11 +3554,11 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r if (rgb) texres.ta*= stencilTin; else texres.tin*= stencilTin; } - + /* mapping */ if (((mtex->mapto & LAMAP_COL) && (effect & LA_TEXTURE))||((mtex->mapto & LAMAP_SHAD) && (effect & LA_SHAD_TEX))) { float col[3]; - + if (rgb==0) { texres.tr= mtex->r; texres.tg= mtex->g; @@ -3573,7 +3573,7 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r if (tex->type==TEX_IMAGE) { Image *ima = tex->ima; ImBuf *ibuf = BKE_image_pool_acquire_ibuf(ima, &tex->iuser, R.pool); - + /* don't linearize float buffers, assumed to be linear */ if (ibuf && !(ibuf->rect_float) && R.scene_color_manage) IMB_colormanagement_colorspace_to_scene_linear_v3(&texres.tr, ibuf->rect_colorspace); @@ -3609,26 +3609,26 @@ int externtex(const MTex *mtex, TexResult texr; float dxt[3], dyt[3], texvec[3]; int rgb; - + tex= mtex->tex; if (tex==NULL) return 0; texr.nor= NULL; - + /* placement */ if (mtex->projx) texvec[0]= mtex->size[0]*(vec[mtex->projx-1]+mtex->ofs[0]); else texvec[0]= mtex->size[0]*(mtex->ofs[0]); - + if (mtex->projy) texvec[1]= mtex->size[1]*(vec[mtex->projy-1]+mtex->ofs[1]); else texvec[1]= mtex->size[1]*(mtex->ofs[1]); - + if (mtex->projz) texvec[2]= mtex->size[2]*(vec[mtex->projz-1]+mtex->ofs[2]); else texvec[2]= mtex->size[2]*(mtex->ofs[2]); - + /* texture */ if (tex->type==TEX_IMAGE) { do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt); } - + rgb = multitex(tex, texvec, dxt, dyt, @@ -3639,7 +3639,7 @@ int externtex(const MTex *mtex, skip_load_image, texnode_preview, true); - + if (rgb) { texr.tin = IMB_colormanagement_get_luminance(&texr.tr); } @@ -3648,7 +3648,7 @@ int externtex(const MTex *mtex, texr.tg= mtex->g; texr.tb= mtex->b; } - + *tin= texr.tin; *tr= texr.tr; *tg= texr.tg; @@ -3688,11 +3688,11 @@ void render_realtime_texture(ShadeInput *shi, Image *ima) } BLI_thread_unlock(LOCK_IMAGE); } - + tex= &imatex[shi->thread]; tex->iuser.ok= ima->ok; tex->ima = ima; - + texvec[0]= 0.5f+0.5f*suv->uv[0]; texvec[1]= 0.5f+0.5f*suv->uv[1]; texvec[2] = 0.0f; /* initalize it because imagewrap looks at it. */ @@ -3702,11 +3702,11 @@ void render_realtime_texture(ShadeInput *shi, Image *ima) dy[0]= 0.5f*suv->dyuv[0]; dy[1]= 0.5f*suv->dyuv[1]; } - + texr.nor= NULL; - + if (shi->osatex) imagewraposa(tex, ima, NULL, texvec, dx, dy, &texr, R.pool, skip_load_image); - else imagewrap(tex, ima, NULL, texvec, &texr, R.pool, skip_load_image); + else imagewrap(tex, ima, NULL, texvec, &texr, R.pool, skip_load_image); shi->vcol[0]*= texr.tr; shi->vcol[1]*= texr.tg; @@ -3733,7 +3733,7 @@ static void textured_face_generate_uv( t10= v3[axis1]-v2[axis1]; t11= v3[axis2]-v2[axis2]; detsh= 1.0f/(t00*t11-t10*t01); - t00*= detsh; t01*=detsh; + t00*= detsh; t01*=detsh; t10*=detsh; t11*=detsh; r_uv[0] = (hit[axis1] - v3[axis1]) * t11 - (hit[axis2] - v3[axis2]) * t10; @@ -3761,7 +3761,7 @@ Material *RE_sample_material_init(Material *orig_mat, Scene *scene) /* strip material copy from unsupported flags */ for (tex_nr=0; tex_nrmtex[tex_nr]) { MTex *mtex = mat->mtex[tex_nr]; @@ -3793,7 +3793,7 @@ Material *RE_sample_material_init(Material *orig_mat, Scene *scene) /* strip all mapto flags except color and alpha */ mtex->mapto = mtex->mapto & (MAP_TRANSMISSION_COL | MAP_REFLECTION_COL | MAP_DENSITY); } - + /* if mapped to an object, calculate inverse matrices */ if (mtex->texco==TEXCO_OBJECT) { Object *ob= mtex->object; @@ -3843,7 +3843,7 @@ void RE_sample_material_free(Material *mat) if (mat->septex & (1<mtex[tex_nr]) { MTex *mtex= mat->mtex[tex_nr]; - + if (mtex->tex) { /* don't update user counts as we are freeing a duplicate */ BKE_texture_free(mtex->tex); diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index 77f399d08d1..99d2436d4bc 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -79,29 +79,29 @@ void calc_view_vector(float view[3], float x, float y) { view[2]= -ABS(R.clipsta); - + if (R.r.mode & R_ORTHO) { view[0]= view[1]= 0.0f; } else { - + if (R.r.mode & R_PANORAMA) { x-= R.panodxp; } - + /* move x and y to real viewplane coords */ x = (x / (float)R.winx); view[0] = R.viewplane.xmin + x * BLI_rctf_size_x(&R.viewplane); - + y = (y / (float)R.winy); 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; // else view[1]= (y+R.ystart+1.0)*R.ycor; // } // else view[1]= (y+R.ystart+R.bluroffsy+0.5)*R.ycor; - + if (R.r.mode & R_PANORAMA) { float u= view[0] + R.panodxv; float v= view[2]; view[0]= R.panoco*u + R.panosi*v; @@ -116,10 +116,10 @@ void calc_renderco_ortho(float co[3], float x, float y, int z) float fx= 2.0f/(R.winx*R.winmat[0][0]); float fy= 2.0f/(R.winy*R.winmat[1][1]); float zco; - + co[0]= (x - 0.5f*R.winx)*fx - R.winmat[3][0]/R.winmat[0][0]; co[1]= (y - 0.5f*R.winy)*fy - R.winmat[3][1]/R.winmat[1][1]; - + zco= ((float)z)/2147483647.0f; co[2]= R.winmat[3][2]/( R.winmat[2][3]*zco - R.winmat[2][2] ); } @@ -127,7 +127,7 @@ void calc_renderco_ortho(float co[3], float x, float y, int z) void calc_renderco_zbuf(float co[3], const float view[3], int z) { float fac, zco; - + /* inverse of zbuf calc: zbuf = MAXZ*hoco_z/hoco_w */ zco= ((float)z)/2147483647.0f; co[2]= R.winmat[3][2]/( R.winmat[2][3]*zco - R.winmat[2][2] ); @@ -147,7 +147,7 @@ int count_mask(unsigned short mask) static int calchalo_z(HaloRen *har, int zz) { - + if (har->type & HA_ONLYSKY) { if (zz < 0x7FFFFFF0) zz= - 0x7FFFFF; /* edge render messes zvalues */ } @@ -163,17 +163,17 @@ static void halo_pixelstruct(HaloRen *har, RenderLayer **rlpp, int totsample, in { float col[4], accol[4], fac; int amount, amountm, zz, flarec, sample, fullsample, mask=0; - + fullsample= (totsample > 1); amount= 0; accol[0] = accol[1] = accol[2] = accol[3]= 0.0f; col[0] = col[1] = col[2] = col[3]= 0.0f; flarec= har->flarec; - + while (ps) { amountm= count_mask(ps->mask); amount+= amountm; - + zz= calchalo_z(har, ps->z); if ((zz> har->zs) || (har->mat && (har->mat->mode & MA_HALO_SOFT))) { if (shadeHaloFloat(har, col, zz, dist, xn, yn, flarec)) { @@ -196,7 +196,7 @@ static void halo_pixelstruct(HaloRen *har, RenderLayer **rlpp, int totsample, in } } } - + mask |= ps->mask; ps= ps->next; } @@ -228,7 +228,7 @@ static void halo_pixelstruct(HaloRen *har, RenderLayer **rlpp, int totsample, in col[1]= accol[1]; col[2]= accol[2]; col[3]= accol[3]; - + for (sample=0; sampleadd); @@ -255,7 +255,7 @@ static void halo_tile(RenderPart *pa, RenderLayer *rl) testrect.ymin+= pa->crop; testrect.ymax-= pa->crop; } - + totsample= get_sample_layers(pa, rl, rlpp); for (a=0; axs-har->rad); maxx= ceil(har->xs+har->rad); - + if (testrect.xmin > maxx) { /* pass */ } @@ -283,24 +283,24 @@ static void halo_tile(RenderPart *pa, RenderLayer *rl) /* pass */ } else { - + minx = max_ii(minx, testrect.xmin); maxx = min_ii(maxx, testrect.xmax); - + miny = max_ii(har->miny, testrect.ymin); maxy = min_ii(har->maxy, testrect.ymax); - + for (y=miny; yrectx + (minx - disprect.xmin); rz= pa->rectz + rectofs; od= rectofs; - + if (pa->rectdaps) rd= pa->rectdaps + rectofs; - + yn= (y-har->ys)*R.ycor; ysq= yn*yn; - + for (x=minx; xxs; xsq= xn*xn; @@ -326,7 +326,7 @@ static void halo_tile(RenderPart *pa, RenderLayer *rl) } } } - if (R.test_break(R.tbh) ) break; + if (R.test_break(R.tbh) ) break; } } @@ -339,27 +339,27 @@ static void lamphalo_tile(RenderPart *pa, RenderLayer *rl) intptr_t *rd= pa->rectdaps; const int *rz= pa->rectz; int x, y, sample, totsample, fullsample, od; - + totsample= get_sample_layers(pa, rl, rlpp); fullsample= (totsample > 1); shade_input_initialize(&shi, pa, rl, 0); /* this zero's ShadeInput for us */ - + for (od=0, y=pa->disprect.ymin; ydisprect.ymax; y++) { for (x=pa->disprect.xmin; xdisprect.xmax; x++, rz++, od++) { - + calc_view_vector(shi.view, x, y); - + if (rd && *rd) { PixStr *ps= (PixStr *)*rd; int count, totsamp= 0, mask= 0; - + while (ps) { if (R.r.mode & R_ORTHO) calc_renderco_ortho(shi.co, (float)x, (float)y, ps->z); else calc_renderco_zbuf(shi.co, shi.view, ps->z); - + totsamp+= count= count_mask(ps->mask); mask |= ps->mask; @@ -430,7 +430,7 @@ static void lamphalo_tile(RenderPart *pa, RenderLayer *rl) calc_renderco_ortho(shi.co, (float)x, (float)y, *rz); else calc_renderco_zbuf(shi.co, shi.view, *rz); - + col[0]= col[1]= col[2]= col[3]= 0.0f; renderspothalo(&shi, col, 1.0f); @@ -444,13 +444,13 @@ static void lamphalo_tile(RenderPart *pa, RenderLayer *rl) if (pass[3]>1.0f) pass[3]= 1.0f; } } - + if (rd) rd++; } if (y&1) - if (R.test_break(R.tbh)) break; + if (R.test_break(R.tbh)) break; } -} +} /* ********************* MAINLOOPS ******************** */ @@ -463,7 +463,7 @@ static void add_filt_passes(RenderLayer *rl, int curmask, int rectx, int offset, for (rpass= rl->passes.first; rpass; rpass= rpass->next) { float *fp, *col= NULL; int pixsize= 3; - + if (STREQ(rpass->name, RE_PASSNAME_COMBINED)) { add_filt_fmask(curmask, shr->combined, rpass->rect + 4*offset, rectx); } @@ -570,7 +570,7 @@ static void add_passes(RenderLayer *rl, int offset, ShadeInput *shi, ShadeResult for (rpass= rl->passes.first; rpass; rpass= rpass->next) { float *col= NULL, uvcol[3]; int a, pixsize= 3; - + if (STREQ(rpass->name, RE_PASSNAME_COMBINED)) { /* copy combined to use for preview */ copy_v4_v4(rpass->rect + 4*offset, shr->combined); @@ -656,13 +656,13 @@ static void add_passes(RenderLayer *rl, int offset, ShadeInput *shi, ShadeResult int get_sample_layers(RenderPart *pa, RenderLayer *rl, RenderLayer **rlpp) { - + if (pa->fullresult.first) { int sample, nr= BLI_findindex(&pa->result->layers, rl); - + for (sample=0; samplefullresult, sample); - + rlpp[sample]= BLI_findlink(&rr->layers, nr); } return R.osa; @@ -679,29 +679,29 @@ static void sky_tile(RenderPart *pa, RenderLayer *rl) { RenderLayer *rlpp[RE_MAX_OSA]; int x, y, od=0, totsample; - + if (R.r.alphamode!=R_ADDSKY) return; - + totsample= get_sample_layers(pa, rl, rlpp); - + for (y=pa->disprect.ymin; ydisprect.ymax; y++) { for (x=pa->disprect.xmin; xdisprect.xmax; x++, od+=4) { float col[4]; int sample; bool done = false; - + for (sample= 0; samplethread); done = true; } - + if (pass[3]==0.0f) { copy_v4_v4(pass, col); pass[3] = 1.0f; @@ -713,9 +713,9 @@ static void sky_tile(RenderPart *pa, RenderLayer *rl) } } } - + if (y&1) - if (R.test_break(R.tbh)) break; + if (R.test_break(R.tbh)) break; } } @@ -727,7 +727,7 @@ static void atm_tile(RenderPart *pa, RenderLayer *rl) RenderLayer *rlpp[RE_MAX_OSA]; int totsample; int x, y, od= 0; - + totsample= get_sample_layers(pa, rl, rlpp); /* check that z pass is enabled */ @@ -735,7 +735,7 @@ static void atm_tile(RenderPart *pa, RenderLayer *rl) for (zpass= rl->passes.first; zpass; zpass= zpass->next) if (STREQ(zpass->name, RE_PASSNAME_Z)) break; - + if (zpass==NULL) return; /* check for at least one sun lamp that its atmosphere flag is enabled */ @@ -747,24 +747,24 @@ static void atm_tile(RenderPart *pa, RenderLayer *rl) /* do nothign and return if there is no sun lamp */ if (go==NULL) return; - + /* for each x,y and each sample, and each sun lamp*/ for (y=pa->disprect.ymin; ydisprect.ymax; y++) { for (x=pa->disprect.xmin; xdisprect.xmax; x++, od++) { int sample; - + for (sample=0; samplenext) { - - + + lar= go->lampren; if (lar->type==LA_SUN && lar->sunsky) { - + /* if it's sky continue and don't apply atmosphere effect on it */ if (*zrect >= 9.9e10f || rgbrect[3]==0.0f) { continue; @@ -772,12 +772,12 @@ static void atm_tile(RenderPart *pa, RenderLayer *rl) if ((lar->sunsky->effect_type & LA_SUN_EFFECT_AP)) { float tmp_rgb[3]; - + /* skip if worldspace lamp vector is below horizon */ if (go->ob->obmat[2][2] < 0.f) { continue; } - + copy_v3_v3(tmp_rgb, rgbrect); if (rgbrect[3]!=1.0f) { /* de-premul */ mul_v3_fl(tmp_rgb, 1.0f/rgbrect[3]); @@ -786,7 +786,7 @@ static void atm_tile(RenderPart *pa, RenderLayer *rl) if (rgbrect[3]!=1.0f) { /* premul */ mul_v3_fl(tmp_rgb, rgbrect[3]); } - + if (done==0) { copy_v3_v3(rgb, tmp_rgb); done = true; @@ -816,45 +816,45 @@ static void shadeDA_tile(RenderPart *pa, RenderLayer *rl) intptr_t *rd, *rectdaps= pa->rectdaps; int samp; int x, y, seed, crop=0, offs=0, od; - - if (R.test_break(R.tbh)) return; - + + if (R.test_break(R.tbh)) return; + /* irregular shadowb buffer creation */ if (R.r.mode & R_SHADOW) ISB_create(pa, NULL); - + /* we set per pixel a fixed seed, for random AO and shadow samples */ seed= pa->rectx*pa->disprect.ymin; - + /* general shader info, passes */ shade_sample_initialize(&ssamp, pa, rl); /* occlusion caching */ if (R.occlusiontree) cache_occ_samples(&R, pa, &ssamp); - + /* filtered render, for now we assume only 1 filter size */ if (pa->crop) { crop= 1; rectdaps+= pa->rectx + 1; offs= pa->rectx + 1; } - + /* scanline updates have to be 2 lines behind */ rr->renrect.ymin = 0; rr->renrect.ymax = -2*crop; rr->renlay= rl; - + for (y=pa->disprect.ymin+crop; ydisprect.ymax-crop; y++, rr->renrect.ymax++) { rd= rectdaps; od= offs; - + for (x=pa->disprect.xmin+crop; xdisprect.xmax-crop; x++, rd++, od++) { BLI_thread_srandom(pa->thread, seed++); - + if (*rd) { if (shade_samples(&ssamp, (PixStr *)(*rd), x, y)) { - + /* multisample buffers or filtered mask filling? */ if (pa->fullresult.first) { int a; @@ -874,16 +874,16 @@ static void shadeDA_tile(RenderPart *pa, RenderLayer *rl) } } } - + rectdaps+= pa->rectx; offs+= pa->rectx; - - if (y&1) if (R.test_break(R.tbh)) break; + + if (y&1) if (R.test_break(R.tbh)) break; } - + /* disable scanline updating */ rr->renlay= NULL; - + if (R.r.mode & R_SHADOW) ISB_free(pa); @@ -897,20 +897,20 @@ static void shadeDA_tile(RenderPart *pa, RenderLayer *rl) static PixStrMain *addpsmain(ListBase *lb) { PixStrMain *psm; - + psm= (PixStrMain *)MEM_mallocN(sizeof(PixStrMain), "pixstrMain"); BLI_addtail(lb, psm); - + psm->ps= (PixStr *)MEM_mallocN(4096*sizeof(PixStr), "pixstr"); psm->counter= 0; - + return psm; } static void freeps(ListBase *lb) { PixStrMain *psm, *psmnext; - + for (psm= lb->first; psm; psm= psmnext) { psmnext= psm->next; if (psm->ps) @@ -924,10 +924,10 @@ static void addps(ListBase *lb, intptr_t *rd, int obi, int facenr, int z, int ma { PixStrMain *psm; PixStr *ps, *last= NULL; - + if (*rd) { ps= (PixStr *)(*rd); - + while (ps) { if ( ps->obi == obi && ps->facenr == facenr ) { ps->mask |= mask; @@ -937,18 +937,18 @@ static void addps(ListBase *lb, intptr_t *rd, int obi, int facenr, int z, int ma ps= ps->next; } } - + /* make new PS (pixel struct) */ psm= lb->last; - + if (psm->counter==4095) psm= addpsmain(lb); - + ps= psm->ps + psm->counter++; - + if (last) last->next= ps; else *rd= (intptr_t)ps; - + ps->next= NULL; ps->obi= obi; ps->facenr= facenr; @@ -962,10 +962,10 @@ static void edge_enhance_add(RenderPart *pa, float *rectf, float *arect) { float addcol[4]; int pix; - + if (arect==NULL) return; - + for (pix= pa->rectx*pa->recty; pix>0; pix--, arect++, rectf+=4) { if (*arect != 0.0f) { addcol[0]= *arect * R.r.edgeR; @@ -982,13 +982,13 @@ 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; samplerecty; y++) for (x=0; xrectx; x++, rz++) (*rz)>>= 4; - + rz1= rectz; rz2= rz1+pa->rectx; rz3= rz2+pa->rectx; - + rf= rectf+pa->rectx+1; - + for (y=0; yrecty-2; y++) { for (x=0; xrectx-2; x++, rz1++, rz2++, rz3++, rf++) { - + /* prevent overflow with sky z values */ zval1= rz1[0] + 2*rz1[1] + rz1[2]; zval2= 2*rz2[0] + 2*rz2[2]; zval3= rz3[0] + 2*rz3[1] + rz3[2]; - + col= ( 4*rz2[1] - (zval1 + zval2 + zval3)/3 ); if (col<0) col= -col; - + col >>= 5; if (col > (1<<16)) col= (1<<16); else col= (R.r.edgeint*col)>>8; - + if (col>0) { float fcol; - + if (col>255) fcol= 1.0f; else fcol= (float)col/255.0f; - + if (R.osa) *rf+= fcol/(float)R.osa; else @@ -1054,12 +1054,12 @@ static void edge_enhance_tile(RenderPart *pa, float *rectf, int *rectz) rz3+= 2; rf+= 2; } - + /* shift back zbuf values, we might need it still */ rz= rectz; for (y=0; yrecty; y++) for (x=0; xrectx; x++, rz++) (*rz)<<= 4; - + } static void reset_sky_speed(RenderPart *pa, RenderLayer *rl) @@ -1068,7 +1068,7 @@ static void reset_sky_speed(RenderPart *pa, RenderLayer *rl) RenderLayer *rlpp[RE_MAX_OSA]; float *fp; int a, sample, totsample; - + totsample= get_sample_layers(pa, rl, rlpp); for (sample= 0; samplerectdaps; unsigned short *solidmask, *sp; int x; @@ -1093,7 +1093,7 @@ static unsigned short *make_solid_mask(RenderPart *pa) for (x=pa->rectx*pa->recty; x>0; x--, rd++, sp++) { if (*rd) { PixStr *ps= (PixStr *)*rd; - + *sp= ps->mask; for (ps= ps->next; ps; ps= ps->next) *sp |= ps->mask; @@ -1109,14 +1109,14 @@ static void addAlphaOverFloatMask(float *dest, float *source, unsigned short dma { unsigned short shared= dmask & smask; float mul= 1.0f - source[3]; - + if (shared) { /* overlapping masks */ - + /* masks differ, we make a mixture of 'add' and 'over' */ if (shared!=dmask) { float shared_bits= (float)count_mask(shared); /* alpha over */ float tot_bits= (float)count_mask(smask|dmask); /* alpha add */ - + float add= (tot_bits - shared_bits)/tot_bits; /* add level */ mul= add + (1.0f-add)*mul; } @@ -1127,7 +1127,7 @@ static void addAlphaOverFloatMask(float *dest, float *source, unsigned short dma dest[1]+= source[1]; dest[2]+= source[2]; dest[3]+= source[3]; - + return; } @@ -1163,8 +1163,8 @@ static void make_pixelstructs(RenderPart *pa, ZSpan *zspan, int sample, void *da } } - if (sdata->rl->layflag & SCE_LAY_EDGE) - if (R.r.mode & R_EDGE) + if (sdata->rl->layflag & SCE_LAY_EDGE) + if (R.r.mode & R_EDGE) edge_enhance_tile(pa, sdata->edgerect, zspan->rectz); } @@ -1176,7 +1176,7 @@ void zbufshadeDA_tile(RenderPart *pa) RenderLayer *rl; ListBase psmlist= {NULL, NULL}; float *edgerect= NULL; - + /* allocate the necessary buffers */ /* zbuffer inits these rects */ pa->recto= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "recto"); @@ -1187,15 +1187,15 @@ void zbufshadeDA_tile(RenderPart *pa) if ((rl->layflag & SCE_LAY_ZMASK) && (rl->layflag & SCE_LAY_NEG_ZMASK)) pa->rectmask= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectmask"); - + /* initialize pixelstructs and edge buffer */ addpsmain(&psmlist); pa->rectdaps= MEM_callocN(sizeof(intptr_t)*pa->rectx*pa->recty+4, "zbufDArectd"); - - if (rl->layflag & SCE_LAY_EDGE) - if (R.r.mode & R_EDGE) + + if (rl->layflag & SCE_LAY_EDGE) + if (R.r.mode & R_EDGE) edgerect= MEM_callocN(sizeof(float)*pa->rectx*pa->recty, "rectedge"); - + /* always fill visibility */ for (pa->sample=0; pa->samplesample+=4) { ZbufSolidData sdata; @@ -1204,18 +1204,18 @@ void zbufshadeDA_tile(RenderPart *pa) sdata.psmlist= &psmlist; sdata.edgerect= edgerect; zbuffer_solid(pa, rl, make_pixelstructs, &sdata); - if (R.test_break(R.tbh)) break; + if (R.test_break(R.tbh)) break; } - + /* shades solid */ - if (rl->layflag & SCE_LAY_SOLID) + if (rl->layflag & SCE_LAY_SOLID) shadeDA_tile(pa, rl); - + /* lamphalo after solid, before ztra, looks nicest because ztra does own halo */ if (R.flag & R_LAMPHALO) if (rl->layflag & SCE_LAY_HALO) lamphalo_tile(pa, rl); - + /* halo before ztra, because ztra fills in zbuffer now */ if (R.flag & R_HALO) if (rl->layflag & SCE_LAY_HALO) @@ -1229,15 +1229,15 @@ void zbufshadeDA_tile(RenderPart *pa) } else { unsigned short *ztramask, *solidmask= NULL; /* 16 bits, MAX_OSA */ - + /* allocate, but not free here, for asynchronous display of this rect in main thread */ rl->acolrect= MEM_callocN(4*sizeof(float)*pa->rectx*pa->recty, "alpha layer"); - + /* swap for live updates, and it is used in zbuf.c!!! */ SWAP(float *, rl->acolrect, rect); ztramask = zbuffer_transp_shade(pa, rl, rect, &psmlist); SWAP(float *, rl->acolrect, rect); - + /* zbuffer transp only returns ztramask if there's solid rendered */ if (ztramask) solidmask= make_solid_mask(pa); @@ -1248,7 +1248,7 @@ void zbufshadeDA_tile(RenderPart *pa) float *fcol= rect; float *acol= rl->acolrect; int x; - + for (x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4, sps++, spz++) { if (*sps == fullmask) addAlphaOverFloat(fcol, acol); @@ -1273,26 +1273,26 @@ void zbufshadeDA_tile(RenderPart *pa) /* sun/sky */ if (rl->layflag & SCE_LAY_SKY) atm_tile(pa, rl); - + /* sky before edge */ if (rl->layflag & SCE_LAY_SKY) sky_tile(pa, rl); /* extra layers */ - if (rl->layflag & SCE_LAY_EDGE) - if (R.r.mode & R_EDGE) + if (rl->layflag & SCE_LAY_EDGE) + if (R.r.mode & R_EDGE) edge_enhance_add(pa, rect, edgerect); - + 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); - + /* free stuff within loop! */ MEM_freeN(pa->rectdaps); pa->rectdaps= NULL; freeps(&psmlist); - + if (edgerect) MEM_freeN(edgerect); edgerect= NULL; @@ -1301,12 +1301,12 @@ void zbufshadeDA_tile(RenderPart *pa) pa->rectmask= NULL; } } - + /* free all */ MEM_freeN(pa->recto); pa->recto= NULL; MEM_freeN(pa->rectp); pa->rectp= NULL; MEM_freeN(pa->rectz); pa->rectz= NULL; - + /* display active layer */ rr->renrect.ymin=rr->renrect.ymax = 0; rr->renlay= render_get_active_layer(&R, rr); @@ -1324,11 +1324,11 @@ void zbufshade_tile(RenderPart *pa) RenderLayer *rl; PixStr ps; float *edgerect= NULL; - + /* fake pixel struct, to comply to osa render */ ps.next= NULL; ps.mask= 0xFFFF; - + /* zbuffer code clears/inits rects */ pa->recto= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "recto"); pa->rectp= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectp"); @@ -1341,11 +1341,11 @@ void zbufshade_tile(RenderPart *pa) /* general shader info, passes */ shade_sample_initialize(&ssamp, pa, rl); - + zbuffer_solid(pa, rl, NULL, NULL); - + if (!R.test_break(R.tbh)) { /* NOTE: this if () is not consistent */ - + /* edges only for solid part, ztransp doesn't support it yet anti-aliased */ if (rl->layflag & SCE_LAY_EDGE) { if (R.r.mode & R_EDGE) { @@ -1353,31 +1353,31 @@ void zbufshade_tile(RenderPart *pa) edge_enhance_tile(pa, edgerect, pa->rectz); } } - + /* initialize scanline updates for main thread */ rr->renrect.ymin = 0; rr->renlay= rl; - + if (rl->layflag & SCE_LAY_SOLID) { const float *fcol = rect; const int *ro= pa->recto, *rp= pa->rectp, *rz= pa->rectz; int x, y, offs=0, seed; - + /* we set per pixel a fixed seed, for random AO and shadow samples */ seed= pa->rectx*pa->disprect.ymin; - + /* irregular shadowb buffer creation */ if (R.r.mode & R_SHADOW) ISB_create(pa, NULL); if (R.occlusiontree) cache_occ_samples(&R, pa, &ssamp); - + for (y=pa->disprect.ymin; ydisprect.ymax; y++, rr->renrect.ymax++) { for (x=pa->disprect.xmin; xdisprect.xmax; x++, ro++, rz++, rp++, fcol+=4, offs++) { /* per pixel fixed seed */ BLI_thread_srandom(pa->thread, seed++); - + if (*rp) { ps.obi= *ro; ps.facenr= *rp; @@ -1389,67 +1389,67 @@ void zbufshade_tile(RenderPart *pa) } } if (y&1) - if (R.test_break(R.tbh)) break; + if (R.test_break(R.tbh)) break; } - + if (R.occlusiontree) free_occ_samples(&R, pa); - + if (R.r.mode & R_SHADOW) ISB_free(pa); } - + /* disable scanline updating */ rr->renlay= NULL; } - + /* lamphalo after solid, before ztra, looks nicest because ztra does own halo */ if (R.flag & R_LAMPHALO) if (rl->layflag & SCE_LAY_HALO) lamphalo_tile(pa, rl); - + /* halo before ztra, because ztra fills in zbuffer now */ if (R.flag & R_HALO) if (rl->layflag & SCE_LAY_HALO) halo_tile(pa, rl); - + if (R.flag & R_ZTRA || R.totstrand) { if (rl->layflag & (SCE_LAY_ZTRA|SCE_LAY_STRAND)) { float *fcol, *acol; int x; - + /* allocate, but not free here, for asynchronous display of this rect in main thread */ rl->acolrect= MEM_callocN(4*sizeof(float)*pa->rectx*pa->recty, "alpha layer"); - + /* swap for live updates */ SWAP(float *, rl->acolrect, rect); zbuffer_transp_shade(pa, rl, rect, NULL); SWAP(float *, rl->acolrect, rect); - + fcol= rect; acol= rl->acolrect; for (x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4) { addAlphaOverFloat(fcol, acol); } } } - + /* sun/sky */ if (rl->layflag & SCE_LAY_SKY) atm_tile(pa, rl); - + /* sky before edge */ if (rl->layflag & SCE_LAY_SKY) sky_tile(pa, rl); - + if (!R.test_break(R.tbh)) { - if (rl->layflag & SCE_LAY_EDGE) + if (rl->layflag & SCE_LAY_EDGE) if (R.r.mode & R_EDGE) edge_enhance_add(pa, rect, edgerect); } - + if (rl->passflag & SCE_PASS_VECTOR) reset_sky_speed(pa, rl); - + if (edgerect) MEM_freeN(edgerect); edgerect= NULL; @@ -1462,7 +1462,7 @@ void zbufshade_tile(RenderPart *pa) /* display active layer */ rr->renrect.ymin=rr->renrect.ymax = 0; rr->renlay= render_get_active_layer(&R, rr); - + MEM_freeN(pa->recto); pa->recto= NULL; MEM_freeN(pa->rectp); pa->rectp= NULL; MEM_freeN(pa->rectz); pa->rectz= NULL; @@ -1486,7 +1486,7 @@ static void addps_sss(void *cb_handle, int obi, int facenr, int x, int y, int z) return; if (ycrop || y>=pa->recty-pa->crop) return; - + if (pa->rectall) { intptr_t *rs= pa->rectall + pa->rectx*y + x; @@ -1529,8 +1529,8 @@ static void shade_sample_sss(ShadeSample *ssamp, Material *mat, ObjectInstanceRe /* cache for shadow */ shi->samplenr= R.shadowsamplenr[shi->thread]++; - - if (quad) + + if (quad) shade_input_set_triangle_i(shi, obi, vlr, 0, 2, 3); else shade_input_set_triangle_i(shi, obi, vlr, 0, 1, 2); @@ -1576,13 +1576,13 @@ static void shade_sample_sss(ShadeSample *ssamp, Material *mat, ObjectInstanceRe /* init material vars */ shade_input_init_material(shi); - + /* render */ shade_input_set_shade_texco(shi); - + shade_samples_do_AO(ssamp); shade_material_loop(shi, &shr); - + copy_v3_v3(co, shi->co); copy_v3_v3(color, shr.combined); @@ -1649,7 +1649,7 @@ void zbufshade_sss_tile(RenderPart *pa) memset(&ssamp, 0, sizeof(ssamp)); shade_sample_initialize(&ssamp, pa, rr->layers.first); ssamp.tot= 1; - + for (rl=rr->layers.first; rl; rl=rl->next) { ssamp.shi[0].lay |= rl->lay; ssamp.shi[0].layflag |= rl->layflag; @@ -1671,7 +1671,7 @@ void zbufshade_sss_tile(RenderPart *pa) zbufshade_sss_free(pa); return; } - + fcol= RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, R.viewname); co= MEM_mallocN(sizeof(float)*3*handle.totps, "SSSCo"); @@ -1689,7 +1689,7 @@ void zbufshade_sss_tile(RenderPart *pa) rr->renrect.ymin = 0; rr->renlay= rl; } - + seed= pa->rectx*pa->disprect.ymin; #if 0 rs= pa->rectall; @@ -1707,7 +1707,7 @@ void zbufshade_sss_tile(RenderPart *pa) for (x=pa->disprect.xmin; xdisprect.xmax; x++, fcol+=4) { /* per pixel fixed seed */ BLI_thread_srandom(pa->thread, seed++); - + #if 0 if (rs) { /* for each sample in this pixel, shade it */ @@ -1741,7 +1741,7 @@ void zbufshade_sss_tile(RenderPart *pa) shade_sample_sss(&ssamp, mat, obi, vlr, quad, x, y, *rz, co[totpoint], color[totpoint], &area[totpoint]); - + add_v3_v3(fcol, color[totpoint]); fcol[3]= 1.0f; totpoint++; @@ -1761,7 +1761,7 @@ void zbufshade_sss_tile(RenderPart *pa) shade_sample_sss(&ssamp, mat, obi, vlr, quad, x, y, *rbz, co[totpoint], color[totpoint], &area[totpoint]); - + /* to indicate this is a back sample */ area[totpoint]= -area[totpoint]; @@ -1776,7 +1776,7 @@ void zbufshade_sss_tile(RenderPart *pa) } if (y&1) - if (re->test_break(re->tbh)) break; + if (re->test_break(re->tbh)) break; } /* note: after adding we do not free these arrays, sss keeps them */ @@ -1788,18 +1788,18 @@ void zbufshade_sss_tile(RenderPart *pa) MEM_freeN(color); MEM_freeN(area); } - + #if 0 if (re->r.mode & R_SHADOW) ISB_free(pa); #endif - + if (display) { /* display active layer */ rr->renrect.ymin=rr->renrect.ymax = 0; rr->renlay= render_get_active_layer(&R, rr); } - + zbufshade_sss_free(pa); } @@ -1814,10 +1814,10 @@ static void renderhalo_post(RenderResult *rr, float *rectf, HaloRen *har) /* pos /* calculate the disprect mapped coordinate for halo. note: rectx is disprect corrected */ haloxs= har->xs - R.disprect.xmin; haloys= har->ys - R.disprect.ymin; - + har->miny= miny= haloys - har->rad/R.ycor; har->maxy= maxy= haloys + har->rad/R.ycor; - + if (maxy < 0) { /* pass */ } @@ -1827,7 +1827,7 @@ static void renderhalo_post(RenderResult *rr, float *rectf, HaloRen *har) /* pos else { minx = floor(haloxs - har->rad); maxx = ceil(haloxs + har->rad); - + if (maxx < 0) { /* pass */ } @@ -1839,35 +1839,35 @@ static void renderhalo_post(RenderResult *rr, float *rectf, HaloRen *har) /* pos if (maxx>=rr->rectx) maxx= rr->rectx-1; if (miny<0) miny= 0; if (maxy>rr->recty) maxy= rr->recty; - + rectft= rectf+ 4*rr->rectx*miny; for (y=miny; yradsq) { - + if (shadeHaloFloat(har, colf, 0x7FFFFF, dist, xn, yn, har->flarec)) addalphaAddfacFloat(rtf, colf, har->add); } rtf+=4; } - + rectft+= 4*rr->rectx; - - if (R.test_break(R.tbh)) break; + + if (R.test_break(R.tbh)) break; } } } -} +} /* ------------------------------------------------------------------------ */ static void renderflare(RenderResult *rr, float *rectf, HaloRen *har) @@ -1878,57 +1878,57 @@ static void renderflare(RenderResult *rr, float *rectf, HaloRen *har) const float *rc; float rad, alfa, visifac, vec[3]; int b, type; - + fla= *har; fla.linec= fla.ringc= fla.flarec= 0; - + rad= har->rad; alfa= har->alfa; - + visifac= R.ycor*(har->pixels); /* all radials added / r^3 == 1.0f! */ visifac /= (har->rad*har->rad*har->rad); visifac*= visifac; ma= har->mat; - + /* first halo: just do */ - + har->rad= rad*ma->flaresize*visifac; har->radsq= har->rad*har->rad; har->zs= fla.zs= 0; - + har->alfa= alfa*visifac; renderhalo_post(rr, rectf, har); - + /* next halo's: the flares */ rc= hashvectf + ma->seed2; - + for (b=1; bflarec; b++) { - + fla.r = fabsf(rc[0]); fla.g = fabsf(rc[1]); fla.b = fabsf(rc[2]); fla.alfa= ma->flareboost*fabsf(alfa*visifac*rc[3]); fla.hard= 20.0f + fabsf(70.0f*rc[7]); fla.tex= 0; - + type= (int)(fabsf(3.9f*rc[6])); fla.rad = ma->subsize * sqrtf(fabsf(2.0f * har->rad * rc[4])); - + if (type==3) { fla.rad*= 3.0f; fla.rad+= R.rectx/10; } - + fla.radsq= fla.rad*fla.rad; - + vec[0]= 1.4f*rc[5]*(har->xs-R.winx/2); vec[1]= 1.4f*rc[5]*(har->ys-R.winy/2); vec[2]= 32.0f*sqrtf(vec[0]*vec[0] + vec[1]*vec[1] + 1.0f); - + fla.xs= R.winx/2 + vec[0] + (1.2f+rc[8])*R.rectx*vec[0]/vec[2]; fla.ys= R.winy/2 + vec[1] + (1.2f+rc[8])*R.rectx*vec[1]/vec[2]; @@ -1944,7 +1944,7 @@ static void renderflare(RenderResult *rr, float *rectf, HaloRen *har) if (type & 2) fla.type= HA_FLARECIRC; else fla.type= 0; renderhalo_post(rr, rectf, &fla); - + rc+= 7; } } @@ -1957,11 +1957,11 @@ void add_halo_flare(Render *re) HaloRen *har; int a, mode; float *rect; - + /* for now, we get the first renderlayer in list with halos set */ for (rl= rr->layers.first; rl; rl= rl->next) { bool do_draw = false; - + if ((rl->layflag & SCE_LAY_HALO) == 0) continue; @@ -1972,18 +1972,18 @@ void add_halo_flare(Render *re) mode= R.r.mode; R.r.mode &= ~R_PANORAMA; - + project_renderdata(&R, projectverto, 0, 0, 0); - + for (a=0; aflarec && (har->lay & rl->lay)) { do_draw = true; renderflare(rr, rect, har); } } - + if (do_draw) { /* weak... the display callback wants an active renderlayer pointer... */ rr->renlay= rl; diff --git a/source/blender/render/intern/source/renderdatabase.c b/source/blender/render/intern/source/renderdatabase.c index 79e41bc64cf..67bfd1bfdc7 100644 --- a/source/blender/render/intern/source/renderdatabase.c +++ b/source/blender/render/intern/source/renderdatabase.c @@ -68,8 +68,8 @@ #include "BLI_utildefines.h" #include "BLI_hash.h" -#include "DNA_material_types.h" -#include "DNA_meshdata_types.h" +#include "DNA_material_types.h" +#include "DNA_meshdata_types.h" #include "DNA_texture_types.h" #include "DNA_listBase.h" #include "DNA_particle_types.h" @@ -114,10 +114,10 @@ float *RE_vertren_get_stress(ObjectRen *obr, VertRen *ver, int verify) { float *stress; int nr= ver->index>>8; - + stress= obr->vertnodes[nr].stress; if (stress==NULL) { - if (verify) + if (verify) stress= obr->vertnodes[nr].stress= MEM_mallocN(256*RE_STRESS_ELEMS*sizeof(float), "stress table"); else return NULL; @@ -130,10 +130,10 @@ float *RE_vertren_get_rad(ObjectRen *obr, VertRen *ver, int verify) { float *rad; int nr= ver->index>>8; - + rad= obr->vertnodes[nr].rad; if (rad==NULL) { - if (verify) + if (verify) rad= obr->vertnodes[nr].rad= MEM_callocN(256*RE_RAD_ELEMS*sizeof(float), "rad table"); else return NULL; @@ -145,10 +145,10 @@ float *RE_vertren_get_strand(ObjectRen *obr, VertRen *ver, int verify) { float *strand; int nr= ver->index>>8; - + strand= obr->vertnodes[nr].strand; if (strand==NULL) { - if (verify) + if (verify) strand= obr->vertnodes[nr].strand= MEM_mallocN(256*RE_STRAND_ELEMS*sizeof(float), "strand table"); else return NULL; @@ -161,10 +161,10 @@ float *RE_vertren_get_tangent(ObjectRen *obr, VertRen *ver, int verify) { float *tangent; int nr= ver->index>>8; - + tangent= obr->vertnodes[nr].tangent; if (tangent==NULL) { - if (verify) + if (verify) tangent= obr->vertnodes[nr].tangent= MEM_callocN(256*RE_TANGENT_ELEMS*sizeof(float), "tangent table"); else return NULL; @@ -178,7 +178,7 @@ float *RE_vertren_get_winspeed(ObjectInstanceRen *obi, VertRen *ver, int verify) { float *winspeed; int totvector; - + winspeed= obi->vectors; if (winspeed==NULL) { if (verify) { @@ -212,7 +212,7 @@ VertRen *RE_vertren_copy(ObjectRen *obr, VertRen *ver) float *fp1, *fp2; int *int1, *int2; int index= v1->index; - + *v1= *ver; v1->index= index; @@ -255,25 +255,25 @@ VertRen *RE_findOrAddVert(ObjectRen *obr, int nr) return NULL; } a= nr>>8; - + if (a>=obr->vertnodeslen-1) { /* Need to allocate more columns..., and keep last element NULL for free loop */ temp= obr->vertnodes; - + obr->vertnodes= MEM_mallocN(sizeof(VertTableNode)*(obr->vertnodeslen+TABLEINITSIZE), "vertnodes"); if (temp) memcpy(obr->vertnodes, temp, obr->vertnodeslen*sizeof(VertTableNode)); memset(obr->vertnodes+obr->vertnodeslen, 0, TABLEINITSIZE*sizeof(VertTableNode)); - - obr->vertnodeslen+=TABLEINITSIZE; + + obr->vertnodeslen+=TABLEINITSIZE; if (temp) MEM_freeN(temp); } - + v= obr->vertnodes[a].vert; if (v==NULL) { int i; - + v= (VertRen *)MEM_callocN(256*sizeof(VertRen), "findOrAddVert"); obr->vertnodes[a].vert= v; - + for (i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++) { v[a].index= i; } @@ -371,10 +371,10 @@ float *RE_vlakren_get_surfnor(ObjectRen *obr, VlakRen *vlak, int verify) { float *surfnor; int nr= vlak->index>>8; - + surfnor= obr->vlaknodes[nr].surfnor; if (surfnor==NULL) { - if (verify) + if (verify) surfnor= obr->vlaknodes[nr].surfnor= MEM_callocN(256*RE_SURFNOR_ELEMS*sizeof(float), "surfnor table"); else return NULL; @@ -410,10 +410,10 @@ RadFace **RE_vlakren_get_radface(ObjectRen *obr, VlakRen *vlak, int verify) { RadFace **radface; int nr= vlak->index>>8; - + radface= obr->vlaknodes[nr].radface; if (radface==NULL) { - if (verify) + if (verify) radface = obr->vlaknodes[nr].radface= MEM_callocN(256 * RE_RADFACE_ELEMS * sizeof(void *), "radface table"); else return NULL; @@ -493,7 +493,7 @@ void RE_set_customdata_names(ObjectRen *obr, CustomData *data) { /* CustomData layer names are stored per object here, because the * DerivedMesh which stores the layers is freed */ - + CustomDataLayer *layer; int numtf = 0, numcol = 0, i, mtfn, mcn; @@ -533,10 +533,10 @@ VlakRen *RE_findOrAddVlak(ObjectRen *obr, int nr) return obr->vlaknodes[0].vlak; } a= nr>>8; - + if (a>=obr->vlaknodeslen-1) { /* Need to allocate more columns..., and keep last element NULL for free loop */ temp= obr->vlaknodes; - + obr->vlaknodes= MEM_mallocN(sizeof(VlakTableNode)*(obr->vlaknodeslen+TABLEINITSIZE), "vlaknodes"); if (temp) memcpy(obr->vlaknodes, temp, obr->vlaknodeslen*sizeof(VlakTableNode)); memset(obr->vlaknodes+obr->vlaknodeslen, 0, TABLEINITSIZE*sizeof(VlakTableNode)); @@ -546,7 +546,7 @@ VlakRen *RE_findOrAddVlak(ObjectRen *obr, int nr) } v= obr->vlaknodes[a].vlak; - + if (v==NULL) { int i; @@ -566,10 +566,10 @@ float *RE_strandren_get_surfnor(ObjectRen *obr, StrandRen *strand, int verify) { float *surfnor; int nr= strand->index>>8; - + surfnor= obr->strandnodes[nr].surfnor; if (surfnor==NULL) { - if (verify) + if (verify) surfnor= obr->strandnodes[nr].surfnor= MEM_callocN(256*RE_SURFNOR_ELEMS*sizeof(float), "surfnor strand table"); else return NULL; @@ -649,10 +649,10 @@ float *RE_strandren_get_simplify(struct ObjectRen *obr, struct StrandRen *strand { float *simplify; int nr= strand->index>>8; - + simplify= obr->strandnodes[nr].simplify; if (simplify==NULL) { - if (verify) + if (verify) simplify= obr->strandnodes[nr].simplify= MEM_callocN(256*RE_SIMPLIFY_ELEMS*sizeof(float), "simplify strand table"); else return NULL; @@ -664,10 +664,10 @@ int *RE_strandren_get_face(ObjectRen *obr, StrandRen *strand, int verify) { int *face; int nr= strand->index>>8; - + face= obr->strandnodes[nr].face; if (face==NULL) { - if (verify) + if (verify) face= obr->strandnodes[nr].face= MEM_callocN(256*RE_FACE_ELEMS*sizeof(int), "face strand table"); else return NULL; @@ -680,7 +680,7 @@ float *RE_strandren_get_winspeed(ObjectInstanceRen *obi, StrandRen *strand, int { float *winspeed; int totvector; - + winspeed= obi->vectors; if (winspeed==NULL) { if (verify) { @@ -704,10 +704,10 @@ StrandRen *RE_findOrAddStrand(ObjectRen *obr, int nr) return obr->strandnodes[0].strand; } a= nr>>8; - + if (a>=obr->strandnodeslen-1) { /* Need to allocate more columns..., and keep last element NULL for free loop */ temp= obr->strandnodes; - + obr->strandnodes= MEM_mallocN(sizeof(StrandTableNode)*(obr->strandnodeslen+TABLEINITSIZE), "strandnodes"); if (temp) memcpy(obr->strandnodes, temp, obr->strandnodeslen*sizeof(StrandTableNode)); memset(obr->strandnodes+obr->strandnodeslen, 0, TABLEINITSIZE*sizeof(StrandTableNode)); @@ -717,7 +717,7 @@ StrandRen *RE_findOrAddStrand(ObjectRen *obr, int nr) } v= obr->strandnodes[a].strand; - + if (v==NULL) { int i; @@ -750,7 +750,7 @@ StrandBuffer *RE_addStrandBuffer(ObjectRen *obr, int totvert) ObjectRen *RE_addRenderObject(Render *re, Object *ob, Object *par, int index, int psysindex, int lay) { ObjectRen *obr= MEM_callocN(sizeof(ObjectRen), "object render struct"); - + BLI_addtail(&re->objecttable, obr); obr->ob= ob; obr->par= par; @@ -764,12 +764,12 @@ ObjectRen *RE_addRenderObject(Render *re, Object *ob, Object *par, int index, in void free_renderdata_vertnodes(VertTableNode *vertnodes) { int a; - + if (vertnodes==NULL) return; - + for (a=0; vertnodes[a].vert; a++) { MEM_freeN(vertnodes[a].vert); - + if (vertnodes[a].rad) MEM_freeN(vertnodes[a].rad); if (vertnodes[a].strand) @@ -783,19 +783,19 @@ void free_renderdata_vertnodes(VertTableNode *vertnodes) if (vertnodes[a].origindex) MEM_freeN(vertnodes[a].origindex); } - + MEM_freeN(vertnodes); } void free_renderdata_vlaknodes(VlakTableNode *vlaknodes) { int a; - + if (vlaknodes==NULL) return; - + for (a=0; vlaknodes[a].vlak; a++) { MEM_freeN(vlaknodes[a].vlak); - + if (vlaknodes[a].mtface) MEM_freeN(vlaknodes[a].mtface); if (vlaknodes[a].mcol) @@ -811,19 +811,19 @@ void free_renderdata_vlaknodes(VlakTableNode *vlaknodes) if (vlaknodes[a].radface) MEM_freeN(vlaknodes[a].radface); } - + MEM_freeN(vlaknodes); } static void free_renderdata_strandnodes(StrandTableNode *strandnodes) { int a; - + if (strandnodes==NULL) return; - + for (a=0; strandnodes[a].strand; a++) { MEM_freeN(strandnodes[a].strand); - + if (strandnodes[a].uv) MEM_freeN(strandnodes[a].uv); if (strandnodes[a].mcol) @@ -837,7 +837,7 @@ static void free_renderdata_strandnodes(StrandTableNode *strandnodes) if (strandnodes[a].face) MEM_freeN(strandnodes[a].face); } - + MEM_freeN(strandnodes); } @@ -847,7 +847,7 @@ void free_renderdata_tables(Render *re) ObjectRen *obr; StrandBuffer *strandbuf; int a=0; - + for (obr=re->objecttable.first; obr; obr=obr->next) { if (obr->vertnodes) { free_renderdata_vertnodes(obr->vertnodes); @@ -889,7 +889,7 @@ void free_renderdata_tables(Render *re) if (obr->mcol) MEM_freeN(obr->mcol); - + if (obr->rayfaces) { MEM_freeN(obr->rayfaces); obr->rayfaces = NULL; @@ -943,19 +943,19 @@ HaloRen *RE_findOrAddHalo(ObjectRen *obr, int nr) return NULL; } a= nr>>8; - + if (a>=obr->blohalen-1) { /* Need to allocate more columns..., and keep last element NULL for free loop */ - //printf("Allocating %i more halo groups. %i total.\n", + //printf("Allocating %i more halo groups. %i total.\n", // TABLEINITSIZE, obr->blohalen+TABLEINITSIZE ); temp=obr->bloha; - + obr->bloha = (HaloRen **)MEM_callocN(sizeof(void *) * (obr->blohalen + TABLEINITSIZE), "Bloha"); if (temp) memcpy(obr->bloha, temp, obr->blohalen*sizeof(void *)); memset(&(obr->bloha[obr->blohalen]), 0, TABLEINITSIZE * sizeof(void *)); obr->blohalen+=TABLEINITSIZE; /*Does this really need to be power of 2?*/ if (temp) MEM_freeN(temp); } - + h= obr->bloha[a]; if (h==NULL) { h= (HaloRen *)MEM_callocN(256*sizeof(HaloRen), "findOrAdHalo"); @@ -997,9 +997,9 @@ HaloRen *RE_inithalo(Render *re, ObjectRen *obr, Material *ma, har->xs= 0.5f*re->winx*(hoco[0]/zn); har->ys= 0.5f*re->winy*(hoco[1]/zn); har->zs= 0x7FFFFF*(hoco[2]/zn); - - har->zBufDist = 0x7FFFFFFF*(hoco[2]/zn); - + + har->zBufDist = 0x7FFFFFFF*(hoco[2]/zn); + /* halovect */ if (vec1) { @@ -1015,7 +1015,7 @@ HaloRen *RE_inithalo(Render *re, ObjectRen *obr, Material *ma, zn= len_v3v3(vec1, vec); har->hasize= vectsize*zn + (1.0f-vectsize)*hasize; - + sub_v3_v3v3(har->no, vec, vec1); normalize_v3(har->no); } @@ -1127,9 +1127,9 @@ HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Mater har->xs= 0.5f*re->winx*(hoco[0]/zn); har->ys= 0.5f*re->winy*(hoco[1]/zn); har->zs= 0x7FFFFF*(hoco[2]/zn); - - har->zBufDist = 0x7FFFFFFF*(hoco[2]/zn); - + + har->zBufDist = 0x7FFFFFFF*(hoco[2]/zn); + /* halovect */ if (vec1) { @@ -1145,7 +1145,7 @@ HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Mater zn= len_v3v3(vec1, vec)*0.5f; har->hasize= vectsize*zn + (1.0f-vectsize)*hasize; - + sub_v3_v3v3(har->no, vec, vec1); normalize_v3(har->no); } @@ -1168,7 +1168,7 @@ HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Mater if ((ma->mode & MA_HALOTEX) && ma->mtex[0]) har->tex= 1; - + for (i=0; imtex[i] && (ma->septex & (1<mtex[i]; @@ -1317,7 +1317,7 @@ void project_renderdata(Render *re, if (do_pano) { float panophi= xoffs; - + re->panosi = sinf(panophi); re->panoco = cosf(panophi); } @@ -1338,11 +1338,11 @@ void project_renderdata(Render *re, } projectfunc(vec, re->winmat, hoco); - + /* we clip halos less critical, but not for the Z */ hoco[0]*= 0.5f; hoco[1]*= 0.5f; - + if ( panotestclip(re, do_pano, hoco) ) { har->miny= har->maxy= -10000; /* that way render clips it */ } @@ -1353,42 +1353,42 @@ void project_renderdata(Render *re, /* bring back hocos */ hoco[0]*= 2.0f; hoco[1]*= 2.0f; - + zn= hoco[3]; har->xs= 0.5f*re->winx*(1.0f+hoco[0]/zn); /* the 0.5 negates the previous 2...*/ har->ys= 0.5f*re->winy*(1.0f+hoco[1]/zn); - + /* this should be the zbuffer coordinate */ har->zs= 0x7FFFFF*(hoco[2]/zn); /* taking this from the face clip functions? seems ok... */ har->zBufDist = 0x7FFFFFFF*(hoco[2]/zn); - + vec[0]+= har->hasize; projectfunc(vec, re->winmat, hoco); vec[0]-= har->hasize; zn= hoco[3]; har->rad= fabsf(har->xs- 0.5f*re->winx*(1.0f+hoco[0]/zn)); - + /* this clip is not really OK, to prevent stars to become too large */ if (har->type & HA_ONLYSKY) { if (har->rad>3.0f) har->rad= 3.0f; } - + har->radsq= har->rad*har->rad; - + har->miny= har->ys - har->rad/re->ycor; har->maxy= har->ys + har->rad/re->ycor; - + /* the Zd value is still not really correct for pano */ - + vec[2] -= har->hasize; /* z negative, otherwise it's clipped */ projectfunc(vec, re->winmat, hoco); zn = hoco[3]; zn = fabsf((float)har->zs - 0x7FFFFF * (hoco[2] / zn)); har->zd = CLAMPIS(zn, 0, INT_MAX); - + } - + } } } @@ -1578,14 +1578,14 @@ int clip_render_object(float boundbox[2][3], float bounds[4], float winmat[4][4] if (bounds) { if (vec[0] < bounds[0] * vec[3]) fl |= 1; else if (vec[0] > bounds[1] * vec[3]) fl |= 2; - + if (vec[1] > bounds[3] * vec[3]) fl |= 4; else if (vec[1] < bounds[2] * vec[3]) fl |= 8; } else { if (vec[0] < -vec[3]) fl |= 1; else if (vec[0] > vec[3]) fl |= 2; - + if (vec[1] > vec[3]) fl |= 4; else if (vec[1] < -vec[3]) fl |= 8; } diff --git a/source/blender/render/intern/source/shadbuf.c b/source/blender/render/intern/source/shadbuf.c index fb441662829..04e9177241b 100644 --- a/source/blender/render/intern/source/shadbuf.c +++ b/source/blender/render/intern/source/shadbuf.c @@ -89,7 +89,7 @@ static void copy_to_ztile(int *rectz, int size, int x1, int y1, int tile, char * { int len4, *rz; int x2, y2; - + x2= x1+tile; y2= y1+tile; if (x2>=size) x2= size-1; @@ -111,12 +111,12 @@ static int sizeoflampbuf(ShadBuf *shb) { int num, count=0; char *cp; - + cp= shb->cbuf; num= (shb->size*shb->size)/256; while (num--) count+= *(cp++); - + return 256*count; } #endif @@ -132,7 +132,7 @@ static float *give_jitter_tab(int samp) static float jit[1496][2]; static char ctab[17]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int a, offset=0; - + if (samp<2) samp= 2; else if (samp>16) samp= 16; @@ -142,19 +142,19 @@ static float *give_jitter_tab(int samp) ctab[samp]= 1; BLI_jitter_init((float (*)[2])jit[offset], samp*samp); } - + return jit[offset]; - + } -static void make_jitter_weight_tab(Render *re, ShadBuf *shb, short filtertype) +static void make_jitter_weight_tab(Render *re, ShadBuf *shb, short filtertype) { float *jit, totw= 0.0f; int samp= get_render_shadow_samples(&re->r, shb->samp); int a, tot=samp*samp; - + shb->weight= MEM_mallocN(sizeof(float)*tot, "weight tab lamp"); - + for (jit= shb->jit, a=0; aweight[a] = 0.71f - sqrtf(jit[0] * jit[0] + jit[1] * jit[1]); @@ -162,10 +162,10 @@ static void make_jitter_weight_tab(Render *re, ShadBuf *shb, short filtertype) shb->weight[a] = RE_filter_value(R_FILTER_GAUSS, 1.8f * sqrtf(jit[0] * jit[0] + jit[1] * jit[1])); else shb->weight[a]= 1.0f; - + totw+= shb->weight[a]; } - + totw= 1.0f/totw; for (a=0; aweight[a]*= totw; @@ -319,7 +319,7 @@ static void compress_deepshadowbuf(Render *re, ShadBuf *shb, APixstr *apixbuf, A int a, b, c, tot, minz, found, prevtot, newtot; int sampletot[RE_MAX_OSA], totsample = 0, totsamplec = 0; - + shsample= MEM_callocN(sizeof(ShadSampleBuf), "shad sample buf"); BLI_addtail(&shb->buffers, shsample); @@ -511,32 +511,32 @@ static void compress_shadowbuf(ShadBuf *shb, int *rectz, int square) int *rz, *rz1, verg, verg1, size= shb->size; int a, x, y, minx, miny, byt1, byt2; char *rc, *rcline, *ctile, *zt; - + shsample= MEM_callocN(sizeof(ShadSampleBuf), "shad sample buf"); BLI_addtail(&shb->buffers, shsample); - + shsample->zbuf= MEM_mallocN(sizeof(uintptr_t)*(size*size)/256, "initshadbuf2"); shsample->cbuf= MEM_callocN((size*size)/256, "initshadbuf3"); - + ztile= (uintptr_t *)shsample->zbuf; ctile= shsample->cbuf; - + /* help buffer */ rcline= MEM_mallocN(256*4+sizeof(int), "makeshadbuf2"); - + for (y=0; y(float)(a+12)) { /* 12, tested with a onlyshadow lamp */ a= 256; verg= 0; /* 0x80000000; */ /* 0x7FFFFFFF; */ rz1= (&verg)+1; @@ -544,9 +544,9 @@ static void compress_shadowbuf(ShadBuf *shb, int *rectz, int square) else { copy_to_ztile(rectz, size, x, y, 16, rcline); rz1= (int *)rcline; - + verg= (*rz1 & 0xFFFFFF00); - + for (a=0;a<256;a++, rz1++) { if ( (*rz1 & 0xFFFFFF00) !=verg) break; } @@ -556,9 +556,9 @@ static void compress_shadowbuf(ShadBuf *shb, int *rectz, int square) *ztile= *(rz1-1); } else { - + /* ACOMP etc. are defined to work L/B endian */ - + rc= rcline; rz1= (int *)rcline; verg= rc[ACOMP]; @@ -568,7 +568,7 @@ static void compress_shadowbuf(ShadBuf *shb, int *rectz, int square) for (a=1;a<256;a++, rc+=4) { byt1 &= (verg==rc[ACOMP]); byt2 &= (verg1==rc[BCOMP]); - + if (byt1==0) break; } if (byt1 && byt2) { /* only store byte */ @@ -576,7 +576,7 @@ static void compress_shadowbuf(ShadBuf *shb, int *rectz, int square) *ztile= (uintptr_t)MEM_mallocN(256+4, "tile1"); rz= (int *)*ztile; *rz= *rz1; - + zt= (char *)(rz+1); rc= rcline; for (a=0; a<256; a++, zt++, rc+=4) *zt= rc[GCOMP]; @@ -586,7 +586,7 @@ static void compress_shadowbuf(ShadBuf *shb, int *rectz, int square) *ztile= (uintptr_t)MEM_mallocN(2*256+4, "Tile2"); rz= (int *)*ztile; *rz= *rz1; - + zt= (char *)(rz+1); rc= rcline; for (a=0; a<256; a++, zt+=2, rc+=4) { @@ -627,10 +627,10 @@ static void shadowbuf_autoclip(Render *re, LampRen *lar) unsigned int lay = -1; int i, a, maxtotvert, ok= 1; char *clipflag; - + minz= 1.0e30f; maxz= -1.0e30f; copy_m4_m4(viewmat, lar->shb->viewmat); - + if (lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) lay= lar->lay; maxtotvert= 0; @@ -654,14 +654,14 @@ static void shadowbuf_autoclip(Render *re, LampRen *lar) for (a=0; atotvlak; a++) { if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; else vlr++; - + /* note; these conditions are copied from zbuffer_shadow() */ if (vlr->mat!= ma) { ma= vlr->mat; ok= 1; if ((ma->mode2 & MA_CASTSHADOW)==0 || (ma->mode & MA_SHADBUF)==0) ok= 0; } - + if (ok && (obi->lay & lay)) { clipflag[vlr->v1->index]= 1; clipflag[vlr->v2->index]= 1; @@ -669,19 +669,19 @@ static void shadowbuf_autoclip(Render *re, LampRen *lar) if (vlr->v4) clipflag[vlr->v4->index]= 1; } } - + /* calculate min and max */ for (a=0; a< obr->totvert;a++) { if ((a & 255)==0) ver= RE_findOrAddVert(obr, a); else ver++; - + if (clipflag[a]) { copy_v3_v3(vec, ver->co); mul_m4_v3(obviewmat, vec); /* Z on visible side of lamp space */ if (vec[2] < 0.0f) { float inpr, z= -vec[2]; - + /* since vec is rotated in lampspace, this is how to get the cosine of angle */ /* precision is set 20% larger */ vec[2]*= 1.2f; @@ -698,17 +698,17 @@ static void shadowbuf_autoclip(Render *re, LampRen *lar) } MEM_freeN(clipflag); - + /* set clipping min and max */ if (minz < maxz) { float delta= (maxz - minz); /* threshold to prevent precision issues */ - + //printf("minz %f maxz %f delta %f\n", minz, maxz, delta); if (lar->bufflag & LA_SHADBUF_AUTO_START) lar->shb->d= minz - delta*0.02f; /* 0.02 is arbitrary... needs more thinking! */ if (lar->bufflag & LA_SHADBUF_AUTO_END) lar->shb->clipend= maxz + delta*0.1f; - + /* bias was calculated as percentage, we scale it to prevent animation issues */ delta= (lar->clipend-lar->clipsta)/(lar->shb->clipend-lar->shb->d); //printf("bias delta %f\n", delta); @@ -723,7 +723,7 @@ static void makeflatshadowbuf(Render *re, LampRen *lar, float *jitbuf) /* zbuffering */ rectz= MEM_mapallocN(sizeof(int)*shb->size*shb->size, "makeshadbuf"); - + for (samples=0; samplestotbuf; samples++) { zbuffer_shadow(re, shb->persmat, lar, rectz, shb->size, jitbuf[2*samples], jitbuf[2*samples+1]); /* create Z tiles (for compression): this system is 24 bits!!! */ @@ -732,7 +732,7 @@ static void makeflatshadowbuf(Render *re, LampRen *lar, float *jitbuf) if (re->test_break(re->tbh)) break; } - + MEM_freeN(rectz); } @@ -753,7 +753,7 @@ static void makedeepshadowbuf(Render *re, LampRen *lar, float *jitbuf) /* create Z tiles (for compression): this system is 24 bits!!! */ compress_deepshadowbuf(re, shb, apixbuf, apixbufstrand); - + MEM_freeN(apixbuf); if (apixbufstrand) MEM_freeN(apixbufstrand); @@ -764,22 +764,22 @@ void makeshadowbuf(Render *re, LampRen *lar) { ShadBuf *shb= lar->shb; float wsize, *jitbuf, twozero[2]= {0.0f, 0.0f}, angle, temp; - + if (lar->bufflag & (LA_SHADBUF_AUTO_START|LA_SHADBUF_AUTO_END)) shadowbuf_autoclip(re, lar); - + /* just to enforce identical behavior of all irregular buffers */ if (lar->buftype==LA_SHADBUF_IRREGULAR) shb->size= 1024; - + /* matrices and window: in winmat the transformation is being put, * transforming from observer view to lamp view, including lamp window matrix */ - + angle= saacos(lar->spotsi); temp = 0.5f * shb->size * cosf(angle) / sinf(angle); shb->pixsize= (shb->d)/temp; wsize= shb->pixsize*(shb->size/2.0f); - + perspective_m4(shb->winmat, -wsize, wsize, -wsize, wsize, shb->d, shb->clipend); mul_m4_m4m4(shb->persmat, shb->winmat, shb->viewmat); @@ -791,11 +791,11 @@ void makeshadowbuf(Render *re, LampRen *lar) shb->jit= give_jitter_tab(get_render_shadow_samples(&re->r, shb->samp)); make_jitter_weight_tab(re, shb, lar->filtertype); BLI_thread_unlock(LOCK_CUSTOM1); - + if (shb->totbuf==4) jitbuf= give_jitter_tab(2); else if (shb->totbuf==9) jitbuf= give_jitter_tab(3); else jitbuf= twozero; - + /* zbuffering */ if (lar->buftype == LA_SHADBUF_DEEP) { makedeepshadowbuf(re, lar, jitbuf); @@ -853,7 +853,7 @@ void threaded_makeshadowbufs(Render *re) for (lar=re->lampren.first; lar; lar= lar->next) if (lar->shb) totthread++; - + totthread = min_ii(totthread, re->r.threads); } else @@ -879,7 +879,7 @@ void threaded_makeshadowbufs(Render *re) } BLI_threadpool_init(&threads, do_shadow_thread, totthread); - + for (a=0; ashb; ShadSampleBuf *shsample; int b, v; - + for (shsample= shb->buffers.first; shsample; shsample= shsample->next) { if (shsample->deepbuf) { v= shb->size*shb->size; for (b=0; bdeepbuf[b]) MEM_freeN(shsample->deepbuf[b]); - + MEM_freeN(shsample->deepbuf); MEM_freeN(shsample->totbuf); } else { intptr_t *ztile= shsample->zbuf; const char *ctile= shsample->cbuf; - + v= (shb->size*shb->size)/256; for (b=0; bzbuf); MEM_freeN(shsample->cbuf); } } BLI_freelistN(&shb->buffers); - + if (shb->weight) MEM_freeN(shb->weight); MEM_freeN(lar->shb); - + lar->shb= NULL; } } @@ -966,10 +966,10 @@ static int firstreadshadbuf(ShadBuf *shb, ShadSampleBuf *shsample, int **rz, int return 1; } else if (*rz!= *( (int **)(shsample->zbuf+ofs) )) return 0; - + return 1; } - + return 0; } @@ -989,7 +989,7 @@ static float readdeepvisibility(DeepSample *dsample, int tot, int z, int bias, f *biast= 0.0f; return (ds-1)->v; /* completely behind all samples */ } - + /* check if this read needs bias blending */ if (biast) { if (z > ds->z) @@ -1035,7 +1035,7 @@ static float readdeepshadowbuf(ShadBuf *shb, ShadSampleBuf *shsample, int bias, } /* return 1.0 : fully in light */ -static float readshadowbuf(ShadBuf *shb, ShadSampleBuf *shsample, int bias, int xs, int ys, int zs) +static float readshadowbuf(ShadBuf *shb, ShadSampleBuf *shsample, int bias, int xs, int ys, int zs) { float temp; int *rz, ofs; @@ -1045,7 +1045,7 @@ static float readshadowbuf(ShadBuf *shb, ShadSampleBuf *shsample, int bias, int /* simpleclip */ /* if (xs<0 || ys<0) return 1.0; */ /* if (xs>=shb->size || ys>=shb->size) return 1.0; */ - + /* always test borders of shadowbuffer */ if (xs<0) xs= 0; else if (xs>=shb->size) xs= shb->size-1; if (ys<0) ys= 0; else if (ys>=shb->size) ys= shb->size-1; @@ -1069,7 +1069,7 @@ static float readshadowbuf(ShadBuf *shb, ShadSampleBuf *shsample, int bias, int ct= ((char *)rz); ct+= 4+2*16*(ys & 15)+2*(xs & 15); zsamp= *rz; - + cz= (char *)&zsamp; cz[BCOMP]= ct[0]; cz[GCOMP]= ct[1]; @@ -1090,15 +1090,15 @@ static float readshadowbuf(ShadBuf *shb, ShadSampleBuf *shsample, int bias, int } /* tricky stuff here; we use ints which can overflow easily with bias values */ - + if (zsamp > zs) return 1.0; /* absolute no shadow */ else if (zs < - 0x7FFFFE00 + bias) return 1.0; /* extreme close to clipstart */ else if (zsamp < zs-bias) return 0.0; /* absolute in shadow */ else { /* soft area */ - + temp= ( (float)(zs- zsamp) )/(float)bias; return 1.0f - temp*temp; - + } } @@ -1125,11 +1125,11 @@ float testshadowbuf(Render *re, ShadBuf *shb, const float co[3], const float dxc float xs1, ys1, zs1, *jit, *weight, xres, yres, biasf; int xs, ys, zs, bias, *rz; short a, num; - + /* crash preventer */ if (shb->buffers.first==NULL) return 1.0f; - + /* when facing away, assume fully in shadow */ if (inp <= 0.0f) return 0.0f; @@ -1150,19 +1150,19 @@ float testshadowbuf(Render *re, ShadBuf *shb, const float co[3], const float dxc num= get_render_shadow_samples(&re->r, shb->samp); num= num*num; fac= shb->soft; - + /* compute z bias */ if (mat_bias!=0.0f) biasf= shb->bias*mat_bias; else biasf= shb->bias; - /* with inp==1.0, bias is half the size. correction value was 1.1, giving errors + /* with inp==1.0, bias is half the size. correction value was 1.1, giving errors * on cube edges, with one side being almost frontal lighted (ton) */ bias= (1.5f-inp*inp)*biasf; - + /* in case of no filtering we can do things simpler */ if (num==1) { for (shsample= shb->buffers.first; shsample; shsample= shsample->next) shadfac += readshadowbuf(shb, shsample, bias, (int)xs1, (int)ys1, zs); - + return shadfac/(float)shb->totbuf; } @@ -1176,12 +1176,12 @@ float testshadowbuf(Render *re, ShadBuf *shb, const float co[3], const float dxc shadowbuf_project_co(&dy[0], &dy[1], NULL, shb, dco); dy[0]= xs1 - dy[0]; dy[1]= ys1 - dy[1]; - + xres = fac * (fabsf(dx[0]) + fabsf(dy[0])); yres = fac * (fabsf(dx[1]) + fabsf(dy[1])); if (xres<1.0f) xres= 1.0f; if (yres<1.0f) yres= 1.0f; - + /* make xs1/xs1 corner of sample area */ xs1 -= xres*0.5f; ys1 -= yres*0.5f; @@ -1199,19 +1199,19 @@ float testshadowbuf(Render *re, ShadBuf *shb, const float co[3], const float dxc } } } - + /* full jittered shadow buffer lookup */ for (shsample= shb->buffers.first; shsample; shsample= shsample->next) { jit= shb->jit; weight= shb->weight; - + for (a=num; a>0; a--, jit+=2, weight++) { /* instead of jit i tried random: ugly! */ /* note: the plus 0.5 gives best sampling results, jit goes from -0.5 to 0.5 */ /* xs1 and ys1 are already corrected to be corner of sample area */ xs= xs1 + xres*(jit[0] + 0.5f); ys= ys1 + yres*(jit[1] + 0.5f); - + shadfac+= *weight * readshadowbuf(shb, shsample, bias, xs, ys, zs); } } @@ -1231,7 +1231,7 @@ static float readshadowbuf_halo(ShadBuf *shb, ShadSampleBuf *shsample, int xs, i /* negative! The other side is more important */ bias= -shb->bias; - + /* simpleclip */ if (xs<0 || ys<0) return 0.0; if (xs>=shb->size || ys>=shb->size) return 0.0; @@ -1253,7 +1253,7 @@ static float readshadowbuf_halo(ShadBuf *shb, ShadSampleBuf *shsample, int xs, i ct= ((char *)rz); ct+= 4+2*16*(ys & 15)+2*(xs & 15); zsamp= *rz; - + cz= (char *)&zsamp; cz[BCOMP]= ct[0]; cz[GCOMP]= ct[1]; @@ -1288,7 +1288,7 @@ static float readshadowbuf_halo(ShadBuf *shb, ShadSampleBuf *shsample, int xs, i } /* soft area */ - + temp= ( (float)(zs- zsamp) )/(float)bias; return 1.0f - temp*temp; } @@ -1305,9 +1305,9 @@ float shadow_halo(LampRen *lar, const float p1[3], const float p2[3]) float count, lightcount; int x, y, z, xs1, ys1; int dx = 0, dy = 0; - + siz= 0.5f*(float)shb->size; - + co[0]= p1[0]; co[1]= p1[1]; co[2]= p1[2]/lar->sh_zfac; @@ -1365,7 +1365,7 @@ float shadow_halo(LampRen *lar, const float p1[3], const float p2[3]) lambda_y= 1.0; ldy= 0.0; } - + x= xs1; y= ys1; lambda= count= lightcount= 0.0; @@ -1374,7 +1374,7 @@ float shadow_halo(LampRen *lar, const float p1[3], const float p2[3]) do { lambda_o= lambda; - + if (lambda_x==lambda_y) { lambda_x+= ldx; x+= dx; @@ -1391,7 +1391,7 @@ float shadow_halo(LampRen *lar, const float p1[3], const float p2[3]) y+= dy; } } - + lambda = min_ff(lambda_x, lambda_y); /* not making any progress? */ @@ -1405,21 +1405,21 @@ float shadow_halo(LampRen *lar, const float p1[3], const float p2[3]) if (zf<= -1.0f) lightcount += 1.0f; /* close to the spot */ else { - + /* make sure, behind the clipend we extend halolines. */ if (zf>=1.0f) z= 0x7FFFF000; else z= (int)(0x7FFFF000*zf); - + for (shsample= shb->buffers.first; shsample; shsample= shsample->next) lightcount+= readshadowbuf_halo(shb, shsample, x, y, z); - + } } while (lambda < 1.0f); if (count!=0.0f) return (lightcount/count); return 0.0f; - + } @@ -1461,7 +1461,7 @@ typedef struct BSPFace { int facenr; /* index to retrieve VlakRen */ int type; /* only for strand now */ short shad_alpha, is_full; - + /* strand caching data, optimize for point_behind_strand() */ float radline, radline_end, len; float vec1[3], vec2[3], rc[3]; @@ -1502,25 +1502,25 @@ static void bound_rectf(rctf *box, const float v1[2]) /* halfway splitting, for initializing a more regular tree */ static void isb_bsp_split_init(ISBBranch *root, MemArena *mem, int level) { - + /* if level > 0 we create new branches and go deeper */ if (level > 0) { ISBBranch *left, *right; int i; - + /* splitpoint */ root->divider[0]= 0.5f*(root->box.xmin+root->box.xmax); root->divider[1]= 0.5f*(root->box.ymin+root->box.ymax); - + /* find best splitpoint */ if (RCT_SIZE_X(&root->box) > RCT_SIZE_Y(&root->box)) i = root->index = 0; else i = root->index = 1; - + left= root->left= BLI_memarena_alloc(mem, sizeof(ISBBranch)); right= root->right= BLI_memarena_alloc(mem, sizeof(ISBBranch)); - + /* box info */ left->box= root->box; right->box= root->box; @@ -1556,13 +1556,13 @@ static void isb_bsp_split(ISBBranch *root, MemArena *mem) } root->divider[0]/= BSPMAX_SAMPLE; root->divider[1]/= BSPMAX_SAMPLE; - + /* find best splitpoint */ if (RCT_SIZE_X(&root->box) > RCT_SIZE_Y(&root->box)) i = root->index = 0; else i = root->index = 1; - + /* new branches */ left= root->left= BLI_memarena_alloc(mem, sizeof(ISBBranch)); right= root->right= BLI_memarena_alloc(mem, sizeof(ISBBranch)); @@ -1579,7 +1579,7 @@ static void isb_bsp_split(ISBBranch *root, MemArena *mem) comp= a & 1; else if (root->samples[a]->zco[i] < root->divider[i]) comp= 1; - + if (comp==1) { left->samples[left->totsamp]= root->samples[a]; left->totsamp++; @@ -1589,12 +1589,12 @@ static void isb_bsp_split(ISBBranch *root, MemArena *mem) right->totsamp++; } } - + /* copy samples from tmp */ memcpy(root->samples, samples, right->totsamp*(sizeof(void *))); right->samples= root->samples; root->samples= NULL; - + /* box info */ left->box= root->box; right->box= root->box; @@ -1615,10 +1615,10 @@ static int isb_bsp_insert(ISBBranch *root, MemArena *memarena, ISBSample *sample ISBBranch *bspn= root; const float *zco= sample->zco; int i= 0; - + /* debug counter, also used to check if something was filled in ever */ root->totsamp++; - + /* going over branches until last one found */ while (bspn->left) { if (zco[bspn->index] <= bspn->divider[bspn->index]) @@ -1628,12 +1628,12 @@ static int isb_bsp_insert(ISBBranch *root, MemArena *memarena, ISBSample *sample i++; } /* bspn now is the last branch */ - + if (bspn->totsamp==BSPMAX_SAMPLE) { printf("error in bsp branch\n"); /* only for debug, cannot happen */ return 1; } - + /* insert */ bspn->samples[bspn->totsamp]= sample; bspn->totsamp++; @@ -1650,23 +1650,23 @@ static int isb_bsp_insert(ISBBranch *root, MemArena *memarena, ISBSample *sample } /* initialize vars in face, for optimal point-in-face test */ -static void bspface_init_strand(BSPFace *face) +static void bspface_init_strand(BSPFace *face) { - + face->radline= 0.5f* len_v2v2(face->v1, face->v2); - + mid_v3_v3v3(face->vec1, face->v1, face->v2); if (face->v4) mid_v3_v3v3(face->vec2, face->v3, face->v4); else copy_v3_v3(face->vec2, face->v3); - + face->rc[0]= face->vec2[0]-face->vec1[0]; face->rc[1]= face->vec2[1]-face->vec1[1]; face->rc[2]= face->vec2[2]-face->vec1[2]; - + face->len= face->rc[0]*face->rc[0]+ face->rc[1]*face->rc[1]; - + if (face->len != 0.0f) { face->radline_end = face->radline / sqrtf(face->len); face->len = 1.0f / face->len; @@ -1678,31 +1678,31 @@ static int point_behind_strand(const float p[3], BSPFace *face) { /* v1 - v2 is radius, v1 - v3 length */ float dist, rc[2], pt[2]; - + /* using code from dist_to_line_segment_v2(), distance vec to line-piece */ if (face->len==0.0f) { rc[0]= p[0]-face->vec1[0]; rc[1]= p[1]-face->vec1[1]; dist = len_v2(rc); - + if (dist < face->radline) return 1; } else { float lambda= ( face->rc[0]*(p[0]-face->vec1[0]) + face->rc[1]*(p[1]-face->vec1[1]) )*face->len; - + if (lambda > -face->radline_end && lambda < 1.0f+face->radline_end) { /* hesse for dist: */ //dist= (float)(fabs( (p[0]-vec2[0])*rc[1] + (p[1]-vec2[1])*rc[0])/len); - + pt[0]= lambda*face->rc[0]+face->vec1[0]; pt[1]= lambda*face->rc[1]+face->vec1[1]; rc[0]= pt[0]-p[0]; rc[1]= pt[1]-p[1]; dist = len_v2(rc); - + if (dist < face->radline) { float zval= face->vec1[2] + lambda*face->rc[2]; if (p[2] > zval) @@ -1719,21 +1719,21 @@ static int point_behind_tria2d(const float p[3], const float v1[3], const float { float a[2], c[2], h[2], div; float u, v; - + a[0] = v2[0] - v1[0]; a[1] = v2[1] - v1[1]; c[0] = v3[0] - v1[0]; c[1] = v3[1] - v1[1]; - + div = a[0]*c[1] - a[1]*c[0]; if (div==0.0f) return 0; - + h[0] = p[0] - v1[0]; h[1] = p[1] - v1[1]; - + div = 1.0f/div; - + u = (h[0]*c[1] - h[1]*c[0])*div; if (u >= 0.0f) { v = (a[0]*h[1] - a[1]*h[0])*div; @@ -1746,7 +1746,7 @@ static int point_behind_tria2d(const float p[3], const float v1[3], const float } } } - + return 0; } @@ -1758,13 +1758,13 @@ static int rect_outside_line(rctf *rect, const float v1[3], const float v2[3], c { float a, b, c; int side; - + /* line formula for v1-v2 */ a= v2[1]-v1[1]; b= v1[0]-v2[0]; c= -a*v1[0] - b*v1[1]; side= a*v3[0] + b*v3[1] + c < 0.0f; - + /* the four quad points */ if ( side==(rect->xmin*a + rect->ymin*b + c >= 0.0f) ) if ( side==(rect->xmax*a + rect->ymin*b + c >= 0.0f) ) @@ -1790,7 +1790,7 @@ static int rect_isect_tria(rctf *rect, const float v1[3], const float v2[3], con /* if face overlaps a branch, it executes func. recursive */ static void isb_bsp_face_inside(ISBBranch *bspn, BSPFace *face) { - + /* are we descending? */ if (bspn->left) { /* hrmf, the box struct cannot be addressed with index */ @@ -1810,30 +1810,30 @@ static void isb_bsp_face_inside(ISBBranch *bspn, BSPFace *face) else { /* else: end branch reached */ int a; - + if (bspn->totsamp==0) return; - + /* check for nodes entirely in shadow, can be skipped */ if (bspn->totsamp==bspn->full) return; - + /* if bsp node is entirely in front of face, give up */ if (bspn->box.zmax < face->box.zmin) return; - + /* if face boundbox is outside of branch rect, give up */ if (0==BLI_rctf_isect((rctf *)&face->box, (rctf *)&bspn->box, NULL)) return; - + /* test all points inside branch */ for (a=bspn->totsamp-1; a>=0; a--) { ISBSample *samp= bspn->samples[a]; - + if ((samp->facenr!=face->facenr || samp->obi!=face->obi) && samp->shadfac) { if (face->box.zmin < samp->zco[2]) { if (BLI_rctf_isect_pt_v((rctf *)&face->box, samp->zco)) { int inshadow= 0; - + if (face->type) { if (point_behind_strand(samp->zco, face)) inshadow= 1; @@ -1867,7 +1867,7 @@ static void isb_bsp_recalc_box(ISBBranch *root) } else if (root->totsamp) { int a; - + init_box(&root->box); for (a=root->totsamp-1; a>=0; a--) bound_boxf(&root->box, root->samples[a]->zco); @@ -1879,7 +1879,7 @@ static void isb_bsp_test_strand(ZSpan *zspan, int obi, int zvlnr, const float *v1, const float *v2, const float *v3, const float *v4) { BSPFace face; - + face.v1= v1; face.v2= v2; face.v3= v3; @@ -1891,9 +1891,9 @@ static void isb_bsp_test_strand(ZSpan *zspan, int obi, int zvlnr, face.shad_alpha= (short)ceil(4096.0f*zspan->shad_alpha/(float)R.osa); else face.shad_alpha= (short)ceil(4096.0f*zspan->shad_alpha); - + face.is_full= (zspan->shad_alpha==1.0f); - + /* setup boundbox */ init_box(&face.box); bound_boxf(&face.box, v1); @@ -1901,12 +1901,12 @@ static void isb_bsp_test_strand(ZSpan *zspan, int obi, int zvlnr, bound_boxf(&face.box, v3); if (v4) bound_boxf(&face.box, v4); - + /* optimize values */ bspface_init_strand(&face); - + isb_bsp_face_inside((ISBBranch *)zspan->rectz, &face); - + } /* callback function for zbuf clip */ @@ -1914,7 +1914,7 @@ static void isb_bsp_test_face(ZSpan *zspan, int obi, int zvlnr, const float *v1, const float *v2, const float *v3, const float *v4) { BSPFace face; - + face.v1= v1; face.v2= v2; face.v3= v3; @@ -1926,9 +1926,9 @@ static void isb_bsp_test_face(ZSpan *zspan, int obi, int zvlnr, face.shad_alpha= (short)ceil(4096.0f*zspan->shad_alpha/(float)R.osa); else face.shad_alpha= (short)ceil(4096.0f*zspan->shad_alpha); - + face.is_full= (zspan->shad_alpha==1.0f); - + /* setup boundbox */ init_box(&face.box); bound_boxf(&face.box, v1); @@ -1944,13 +1944,13 @@ static int testclip_minmax(const float ho[4], const float minmax[4]) { float wco= ho[3]; int flag= 0; - + if ( ho[0] > minmax[1]*wco) flag = 1; else if ( ho[0]< minmax[0]*wco) flag = 2; - + if ( ho[1] > minmax[3]*wco) flag |= 4; else if ( ho[1]< minmax[2]*wco) flag |= 8; - + return flag; } @@ -1966,35 +1966,35 @@ static void isb_bsp_fillfaces(Render *re, LampRen *lar, ISBBranch *root) float minmaxf[4], winmat[4][4]; int size= shb->size; int i, a, ok=1, lay= -1; - + /* further optimize, also sets minz maxz */ isb_bsp_recalc_box(root); - + /* extra clipping for minmax */ minmaxf[0]= (2.0f*root->box.xmin - size-2.0f)/size; minmaxf[1]= (2.0f*root->box.xmax - size+2.0f)/size; minmaxf[2]= (2.0f*root->box.ymin - size-2.0f)/size; minmaxf[3]= (2.0f*root->box.ymax - size+2.0f)/size; - + if (lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) lay= lar->lay; - + /* (ab)use zspan, since we use zbuffer clipping code */ zbuf_alloc_span(&zspan, size, size, re->clipcrop); - + zspan.zmulx= ((float)size)/2.0f; zspan.zmuly= ((float)size)/2.0f; zspan.zofsx= -0.5f; zspan.zofsy= -0.5f; - + /* pass on bsp root to zspan */ zspan.rectz= (int *)root; - + /* filling methods */ zspanstrand= zspan; // zspan.zbuflinefunc= zbufline_onlyZ; zspan.zbuffunc= isb_bsp_test_face; zspanstrand.zbuffunc= isb_bsp_test_strand; - + for (i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) { obr= obi->obr; @@ -2004,10 +2004,10 @@ static void isb_bsp_fillfaces(Render *re, LampRen *lar, ISBBranch *root) copy_m4_m4(winmat, shb->persmat); for (a=0; atotvlak; a++) { - + if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; else vlr++; - + /* note, these conditions are copied in shadowbuf_autoclip() */ if (vlr->mat!= ma) { ma= vlr->mat; @@ -2016,13 +2016,13 @@ static void isb_bsp_fillfaces(Render *re, LampRen *lar, ISBBranch *root) if (ma->material_type == MA_TYPE_WIRE) ok= 0; zspanstrand.shad_alpha= zspan.shad_alpha= ma->shad_alpha; } - + if (ok && (obi->lay & lay)) { float hoco[4][4]; int c1, c2, c3, c4=0; int d1, d2, d3, d4=0; int partclip; - + /* create hocos per face, it is while render */ projectvert(vlr->v1->co, winmat, hoco[0]); d1= testclip_minmax(hoco[0], minmaxf); projectvert(vlr->v2->co, winmat, hoco[1]); d2= testclip_minmax(hoco[1], minmaxf); @@ -2034,16 +2034,16 @@ static void isb_bsp_fillfaces(Render *re, LampRen *lar, ISBBranch *root) /* minmax clipping */ if (vlr->v4) partclip= d1 & d2 & d3 & d4; else partclip= d1 & d2 & d3; - + if (partclip==0) { - + /* window clipping */ - c1= testclip(hoco[0]); - c2= testclip(hoco[1]); - c3= testclip(hoco[2]); + c1= testclip(hoco[0]); + c2= testclip(hoco[1]); + c3= testclip(hoco[2]); if (vlr->v4) - c4= testclip(hoco[3]); - + c4= testclip(hoco[3]); + /* ***** NO WIRE YET */ if (ma->material_type == MA_TYPE_WIRE) { if (vlr->v4) @@ -2059,12 +2059,12 @@ static void isb_bsp_fillfaces(Render *re, LampRen *lar, ISBBranch *root) } else zbufclip(&zspan, i, a+1, hoco[0], hoco[1], hoco[2], c1, c2, c3); - + } } } } - + zbuf_free_span(&zspan); } @@ -2073,7 +2073,7 @@ static int viewpixel_to_lampbuf(ShadBuf *shb, ObjectInstanceRen *obi, VlakRen *v { float hoco[4], v1[3], nor[3]; float dface, fac, siz; - + RE_vlakren_get_normal(&R, obi, vlr, nor); copy_v3_v3(v1, vlr->v1->co); if (obi->flag & R_TRANSFORMED) @@ -2082,16 +2082,16 @@ static int viewpixel_to_lampbuf(ShadBuf *shb, ObjectInstanceRen *obi, VlakRen *v /* from shadepixel() */ dface = dot_v3v3(v1, nor); hoco[3]= 1.0f; - + /* ortho viewplane cannot intersect using view vector originating in (0, 0, 0) */ if (R.r.mode & R_ORTHO) { /* x and y 3d coordinate can be derived from pixel coord and winmat */ float fx= 2.0f/(R.winx*R.winmat[0][0]); float fy= 2.0f/(R.winy*R.winmat[1][1]); - + hoco[0]= (x - 0.5f*R.winx)*fx - R.winmat[3][0]/R.winmat[0][0]; hoco[1]= (y - 0.5f*R.winy)*fy - R.winmat[3][1]/R.winmat[1][1]; - + /* using a*x + b*y + c*z = d equation, (a b c) is normal */ if (nor[2]!=0.0f) hoco[2]= (dface - nor[0]*hoco[0] - nor[1]*hoco[1])/nor[2]; @@ -2100,23 +2100,23 @@ static int viewpixel_to_lampbuf(ShadBuf *shb, ObjectInstanceRen *obi, VlakRen *v } else { float div, view[3]; - + calc_view_vector(view, x, y); - + div = dot_v3v3(nor, view); - if (div==0.0f) + if (div==0.0f) return 0; - + fac= dface/div; - + hoco[0]= fac*view[0]; hoco[1]= fac*view[1]; hoco[2]= fac*view[2]; } - + /* move 3d vector to lampbuf */ mul_m4_v4(shb->persmat, hoco); /* rational hom co */ - + /* clip We can test for -1.0/1.0 because of the properties of the * coordinate transformations. */ fac = fabsf(hoco[3]); @@ -2126,15 +2126,15 @@ static int viewpixel_to_lampbuf(ShadBuf *shb, ObjectInstanceRen *obi, VlakRen *v return 0; if (hoco[2]<-fac || hoco[2]>fac) return 0; - + siz= 0.5f*(float)shb->size; co_r[0]= siz*(1.0f+hoco[0]/hoco[3]) -0.5f; co_r[1]= siz*(1.0f+hoco[1]/hoco[3]) -0.5f; co_r[2]= ((float)0x7FFFFFFF)*(hoco[2]/hoco[3]); - + /* XXXX bias, much less than normal shadbuf, or do we need a constant? */ co_r[2] -= 0.05f*shb->bias; - + return 1; } @@ -2143,13 +2143,13 @@ static void isb_add_shadfac(ISBShadfacA **isbsapp, MemArena *mem, int obi, int f { ISBShadfacA *new; float shadfacf; - + /* in osa case, the samples were filled in with factor 1.0/R.osa. if fewer samples we have to correct */ if (R.osa) shadfacf= ((float)shadfac*R.osa)/(4096.0f*samples); else shadfacf= ((float)shadfac)/(4096.0f); - + new= BLI_memarena_alloc(mem, sizeof(ISBShadfacA)); new->obi= obi; new->facenr= facenr & ~RE_QUAD_OFFS; @@ -2158,7 +2158,7 @@ static void isb_add_shadfac(ISBShadfacA **isbsapp, MemArena *mem, int obi, int f new->next= (*isbsapp); else new->next= NULL; - + *isbsapp= new; } @@ -2167,7 +2167,7 @@ static int isb_add_samples(RenderPart *pa, ISBBranch *root, MemArena *memarena, { int xi, yi, *xcos, *ycos; int sample, bsp_err= 0; - + /* bsp split doesn't like to handle regular sequences */ xcos= MEM_mallocN(pa->rectx*sizeof(int), "xcos"); ycos= MEM_mallocN(pa->recty*sizeof(int), "ycos"); @@ -2177,10 +2177,10 @@ static int isb_add_samples(RenderPart *pa, ISBBranch *root, MemArena *memarena, ycos[yi]= yi; BLI_array_randomize(xcos, sizeof(int), pa->rectx, 12345); BLI_array_randomize(ycos, sizeof(int), pa->recty, 54321); - + for (sample=0; sample<(R.osa?R.osa:1); sample++) { ISBSample *samp= samplebuf[sample], *samp1; - + for (yi=0; yirecty; yi++) { int y= ycos[yi]; for (xi=0; xirectx; xi++) { @@ -2192,7 +2192,7 @@ static int isb_add_samples(RenderPart *pa, ISBBranch *root, MemArena *memarena, if (bsp_err) break; } } - + MEM_freeN(xcos); MEM_freeN(ycos); @@ -2210,37 +2210,37 @@ static void isb_make_buffer(RenderPart *pa, LampRen *lar) MemArena *memarena; intptr_t *rd; int *recto, *rectp, x, y, sindex, sample, bsp_err=0; - + /* storage for shadow, per thread */ isbdata= shb->isb_result[pa->thread]; - + /* to map the shi->xs and ys coordinate */ isbdata->minx= pa->disprect.xmin; isbdata->miny= pa->disprect.ymin; isbdata->rectx= pa->rectx; isbdata->recty= pa->recty; - + /* branches are added using memarena (32k branches) */ memarena = BLI_memarena_new(0x8000 * sizeof(ISBBranch), "isb arena"); BLI_memarena_use_calloc(memarena); - + /* samplebuf is in camera view space (pixels) */ for (sample=0; sample<(R.osa?R.osa:1); sample++) samplebuf[sample]= MEM_callocN(sizeof(ISBSample)*pa->rectx*pa->recty, "isb samplebuf"); - + /* for end result, ISBSamples point to this in non OSA case, otherwise to pixstruct->shadfac */ if (R.osa==0) isbdata->shadfacs= MEM_callocN(pa->rectx*pa->recty*sizeof(short), "isb shadfacs"); - + /* setup bsp root */ memset(&root, 0, sizeof(ISBBranch)); root.box.xmin = (float)shb->size; root.box.ymin = (float)shb->size; - + /* create the sample buffers */ for (sindex=0, y=0; yrecty; y++) { for (x=0; xrectx; x++, sindex++) { - + /* this makes it a long function, but splitting it out would mean 10+ arguments */ /* first check OSA case */ if (R.osa) { @@ -2248,11 +2248,11 @@ static void isb_make_buffer(RenderPart *pa, LampRen *lar) if (*rd) { float xs= (float)(x + pa->disprect.xmin); float ys= (float)(y + pa->disprect.ymin); - + for (sample=0; samplemask & mask) break; @@ -2262,7 +2262,7 @@ static void isb_make_buffer(RenderPart *pa, LampRen *lar) ObjectInstanceRen *obi= &R.objectinstance[ps->obi]; ObjectRen *obr= obi->obr; VlakRen *vlr= RE_findOrAddVlak(obr, (ps->facenr-1) & RE_QUAD_MASK); - + samp= samplebuf[sample] + sindex; /* convert image plane pixel location to lamp buffer space */ if (viewpixel_to_lampbuf(shb, obi, vlr, xs + R.jit[sample][0], ys + R.jit[sample][1], samp->zco)) { @@ -2285,7 +2285,7 @@ static void isb_make_buffer(RenderPart *pa, LampRen *lar) VlakRen *vlr= RE_findOrAddVlak(obr, (*rectp-1) & RE_QUAD_MASK); float xs= (float)(x + pa->disprect.xmin); float ys= (float)(y + pa->disprect.ymin); - + samp= samplebuf[0] + sindex; /* convert image plane pixel location to lamp buffer space */ if (viewpixel_to_lampbuf(shb, obi, vlr, xs, ys, samp->zco)) { @@ -2298,30 +2298,30 @@ static void isb_make_buffer(RenderPart *pa, LampRen *lar) } } } - + /* simple method to see if we have samples */ if (root.box.xmin != (float)shb->size) { /* now create a regular split, root.box has the initial bounding box of all pixels */ /* split bsp 8 levels deep, in regular grid (16 x 16) */ isb_bsp_split_init(&root, memarena, 8); - + /* insert all samples in BSP now */ bsp_err= isb_add_samples(pa, &root, memarena, samplebuf); - + if (bsp_err==0) { /* go over all faces and fill in shadow values */ - + isb_bsp_fillfaces(&R, lar, &root); /* shb->persmat should have been calculated */ - + /* copy shadow samples to persistent buffer, reduce memory overhead */ if (R.osa) { ISBShadfacA **isbsa= isbdata->shadfaca= MEM_callocN(pa->rectx*pa->recty*sizeof(void *), "isb shadfacs"); - + isbdata->memarena = BLI_memarena_new(0x8000 * sizeof(ISBSampleA), "isb arena"); BLI_memarena_use_calloc(isbdata->memarena); for (rd= pa->rectdaps, x=pa->rectx*pa->recty; x>0; x--, rd++, isbsa++) { - + if (*rd) { PixStr *ps= (PixStr *)(*rd); while (ps) { @@ -2343,11 +2343,11 @@ static void isb_make_buffer(RenderPart *pa, LampRen *lar) /* free BSP */ BLI_memarena_free(memarena); - + /* free samples */ for (x=0; x<(R.osa?R.osa:1); x++) MEM_freeN(samplebuf[x]); - + if (bsp_err) printf("error in filling bsp\n"); } @@ -2355,13 +2355,13 @@ static void isb_make_buffer(RenderPart *pa, LampRen *lar) static ISBSampleA *isb_alloc_sample_transp(ISBSampleA **isbsa, MemArena *mem) { ISBSampleA *new; - + new= BLI_memarena_alloc(mem, sizeof(ISBSampleA)); if (*isbsa) new->next= (*isbsa); else new->next= NULL; - + *isbsa= new; return new; } @@ -2371,7 +2371,7 @@ static int isb_add_samples_transp(RenderPart *pa, ISBBranch *root, MemArena *mem { int xi, yi, *xcos, *ycos; int sample, bsp_err= 0; - + /* bsp split doesn't like to handle regular sequences */ xcos= MEM_mallocN(pa->rectx*sizeof(int), "xcos"); ycos= MEM_mallocN(pa->recty*sizeof(int), "ycos"); @@ -2381,15 +2381,15 @@ static int isb_add_samples_transp(RenderPart *pa, ISBBranch *root, MemArena *mem ycos[yi]= yi; BLI_array_randomize(xcos, sizeof(int), pa->rectx, 12345); BLI_array_randomize(ycos, sizeof(int), pa->recty, 54321); - + for (sample=0; sample<(R.osa?R.osa:1); sample++) { ISBSampleA **samp= samplebuf[sample], *samp1; - + for (yi=0; yirecty; yi++) { int y= ycos[yi]; for (xi=0; xirectx; xi++) { int x= xcos[xi]; - + samp1= *(samp + y*pa->rectx + x); while (samp1) { bsp_err |= isb_bsp_insert(root, memarena, (ISBSample *)samp1); @@ -2399,10 +2399,10 @@ static int isb_add_samples_transp(RenderPart *pa, ISBBranch *root, MemArena *mem if (bsp_err) break; } } - + MEM_freeN(xcos); MEM_freeN(ycos); - + return bsp_err; } @@ -2418,24 +2418,24 @@ static void isb_make_buffer_transp(RenderPart *pa, APixstr *apixbuf, LampRen *la MemArena *memarena; APixstr *ap; int x, y, sindex, sample, bsp_err=0; - + /* storage for shadow, per thread */ isbdata= shb->isb_result[pa->thread]; - + /* to map the shi->xs and ys coordinate */ isbdata->minx= pa->disprect.xmin; isbdata->miny= pa->disprect.ymin; isbdata->rectx= pa->rectx; isbdata->recty= pa->recty; - + /* branches are added using memarena (32k branches) */ memarena = BLI_memarena_new(0x8000 * sizeof(ISBBranch), "isb arena"); BLI_memarena_use_calloc(memarena); - + /* samplebuf is in camera view space (pixels) */ for (sample=0; sample<(R.osa?R.osa:1); sample++) samplebuf[sample]= MEM_callocN(sizeof(void *)*pa->rectx*pa->recty, "isb alpha samplebuf"); - + /* setup bsp root */ memset(&root, 0, sizeof(ISBBranch)); root.box.xmin = (float)shb->size; @@ -2444,12 +2444,12 @@ static void isb_make_buffer_transp(RenderPart *pa, APixstr *apixbuf, LampRen *la /* create the sample buffers */ for (ap= apixbuf, sindex=0, y=0; yrecty; y++) { for (x=0; xrectx; x++, sindex++, ap++) { - + if (ap->p[0]) { APixstr *apn; float xs= (float)(x + pa->disprect.xmin); float ys= (float)(y + pa->disprect.ymin); - + for (apn=ap; apn; apn= apn->next) { int a; for (a=0; a<4; a++) { @@ -2458,23 +2458,23 @@ static void isb_make_buffer_transp(RenderPart *pa, APixstr *apixbuf, LampRen *la ObjectRen *obr= obi->obr; VlakRen *vlr= RE_findOrAddVlak(obr, (apn->p[a]-1) & RE_QUAD_MASK); float zco[3]; - + /* here we store shadfac, easier to create the end storage buffer. needs zero'ed, multiple shadowbufs use it */ apn->shadfac[a]= 0; - + if (R.osa) { for (sample=0; samplemask[a] & mask) { - + /* convert image plane pixel location to lamp buffer space */ if (viewpixel_to_lampbuf(shb, obi, vlr, xs + R.jit[sample][0], ys + R.jit[sample][1], zco)) { samp= isb_alloc_sample_transp(samplebuf[sample] + sindex, memarena); samp->obi= apn->obi[a]; samp->facenr= apn->p[a] & ~RE_QUAD_OFFS; samp->shadfac= &apn->shadfac[a]; - + copy_v3_v3(samp->zco, zco); bound_rectf((rctf *)&root.box, samp->zco); } @@ -2482,15 +2482,15 @@ static void isb_make_buffer_transp(RenderPart *pa, APixstr *apixbuf, LampRen *la } } else { - + /* convert image plane pixel location to lamp buffer space */ if (viewpixel_to_lampbuf(shb, obi, vlr, xs, ys, zco)) { - + samp= isb_alloc_sample_transp(samplebuf[0] + sindex, memarena); samp->obi= apn->obi[a]; samp->facenr= apn->p[a] & ~RE_QUAD_OFFS; samp->shadfac= &apn->shadfac[a]; - + copy_v3_v3(samp->zco, zco); bound_rectf((rctf *)&root.box, samp->zco); } @@ -2501,29 +2501,29 @@ static void isb_make_buffer_transp(RenderPart *pa, APixstr *apixbuf, LampRen *la } } } - + /* simple method to see if we have samples */ if (root.box.xmin != (float)shb->size) { /* now create a regular split, root.box has the initial bounding box of all pixels */ /* split bsp 8 levels deep, in regular grid (16 x 16) */ isb_bsp_split_init(&root, memarena, 8); - + /* insert all samples in BSP now */ bsp_err= isb_add_samples_transp(pa, &root, memarena, samplebuf); - + if (bsp_err==0) { ISBShadfacA **isbsa; - + /* go over all faces and fill in shadow values */ isb_bsp_fillfaces(&R, lar, &root); /* shb->persmat should have been calculated */ - + /* copy shadow samples to persistent buffer, reduce memory overhead */ isbsa= isbdata->shadfaca= MEM_callocN(pa->rectx*pa->recty*sizeof(void *), "isb shadfacs"); - + isbdata->memarena = BLI_memarena_new(0x8000 * sizeof(ISBSampleA), "isb arena"); - + for (ap= apixbuf, x=pa->rectx*pa->recty; x>0; x--, ap++, isbsa++) { - + if (ap->p[0]) { APixstr *apn; for (apn=ap; apn; apn= apn->next) { @@ -2563,14 +2563,14 @@ float ISB_getshadow(ShadeInput *shi, ShadBuf *shb) /* if raytracing, we can't accept irregular shadow */ if (shi->depth==0) { ISBData *isbdata= shb->isb_result[shi->thread]; - + if (isbdata) { if (isbdata->shadfacs || isbdata->shadfaca) { int x= shi->xs - isbdata->minx; - + if (x >= 0 && x < isbdata->rectx) { int y= shi->ys - isbdata->miny; - + if (y >= 0 && y < isbdata->recty) { if (isbdata->shadfacs) { const short *sp= isbdata->shadfacs + y*isbdata->rectx + x; @@ -2580,7 +2580,7 @@ float ISB_getshadow(ShadeInput *shi, ShadBuf *shb) int sindex= y*isbdata->rectx + x; int obi= shi->obi - R.objectinstance; ISBShadfacA *isbsa= *(isbdata->shadfaca + sindex); - + while (isbsa) { if (isbsa->facenr==shi->facenr+1 && isbsa->obi==obi) return isbsa->shadfac>=1.0f?0.0f:1.0f - isbsa->shadfac; @@ -2599,16 +2599,16 @@ float ISB_getshadow(ShadeInput *shi, ShadBuf *shb) void ISB_create(RenderPart *pa, APixstr *apixbuf) { GroupObject *go; - + /* go over all lamps, and make the irregular buffers */ for (go=R.lights.first; go; go= go->next) { LampRen *lar= go->lampren; - + if (lar->type==LA_SPOT && lar->shb && lar->buftype==LA_SHADBUF_IRREGULAR) { - + /* create storage for shadow, per thread */ lar->shb->isb_result[pa->thread]= MEM_callocN(sizeof(ISBData), "isb data"); - + if (apixbuf) isb_make_buffer_transp(pa, apixbuf, lar); else @@ -2622,11 +2622,11 @@ void ISB_create(RenderPart *pa, APixstr *apixbuf) void ISB_free(RenderPart *pa) { GroupObject *go; - + /* go over all lamps, and free the irregular buffers */ for (go=R.lights.first; go; go= go->next) { LampRen *lar= go->lampren; - + if (lar->type==LA_SPOT && lar->shb && lar->buftype==LA_SHADBUF_IRREGULAR) { ISBData *isbdata= lar->shb->isb_result[pa->thread]; @@ -2635,10 +2635,10 @@ void ISB_free(RenderPart *pa) MEM_freeN(isbdata->shadfacs); if (isbdata->shadfaca) MEM_freeN(isbdata->shadfaca); - + if (isbdata->memarena) BLI_memarena_free(isbdata->memarena); - + MEM_freeN(isbdata); lar->shb->isb_result[pa->thread]= NULL; } diff --git a/source/blender/render/intern/source/shadeinput.c b/source/blender/render/intern/source/shadeinput.c index b4ff5f52fcf..d79749871c3 100644 --- a/source/blender/render/intern/source/shadeinput.c +++ b/source/blender/render/intern/source/shadeinput.c @@ -82,7 +82,7 @@ extern struct Render R; * */ -/* initialize material variables in shadeinput, +/* initialize material variables in shadeinput, * doing inverse gamma correction where applicable */ void shade_input_init_material(ShadeInput *shi) { @@ -97,11 +97,11 @@ void shade_material_loop(ShadeInput *shi, ShadeResult *shr) { shade_lamp_loop(shi, shr); /* clears shr */ - + if (shi->translucency != 0.0f) { ShadeResult shr_t; float fac = shi->translucency; - + shade_input_init_material(shi); negate_v3_v3(shi->vn, shi->vno); negate_v3(shi->facenor); @@ -123,7 +123,7 @@ void shade_material_loop(ShadeInput *shi, ShadeResult *shr) negate_v3(shi->vn); negate_v3(shi->facenor); } - + /* depth >= 1 when ray-shading */ if (shi->depth == 0 || shi->volume_depth > 0) { if (R.r.mode & R_RAYTRACE) { @@ -137,7 +137,7 @@ void shade_material_loop(ShadeInput *shi, ShadeResult *shr) if ((shi->layflag & SCE_LAY_SKY) && (R.r.alphamode == R_ADDSKY)) shr->alpha = 1.0f; } - + if (R.r.mode & R_RAYTRACE) { if (R.render_volumes_inside.first) shade_volume_inside(shi, shr); @@ -150,12 +150,12 @@ void shade_input_do_shade(ShadeInput *shi, ShadeResult *shr) { bool compat = false; float alpha; - + /* ------ main shading loop -------- */ #ifdef RE_RAYCOUNTER memset(&shi->raycounter, 0, sizeof(shi->raycounter)); #endif - + if (shi->mat->nodetree && shi->mat->use_nodes) { compat = ntreeShaderExecTree(shi->mat->nodetree, shi, shr); } @@ -164,7 +164,7 @@ void shade_input_do_shade(ShadeInput *shi, ShadeResult *shr) if (compat == false) { /* copy all relevant material vars, note, keep this synced with render_types.h */ shade_input_init_material(shi); - + if (shi->mat->material_type == MA_TYPE_VOLUME) { if (R.r.mode & R_RAYTRACE) { shade_volume_outside(shi, shr); @@ -174,13 +174,13 @@ void shade_input_do_shade(ShadeInput *shi, ShadeResult *shr) shade_material_loop(shi, shr); } } - + /* copy additional passes */ if (shi->passflag & (SCE_PASS_VECTOR | SCE_PASS_NORMAL)) { copy_v4_v4(shr->winspeed, shi->winspeed); copy_v3_v3(shr->nor, shi->vn); } - + /* MIST */ if ((shi->passflag & SCE_PASS_MIST) || ((R.wrld.mode & WO_MIST) && (shi->mat->mode & MA_NOMIST) == 0)) { if (R.r.mode & R_ORTHO) @@ -189,26 +189,26 @@ void shade_input_do_shade(ShadeInput *shi, ShadeResult *shr) shr->mist = mistfactor(len_v3(shi->co), shi->co); } else shr->mist = 0.0f; - + if ((R.wrld.mode & WO_MIST) && (shi->mat->mode & MA_NOMIST) == 0) { alpha = shr->mist; } else alpha = 1.0f; - + /* add mist and premul color */ if (shr->alpha != 1.0f || alpha != 1.0f) { float fac = alpha * (shr->alpha); shr->combined[3] = fac; - + if (shi->mat->material_type != MA_TYPE_VOLUME) mul_v3_fl(shr->combined, fac); } else shr->combined[3] = 1.0f; - + /* add z */ shr->z = -shi->co[2]; - + /* RAYHITS */ #if 0 if (1 || shi->passflag & SCE_PASS_RAYHITS) { @@ -234,7 +234,7 @@ void vlr_set_uv_indices(VlakRen *vlr, int *i1, int *i2, int *i3) /* |\ 1| or |1 /| */ /* |0\ | |/ 0| */ /* 1---2 1---2 0 = orig face, 1 = new face */ - + /* Update vert nums to point to correct verts of original face */ if (vlr->flag & R_DIVIDE_24) { if (vlr->flag & R_FACE_SPLIT) { @@ -245,7 +245,7 @@ void vlr_set_uv_indices(VlakRen *vlr, int *i1, int *i2, int *i3) } } else if (vlr->flag & R_FACE_SPLIT) { - (*i2)++; (*i3)++; + (*i2)++; (*i3)++; } } @@ -254,7 +254,7 @@ void vlr_set_uv_indices(VlakRen *vlr, int *i1, int *i2, int *i3) void shade_input_set_triangle_i(ShadeInput *shi, ObjectInstanceRen *obi, VlakRen *vlr, short i1, short i2, short i3) { VertRen **vpp = &vlr->v1; - + shi->vlr = vlr; shi->obi = obi; shi->obr = obi->obr; @@ -266,10 +266,10 @@ void shade_input_set_triangle_i(ShadeInput *shi, ObjectInstanceRen *obi, VlakRen shi->i1 = i1; shi->i2 = i2; shi->i3 = i3; - + /* note, shi->mat is set in node shaders */ shi->mat = shi->mat_override ? shi->mat_override : vlr->mat; - + shi->osatex = (shi->mat->texco & TEXCO_OSA); shi->mode = shi->mat->mode_l; /* or-ed result for all nodes */ shi->mode2 = shi->mat->mode2_l; @@ -277,7 +277,7 @@ void shade_input_set_triangle_i(ShadeInput *shi, ObjectInstanceRen *obi, VlakRen /* facenormal copy, can get flipped */ shi->flippednor = 0; RE_vlakren_get_normal(&R, obi, vlr, shi->facenor); - + /* calculate vertexnormals */ if (vlr->flag & R_SMOOTH) { copy_v3_v3(shi->n1, shi->v1->n); @@ -301,7 +301,7 @@ void shade_input_set_triangle(ShadeInput *shi, int obi, int facenr, int UNUSED(n shi->facenr = (facenr - 1) & RE_QUAD_MASK; if (shi->facenr < shi->obr->totvlak) { VlakRen *vlr = RE_findOrAddVlak(shi->obr, shi->facenr); - + if (facenr & RE_QUAD_OFFS) shade_input_set_triangle_i(shi, shi->obi, vlr, 0, 2, 3); else @@ -326,7 +326,7 @@ void shade_input_set_strand(ShadeInput *shi, StrandRen *strand, StrandPoint *spo { /* note, shi->mat is set in node shaders */ shi->mat = shi->mat_override ? shi->mat_override : strand->buffer->ma; - + shi->osatex = (shi->mat->texco & TEXCO_OSA); shi->mode = shi->mat->mode_l; /* or-ed result for all nodes */ @@ -405,7 +405,7 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert if (R.r.mode & R_SPEED) { const float *speed; - + speed = RE_strandren_get_winspeed(shi->obi, strand, 0); if (speed) copy_v4_v4(shi->winspeed, speed); @@ -422,7 +422,7 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert if (texco & TEXCO_GLOB) { mul_v3_m4v3(shi->gl, R.viewinv, shi->co); - + if (shi->osatex) { mul_v3_mat3_m4v3(shi->dxgl, R.viewinv, shi->dxco); mul_v3_mat3_m4v3(shi->dygl, R.viewinv, shi->dyco); @@ -453,7 +453,7 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert for (i = 0; (mcol = RE_strandren_get_mcol(obr, strand, i, &name, 0)); i++) { ShadeInputCol *scol = &shi->col[i]; const char *cp = (char *)mcol; - + shi->totcol++; scol->name = name; @@ -517,7 +517,7 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert suv->uv[0] = 0.0f; suv->uv[1] = spoint->strandco; suv->uv[2] = 0.0f; /* texture.c assumes there are 3 coords */ - + if (mode & MA_FACETEXTURE) { /* no tface? set at 1.0f */ shi->vcol[0] = 1.0f; @@ -564,13 +564,13 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert } } } - + if (shi->do_manage) { if (mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE)) { srgb_to_linearrgb_v3_v3(shi->vcol, shi->vcol); } } - + } /* from scanline pixel coordinates to 3d coordinates, requires set_triangle */ @@ -578,7 +578,7 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v { /* returns not normalized, so is in viewplane coords */ calc_view_vector(view, x, y); - + if (shi->mat->material_type == MA_TYPE_WIRE) { /* wire cannot use normal for calculating shi->co, so * we reconstruct the coordinate less accurate */ @@ -590,43 +590,43 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v else { /* for non-wire, intersect with the triangle to get the exact coord */ float fac, dface, v1[3]; - + copy_v3_v3(v1, shi->v1->co); if (shi->obi->flag & R_TRANSFORMED) mul_m4_v3(shi->obi->mat, v1); - + dface = dot_v3v3(v1, shi->facenor); - + /* ortho viewplane cannot intersect using view vector originating in (0,0,0) */ if (R.r.mode & R_ORTHO) { /* x and y 3d coordinate can be derived from pixel coord and winmat */ float fx = 2.0f / (R.winx * R.winmat[0][0]); float fy = 2.0f / (R.winy * R.winmat[1][1]); - + co[0] = (x - 0.5f * R.winx) * fx - R.winmat[3][0] / R.winmat[0][0]; co[1] = (y - 0.5f * R.winy) * fy - R.winmat[3][1] / R.winmat[1][1]; - + /* using a*x + b*y + c*z = d equation, (a b c) is normal */ if (shi->facenor[2] != 0.0f) co[2] = (dface - shi->facenor[0] * co[0] - shi->facenor[1] * co[1]) / shi->facenor[2]; else co[2] = 0.0f; - + if (dxco && dyco) { dxco[0] = fx; dxco[1] = 0.0f; if (shi->facenor[2] != 0.0f) dxco[2] = -(shi->facenor[0] * fx) / shi->facenor[2]; - else + else dxco[2] = 0.0f; - + dyco[0] = 0.0f; dyco[1] = fy; if (shi->facenor[2] != 0.0f) dyco[2] = -(shi->facenor[1] * fy) / shi->facenor[2]; - else + else dyco[2] = 0.0f; - + if (dxyview) { fac = (co[2] != 0.0f) ? (1.0f / co[2]) : 0.0f; dxyview[0] = -R.viewdx * fac; @@ -636,20 +636,20 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v } else { float div; - + div = dot_v3v3(shi->facenor, view); if (div != 0.0f) fac = dface / div; else fac = 0.0f; - + co[0] = fac * view[0]; co[1] = fac * view[1]; co[2] = fac * view[2]; - + /* pixel dx/dy for render coord */ if (dxco && dyco) { float u = dface / (div - R.viewdx * shi->facenor[0]); float v = dface / (div - R.viewdy * shi->facenor[1]); - + dxco[0] = co[0] - (view[0] - R.viewdx) * u; dxco[1] = co[1] - (view[1]) * u; dxco[2] = co[2] - (view[2]) * u; @@ -657,7 +657,7 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v dyco[0] = co[0] - (view[0]) * v; dyco[1] = co[1] - (view[1] - R.viewdy) * v; dyco[2] = co[2] - (view[2]) * v; - + if (dxyview) { if (fac != 0.0f) fac = 1.0f / fac; dxyview[0] = -R.viewdx * fac; @@ -666,11 +666,11 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v } } } - + /* set camera coords - for scanline, it's always 0.0,0.0,0.0 (render is in camera space) * however for raytrace it can be different - the position of the last intersection */ shi->camera_co[0] = shi->camera_co[1] = shi->camera_co[2] = 0.0f; - + /* cannot normalize earlier, code above needs it at viewplane level */ normalize_v3(view); } @@ -679,7 +679,7 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v void shade_input_set_viewco(ShadeInput *shi, float x, float y, float xs, float ys, float z) { float *dxyview = NULL, *dxco = NULL, *dyco = NULL; - + /* currently in use for dithering (soft shadow), node preview, irregular shad */ shi->xs = (int)xs; shi->ys = (int)ys; @@ -734,7 +734,7 @@ void barycentric_differentials_from_position( void shade_input_set_uv(ShadeInput *shi) { VlakRen *vlr = shi->vlr; - + if ((vlr->flag & R_SMOOTH) || (shi->mat->texco & NEED_UV) || (shi->passflag & SCE_PASS_UV)) { float v1[3], v2[3], v3[3]; @@ -751,10 +751,10 @@ void shade_input_set_uv(ShadeInput *shi) /* exception case for wire render of edge */ if (vlr->v2 == vlr->v3) { float lend, lenc; - + lend = len_v3v3(v2, v1); lenc = len_v3v3(shi->co, v1); - + if (lend == 0.0f) { shi->u = shi->v = 0.0f; } @@ -762,7 +762,7 @@ void shade_input_set_uv(ShadeInput *shi) shi->u = -(1.0f - lenc / lend); shi->v = 0.0f; } - + if (shi->osatex) { shi->dx_u = 0.0f; shi->dx_v = 0.0f; @@ -799,7 +799,7 @@ void shade_input_set_normals(ShadeInput *shi) shi->flippednor = 1; } } - + /* calculate vertexnormals */ if (shi->vlr->flag & R_SMOOTH) { float *n1 = shi->n1, *n2 = shi->n2, *n3 = shi->n3; @@ -809,21 +809,21 @@ void shade_input_set_normals(ShadeInput *shi) negate_v3(n2); negate_v3(n3); } - + shi->vn[0] = l * n3[0] - u * n1[0] - v * n2[0]; shi->vn[1] = l * n3[1] - u * n1[1] - v * n2[1]; shi->vn[2] = l * n3[2] - u * n1[2] - v * n2[2]; /* use unnormalized normal (closer to games) */ copy_v3_v3(shi->nmapnorm, shi->vn); - + normalize_v3(shi->vn); } else { copy_v3_v3(shi->vn, shi->facenor); copy_v3_v3(shi->nmapnorm, shi->vn); } - + /* used in nodes */ copy_v3_v3(shi->vno, shi->vn); @@ -838,25 +838,25 @@ void shade_input_set_vertex_normals(ShadeInput *shi) { float u = shi->u, v = shi->v; float l = 1.0f + u + v; - + /* calculate vertexnormals */ if (shi->vlr->flag & R_SMOOTH) { const float *n1 = shi->n1, *n2 = shi->n2, *n3 = shi->n3; - + shi->vn[0] = l * n3[0] - u * n1[0] - v * n2[0]; shi->vn[1] = l * n3[1] - u * n1[1] - v * n2[1]; shi->vn[2] = l * n3[2] - u * n1[2] - v * n2[2]; - + /* use unnormalized normal (closer to games) */ copy_v3_v3(shi->nmapnorm, shi->vn); - + normalize_v3(shi->vn); } else { copy_v3_v3(shi->vn, shi->facenor); copy_v3_v3(shi->nmapnorm, shi->vn); } - + /* used in nodes */ copy_v3_v3(shi->vno, shi->vn); } @@ -887,10 +887,10 @@ void shade_input_set_shade_texco(ShadeInput *shi) /* calculate dxno */ if (shi->vlr->flag & R_SMOOTH) { - + if (shi->osatex && (texco & (TEXCO_NORM | TEXCO_REFL)) ) { const float *n1 = shi->n1, *n2 = shi->n2, *n3 = shi->n3; - + dl = shi->dx_u + shi->dx_v; shi->dxno[0] = dl * n3[0] - shi->dx_u * n1[0] - shi->dx_v * n2[0]; shi->dxno[1] = dl * n3[1] - shi->dx_u * n1[1] - shi->dx_v * n2[1]; @@ -899,7 +899,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) shi->dyno[0] = dl * n3[0] - shi->dy_u * n1[0] - shi->dy_v * n2[0]; shi->dyno[1] = dl * n3[1] - shi->dy_u * n1[1] - shi->dy_v * n2[1]; shi->dyno[2] = dl * n3[2] - shi->dy_u * n1[2] - shi->dy_v * n2[2]; - + } } @@ -999,10 +999,10 @@ void shade_input_set_shade_texco(ShadeInput *shi) shi->surfdist = 0.0f; } - + if (R.r.mode & R_SPEED) { const float *s1, *s2, *s3; - + s1 = RE_vertren_get_winspeed(obi, v1, 0); s2 = RE_vertren_get_winspeed(obi, v2, 0); s3 = RE_vertren_get_winspeed(obi, v3, 0); @@ -1020,14 +1020,14 @@ void shade_input_set_shade_texco(ShadeInput *shi) /* pass option forces UV calc */ if ((shi->passflag & SCE_PASS_UV) || (R.flag & R_NEED_VCOL)) texco |= (NEED_UV | TEXCO_UV); - + /* texture coordinates. shi->dxuv shi->dyuv have been set */ if (texco & NEED_UV) { - + if (texco & TEXCO_ORCO) { if (v1->orco) { const float *o1, *o2, *o3; - + o1 = v1->orco; o2 = v2->orco; o3 = v3->orco; @@ -1035,7 +1035,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) shi->lo[0] = l * o3[0] - u * o1[0] - v * o2[0]; shi->lo[1] = l * o3[1] - u * o1[1] - v * o2[1]; shi->lo[2] = l * o3[2] - u * o1[2] - v * o2[2]; - + if (shi->osatex) { dl = shi->dx_u + shi->dx_v; shi->dxlo[0] = dl * o3[0] - shi->dx_u * o1[0] - shi->dx_v * o2[0]; @@ -1050,18 +1050,18 @@ void shade_input_set_shade_texco(ShadeInput *shi) copy_v3_v3(shi->duplilo, obi->dupliorco); } - + if (texco & TEXCO_GLOB) { copy_v3_v3(shi->gl, shi->co); mul_m4_v3(R.viewinv, shi->gl); if (shi->osatex) { copy_v3_v3(shi->dxgl, shi->dxco); - mul_mat3_m4_v3(R.viewinv, shi->dxgl); + mul_mat3_m4_v3(R.viewinv, shi->dxgl); copy_v3_v3(shi->dygl, shi->dyco); mul_mat3_m4_v3(R.viewinv, shi->dygl); } } - + if (texco & TEXCO_STRAND) { shi->strandco = (l * v3->accum - u * v1->accum - v * v2->accum); if (shi->osatex) { @@ -1071,7 +1071,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) shi->dystrand = dl * v3->accum - shi->dy_u * v1->accum - shi->dy_v * v2->accum; } } - + if ((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE)) || (R.flag & R_NEED_VCOL)) { VlakRen *vlr = shi->vlr; MTFace *tface; @@ -1092,7 +1092,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) ShadeInputCol *scol = &shi->col[i]; const char *cp1, *cp2, *cp3; float a[3]; - + shi->totcol++; scol->name = name; @@ -1252,7 +1252,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) suv->uv[0] = 2.0f * (u + .5f); suv->uv[1] = 2.0f * (v + .5f); suv->uv[2] = 0.0f; /* texture.c assumes there are 3 coords */ - + if (mode & MA_FACETEXTURE) { /* no tface? set at 1.0f */ shi->vcol[0] = 1.0f; @@ -1262,16 +1262,16 @@ void shade_input_set_shade_texco(ShadeInput *shi) } } } - + if (texco & TEXCO_NORM) { shi->orn[0] = -shi->vn[0]; shi->orn[1] = -shi->vn[1]; shi->orn[2] = -shi->vn[2]; } - + if (texco & TEXCO_STRESS) { const float *s1, *s2, *s3; - + s1 = RE_vertren_get_stress(obr, v1, 0); s2 = RE_vertren_get_stress(obr, v2, 0); s3 = RE_vertren_get_stress(obr, v3, 0); @@ -1282,7 +1282,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) } else shi->stress = 0.0f; } - + if (texco & TEXCO_TANGENT) { if ((mode & MA_TANGENT_V) == 0) { /* just prevent surprises */ @@ -1291,12 +1291,12 @@ void shade_input_set_shade_texco(ShadeInput *shi) } } } - + /* this only avalailable for scanline renders */ if (shi->depth == 0) { float x = shi->xs; float y = shi->ys; - + if (texco & TEXCO_WINDOW) { shi->winco[0] = -1.0f + 2.0f * x / (float)R.winx; shi->winco[1] = -1.0f + 2.0f * y / (float)R.winy; @@ -1319,7 +1319,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) srgb_to_linearrgb_v3_v3(shi->vcol, shi->vcol); } } - + } /* ****************** ShadeSample ************************************** */ @@ -1327,9 +1327,9 @@ void shade_input_set_shade_texco(ShadeInput *shi) /* initialize per part, not per pixel! */ void shade_input_initialize(ShadeInput *shi, RenderPart *pa, RenderLayer *rl, int sample) { - + memset(shi, 0, sizeof(ShadeInput)); - + shi->sample = sample; shi->thread = pa->thread; shi->do_preview = (R.r.scemode & R_MATNODE_PREVIEW) != 0; @@ -1345,21 +1345,21 @@ void shade_input_initialize(ShadeInput *shi, RenderPart *pa, RenderLayer *rl, in shi->light_override = rl->light_override; // shi->rl= rl; /* note shi.depth==0 means first hit, not raytracing */ - + } /* initialize per part, not per pixel! */ void shade_sample_initialize(ShadeSample *ssamp, RenderPart *pa, RenderLayer *rl) { int a, tot; - + tot = R.osa == 0 ? 1 : R.osa; - + for (a = 0; a < tot; a++) { shade_input_initialize(&ssamp->shi[a], pa, rl, a); memset(&ssamp->shr[a], 0, sizeof(ShadeResult)); } - + get_sample_layers(pa, rl, ssamp->rlpp); } @@ -1370,7 +1370,7 @@ void shade_samples_do_AO(ShadeSample *ssamp) return; if (!(R.r.mode & R_RAYTRACE) && !(R.wrld.ao_gather_method == WO_AOGATHER_APPROX)) return; - + if (R.wrld.mode & (WO_AMB_OCC | WO_ENV_LIGHT | WO_INDIRECT_LIGHT)) { ShadeInput *shi = &ssamp->shi[0]; int sample; @@ -1390,28 +1390,28 @@ void shade_samples_fill_with_ps(ShadeSample *ssamp, PixStr *ps, int x, int y) { ShadeInput *shi; float xs, ys; - + ssamp->tot = 0; - + for (shi = ssamp->shi; ps; ps = ps->next) { shade_input_set_triangle(shi, ps->obi, ps->facenr, 1); - + if (shi->vlr) { /* NULL happens for env material or for 'all z' */ unsigned short curmask = ps->mask; - + /* full osa is only set for OSA renders */ if (shi->vlr->flag & R_FULL_OSA) { short shi_cp = 0, samp; - + for (samp = 0; samp < R.osa; samp++) { if (curmask & (1 << samp)) { /* zbuffer has this inverse corrected, ensures xs,ys are inside pixel */ xs = (float)x + R.jit[samp][0] + 0.5f; ys = (float)y + R.jit[samp][1] + 0.5f; - + if (shi_cp) shade_input_copy_triangle(shi, shi - 1); - + shi->mask = (1 << samp); // shi->rl= ssamp->rlpp[samp]; shi->samplenr = R.shadowsamplenr[shi->thread]++; /* this counter is not being reset per pixel */ @@ -1421,7 +1421,7 @@ void shade_samples_fill_with_ps(ShadeSample *ssamp, PixStr *ps, int x, int y) shade_input_set_normals(shi); else /* XXX shi->flippednor messes up otherwise */ shade_input_set_vertex_normals(shi); - + shi_cp = 1; shi++; } @@ -1449,7 +1449,7 @@ void shade_samples_fill_with_ps(ShadeSample *ssamp, PixStr *ps, int x, int y) shade_input_set_normals(shi); shi++; } - + /* total sample amount, shi->sample is static set in initialize */ if (shi != ssamp->shi) ssamp->tot = (shi - 1)->sample + 1; @@ -1461,15 +1461,15 @@ void shade_samples_fill_with_ps(ShadeSample *ssamp, PixStr *ps, int x, int y) int shade_samples(ShadeSample *ssamp, PixStr *ps, int x, int y) { shade_samples_fill_with_ps(ssamp, ps, x, y); - + if (ssamp->tot) { ShadeInput *shi = ssamp->shi; ShadeResult *shr = ssamp->shr; int samp; - + /* if shadow or AO? */ shade_samples_do_AO(ssamp); - + /* if shade (all shadepinputs have same passflag) */ if (ssamp->shi[0].passflag & ~(SCE_PASS_Z | SCE_PASS_INDEXOB | SCE_PASS_INDEXMA)) { @@ -1482,7 +1482,7 @@ int shade_samples(ShadeSample *ssamp, PixStr *ps, int x, int y) for (samp = 0; samp < ssamp->tot; samp++, shi++, shr++) shr->z = -shi->co[2]; } - + return 1; } return 0; diff --git a/source/blender/render/intern/source/shadeoutput.c b/source/blender/render/intern/source/shadeoutput.c index 83827067775..090c249defb 100644 --- a/source/blender/render/intern/source/shadeoutput.c +++ b/source/blender/render/intern/source/shadeoutput.c @@ -68,14 +68,14 @@ extern struct Render R; ListBase *get_lights(ShadeInput *shi) { - + if (R.r.scemode & R_BUTS_PREVIEW) return &R.lights; if (shi->light_override) return &shi->light_override->gobject; if (shi->mat && shi->mat->group) return &shi->mat->group->gobject; - + return &R.lights; } @@ -84,15 +84,15 @@ static void fogcolor(const float colf[3], float *rco, float *view) { float alpha, stepsize, startdist, dist, hor[4], zen[3], vec[3], dview[3]; float div=0.0f, distfac; - + hor[0]= R.wrld.horr; hor[1]= R.wrld.horg; hor[2]= R.wrld.horb; zen[0]= R.wrld.zenr; zen[1]= R.wrld.zeng; zen[2]= R.wrld.zenb; - + copy_v3_v3(vec, rco); - + /* we loop from cur coord to mist start in steps */ stepsize= 1.0f; - + div= ABS(view[2]); dview[0]= view[0]/(stepsize*div); dview[1]= view[1]/(stepsize*div); @@ -100,22 +100,22 @@ static void fogcolor(const float colf[3], float *rco, float *view) startdist= -rco[2] + BLI_frand(); for (dist= startdist; dist>R.wrld.miststa; dist-= stepsize) { - + hor[0]= R.wrld.horr; hor[1]= R.wrld.horg; hor[2]= R.wrld.horb; alpha= 1.0f; do_sky_tex(vec, vec, NULL, hor, zen, &alpha); - + distfac= (dist-R.wrld.miststa)/R.wrld.mistdist; - + hor[3]= hor[0]*distfac*distfac; - + /* premul! */ alpha= hor[3]; hor[0]= hor[0]*alpha; hor[1]= hor[1]*alpha; hor[2]= hor[2]*alpha; addAlphaOverFloat(colf, hor); - + sub_v3_v3(vec, dview); } } @@ -125,16 +125,16 @@ static void fogcolor(const float colf[3], float *rco, float *view) float mistfactor(float zcor, float const co[3]) { float fac, hi; - + fac = zcor - R.wrld.miststa; /* zcor is calculated per pixel */ /* fac= -co[2]-R.wrld.miststa; */ if (fac > 0.0f) { if (fac < R.wrld.mistdist) { - + fac = (fac / R.wrld.mistdist); - + if (R.wrld.mistype == 0) { fac *= fac; } @@ -152,7 +152,7 @@ float mistfactor(float zcor, float const co[3]) else { fac = 0.0f; } - + /* height switched off mist */ if (R.wrld.misthi!=0.0f && fac!=0.0f) { /* at height misthi the mist is completely gone */ @@ -161,7 +161,7 @@ float mistfactor(float zcor, float const co[3]) R.viewinv[1][2] * co[1] + R.viewinv[2][2] * co[2] + R.viewinv[3][2]; - + if (hi > R.wrld.misthi) { fac = 0.0f; } @@ -184,7 +184,7 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) *intens= 0.0f; haint= lar->haint; - + if (R.r.mode & R_ORTHO) { /* camera pos (view vector) cannot be used... */ /* camera position (cox,coy,0) rotate around lamp */ @@ -193,18 +193,18 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) p1[2]= -lar->co[2]; mul_m3_v3(lar->imat, p1); copy_v3db_v3fl(npos, p1); /* npos is double! */ - + /* pre-scale */ npos[2] *= (double)lar->sh_zfac; } else { copy_v3db_v3fl(npos, lar->sh_invcampos); /* in initlamp calculated */ } - + /* rotate view */ copy_v3db_v3fl(nray, shi->view); mul_m3_v3_double(lar->imat, nray); - + if (R.wrld.mode & WO_MIST) { /* patchy... */ haint *= mistfactor(-lar->co[2], lar->co); @@ -222,7 +222,7 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) p1[0]= shi->co[0]-lar->co[0]; p1[1]= shi->co[1]-lar->co[1]; p1[2]= shi->co[2]-lar->co[2]; - + maxz= lar->imat[0][2]*p1[0]+lar->imat[1][2]*p1[1]+lar->imat[2][2]*p1[2]; maxz*= lar->sh_zfac; maxy= lar->imat[0][1]*p1[0]+lar->imat[1][1]*p1[1]+lar->imat[2][1]*p1[2]; @@ -231,13 +231,13 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) use_yco = true; } } - + /* scale z to make sure volume is normalized */ nray[2] *= (double)lar->sh_zfac; /* nray does not need normalization */ - + ladist= lar->sh_zfac*lar->dist; - + /* solve */ a = nray[0] * nray[0] + nray[1] * nray[1] - nray[2]*nray[2]; b = nray[0] * npos[0] + nray[1] * npos[1] - nray[2]*npos[2]; @@ -252,7 +252,7 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) } else { disc = b*b - a*c; - + if (disc==0.0) { t1=t2= (-b)/ a; cuts= 2; @@ -279,14 +279,14 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) /* evaluate both points */ if (p1[2]<=0.0f) ok1= 1; if (p2[2]<=0.0f && t1!=t2) ok2= 1; - + /* at least 1 point with negative z */ if (ok1==0 && ok2==0) return; - + /* intersction point with -ladist, the bottom of the cone */ if (use_yco == false) { t3= ((double)(-ladist)-npos[2])/nray[2]; - + /* de we have to replace one of the intersection points? */ if (ok1) { if (p1[2]<-ladist) t1= t3; @@ -302,21 +302,21 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) } } else if (ok1==0 || ok2==0) return; - + /* at least 1 visible interesction point */ if (t1<0.0 && t2<0.0) return; - + if (t1<0.0) t1= 0.0; if (t2<0.0) t2= 0.0; - + if (t1==t2) return; - + /* sort again to be sure */ if (t1>t2) { a= t1; t1= t2; t2= a; } - - /* calculate t0: is the maximum visible z (when halo is intersected by face) */ + + /* calculate t0: is the maximum visible z (when halo is intersected by face) */ if (do_clip) { if (use_yco == false) t0 = ((double)maxz - npos[2]) / nray[2]; else t0 = ((double)maxy - npos[1]) / nray[1]; @@ -332,20 +332,20 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) p2[0]= npos[0] + t2*nray[0]; p2[1]= npos[1] + t2*nray[1]; p2[2]= npos[2] + t2*nray[2]; - - + + /* now we have 2 points, make three lengths with it */ - + a = len_v3(p1); b = len_v3(p2); c = len_v3v3(p1, p2); - + a/= ladist; a= sqrt(a); - b/= ladist; + b/= ladist; b= sqrt(b); c/= ladist; - + *intens= c*( (1.0-a)+(1.0-b) ); /* WATCH IT: do not clip a,b en c at 1.0, this gives nasty little overflows @@ -357,13 +357,13 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) /* if (doclip && t0shb && lar->shb->shadhalostep) { *intens *= shadow_halo(lar, p1, p2); } - + } } @@ -373,22 +373,22 @@ void renderspothalo(ShadeInput *shi, float col[4], float alpha) GroupObject *go; LampRen *lar; float i; - + if (alpha==0.0f) return; - + lights= get_lights(shi); for (go=lights->first; go; go= go->next) { lar= go->lampren; if (lar==NULL) continue; - + if (lar->type==LA_SPOT && (lar->mode & LA_HALO) && (lar->buftype != LA_SHADBUF_DEEP) && lar->haint>0) { - - if (lar->mode & LA_LAYER) - if (shi->vlr && (lar->lay & shi->obi->lay)==0) + + if (lar->mode & LA_LAYER) + if (shi->vlr && (lar->lay & shi->obi->lay)==0) continue; - if ((lar->lay & shi->lay)==0) + if ((lar->lay & shi->lay)==0) continue; - + spothalo(lar, shi, &i); if (i > 0.0f) { const float i_alpha = i * alpha; @@ -410,14 +410,14 @@ void renderspothalo(ShadeInput *shi, float col[4], float alpha) static double Normalize_d(double *n) { double d; - + d= n[0]*n[0]+n[1]*n[1]+n[2]*n[2]; if (d>0.00000000000000001) { d= sqrt(d); - n[0]/=d; - n[1]/=d; + n[0]/=d; + n[1]/=d; n[2]/=d; } else { @@ -431,15 +431,15 @@ static double Normalize_d(double *n) float fresnel_fac(const float view[3], const float vn[3], float grad, float fac) { float t1, t2; - + if (fac==0.0f) return 1.0f; - + t1 = dot_v3v3(view, vn); if (t1>0.0f) t2= 1.0f+t1; else t2= 1.0f-t1; - + t2= grad + (1.0f-grad)*powf(t2, fac); - + if (t2<0.0f) return 0.0f; else if (t2>1.0f) return 1.0f; return t2; @@ -464,7 +464,7 @@ static float area_lamp_energy(float (*area)[3], const float co[3], const float v VECSUB(vec[1], co, area[1]); VECSUB(vec[2], co, area[2]); VECSUB(vec[3], co, area[3]); - + Normalize_d(vec[0]); Normalize_d(vec[1]); Normalize_d(vec[2]); @@ -528,32 +528,32 @@ static float area_lamp_energy_multisample(LampRen *lar, const float co[3], float vec[1]= jitlamp[1]; vec[2]= 0.0f; mul_m3_v3(lar->mat, vec); - + add_v3_v3v3(area[0], lar->area[0], vec); add_v3_v3v3(area[1], lar->area[1], vec); add_v3_v3v3(area[2], lar->area[2], vec); add_v3_v3v3(area[3], lar->area[3], vec); - + intens+= area_lamp_energy(area, co, vn); - + jitlamp+= 2; } intens /= (float)lar->ray_totsamp; - + return pow(intens * lar->areasize, lar->k); /* corrected for buttons size and lar->dist^2 */ } -static float spec(float inp, int hard) +static float spec(float inp, int hard) { float b1; - + if (inp>=1.0f) return 1.0f; else if (inp<=0.0f) return 0.0f; - + b1= inp*inp; /* avoid FPE */ if (b1<0.01f) b1= 0.01f; - + if ((hard & 1)==0) inp= 1.0f; if (hard & 2) inp*= b1; b1*= b1; @@ -587,18 +587,18 @@ static float Phong_Spec(const float n[3], const float l[3], const float v[3], in { float h[3]; float rslt; - + h[0] = l[0] + v[0]; h[1] = l[1] + v[1]; h[2] = l[2] + v[2]; normalize_v3(h); - + rslt = h[0]*n[0] + h[1]*n[1] + h[2]*n[2]; if (tangent) rslt= sasqrt(1.0f - rslt*rslt); - + if ( rslt > 0.0f ) rslt= spec(rslt, hard); else rslt = 0.0f; - + return rslt; } @@ -616,7 +616,7 @@ static float CookTorr_Spec(const float n[3], const float l[3], const float v[3], nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; if (tangent) nh= sasqrt(1.0f - nh*nh); else if (nh<0.0f) return 0.0f; - + nv= n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; if (tangent) nv= sasqrt(1.0f - nv*nv); else if (nv<0.0f) nv= 0.0f; @@ -635,12 +635,12 @@ static float Blinn_Spec(const float n[3], const float l[3], const float v[3], fl if (refrac < 1.0f) return 0.0f; if (spec_power == 0.0f) return 0.0f; - + /* conversion from 'hardness' (1-255) to 'spec_power' (50 maps at 0.1) */ if (spec_power<100.0f) spec_power = sqrtf(1.0f / spec_power); else spec_power= 10.0f/spec_power; - + h[0]= v[0]+l[0]; h[1]= v[1]+l[1]; h[2]= v[2]+l[2]; @@ -677,7 +677,7 @@ static float Blinn_Spec(const float n[3], const float l[3], const float v[3], fl i= f * g * exp((double)(-(ang*ang) / (2.0f*spec_power*spec_power))); if (i<0.0f) i= 0.0f; - + return i; } @@ -687,21 +687,21 @@ static float Toon_Spec(const float n[3], const float l[3], const float v[3], flo float h[3]; float ang; float rslt; - + h[0] = l[0] + v[0]; h[1] = l[1] + v[1]; h[2] = l[2] + v[2]; normalize_v3(h); - + rslt = h[0]*n[0] + h[1]*n[1] + h[2]*n[2]; if (tangent) rslt = sasqrt(1.0f - rslt*rslt); - - ang = saacos( rslt ); - + + ang = saacos( rslt ); + if ( ang < size ) rslt = 1.0f; else if ( ang >= (size + smooth) || smooth == 0.0f ) rslt = 0.0f; else rslt = 1.0f - ((ang - size) / smooth); - + return rslt; } @@ -720,7 +720,7 @@ static float WardIso_Spec(const float n[3], const float l[3], const float v[3], nh = n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; /* Dot product between surface normal and half-way vector */ if (tangent) nh = sasqrt(1.0f - nh*nh); if (nh<=0.0f) nh = 0.001f; - + nv = n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; /* Dot product between surface normal and view vector */ if (tangent) nv = sasqrt(1.0f - nv*nv); if (nv<=0.0f) nv = 0.001f; @@ -762,41 +762,41 @@ static float OrenNayar_Diff(float nl, const float n[3], const float l[3], const float i/*, nh*/, nv /*, vh */, realnl, h[3]; float a, b, t, A, B; float Lit_A, View_A, Lit_B[3], View_B[3]; - + h[0]= v[0]+l[0]; h[1]= v[1]+l[1]; h[2]= v[2]+l[2]; normalize_v3(h); - + /* nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; */ /* Dot product between surface normal and half-way vector */ /* if (nh<0.0f) nh = 0.0f; */ - + nv= n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; /* Dot product between surface normal and view vector */ if (nv<=0.0f) nv= 0.0f; - + realnl= n[0]*l[0]+n[1]*l[1]+n[2]*l[2]; /* Dot product between surface normal and light vector */ if (realnl<=0.0f) return 0.0f; if (nl<0.0f) return 0.0f; /* value from area light */ - + /* vh= v[0]*h[0]+v[1]*h[1]+v[2]*h[2]; */ /* Dot product between view vector and halfway vector */ /* if (vh<=0.0f) vh= 0.0f; */ - + Lit_A = saacos(realnl); View_A = saacos( nv ); - + Lit_B[0] = l[0] - (realnl * n[0]); Lit_B[1] = l[1] - (realnl * n[1]); Lit_B[2] = l[2] - (realnl * n[2]); normalize_v3(Lit_B); - + View_B[0] = v[0] - (nv * n[0]); View_B[1] = v[1] - (nv * n[1]); View_B[2] = v[2] - (nv * n[2]); normalize_v3(View_B); - + t = Lit_B[0]*View_B[0] + Lit_B[1]*View_B[1] + Lit_B[2]*View_B[2]; if ( t < 0 ) t = 0; - + if ( Lit_A > View_A ) { a = Lit_A; b = View_A; @@ -805,14 +805,14 @@ static float OrenNayar_Diff(float nl, const float n[3], const float l[3], const a = View_A; b = Lit_A; } - + A = 1.0f - (0.5f * ((rough * rough) / ((rough * rough) + 0.33f))); B = 0.45f * ((rough * rough) / ((rough * rough) + 0.09f)); - + b*= 0.95f; /* prevent tangens from shooting to inf, 'nl' can be not a dot product here. */ /* overflow only happens with extreme size area light, and higher roughness */ i = nl * ( A + ( B * t * sinf(a) * tanf(b) ) ); - + return i; } @@ -910,15 +910,15 @@ void shade_color(ShadeInput *shi, ShadeResult *shr) shi->g= shi->g*neg_alpha + shi->vcol[1]*shi->vcol[3]; shi->b= shi->b*neg_alpha + shi->vcol[2]*shi->vcol[3]; } - + if (ma->texco) do_material_tex(shi, &R); - if (ma->fresnel_tra!=0.0f) + if (ma->fresnel_tra!=0.0f) shi->alpha*= fresnel_fac(shi->view, shi->vn, ma->fresnel_tra_i, ma->fresnel_tra); - + if (!(shi->mode & MA_TRANSP)) shi->alpha= 1.0f; - + shr->diff[0]= shi->r; shr->diff[1]= shi->g; shr->diff[2]= shi->b; @@ -950,10 +950,10 @@ static void ramp_diffuse_result(float *diff, ShadeInput *shi) if (ma->rampin_col==MA_RAMP_IN_RESULT) { float fac = IMB_colormanagement_get_luminance(diff); BKE_colorband_evaluate(ma->ramp_col, fac, col); - + /* blending method */ fac= col[3]*ma->rampfac_col; - + ramp_blend(ma->rampblend_col, diff, fac, col); } } @@ -965,7 +965,7 @@ static void add_to_diffuse(float diff[3], const ShadeInput *shi, const float is, Material *ma= shi->mat; if (ma->ramp_col && (ma->mode & MA_RAMP_COL)) { - + /* MA_RAMP_IN_RESULT is exceptional */ if (ma->rampin_col==MA_RAMP_IN_RESULT) { /* normal add */ @@ -992,9 +992,9 @@ static void add_to_diffuse(float diff[3], const ShadeInput *shi, const float is, fac = 0.0f; break; } - + BKE_colorband_evaluate(ma->ramp_col, fac, col); - + /* blending method */ fac = col[3] * ma->rampfac_col; copy_v3_v3(colt, &shi->r); @@ -1023,12 +1023,12 @@ static void ramp_spec_result(float spec_col[3], ShadeInput *shi) float fac = IMB_colormanagement_get_luminance(spec_col); BKE_colorband_evaluate(ma->ramp_spec, fac, col); - + /* blending method */ fac= col[3]*ma->rampfac_spec; - + ramp_blend(ma->rampblend_spec, spec_col, fac, col); - + } } @@ -1061,12 +1061,12 @@ static void do_specular_ramp(ShadeInput *shi, float is, float t, float spec[3]) fac= 0.0f; break; } - + BKE_colorband_evaluate(ma->ramp_spec, fac, col); - + /* blending method */ fac= col[3]*ma->rampfac_spec; - + ramp_blend(ma->rampblend_spec, spec, fac, col); } } @@ -1128,7 +1128,7 @@ void environment_lighting_apply(ShadeInput *shi, ShadeResult *shr) return; if (f == 0.0f) return; - + shr->combined[0] += shi->env[0]*shi->r*shi->refl*f; shr->combined[1] += shi->env[1]*shi->g*shi->refl*f; shr->combined[2] += shi->env[2]*shi->b*shi->refl*f; @@ -1152,11 +1152,11 @@ static void indirect_lighting_apply(ShadeInput *shi, ShadeResult *shr) void lamp_get_shadow(LampRen *lar, ShadeInput *shi, float inp, float shadfac[4], int do_real) { LampShadowSubSample *lss= &(lar->shadsamp[shi->thread].s[shi->sample]); - + if (do_real || lss->samplenr!=shi->samplenr) { - + shadfac[0]= shadfac[1]= shadfac[2]= shadfac[3]= 1.0f; - + if (lar->shb) { if (lar->buftype==LA_SHADBUF_IRREGULAR) shadfac[3]= ISB_getshadow(shi, lar->shb); @@ -1166,7 +1166,7 @@ void lamp_get_shadow(LampRen *lar, ShadeInput *shi, float inp, float shadfac[4], else if (lar->mode & LA_SHAD_RAY) { ray_shadow(shi, lar, shadfac); } - + if (shi->depth==0) { copy_v4_v4(lss->shadfac, shadfac); lss->samplenr= shi->samplenr; @@ -1187,10 +1187,10 @@ float lamp_get_visibility(LampRen *lar, const float co[3], float lv[3], float *d } else { float visifac= 1.0f, visifac_r; - + sub_v3_v3v3(lv, co, lar->co); mul_v3_fl(lv, 1.0f / (*dist = len_v3(lv))); - + /* area type has no quad or sphere option */ if (lar->type==LA_AREA) { /* area is single sided */ @@ -1235,30 +1235,30 @@ float lamp_get_visibility(LampRen *lar, const float co[3], float lv[3], float *d visifac = curvemapping_evaluateF(lar->curfalloff, 0, dist[0]/lar->dist); break; } - + if (lar->mode & LA_SPHERE) { float t= lar->dist - dist[0]; - if (t<=0.0f) + if (t<=0.0f) visifac= 0.0f; else visifac*= t/lar->dist; } - + if (visifac > 0.0f) { if (lar->type==LA_SPOT) { float inpr, t; - + if (lar->mode & LA_SQUARE) { if (dot_v3v3(lv, lar->vec) > 0.0f) { float lvrot[3], x; - + /* rotate view to lampspace */ copy_v3_v3(lvrot, lv); mul_m3_v3(lar->imat, lvrot); - + x = max_ff(fabsf(lvrot[0]/lvrot[2]), fabsf(lvrot[1]/lvrot[2])); /* 1.0f/(sqrt(1+x*x)) is equivalent to cos(atan(x)) */ - + inpr = 1.0f / (sqrtf(1.0f + x * x)); } else inpr= 0.0f; @@ -1266,9 +1266,9 @@ float lamp_get_visibility(LampRen *lar, const float co[3], float lv[3], float *d else { inpr= lv[0]*lar->vec[0]+lv[1]*lar->vec[1]+lv[2]*lar->vec[2]; } - + t= lar->spotsi; - if (inpr<=t) + if (inpr<=t) visifac= 0.0f; else { t= inpr-t; @@ -1296,11 +1296,11 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int float lv[3], lampdist, lacol[3], shadfac[4], lashdw[3]; float i, is, i_noshad, inp, *vn, *view, vnor[3], phongcorr=1.0f; float visifac; - + vn= shi->vn; view= shi->view; - - + + if (lar->energy == 0.0f) return; /* only shadow lamps shouldn't affect shadow-less materials at all */ if ((lar->mode & LA_ONLYSHADOW) && (!(ma->mode & MA_SHADOW) || !(R.r.mode & R_SHADOW))) @@ -1308,35 +1308,35 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int /* optimization, don't render fully black lamps */ if (!(lar->mode & LA_TEXTURE) && (lar->r + lar->g + lar->b == 0.0f)) return; - + /* lampdist, spot angle, area side, ... */ visifac= lamp_get_visibility(lar, shi->co, lv, &lampdist); if (visifac==0.0f) return; - + if (lar->type==LA_SPOT) { if (lar->mode & LA_OSATEX) { shi->osatex= 1; /* signal for multitex() */ - + shi->dxlv[0]= lv[0] - (shi->co[0]-lar->co[0]+shi->dxco[0])/lampdist; shi->dxlv[1]= lv[1] - (shi->co[1]-lar->co[1]+shi->dxco[1])/lampdist; shi->dxlv[2]= lv[2] - (shi->co[2]-lar->co[2]+shi->dxco[2])/lampdist; - + shi->dylv[0]= lv[0] - (shi->co[0]-lar->co[0]+shi->dyco[0])/lampdist; shi->dylv[1]= lv[1] - (shi->co[1]-lar->co[1]+shi->dyco[1])/lampdist; shi->dylv[2]= lv[2] - (shi->co[2]-lar->co[2]+shi->dyco[2])/lampdist; } } - + /* lamp color texture */ lacol[0]= lar->r; lacol[1]= lar->g; lacol[2]= lar->b; - + lashdw[0]= lar->shdwr; lashdw[1]= lar->shdwg; lashdw[2]= lar->shdwb; - + if (lar->mode & LA_TEXTURE) do_lamp_tex(lar, lv, shi, lacol, LA_TEXTURE); if (lar->mode & LA_SHAD_TEX) do_lamp_tex(lar, lv, shi, lashdw, LA_SHAD_TEX); @@ -1381,7 +1381,7 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int vnor[0]= -vnor[0];vnor[1]= -vnor[1];vnor[2]= -vnor[2]; vn= vnor; } - + /* dot product and reflectivity */ /* inp = dotproduct, is = shader result, i = lamp energy (with shadow), i_noshad = i without shadow */ inp= dot_v3v3(vn, lv); @@ -1408,7 +1408,7 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int } } } - + /* diffuse shaders */ if (lar->mode & LA_NO_DIFF) { is = 0.0f; /* skip shaders */ @@ -1417,10 +1417,10 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int is = 0.5f * inp + 0.5f; } else { - + if (lar->type==LA_AREA) inp= area_lamp_energy_multisample(lar, shi->co, vn); - + /* diffuse shaders (oren nayer gets inp from area light) */ if (ma->diff_shader==MA_DIFF_ORENNAYAR) is= OrenNayar_Diff(inp, vn, lv, view, ma->roughness); else if (ma->diff_shader==MA_DIFF_TOON) is= Toon_Diff(vn, lv, view, ma->param[0], ma->param[1]); @@ -1435,48 +1435,48 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int } i= is*phongcorr; - + if (i>0.0f) { i*= visifac*shi->refl; } i_noshad= i; - + vn = shi->vn; /* bring back original vector, we use special specular shaders for tangent */ if (ma->mode & MA_TANGENT_V) vn= shi->tang; - + /* init transp shadow */ shadfac[0]= shadfac[1]= shadfac[2]= shadfac[3]= 1.0f; - + /* shadow and spec, (visifac==0 outside spot) */ if (visifac> 0.0f) { - + if ((R.r.mode & R_SHADOW)) { if (ma->mode & MA_SHADOW) { if (lar->shb || (lar->mode & LA_SHAD_RAY)) { - + if (vn==vnor) /* tangent trigger */ lamp_get_shadow(lar, shi, dot_v3v3(shi->vn, lv), shadfac, shi->depth); else lamp_get_shadow(lar, shi, inp, shadfac, shi->depth); - + /* warning, here it skips the loop */ if ((lar->mode & LA_ONLYSHADOW) && i>0.0f) { - + shadfac[3]= i*lar->energy*(1.0f-shadfac[3]); shr->shad[0] -= shadfac[3]*shi->r*(1.0f-lashdw[0]); shr->shad[1] -= shadfac[3]*shi->g*(1.0f-lashdw[1]); shr->shad[2] -= shadfac[3]*shi->b*(1.0f-lashdw[2]); - + if (!(lar->mode & LA_NO_SPEC)) { shr->spec[0] -= shadfac[3]*shi->specr*(1.0f-lashdw[0]); shr->spec[1] -= shadfac[3]*shi->specg*(1.0f-lashdw[1]); shr->spec[2] -= shadfac[3]*shi->specb*(1.0f-lashdw[2]); } - + return; } - + i*= shadfac[3]; shr->shad[3] = shadfac[3]; /* store this for possible check in troublesome cases */ } @@ -1485,7 +1485,7 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int } } } - + /* in case 'no diffuse' we still do most calculus, spec can be in shadow.*/ if (!(lar->mode & LA_NO_DIFF)) { if (i>0.0f) { @@ -1531,33 +1531,33 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int } } } - + /* specularity */ shadfac[3]*= phongcorr; /* note, shadfac not allowed to be stored nonlocal */ - + if (shadfac[3]>0.0f && shi->spec!=0.0f && !(lar->mode & LA_NO_SPEC) && !(lar->mode & LA_ONLYSHADOW)) { - + if (!(passflag & (SCE_PASS_COMBINED | SCE_PASS_SPEC))) { /* pass */ } else if (lar->type == LA_HEMI) { float t; /* hemi uses no spec shaders (yet) */ - + lv[0]+= view[0]; lv[1]+= view[1]; lv[2]+= view[2]; - + normalize_v3(lv); - + t= vn[0]*lv[0]+vn[1]*lv[1]+vn[2]*lv[2]; - + if (lar->type==LA_HEMI) { t= 0.5f*t+0.5f; } - + t= shadfac[3]*shi->spec*spec(t, shi->har); - + shr->spec[0]+= t*(lacol[0] * shi->specr); shr->spec[1]+= t*(lacol[1] * shi->specg); shr->spec[2]+= t*(lacol[2] * shi->specb); @@ -1565,23 +1565,23 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int else { /* specular shaders */ float specfac, t; - - if (ma->spec_shader==MA_SPEC_PHONG) + + if (ma->spec_shader==MA_SPEC_PHONG) specfac= Phong_Spec(vn, lv, view, shi->har, (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V)); - else if (ma->spec_shader==MA_SPEC_COOKTORR) + else if (ma->spec_shader==MA_SPEC_COOKTORR) specfac= CookTorr_Spec(vn, lv, view, shi->har, (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V)); - else if (ma->spec_shader==MA_SPEC_BLINN) + else if (ma->spec_shader==MA_SPEC_BLINN) specfac= Blinn_Spec(vn, lv, view, ma->refrac, (float)shi->har, (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V)); else if (ma->spec_shader==MA_SPEC_WARDISO) specfac= WardIso_Spec( vn, lv, view, ma->rms, (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V)); - else + else specfac= Toon_Spec(vn, lv, view, ma->param[2], ma->param[3], (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V)); - + /* area lamp correction */ if (lar->type==LA_AREA) specfac*= inp; - + t= shadfac[3]*shi->spec*visifac*specfac; - + if (ma->mode & MA_RAMP_SPEC) { float spec[3]; do_specular_ramp(shi, specfac, t, spec); @@ -1601,7 +1601,7 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr) { - + if (R.r.mode & R_SHADOW) { ListBase *lights; LampRen *lar; @@ -1610,19 +1610,19 @@ static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr) float /* *view, */ shadfac[4]; float ir, accum, visifac, lampdist; float shaded = 0.0f, lightness = 0.0f; - + /* view= shi->view; */ /* UNUSED */ accum= ir= 0.0f; - + lights= get_lights(shi); for (go=lights->first; go; go= go->next) { lar= go->lampren; if (lar==NULL) continue; - + if (lar->mode & LA_LAYER) if ((lar->lay & shi->obi->lay)==0) continue; if ((lar->lay & shi->lay)==0) continue; - + if (lar->shb || (lar->mode & LA_SHAD_RAY)) { visifac= lamp_get_visibility(lar, shi->co, lv, &lampdist); ir+= 1.0f; @@ -1687,14 +1687,14 @@ static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr) else shr->alpha= 0.f; } } - + /* quite disputable this... also note it doesn't mirror-raytrace */ if ((R.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT)) && shi->amb!=0.0f) { float f; - + if (R.wrld.mode & WO_AMB_OCC) { f= R.wrld.aoenergy*shi->amb; - + if (R.wrld.aomix==WO_AOADD) { if (shi->mat->shadowonly_flag == MA_SO_OLD) { f= f*(1.0f - IMB_colormanagement_get_luminance(shi->ao)); @@ -1726,7 +1726,7 @@ static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr) /* let's map negative light as if it mirrors positive light, otherwise negative values disappear */ static void wrld_exposure_correct(float diff[3]) { - + diff[0]= R.wrld.linfac*(1.0f-expf( diff[0]*R.wrld.logfac) ); diff[1]= R.wrld.linfac*(1.0f-expf( diff[1]*R.wrld.logfac) ); diff[2]= R.wrld.linfac*(1.0f-expf( diff[2]*R.wrld.logfac) ); @@ -1748,18 +1748,18 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) int passflag= shi->passflag; memset(shr, 0, sizeof(ShadeResult)); - + if (!(shi->mode & MA_TRANSP)) shi->alpha = 1.0f; - + /* separate loop */ if (ma->mode & MA_ONLYSHADOW) { shade_lamp_loop_only_shadow(shi, shr); return; } - + /* envmap hack, always reset */ shi->refcol[0]= shi->refcol[1]= shi->refcol[2]= shi->refcol[3]= 0.0f; - + /* material color itself */ if (passflag & color_passes) { if (ma->mode & (MA_FACETEXTURE)) { @@ -1787,7 +1787,7 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) do_material_tex(shi, &R); if (!(shi->mode & MA_TRANSP)) shi->alpha = 1.0f; } - + shr->col[0]= shi->r*shi->alpha; shr->col[1]= shi->g*shi->alpha; shr->col[2]= shi->b*shi->alpha; @@ -1803,7 +1803,7 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) shi->g= pow(max_ff(shi->g, 0.0f), ma->sss_texfac); shi->b= pow(max_ff(shi->b, 0.0f), ma->sss_texfac); shi->alpha= pow(max_ff(shi->alpha, 0.0f), ma->sss_texfac); - + shr->col[0]= pow(max_ff(shr->col[0], 0.0f), ma->sss_texfac); shr->col[1]= pow(max_ff(shr->col[1], 0.0f), ma->sss_texfac); shr->col[2]= pow(max_ff(shr->col[2], 0.0f), ma->sss_texfac); @@ -1811,7 +1811,7 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) } } } - + if (ma->mode & MA_SHLESS) { shr->combined[0]= shi->r; shr->combined[1]= shi->g; @@ -1830,7 +1830,7 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) shr->emit[1]= shi->g*shi->emit; shr->emit[2]= shi->b*shi->emit; } - + /* AO pass */ if (((passflag & SCE_PASS_COMBINED) && (shi->combinedflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) || (passflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) { @@ -1848,22 +1848,22 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) zero_v3(shr->indirect); } } - + /* lighting pass */ if (passflag & (SCE_PASS_COMBINED|SCE_PASS_DIFFUSE|SCE_PASS_SPEC|SCE_PASS_SHADOW)) { GroupObject *go; ListBase *lights; LampRen *lar; - + lights= get_lights(shi); for (go=lights->first; go; go= go->next) { lar= go->lampren; if (lar==NULL) continue; - + /* test for lamp layer */ if (lar->mode & LA_LAYER) if ((lar->lay & shi->obi->lay)==0) continue; if ((lar->lay & shi->lay)==0) continue; - + /* accumulates in shr->diff and shr->spec and shr->shad (diffuse with shadow!) */ shade_one_light(lar, shi, shr, passflag); } @@ -1877,7 +1877,7 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) if (shr->shad[0] < 0) shr->shad[0] = 0; if (shr->shad[1] < 0) shr->shad[1] = 0; if (shr->shad[2] < 0) shr->shad[2] = 0; - + if (ma->sss_flag & MA_DIFF_SSS) { float sss[3], col[3], invalpha, texfac= ma->sss_texfac; @@ -1912,14 +1912,14 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) } } } - + if (shi->combinedflag & SCE_PASS_SHADOW) copy_v3_v3(shr->diffshad, shr->shad); else copy_v3_v3(shr->diffshad, shr->diff); copy_v3_v3(shr->combined, shr->diffshad); - + /* calculate shadow pass, we use a multiplication mask */ /* Even if diff = 0,0,0, it does matter what the shadow pass is, since we may want it 'for itself'! */ if (passflag & SCE_PASS_SHADOW) { @@ -1933,19 +1933,19 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) if (shr->diff[2]!=0.0f) shr->shad[2]= shr->shad[2]/shr->diff[2]; else if (shr->shad[2]==0.0f) shr->shad[2]= shr->shad[3]; } - + /* exposure correction */ if ((R.wrld.exp!=0.0f || R.wrld.range!=1.0f) && !R.sss_points) { wrld_exposure_correct(shr->combined); /* has no spec! */ wrld_exposure_correct(shr->spec); } } - + /* alpha in end, spec can influence it */ if (passflag & (SCE_PASS_COMBINED)) { if ((ma->fresnel_tra!=0.0f) && (shi->mode & MA_TRANSP)) shi->alpha*= fresnel_fac(shi->view, shi->vn, ma->fresnel_tra_i, ma->fresnel_tra); - + /* note: shi->mode! */ if (shi->mode & MA_TRANSP && (shi->mode & (MA_ZTRANSP|MA_RAYTRANSP))) { if (shi->spectra!=0.0f) { @@ -1957,7 +1957,7 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) } } shr->alpha= shi->alpha; - + /* from now stuff everything in shr->combined: ambient, AO, ramps, exposure */ if (!(ma->sss_flag & MA_DIFF_SSS) || !sss_pass_done(&R, ma)) { if (R.r.mode & R_SHADOW) { @@ -1974,32 +1974,32 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) if (shi->combinedflag & SCE_PASS_INDIRECT) indirect_lighting_apply(shi, shr); } - + shr->combined[0]+= shi->ambr; shr->combined[1]+= shi->ambg; shr->combined[2]+= shi->ambb; - + if (ma->mode & MA_RAMP_COL) ramp_diffuse_result(shr->combined, shi); } if (ma->mode & MA_RAMP_SPEC) ramp_spec_result(shr->spec, shi); - + /* refcol is for envmap only */ if (shi->refcol[0]!=0.0f) { float result[3]; - + result[0]= shi->mirr*shi->refcol[1] + (1.0f - shi->mirr*shi->refcol[0])*shr->combined[0]; result[1]= shi->mirg*shi->refcol[2] + (1.0f - shi->mirg*shi->refcol[0])*shr->combined[1]; result[2]= shi->mirb*shi->refcol[3] + (1.0f - shi->mirb*shi->refcol[0])*shr->combined[2]; - + if (passflag & SCE_PASS_REFLECT) sub_v3_v3v3(shr->refl, result, shr->combined); - + if (shi->combinedflag & SCE_PASS_REFLECT) copy_v3_v3(shr->combined, result); - + } - + /* and add emit and spec */ if (shi->combinedflag & SCE_PASS_EMIT) add_v3_v3(shr->combined, shr->emit); diff --git a/source/blender/render/intern/source/sss.c b/source/blender/render/intern/source/sss.c index c29da9b17c6..5919b8130d7 100644 --- a/source/blender/render/intern/source/sss.c +++ b/source/blender/render/intern/source/sss.c @@ -190,7 +190,7 @@ static float compute_reduced_albedo(ScatterSettings *ss) if (xn > 1.0f) xn= 1.0f; if (xn_1 > 1.0f) xn_1= 1.0f; - + fxn= f_Rd(xn, ss->A, ss->ro); } @@ -299,7 +299,7 @@ static void build_Rd_table(ScatterSettings *ss) ScatterSettings *scatter_settings_new(float refl, float radius, float ior, float reflfac, float frontweight, float backweight) { ScatterSettings *ss; - + ss= MEM_callocN(sizeof(ScatterSettings), "ScatterSettings"); /* see [1] and [3] for these formulas */ @@ -346,7 +346,7 @@ void scatter_settings_free(ScatterSettings *ss) #define SUBNODE_INDEX(co, split) \ ((co[0]>=split[0]) + (co[1]>=split[1])*2 + (co[2]>=split[2])*4) - + static void add_radiance(ScatterTree *tree, float *frontrad, float *backrad, float area, float backarea, float rr, ScatterResult *result) { float rd[3], frontrd[3], backrd[3]; @@ -694,7 +694,7 @@ static void create_octree_node(ScatterTree *tree, ScatterNode *node, float *mid, if (i != 0) noffset[i]= noffset[i-1]+nsize[i-1]; } - + if (used_nodes <= 1) { subnode_middle(usedi, mid, subsize, submid); create_octree_node(tree, node, submid, subsize, refpoints, depth+1); @@ -807,7 +807,7 @@ void scatter_tree_build(ScatterTree *tree) tree->refpoints= NULL; tree->tmppoints= NULL; tree->points= newpoints; - + /* sum radiance at nodes */ sum_radiance(tree, tree->root); } @@ -827,7 +827,7 @@ void scatter_tree_free(ScatterTree *tree) if (tree->arena) BLI_memarena_free(tree->arena); if (tree->points) MEM_freeN(tree->points); if (tree->refpoints) MEM_freeN(tree->refpoints); - + MEM_freeN(tree); } @@ -859,7 +859,7 @@ static void sss_create_tree_mat(Render *re, Material *mat) if (re->test_break(re->tbh)) return; - + points.first= points.last= NULL; /* TODO: this is getting a bit ugly, copying all those variables and @@ -884,7 +884,7 @@ static void sss_create_tree_mat(Render *re, Material *mat) BLI_rw_mutex_unlock(&re->resultmutex); RE_TileProcessor(re); - + BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); if (!(re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))) { RE_FreeRenderResult(re->result); @@ -907,7 +907,7 @@ static void sss_create_tree_mat(Render *re, Material *mat) if (!re->test_break(re->tbh)) { for (totpoint=0, p=points.first; p; p=p->next) totpoint += p->totpoint; - + co= MEM_mallocN(sizeof(*co)*totpoint, "SSSCo"); color= MEM_mallocN(sizeof(*color)*totpoint, "SSSColor"); area= MEM_mallocN(sizeof(*area)*totpoint, "SSSArea"); @@ -939,7 +939,7 @@ static void sss_create_tree_mat(Render *re, Material *mat) error= get_render_aosss_error(&re->r, error); if ((re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW)) && error < 0.5f) error= 0.5f; - + sss->ss[0]= scatter_settings_new(mat->sss_col[0], radius[0], ior, cfac, fw, bw); sss->ss[1]= scatter_settings_new(mat->sss_col[1], radius[1], ior, cfac, fw, bw); sss->ss[2]= scatter_settings_new(mat->sss_col[2], radius[2], ior, cfac, fw, bw); @@ -964,7 +964,7 @@ static void sss_create_tree_mat(Render *re, Material *mat) void sss_add_points(Render *re, float (*co)[3], float (*color)[3], float *area, int totpoint) { SSSPoints *p; - + if (totpoint > 0) { p= MEM_callocN(sizeof(SSSPoints), "SSSPoints"); @@ -997,11 +997,11 @@ void make_sss_tree(Render *re) const char *prevstr = NULL; free_sss(re); - + re->sss_hash= BLI_ghash_ptr_new("make_sss_tree gh"); re->stats_draw(re->sdh, &re->i); - + for (mat= re->main->mat.first; mat; mat= mat->id.next) { if (mat->id.us && (mat->flag & MA_IS_USED) && (mat->sss_flag & MA_DIFF_SSS)) { if (!infostr_set) { @@ -1013,7 +1013,7 @@ void make_sss_tree(Render *re) sss_create_tree_mat(re, mat); } } - + /* XXX preview exception */ /* localizing preview render data is not fun for node trees :( */ if (re->main!=G.main) { @@ -1029,7 +1029,7 @@ void make_sss_tree(Render *re) } } } - + if (infostr_set) re->i.infostr = prevstr; } diff --git a/source/blender/render/intern/source/strand.c b/source/blender/render/intern/source/strand.c index 6b52d4aa419..5fde688481a 100644 --- a/source/blender/render/intern/source/strand.c +++ b/source/blender/render/intern/source/strand.c @@ -68,7 +68,7 @@ static float strand_eval_width(Material *ma, float strandco) fac= pow(strandco, 1.0f/(1.0f-ma->strand_ease)); } else fac= strandco; - + return ((1.0f-fac)*ma->strand_sta + (fac)*ma->strand_end); } @@ -131,7 +131,7 @@ void strand_eval_point(StrandSegment *sseg, StrandPoint *spoint) negate_v3(spoint->nor); spoint->width= strand_eval_width(ma, spoint->strandco); - + /* simplification */ simplify= RE_strandren_get_simplify(strandbuf->obr, sseg->strand, 0); spoint->alpha= (simplify)? simplify[1]: 1.0f; @@ -285,10 +285,10 @@ static void strand_shade_point(Render *re, ShadeSample *ssamp, StrandSegment *ss shade_input_set_strand(shi, sseg->strand, spoint); shade_input_set_strand_texco(shi, sseg->strand, sseg->v[1], spoint); - + /* init material vars */ shade_input_init_material(shi); - + /* shade */ shade_samples_do_AO(ssamp); shade_input_do_shade(shi, shr); @@ -300,7 +300,7 @@ static void strand_shade_point(Render *re, ShadeSample *ssamp, StrandSegment *ss if (re->flag & R_LAMPHALO) if (shi->layflag & SCE_LAY_HALO) renderspothalo(shi, shr->combined, shr->combined[3]); - + shi->strand= NULL; } @@ -325,7 +325,7 @@ StrandShadeCache *strand_shade_cache_create(void) cache->resulthash= BLI_ghash_pair_new("strand_shade_cache_create1 gh"); cache->refcounthash= BLI_ghash_pair_new("strand_shade_cache_create2 gh"); cache->memarena= BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "strand shade cache arena"); - + return cache; } @@ -367,7 +367,7 @@ static void strand_shade_get(Render *re, StrandShadeCache *cache, ShadeSample *s else /* already shaded, just copy previous result from hash */ ssamp->shr[0]= entry->shr; - + /* lower reference count and remove if not needed anymore by any samples */ (*refcount)--; if (*refcount == 0) { @@ -536,10 +536,10 @@ static void do_strand_fillac(void *handle, int x, int y, float u, float v, float /* find the z of the sample */ PixStr *ps; intptr_t *rd= spart->rectdaps + offset; - + bufferz= 0x7FFFFFFF; if (spart->rectmask) maskz= 0x7FFFFFFF; - + if (*rd) { for (ps= (PixStr *)(*rd); ps; ps= ps->next) { if (mask & ps->mask) { @@ -609,7 +609,7 @@ static int strand_test_clip(float winmat[4][4], ZSpan *UNUSED(zspan), float *bou if (hoco[0]+widthx < bounds[0]*hoco[3]) clipflag |= 1; else if (hoco[0]-widthx > bounds[1]*hoco[3]) clipflag |= 2; - + if (hoco[1]-widthy > bounds[3]*hoco[3]) clipflag |= 4; else if (hoco[1]+widthy < bounds[2]*hoco[3]) clipflag |= 8; @@ -713,7 +713,7 @@ static int strand_segment_recursive(Render *re, float winmat[4][4], StrandPart * if (len1 == 0.0f || len2 == 0.0f) return 0; - + dot= d1[0]*d2[0] + d1[1]*d2[1]; if (dot*dot > sseg->sqadaptcos*len1*len2) return 0; @@ -735,7 +735,7 @@ static int strand_segment_recursive(Render *re, float winmat[4][4], StrandPart * strand_render(re, sseg, winmat, spart, zspan, totzspan, p1, &p); if (!strand_segment_recursive(re, winmat, spart, zspan, totzspan, sseg, &p, p2, depth+1)) strand_render(re, sseg, winmat, spart, zspan, totzspan, &p, p2); - + return 1; } @@ -818,7 +818,7 @@ int zbuffer_strands_abuf(Render *re, RenderPart *pa, APixstrand *apixbuf, ListBa /* needed for transform from hoco to zbuffer co */ zspan.zmulx= ((float)winx)/2.0f; zspan.zmuly= ((float)winy)/2.0f; - + zspan.zofsx= -pa->disprect.xmin; zspan.zofsy= -pa->disprect.ymin; @@ -866,7 +866,7 @@ int zbuffer_strands_abuf(Render *re, RenderPart *pa, APixstrand *apixbuf, ListBa if (clip_render_object(obi->obr->boundbox, bounds, obwinmat)) continue; - + widthx= obr->strandbuf->maxwidth*obwinmat[0][0]; widthy= obr->strandbuf->maxwidth*obwinmat[1][1]; @@ -962,7 +962,7 @@ int zbuffer_strands_abuf(Render *re, RenderPart *pa, APixstrand *apixbuf, ListBa if (sortsegments) MEM_freeN(sortsegments); MEM_freeN(spart.totapixbuf); - + zbuf_free_span(&zspan); return totsegment; @@ -1057,7 +1057,7 @@ void strand_minmax(StrandRen *strand, float min[3], float max[3], const float wi for (a=0, svert=strand->vert; atotvert; a++, svert++) { copy_v3_v3(vec, svert->co); minmax_v3v3_v3(min, max, vec); - + if (width!=0.0f) { add_v3_fl(vec, width); minmax_v3v3_v3(min, max, vec); diff --git a/source/blender/render/intern/source/sunsky.c b/source/blender/render/intern/source/sunsky.c index 7aed5f87dbc..80dd52c220c 100644 --- a/source/blender/render/intern/source/sunsky.c +++ b/source/blender/render/intern/source/sunsky.c @@ -122,13 +122,13 @@ static void DirectionToThetaPhi(float *toSun, float *theta, float *phi) static float PerezFunction(struct SunSky *sunsky, const float *lam, float theta, float gamma, float lvz) { float den, num; - + den = ((1 + lam[0] * expf(lam[1])) * (1 + lam[2] * expf(lam[3] * sunsky->theta) + lam[4] * cosf(sunsky->theta) * cosf(sunsky->theta))); - + num = ((1 + lam[0] * expf(lam[1] / cosf(theta))) * (1 + lam[2] * expf(lam[3] * gamma) + lam[4] * cosf(gamma) * cosf(gamma))); - + return(lvz * num / den); } @@ -166,7 +166,7 @@ void InitSunSky(struct SunSky *sunsky, float turb, const float toSun[3], float h sunsky->skyblendtype = skyblendtype; sunsky->sky_exposure = -sky_exposure; sunsky->sky_colorspace = sky_colorspace; - + sunsky->toSun[0] = toSun[0]; sunsky->toSun[1] = toSun[1]; sunsky->toSun[2] = toSun[2]; @@ -186,7 +186,7 @@ void InitSunSky(struct SunSky *sunsky, float turb, const float toSun[3], float h if (sunsky->zenith_Y <= 0) sunsky->zenith_Y = 1e-6; - + sunsky->zenith_x = (+0.00165f * theta3 - 0.00374f * theta2 + 0.00208f * sunsky->theta + 0.0f) * T2 + (-0.02902f * theta3 + 0.06377f * theta2 - 0.03202f * sunsky->theta + 0.00394f) * T + @@ -197,7 +197,7 @@ void InitSunSky(struct SunSky *sunsky, float turb, const float toSun[3], float h (-0.04214f * theta3 + 0.08970f * theta2 - 0.04153f * sunsky->theta + 0.00515f) * T + (+0.15346f * theta3 - 0.26756f * theta2 + 0.06669f * sunsky->theta + 0.26688f); - + sunsky->perez_Y[0] = 0.17872f * T - 1.46303f; sunsky->perez_Y[1] = -0.35540f * T + 0.42749f; sunsky->perez_Y[2] = -0.02266f * T + 5.32505f; @@ -215,12 +215,12 @@ void InitSunSky(struct SunSky *sunsky, float turb, const float toSun[3], float h sunsky->perez_y[2] = -0.00792f * T + 0.21023f; sunsky->perez_y[3] = -0.04405f * T - 1.65369f; sunsky->perez_y[4] = -0.01092f * T + 0.05291f; - + /* suggested by glome in patch [#8063] */ sunsky->perez_Y[0] *= sunsky->horizon_brightness; sunsky->perez_x[0] *= sunsky->horizon_brightness; sunsky->perez_y[0] *= sunsky->horizon_brightness; - + sunsky->perez_Y[1] *= sunsky->spread; sunsky->perez_x[1] *= sunsky->spread; sunsky->perez_y[1] *= sunsky->spread; @@ -228,11 +228,11 @@ void InitSunSky(struct SunSky *sunsky, float turb, const float toSun[3], float h sunsky->perez_Y[2] *= sunsky->sun_brightness; sunsky->perez_x[2] *= sunsky->sun_brightness; sunsky->perez_y[2] *= sunsky->sun_brightness; - + sunsky->perez_Y[3] *= sunsky->sun_size; sunsky->perez_x[3] *= sunsky->sun_size; sunsky->perez_y[3] *= sunsky->sun_size; - + sunsky->perez_Y[4] *= sunsky->backscattered_light; sunsky->perez_x[4] *= sunsky->backscattered_light; sunsky->perez_y[4] *= sunsky->backscattered_light; @@ -269,7 +269,7 @@ void GetSkyXYZRadiance(struct SunSky *sunsky, float theta, float phi, float colo } gamma = AngleBetween(theta, phi, sunsky->theta, sunsky->phi); - + /* Compute xyY values */ x = PerezFunction(sunsky, sunsky->perez_x, theta, gamma, sunsky->zenith_x); y = PerezFunction(sunsky, sunsky->perez_y, theta, gamma, sunsky->zenith_y); @@ -277,7 +277,7 @@ void GetSkyXYZRadiance(struct SunSky *sunsky, float theta, float phi, float colo if (sunsky->sky_exposure != 0.0f) Y = 1.0 - exp(Y * sunsky->sky_exposure); - + X = (x / y) * Y; Z = ((1 - x - y) / y) * Y; @@ -326,14 +326,14 @@ static void ComputeAttenuatedSunlight(float theta, int turbidity, float fTau[3]) float fAlpha; int i; - float fLambda[3]; + float fLambda[3]; fLambda[0] = 0.65f; fLambda[1] = 0.57f; fLambda[2] = 0.475f; fAlpha = 1.3f; fBeta = 0.04608365822050f * turbidity - 0.04586025928522f; - + m = 1.0f / (cosf(theta) + 0.15f * powf(93.885f - theta / (float)M_PI * 180.0f, -1.253f)); for (i = 0; i < 3; i++) { @@ -371,11 +371,11 @@ void InitAtmosphere(struct SunSky *sunSky, float sun_intens, float mief, float r float c = (6.544f * T - 6.51f) * 1e-17f; float K[3] = {0.685f, 0.679f, 0.670f}; float vBetaMieTemp[3]; - + float fLambda[3], fLambda2[3], fLambda4[3]; float vLambda2[3]; float vLambda4[3]; - + int i; sunSky->atm_SunIntensity = sun_intens; @@ -384,7 +384,7 @@ void InitAtmosphere(struct SunSky *sunSky, float sun_intens, float mief, float r sunSky->atm_InscatteringMultiplier = inscattf; sunSky->atm_ExtinctionMultiplier = extincf; sunSky->atm_DistanceMultiplier = disf; - + sunSky->atm_HGg = 0.8; fLambda[0] = 1 / 650e-9f; @@ -415,12 +415,12 @@ void InitAtmosphere(struct SunSky *sunSky, float sun_intens, float mief, float r /* Mie scattering constants. */ fTemp2 = 0.434f * c * (2 * pi) * (2 * pi) * 0.5f; VEC3OPF(sunSky->atm_BetaDashMie, vLambda2, *, fTemp2); - + fTemp3 = 0.434f * c * pi * (2 * pi) * (2 * pi); - + VEC3OPV(vBetaMieTemp, K, *, fLambda); VEC3OPF(sunSky->atm_BetaMie, vBetaMieTemp, *, fTemp3); - + } /** @@ -438,19 +438,19 @@ void AtmospherePixleShader(struct SunSky *sunSky, float view[3], float s, float float Phase_1; float Phase_2; float sunColor[3]; - + float E[3]; float E1[3]; - - + + float I[3]; float fTemp; float vTemp1[3], vTemp2[3]; float sunDirection[3]; - + s *= sunSky->atm_DistanceMultiplier; - + sunDirection[0] = sunSky->toSun[0]; sunDirection[1] = sunSky->toSun[1]; sunDirection[2] = sunSky->toSun[2]; @@ -474,7 +474,7 @@ void AtmospherePixleShader(struct SunSky *sunSky, float view[3], float s, float fTemp = 1 + sunSky->atm_HGg - 2 * sunSky->atm_HGg * costheta; fTemp = fTemp * sqrtf(fTemp); Phase_2 = (1 - sunSky->atm_HGg * sunSky->atm_HGg) / fTemp; - + VEC3OPF(vTemp1, sunSky->atm_BetaDashRay, *, Phase_1); VEC3OPF(vTemp2, sunSky->atm_BetaDashMie, *, Phase_2); @@ -485,7 +485,7 @@ void AtmospherePixleShader(struct SunSky *sunSky, float view[3], float s, float FOPVEC3(vTemp2, 1.0f, /, sunSky->atm_BetaRM); VEC3OPV(I, vTemp1, *, vTemp2); - + VEC3OPF(I, I, *, sunSky->atm_InscatteringMultiplier); VEC3OPF(E, E, *, sunSky->atm_ExtinctionMultiplier); diff --git a/source/blender/render/intern/source/volume_precache.c b/source/blender/render/intern/source/volume_precache.c index 8ef35828be9..8e79f309814 100644 --- a/source/blender/render/intern/source/volume_precache.c +++ b/source/blender/render/intern/source/volume_precache.c @@ -76,18 +76,18 @@ extern struct Render R; static int intersect_outside_volume(RayObject *tree, Isect *isect, float *offset, int limit, int depth) { if (limit == 0) return depth; - + if (RE_rayobject_raycast(tree, isect)) { - + isect->start[0] = isect->start[0] + isect->dist*isect->dir[0]; isect->start[1] = isect->start[1] + isect->dist*isect->dir[1]; isect->start[2] = isect->start[2] + isect->dist*isect->dir[2]; - + isect->dist = FLT_MAX; isect->skip = RE_SKIP_VLR_NEIGHBOUR; isect->orig.face= isect->hit.face; isect->orig.ob= isect->hit.ob; - + return intersect_outside_volume(tree, isect, offset, limit-1, depth+1); } else { @@ -101,14 +101,14 @@ static int point_inside_obi(RayObject *tree, ObjectInstanceRen *obi, const float Isect isect= {{0}}; float dir[3] = {0.0f, 0.0f, 1.0f}; int final_depth=0, depth=0, limit=20; - + /* set up the isect */ copy_v3_v3(isect.start, co); copy_v3_v3(isect.dir, dir); isect.mode= RE_RAY_MIRROR; isect.last_hit= NULL; isect.lay= -1; - + isect.dist = FLT_MAX; isect.orig.face= NULL; isect.orig.ob = NULL; @@ -116,7 +116,7 @@ static int point_inside_obi(RayObject *tree, ObjectInstanceRen *obi, const float RE_instance_rotate_ray(obi, &isect); final_depth = intersect_outside_volume(tree, &isect, dir, limit, depth); RE_instance_rotate_ray_restore(obi, &isect); - + /* even number of intersections: point is outside * odd number: point is inside */ if (final_depth % 2 == 0) return 0; @@ -131,37 +131,37 @@ void global_bounds_obi(Render *re, ObjectInstanceRen *obi, float bbmin[3], float VertRen *ver= NULL; float co[3]; int a; - + if (vp->bbmin != NULL && vp->bbmax != NULL) { copy_v3_v3(bbmin, vp->bbmin); copy_v3_v3(bbmax, vp->bbmax); return; } - + vp->bbmin = MEM_callocN(sizeof(float)*3, "volume precache min boundbox corner"); vp->bbmax = MEM_callocN(sizeof(float)*3, "volume precache max boundbox corner"); - + INIT_MINMAX(bbmin, bbmax); - + for (a=0; atotvert; a++) { if ((a & 255)==0) ver= obr->vertnodes[a>>8].vert; else ver++; - + copy_v3_v3(co, ver->co); - + /* transformed object instance in camera space */ if (obi->flag & R_TRANSFORMED) mul_m4_v3(obi->mat, co); - + /* convert to global space */ mul_m4_v3(re->viewinv, co); - + minmax_v3v3_v3(vp->bbmin, vp->bbmax, co); } - + copy_v3_v3(bbmin, vp->bbmin); copy_v3_v3(bbmax, vp->bbmax); - + } /* *** light cache filtering *** */ @@ -171,34 +171,34 @@ static float get_avg_surrounds(float *cache, int *res, int xx, int yy, int zz) int x, y, z, x_, y_, z_; int added=0; float tot=0.0f; - + for (z=-1; z <= 1; z++) { z_ = zz+z; if (z_ >= 0 && z_ <= res[2]-1) { - + for (y=-1; y <= 1; y++) { y_ = yy+y; if (y_ >= 0 && y_ <= res[1]-1) { - + for (x=-1; x <= 1; x++) { x_ = xx+x; if (x_ >= 0 && x_ <= res[0]-1) { const int64_t i = BLI_VOXEL_INDEX(x_, y_, z_, res); - + if (cache[i] > 0.0f) { tot += cache[i]; added++; } - + } } } } } } - + if (added > 0) tot /= added; - + return tot; } @@ -215,7 +215,7 @@ static void lightcache_filter(VolumePrecache *vp) for (x=0; x < vp->res[0]; x++) { /* trigger for outside mesh */ const int64_t i = BLI_VOXEL_INDEX(x, y, z, vp->res); - + if (vp->data_r[i] < -0.f) vp->data_r[i] = get_avg_surrounds(vp->data_r, vp->res, x, y, z); if (vp->data_g[i] < -0.f) @@ -233,15 +233,15 @@ static void lightcache_filter2(VolumePrecache *vp) int x, y, z; float *new_r, *new_g, *new_b; int field_size = vp->res[0]*vp->res[1]*vp->res[2]*sizeof(float); - + new_r = MEM_mallocN(field_size, "temp buffer for light cache filter r channel"); new_g = MEM_mallocN(field_size, "temp buffer for light cache filter g channel"); new_b = MEM_mallocN(field_size, "temp buffer for light cache filter b channel"); - + memcpy(new_r, vp->data_r, field_size); memcpy(new_g, vp->data_g, field_size); memcpy(new_b, vp->data_b, field_size); - + for (z=0; z < vp->res[2]; z++) { for (y=0; y < vp->res[1]; y++) { for (x=0; x < vp->res[0]; x++) { @@ -256,11 +256,11 @@ static void lightcache_filter2(VolumePrecache *vp) } } } - + SWAP(float *, vp->data_r, new_r); SWAP(float *, vp->data_g, new_g); SWAP(float *, vp->data_b, new_b); - + if (new_r) { MEM_freeN(new_r); new_r=NULL; } if (new_g) { MEM_freeN(new_g); new_g=NULL; } if (new_b) { MEM_freeN(new_b); new_b=NULL; } @@ -286,7 +286,7 @@ BLI_INLINE int64_t v_I_pad(int x, int y, int z, const int *n) } BLI_INLINE int64_t lc_to_ms_I(int x, int y, int z, const int *n) -{ +{ /* converting light cache index to multiple scattering index */ return ((int64_t)(x - 1) * ((int64_t)n[1] * (int64_t)n[2]) + (int64_t)(y - 1) * ((int64_t)n[2]) + @@ -301,12 +301,12 @@ static float total_ss_energy(Render *re, int do_test_break, VolumePrecache *vp) int x, y, z; const int *res = vp->res; float energy=0.f; - + for (z=0; z < res[2]; z++) { for (y=0; y < res[1]; y++) { for (x=0; x < res[0]; x++) { const int64_t i = BLI_VOXEL_INDEX(x, y, z, res); - + if (vp->data_r[i] > 0.f) energy += vp->data_r[i]; if (vp->data_g[i] > 0.f) energy += vp->data_g[i]; if (vp->data_b[i] > 0.f) energy += vp->data_b[i]; @@ -315,7 +315,7 @@ static float total_ss_energy(Render *re, int do_test_break, VolumePrecache *vp) if (do_test_break && re->test_break(re->tbh)) break; } - + return energy; } @@ -323,12 +323,12 @@ static float total_ms_energy(Render *re, int do_test_break, float *sr, float *sg { int x, y, z; float energy=0.f; - + for (z=1;z<=res[2];z++) { for (y=1;y<=res[1];y++) { for (x=1;x<=res[0];x++) { const int64_t i = ms_I(x, y, z, res); - + if (sr[i] > 0.f) energy += sr[i]; if (sg[i] > 0.f) energy += sg[i]; if (sb[i] > 0.f) energy += sb[i]; @@ -337,7 +337,7 @@ static float total_ms_energy(Render *re, int do_test_break, float *sr, float *sg if (do_test_break && re->test_break(re->tbh)) break; } - + return energy; } @@ -350,7 +350,7 @@ static void ms_diffuse(Render *re, int do_test_break, const float *x0, float *x, const float dt = VOL_MS_TIMESTEP; int64_t size = (int64_t)n[0] * (int64_t)n[1] * (int64_t)n[2]; const float a = dt * diff * size; - + for (l=0; l<20; l++) { for (k=1; k<=n[2]; k++) { for (j=1; j<=n[1]; j++) { @@ -379,7 +379,7 @@ static void multiple_scattering_diffusion(Render *re, VolumePrecache *vp, Materi const int simframes = (int)(ma->vol.ms_spread * (float)max_iii(vp->res[0], vp->res[1], vp->res[2])); const int shade_type = ma->vol.shade_type; float fac = ma->vol.ms_intensity; - + int x, y, z, m; const int *n = vp->res; const int size = (n[0]+2)*(n[1]+2)*(n[2]+2); @@ -398,9 +398,9 @@ static void multiple_scattering_diffusion(Render *re, VolumePrecache *vp, Materi float *sb=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer"); total = (float)(n[0]*n[1]*n[2]*simframes); - + energy_ss = total_ss_energy(re, do_test_break, vp); - + /* Scattering as diffusion pass */ for (m=0; mdata_r[i] > 0.0f) @@ -418,7 +418,7 @@ static void multiple_scattering_diffusion(Render *re, VolumePrecache *vp, Materi sg[j] += vp->data_g[i]; if (vp->data_b[i] > 0.0f) sb[j] += vp->data_b[i]; - + /* Displays progress every second */ if (time-lasttime>1.0) { char str[64]; @@ -445,14 +445,14 @@ static void multiple_scattering_diffusion(Render *re, VolumePrecache *vp, Materi ms_diffuse(re, do_test_break, sr0, sr, diff, n); ms_diffuse(re, do_test_break, sg0, sg, diff, n); ms_diffuse(re, do_test_break, sb0, sb, diff, n); - + if (re->test_break(re->tbh)) break; } - + /* normalization factor to conserve energy */ energy_ms = total_ms_energy(re, do_test_break, sr, sg, sb, n); fac *= (energy_ss / energy_ms); - + /* blend multiple scattering back in the light cache */ if (shade_type == MA_VOL_SHADE_SHADEDPLUSMULTIPLE) { /* conserve energy - half single, half multiple */ @@ -468,7 +468,7 @@ static void multiple_scattering_diffusion(Render *re, VolumePrecache *vp, Materi for (x=1;x<=n[0];x++) { const int64_t i = lc_to_ms_I(x, y, z, n); //lc index const int64_t j = ms_I(x, y, z, n); //ms index - + vp->data_r[i] = origf * vp->data_r[i] + fac * sr[j]; vp->data_g[i] = origf * vp->data_g[i] + fac * sg[j]; vp->data_b[i] = origf * vp->data_b[i] + fac * sb[j]; @@ -532,7 +532,7 @@ static void vol_precache_part(TaskPool * __restrict pool, void *taskdata, int UN if (re->test_break && re->test_break(re->tbh)) return; - + //printf("thread id %d\n", threadid); res[0]= pa->res[0]; @@ -541,17 +541,17 @@ static void vol_precache_part(TaskPool * __restrict pool, void *taskdata, int UN for (z= pa->minz; z < pa->maxz; z++) { co[2] = pa->bbmin[2] + (pa->voxel[2] * (z + 0.5f)); - + for (y= pa->miny; y < pa->maxy; y++) { co[1] = pa->bbmin[1] + (pa->voxel[1] * (y + 0.5f)); - + for (x=pa->minx; x < pa->maxx; x++) { int64_t i; co[0] = pa->bbmin[0] + (pa->voxel[0] * (x + 0.5f)); - + if (re->test_break && re->test_break(re->tbh)) break; - + /* convert from world->camera space for shading */ mul_v3_m4v3(cco, pa->viewmat, co); @@ -564,15 +564,15 @@ static void vol_precache_part(TaskPool * __restrict pool, void *taskdata, int UN obi->volume_precache->data_b[i] = -1.0f; continue; } - + copy_v3_v3(view, cco); normalize_v3(view); vol_get_scattering(shi, scatter_col, cco, view); - + obi->volume_precache->data_r[i] = scatter_col[0]; obi->volume_precache->data_g[i] = scatter_col[1]; obi->volume_precache->data_b[i] = scatter_col[2]; - + } } } @@ -599,7 +599,7 @@ static void vol_precache_part(TaskPool * __restrict pool, void *taskdata, int UN static void precache_setup_shadeinput(Render *re, ObjectInstanceRen *obi, Material *ma, ShadeInput *shi) { - memset(shi, 0, sizeof(ShadeInput)); + memset(shi, 0, sizeof(ShadeInput)); shi->depth= 1; shi->mask= 1; shi->mat = ma; @@ -627,26 +627,26 @@ static void precache_launch_parts(Render *re, RayObject *tree, ShadeInput *shi, int minz, maxz; int totthread = re->r.threads; int parts[3]; - + if (!vp) return; /* currently we just subdivide the box, number of threads per side */ parts[0] = parts[1] = parts[2] = totthread; res = vp->res; - + /* setup task scheduler */ memset(&state, 0, sizeof(state)); state.doneparts = 0; state.totparts = parts[0]*parts[1]*parts[2]; state.lasttime = PIL_check_seconds_timer(); - + task_scheduler = BLI_task_scheduler_create(totthread); task_pool = BLI_task_pool_create(task_scheduler, &state); /* using boundbox in worldspace */ global_bounds_obi(re, obi, bbmin, bbmax); sub_v3_v3v3(voxel, bbmax, bbmin); - + voxel[0] /= (float)res[0]; voxel[1] /= (float)res[1]; voxel[2] /= (float)res[2]; @@ -656,38 +656,38 @@ static void precache_launch_parts(Render *re, RayObject *tree, ShadeInput *shi, minx = x * sizex; maxx = minx + sizex; maxx = (maxx>res[0])?res[0]:maxx; - + for (y=0; y < parts[1]; y++) { sizey = ceil(res[1] / (float)parts[1]); miny = y * sizey; maxy = miny + sizey; maxy = (maxy>res[1])?res[1]:maxy; - + for (z=0; z < parts[2]; z++) { VolPrecachePart *pa= MEM_callocN(sizeof(VolPrecachePart), "new precache part"); - + sizez = ceil(res[2] / (float)parts[2]); minz = z * sizez; maxz = minz + sizez; maxz = (maxz>res[2])?res[2]:maxz; - + pa->re = re; pa->num = i; pa->tree = tree; pa->shi = shi; pa->obi = obi; copy_m4_m4(pa->viewmat, re->viewmat); - + copy_v3_v3(pa->bbmin, bbmin); copy_v3_v3(pa->voxel, voxel); copy_v3_v3_int(pa->res, res); - + pa->minx = minx; pa->maxx = maxx; pa->miny = miny; pa->maxy = maxy; pa->minz = minz; pa->maxz = maxz; - + BLI_task_pool_push(task_pool, vol_precache_part, pa, true, TASK_PRIORITY_HIGH); - + i++; } } @@ -706,23 +706,23 @@ static int precache_resolution(Render *re, VolumePrecache *vp, ObjectInstanceRen { float dim[3], div; float bbmin[3], bbmax[3]; - + /* bound box in global space */ global_bounds_obi(re, obi, bbmin, bbmax); sub_v3_v3v3(dim, bbmax, bbmin); - + div = max_fff(dim[0], dim[1], dim[2]); dim[0] /= div; dim[1] /= div; dim[2] /= div; - + vp->res[0] = ceil(dim[0] * res); vp->res[1] = ceil(dim[1] * res); vp->res[2] = ceil(dim[2] * res); - + if ((vp->res[0] < 1) || (vp->res[1] < 1) || (vp->res[2] < 1)) return 0; - + return 1; } @@ -736,17 +736,17 @@ static void vol_precache_objectinstance_threads(Render *re, ObjectInstanceRen *o VolumePrecache *vp; RayObject *tree; ShadeInput shi; - + R = *re; - /* create a raytree with just the faces of the instanced ObjectRen, + /* create a raytree with just the faces of the instanced ObjectRen, * used for checking if the cached point is inside or outside. */ tree = makeraytree_object(&R, obi); if (!tree) return; vp = MEM_callocN(sizeof(VolumePrecache), "volume light cache"); obi->volume_precache = vp; - + if (!precache_resolution(re, vp, obi, ma->vol.precache_resolution)) { MEM_freeN(vp); vp = NULL; @@ -763,7 +763,7 @@ static void vol_precache_objectinstance_threads(Render *re, ObjectInstanceRen *o /* Need a shadeinput to calculate scattering */ precache_setup_shadeinput(re, obi, ma, &shi); - + precache_launch_parts(re, tree, &shi, obi); if (tree) { @@ -772,12 +772,12 @@ static void vol_precache_objectinstance_threads(Render *re, ObjectInstanceRen *o //RE_rayobject_free(tree); //tree= NULL; } - + if (ELEM(ma->vol.shade_type, MA_VOL_SHADE_MULTIPLE, MA_VOL_SHADE_SHADEDPLUSMULTIPLE)) { /* this should be before the filtering */ multiple_scattering_diffusion(re, obi->volume_precache, ma); } - + lightcache_filter(obi->volume_precache); } @@ -812,7 +812,7 @@ void volume_precache(Render *re) break; } } - + re->i.infostr = NULL; re->stats_draw(re->sdh, &re->i); } @@ -820,7 +820,7 @@ void volume_precache(Render *re) void free_volume_precache(Render *re) { ObjectInstanceRen *obi; - + for (obi= re->instancetable.first; obi; obi= obi->next) { if (obi->volume_precache != NULL) { MEM_freeN(obi->volume_precache->data_r); @@ -832,7 +832,7 @@ void free_volume_precache(Render *re) obi->volume_precache = NULL; } } - + BLI_freelistN(&re->volumes); } @@ -840,16 +840,16 @@ int point_inside_volume_objectinstance(Render *re, ObjectInstanceRen *obi, const { RayObject *tree; int inside=0; - + tree = makeraytree_object(re, obi); if (!tree) return 0; - + inside = point_inside_obi(tree, obi, co); - + //TODO: makeraytree_object creates a tree and saves it on OBI, if we free this tree we should also clear other pointers to it //RE_rayobject_free(tree); //tree= NULL; - + return inside; } diff --git a/source/blender/render/intern/source/volumetric.c b/source/blender/render/intern/source/volumetric.c index 7f3f14a1593..583353ed8cf 100644 --- a/source/blender/render/intern/source/volumetric.c +++ b/source/blender/render/intern/source/volumetric.c @@ -70,16 +70,16 @@ extern struct Render R; static float vol_get_shadow(ShadeInput *shi, LampRen *lar, const float co[3]) { float visibility = 1.f; - + if (lar->shb) { float dxco[3] = {0.f, 0.f, 0.f}, dyco[3] = {0.f, 0.f, 0.f}; - + visibility = testshadowbuf(&R, lar->shb, co, dxco, dyco, 1.0, 0.0); } else if (lar->mode & LA_SHAD_RAY) { /* trace shadow manually, no good lamp api atm */ Isect is; - + copy_v3_v3(is.start, co); if (lar->type == LA_SUN || lar->type == LA_HEMI) { is.dir[0] = -lar->vec[0]; @@ -95,16 +95,16 @@ static float vol_get_shadow(ShadeInput *shi, LampRen *lar, const float co[3]) is.mode = RE_RAY_MIRROR; is.check = RE_CHECK_VLR_NON_SOLID_MATERIAL; is.skip = 0; - + if (lar->mode & (LA_LAYER | LA_LAYER_SHADOW)) is.lay = lar->lay; else is.lay = -1; - + is.orig.ob = NULL; is.orig.face = NULL; is.last_hit = lar->last_hit[shi->thread]; - + RE_instance_rotate_ray(shi->obi, &is); if (RE_rayobject_raycast(R.raytree, &is)) { @@ -112,7 +112,7 @@ static float vol_get_shadow(ShadeInput *shi, LampRen *lar, const float co[3]) visibility = 0.f; } - + lar->last_hit[shi->thread] = is.last_hit; } return visibility; @@ -120,7 +120,7 @@ static float vol_get_shadow(ShadeInput *shi, LampRen *lar, const float co[3]) static int vol_get_bounds(ShadeInput *shi, const float co[3], const float vec[3], float hitco[3], Isect *isect, int intersect_type) { - + copy_v3_v3(isect->start, co); copy_v3_v3(isect->dir, vec); isect->dist = FLT_MAX; @@ -128,7 +128,7 @@ static int vol_get_bounds(ShadeInput *shi, const float co[3], const float vec[3] isect->last_hit = NULL; isect->lay = -1; isect->check = RE_CHECK_VLR_NONE; - + if (intersect_type == VOL_BOUNDS_DEPTH) { isect->skip = RE_SKIP_VLR_NEIGHBOUR; isect->orig.face = (void *)shi->vlr; @@ -141,7 +141,7 @@ static int vol_get_bounds(ShadeInput *shi, const float co[3], const float vec[3] } RE_instance_rotate_ray(shi->obi, isect); - + if (RE_rayobject_raycast(R.raytree, isect)) { RE_instance_rotate_ray_restore(shi->obi, isect); @@ -159,9 +159,9 @@ static void shade_intersection(ShadeInput *shi, float col_r[4], Isect *is) { ShadeInput shi_new; ShadeResult shr_new; - - memset(&shi_new, 0, sizeof(ShadeInput)); - + + memset(&shi_new, 0, sizeof(ShadeInput)); + shi_new.mask = shi->mask; shi_new.osatex = shi->osatex; shi_new.thread = shi->thread; @@ -174,16 +174,16 @@ static void shade_intersection(ShadeInput *shi, float col_r[4], Isect *is) shi_new.combinedflag = 0xFFFFFF; /* ray trace does all options */ shi_new.light_override = shi->light_override; shi_new.mat_override = shi->mat_override; - + copy_v3_v3(shi_new.camera_co, is->start); - + memset(&shr_new, 0, sizeof(ShadeResult)); - + /* hardcoded limit of 100 for now - prevents problems in weird geometry */ if (shi->volume_depth < 100) { shade_ray(is, &shi_new, &shr_new); } - + copy_v3_v3(col_r, shr_new.combined); col_r[3] = shr_new.alpha; } @@ -191,11 +191,11 @@ static void shade_intersection(ShadeInput *shi, float col_r[4], Isect *is) static void vol_trace_behind(ShadeInput *shi, VlakRen *vlr, const float co[3], float col_r[4]) { Isect isect; - + copy_v3_v3(isect.start, co); copy_v3_v3(isect.dir, shi->view); isect.dist = FLT_MAX; - + isect.mode = RE_RAY_MIRROR; isect.check = RE_CHECK_VLR_NONE; isect.skip = RE_SKIP_VLR_NEIGHBOUR; @@ -203,7 +203,7 @@ static void vol_trace_behind(ShadeInput *shi, VlakRen *vlr, const float co[3], f isect.orig.face = (void *)vlr; isect.last_hit = NULL; isect.lay = -1; - + /* check to see if there's anything behind the volume, otherwise shade the sky */ RE_instance_rotate_ray(shi->obi, &isect); @@ -225,9 +225,9 @@ static void vol_get_precached_scattering(Render *re, ShadeInput *shi, float scat VolumePrecache *vp = shi->obi->volume_precache; float bbmin[3], bbmax[3], dim[3]; float world_co[3], sample_co[3]; - + if (!vp) return; - + /* find sample point in global space bounding box 0.0-1.0 */ global_bounds_obi(re, shi->obi, bbmin, bbmax); sub_v3_v3v3(dim, bbmax, bbmin); @@ -243,23 +243,23 @@ static void vol_get_precached_scattering(Render *re, ShadeInput *shi, float scat scatter_col[2] = BLI_voxel_sample_triquadratic(vp->data_b, vp->res, sample_co); } -/* Meta object density, brute force for now +/* Meta object density, brute force for now * (might be good enough anyway, don't need huge number of metaobs to model volumetric objects */ static float metadensity(Object *ob, const float co[3]) { float mat[4][4], imat[4][4], dens = 0.f; MetaBall *mb = (MetaBall *)ob->data; MetaElem *ml; - + /* transform co to meta-element */ float tco[3] = {co[0], co[1], co[2]}; mul_m4_m4m4(mat, R.viewmat, ob->obmat); invert_m4_m4(imat, mat); mul_m4_v3(imat, tco); - + for (ml = mb->elems.first; ml; ml = ml->next) { float bmat[3][3], dist2; - + /* element rotation transform */ float tp[3] = {ml->x - tco[0], ml->y - tco[1], ml->z - tco[2]}; quat_to_mat3(bmat, ml->quat); @@ -290,7 +290,7 @@ static float metadensity(Object *ob, const float co[3]) if (dist2 > 0.f) dens += (ml->flag & MB_NEGATIVE) ? -ml->s * dist2 * dist2 * dist2 : ml->s * dist2 * dist2 * dist2; } - + dens -= mb->thresh; return (dens < 0.f) ? 0.f : dens; } @@ -299,36 +299,36 @@ float vol_get_density(struct ShadeInput *shi, const float co[3]) { float density = shi->mat->vol.density; float density_scale = shi->mat->vol.density_scale; - + if (shi->mat->mapto_textured & MAP_DENSITY) do_volume_tex(shi, co, MAP_DENSITY, NULL, &density, &R); - + /* if meta-object, modulate by metadensity without increasing it */ if (shi->obi->obr->ob->type == OB_MBALL) { const float md = metadensity(shi->obi->obr->ob, co); if (md < 1.f) density *= md; } - + return density * density_scale; } /* Color of light that gets scattered out by the volume */ -/* Uses same physically based scattering parameter as in transmission calculations, +/* Uses same physically based scattering parameter as in transmission calculations, * along with artificial reflection scale/reflection color tint */ static void vol_get_reflection_color(ShadeInput *shi, float ref_col[3], const float co[3]) { float scatter = shi->mat->vol.scattering; float reflection = shi->mat->vol.reflection; copy_v3_v3(ref_col, shi->mat->vol.reflection_col); - + if (shi->mat->mapto_textured & (MAP_SCATTERING + MAP_REFLECTION_COL)) do_volume_tex(shi, co, MAP_SCATTERING + MAP_REFLECTION_COL, ref_col, &scatter, &R); - + /* only one single float parameter at a time... :s */ if (shi->mat->mapto_textured & (MAP_REFLECTION)) do_volume_tex(shi, co, MAP_REFLECTION, NULL, &reflection, &R); - + ref_col[0] = reflection * ref_col[0] * scatter; ref_col[1] = reflection * ref_col[1] * scatter; ref_col[2] = reflection * ref_col[2] * scatter; @@ -340,10 +340,10 @@ static void vol_get_emission(ShadeInput *shi, float emission_col[3], const float { float emission = shi->mat->vol.emission; copy_v3_v3(emission_col, shi->mat->vol.emission_col); - + if (shi->mat->mapto_textured & (MAP_EMISSION + MAP_EMISSION_COL)) do_volume_tex(shi, co, MAP_EMISSION + MAP_EMISSION_COL, emission_col, &emission, &R); - + emission_col[0] = emission_col[0] * emission; emission_col[1] = emission_col[1] * emission; emission_col[2] = emission_col[2] * emission; @@ -356,26 +356,26 @@ static void vol_get_emission(ShadeInput *shi, float emission_col[3], const float * It's easy enough to get a good wide range of results with just these two parameters. */ static void vol_get_sigma_t(ShadeInput *shi, float sigma_t[3], const float co[3]) { - /* technically absorption, but named transmission color + /* technically absorption, but named transmission color * since it describes the effect of the coloring *after* absorption */ float transmission_col[3] = {shi->mat->vol.transmission_col[0], shi->mat->vol.transmission_col[1], shi->mat->vol.transmission_col[2]}; float scattering = shi->mat->vol.scattering; - + if (shi->mat->mapto_textured & (MAP_SCATTERING + MAP_TRANSMISSION_COL)) do_volume_tex(shi, co, MAP_SCATTERING + MAP_TRANSMISSION_COL, transmission_col, &scattering, &R); - + sigma_t[0] = (1.0f - transmission_col[0]) + scattering; sigma_t[1] = (1.0f - transmission_col[1]) + scattering; sigma_t[2] = (1.0f - transmission_col[2]) + scattering; } -/* phase function - determines in which directions the light +/* phase function - determines in which directions the light * is scattered in the volume relative to incoming direction * and view direction */ static float vol_get_phasefunc(ShadeInput *UNUSED(shi), float g, const float w[3], const float wp[3]) { const float normalize = 0.25f; // = 1.f/4.f = M_PI/(4.f*M_PI) - + /* normalization constant is 1/4 rather than 1/4pi, since * Blender's shading system doesn't normalize for * energy conservation - eg. multiplying by pdf ( 1/pi for a lambert brdf ). @@ -385,7 +385,7 @@ static float vol_get_phasefunc(ShadeInput *UNUSED(shi), float g, const float w[3 * To correct this, scale up the phase function values by pi * until Blender's shading system supports this better. --matt */ - + if (g == 0.f) { /* isotropic */ return normalize * 1.f; } @@ -394,7 +394,7 @@ static float vol_get_phasefunc(ShadeInput *UNUSED(shi), float g, const float w[3 const float kcostheta = k * dot_v3v3(w, wp); return normalize * (1.f - k * k) / ((1.f - kcostheta) * (1.f - kcostheta)); } - + /* not used, but here for reference: */ #if 0 switch (phasefunc_type) { @@ -426,14 +426,14 @@ static void vol_get_transmittance_seg(ShadeInput *shi, float tr[3], float stepsi float tau[3] = {0.f, 0.f, 0.f}; const float stepd = density * stepsize; float sigma_t[3]; - + vol_get_sigma_t(shi, sigma_t, co); - + /* homogeneous volume within the sampled distance */ tau[0] += stepd * sigma_t[0]; tau[1] += stepd * sigma_t[1]; tau[2] += stepd * sigma_t[2]; - + tr[0] *= expf(-tau[0]); tr[1] *= expf(-tau[1]); tr[2] *= expf(-tau[2]); @@ -449,7 +449,7 @@ static void vol_get_transmittance(ShadeInput *shi, float tr[3], const float co[3 float t0 = 0.f; float t1 = normalize_v3(step_vec); float pt0 = t0; - + t0 += shi->mat->vol.stepsize * ((shi->mat->vol.stepsize_type == MA_VOL_STEP_CONSTANT) ? 0.5f : BLI_thread_frand(shi->thread)); p[0] += t0 * step_vec[0]; p[1] += t0 * step_vec[1]; @@ -460,16 +460,16 @@ static void vol_get_transmittance(ShadeInput *shi, float tr[3], const float co[3 const float d = vol_get_density(shi, p); const float stepd = (t0 - pt0) * d; float sigma_t[3]; - + vol_get_sigma_t(shi, sigma_t, p); - + tau[0] += stepd * sigma_t[0]; tau[1] += stepd * sigma_t[1]; tau[2] += stepd * sigma_t[2]; - + add_v3_v3(p, step_vec); } - + /* return transmittance */ tr[0] = expf(-tau[0]); tr[1] = expf(-tau[1]); @@ -482,15 +482,15 @@ static void vol_shade_one_lamp(struct ShadeInput *shi, const float co[3], const float tr[3] = {1.0, 1.0, 1.0}; float hitco[3], *atten_co; float p, ref_col[3]; - + if (lar->mode & LA_LAYER) if ((lar->lay & shi->obi->lay) == 0) return; if ((lar->lay & shi->lay) == 0) return; if (lar->energy == 0.0f) return; - + if ((visifac = lamp_get_visibility(lar, co, lv, &lampdist)) == 0.f) return; - + copy_v3_v3(lacol, &lar->r); - + if (lar->mode & LA_TEXTURE) { shi->osatex = 0; do_lamp_tex(lar, lv, shi, lacol, LA_TEXTURE); @@ -501,23 +501,23 @@ static void vol_shade_one_lamp(struct ShadeInput *shi, const float co[3], const if (ELEM(lar->type, LA_SUN, LA_HEMI)) copy_v3_v3(lv, lar->vec); negate_v3(lv); - + if (shi->mat->vol.shade_type == MA_VOL_SHADE_SHADOWED) { mul_v3_fl(lacol, vol_get_shadow(shi, lar, co)); } 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) { mul_v3_fl(lacol, vol_get_shadow(shi, lar, co)); if (IMB_colormanagement_get_luminance(lacol) < 0.001f) return; } - + /* find minimum of volume bounds, or lamp coord */ if (vol_get_bounds(shi, co, lv, hitco, &is, VOL_BOUNDS_SS)) { float dist = len_v3v3(co, hitco); VlakRen *vlr = (VlakRen *)is.hit.face; - + /* simple internal shadowing */ if (vlr->mat->material_type == MA_TYPE_SURFACE) { lacol[0] = lacol[1] = lacol[2] = 0.0f; @@ -532,9 +532,9 @@ static void vol_shade_one_lamp(struct ShadeInput *shi, const float co[3], const } else atten_co = hitco; - + vol_get_transmittance(shi, tr, co, atten_co); - + mul_v3_v3v3(lacol, lacol, tr); } else { @@ -543,15 +543,15 @@ static void vol_shade_one_lamp(struct ShadeInput *shi, const float co[3], const * Radiance from lamp remains unchanged */ } } - + if (IMB_colormanagement_get_luminance(lacol) < 0.001f) return; - + normalize_v3(lv); p = vol_get_phasefunc(shi, shi->mat->vol.asymmetry, view, lv); - + /* physically based scattering with non-physically based RGB gain */ vol_get_reflection_color(shi, ref_col, co); - + lacol[0] *= p * ref_col[0]; lacol[1] *= p * ref_col[1]; lacol[2] *= p * ref_col[2]; @@ -570,7 +570,7 @@ void vol_get_scattering(ShadeInput *shi, float scatter_col[3], const float co[3] for (go = lights->first; go; go = go->next) { float lacol[3] = {0.f, 0.f, 0.f}; lar = go->lampren; - + if (lar) { vol_shade_one_lamp(shi, co, view, lar, lacol); add_v3_v3(scatter_col, lacol); @@ -578,7 +578,7 @@ void vol_get_scattering(ShadeInput *shi, float scatter_col[3], const float co[3] } } - + /* * The main volumetric integrator, using an emission/absorption/scattering model. * @@ -590,7 +590,7 @@ void vol_get_scattering(ShadeInput *shi, float scatter_col[3], const float co[3] * (radiance added by scattering + radiance added by emission) * beam transmittance/attenuation */ -/* For ease of use, I've also introduced a 'reflection' and 'reflection color' parameter, which isn't +/* For ease of use, I've also introduced a 'reflection' and 'reflection color' parameter, which isn't * physically correct. This works as an RGB tint/gain on out-scattered light, but doesn't affect the light * that is transmitted through the volume. While having wavelength dependent absorption/scattering is more correct, * it also makes it harder to control the overall look of the volume since coloring the outscattered light results @@ -603,57 +603,57 @@ static void volumeintegrate(struct ShadeInput *shi, float col[4], const float co float p[3] = {co[0], co[1], co[2]}; float step_vec[3] = {endco[0] - co[0], endco[1] - co[1], endco[2] - co[2]}; const float stepsize = shi->mat->vol.stepsize; - + float t0 = 0.f; float pt0 = t0; float t1 = normalize_v3(step_vec); /* returns vector length */ - + t0 += stepsize * ((shi->mat->vol.stepsize_type == MA_VOL_STEP_CONSTANT) ? 0.5f : BLI_thread_frand(shi->thread)); p[0] += t0 * step_vec[0]; p[1] += t0 * step_vec[1]; p[2] += t0 * step_vec[2]; mul_v3_fl(step_vec, stepsize); - + for (; t0 < t1; pt0 = t0, t0 += stepsize) { const float density = vol_get_density(shi, p); - + if (density > 0.00001f) { float scatter_col[3] = {0.f, 0.f, 0.f}, emit_col[3]; const float stepd = (t0 - pt0) * density; - + /* transmittance component (alpha) */ vol_get_transmittance_seg(shi, tr, stepsize, co, density); - + if (t0 > t1 * 0.25f) { /* only use depth cutoff after we've traced a little way into the volume */ if (IMB_colormanagement_get_luminance(tr) < shi->mat->vol.depth_cutoff) break; } - + vol_get_emission(shi, emit_col, p); - + if (shi->obi->volume_precache) { float p2[3]; - + p2[0] = p[0] + (step_vec[0] * 0.5f); p2[1] = p[1] + (step_vec[1] * 0.5f); p2[2] = p[2] + (step_vec[2] * 0.5f); - + vol_get_precached_scattering(&R, shi, scatter_col, p2); } else vol_get_scattering(shi, scatter_col, p, shi->view); - + radiance[0] += stepd * tr[0] * (emit_col[0] + scatter_col[0]); radiance[1] += stepd * tr[1] * (emit_col[1] + scatter_col[1]); radiance[2] += stepd * tr[2] * (emit_col[2] + scatter_col[2]); } add_v3_v3(p, step_vec); } - + /* multiply original color (from behind volume) with transmittance over entire distance */ mul_v3_v3v3(col, tr, col); add_v3_v3(col, radiance); - + /* alpha <-- transmission luminance */ col[3] = 1.0f - IMB_colormanagement_get_luminance(tr); } @@ -674,11 +674,11 @@ static void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr, int in if (shi->flippednor) inside_volume = VOL_SHADE_INSIDE; } - + if (ztransp && inside_volume == VOL_SHADE_INSIDE) { MatInside *mi; int render_this = 0; - + /* don't render the backfaces of ztransp volume materials. * * volume shading renders the internal volume from between the @@ -687,33 +687,33 @@ static void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr, int in * the front face. * * Because ztransp renders both front and back faces independently - * this will double up, so here we prevent rendering the backface as well, + * this will double up, so here we prevent rendering the backface as well, * which would otherwise render the volume in between the camera and the backface * --matt */ - + for (mi = R.render_volumes_inside.first; mi; mi = mi->next) { /* weak... */ if (mi->ma == shi->mat) render_this = 1; } if (!render_this) return; } - + if (inside_volume == VOL_SHADE_INSIDE) { startco = shi->camera_co; endco = shi->co; - + if (trace_behind) { if (!ztransp) /* trace behind the volume object */ vol_trace_behind(shi, shi->vlr, endco, col); } else { - /* we're tracing through the volume between the camera + /* we're tracing through the volume between the camera * and a solid surface, so use that pre-shaded radiance */ copy_v4_v4(col, shr->combined); } - + /* shade volume from 'camera' to 1st hit point */ volumeintegrate(shi, col, startco, endco); } @@ -721,10 +721,10 @@ static void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr, int in /* (ray intersect ignores front faces here) */ else if (vol_get_bounds(shi, shi->co, shi->view, hitco, &is, VOL_BOUNDS_DEPTH)) { VlakRen *vlr = (VlakRen *)is.hit.face; - + startco = shi->co; endco = hitco; - + if (!ztransp) { /* if it's another face in the same material */ if (vlr->mat == shi->mat) { @@ -735,24 +735,24 @@ static void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr, int in shade_intersection(shi, col, &is); } } - + /* shade volume from 1st hit point to 2nd hit point */ volumeintegrate(shi, col, startco, endco); } - + if (ztransp) col[3] = col[3] > 1.f ? 1.f : col[3]; else col[3] = 1.f; - + copy_v3_v3(shr->combined, col); shr->alpha = col[3]; - + copy_v3_v3(shr->diff, shr->combined); copy_v3_v3(shr->diffshad, shr->diff); } -/* Traces a shadow through the object, +/* Traces a shadow through the object, * pretty much gets the transmission over a ray path */ void shade_volume_shadow(struct ShadeInput *shi, struct ShadeResult *shr, struct Isect *last_is) { @@ -762,14 +762,14 @@ void shade_volume_shadow(struct ShadeInput *shi, struct ShadeResult *shr, struct const float *startco, *endco; memset(shr, 0, sizeof(ShadeResult)); - - /* if 1st hit normal is facing away from the camera, + + /* if 1st hit normal is facing away from the camera, * then we're inside the volume already. */ if (shi->flippednor) { startco = last_is->start; endco = shi->co; } - + /* trace to find a backface, the other side bounds of the volume */ /* (ray intersect ignores front faces here) */ else if (vol_get_bounds(shi, shi->co, shi->view, hitco, &is, VOL_BOUNDS_DEPTH)) { @@ -784,7 +784,7 @@ void shade_volume_shadow(struct ShadeInput *shi, struct ShadeResult *shr, struct vol_get_transmittance(shi, tr, startco, endco); - + /* if we hit another face in the same volume bounds */ /* shift raytrace coordinates to the hit point, to avoid shading volume twice */ /* due to idiosyncracy in ray_trace_shadow_tra() */ @@ -794,7 +794,7 @@ void shade_volume_shadow(struct ShadeInput *shi, struct ShadeResult *shr, struct shi->vlr = (VlakRen *)is.hit.face; } - + copy_v3_v3(shr->combined, tr); shr->combined[3] = 1.0f - IMB_colormanagement_get_luminance(tr); shr->alpha = shr->combined[3]; @@ -819,14 +819,14 @@ void shade_volume_inside(ShadeInput *shi, ShadeResult *shr) /* XXX: extend to multiple volumes perhaps later */ mat_backup = shi->mat; obi_backup = shi->obi; - + m = R.render_volumes_inside.first; shi->mat = m->ma; shi->obi = m->obi; shi->obr = m->obi->obr; - + volume_trace(shi, shr, VOL_SHADE_INSIDE); - + shr->alpha = shr->alpha + prev_alpha; CLAMP(shr->alpha, 0.0f, 1.0f); diff --git a/source/blender/render/intern/source/voxeldata.c b/source/blender/render/intern/source/voxeldata.c index 0d9f7b197e1..2daa4123536 100644 --- a/source/blender/render/intern/source/voxeldata.c +++ b/source/blender/render/intern/source/voxeldata.c @@ -88,10 +88,10 @@ static size_t vd_resol_size(VoxelData *vd) } static int load_frame_blendervoxel(VoxelData *vd, FILE *fp, int frame) -{ +{ const size_t size = vd_resol_size(vd); size_t offset = sizeof(VoxelDataHeader); - + if (is_vd_res_ok(vd) == false) return 0; @@ -102,7 +102,7 @@ static int load_frame_blendervoxel(VoxelData *vd, FILE *fp, int frame) return 0; if (fread(vd->dataset, sizeof(float), size, fp) != size) return 0; - + vd->cachedframe = frame; vd->ok = 1; return 1; @@ -138,12 +138,12 @@ static int load_frame_raw8(VoxelData *vd, FILE *fp, int frame) vd->dataset = NULL; return 0; } - + for (i = 0; i < size; i++) { vd->dataset[i] = (float)data_c[i] / 255.f; } MEM_freeN(data_c); - + vd->cachedframe = frame; vd->ok = 1; return 1; @@ -160,7 +160,7 @@ static void load_frame_image_sequence(VoxelData *vd, Tex *tex) if (!ima) return; if (iuser.frames == 0) return; - + ima->source = IMA_SRC_SEQUENCE; iuser.framenr = 1 + iuser.offset; @@ -173,13 +173,13 @@ static void load_frame_image_sequence(VoxelData *vd, Tex *tex) } if (!ibuf) return; if (!ibuf->rect_float) IMB_float_from_rect(ibuf); - + vd->flag |= TEX_VD_STILL; vd->resol[0] = ibuf->x; vd->resol[1] = ibuf->y; vd->resol[2] = iuser.frames; vd->dataset = MEM_mapallocN(sizeof(float) * vd_resol_size(vd), "voxel dataset"); - + for (z = 0; z < iuser.frames; z++) { /* get a new ibuf for each frame */ if (z > 0) { @@ -190,7 +190,7 @@ static void load_frame_image_sequence(VoxelData *vd, Tex *tex) if (!ibuf->rect_float) IMB_float_from_rect(ibuf); } rf = ibuf->rect_float; - + for (y = 0; y < ibuf->y; y++) { for (x = 0; x < ibuf->x; x++) { /* currently averaged to monchrome */ @@ -198,7 +198,7 @@ static void load_frame_image_sequence(VoxelData *vd, Tex *tex) rf += 4; } } - + BKE_image_free_anim_ibufs(ima, iuser.framenr); } @@ -211,13 +211,13 @@ static void load_frame_image_sequence(VoxelData *vd, Tex *tex) static int read_voxeldata_header(FILE *fp, struct VoxelData *vd) { VoxelDataHeader *h = (VoxelDataHeader *)MEM_mallocN(sizeof(VoxelDataHeader), "voxel data header"); - + rewind(fp); if (fread(h, sizeof(VoxelDataHeader), 1, fp) != 1) { MEM_freeN(h); return 0; } - + vd->resol[0] = h->resolX; vd->resol[1] = h->resolY; vd->resol[2] = h->resolZ; @@ -231,16 +231,16 @@ static void init_frame_smoke(VoxelData *vd, int cfra) #ifdef WITH_SMOKE Object *ob; ModifierData *md; - + vd->dataset = NULL; if (vd->object == NULL) return; ob = vd->object; - + /* draw code for smoke */ if ((md = (ModifierData *)modifiers_findByType(ob, eModifierType_Smoke))) { SmokeModifierData *smd = (SmokeModifierData *)md; SmokeDomainSettings *sds = smd->domain; - + if (sds && sds->fluid) { BLI_rw_mutex_lock(sds->fluid_mutex, THREAD_LOCK_READ); @@ -356,7 +356,7 @@ static void init_frame_smoke(VoxelData *vd, int cfra) BLI_rw_mutex_unlock(sds->fluid_mutex); } } - + vd->ok = 1; #else // WITH_SMOKE @@ -371,14 +371,14 @@ static void init_frame_hair(VoxelData *vd, int UNUSED(cfra)) { Object *ob; ModifierData *md; - + vd->dataset = NULL; if (vd->object == NULL) return; ob = vd->object; - + if ((md = (ModifierData *)modifiers_findByType(ob, eModifierType_ParticleSystem))) { ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md; - + if (pmd->psys && pmd->psys->clmd) { vd->ok |= BPH_cloth_solver_get_texture_data(ob, pmd->psys->clmd, vd); } @@ -386,16 +386,16 @@ static void init_frame_hair(VoxelData *vd, int UNUSED(cfra)) } void cache_voxeldata(Tex *tex, int scene_frame) -{ +{ VoxelData *vd = tex->vd; FILE *fp; int curframe; char path[sizeof(vd->source_path)]; - + /* only re-cache if dataset needs updating */ if ((vd->flag & TEX_VD_STILL) || (vd->cachedframe == scene_frame)) if (vd->ok) return; - + /* clear out old cache, ready for new */ if (vd->dataset) { MEM_freeN(vd->dataset); @@ -408,9 +408,9 @@ void cache_voxeldata(Tex *tex, int scene_frame) curframe = vd->still_frame; else curframe = scene_frame; - + BLI_strncpy(path, vd->source_path, sizeof(path)); - + /* each type is responsible for setting to true */ vd->ok = false; @@ -428,7 +428,7 @@ void cache_voxeldata(Tex *tex, int scene_frame) BLI_path_abs(path, BKE_main_blendfile_path_from_global()); fp = BLI_fopen(path, "rb"); if (!fp) return; - + if (read_voxeldata_header(fp, vd)) load_frame_blendervoxel(vd, fp, curframe - 1); @@ -438,7 +438,7 @@ void cache_voxeldata(Tex *tex, int scene_frame) BLI_path_abs(path, BKE_main_blendfile_path_from_global()); fp = BLI_fopen(path, "rb"); if (!fp) return; - + load_frame_raw8(vd, fp, curframe); fclose(fp); return; @@ -448,24 +448,24 @@ void cache_voxeldata(Tex *tex, int scene_frame) void make_voxeldata(struct Render *re) { Tex *tex; - + re->i.infostr = IFACE_("Loading voxel datasets"); re->stats_draw(re->sdh, &re->i); - + /* XXX: should be doing only textures used in this render */ for (tex = re->main->tex.first; tex; tex = tex->id.next) { if (tex->id.us && tex->type == TEX_VOXELDATA) { cache_voxeldata(tex, re->r.cfra); } } - + re->i.infostr = NULL; re->stats_draw(re->sdh, &re->i); - + } int voxeldatatex(struct Tex *tex, const float texvec[3], struct TexResult *texres) -{ +{ VoxelData *vd = tex->vd; float co[3], offset[3] = {0.5, 0.5, 0.5}, a; int retval = (vd->data_type == TEX_VD_RGBA_PREMUL) ? TEX_RGB : TEX_INT; @@ -476,7 +476,7 @@ int voxeldatatex(struct Tex *tex, const float texvec[3], struct TexResult *texre texres->tin = 0.0f; return 0; } - + /* scale lookup from 0.0-1.0 (original location) to -1.0, 1.0, consistent with image texture tex coords */ /* in implementation this works backwards, bringing sample locations from -1.0, 1.0 * to the range 0.0, 1.0, before looking up in the voxel structure. */ @@ -531,7 +531,7 @@ int voxeldatatex(struct Tex *tex, const float texvec[3], struct TexResult *texre switch (vd->interp_type) { case TEX_VD_NEARESTNEIGHBOR: *result = BLI_voxel_sample_nearest(dataset, vd->resol, co); - break; + break; case TEX_VD_LINEAR: *result = BLI_voxel_sample_trilinear(dataset, vd->resol, co); break; @@ -548,7 +548,7 @@ int voxeldatatex(struct Tex *tex, const float texvec[3], struct TexResult *texre a = texres->tin; texres->tin *= vd->int_multiplier; BRICONT; - + if (vd->data_type == TEX_VD_RGBA_PREMUL) { /* unmultiply */ if (a>0.001f) { @@ -566,6 +566,6 @@ int voxeldatatex(struct Tex *tex, const float texvec[3], struct TexResult *texre texres->ta = texres->tin; BRICONTRGB; - + return retval; } diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c index 82bb3b9c951..6c11dee5dde 100644 --- a/source/blender/render/intern/source/zbuf.c +++ b/source/blender/render/intern/source/zbuf.c @@ -90,10 +90,10 @@ extern struct Render R; void zbuf_alloc_span(ZSpan *zspan, int rectx, int recty, float clipcrop) { memset(zspan, 0, sizeof(ZSpan)); - + zspan->rectx= rectx; zspan->recty= recty; - + zspan->span1= MEM_mallocN(recty*sizeof(float), "zspan"); zspan->span2= MEM_mallocN(recty*sizeof(float), "zspan"); @@ -123,27 +123,27 @@ static void zbuf_add_to_span(ZSpan *zspan, const float v1[2], const float v2[2]) float *span; float xx1, dx0, xs0; int y, my0, my2; - + if (v1[1]= zspan->recty) return; - + /* clip top */ if (my2>=zspan->recty) my2= zspan->recty-1; /* clip bottom */ if (my0<0) my0= 0; - + if (my0>my2) return; /* if (my0>my2) should still fill in, that way we get spans that skip nicely */ - + xx1= maxv[1]-minv[1]; if (xx1>FLT_EPSILON) { dx0= (minv[0]-maxv[0])/xx1; @@ -153,7 +153,7 @@ static void zbuf_add_to_span(ZSpan *zspan, const float v1[2], const float v2[2]) dx0 = 0.0f; xs0 = min_ff(minv[0], maxv[0]); } - + /* empty span */ if (zspan->maxp1 == NULL) { span= zspan->span1; @@ -196,9 +196,9 @@ static void zbuf_add_to_span(ZSpan *zspan, const float v1[2], const float v2[2]) } } -/*-----------------------------------------------------------*/ +/*-----------------------------------------------------------*/ /* Functions */ -/*-----------------------------------------------------------*/ +/*-----------------------------------------------------------*/ void fillrect(int *rect, int x, int y, int val) { @@ -217,7 +217,7 @@ void fillrect(int *rect, int x, int y, int val) static short cliptestf(float a, float b, float c, float d, float *u1, float *u2) { float p= a + b, q= c + d, r; - + if (p<0.0f) { if (q abs4) c+=2; - + if ( v[1] > abs4) c+=4; else if ( v[1] < -abs4) c+=8; - + if (v[2] < -abs4) c+=16; /* this used to be " if (v[2]<0) ", see clippz() */ else if (v[2]> abs4) c+= 32; - + return c; } @@ -313,10 +313,10 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr, const float *span1, *span2; int *rz, *rm, x, y; int sn1, sn2, rectx, *rectzofs, *rectmaskofs, my0, my2, mask; - + /* init */ zbuf_init_span(zspan); - + /* set spans */ zbuf_add_to_span(zspan, v1, v2); zbuf_add_to_span(zspan, v2, v3); @@ -326,15 +326,15 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr, } else zbuf_add_to_span(zspan, v3, v1); - + /* clipped */ if (zspan->minp2==NULL || zspan->maxp2==NULL) return; my0 = max_ii(zspan->miny1, zspan->miny2); my2 = min_ii(zspan->maxy1, zspan->maxy2); - + if (my2rectx; rectzofs= (int *)(zspan->arectz+rectx*(my2)); @@ -371,33 +371,33 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr, span1= zspan->span2+my2; span2= zspan->span1+my2; } - + for (y=my2; y>=my0; y--, span1--, span2--) { - + sn1= floor(*span1); sn2= floor(*span2); - sn1++; - + sn1++; + if (sn2>=rectx) sn2= rectx-1; if (sn1<0) sn1= 0; - + if (sn2>=sn1) { int intzverg; - + zverg= (double)sn1*zxd + zy0; rz= rectzofs+sn1; rm= rectmaskofs+sn1; ap= apofs+sn1; x= sn2-sn1; - + zverg-= zspan->polygon_offset; - + while (x>=0) { intzverg = round_db_to_int_clamp(zverg); if ( intzverg < *rz) { if (!zspan->rectmask || intzverg > *rm) { - + apn= ap; while (apn) { if (apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= intzverg; apn->mask[0]= mask; break; } @@ -414,13 +414,13 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr, } } zverg+= zxd; - rz++; + rz++; rm++; - ap++; + ap++; x--; } } - + zy0-=zyd; rectzofs-= rectx; rectmaskofs-= rectx; @@ -438,12 +438,12 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], co int dz, vergz, mask, maxtest=0; float dx, dy; float v1[3], v2[3]; - + dx= vec2[0]-vec1[0]; dy= vec2[1]-vec1[1]; - + mask= zspan->mask; - + if (fabsf(dx) > fabsf(dy)) { /* all lines from left to right */ @@ -460,24 +460,24 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], co start= floor(v1[0]); end= start+floor(dx); if (end>=zspan->rectx) end= zspan->rectx-1; - + oldy= floor(v1[1]); dy/= dx; - + vergz= v1[2]; vergz-= zspan->polygon_offset; dz= (v2[2]-v1[2])/dx; if (vergz>0x50000000 && dz>0) maxtest= 1; /* prevent overflow */ - + rectz= (int *)(zspan->arectz+zspan->rectx*(oldy) +start); rectmask= (int *)(zspan->rectmask+zspan->rectx*(oldy) +start); ap= (zspan->apixbuf+ zspan->rectx*(oldy) +start); if (dy<0) ofs= -zspan->rectx; else ofs= zspan->rectx; - + for (x= start; x<=end; x++, rectz++, rectmask++, ap++) { - + y= floor(v1[1]); if (y!=oldy) { oldy= y; @@ -485,11 +485,11 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], co rectmask+= ofs; ap+= ofs; } - + if (x>=0 && y>=0 && yrecty) { if (vergz<*rectz) { if (!zspan->rectmask || vergz>*rectmask) { - + apn= ap; while (apn) { /* loop unrolled */ if (apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= vergz; apn->mask[0]= mask; break; } @@ -506,14 +506,14 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], co } } } - + v1[1]+= dy; if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; else vergz+= dz; } } else { - + /* all lines from top to bottom */ if (vec1[1]=zspan->recty || end<0) return; - + if (end>=zspan->recty) end= zspan->recty-1; - + oldx= floor(v1[0]); dx/= dy; - + vergz= v1[2]; vergz-= zspan->polygon_offset; dz= (v2[2]-v1[2])/dy; @@ -543,12 +543,12 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], co rectz= (int *)( zspan->arectz+ (start)*zspan->rectx+ oldx ); rectmask= (int *)( zspan->rectmask+ (start)*zspan->rectx+ oldx ); ap= (zspan->apixbuf+ zspan->rectx*(start) +oldx); - + if (dx<0) ofs= -1; else ofs= 1; for (y= start; y<=end; y++, rectz+=zspan->rectx, rectmask+=zspan->rectx, ap+=zspan->rectx) { - + x= floor(v1[0]); if (x!=oldx) { oldx= x; @@ -556,11 +556,11 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], co rectmask+= ofs; ap+= ofs; } - + if (x>=0 && y>=0 && xrectx) { if (vergz<*rectz) { if (!zspan->rectmask || vergz>*rectmask) { - + apn= ap; while (apn) { /* loop unrolled */ if (apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= vergz; apn->mask[0]= mask; break; } @@ -577,7 +577,7 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], co } } } - + v1[0]+= dx; if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; else vergz+= dz; @@ -594,10 +594,10 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], cons int dz, vergz, maxtest= 0; float dx, dy; float v1[3], v2[3]; - + dx= vec2[0]-vec1[0]; dy= vec2[1]-vec1[1]; - + if (fabsf(dx) > fabsf(dy)) { /* all lines from left to right */ @@ -614,24 +614,24 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], cons start= floor(v1[0]); end= start+floor(dx); if (end>=zspan->rectx) end= zspan->rectx-1; - + oldy= floor(v1[1]); dy/= dx; - + vergz= floor(v1[2]); dz= floor((v2[2]-v1[2])/dx); if (vergz>0x50000000 && dz>0) maxtest= 1; /* prevent overflow */ - + rectz= zspan->rectz + oldy*zspan->rectx+ start; rectp= zspan->rectp + oldy*zspan->rectx+ start; recto= zspan->recto + oldy*zspan->rectx+ start; rectmask= zspan->rectmask + oldy*zspan->rectx+ start; - + if (dy<0) ofs= -zspan->rectx; else ofs= zspan->rectx; - + for (x= start; x<=end; x++, rectz++, rectp++, recto++, rectmask++) { - + y= floor(v1[1]); if (y!=oldy) { oldy= y; @@ -640,7 +640,7 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], cons recto+= ofs; rectmask+= ofs; } - + if (x>=0 && y>=0 && yrecty) { if (vergz<*rectz) { if (!zspan->rectmask || vergz>*rectmask) { @@ -650,9 +650,9 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], cons } } } - + v1[1]+= dy; - + if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; else vergz+= dz; } @@ -671,26 +671,26 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], cons start= floor(v1[1]); end= start+floor(dy); - + if (end>=zspan->recty) end= zspan->recty-1; - + oldx= floor(v1[0]); dx/= dy; - + vergz= floor(v1[2]); dz= floor((v2[2]-v1[2])/dy); if (vergz>0x50000000 && dz>0) maxtest= 1; /* prevent overflow */ - + rectz= zspan->rectz + start*zspan->rectx+ oldx; rectp= zspan->rectp + start*zspan->rectx+ oldx; recto= zspan->recto + start*zspan->rectx+ oldx; rectmask= zspan->rectmask + start*zspan->rectx+ oldx; - + if (dx<0) ofs= -1; else ofs= 1; for (y= start; y<=end; y++, rectz+=zspan->rectx, rectp+=zspan->rectx, recto+=zspan->rectx, rectmask+=zspan->rectx) { - + x= floor(v1[0]); if (x!=oldx) { oldx= x; @@ -699,7 +699,7 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], cons recto+= ofs; rectmask+= ofs; } - + if (x>=0 && y>=0 && xrectx) { if (vergz<*rectz) { if (!zspan->rectmask || vergz>*rectmask) { @@ -709,7 +709,7 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], cons } } } - + v1[0]+= dx; if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; else vergz+= dz; @@ -724,12 +724,12 @@ static void zbufline_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), con int dz, vergz, maxtest= 0; float dx, dy; float v1[3], v2[3]; - + dx= vec2[0]-vec1[0]; dy= vec2[1]-vec1[1]; - + if (fabsf(dx) > fabsf(dy)) { - + /* all lines from left to right */ if (vec1[0]=zspan->rectx) end= zspan->rectx-1; - + oldy= floor(v1[1]); dy/= dx; - + vergz= floor(v1[2]); dz= floor((v2[2]-v1[2])/dx); if (vergz>0x50000000 && dz>0) maxtest= 1; /* prevent overflow */ - + rectz= zspan->rectz + oldy*zspan->rectx+ start; if (zspan->rectz1) rectz1= zspan->rectz1 + oldy*zspan->rectx+ start; - + if (dy<0) ofs= -zspan->rectx; else ofs= zspan->rectx; - + for (x= start; x<=end; x++, rectz++) { - + y= floor(v1[1]); if (y!=oldy) { oldy= y; rectz+= ofs; if (rectz1) rectz1+= ofs; } - + if (x>=0 && y>=0 && yrecty) { if (vergz < *rectz) { if (rectz1) *rectz1= *rectz; @@ -776,12 +776,12 @@ static void zbufline_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), con else if (rectz1 && vergz < *rectz1) *rectz1= vergz; } - + v1[1]+= dy; - + if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; else vergz+= dz; - + if (rectz1) rectz1++; } } @@ -796,15 +796,15 @@ static void zbufline_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), con copy_v3_v3(v1, vec2); dx= -dx; dy= -dy; } - + start= floor(v1[1]); end= start+floor(dy); - + if (end>=zspan->recty) end= zspan->recty-1; - + oldx= floor(v1[0]); dx/= dy; - + vergz= floor(v1[2]); dz= floor((v2[2]-v1[2])/dy); if (vergz>0x50000000 && dz>0) maxtest= 1; /* prevent overflow */ @@ -812,19 +812,19 @@ static void zbufline_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), con rectz= zspan->rectz + start*zspan->rectx+ oldx; if (zspan->rectz1) rectz1= zspan->rectz1 + start*zspan->rectx+ oldx; - + if (dx<0) ofs= -1; else ofs= 1; - + for (y= start; y<=end; y++, rectz+=zspan->rectx) { - + x= floor(v1[0]); if (x!=oldx) { oldx= x; rectz+= ofs; if (rectz1) rectz1+= ofs; } - + if (x>=0 && y>=0 && xrectx) { if (vergz < *rectz) { if (rectz1) *rectz1= *rectz; @@ -833,11 +833,11 @@ static void zbufline_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), con else if (rectz1 && vergz < *rectz1) *rectz1= vergz; } - + v1[0]+= dx; if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0; else vergz+= dz; - + if (rectz1) rectz1+=zspan->rectx; } @@ -849,29 +849,29 @@ static int clipline(float v1[4], float v2[4]) /* return 0: do not draw */ { float dz, dw, u1=0.0, u2=1.0; float dx, dy, v13; - + dz= v2[2]-v1[2]; dw= v2[3]-v1[3]; - + /* this 1.01 is for clipping x and y just a tinsy larger. that way it is * filled in with zbufwire correctly when rendering in parts. otherwise * you see line endings at edges... */ - + if (cliptestf(-dz, -dw, v1[3], v1[2], &u1, &u2)) { if (cliptestf(dz, -dw, v1[3], -v1[2], &u1, &u2)) { - + dx= v2[0]-v1[0]; dz= 1.01f*(v2[3]-v1[3]); v13= 1.01f*v1[3]; - + if (cliptestf(-dx, -dz, v1[0], v13, &u1, &u2)) { if (cliptestf(dx, -dz, v13, -v1[0], &u1, &u2)) { - + dy= v2[1]-v1[1]; - + if (cliptestf(-dy, -dz, v1[1], v13, &u1, &u2)) { if (cliptestf(dy, -dz, v13, -v1[1], &u1, &u2)) { - + if (u2<1.0f) { v2[0]= v1[0]+u2*dx; v2[1]= v1[1]+u2*dy; @@ -891,14 +891,14 @@ static int clipline(float v1[4], float v2[4]) /* return 0: do not draw */ } } } - + return 0; } void hoco_to_zco(ZSpan *zspan, float zco[3], const float hoco[4]) { float div; - + div= 1.0f/hoco[3]; zco[0]= zspan->zmulx*(1.0f+hoco[0]*div) + zspan->zofsx; zco[1]= zspan->zmuly*(1.0f+hoco[1]*div) + zspan->zofsy; @@ -923,7 +923,7 @@ void zbufclipwire(ZSpan *zspan, int obi, int zvlnr, int ec, and= (c1 & c2 & c3); or= (c1 | c2 | c3); } - + if (or) { /* not in the middle */ if (and) { /* out completely */ return; @@ -979,7 +979,7 @@ void zbufclipwire(ZSpan *zspan, int obi, int zvlnr, int ec, } } } - + return; } } @@ -1307,10 +1307,10 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), const float *span1, *span2; int *rz, *rz1, x, y; int sn1, sn2, rectx, *rectzofs, *rectzofs1= NULL, my0, my2; - + /* init */ zbuf_init_span(zspan); - + /* set spans */ zbuf_add_to_span(zspan, v1, v2); zbuf_add_to_span(zspan, v2, v3); @@ -1318,19 +1318,19 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), zbuf_add_to_span(zspan, v3, v4); zbuf_add_to_span(zspan, v4, v1); } - else + else zbuf_add_to_span(zspan, v3, v1); - + /* clipped */ if (zspan->minp2==NULL || zspan->maxp2==NULL) return; - + my0 = max_ii(zspan->miny1, zspan->miny2); my2 = min_ii(zspan->maxy1, zspan->maxy2); - + // printf("my %d %d\n", my0, my2); if (my2rectx; rectzofs= (zspan->rectz+rectx*my2); if (zspan->rectz1) rectzofs1= (zspan->rectz1+rectx*my2); - + /* correct span */ sn1= (my0 + my2)/2; if (zspan->span1[sn1] < zspan->span2[sn1]) { @@ -1366,22 +1366,22 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), span1= zspan->span2+my2; span2= zspan->span1+my2; } - + for (y=my2; y>=my0; y--, span1--, span2--) { - + sn1= floor(*span1); sn2= floor(*span2); - sn1++; - + sn1++; + if (sn2>=rectx) sn2= rectx-1; if (sn1<0) sn1= 0; - + if (sn2>=sn1) { zverg= (double)sn1*zxd + zy0; rz= rectzofs+sn1; rz1= rectzofs1+sn1; x= sn2-sn1; - + while (x>=0) { int zvergi = round_db_to_int_clamp(zverg); @@ -1394,13 +1394,13 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), *rz1= zvergi; zverg+= zxd; - - rz++; + + rz++; rz1++; x--; } } - + zy0-=zyd; rectzofs-= rectx; if (rectzofs1) rectzofs1-= rectx; @@ -1414,24 +1414,24 @@ void zspan_scanconvert_strand(ZSpan *zspan, void *handle, float *v1, float *v2, float u, v, uxd, uyd, vxd, vyd, uy0, vy0, zxd, zyd, zy0, xx1; const float *span1, *span2; int x, y, sn1, sn2, rectx= zspan->rectx, my0, my2; - + /* init */ zbuf_init_span(zspan); - + /* set spans */ zbuf_add_to_span(zspan, v1, v2); zbuf_add_to_span(zspan, v2, v3); zbuf_add_to_span(zspan, v3, v1); - + /* clipped */ if (zspan->minp2==NULL || zspan->maxp2==NULL) return; - + my0 = max_ii(zspan->miny1, zspan->miny2); my2 = min_ii(zspan->maxy1, zspan->maxy2); - + // printf("my %d %d\n", my0, my2); if (my2span1[sn1] < zspan->span2[sn1]) { @@ -1483,23 +1483,23 @@ void zspan_scanconvert_strand(ZSpan *zspan, void *handle, float *v1, float *v2, span1= zspan->span2+my2; span2= zspan->span1+my2; } - + for (y=my2; y>=my0; y--, span1--, span2--) { - + sn1= floor(*span1); sn2= floor(*span2); - sn1++; - + sn1++; + if (sn2>=rectx) sn2= rectx-1; if (sn1<0) sn1= 0; - + u= (double)sn1*uxd + uy0; v= (double)sn1*vxd + vy0; z= (double)sn1*zxd + zy0; - + for (x= sn1; x<=sn2; x++, u+=uxd, v+=vxd, z+=zxd) func(handle, x, y, u, v, z); - + uy0 -= uyd; vy0 -= vyd; zy0 -= zyd; @@ -1514,30 +1514,30 @@ void zspan_scanconvert(ZSpan *zspan, void *handle, float *v1, float *v2, float * float u, v, uxd, uyd, vxd, vyd, uy0, vy0, xx1; const float *span1, *span2; int i, j, x, y, sn1, sn2, rectx = zspan->rectx, my0, my2; - + /* init */ zbuf_init_span(zspan); - + /* set spans */ zbuf_add_to_span(zspan, v1, v2); zbuf_add_to_span(zspan, v2, v3); zbuf_add_to_span(zspan, v3, v1); - + /* clipped */ if (zspan->minp2==NULL || zspan->maxp2==NULL) return; - + my0 = max_ii(zspan->miny1, zspan->miny2); my2 = min_ii(zspan->maxy1, zspan->maxy2); - + // printf("my %d %d\n", my0, my2); if (my2span1+my2; span2= zspan->span2+my2; - + for (i = 0, y = my2; y >= my0; i++, y--, span1--, span2--) { - + sn1= floor(min_ff(*span1, *span2)); sn2= floor(max_ff(*span1, *span2)); - sn1++; - + sn1++; + if (sn2>=rectx) sn2= rectx-1; if (sn1<0) sn1= 0; - + u = (((double)sn1 * uxd) + uy0) - (i * uyd); v = (((double)sn1 * vxd) + vy0) - (i * vyd); - + for (j = 0, x = sn1; x <= sn2; j++, x++) { func(handle, x, y, u + (j * uxd), v + (j * vxd)); } @@ -1603,7 +1603,7 @@ static void clippyra(float *lambda, float *v1, float *v2, int *b2, int *b3, int { float da, dw, u1=0.0, u2=1.0; float v13; - + lambda[0]= -1.0; lambda[1]= -1.0; @@ -1677,7 +1677,7 @@ static void makevertpyra(float *vez, float *lambda, float **trias, float *v1, fl adr[3]= v1[3]+l1*(v2[3]-v1[3]); } else trias[*b1]= v1; - + (*b1)++; } if (l2!= -1.0f) { @@ -1841,7 +1841,7 @@ void zbufclip(ZSpan *zspan, int obi, int zvlnr, { float *vlzp[32][3], lambda[3][2]; float vez[400], *trias[40]; - + if (c1 | c2 | c3) { /* not in middle */ if (c1 & c2 & c3) { /* completely out */ return; @@ -1864,22 +1864,22 @@ void zbufclip(ZSpan *zspan, int obi, int zvlnr, clipflag[2]= ( (c1 & 12) | (c2 & 12) | (c3 & 12) ); } else clipflag[1]=clipflag[2]= 0; - + for (b=0;b<3;b++) { - + if (clipflag[b]) { - + clvlo= clvl; - + for (v=0; vclipcrop); clippyra(lambda[1], vlzp[v][1], vlzp[v][2], &b2, &b3, arg, zspan->clipcrop); clippyra(lambda[2], vlzp[v][2], vlzp[v][0], &b2, &b3, arg, zspan->clipcrop); @@ -1913,7 +1913,7 @@ void zbufclip(ZSpan *zspan, int obi, int zvlnr, f1+= 4; } } - + vlzp[v][0]= NULL; if (b1>2) { for (b3=3; b3<=b1; b3++) { @@ -1959,7 +1959,7 @@ void zbufclip4(ZSpan *zspan, int obi, int zvlnr, const int c1, const int c2, const int c3, const int c4) { float vez[16]; - + if (c1 | c2 | c3 | c4) { /* not in middle */ if (c1 & c2 & c3 & c4) { /* completely out */ return; @@ -1990,11 +1990,11 @@ static void zmask_rect(int *rectz, int *rectp, int xs, int ys, int neg) int len=0, x, y; int *temprectp; int row1, row2, row3, *curp, *curz; - + temprectp= MEM_dupallocN(rectp); - + /* extend: if pixel is not filled in, we check surrounding pixels and average z value */ - + for (y=1; y<=ys; y++) { /* setup row indices */ row1= (y-2)*xs; @@ -2004,15 +2004,15 @@ static void zmask_rect(int *rectz, int *rectp, int xs, int ys, int neg) row1= row2; else if (y==ys) row3= row2; - + curp= rectp + (y-1)*xs; curz= rectz + (y-1)*xs; - + for (x=0; xlayflag & SCE_LAY_ZMASK) && (rl->layflag & SCE_LAY_NEG_ZMASK); zbuf_make_winmat(&R, winmat); - + samples= (R.osa? R.osa: 1); samples= MIN2(4, samples-pa->sample); @@ -2082,11 +2082,11 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart * zbuffer_part_bounds(R.winx, R.winy, pa, bounds); zbuf_alloc_span(zspan, pa->rectx, pa->recty, R.clipcrop); - + /* needed for transform from hoco to zbuffer co */ zspan->zmulx= ((float)R.winx)/2.0f; zspan->zmuly= ((float)R.winy)/2.0f; - + if (R.osa) { zspan->zofsx= -pa->disprect.xmin - R.jit[pa->sample+zsample][0]; zspan->zofsy= -pa->disprect.ymin - R.jit[pa->sample+zsample][1]; @@ -2102,7 +2102,7 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart * /* to center the sample position */ zspan->zofsx -= 0.5f; zspan->zofsy -= 0.5f; - + /* the buffers */ if (zsample == samples-1) { zspan->rectp= pa->rectp; @@ -2127,7 +2127,7 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart * /* in case zmask we fill Z for objects in lay_zmask first, then clear Z, and then do normal zbuffering */ if (rl->layflag & SCE_LAY_ZMASK) zmaskpass= 1; - + for (; zmaskpass >=0; zmaskpass--) { ma= NULL; @@ -2153,7 +2153,7 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart * } else if (!all_z && !(obi->lay & (lay|lay_zmask))) continue; - + if (obi->flag & R_TRANSFORMED) mul_m4_m4m4(obwinmat, winmat, obi->mat); else @@ -2175,7 +2175,7 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart * nofill= (ma->mode & MA_ONLYCAST) || ((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP)); env= (ma->mode & MA_ENV); wire= (ma->material_type == MA_TYPE_WIRE); - + for (zsample=0; zsamplemode & MA_ZINV || (zmaskpass && neg_zmask)) zspans[zsample].zbuffunc= zbuffillGLinv4; @@ -2187,7 +2187,7 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart * else if (all_z || (obi->lay & lay_zmask)) { env= 1; nofill= 0; - ma= NULL; + ma= NULL; } else { nofill= 1; @@ -2196,7 +2196,7 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart * if (!(vlr->flag & R_HIDDEN) && nofill==0) { unsigned short partclip; - + v1= vlr->v1; v2= vlr->v2; v3= vlr->v3; @@ -2214,7 +2214,7 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart * } if (partclip==0) { - + if (env) zvlnr= -1; else zvlnr= v+1; @@ -2249,7 +2249,7 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart * } } } - + /* clear all z to close value, so it works as mask for next passes (ztra+strand) */ if (zmaskpass) { for (zsample=0; zsampletest_break(re->tbh)) + if ((a & 255)==255 && re->test_break(re->tbh)) break; } @@ -2429,24 +2429,24 @@ void zbuffer_shadow(Render *re, float winmat[4][4], LampRen *lar, int *rectz, in } } - if ((a & 255)==255 && re->test_break(re->tbh)) + if ((a & 255)==255 && re->test_break(re->tbh)) break; } } } - if (re->test_break(re->tbh)) + if (re->test_break(re->tbh)) break; } - + /* merge buffers */ if (lar->buftype==LA_SHADBUF_HALFWAY) { for (a=size*size -1; a>=0; a--) rectz[a]= (rectz[a]>>1) + (zspan.rectz1[a]>>1); - + MEM_freeN(zspan.rectz1); } - + zbuf_free_span(&zspan); } @@ -2458,7 +2458,7 @@ static void zbuffill_sss(ZSpan *zspan, int obi, int zvlnr, int x, y, sn1, sn2, rectx= zspan->rectx, my0, my2; /* init */ zbuf_init_span(zspan); - + /* set spans */ zbuf_add_to_span(zspan, v1, v2); zbuf_add_to_span(zspan, v2, v3); @@ -2466,17 +2466,17 @@ static void zbuffill_sss(ZSpan *zspan, int obi, int zvlnr, zbuf_add_to_span(zspan, v3, v4); zbuf_add_to_span(zspan, v4, v1); } - else + else zbuf_add_to_span(zspan, v3, v1); - + /* clipped */ if (zspan->minp2==NULL || zspan->maxp2==NULL) return; - + my0 = max_ii(zspan->miny1, zspan->miny2); my2 = min_ii(zspan->maxy1, zspan->maxy2); - + if (my2span1[sn1] < zspan->span2[sn1]) { @@ -2506,20 +2506,20 @@ static void zbuffill_sss(ZSpan *zspan, int obi, int zvlnr, span1= zspan->span2+my2; span2= zspan->span1+my2; } - + for (y=my2; y>=my0; y--, span1--, span2--) { sn1= floor(*span1); sn2= floor(*span2); - sn1++; - + sn1++; + if (sn2>=rectx) sn2= rectx-1; if (sn1<0) sn1= 0; - + z= (double)sn1*zxd + zy0; - + for (x= sn1; x<=sn2; x++, z+=zxd) zspan->sss_func(zspan->sss_handle, obi, zvlnr, x, y, z); - + zy0 -= zyd; } } @@ -2537,34 +2537,34 @@ void zbuffer_sss(RenderPart *pa, unsigned int lay, void *handle, void (*func)(vo float ho1[4], ho2[4], ho3[4], ho4[4]={0}; int i, v, zvlnr, c1, c2, c3, c4=0; short nofill=0, env=0, wire=0; - + zbuf_make_winmat(&R, winmat); zbuffer_part_bounds(R.winx, R.winy, pa, bounds); zbuf_alloc_span(&zspan, pa->rectx, pa->recty, R.clipcrop); zspan.sss_handle= handle; zspan.sss_func= func; - + /* needed for transform from hoco to zbuffer co */ zspan.zmulx= ((float)R.winx)/2.0f; zspan.zmuly= ((float)R.winy)/2.0f; - + /* -0.5f to center the sample position */ zspan.zofsx= -pa->disprect.xmin - 0.5f; zspan.zofsy= -pa->disprect.ymin - 0.5f; - + /* filling methods */ zspan.zbuffunc= zbuffill_sss; /* fill front and back zbuffer */ if (pa->rectz) { - fillrect(pa->recto, pa->rectx, pa->recty, 0); - fillrect(pa->rectp, pa->rectx, pa->recty, 0); + fillrect(pa->recto, pa->rectx, pa->recty, 0); + fillrect(pa->rectp, pa->rectx, pa->recty, 0); fillrect(pa->rectz, pa->rectx, pa->recty, 0x7FFFFFFF); } if (pa->rectbackz) { - fillrect(pa->rectbacko, pa->rectx, pa->recty, 0); - fillrect(pa->rectbackp, pa->rectx, pa->recty, 0); + fillrect(pa->rectbacko, pa->rectx, pa->recty, 0); + fillrect(pa->rectbackp, pa->rectx, pa->recty, 0); fillrect(pa->rectbackz, pa->rectx, pa->recty, -0x7FFFFFFF); } @@ -2587,7 +2587,7 @@ void zbuffer_sss(RenderPart *pa, unsigned int lay, void *handle, void (*func)(vo for (v=0; vtotvlak; v++) { if ((v & 255)==0) vlr= obr->vlaknodes[v>>8].vlak; else vlr++; - + if (material_in_material(vlr->mat, sss_ma)) { /* three cases, visible for render, only z values and nothing */ if (obi->lay & lay) { @@ -2602,10 +2602,10 @@ void zbuffer_sss(RenderPart *pa, unsigned int lay, void *handle, void (*func)(vo nofill= 1; ma= NULL; /* otherwise nofill can hang */ } - + if (nofill==0 && wire==0 && env==0) { unsigned short partclip; - + v1= vlr->v1; v2= vlr->v2; v3= vlr->v3; @@ -2638,7 +2638,7 @@ void zbuffer_sss(RenderPart *pa, unsigned int lay, void *handle, void (*func)(vo } } } - + zbuf_free_span(&zspan); } @@ -2653,7 +2653,7 @@ static void copyto_abufz(RenderPart *pa, int *arectz, int *rectmask, int sample) PixStr *ps; int x, y, *rza, *rma; intptr_t *rd; - + if (R.osa==0) { if (!pa->rectz) fillrect(arectz, pa->rectx, pa->recty, 0x7FFFFFFE); @@ -2669,16 +2669,16 @@ static void copyto_abufz(RenderPart *pa, int *arectz, int *rectmask, int sample) fillrect(arectz, pa->rectx, pa->recty, 0x7FFFFFFE); return; } - + rza= arectz; rma= rectmask; rd= pa->rectdaps; sample= (1<recty; y++) { for (x=0; xrectx; x++) { - + *rza= 0x7FFFFFFF; if (rectmask) *rma= 0x7FFFFFFF; if (*rd) { @@ -2691,7 +2691,7 @@ static void copyto_abufz(RenderPart *pa, int *arectz, int *rectmask, int sample) } } } - + rza++; rma++; rd++; @@ -2726,16 +2726,16 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase * zspan= &zspans[zsample]; zbuf_alloc_span(zspan, pa->rectx, pa->recty, re->clipcrop); - + /* needed for transform from hoco to zbuffer co */ zspan->zmulx= ((float)winx)/2.0f; zspan->zmuly= ((float)winy)/2.0f; - + /* the buffers */ zspan->arectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "Arectz"); zspan->apixbuf= APixbuf; zspan->apsmbase= apsmbase; - + if (negzmask) zspan->rectmask= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "Arectmask"); @@ -2759,10 +2759,10 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase * zspan->zofsx -= 0.5f; zspan->zofsy -= 0.5f; } - + /* we use this to test if nothing was filled in */ zvlnr= 0; - + for (i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) { obr= obi->obr; @@ -2783,7 +2783,7 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase * if ((v & 255)==0) vlr= obr->vlaknodes[v>>8].vlak; else vlr++; - + if (vlr->mat!=ma) { ma= vlr->mat; if (shadow) @@ -2791,11 +2791,11 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase * else dofill= (((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP)) && !(ma->mode & MA_ONLYCAST)); } - + if (dofill) { if (!(vlr->flag & R_HIDDEN) && (obi->lay & lay)) { unsigned short partclip; - + v1= vlr->v1; v2= vlr->v2; v3= vlr->v3; @@ -2819,7 +2819,7 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase * zval= mul*(1.0f+ho1[2]/ho1[3]); copy_v3_v3(vec, v1->co); - /* z is negative, otherwise its being clipped */ + /* z is negative, otherwise its being clipped */ vec[2]-= ma->zoffs; projectverto(vec, obwinmat, hoco); fval= mul*(1.0f+hoco[2]/hoco[3]); @@ -2827,7 +2827,7 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase * polygon_offset= (int)fabsf(zval - fval); } else polygon_offset= 0; - + zvlnr= v+1; c1= testclip(ho1); @@ -2839,7 +2839,7 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase * for (zsample=0; zsamplepolygon_offset= polygon_offset; - + if (ma->material_type == MA_TYPE_WIRE) { if (v4) zbufclipwire(zspan, i, zvlnr, vlr->ec, ho1, ho2, ho3, ho4, c1, c2, c3, c4); @@ -2858,16 +2858,16 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase * } } } - if ((v & 255)==255) - if (re->test_break(re->tbh)) - break; + if ((v & 255)==255) + if (re->test_break(re->tbh)) + break; } } } if (re->test_break(re->tbh)) break; } - + for (zsample=0; zsamplearectz); @@ -2875,7 +2875,7 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase * MEM_freeN(zspan->rectmask); zbuf_free_span(zspan); } - + return zvlnr; } @@ -2893,7 +2893,7 @@ static int zbuffer_abuf_render(RenderPart *pa, APixstr *APixbuf, APixstrand *APi jit= &R.mblur_jit[R.i.curblur-1]; else jit= NULL; - + zbuf_make_winmat(&R, winmat); if (rl->layflag & SCE_LAY_ZTRA) @@ -2931,11 +2931,11 @@ void zbuffer_abuf_shadow(Render *re, LampRen *lar, float winmat[4][4], APixstr * static void add_transp_speed(RenderLayer *rl, int offset, float speed[4], float alpha, intptr_t *rdrect) { RenderPass *rpass; - + for (rpass= rl->passes.first; rpass; rpass= rpass->next) { if (STREQ(rpass->name, RE_PASSNAME_VECTOR)) { float *fp= rpass->rect + 4*offset; - + if (speed==NULL) { /* clear */ if (fp[0]==PASS_VECTOR_MAX) fp[0]= 0.0f; @@ -2965,7 +2965,7 @@ static void add_transp_speed(RenderLayer *rl, int offset, float speed[4], float static void add_transp_obindex(RenderLayer *rl, int offset, Object *ob) { RenderPass *rpass; - + for (rpass= rl->passes.first; rpass; rpass= rpass->next) { if (STREQ(rpass->name, RE_PASSNAME_INDEXOB)) { float *fp= rpass->rect + offset; @@ -2978,7 +2978,7 @@ static void add_transp_obindex(RenderLayer *rl, int offset, Object *ob) static void add_transp_material_index(RenderLayer *rl, int offset, Material *mat) { RenderPass *rpass; - + for (rpass= rl->passes.first; rpass; rpass= rpass->next) { if (STREQ(rpass->name, RE_PASSNAME_INDEXMA)) { float *fp= rpass->rect + offset; @@ -2995,11 +2995,11 @@ static void merge_transp_passes(RenderLayer *rl, ShadeResult *shr) RenderPass *rpass; float weight= 1.0f/((float)R.osa); int delta= sizeof(ShadeResult)/4; - + for (rpass= rl->passes.first; rpass; rpass= rpass->next) { float *col = NULL; int pixsize = 3; - + if (STREQ(rpass->name, RE_PASSNAME_RGBA)) { col = shr->col; pixsize = 4; @@ -3049,10 +3049,10 @@ static void merge_transp_passes(RenderLayer *rl, ShadeResult *shr) /* add minimum speed in pixel */ for (samp = 1; sampcombined[3] > 0.0f) { const float *speed = shr_t->winspeed; - + if ( (ABS(speed[0]) + ABS(speed[1]))< (ABS(fp[0]) + ABS(fp[1])) ) { fp[0] = speed[0]; fp[1] = speed[1]; @@ -3068,7 +3068,7 @@ static void merge_transp_passes(RenderLayer *rl, ShadeResult *shr) if (col) { const float *fp= col+delta; int samp; - + for (samp= 1; samp1) { @@ -3085,17 +3085,17 @@ static void merge_transp_passes(RenderLayer *rl, ShadeResult *shr) } } } - + } static void add_transp_passes(RenderLayer *rl, int offset, ShadeResult *shr, float alpha) { RenderPass *rpass; - + for (rpass= rl->passes.first; rpass; rpass= rpass->next) { float *fp, *col= NULL; int pixsize= 3; - + if (STREQ(rpass->name, RE_PASSNAME_Z)) { fp = rpass->rect + offset; if (shr->z < *fp) @@ -3223,23 +3223,23 @@ static void shade_tra_samples_fill(ShadeSample *ssamp, int x, int y, int z, int { ShadeInput *shi= ssamp->shi; float xs, ys; - + ssamp->tot= 0; shade_input_set_triangle(shi, obi, facenr, 1); - + /* officially should always be true... we have no sky info */ if (shi->vlr) { - + /* full osa is only set for OSA renders */ if (shi->vlr->flag & R_FULL_OSA) { short shi_inc= 0, samp; - + for (samp=0; sampflippednor messes up otherwise */ shade_input_set_vertex_normals(shi); - + shi_inc= 1; } } @@ -3277,7 +3277,7 @@ static void shade_tra_samples_fill(ShadeSample *ssamp, int x, int y, int z, int shade_input_set_uv(shi); shade_input_set_normals(shi); } - + /* total sample amount, shi->sample is static set in initialize */ ssamp->tot= shi->sample+1; } @@ -3291,21 +3291,21 @@ static int shade_tra_samples(ShadeSample *ssamp, StrandShadeCache *cache, int x, } shade_tra_samples_fill(ssamp, x, y, row->z, row->obi, row->p, row->mask); - + if (ssamp->tot) { ShadeInput *shi= ssamp->shi; ShadeResult *shr= ssamp->shr; int samp; - + /* if AO? */ shade_samples_do_AO(ssamp); - + /* if shade (all shadepinputs have same passflag) */ if (shi->passflag & ~(SCE_PASS_Z|SCE_PASS_INDEXOB|SCE_PASS_INDEXMA)) { for (samp=0; samptot; samp++, shi++, shr++) { shade_input_set_shade_texco(shi); shade_input_do_shade(shi, shr); - + /* include lamphalos for ztra, since halo layer was added already */ if (R.flag & R_LAMPHALO) if (shi->layflag & SCE_LAY_HALO) @@ -3325,18 +3325,18 @@ static int shade_tra_samples(ShadeSample *ssamp, StrandShadeCache *cache, int x, static int addtosamp_shr(ShadeResult *samp_shr, ShadeSample *ssamp, int addpassflag) { int a, sample, osa = (R.osa? R.osa: 1), retval = osa; - + for (a=0; a < osa; a++, samp_shr++) { ShadeInput *shi= ssamp->shi; ShadeResult *shr= ssamp->shr; - + for (sample=0; sampletot; sample++, shi++, shr++) { - + if (shi->mask & (1<combined[3])*shr->combined[3]; - + addAlphaUnderFloat(samp_shr->combined, shr->combined); - + samp_shr->z = min_ff(samp_shr->z, shr->z); if (addpassflag & SCE_PASS_VECTOR) { @@ -3344,10 +3344,10 @@ static int addtosamp_shr(ShadeResult *samp_shr, ShadeSample *ssamp, int addpassf } /* optim... */ if (addpassflag & ~(SCE_PASS_VECTOR)) { - + if (addpassflag & SCE_PASS_RGBA) addAlphaUnderFloat(samp_shr->col, shr->col); - + if (addpassflag & SCE_PASS_NORMAL) madd_v3_v3fl(samp_shr->nor, shr->nor, fac); @@ -3356,7 +3356,7 @@ static int addtosamp_shr(ShadeResult *samp_shr, ShadeSample *ssamp, int addpassf if (addpassflag & SCE_PASS_DIFFUSE) madd_v3_v3fl(samp_shr->diff, shr->diff, fac); - + if (addpassflag & SCE_PASS_SPEC) madd_v3_v3fl(samp_shr->spec, shr->spec, fac); @@ -3374,17 +3374,17 @@ static int addtosamp_shr(ShadeResult *samp_shr, ShadeSample *ssamp, int addpassf if (addpassflag & SCE_PASS_REFLECT) madd_v3_v3fl(samp_shr->refl, shr->refl, fac); - + if (addpassflag & SCE_PASS_REFRACT) madd_v3_v3fl(samp_shr->refr, shr->refr, fac); - + if (addpassflag & SCE_PASS_MIST) samp_shr->mist= samp_shr->mist+fac*shr->mist; } } } - + if (samp_shr->combined[3]>0.999f) retval--; } return retval; @@ -3396,11 +3396,11 @@ static void reset_sky_speedvectors(RenderPart *pa, RenderLayer *rl, float *rectf /* for all pixels with alpha zero, we re-initialize speed again then */ float *fp, *col; int a; - + fp = RE_RenderLayerGetPass(rl, RE_PASSNAME_VECTOR, R.viewname); if (fp==NULL) return; col= rectf+3; - + for (a= 4*pa->rectx*pa->recty -4; a>=0; a-=4) { if (col[a]==0.0f) { fp[a]= PASS_VECTOR_MAX; @@ -3437,13 +3437,13 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas /* looks nicer for calling code */ if (R.test_break(R.tbh)) return NULL; - + if (R.osa > 16) { /* MAX_OSA */ printf("zbuffer_transp_shade: osa too large\n"); G.is_break = true; return NULL; } - + APixbuf= MEM_callocN(pa->rectx*pa->recty*sizeof(APixstr), "APixbuf"); if (R.totstrand && (rl->layflag & SCE_LAY_STRAND)) { APixbufstrand= MEM_callocN(pa->rectx*pa->recty*sizeof(APixstrand), "APixbufstrand"); @@ -3453,12 +3453,12 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas /* general shader info, passes */ shade_sample_initialize(&ssamp, pa, rl); addpassflag= rl->passflag & ~(SCE_PASS_COMBINED); - + if (R.osa) sampalpha= 1.0f/(float)R.osa; else sampalpha= 1.0f; - + /* fill the Apixbuf */ doztra= zbuffer_abuf_render(pa, APixbuf, APixbufstrand, &apsmbase, rl, sscache); @@ -3479,7 +3479,7 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas /* needed for correct zbuf/index pass */ totfullsample= get_sample_layers(pa, rl, rlpp); - + /* irregular shadowb buffer creation */ if (R.r.mode & R_SHADOW) ISB_create(pa, APixbuf); @@ -3502,26 +3502,26 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas aprect+= offs; aprectstrand+= offs; } - + /* init scanline updates */ rr->renrect.ymin = 0; rr->renrect.ymax = -pa->crop; rr->renlay= rl; - + /* render the tile */ for (y=pa->disprect.ymin+crop; ydisprect.ymax-crop; y++, rr->renrect.ymax++) { pass= passrect; ap= aprect; apstrand= aprectstrand; od= offs; - + if (R.test_break(R.tbh)) break; - + for (x=pa->disprect.xmin+crop; xdisprect.xmax-crop; x++, ap++, apstrand++, pass+=4, od++) { - + if (ap->p[0]==0 && (!APixbufstrand || apstrand->p[0]==0)) { - if (addpassflag & SCE_PASS_VECTOR) + if (addpassflag & SCE_PASS_VECTOR) add_transp_speed(rl, od, NULL, 0.0f, rdrect); } else { @@ -3576,12 +3576,12 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas if (zrow[0].z < zrow[1].z) { SWAP(ZTranspRow, zrow[0], zrow[1]); } - + } else if (totface>2) { qsort(zrow, totface, sizeof(ZTranspRow), vergzvlak); } - + /* front face does index pass for transparent, no AA or filters, but yes FSA */ if (addpassflag & SCE_PASS_INDEXOB) { ObjectRen *obr= R.objectinstance[zrow[totface-1].obi].obr; @@ -3633,11 +3633,11 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas if (R.osa==0) { while (totface>0) { totface--; - + if (shade_tra_samples(&ssamp, sscache, x, y, &zrow[totface], addpassflag)) { filled= addtosamp_shr(samp_shr, &ssamp, addpassflag); addAlphaUnderFloat(pass, ssamp.shr[0].combined); - + if (filled == 0) { if (sscache) unref_strand_samples(sscache, zrow, totface); @@ -3655,13 +3655,13 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas } else { short *sp= (short *)(ztramask+od); - + while (totface>0) { totface--; - + if (shade_tra_samples(&ssamp, sscache, x, y, &zrow[totface], addpassflag)) { filled= addtosamp_shr(samp_shr, &ssamp, addpassflag); - + if (ztramask) *sp |= zrow[totface].mask; if (filled==0) { @@ -3671,7 +3671,7 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas } } } - + /* multisample buffers or filtered mask filling? */ if (pa->fullresult.first) { for (a=0; arectx); alpha+= samp_shr[a].combined[3]; } - + if (addpassflag) { alpha*= sampalpha; - + /* merge all in one, and then add */ merge_transp_passes(rl, samp_shr); add_transp_passes(rl, od, samp_shr, alpha); @@ -3711,7 +3711,7 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas } } } - + aprect+= pa->rectx; aprectstrand+= pa->rectx; passrect+= 4*pa->rectx; -- cgit v1.2.3