diff options
156 files changed, 4151 insertions, 3406 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index f50ef91c978..bd038415772 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,4 @@ +set(Boost_DEBUG TRUE) # ***** BEGIN GPL LICENSE BLOCK ***** # # This program is free software; you can redistribute it and/or @@ -647,10 +648,17 @@ if(UNIX AND NOT APPLE) find_package(OpenImageIO) - set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES}) + set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES}) set(OPENIMAGEIO_LIBPATH) # TODO, remove and reference the absolute path everywhere set(OPENIMAGEIO_DEFINITIONS) + if(WITH_IMAGE_TIFF) + list(APPEND OPENIMAGEIO_LIBRARIES "${TIFF_LIBRARY}") + endif() + if(WITH_IMAGE_OPENEXR) + list(APPEND OPENIMAGEIO_LIBRARIES "${OPENEXR_LIBRARIES}") + endif() + if(NOT OPENIMAGEIO_FOUND) set(WITH_OPENIMAGEIO OFF) set(WITH_CYCLES OFF) diff --git a/build_files/buildbot/config/user-config-i686.py b/build_files/buildbot/config/user-config-i686.py index f7190b3dedb..b07dd505369 100644 --- a/build_files/buildbot/config/user-config-i686.py +++ b/build_files/buildbot/config/user-config-i686.py @@ -97,6 +97,7 @@ WITH_BF_JACK = True # Cycles WITH_BF_CYCLES = True WITH_BF_CYCLES_CUDA_BINARIES = True +BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_13', 'sm_20', 'sm_21', 'sm_30'] WITH_BF_OIIO = True WITH_BF_STATICOIIO = True diff --git a/build_files/buildbot/config/user-config-x86_64.py b/build_files/buildbot/config/user-config-x86_64.py index ac2342057fb..5905a9c29dd 100644 --- a/build_files/buildbot/config/user-config-x86_64.py +++ b/build_files/buildbot/config/user-config-x86_64.py @@ -97,6 +97,7 @@ WITH_BF_JACK = True # Cycles WITH_BF_CYCLES = True WITH_BF_CYCLES_CUDA_BINARIES = True +BF_CYCLES_CUDA_BINARIES_ARCH = ['sm_13', 'sm_20', 'sm_21', 'sm_30'] WITH_BF_OIIO = True WITH_BF_STATICOIIO = True diff --git a/doc/python_api/examples/bpy.types.Object.py b/doc/python_api/examples/bpy.types.Object.py new file mode 100644 index 00000000000..5301797aae2 --- /dev/null +++ b/doc/python_api/examples/bpy.types.Object.py @@ -0,0 +1,27 @@ +""" +Basic Object Operations Example ++++++++++++++++++++++++++++++++ +This script demonstrates basic operations on object like creating new +object, placing it into scene, selecting it and making it active +""" + +import bpy +from mathutils import Matrix + +scene = bpy.context.scene + +# Create new lamp datablock +lamp_data = bpy.data.lamps.new(name="New Lamp", type="POINT") + +# Create new object with out lamp datablock +lamp_object = bpy.data.objects.new(name="New Lamp", object_data=lamp_data) + +# Link lamp object to the scene so it'll appear in this scene +scene.objects.link(lamp_object) + +# Place lamp to specified location +lamp_object.location = (5.0, 5.0, 5.0) + +# And finally select it make active +lamp_object.select = True +scene.objects.active = lamp_object diff --git a/intern/bsp/intern/BSP_CSGMesh_CFIterator.h b/intern/bsp/intern/BSP_CSGMesh_CFIterator.h index cadd3df4360..928d04eda20 100644 --- a/intern/bsp/intern/BSP_CSGMesh_CFIterator.h +++ b/intern/bsp/intern/BSP_CSGMesh_CFIterator.h @@ -127,10 +127,10 @@ BSP_CSGMeshVertexIt_Construct( BSP_CSGMesh_VertexIt * v_it = new BSP_CSGMesh_VertexIt; v_it->mesh = mesh; - if( output->num_elements > 0 ) + if ( output->num_elements > 0 ) v_it->pos = &mesh->VertexSet()[0]; output->it = v_it; -}; +} /** diff --git a/intern/container/intern/CTR_List.cpp b/intern/container/intern/CTR_List.cpp index 2fc7b0261ef..c72d3ccf0d8 100644 --- a/intern/container/intern/CTR_List.cpp +++ b/intern/container/intern/CTR_List.cpp @@ -33,118 +33,95 @@ #include "CTR_List.h" -CTR_Link:: -CTR_Link( -) : +CTR_Link::CTR_Link() : m_next(0), m_prev(0) { } -CTR_Link:: -CTR_Link( - CTR_Link *next, - CTR_Link *prev -) : +CTR_Link::CTR_Link(CTR_Link *next, CTR_Link *prev) : m_next(next), m_prev(prev) { } - CTR_Link * -CTR_Link:: -getNext( -) const { +CTR_Link * +CTR_Link::getNext() const +{ return m_next; } - CTR_Link * -CTR_Link:: -getPrev( -) const { +CTR_Link * +CTR_Link::getPrev() const +{ return m_prev; } - bool -CTR_Link:: -isHead( -) const { +bool +CTR_Link::isHead() const +{ return m_prev == 0; } - bool -CTR_Link:: -isTail( -) const { +bool +CTR_Link::isTail() const +{ return m_next == 0; } - void -CTR_Link:: -insertBefore( - CTR_Link *link -) { - m_next = link; - m_prev = link->m_prev; - m_next->m_prev = this; - m_prev->m_next = this; +void +CTR_Link::insertBefore(CTR_Link *link) +{ + m_next = link; + m_prev = link->m_prev; + m_next->m_prev = this; + m_prev->m_next = this; } - void -CTR_Link:: -insertAfter( - CTR_Link *link -) { - m_next = link->m_next; - m_prev = link; - m_next->m_prev = this; - m_prev->m_next = this; +void +CTR_Link::insertAfter(CTR_Link *link) +{ + m_next = link->m_next; + m_prev = link; + m_next->m_prev = this; + m_prev->m_next = this; } - void -CTR_Link:: -remove( -) { - m_next->m_prev = m_prev; - m_prev->m_next = m_next; +void +CTR_Link::remove() +{ + m_next->m_prev = m_prev; + m_prev->m_next = m_next; } -CTR_List:: -CTR_List( -) : +CTR_List::CTR_List() : m_head(&m_tail, 0), m_tail(0, &m_head) { } - CTR_Link * -CTR_List:: -getHead( -) const { +CTR_Link * +CTR_List:: getHead() const +{ return m_head.getNext(); } - CTR_Link * -CTR_List:: -getTail( -) const { +CTR_Link * +CTR_List::getTail() const +{ return m_tail.getPrev(); } - void -CTR_List:: -addHead( - CTR_Link *link -) { +void +CTR_List::addHead(CTR_Link *link) +{ link->insertAfter(&m_head); } - void -CTR_List:: -addTail( - CTR_Link *link -) { +void +CTR_List::addTail(CTR_Link *link) +{ link->insertBefore(&m_tail); } diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py index 8480b0a5256..3b906bb4bdf 100644 --- a/intern/cycles/blender/addon/ui.py +++ b/intern/cycles/blender/addon/ui.py @@ -488,9 +488,7 @@ class CyclesLamp_PT_lamp(CyclesButtonsPanel, Panel): col = split.column() col.prop(clamp, "cast_shadow") - if lamp.type == 'SPOT': - layout.label(text="Not supported, interpreted as point lamp.") - elif lamp.type == 'HEMI': + if lamp.type == 'HEMI': layout.label(text="Not supported, interpreted as sun lamp.") @@ -509,6 +507,29 @@ class CyclesLamp_PT_nodes(CyclesButtonsPanel, Panel): if not panel_node_draw(layout, lamp, 'OUTPUT_LAMP', 'Surface'): layout.prop(lamp, "color") +class CyclesLamp_PT_spot(CyclesButtonsPanel, Panel): + bl_label = "Spot Shape" + bl_context = "data" + + @classmethod + def poll(cls, context): + lamp = context.lamp + return (lamp and lamp.type == 'SPOT') and CyclesButtonsPanel.poll(context) + + def draw(self, context): + layout = self.layout + + lamp = context.lamp + + split = layout.split() + + col = split.column() + sub = col.column() + sub.prop(lamp, "spot_size", text="Size") + sub.prop(lamp, "spot_blend", text="Blend", slider=True) + + col = split.column() + col.prop(lamp, "show_cone") class CyclesWorld_PT_surface(CyclesButtonsPanel, Panel): bl_label = "Surface" diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index b04e0137e37..cea3b0256bd 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -106,7 +106,9 @@ void BlenderSync::sync_light(BL::Object b_parent, int b_index, BL::Object b_ob, case BL::Lamp::type_SPOT: { BL::SpotLamp b_spot_lamp(b_lamp); light->size = b_spot_lamp.shadow_soft_size(); - light->type = LIGHT_POINT; + light->type = LIGHT_SPOT; + light->spot_angle = b_spot_lamp.spot_size(); + light->spot_smooth = b_spot_lamp.spot_blend(); break; } case BL::Lamp::type_HEMI: { diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index 75cc9115531..130b73a2808 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -106,7 +106,7 @@ static void get_tex_mapping(TextureMapping *mapping, BL::ShaderNodeMapping b_map mapping->max = get_float3(b_mapping.max()); } -static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::ShaderNode b_node) +static ShaderNode *add_node(BL::BlendData b_data, BL::Scene b_scene, ShaderGraph *graph, BL::ShaderNode b_node) { ShaderNode *node = NULL; @@ -343,7 +343,7 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Shader ImageTextureNode *image = new ImageTextureNode(); /* todo: handle generated/builtin images */ if(b_image) - image->filename = blender_absolute_path(b_data, b_image, b_image.filepath()); + image->filename = image_user_file_path(b_image_node.image_user(), b_image, b_scene.frame_current()); image->color_space = ImageTextureNode::color_space_enum[(int)b_image_node.color_space()]; get_tex_mapping(&image->tex_mapping, b_image_node.texture_mapping()); node = image; @@ -354,7 +354,7 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Shader BL::Image b_image(b_env_node.image()); EnvironmentTextureNode *env = new EnvironmentTextureNode(); if(b_image) - env->filename = blender_absolute_path(b_data, b_image, b_image.filepath()); + env->filename = image_user_file_path(b_env_node.image_user(), b_image, b_scene.frame_current()); env->color_space = EnvironmentTextureNode::color_space_enum[(int)b_env_node.color_space()]; env->projection = EnvironmentTextureNode::projection_enum[(int)b_env_node.projection()]; get_tex_mapping(&env->tex_mapping, b_env_node.texture_mapping()); @@ -530,7 +530,7 @@ static void set_default_value(ShaderInput *input, BL::NodeSocket sock) } } -static void add_nodes(BL::BlendData b_data, ShaderGraph *graph, BL::ShaderNodeTree b_ntree, PtrSockMap& sockets_map) +static void add_nodes(BL::BlendData b_data, BL::Scene b_scene, ShaderGraph *graph, BL::ShaderNodeTree b_ntree, PtrSockMap& sockets_map) { /* add nodes */ BL::ShaderNodeTree::nodes_iterator b_node; @@ -578,10 +578,10 @@ static void add_nodes(BL::BlendData b_data, ShaderGraph *graph, BL::ShaderNodeTr set_default_value(proxy->inputs[0], b_output->group_socket()); } - add_nodes(b_data, graph, b_group_ntree, group_sockmap); + add_nodes(b_data, b_scene, graph, b_group_ntree, group_sockmap); } else { - ShaderNode *node = add_node(b_data, graph, BL::ShaderNode(*b_node)); + ShaderNode *node = add_node(b_data, b_scene, graph, BL::ShaderNode(*b_node)); if(node) { BL::Node::inputs_iterator b_input; @@ -671,7 +671,7 @@ void BlenderSync::sync_materials() PtrSockMap sock_to_node; BL::ShaderNodeTree b_ntree(b_mat->node_tree()); - add_nodes(b_data, graph, b_ntree, sock_to_node); + add_nodes(b_data, b_scene, graph, b_ntree, sock_to_node); } else { ShaderNode *closure, *out; @@ -712,7 +712,7 @@ void BlenderSync::sync_world() PtrSockMap sock_to_node; BL::ShaderNodeTree b_ntree(b_world.node_tree()); - add_nodes(b_data, graph, b_ntree, sock_to_node); + add_nodes(b_data, b_scene, graph, b_ntree, sock_to_node); } else if(b_world) { ShaderNode *closure, *out; @@ -771,7 +771,7 @@ void BlenderSync::sync_lamps() PtrSockMap sock_to_node; BL::ShaderNodeTree b_ntree(b_lamp->node_tree()); - add_nodes(b_data, graph, b_ntree, sock_to_node); + add_nodes(b_data, b_scene, graph, b_ntree, sock_to_node); } else { ShaderNode *closure, *out; diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h index b01fa81ee40..b9c60738b36 100644 --- a/intern/cycles/blender/blender_util.h +++ b/intern/cycles/blender/blender_util.h @@ -53,6 +53,7 @@ int rna_Object_is_deform_modified(void *ob, void *scene, int settings); void BLI_timestr(double _time, char *str); void rna_ColorRamp_eval(void *coba, float position, float color[4]); void rna_Scene_frame_set(void *scene, int frame, float subframe); +void BKE_image_user_file_path(void *iuser, void *ima, int cfra, char *path); } @@ -101,6 +102,13 @@ static inline bool BKE_object_is_deform_modified(BL::Object self, BL::Scene scen return rna_Object_is_deform_modified(self.ptr.data, scene.ptr.data, (preview)? (1<<0): (1<<1))? true: false; } +static inline string image_user_file_path(BL::ImageUser iuser, BL::Image ima, int cfra) +{ + char filepath[1024]; + BKE_image_user_file_path(iuser.ptr.data, ima.ptr.data, cfra, filepath); + return string(filepath); +} + static inline void scene_frame_set(BL::Scene scene, int frame) { rna_Scene_frame_set(scene.ptr.data, frame, 0.0f); diff --git a/intern/cycles/kernel/kernel_emission.h b/intern/cycles/kernel/kernel_emission.h index 0ef1425e68a..881d25ad7ba 100644 --- a/intern/cycles/kernel/kernel_emission.h +++ b/intern/cycles/kernel/kernel_emission.h @@ -104,13 +104,8 @@ __device bool direct_emission(KernelGlobals *kg, ShaderData *sd, int lindex, float mis_weight = power_heuristic(pdf, bsdf_pdf); light_eval *= mis_weight; } - /* todo: clean up these weights */ - else if(ls.shader & SHADER_AREA_LIGHT) - light_eval *= 0.25f; /* area lamp */ - else if(ls.t != FLT_MAX) - light_eval *= 0.25f*M_1_PI_F; /* point lamp */ - bsdf_eval_mul(eval, light_eval/pdf); + bsdf_eval_mul(eval, light_eval*(ls.eval_fac/pdf)); if(bsdf_eval_is_zero(eval)) return false; diff --git a/intern/cycles/kernel/kernel_light.h b/intern/cycles/kernel/kernel_light.h index e9e7fbd4ca1..a056cd71bb1 100644 --- a/intern/cycles/kernel/kernel_light.h +++ b/intern/cycles/kernel/kernel_light.h @@ -23,6 +23,7 @@ typedef struct LightSample { float3 D; float3 Ng; float t; + float eval_fac; int object; int prim; int shader; @@ -189,6 +190,7 @@ __device void regular_light_sample(KernelGlobals *kg, int point, ls->Ng = D; ls->D = -D; ls->t = FLT_MAX; + ls->eval_fac = 1.0f; } #ifdef __BACKGROUND_MIS__ else if(type == LIGHT_BACKGROUND) { @@ -199,6 +201,7 @@ __device void regular_light_sample(KernelGlobals *kg, int point, ls->Ng = D; ls->D = -D; ls->t = FLT_MAX; + ls->eval_fac = 1.0f; } #endif else { @@ -212,6 +215,36 @@ __device void regular_light_sample(KernelGlobals *kg, int point, ls->P += sphere_light_sample(P, ls->P, size, randu, randv); ls->Ng = normalize(P - ls->P); + ls->eval_fac = 0.25f*M_1_PI_F; + } + else if(type == LIGHT_SPOT) { + float4 data2 = kernel_tex_fetch(__light_data, point*LIGHT_SIZE + 2); + float size = data1.y; + + /* spot light */ + if(size > 0.0f) + ls->P += sphere_light_sample(P, ls->P, size, randu, randv); + + float3 dir = make_float3(data1.z, data1.w, data2.x); + float3 I = normalize(P - ls->P); + + float spot_angle = data2.y; + float spot_smooth = data2.z; + + float eval_fac = dot(dir, I); + + if(eval_fac <= spot_angle) { + eval_fac = 0.0f; + } + else { + float t = eval_fac - spot_angle; + + if(t < spot_smooth && spot_smooth != 0.0f) + eval_fac *= smoothstepf(t/spot_smooth); + } + + ls->Ng = I; + ls->eval_fac = eval_fac*0.25f*M_1_PI_F; } else { /* area light */ @@ -224,6 +257,7 @@ __device void regular_light_sample(KernelGlobals *kg, int point, ls->P += area_light_sample(axisu, axisv, randu, randv); ls->Ng = D; + ls->eval_fac = 0.25f; } ls->t = 0.0f; @@ -262,6 +296,7 @@ __device void triangle_light_sample(KernelGlobals *kg, int prim, int object, ls->prim = prim; ls->t = 0.0f; ls->type = LIGHT_AREA; + ls->eval_fac = 1.0f; #ifdef __INSTANCING__ /* instance transform */ diff --git a/intern/cycles/kernel/kernel_shader.h b/intern/cycles/kernel/kernel_shader.h index 8e0d36705ad..53a41d58e20 100644 --- a/intern/cycles/kernel/kernel_shader.h +++ b/intern/cycles/kernel/kernel_shader.h @@ -520,7 +520,7 @@ __device float3 shader_emissive_eval(KernelGlobals *kg, ShaderData *sd) if(CLOSURE_IS_EMISSION(sc->type)) { #ifdef __OSL__ - eval += OSLShader::emissive_eval(sd)*sc->weight; + eval += OSLShader::emissive_eval(sd, sc)*sc->weight; #else eval += svm_emissive_eval(sd, sc)*sc->weight; #endif @@ -624,7 +624,7 @@ __device float3 shader_volume_eval_phase(KernelGlobals *kg, ShaderData *sd, if(CLOSURE_IS_VOLUME(sc->type)) { #ifdef __OSL__ - eval += OSLShader::volume_eval_phase(sd, omega_in, omega_out); + eval += OSLShader::volume_eval_phase(sd, sc, omega_in, omega_out); #else eval += volume_eval_phase(sd, sc, omega_in, omega_out); #endif diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h index a64c850d35a..4fd57a5f2b3 100644 --- a/intern/cycles/kernel/kernel_types.h +++ b/intern/cycles/kernel/kernel_types.h @@ -39,6 +39,9 @@ CCL_NAMESPACE_BEGIN #ifdef __KERNEL_CPU__ #define __KERNEL_SHADING__ #define __KERNEL_ADV_SHADING__ +#ifdef WITH_OSL +#define __OSL__ +#endif #endif #ifdef __KERNEL_CUDA__ @@ -107,7 +110,6 @@ CCL_NAMESPACE_BEGIN #endif //#define __MULTI_LIGHT__ -//#define __OSL__ //#define __SOBOL_FULL_SCREEN__ //#define __QBVH__ @@ -283,7 +285,8 @@ typedef enum LightType { LIGHT_DISTANT, LIGHT_BACKGROUND, LIGHT_AREA, - LIGHT_AO + LIGHT_AO, + LIGHT_SPOT } LightType; /* Camera Type */ diff --git a/intern/cycles/kernel/osl/background.cpp b/intern/cycles/kernel/osl/background.cpp index c35119ae9cf..81812a46b6c 100644 --- a/intern/cycles/kernel/osl/background.cpp +++ b/intern/cycles/kernel/osl/background.cpp @@ -48,17 +48,17 @@ using namespace OSL; /// class GenericBackgroundClosure : public BackgroundClosure { public: - GenericBackgroundClosure() { } + GenericBackgroundClosure() {} - void setup() {}; + void setup() {}; - size_t memsize () const { return sizeof(*this); } + size_t memsize() const { return sizeof(*this); } - const char *name () const { return "background"; } + const char *name() const { return "background"; } - void print_on (std::ostream &out) const { - out << name() << " ()"; - } + void print_on(std::ostream &out) const { + out << name() << " ()"; + } }; @@ -72,27 +72,29 @@ public: /// class HoldoutClosure : ClosurePrimitive { public: - HoldoutClosure () : ClosurePrimitive (Holdout) { } + HoldoutClosure () : ClosurePrimitive(Holdout) {} - void setup() {}; + void setup() {}; - size_t memsize () const { return sizeof(*this); } + size_t memsize() const { return sizeof(*this); } - const char *name () const { return "holdout"; } + const char *name() const { return "holdout"; } - void print_on (std::ostream &out) const { - out << name() << " ()"; - } + void print_on(std::ostream &out) const { + out << name() << " ()"; + } }; ClosureParam closure_background_params[] = { - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM(GenericBackgroundClosure) }; + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(GenericBackgroundClosure) +}; CLOSURE_PREPARE(closure_background_prepare, GenericBackgroundClosure) ClosureParam closure_holdout_params[] = { - CLOSURE_FINISH_PARAM(HoldoutClosure) }; + CLOSURE_FINISH_PARAM(HoldoutClosure) +}; CLOSURE_PREPARE(closure_holdout_prepare, HoldoutClosure) diff --git a/intern/cycles/kernel/osl/bsdf_ashikhmin_velvet.cpp b/intern/cycles/kernel/osl/bsdf_ashikhmin_velvet.cpp index a38c5b55cf5..cb6be6959f5 100644 --- a/intern/cycles/kernel/osl/bsdf_ashikhmin_velvet.cpp +++ b/intern/cycles/kernel/osl/bsdf_ashikhmin_velvet.cpp @@ -36,138 +36,142 @@ #include "osl_closures.h" +#include "util_math.h" + CCL_NAMESPACE_BEGIN using namespace OSL; class AshikhminVelvetClosure : public BSDFClosure { public: - Vec3 m_N; - float m_sigma; - float m_invsigma2; - - AshikhminVelvetClosure() : BSDFClosure(Labels::DIFFUSE) { } - - void setup() - { - m_sigma = std::max(m_sigma, 0.01f); - m_invsigma2 = 1.0f/(m_sigma * m_sigma); - } - - bool mergeable (const ClosurePrimitive *other) const { - const AshikhminVelvetClosure *comp = (const AshikhminVelvetClosure *)other; - return m_N == comp->m_N && m_sigma == comp->m_sigma && - BSDFClosure::mergeable(other); - } - - size_t memsize () const { return sizeof(*this); } - - const char *name () const { return "ashikhmin_velvet"; } - - void print_on (std::ostream &out) const - { - out << name() << " ("; - out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), "; - out << m_sigma; - out << ")"; - } - - float albedo (const Vec3 &omega_out) const - { + Vec3 m_N; + float m_sigma; + float m_invsigma2; + + AshikhminVelvetClosure() : BSDFClosure(Labels::DIFFUSE) {} + + void setup() + { + m_sigma = max(m_sigma, 0.01f); + m_invsigma2 = 1.0f / (m_sigma * m_sigma); + } + + bool mergeable(const ClosurePrimitive *other) const { + const AshikhminVelvetClosure *comp = (const AshikhminVelvetClosure *)other; + return m_N == comp->m_N && m_sigma == comp->m_sigma && + BSDFClosure::mergeable(other); + } + + size_t memsize() const { return sizeof(*this); } + + const char *name() const { return "ashikhmin_velvet"; } + + void print_on(std::ostream &out) const + { + out << name() << " ("; + out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), "; + out << m_sigma; + out << ")"; + } + + float albedo(const Vec3 &omega_out) const + { return 1.0f; - } - - Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - float cosNO = m_N.dot(omega_out); - float cosNI = m_N.dot(omega_in); - if (cosNO > 0 && cosNI > 0) { - Vec3 H = omega_in + omega_out; - H.normalize(); - - float cosNH = m_N.dot(H); - float cosHO = fabsf(omega_out.dot(H)); - - float cosNHdivHO = cosNH / cosHO; - cosNHdivHO = std::max(cosNHdivHO, 0.00001f); - - float fac1 = 2 * fabsf(cosNHdivHO * cosNO); - float fac2 = 2 * fabsf(cosNHdivHO * cosNI); - - float sinNH2 = 1 - cosNH * cosNH; - float sinNH4 = sinNH2 * sinNH2; - float cotangent2 = (cosNH * cosNH) / sinNH2; - - float D = expf(-cotangent2 * m_invsigma2) * m_invsigma2 * float(M_1_PI) / sinNH4; - float G = std::min(1.0f, std::min(fac1, fac2)); // TODO: derive G from D analytically - - float out = 0.25f * (D * G) / cosNO; - - pdf = 0.5f * (float) M_1_PI; - return Color3 (out, out, out); - } - return Color3 (0, 0, 0); - } - - Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - return Color3 (0, 0, 0); - } - - ustring sample (const Vec3 &Ng, - const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, - float randu, float randv, - Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, - float &pdf, Color3 &eval) const - { - // we are viewing the surface from above - send a ray out with uniform - // distribution over the hemisphere - sample_uniform_hemisphere (m_N, omega_out, randu, randv, omega_in, pdf); - if (Ng.dot(omega_in) > 0) { - Vec3 H = omega_in + omega_out; - H.normalize(); - - float cosNI = m_N.dot(omega_in); - float cosNO = m_N.dot(omega_out); - float cosNH = m_N.dot(H); - float cosHO = fabsf(omega_out.dot(H)); - - float cosNHdivHO = cosNH / cosHO; - cosNHdivHO = std::max(cosNHdivHO, 0.00001f); - - float fac1 = 2 * fabsf(cosNHdivHO * cosNO); - float fac2 = 2 * fabsf(cosNHdivHO * cosNI); - - float sinNH2 = 1 - cosNH * cosNH; - float sinNH4 = sinNH2 * sinNH2; - float cotangent2 = (cosNH * cosNH) / sinNH2; - - float D = expf(-cotangent2 * m_invsigma2) * m_invsigma2 * float(M_1_PI) / sinNH4; - float G = std::min(1.0f, std::min(fac1, fac2)); // TODO: derive G from D analytically - - float power = 0.25f * (D * G) / cosNO; - - eval.setValue(power, power, power); - - // TODO: find a better approximation for the retroreflective bounce - domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx; - domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy; - domega_in_dx *= 125; - domega_in_dy *= 125; - } else - pdf = 0; - return Labels::REFLECT; - } + } + + Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + float cosNO = m_N.dot(omega_out); + float cosNI = m_N.dot(omega_in); + if (cosNO > 0 && cosNI > 0) { + Vec3 H = omega_in + omega_out; + H.normalize(); + + float cosNH = m_N.dot(H); + float cosHO = fabsf(omega_out.dot(H)); + + float cosNHdivHO = cosNH / cosHO; + cosNHdivHO = max(cosNHdivHO, 0.00001f); + + float fac1 = 2 * fabsf(cosNHdivHO * cosNO); + float fac2 = 2 * fabsf(cosNHdivHO * cosNI); + + float sinNH2 = 1 - cosNH * cosNH; + float sinNH4 = sinNH2 * sinNH2; + float cotangent2 = (cosNH * cosNH) / sinNH2; + + float D = expf(-cotangent2 * m_invsigma2) * m_invsigma2 * float(M_1_PI) / sinNH4; + float G = min(1.0f, min(fac1, fac2)); // TODO: derive G from D analytically + + float out = 0.25f * (D * G) / cosNO; + + pdf = 0.5f * (float) M_1_PI; + return Color3(out, out, out); + } + return Color3(0, 0, 0); + } + + Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + return Color3(0, 0, 0); + } + + ustring sample(const Vec3 &Ng, + const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, + float randu, float randv, + Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, + float &pdf, Color3 &eval) const + { + // we are viewing the surface from above - send a ray out with uniform + // distribution over the hemisphere + sample_uniform_hemisphere(m_N, omega_out, randu, randv, omega_in, pdf); + if (Ng.dot(omega_in) > 0) { + Vec3 H = omega_in + omega_out; + H.normalize(); + + float cosNI = m_N.dot(omega_in); + float cosNO = m_N.dot(omega_out); + float cosNH = m_N.dot(H); + float cosHO = fabsf(omega_out.dot(H)); + + float cosNHdivHO = cosNH / cosHO; + cosNHdivHO = max(cosNHdivHO, 0.00001f); + + float fac1 = 2 * fabsf(cosNHdivHO * cosNO); + float fac2 = 2 * fabsf(cosNHdivHO * cosNI); + + float sinNH2 = 1 - cosNH * cosNH; + float sinNH4 = sinNH2 * sinNH2; + float cotangent2 = (cosNH * cosNH) / sinNH2; + + float D = expf(-cotangent2 * m_invsigma2) * m_invsigma2 * float(M_1_PI) / sinNH4; + float G = min(1.0f, min(fac1, fac2)); // TODO: derive G from D analytically + + float power = 0.25f * (D * G) / cosNO; + + eval.setValue(power, power, power); + + // TODO: find a better approximation for the retroreflective bounce + domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx; + domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy; + domega_in_dx *= 125; + domega_in_dy *= 125; + } + else + pdf = 0; + return Labels::REFLECT; + } }; ClosureParam bsdf_ashikhmin_velvet_params[] = { - CLOSURE_VECTOR_PARAM(AshikhminVelvetClosure, m_N), - CLOSURE_FLOAT_PARAM (AshikhminVelvetClosure, m_sigma), - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM(AshikhminVelvetClosure) }; + CLOSURE_VECTOR_PARAM(AshikhminVelvetClosure, m_N), + CLOSURE_FLOAT_PARAM(AshikhminVelvetClosure, m_sigma), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(AshikhminVelvetClosure) +}; CLOSURE_PREPARE(bsdf_ashikhmin_velvet_prepare, AshikhminVelvetClosure) diff --git a/intern/cycles/kernel/osl/bsdf_diffuse.cpp b/intern/cycles/kernel/osl/bsdf_diffuse.cpp index 0d4b3fa471f..582ac01d959 100644 --- a/intern/cycles/kernel/osl/bsdf_diffuse.cpp +++ b/intern/cycles/kernel/osl/bsdf_diffuse.cpp @@ -36,143 +36,149 @@ #include "osl_closures.h" +#include "util_math.h" + CCL_NAMESPACE_BEGIN using namespace OSL; class DiffuseClosure : public BSDFClosure { public: - Vec3 m_N; - - DiffuseClosure() : BSDFClosure(Labels::DIFFUSE) { } - - void setup() {}; - - bool mergeable (const ClosurePrimitive *other) const { - const DiffuseClosure *comp = (const DiffuseClosure *)other; - return m_N == comp->m_N && BSDFClosure::mergeable(other); - } - - size_t memsize () const { return sizeof(*this); } - - const char *name () const { return "diffuse"; } - - void print_on (std::ostream &out) const - { - out << name() << " ((" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "))"; - } - - float albedo (const Vec3 &omega_out) const - { - return 1.0f; - } - - Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - float cos_pi = std::max(m_N.dot(omega_in),0.0f) * (float) M_1_PI; - pdf = cos_pi; - return Color3 (cos_pi, cos_pi, cos_pi); - } - - Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - return Color3 (0, 0, 0); - } - - ustring sample (const Vec3 &Ng, - const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, - float randu, float randv, - Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, - float &pdf, Color3 &eval) const - { - // we are viewing the surface from the right side - send a ray out with cosine - // distribution over the hemisphere - sample_cos_hemisphere (m_N, omega_out, randu, randv, omega_in, pdf); - if (Ng.dot(omega_in) > 0) { - eval.setValue(pdf, pdf, pdf); - // TODO: find a better approximation for the diffuse bounce - domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx; - domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy; - domega_in_dx *= 125; - domega_in_dy *= 125; - } else - pdf = 0; - return Labels::REFLECT; - } + Vec3 m_N; + + DiffuseClosure() : BSDFClosure(Labels::DIFFUSE) {} + + void setup() {}; + + bool mergeable(const ClosurePrimitive *other) const { + const DiffuseClosure *comp = (const DiffuseClosure *)other; + return m_N == comp->m_N && BSDFClosure::mergeable(other); + } + + size_t memsize() const { return sizeof(*this); } + + const char *name() const { return "diffuse"; } + + void print_on(std::ostream &out) const + { + out << name() << " ((" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "))"; + } + + float albedo(const Vec3 &omega_out) const + { + return 1.0f; + } + + Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + float cos_pi = max(m_N.dot(omega_in), 0.0f) * (float) M_1_PI; + pdf = cos_pi; + return Color3(cos_pi, cos_pi, cos_pi); + } + + Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + return Color3(0, 0, 0); + } + + ustring sample(const Vec3 &Ng, + const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, + float randu, float randv, + Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, + float &pdf, Color3 &eval) const + { + // we are viewing the surface from the right side - send a ray out with cosine + // distribution over the hemisphere + sample_cos_hemisphere(m_N, omega_out, randu, randv, omega_in, pdf); + if (Ng.dot(omega_in) > 0) { + eval.setValue(pdf, pdf, pdf); + // TODO: find a better approximation for the diffuse bounce + domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx; + domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy; + domega_in_dx *= 125; + domega_in_dy *= 125; + } + else + pdf = 0; + return Labels::REFLECT; + } }; class TranslucentClosure : public BSDFClosure { public: - Vec3 m_N; - - TranslucentClosure() : BSDFClosure(Labels::DIFFUSE, Back) { } - - void setup() {}; - - bool mergeable (const ClosurePrimitive *other) const { - const TranslucentClosure *comp = (const TranslucentClosure *)other; - return m_N == comp->m_N && BSDFClosure::mergeable(other); - } - - size_t memsize () const { return sizeof(*this); } - - const char *name () const { return "translucent"; } - - void print_on (std::ostream &out) const - { - out << name() << " ((" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "))"; - } - - Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - return Color3 (0, 0, 0); - } - - float albedo (const Vec3 &omega_out) const - { - return 1.0f; - } - - Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - float cos_pi = std::max(-m_N.dot(omega_in), 0.0f) * (float) M_1_PI; - pdf = cos_pi; - return Color3 (cos_pi, cos_pi, cos_pi); - } - - ustring sample (const Vec3 &Ng, - const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, - float randu, float randv, - Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, - float &pdf, Color3 &eval) const - { - // we are viewing the surface from the right side - send a ray out with cosine - // distribution over the hemisphere - sample_cos_hemisphere (-m_N, omega_out, randu, randv, omega_in, pdf); - if (Ng.dot(omega_in) < 0) { - eval.setValue(pdf, pdf, pdf); - // TODO: find a better approximation for the diffuse bounce - domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx; - domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy; - domega_in_dx *= -125; - domega_in_dy *= -125; - } else - pdf = 0; - return Labels::TRANSMIT; - } + Vec3 m_N; + + TranslucentClosure() : BSDFClosure(Labels::DIFFUSE, Back) {} + + void setup() {}; + + bool mergeable(const ClosurePrimitive *other) const { + const TranslucentClosure *comp = (const TranslucentClosure *)other; + return m_N == comp->m_N && BSDFClosure::mergeable(other); + } + + size_t memsize() const { return sizeof(*this); } + + const char *name() const { return "translucent"; } + + void print_on(std::ostream &out) const + { + out << name() << " ((" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "))"; + } + + Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + return Color3(0, 0, 0); + } + + float albedo(const Vec3 &omega_out) const + { + return 1.0f; + } + + Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + float cos_pi = max(-m_N.dot(omega_in), 0.0f) * (float) M_1_PI; + pdf = cos_pi; + return Color3(cos_pi, cos_pi, cos_pi); + } + + ustring sample(const Vec3 &Ng, + const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, + float randu, float randv, + Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, + float &pdf, Color3 &eval) const + { + // we are viewing the surface from the right side - send a ray out with cosine + // distribution over the hemisphere + sample_cos_hemisphere(-m_N, omega_out, randu, randv, omega_in, pdf); + if (Ng.dot(omega_in) < 0) { + eval.setValue(pdf, pdf, pdf); + // TODO: find a better approximation for the diffuse bounce + domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx; + domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy; + domega_in_dx *= -125; + domega_in_dy *= -125; + } + else + pdf = 0; + return Labels::TRANSMIT; + } }; ClosureParam bsdf_diffuse_params[] = { - CLOSURE_VECTOR_PARAM (DiffuseClosure, m_N), - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM (DiffuseClosure) }; + CLOSURE_VECTOR_PARAM(DiffuseClosure, m_N), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(DiffuseClosure) +}; ClosureParam bsdf_translucent_params[] = { - CLOSURE_VECTOR_PARAM (TranslucentClosure, m_N), - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM (TranslucentClosure) }; + CLOSURE_VECTOR_PARAM(TranslucentClosure, m_N), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(TranslucentClosure) +}; CLOSURE_PREPARE(bsdf_diffuse_prepare, DiffuseClosure) CLOSURE_PREPARE(bsdf_translucent_prepare, TranslucentClosure) diff --git a/intern/cycles/kernel/osl/bsdf_microfacet.cpp b/intern/cycles/kernel/osl/bsdf_microfacet.cpp index d87268da81e..09730d8c3e1 100644 --- a/intern/cycles/kernel/osl/bsdf_microfacet.cpp +++ b/intern/cycles/kernel/osl/bsdf_microfacet.cpp @@ -52,85 +52,85 @@ CCL_NAMESPACE_BEGIN template <int Refractive = 0> class MicrofacetGGXClosure : public BSDFClosure { public: - Vec3 m_N; - float m_ag; // width parameter (roughness) - float m_eta; // index of refraction (for fresnel term) - MicrofacetGGXClosure() : BSDFClosure(Labels::GLOSSY, Refractive ? Back : Front) { m_eta = 1.0f; } + Vec3 m_N; + float m_ag; // width parameter (roughness) + float m_eta; // index of refraction (for fresnel term) + MicrofacetGGXClosure() : BSDFClosure(Labels::GLOSSY, Refractive ? Back : Front) { m_eta = 1.0f; } - void setup() + void setup() { m_ag = clamp(m_ag, 1e-5f, 1.0f); } - bool mergeable (const ClosurePrimitive *other) const { - const MicrofacetGGXClosure *comp = (const MicrofacetGGXClosure *)other; - return m_N == comp->m_N && m_ag == comp->m_ag && - m_eta == comp->m_eta && BSDFClosure::mergeable(other); - } + bool mergeable(const ClosurePrimitive *other) const { + const MicrofacetGGXClosure *comp = (const MicrofacetGGXClosure *)other; + return m_N == comp->m_N && m_ag == comp->m_ag && + m_eta == comp->m_eta && BSDFClosure::mergeable(other); + } - size_t memsize () const { return sizeof(*this); } + size_t memsize() const { return sizeof(*this); } - const char *name () const { - return Refractive ? "microfacet_ggx_refraction" : "microfacet_ggx"; - } + const char *name() const { + return Refractive ? "microfacet_ggx_refraction" : "microfacet_ggx"; + } - void print_on (std::ostream &out) const { - out << name() << " ("; - out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), "; - out << m_ag << ", "; - out << m_eta; - out << ")"; - } + void print_on(std::ostream &out) const { + out << name() << " ("; + out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), "; + out << m_ag << ", "; + out << m_eta; + out << ")"; + } - float albedo (const Vec3 &omega_out) const - { + float albedo(const Vec3 &omega_out) const + { return 1.0f; - } - - Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - if (Refractive == 1) return Color3 (0, 0, 0); - float cosNO = m_N.dot(omega_out); - float cosNI = m_N.dot(omega_in); - if (cosNI > 0 && cosNO > 0) { - // get half vector - Vec3 Hr = omega_in + omega_out; - Hr.normalize(); - // eq. 20: (F*G*D)/(4*in*on) - // eq. 33: first we calculate D(m) with m=Hr: - float alpha2 = m_ag * m_ag; - float cosThetaM = m_N.dot(Hr); - float cosThetaM2 = cosThetaM * cosThetaM; - float tanThetaM2 = (1 - cosThetaM2) / cosThetaM2; - float cosThetaM4 = cosThetaM2 * cosThetaM2; - float D = alpha2 / ((float) M_PI * cosThetaM4 * (alpha2 + tanThetaM2) * (alpha2 + tanThetaM2)); - // eq. 34: now calculate G1(i,m) and G1(o,m) - float G1o = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNO * cosNO) / (cosNO * cosNO))); - float G1i = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNI * cosNI) / (cosNI * cosNI))); - float G = G1o * G1i; - float out = (G * D) * 0.25f / cosNO; - // eq. 24 - float pm = D * cosThetaM; - // convert into pdf of the sampled direction - // eq. 38 - but see also: - // eq. 17 in http://www.graphics.cornell.edu/~bjw/wardnotes.pdf - pdf = pm * 0.25f / Hr.dot(omega_out); - return Color3 (out, out, out); - } - return Color3 (0, 0, 0); - } - - Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - if (Refractive == 0) return Color3 (0, 0, 0); - float cosNO = m_N.dot(omega_out); - float cosNI = m_N.dot(omega_in); - if (cosNO <= 0 || cosNI >= 0) - return Color3 (0, 0, 0); // vectors on same side -- not possible - // compute half-vector of the refraction (eq. 16) - Vec3 ht = -(m_eta * omega_in + omega_out); - Vec3 Ht = ht; Ht.normalize(); - float cosHO = Ht.dot(omega_out); + } + + Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + if (Refractive == 1) return Color3(0, 0, 0); + float cosNO = m_N.dot(omega_out); + float cosNI = m_N.dot(omega_in); + if (cosNI > 0 && cosNO > 0) { + // get half vector + Vec3 Hr = omega_in + omega_out; + Hr.normalize(); + // eq. 20: (F*G*D)/(4*in*on) + // eq. 33: first we calculate D(m) with m=Hr: + float alpha2 = m_ag * m_ag; + float cosThetaM = m_N.dot(Hr); + float cosThetaM2 = cosThetaM * cosThetaM; + float tanThetaM2 = (1 - cosThetaM2) / cosThetaM2; + float cosThetaM4 = cosThetaM2 * cosThetaM2; + float D = alpha2 / ((float) M_PI * cosThetaM4 * (alpha2 + tanThetaM2) * (alpha2 + tanThetaM2)); + // eq. 34: now calculate G1(i,m) and G1(o,m) + float G1o = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNO * cosNO) / (cosNO * cosNO))); + float G1i = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNI * cosNI) / (cosNI * cosNI))); + float G = G1o * G1i; + float out = (G * D) * 0.25f / cosNO; + // eq. 24 + float pm = D * cosThetaM; + // convert into pdf of the sampled direction + // eq. 38 - but see also: + // eq. 17 in http://www.graphics.cornell.edu/~bjw/wardnotes.pdf + pdf = pm * 0.25f / Hr.dot(omega_out); + return Color3(out, out, out); + } + return Color3(0, 0, 0); + } + + Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + if (Refractive == 0) return Color3(0, 0, 0); + float cosNO = m_N.dot(omega_out); + float cosNI = m_N.dot(omega_in); + if (cosNO <= 0 || cosNI >= 0) + return Color3(0, 0, 0); // vectors on same side -- not possible + // compute half-vector of the refraction (eq. 16) + Vec3 ht = -(m_eta * omega_in + omega_out); + Vec3 Ht = ht; Ht.normalize(); + float cosHO = Ht.dot(omega_out); float cosHI = Ht.dot(omega_in); // eq. 33: first we calculate D(m) with m=Ht: @@ -148,122 +148,123 @@ public: float invHt2 = 1 / ht.dot(ht); pdf = D * fabsf(cosThetaM) * (fabsf(cosHI) * (m_eta * m_eta)) * invHt2; float out = (fabsf(cosHI * cosHO) * (m_eta * m_eta) * (G * D) * invHt2) / cosNO; - return Color3 (out, out, out); - } - - ustring sample (const Vec3 &Ng, - const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, - float randu, float randv, - Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, - float &pdf, Color3 &eval) const - { - float cosNO = m_N.dot(omega_out); - if (cosNO > 0) { - Vec3 X, Y, Z = m_N; - make_orthonormals(Z, X, Y); - // generate a random microfacet normal m - // eq. 35,36: - // we take advantage of cos(atan(x)) == 1/sqrt(1+x^2) - // and sin(atan(x)) == x/sqrt(1+x^2) - float alpha2 = m_ag * m_ag; - float tanThetaM2 = alpha2 * randu / (1 - randu); - float cosThetaM = 1 / sqrtf(1 + tanThetaM2); - float sinThetaM = cosThetaM * sqrtf(tanThetaM2); - float phiM = 2 * float(M_PI) * randv; - Vec3 m = (cosf(phiM) * sinThetaM) * X + - (sinf(phiM) * sinThetaM) * Y + - cosThetaM * Z; - if (Refractive == 0) { - float cosMO = m.dot(omega_out); - if (cosMO > 0) { - // eq. 39 - compute actual reflected direction - omega_in = 2 * cosMO * m - omega_out; - if (Ng.dot(omega_in) > 0) { - // microfacet normal is visible to this ray - // eq. 33 - float cosThetaM2 = cosThetaM * cosThetaM; - float cosThetaM4 = cosThetaM2 * cosThetaM2; - float D = alpha2 / (float(M_PI) * cosThetaM4 * (alpha2 + tanThetaM2) * (alpha2 + tanThetaM2)); - // eq. 24 - float pm = D * cosThetaM; - // convert into pdf of the sampled direction - // eq. 38 - but see also: - // eq. 17 in http://www.graphics.cornell.edu/~bjw/wardnotes.pdf - pdf = pm * 0.25f / cosMO; - // eval BRDF*cosNI - float cosNI = m_N.dot(omega_in); - // eq. 34: now calculate G1(i,m) and G1(o,m) - float G1o = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNO * cosNO) / (cosNO * cosNO))); - float G1i = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNI * cosNI) / (cosNI * cosNI))); - float G = G1o * G1i; - // eq. 20: (F*G*D)/(4*in*on) - float out = (G * D) * 0.25f / cosNO; - eval.setValue(out, out, out); - domega_in_dx = (2 * m.dot(domega_out_dx)) * m - domega_out_dx; - domega_in_dy = (2 * m.dot(domega_out_dy)) * m - domega_out_dy; + return Color3(out, out, out); + } + + ustring sample(const Vec3 &Ng, + const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, + float randu, float randv, + Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, + float &pdf, Color3 &eval) const + { + float cosNO = m_N.dot(omega_out); + if (cosNO > 0) { + Vec3 X, Y, Z = m_N; + make_orthonormals(Z, X, Y); + // generate a random microfacet normal m + // eq. 35,36: + // we take advantage of cos(atan(x)) == 1/sqrt(1+x^2) + // and sin(atan(x)) == x/sqrt(1+x^2) + float alpha2 = m_ag * m_ag; + float tanThetaM2 = alpha2 * randu / (1 - randu); + float cosThetaM = 1 / sqrtf(1 + tanThetaM2); + float sinThetaM = cosThetaM * sqrtf(tanThetaM2); + float phiM = 2 * float(M_PI) * randv; + Vec3 m = (cosf(phiM) * sinThetaM) * X + + (sinf(phiM) * sinThetaM) * Y + + cosThetaM * Z; + if (Refractive == 0) { + float cosMO = m.dot(omega_out); + if (cosMO > 0) { + // eq. 39 - compute actual reflected direction + omega_in = 2 * cosMO * m - omega_out; + if (Ng.dot(omega_in) > 0) { + // microfacet normal is visible to this ray + // eq. 33 + float cosThetaM2 = cosThetaM * cosThetaM; + float cosThetaM4 = cosThetaM2 * cosThetaM2; + float D = alpha2 / (float(M_PI) * cosThetaM4 * (alpha2 + tanThetaM2) * (alpha2 + tanThetaM2)); + // eq. 24 + float pm = D * cosThetaM; + // convert into pdf of the sampled direction + // eq. 38 - but see also: + // eq. 17 in http://www.graphics.cornell.edu/~bjw/wardnotes.pdf + pdf = pm * 0.25f / cosMO; + // eval BRDF*cosNI + float cosNI = m_N.dot(omega_in); + // eq. 34: now calculate G1(i,m) and G1(o,m) + float G1o = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNO * cosNO) / (cosNO * cosNO))); + float G1i = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNI * cosNI) / (cosNI * cosNI))); + float G = G1o * G1i; + // eq. 20: (F*G*D)/(4*in*on) + float out = (G * D) * 0.25f / cosNO; + eval.setValue(out, out, out); + domega_in_dx = (2 * m.dot(domega_out_dx)) * m - domega_out_dx; + domega_in_dy = (2 * m.dot(domega_out_dy)) * m - domega_out_dy; /* disabled for now - gives texture filtering problems */ #if 0 - // Since there is some blur to this reflection, make the - // derivatives a bit bigger. In theory this varies with the - // roughness but the exact relationship is complex and - // requires more ops than are practical. - domega_in_dx *= 10; - domega_in_dy *= 10; + // Since there is some blur to this reflection, make the + // derivatives a bit bigger. In theory this varies with the + // roughness but the exact relationship is complex and + // requires more ops than are practical. + domega_in_dx *= 10; + domega_in_dy *= 10; #endif - } - } - } else { - // CAUTION: the i and o variables are inverted relative to the paper - // eq. 39 - compute actual refractive direction - Vec3 R, dRdx, dRdy; - Vec3 T, dTdx, dTdy; - bool inside; - fresnel_dielectric(m_eta, m, omega_out, domega_out_dx, domega_out_dy, - R, dRdx, dRdy, - T, dTdx, dTdy, - inside); - - if (!inside) { - omega_in = T; - domega_in_dx = dTdx; - domega_in_dy = dTdy; - // eq. 33 - float cosThetaM2 = cosThetaM * cosThetaM; - float cosThetaM4 = cosThetaM2 * cosThetaM2; - float D = alpha2 / (float(M_PI) * cosThetaM4 * (alpha2 + tanThetaM2) * (alpha2 + tanThetaM2)); - // eq. 24 - float pm = D * cosThetaM; - // eval BRDF*cosNI - float cosNI = m_N.dot(omega_in); - // eq. 34: now calculate G1(i,m) and G1(o,m) - float G1o = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNO * cosNO) / (cosNO * cosNO))); - float G1i = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNI * cosNI) / (cosNI * cosNI))); - float G = G1o * G1i; - // eq. 21 - float cosHI = m.dot(omega_in); - float cosHO = m.dot(omega_out); - float Ht2 = m_eta * cosHI + cosHO; - Ht2 *= Ht2; - float out = (fabsf(cosHI * cosHO) * (m_eta * m_eta) * (G * D)) / (cosNO * Ht2); - // eq. 38 and eq. 17 - pdf = pm * (m_eta * m_eta) * fabsf(cosHI) / Ht2; - eval.setValue(out, out, out); + } + } + } + else { + // CAUTION: the i and o variables are inverted relative to the paper + // eq. 39 - compute actual refractive direction + Vec3 R, dRdx, dRdy; + Vec3 T, dTdx, dTdy; + bool inside; + fresnel_dielectric(m_eta, m, omega_out, domega_out_dx, domega_out_dy, + R, dRdx, dRdy, + T, dTdx, dTdy, + inside); + + if (!inside) { + omega_in = T; + domega_in_dx = dTdx; + domega_in_dy = dTdy; + // eq. 33 + float cosThetaM2 = cosThetaM * cosThetaM; + float cosThetaM4 = cosThetaM2 * cosThetaM2; + float D = alpha2 / (float(M_PI) * cosThetaM4 * (alpha2 + tanThetaM2) * (alpha2 + tanThetaM2)); + // eq. 24 + float pm = D * cosThetaM; + // eval BRDF*cosNI + float cosNI = m_N.dot(omega_in); + // eq. 34: now calculate G1(i,m) and G1(o,m) + float G1o = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNO * cosNO) / (cosNO * cosNO))); + float G1i = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNI * cosNI) / (cosNI * cosNI))); + float G = G1o * G1i; + // eq. 21 + float cosHI = m.dot(omega_in); + float cosHO = m.dot(omega_out); + float Ht2 = m_eta * cosHI + cosHO; + Ht2 *= Ht2; + float out = (fabsf(cosHI * cosHO) * (m_eta * m_eta) * (G * D)) / (cosNO * Ht2); + // eq. 38 and eq. 17 + pdf = pm * (m_eta * m_eta) * fabsf(cosHI) / Ht2; + eval.setValue(out, out, out); /* disabled for now - gives texture filtering problems */ #if 0 - // Since there is some blur to this refraction, make the - // derivatives a bit bigger. In theory this varies with the - // roughness but the exact relationship is complex and - // requires more ops than are practical. - domega_in_dx *= 10; - domega_in_dy *= 10; + // Since there is some blur to this refraction, make the + // derivatives a bit bigger. In theory this varies with the + // roughness but the exact relationship is complex and + // requires more ops than are practical. + domega_in_dx *= 10; + domega_in_dy *= 10; #endif - } - } - } - return Refractive ? Labels::TRANSMIT : Labels::REFLECT; - } + } + } + } + return Refractive ? Labels::TRANSMIT : Labels::REFLECT; + } }; // microfacet model with Beckmann facet distribution @@ -271,89 +272,92 @@ public: template <int Refractive = 0> class MicrofacetBeckmannClosure : public BSDFClosure { public: - Vec3 m_N; - float m_ab; // width parameter (roughness) - float m_eta; // index of refraction (for fresnel term) - MicrofacetBeckmannClosure() : BSDFClosure(Labels::GLOSSY, Refractive ? Back : Front) { } + Vec3 m_N; + float m_ab; // width parameter (roughness) + float m_eta; // index of refraction (for fresnel term) + MicrofacetBeckmannClosure() : BSDFClosure(Labels::GLOSSY, Refractive ? Back : Front) { + } - void setup() + void setup() { m_ab = clamp(m_ab, 1e-5f, 1.0f); } - bool mergeable (const ClosurePrimitive *other) const { - const MicrofacetBeckmannClosure *comp = (const MicrofacetBeckmannClosure *)other; - return m_N == comp->m_N && m_ab == comp->m_ab && - m_eta == comp->m_eta && BSDFClosure::mergeable(other); - } - - size_t memsize () const { return sizeof(*this); } - - const char * name () const { - return Refractive ? "microfacet_beckmann_refraction" - : "microfacet_beckmann"; - } - - void print_on (std::ostream &out) const - { - out << name() << " ("; - out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), "; - out << m_ab << ", "; - out << m_eta; - out << ")"; - } - - float albedo (const Vec3 &omega_out) const - { + bool mergeable(const ClosurePrimitive *other) const { + const MicrofacetBeckmannClosure *comp = (const MicrofacetBeckmannClosure *)other; + return m_N == comp->m_N && m_ab == comp->m_ab && + m_eta == comp->m_eta && BSDFClosure::mergeable(other); + } + + size_t memsize() const { + return sizeof(*this); + } + + const char *name() const { + return Refractive ? "microfacet_beckmann_refraction" + : "microfacet_beckmann"; + } + + void print_on(std::ostream &out) const + { + out << name() << " ("; + out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), "; + out << m_ab << ", "; + out << m_eta; + out << ")"; + } + + float albedo(const Vec3 &omega_out) const + { return 1.0f; - } - - Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - if (Refractive == 1) return Color3 (0, 0, 0); - float cosNO = m_N.dot(omega_out); - float cosNI = m_N.dot(omega_in); - if (cosNO > 0 && cosNI > 0) { - // get half vector - Vec3 Hr = omega_in + omega_out; - Hr.normalize(); - // eq. 20: (F*G*D)/(4*in*on) - // eq. 25: first we calculate D(m) with m=Hr: - float alpha2 = m_ab * m_ab; - float cosThetaM = m_N.dot(Hr); - float cosThetaM2 = cosThetaM * cosThetaM; - float tanThetaM2 = (1 - cosThetaM2) / cosThetaM2; - float cosThetaM4 = cosThetaM2 * cosThetaM2; - float D = expf(-tanThetaM2 / alpha2) / (float(M_PI) * alpha2 * cosThetaM4); - // eq. 26, 27: now calculate G1(i,m) and G1(o,m) - float ao = 1 / (m_ab * sqrtf((1 - cosNO * cosNO) / (cosNO * cosNO))); - float ai = 1 / (m_ab * sqrtf((1 - cosNI * cosNI) / (cosNI * cosNI))); - float G1o = ao < 1.6f ? (3.535f * ao + 2.181f * ao * ao) / (1 + 2.276f * ao + 2.577f * ao * ao) : 1.0f; - float G1i = ai < 1.6f ? (3.535f * ai + 2.181f * ai * ai) / (1 + 2.276f * ai + 2.577f * ai * ai) : 1.0f; - float G = G1o * G1i; - float out = (G * D) * 0.25f / cosNO; - // eq. 24 - float pm = D * cosThetaM; - // convert into pdf of the sampled direction - // eq. 38 - but see also: - // eq. 17 in http://www.graphics.cornell.edu/~bjw/wardnotes.pdf - pdf = pm * 0.25f / Hr.dot(omega_out); - return Color3 (out, out, out); - } - return Color3 (0, 0, 0); - } - - Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - if (Refractive == 0) return Color3 (0, 0, 0); - float cosNO = m_N.dot(omega_out); - float cosNI = m_N.dot(omega_in); - if (cosNO <= 0 || cosNI >= 0) - return Color3 (0, 0, 0); - // compute half-vector of the refraction (eq. 16) - Vec3 ht = -(m_eta * omega_in + omega_out); - Vec3 Ht = ht; Ht.normalize(); - float cosHO = Ht.dot(omega_out); + } + + Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + if (Refractive == 1) return Color3(0, 0, 0); + float cosNO = m_N.dot(omega_out); + float cosNI = m_N.dot(omega_in); + if (cosNO > 0 && cosNI > 0) { + // get half vector + Vec3 Hr = omega_in + omega_out; + Hr.normalize(); + // eq. 20: (F*G*D)/(4*in*on) + // eq. 25: first we calculate D(m) with m=Hr: + float alpha2 = m_ab * m_ab; + float cosThetaM = m_N.dot(Hr); + float cosThetaM2 = cosThetaM * cosThetaM; + float tanThetaM2 = (1 - cosThetaM2) / cosThetaM2; + float cosThetaM4 = cosThetaM2 * cosThetaM2; + float D = expf(-tanThetaM2 / alpha2) / (float(M_PI) * alpha2 * cosThetaM4); + // eq. 26, 27: now calculate G1(i,m) and G1(o,m) + float ao = 1 / (m_ab * sqrtf((1 - cosNO * cosNO) / (cosNO * cosNO))); + float ai = 1 / (m_ab * sqrtf((1 - cosNI * cosNI) / (cosNI * cosNI))); + float G1o = ao < 1.6f ? (3.535f * ao + 2.181f * ao * ao) / (1 + 2.276f * ao + 2.577f * ao * ao) : 1.0f; + float G1i = ai < 1.6f ? (3.535f * ai + 2.181f * ai * ai) / (1 + 2.276f * ai + 2.577f * ai * ai) : 1.0f; + float G = G1o * G1i; + float out = (G * D) * 0.25f / cosNO; + // eq. 24 + float pm = D * cosThetaM; + // convert into pdf of the sampled direction + // eq. 38 - but see also: + // eq. 17 in http://www.graphics.cornell.edu/~bjw/wardnotes.pdf + pdf = pm * 0.25f / Hr.dot(omega_out); + return Color3(out, out, out); + } + return Color3(0, 0, 0); + } + + Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + if (Refractive == 0) return Color3(0, 0, 0); + float cosNO = m_N.dot(omega_out); + float cosNI = m_N.dot(omega_in); + if (cosNO <= 0 || cosNI >= 0) + return Color3(0, 0, 0); + // compute half-vector of the refraction (eq. 16) + Vec3 ht = -(m_eta * omega_in + omega_out); + Vec3 Ht = ht; Ht.normalize(); + float cosHO = Ht.dot(omega_out); float cosHI = Ht.dot(omega_in); // eq. 33: first we calculate D(m) with m=Ht: @@ -373,156 +377,161 @@ public: float invHt2 = 1 / ht.dot(ht); pdf = D * fabsf(cosThetaM) * (fabsf(cosHI) * (m_eta * m_eta)) * invHt2; float out = (fabsf(cosHI * cosHO) * (m_eta * m_eta) * (G * D) * invHt2) / cosNO; - return Color3 (out, out, out); - } - - ustring sample (const Vec3 &Ng, - const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, - float randu, float randv, - Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, - float &pdf, Color3 &eval) const - { - float cosNO = m_N.dot(omega_out); - if (cosNO > 0) { - Vec3 X, Y, Z = m_N; - make_orthonormals(Z, X, Y); - // generate a random microfacet normal m - // eq. 35,36: - // we take advantage of cos(atan(x)) == 1/sqrt(1+x^2) - // and sin(atan(x)) == x/sqrt(1+x^2) - float alpha2 = m_ab * m_ab; - float tanThetaM = sqrtf(-alpha2 * logf(1 - randu)); - float cosThetaM = 1 / sqrtf(1 + tanThetaM * tanThetaM); - float sinThetaM = cosThetaM * tanThetaM; - float phiM = 2 * float(M_PI) * randv; - Vec3 m = (cosf(phiM) * sinThetaM) * X + - (sinf(phiM) * sinThetaM) * Y + - cosThetaM * Z; - if (Refractive == 0) { - float cosMO = m.dot(omega_out); - if (cosMO > 0) { - // eq. 39 - compute actual reflected direction - omega_in = 2 * cosMO * m - omega_out; - if (Ng.dot(omega_in) > 0) { - // microfacet normal is visible to this ray - // eq. 25 - float cosThetaM2 = cosThetaM * cosThetaM; - float tanThetaM2 = tanThetaM * tanThetaM; - float cosThetaM4 = cosThetaM2 * cosThetaM2; - float D = expf(-tanThetaM2 / alpha2) / (float(M_PI) * alpha2 * cosThetaM4); - // eq. 24 - float pm = D * cosThetaM; - // convert into pdf of the sampled direction - // eq. 38 - but see also: - // eq. 17 in http://www.graphics.cornell.edu/~bjw/wardnotes.pdf - pdf = pm * 0.25f / cosMO; - // Eval BRDF*cosNI - float cosNI = m_N.dot(omega_in); - // eq. 26, 27: now calculate G1(i,m) and G1(o,m) - float ao = 1 / (m_ab * sqrtf((1 - cosNO * cosNO) / (cosNO * cosNO))); - float ai = 1 / (m_ab * sqrtf((1 - cosNI * cosNI) / (cosNI * cosNI))); - float G1o = ao < 1.6f ? (3.535f * ao + 2.181f * ao * ao) / (1 + 2.276f * ao + 2.577f * ao * ao) : 1.0f; - float G1i = ai < 1.6f ? (3.535f * ai + 2.181f * ai * ai) / (1 + 2.276f * ai + 2.577f * ai * ai) : 1.0f; - float G = G1o * G1i; - // eq. 20: (F*G*D)/(4*in*on) - float out = (G * D) * 0.25f / cosNO; - eval.setValue(out, out, out); - domega_in_dx = (2 * m.dot(domega_out_dx)) * m - domega_out_dx; - domega_in_dy = (2 * m.dot(domega_out_dy)) * m - domega_out_dy; + return Color3(out, out, out); + } + + ustring sample(const Vec3 &Ng, + const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, + float randu, float randv, + Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, + float &pdf, Color3 &eval) const + { + float cosNO = m_N.dot(omega_out); + if (cosNO > 0) { + Vec3 X, Y, Z = m_N; + make_orthonormals(Z, X, Y); + // generate a random microfacet normal m + // eq. 35,36: + // we take advantage of cos(atan(x)) == 1/sqrt(1+x^2) + // and sin(atan(x)) == x/sqrt(1+x^2) + float alpha2 = m_ab * m_ab; + float tanThetaM = sqrtf(-alpha2 * logf(1 - randu)); + float cosThetaM = 1 / sqrtf(1 + tanThetaM * tanThetaM); + float sinThetaM = cosThetaM * tanThetaM; + float phiM = 2 * float(M_PI) * randv; + Vec3 m = (cosf(phiM) * sinThetaM) * X + + (sinf(phiM) * sinThetaM) * Y + + cosThetaM * Z; + if (Refractive == 0) { + float cosMO = m.dot(omega_out); + if (cosMO > 0) { + // eq. 39 - compute actual reflected direction + omega_in = 2 * cosMO * m - omega_out; + if (Ng.dot(omega_in) > 0) { + // microfacet normal is visible to this ray + // eq. 25 + float cosThetaM2 = cosThetaM * cosThetaM; + float tanThetaM2 = tanThetaM * tanThetaM; + float cosThetaM4 = cosThetaM2 * cosThetaM2; + float D = expf(-tanThetaM2 / alpha2) / (float(M_PI) * alpha2 * cosThetaM4); + // eq. 24 + float pm = D * cosThetaM; + // convert into pdf of the sampled direction + // eq. 38 - but see also: + // eq. 17 in http://www.graphics.cornell.edu/~bjw/wardnotes.pdf + pdf = pm * 0.25f / cosMO; + // Eval BRDF*cosNI + float cosNI = m_N.dot(omega_in); + // eq. 26, 27: now calculate G1(i,m) and G1(o,m) + float ao = 1 / (m_ab * sqrtf((1 - cosNO * cosNO) / (cosNO * cosNO))); + float ai = 1 / (m_ab * sqrtf((1 - cosNI * cosNI) / (cosNI * cosNI))); + float G1o = ao < 1.6f ? (3.535f * ao + 2.181f * ao * ao) / (1 + 2.276f * ao + 2.577f * ao * ao) : 1.0f; + float G1i = ai < 1.6f ? (3.535f * ai + 2.181f * ai * ai) / (1 + 2.276f * ai + 2.577f * ai * ai) : 1.0f; + float G = G1o * G1i; + // eq. 20: (F*G*D)/(4*in*on) + float out = (G * D) * 0.25f / cosNO; + eval.setValue(out, out, out); + domega_in_dx = (2 * m.dot(domega_out_dx)) * m - domega_out_dx; + domega_in_dy = (2 * m.dot(domega_out_dy)) * m - domega_out_dy; /* disabled for now - gives texture filtering problems */ #if 0 - // Since there is some blur to this reflection, make the - // derivatives a bit bigger. In theory this varies with the - // roughness but the exact relationship is complex and - // requires more ops than are practical. - domega_in_dx *= 10; - domega_in_dy *= 10; + // Since there is some blur to this reflection, make the + // derivatives a bit bigger. In theory this varies with the + // roughness but the exact relationship is complex and + // requires more ops than are practical. + domega_in_dx *= 10; + domega_in_dy *= 10; #endif - } - } - } else { - // CAUTION: the i and o variables are inverted relative to the paper - // eq. 39 - compute actual refractive direction - Vec3 R, dRdx, dRdy; - Vec3 T, dTdx, dTdy; - bool inside; - fresnel_dielectric(m_eta, m, omega_out, domega_out_dx, domega_out_dy, - R, dRdx, dRdy, - T, dTdx, dTdy, - inside); - if (!inside) { - omega_in = T; - domega_in_dx = dTdx; - domega_in_dy = dTdy; - // eq. 33 - float cosThetaM2 = cosThetaM * cosThetaM; - float tanThetaM2 = tanThetaM * tanThetaM; - float cosThetaM4 = cosThetaM2 * cosThetaM2; - float D = expf(-tanThetaM2 / alpha2) / (float(M_PI) * alpha2 * cosThetaM4); - // eq. 24 - float pm = D * cosThetaM; - // eval BRDF*cosNI - float cosNI = m_N.dot(omega_in); - // eq. 26, 27: now calculate G1(i,m) and G1(o,m) - float ao = 1 / (m_ab * sqrtf((1 - cosNO * cosNO) / (cosNO * cosNO))); - float ai = 1 / (m_ab * sqrtf((1 - cosNI * cosNI) / (cosNI * cosNI))); - float G1o = ao < 1.6f ? (3.535f * ao + 2.181f * ao * ao) / (1 + 2.276f * ao + 2.577f * ao * ao) : 1.0f; - float G1i = ai < 1.6f ? (3.535f * ai + 2.181f * ai * ai) / (1 + 2.276f * ai + 2.577f * ai * ai) : 1.0f; - float G = G1o * G1i; - // eq. 21 - float cosHI = m.dot(omega_in); - float cosHO = m.dot(omega_out); - float Ht2 = m_eta * cosHI + cosHO; - Ht2 *= Ht2; - float out = (fabsf(cosHI * cosHO) * (m_eta * m_eta) * (G * D)) / (cosNO * Ht2); - // eq. 38 and eq. 17 - pdf = pm * (m_eta * m_eta) * fabsf(cosHI) / Ht2; - eval.setValue(out, out, out); + } + } + } + else { + // CAUTION: the i and o variables are inverted relative to the paper + // eq. 39 - compute actual refractive direction + Vec3 R, dRdx, dRdy; + Vec3 T, dTdx, dTdy; + bool inside; + fresnel_dielectric(m_eta, m, omega_out, domega_out_dx, domega_out_dy, + R, dRdx, dRdy, + T, dTdx, dTdy, + inside); + if (!inside) { + omega_in = T; + domega_in_dx = dTdx; + domega_in_dy = dTdy; + // eq. 33 + float cosThetaM2 = cosThetaM * cosThetaM; + float tanThetaM2 = tanThetaM * tanThetaM; + float cosThetaM4 = cosThetaM2 * cosThetaM2; + float D = expf(-tanThetaM2 / alpha2) / (float(M_PI) * alpha2 * cosThetaM4); + // eq. 24 + float pm = D * cosThetaM; + // eval BRDF*cosNI + float cosNI = m_N.dot(omega_in); + // eq. 26, 27: now calculate G1(i,m) and G1(o,m) + float ao = 1 / (m_ab * sqrtf((1 - cosNO * cosNO) / (cosNO * cosNO))); + float ai = 1 / (m_ab * sqrtf((1 - cosNI * cosNI) / (cosNI * cosNI))); + float G1o = ao < 1.6f ? (3.535f * ao + 2.181f * ao * ao) / (1 + 2.276f * ao + 2.577f * ao * ao) : 1.0f; + float G1i = ai < 1.6f ? (3.535f * ai + 2.181f * ai * ai) / (1 + 2.276f * ai + 2.577f * ai * ai) : 1.0f; + float G = G1o * G1i; + // eq. 21 + float cosHI = m.dot(omega_in); + float cosHO = m.dot(omega_out); + float Ht2 = m_eta * cosHI + cosHO; + Ht2 *= Ht2; + float out = (fabsf(cosHI * cosHO) * (m_eta * m_eta) * (G * D)) / (cosNO * Ht2); + // eq. 38 and eq. 17 + pdf = pm * (m_eta * m_eta) * fabsf(cosHI) / Ht2; + eval.setValue(out, out, out); /* disabled for now - gives texture filtering problems */ #if 0 - // Since there is some blur to this refraction, make the - // derivatives a bit bigger. In theory this varies with the - // roughness but the exact relationship is complex and - // requires more ops than are practical. - domega_in_dx *= 10; - domega_in_dy *= 10; + // Since there is some blur to this refraction, make the + // derivatives a bit bigger. In theory this varies with the + // roughness but the exact relationship is complex and + // requires more ops than are practical. + domega_in_dx *= 10; + domega_in_dy *= 10; #endif - } - } - } - return Refractive ? Labels::TRANSMIT : Labels::REFLECT; - } + } + } + } + return Refractive ? Labels::TRANSMIT : Labels::REFLECT; + } }; ClosureParam bsdf_microfacet_ggx_params[] = { - CLOSURE_VECTOR_PARAM(MicrofacetGGXClosure<0>, m_N), - CLOSURE_FLOAT_PARAM (MicrofacetGGXClosure<0>, m_ag), - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM(MicrofacetGGXClosure<0>) }; + CLOSURE_VECTOR_PARAM(MicrofacetGGXClosure<0>, m_N), + CLOSURE_FLOAT_PARAM(MicrofacetGGXClosure<0>, m_ag), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(MicrofacetGGXClosure<0>) +}; ClosureParam bsdf_microfacet_ggx_refraction_params[] = { - CLOSURE_VECTOR_PARAM(MicrofacetGGXClosure<1>, m_N), - CLOSURE_FLOAT_PARAM (MicrofacetGGXClosure<1>, m_ag), - CLOSURE_FLOAT_PARAM (MicrofacetGGXClosure<1>, m_eta), - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM(MicrofacetGGXClosure<1>) }; + CLOSURE_VECTOR_PARAM(MicrofacetGGXClosure<1>, m_N), + CLOSURE_FLOAT_PARAM(MicrofacetGGXClosure<1>, m_ag), + CLOSURE_FLOAT_PARAM(MicrofacetGGXClosure<1>, m_eta), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(MicrofacetGGXClosure<1>) +}; ClosureParam bsdf_microfacet_beckmann_params[] = { - CLOSURE_VECTOR_PARAM(MicrofacetBeckmannClosure<0>, m_N), - CLOSURE_FLOAT_PARAM (MicrofacetBeckmannClosure<0>, m_ab), - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM(MicrofacetBeckmannClosure<0>) }; + CLOSURE_VECTOR_PARAM(MicrofacetBeckmannClosure<0>, m_N), + CLOSURE_FLOAT_PARAM(MicrofacetBeckmannClosure<0>, m_ab), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(MicrofacetBeckmannClosure<0>) +}; ClosureParam bsdf_microfacet_beckmann_refraction_params[] = { - CLOSURE_VECTOR_PARAM(MicrofacetBeckmannClosure<1>, m_N), - CLOSURE_FLOAT_PARAM (MicrofacetBeckmannClosure<1>, m_ab), - CLOSURE_FLOAT_PARAM (MicrofacetBeckmannClosure<1>, m_eta), - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM(MicrofacetBeckmannClosure<1>) }; + CLOSURE_VECTOR_PARAM(MicrofacetBeckmannClosure<1>, m_N), + CLOSURE_FLOAT_PARAM(MicrofacetBeckmannClosure<1>, m_ab), + CLOSURE_FLOAT_PARAM(MicrofacetBeckmannClosure<1>, m_eta), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(MicrofacetBeckmannClosure<1>) +}; CLOSURE_PREPARE(bsdf_microfacet_ggx_prepare, MicrofacetGGXClosure<0>) CLOSURE_PREPARE(bsdf_microfacet_ggx_refraction_prepare, MicrofacetGGXClosure<1>) diff --git a/intern/cycles/kernel/osl/bsdf_oren_nayar.cpp b/intern/cycles/kernel/osl/bsdf_oren_nayar.cpp index 5d2ca909f93..83d0e583695 100644 --- a/intern/cycles/kernel/osl/bsdf_oren_nayar.cpp +++ b/intern/cycles/kernel/osl/bsdf_oren_nayar.cpp @@ -19,19 +19,20 @@ #include <OpenImageIO/fmath.h> #include <OSL/genclosure.h> #include "osl_closures.h" +#include "util_math.h" CCL_NAMESPACE_BEGIN using namespace OSL; -class OrenNayarClosure: public BSDFClosure { +class OrenNayarClosure : public BSDFClosure { public: Vec3 m_N; float m_sigma; float m_a, m_b; - OrenNayarClosure(): BSDFClosure(Labels::DIFFUSE) {} + OrenNayarClosure() : BSDFClosure(Labels::DIFFUSE) {} void setup() { m_sigma = clamp(m_sigma, 0.0f, 1.0f); @@ -42,19 +43,19 @@ public: m_b = m_sigma * div; } - bool mergeable(const ClosurePrimitive* other) const { - const OrenNayarClosure* comp = static_cast<const OrenNayarClosure*>(other); + bool mergeable(const ClosurePrimitive *other) const { + const OrenNayarClosure *comp = static_cast<const OrenNayarClosure *>(other); return - m_N == comp->m_N && - m_sigma == comp->m_sigma && - BSDFClosure::mergeable(other); + m_N == comp->m_N && + m_sigma == comp->m_sigma && + BSDFClosure::mergeable(other); } size_t memsize() const { return sizeof(*this); } - const char* name() const { + const char *name() const { return "oren_nayar"; } @@ -86,13 +87,13 @@ public: } ustring sample( - const Vec3& Ng, - const Vec3& omega_out, const Vec3& domega_out_dx, const Vec3& domega_out_dy, - float randu, float randv, - Vec3& omega_in, Vec3& domega_in_dx, Vec3& domega_in_dy, - float& pdf, Color3& eval - ) const { - sample_uniform_hemisphere (m_N, omega_out, randu, randv, omega_in, pdf); + const Vec3& Ng, + const Vec3& omega_out, const Vec3& domega_out_dx, const Vec3& domega_out_dy, + float randu, float randv, + Vec3& omega_in, Vec3& domega_in_dx, Vec3& domega_in_dy, + float& pdf, Color3& eval + ) const { + sample_uniform_hemisphere(m_N, omega_out, randu, randv, omega_in, pdf); if (Ng.dot(omega_in) > 0.0f) { float is = get_intensity(m_N, omega_out, omega_in); @@ -117,18 +118,18 @@ private: float nv = max(n.dot(v), 0.0f); float t = l.dot(v) - nl * nv; - if(t > 0.0f) { - t /= max(nl, vl) + 1e-8f; + if (t > 0.0f) { + t /= max(nl, nv) + 1e-8f; } return nl * (m_a + m_b * t); } }; ClosureParam bsdf_oren_nayar_params[] = { - CLOSURE_VECTOR_PARAM (OrenNayarClosure, m_N), - CLOSURE_FLOAT_PARAM (OrenNayarClosure, m_sigma), - CLOSURE_STRING_KEYPARAM ("label"), - CLOSURE_FINISH_PARAM (OrenNayarClosure) + CLOSURE_VECTOR_PARAM(OrenNayarClosure, m_N), + CLOSURE_FLOAT_PARAM(OrenNayarClosure, m_sigma), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(OrenNayarClosure) }; CLOSURE_PREPARE(bsdf_oren_nayar_prepare, OrenNayarClosure) diff --git a/intern/cycles/kernel/osl/bsdf_reflection.cpp b/intern/cycles/kernel/osl/bsdf_reflection.cpp index b0caff6df44..7041b4ced6f 100644 --- a/intern/cycles/kernel/osl/bsdf_reflection.cpp +++ b/intern/cycles/kernel/osl/bsdf_reflection.cpp @@ -42,65 +42,66 @@ using namespace OSL; class ReflectionClosure : public BSDFClosure { public: - Vec3 m_N; // shading normal - ReflectionClosure() : BSDFClosure(Labels::SINGULAR) { } - - void setup() {}; - - bool mergeable (const ClosurePrimitive *other) const { - const ReflectionClosure *comp = (const ReflectionClosure *)other; - return m_N == comp->m_N && BSDFClosure::mergeable(other); - } - - size_t memsize () const { return sizeof(*this); } - - const char *name () const { return "reflection"; } - - void print_on (std::ostream &out) const { - out << name() << " ("; - out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "))"; - } - - float albedo (const Vec3 &omega_out) const - { - return 1.0f; - } - - Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - return Color3 (0, 0, 0); - } - - Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - return Color3 (0, 0, 0); - } - - ustring sample (const Vec3 &Ng, - const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, - float randu, float randv, - Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, - float &pdf, Color3 &eval) const - { - // only one direction is possible - float cosNO = m_N.dot(omega_out); - if (cosNO > 0) { - omega_in = (2 * cosNO) * m_N - omega_out; - if (Ng.dot(omega_in) > 0) { - domega_in_dx = 2 * m_N.dot(domega_out_dx) * m_N - domega_out_dx; - domega_in_dy = 2 * m_N.dot(domega_out_dy) * m_N - domega_out_dy; - pdf = 1; - eval.setValue(1, 1, 1); - } - } - return Labels::REFLECT; - } + Vec3 m_N; // shading normal + ReflectionClosure() : BSDFClosure(Labels::SINGULAR) {} + + void setup() {}; + + bool mergeable(const ClosurePrimitive *other) const { + const ReflectionClosure *comp = (const ReflectionClosure *)other; + return m_N == comp->m_N && BSDFClosure::mergeable(other); + } + + size_t memsize() const { return sizeof(*this); } + + const char *name() const { return "reflection"; } + + void print_on(std::ostream &out) const { + out << name() << " ("; + out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "))"; + } + + float albedo(const Vec3 &omega_out) const + { + return 1.0f; + } + + Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + return Color3(0, 0, 0); + } + + Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + return Color3(0, 0, 0); + } + + ustring sample(const Vec3 &Ng, + const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, + float randu, float randv, + Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, + float &pdf, Color3 &eval) const + { + // only one direction is possible + float cosNO = m_N.dot(omega_out); + if (cosNO > 0) { + omega_in = (2 * cosNO) * m_N - omega_out; + if (Ng.dot(omega_in) > 0) { + domega_in_dx = 2 * m_N.dot(domega_out_dx) * m_N - domega_out_dx; + domega_in_dy = 2 * m_N.dot(domega_out_dy) * m_N - domega_out_dy; + pdf = 1; + eval.setValue(1, 1, 1); + } + } + return Labels::REFLECT; + } }; ClosureParam bsdf_reflection_params[] = { - CLOSURE_VECTOR_PARAM(ReflectionClosure, m_N), - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM(ReflectionClosure) }; + CLOSURE_VECTOR_PARAM(ReflectionClosure, m_N), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(ReflectionClosure) +}; CLOSURE_PREPARE(bsdf_reflection_prepare, ReflectionClosure) diff --git a/intern/cycles/kernel/osl/bsdf_refraction.cpp b/intern/cycles/kernel/osl/bsdf_refraction.cpp index 3ae7a3811b4..f56ad7b127c 100644 --- a/intern/cycles/kernel/osl/bsdf_refraction.cpp +++ b/intern/cycles/kernel/osl/bsdf_refraction.cpp @@ -42,77 +42,78 @@ using namespace OSL; class RefractionClosure : public BSDFClosure { public: - Vec3 m_N; // shading normal - float m_eta; // ratio of indices of refraction (inside / outside) - RefractionClosure() : BSDFClosure(Labels::SINGULAR, Back) { } + Vec3 m_N; // shading normal + float m_eta; // ratio of indices of refraction (inside / outside) + RefractionClosure() : BSDFClosure(Labels::SINGULAR, Back) {} - void setup() {} + void setup() {} - bool mergeable (const ClosurePrimitive *other) const { - const RefractionClosure *comp = (const RefractionClosure *)other; - return m_N == comp->m_N && m_eta == comp->m_eta && - BSDFClosure::mergeable(other); - } + bool mergeable(const ClosurePrimitive *other) const { + const RefractionClosure *comp = (const RefractionClosure *)other; + return m_N == comp->m_N && m_eta == comp->m_eta && + BSDFClosure::mergeable(other); + } - size_t memsize () const { return sizeof(*this); } + size_t memsize() const { return sizeof(*this); } - const char *name () const { return "refraction"; } + const char *name() const { return "refraction"; } - void print_on (std::ostream &out) const { - out << name() << " ("; - out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), "; - out << m_eta; - out << ")"; - } + void print_on(std::ostream &out) const { + out << name() << " ("; + out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), "; + out << m_eta; + out << ")"; + } - Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - return Color3 (0, 0, 0); - } + Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + return Color3(0, 0, 0); + } - Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - return Color3 (0, 0, 0); - } + Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + return Color3(0, 0, 0); + } - float albedo (const Vec3 &omega_out) const - { + float albedo(const Vec3 &omega_out) const + { return 1.0f; - } - - ustring sample (const Vec3 &Ng, - const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, - float randu, float randv, - Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, - float &pdf, Color3 &eval) const - { - Vec3 R, dRdx, dRdy; - Vec3 T, dTdx, dTdy; - bool inside; - - fresnel_dielectric(m_eta, m_N, - omega_out, domega_out_dx, domega_out_dy, - R, dRdx, dRdy, - T, dTdx, dTdy, - inside); - - if (!inside) { - pdf = 1; - eval.setValue(1.0f, 1.0f, 1.0f); - omega_in = T; - domega_in_dx = dTdx; - domega_in_dy = dTdy; - } - - return Labels::TRANSMIT; - } + } + + ustring sample(const Vec3 &Ng, + const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, + float randu, float randv, + Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, + float &pdf, Color3 &eval) const + { + Vec3 R, dRdx, dRdy; + Vec3 T, dTdx, dTdy; + bool inside; + + fresnel_dielectric(m_eta, m_N, + omega_out, domega_out_dx, domega_out_dy, + R, dRdx, dRdy, + T, dTdx, dTdy, + inside); + + if (!inside) { + pdf = 1; + eval.setValue(1.0f, 1.0f, 1.0f); + omega_in = T; + domega_in_dx = dTdx; + domega_in_dy = dTdy; + } + + return Labels::TRANSMIT; + } }; ClosureParam bsdf_refraction_params[] = { - CLOSURE_VECTOR_PARAM(RefractionClosure, m_N), - CLOSURE_FLOAT_PARAM (RefractionClosure, m_eta), - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM(RefractionClosure) }; + CLOSURE_VECTOR_PARAM(RefractionClosure, m_N), + CLOSURE_FLOAT_PARAM(RefractionClosure, m_eta), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(RefractionClosure) +}; CLOSURE_PREPARE(bsdf_refraction_prepare, RefractionClosure) diff --git a/intern/cycles/kernel/osl/bsdf_transparent.cpp b/intern/cycles/kernel/osl/bsdf_transparent.cpp index 941abd6a483..acde92530a2 100644 --- a/intern/cycles/kernel/osl/bsdf_transparent.cpp +++ b/intern/cycles/kernel/osl/bsdf_transparent.cpp @@ -42,54 +42,55 @@ using namespace OSL; class TransparentClosure : public BSDFClosure { public: - TransparentClosure() : BSDFClosure(Labels::STRAIGHT, Back) { } - - void setup() {} - - size_t memsize () const { return sizeof(*this); } - - const char *name () const { return "transparent"; } - - void print_on (std::ostream &out) const { - out << name() << " ()"; - } - - float albedo (const Vec3 &omega_out) const - { - return 1.0f; - } - - Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - return Color3 (0, 0, 0); - } - - Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - return Color3 (0, 0, 0); - } - - ustring sample (const Vec3 &Ng, - const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, - float randu, float randv, - Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, - float &pdf, Color3 &eval) const - { - // only one direction is possible - omega_in = -omega_out; - domega_in_dx = -domega_out_dx; - domega_in_dy = -domega_out_dy; - pdf = 1; - eval.setValue(1, 1, 1); - return Labels::TRANSMIT; - } + TransparentClosure() : BSDFClosure(Labels::STRAIGHT, Back) {} + + void setup() {} + + size_t memsize() const { return sizeof(*this); } + + const char *name() const { return "transparent"; } + + void print_on(std::ostream &out) const { + out << name() << " ()"; + } + + float albedo(const Vec3 &omega_out) const + { + return 1.0f; + } + + Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + return Color3(0, 0, 0); + } + + Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + return Color3(0, 0, 0); + } + + ustring sample(const Vec3 &Ng, + const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, + float randu, float randv, + Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, + float &pdf, Color3 &eval) const + { + // only one direction is possible + omega_in = -omega_out; + domega_in_dx = -domega_out_dx; + domega_in_dy = -domega_out_dy; + pdf = 1; + eval.setValue(1, 1, 1); + return Labels::TRANSMIT; + } }; ClosureParam bsdf_transparent_params[] = { - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM(TransparentClosure) }; + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(TransparentClosure) +}; CLOSURE_PREPARE(bsdf_transparent_prepare, TransparentClosure) diff --git a/intern/cycles/kernel/osl/bsdf_ward.cpp b/intern/cycles/kernel/osl/bsdf_ward.cpp index a7742a04d13..4aacbc4ffc3 100644 --- a/intern/cycles/kernel/osl/bsdf_ward.cpp +++ b/intern/cycles/kernel/osl/bsdf_ward.cpp @@ -46,175 +46,179 @@ using namespace OSL; // see http://www.graphics.cornell.edu/~bjw/wardnotes.pdf class WardClosure : public BSDFClosure { public: - Vec3 m_N; - Vec3 m_T; - float m_ax, m_ay; - WardClosure() : BSDFClosure(Labels::GLOSSY) { } + Vec3 m_N; + Vec3 m_T; + float m_ax, m_ay; + WardClosure() : BSDFClosure(Labels::GLOSSY) {} - void setup() + void setup() { m_ax = clamp(m_ax, 1e-5f, 1.0f); m_ay = clamp(m_ay, 1e-5f, 1.0f); } - bool mergeable (const ClosurePrimitive *other) const { - const WardClosure *comp = (const WardClosure *)other; - return m_N == comp->m_N && m_T == comp->m_T && - m_ax == comp->m_ax && m_ay == comp->m_ay && - BSDFClosure::mergeable(other); - } - - size_t memsize () const { return sizeof(*this); } - - const char *name () const { return "ward"; } - - void print_on (std::ostream &out) const { - out << name() << " (("; - out << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), ("; - out << m_T[0] << ", " << m_T[1] << ", " << m_T[2] << "), "; - out << m_ax << ", " << m_ay << ")"; - } - - float albedo (const Vec3 &omega_out) const - { - return 1.0f; - } - - Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - float cosNO = m_N.dot(omega_out); - float cosNI = m_N.dot(omega_in); - if (cosNI > 0 && cosNO > 0) { - // get half vector and get x,y basis on the surface for anisotropy - Vec3 H = omega_in + omega_out; - H.normalize(); // normalize needed for pdf - Vec3 X, Y; - make_orthonormals(m_N, m_T, X, Y); - // eq. 4 - float dotx = H.dot(X) / m_ax; - float doty = H.dot(Y) / m_ay; - float dotn = H.dot(m_N); - float exp_arg = (dotx * dotx + doty * doty) / (dotn * dotn); - float denom = (4 * (float) M_PI * m_ax * m_ay * sqrtf(cosNO * cosNI)); - float exp_val = expf(-exp_arg); - float out = cosNI * exp_val / denom; - float oh = H.dot(omega_out); - denom = 4 * (float) M_PI * m_ax * m_ay * oh * dotn * dotn * dotn; - pdf = exp_val / denom; - return Color3 (out, out, out); - } - return Color3 (0, 0, 0); - } - - Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const - { - return Color3 (0, 0, 0); - } - - ustring sample (const Vec3 &Ng, - const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, - float randu, float randv, - Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, - float &pdf, Color3 &eval) const - { - float cosNO = m_N.dot(omega_out); - if (cosNO > 0) { - // get x,y basis on the surface for anisotropy - Vec3 X, Y; - make_orthonormals(m_N, m_T, X, Y); - // generate random angles for the half vector - // eq. 7 (taking care around discontinuities to keep - // output angle in the right quadrant) - // we take advantage of cos(atan(x)) == 1/sqrt(1+x^2) - // and sin(atan(x)) == x/sqrt(1+x^2) - float alphaRatio = m_ay / m_ax; - float cosPhi, sinPhi; - if (randu < 0.25f) { - float val = 4 * randu; - float tanPhi = alphaRatio * tanf((float) M_PI_2 * val); - cosPhi = 1 / sqrtf(1 + tanPhi * tanPhi); - sinPhi = tanPhi * cosPhi; - } else if (randu < 0.5) { - float val = 1 - 4 * (0.5f - randu); - float tanPhi = alphaRatio * tanf((float) M_PI_2 * val); - // phi = (float) M_PI - phi; - cosPhi = -1 / sqrtf(1 + tanPhi * tanPhi); - sinPhi = -tanPhi * cosPhi; - } else if (randu < 0.75f) { - float val = 4 * (randu - 0.5f); - float tanPhi = alphaRatio * tanf((float) M_PI_2 * val); - //phi = (float) M_PI + phi; - cosPhi = -1 / sqrtf(1 + tanPhi * tanPhi); - sinPhi = tanPhi * cosPhi; - } else { - float val = 1 - 4 * (1 - randu); - float tanPhi = alphaRatio * tanf((float) M_PI_2 * val); - // phi = 2 * (float) M_PI - phi; - cosPhi = 1 / sqrtf(1 + tanPhi * tanPhi); - sinPhi = -tanPhi * cosPhi; - } - // eq. 6 - // we take advantage of cos(atan(x)) == 1/sqrt(1+x^2) - // and sin(atan(x)) == x/sqrt(1+x^2) - float thetaDenom = (cosPhi * cosPhi) / (m_ax * m_ax) + (sinPhi * sinPhi) / (m_ay * m_ay); - float tanTheta2 = -logf(1 - randv) / thetaDenom; - float cosTheta = 1 / sqrtf(1 + tanTheta2); - float sinTheta = cosTheta * sqrtf(tanTheta2); - - Vec3 h; // already normalized becaused expressed from spherical coordinates - h.x = sinTheta * cosPhi; - h.y = sinTheta * sinPhi; - h.z = cosTheta; - // compute terms that are easier in local space - float dotx = h.x / m_ax; - float doty = h.y / m_ay; - float dotn = h.z; - // transform to world space - h = h.x * X + h.y * Y + h.z * m_N; - // generate the final sample - float oh = h.dot(omega_out); - omega_in.x = 2 * oh * h.x - omega_out.x; - omega_in.y = 2 * oh * h.y - omega_out.y; - omega_in.z = 2 * oh * h.z - omega_out.z; - if (Ng.dot(omega_in) > 0) { - float cosNI = m_N.dot(omega_in); - if (cosNI > 0) { - // eq. 9 - float exp_arg = (dotx * dotx + doty * doty) / (dotn * dotn); - float denom = 4 * (float) M_PI * m_ax * m_ay * oh * dotn * dotn * dotn; - pdf = expf(-exp_arg) / denom; - // compiler will reuse expressions already computed - denom = (4 * (float) M_PI * m_ax * m_ay * sqrtf(cosNO * cosNI)); - float power = cosNI * expf(-exp_arg) / denom; - eval.setValue(power, power, power); - domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx; - domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy; + bool mergeable(const ClosurePrimitive *other) const { + const WardClosure *comp = (const WardClosure *)other; + return m_N == comp->m_N && m_T == comp->m_T && + m_ax == comp->m_ax && m_ay == comp->m_ay && + BSDFClosure::mergeable(other); + } + + size_t memsize() const { return sizeof(*this); } + + const char *name() const { return "ward"; } + + void print_on(std::ostream &out) const { + out << name() << " (("; + out << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), ("; + out << m_T[0] << ", " << m_T[1] << ", " << m_T[2] << "), "; + out << m_ax << ", " << m_ay << ")"; + } + + float albedo(const Vec3 &omega_out) const + { + return 1.0f; + } + + Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + float cosNO = m_N.dot(omega_out); + float cosNI = m_N.dot(omega_in); + if (cosNI > 0 && cosNO > 0) { + // get half vector and get x,y basis on the surface for anisotropy + Vec3 H = omega_in + omega_out; + H.normalize(); // normalize needed for pdf + Vec3 X, Y; + make_orthonormals(m_N, m_T, X, Y); + // eq. 4 + float dotx = H.dot(X) / m_ax; + float doty = H.dot(Y) / m_ay; + float dotn = H.dot(m_N); + float exp_arg = (dotx * dotx + doty * doty) / (dotn * dotn); + float denom = (4 * (float) M_PI * m_ax * m_ay * sqrtf(cosNO * cosNI)); + float exp_val = expf(-exp_arg); + float out = cosNI * exp_val / denom; + float oh = H.dot(omega_out); + denom = 4 * (float) M_PI * m_ax * m_ay * oh * dotn * dotn * dotn; + pdf = exp_val / denom; + return Color3(out, out, out); + } + return Color3(0, 0, 0); + } + + Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const + { + return Color3(0, 0, 0); + } + + ustring sample(const Vec3 &Ng, + const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, + float randu, float randv, + Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, + float &pdf, Color3 &eval) const + { + float cosNO = m_N.dot(omega_out); + if (cosNO > 0) { + // get x,y basis on the surface for anisotropy + Vec3 X, Y; + make_orthonormals(m_N, m_T, X, Y); + // generate random angles for the half vector + // eq. 7 (taking care around discontinuities to keep + // output angle in the right quadrant) + // we take advantage of cos(atan(x)) == 1/sqrt(1+x^2) + // and sin(atan(x)) == x/sqrt(1+x^2) + float alphaRatio = m_ay / m_ax; + float cosPhi, sinPhi; + if (randu < 0.25f) { + float val = 4 * randu; + float tanPhi = alphaRatio * tanf((float) M_PI_2 * val); + cosPhi = 1 / sqrtf(1 + tanPhi * tanPhi); + sinPhi = tanPhi * cosPhi; + } + else if (randu < 0.5) { + float val = 1 - 4 * (0.5f - randu); + float tanPhi = alphaRatio * tanf((float) M_PI_2 * val); + // phi = (float) M_PI - phi; + cosPhi = -1 / sqrtf(1 + tanPhi * tanPhi); + sinPhi = -tanPhi * cosPhi; + } + else if (randu < 0.75f) { + float val = 4 * (randu - 0.5f); + float tanPhi = alphaRatio * tanf((float) M_PI_2 * val); + //phi = (float) M_PI + phi; + cosPhi = -1 / sqrtf(1 + tanPhi * tanPhi); + sinPhi = tanPhi * cosPhi; + } + else { + float val = 1 - 4 * (1 - randu); + float tanPhi = alphaRatio * tanf((float) M_PI_2 * val); + // phi = 2 * (float) M_PI - phi; + cosPhi = 1 / sqrtf(1 + tanPhi * tanPhi); + sinPhi = -tanPhi * cosPhi; + } + // eq. 6 + // we take advantage of cos(atan(x)) == 1/sqrt(1+x^2) + // and sin(atan(x)) == x/sqrt(1+x^2) + float thetaDenom = (cosPhi * cosPhi) / (m_ax * m_ax) + (sinPhi * sinPhi) / (m_ay * m_ay); + float tanTheta2 = -logf(1 - randv) / thetaDenom; + float cosTheta = 1 / sqrtf(1 + tanTheta2); + float sinTheta = cosTheta * sqrtf(tanTheta2); + + Vec3 h; // already normalized becaused expressed from spherical coordinates + h.x = sinTheta * cosPhi; + h.y = sinTheta * sinPhi; + h.z = cosTheta; + // compute terms that are easier in local space + float dotx = h.x / m_ax; + float doty = h.y / m_ay; + float dotn = h.z; + // transform to world space + h = h.x * X + h.y * Y + h.z * m_N; + // generate the final sample + float oh = h.dot(omega_out); + omega_in.x = 2 * oh * h.x - omega_out.x; + omega_in.y = 2 * oh * h.y - omega_out.y; + omega_in.z = 2 * oh * h.z - omega_out.z; + if (Ng.dot(omega_in) > 0) { + float cosNI = m_N.dot(omega_in); + if (cosNI > 0) { + // eq. 9 + float exp_arg = (dotx * dotx + doty * doty) / (dotn * dotn); + float denom = 4 * (float) M_PI * m_ax * m_ay * oh * dotn * dotn * dotn; + pdf = expf(-exp_arg) / denom; + // compiler will reuse expressions already computed + denom = (4 * (float) M_PI * m_ax * m_ay * sqrtf(cosNO * cosNI)); + float power = cosNI * expf(-exp_arg) / denom; + eval.setValue(power, power, power); + domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx; + domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy; /* disabled for now - gives texture filtering problems */ #if 0 - // Since there is some blur to this reflection, make the - // derivatives a bit bigger. In theory this varies with the - // roughness but the exact relationship is complex and - // requires more ops than are practical. - domega_in_dx *= 10; - domega_in_dy *= 10; + // Since there is some blur to this reflection, make the + // derivatives a bit bigger. In theory this varies with the + // roughness but the exact relationship is complex and + // requires more ops than are practical. + domega_in_dx *= 10; + domega_in_dy *= 10; #endif - } - } - } - return Labels::REFLECT; - } + } + } + } + return Labels::REFLECT; + } }; ClosureParam bsdf_ward_params[] = { - CLOSURE_VECTOR_PARAM(WardClosure, m_N), - CLOSURE_VECTOR_PARAM(WardClosure, m_T), - CLOSURE_FLOAT_PARAM (WardClosure, m_ax), - CLOSURE_FLOAT_PARAM (WardClosure, m_ay), - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM(WardClosure) }; + CLOSURE_VECTOR_PARAM(WardClosure, m_N), + CLOSURE_VECTOR_PARAM(WardClosure, m_T), + CLOSURE_FLOAT_PARAM(WardClosure, m_ax), + CLOSURE_FLOAT_PARAM(WardClosure, m_ay), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(WardClosure) +}; CLOSURE_PREPARE(bsdf_ward_prepare, WardClosure) diff --git a/intern/cycles/kernel/osl/bsdf_westin.cpp b/intern/cycles/kernel/osl/bsdf_westin.cpp index d322f6a7f7e..a476e8045f7 100644 --- a/intern/cycles/kernel/osl/bsdf_westin.cpp +++ b/intern/cycles/kernel/osl/bsdf_westin.cpp @@ -44,193 +44,197 @@ using namespace OSL; class WestinBackscatterClosure : public BSDFClosure { public: - Vec3 m_N; - float m_roughness; - float m_invroughness; - WestinBackscatterClosure() : BSDFClosure(Labels::GLOSSY) { } + Vec3 m_N; + float m_roughness; + float m_invroughness; + WestinBackscatterClosure() : BSDFClosure(Labels::GLOSSY) {} - void setup() - { + void setup() + { m_roughness = clamp(m_roughness, 1e-5f, 1.0f); - m_invroughness = m_roughness > 0 ? 1 / m_roughness : 0; - } - - bool mergeable (const ClosurePrimitive *other) const { - const WestinBackscatterClosure *comp = (const WestinBackscatterClosure *)other; - return m_N == comp->m_N && m_roughness == comp->m_roughness && - BSDFClosure::mergeable(other); - } - - size_t memsize () const { return sizeof(*this); } - - const char *name () const { return "westin_backscatter"; } - - void print_on (std::ostream &out) const - { - out << name() << " ("; - out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), "; - out << m_roughness; - out << ")"; - } - - float albedo (const Vec3 &omega_out) const - { - return 1.0f; - } - - Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float &pdf) const - { - // pdf is implicitly 0 (no indirect sampling) - float cosNO = m_N.dot(omega_out); - float cosNI = m_N.dot(omega_in); - if (cosNO > 0 && cosNI > 0) { - float cosine = omega_out.dot(omega_in); - pdf = cosine > 0 ? (m_invroughness + 1) * powf(cosine, m_invroughness) : 0; - pdf *= 0.5f * float(M_1_PI); - return Color3 (pdf, pdf, pdf); - } - return Color3 (0, 0, 0); - } - - Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float &pdf) const - { - return Color3 (0, 0, 0); - } - - ustring sample (const Vec3 &Ng, - const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, - float randu, float randv, - Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, - float &pdf, Color3 &eval) const - { - float cosNO = m_N.dot(omega_out); - if (cosNO > 0) { - domega_in_dx = domega_out_dx; - domega_in_dy = domega_out_dy; - Vec3 T, B; - make_orthonormals (omega_out, T, B); - float phi = 2 * (float) M_PI * randu; - float cosTheta = powf(randv, 1 / (m_invroughness + 1)); - float sinTheta2 = 1 - cosTheta * cosTheta; - float sinTheta = sinTheta2 > 0 ? sqrtf(sinTheta2) : 0; - omega_in = (cosf(phi) * sinTheta) * T + - (sinf(phi) * sinTheta) * B + - ( cosTheta) * omega_out; - if (Ng.dot(omega_in) > 0) - { - // common terms for pdf and eval - float cosNI = m_N.dot(omega_in); - // make sure the direction we chose is still in the right hemisphere - if (cosNI > 0) - { - pdf = 0.5f * (float) M_1_PI * powf(cosTheta, m_invroughness); - pdf = (m_invroughness + 1) * pdf; - eval.setValue(pdf, pdf, pdf); - // Since there is some blur to this reflection, make the - // derivatives a bit bigger. In theory this varies with the - // exponent but the exact relationship is complex and - // requires more ops than are practical. - domega_in_dx *= 10; - domega_in_dy *= 10; - } - } - } - return Labels::REFLECT; - } + m_invroughness = m_roughness > 0 ? 1 / m_roughness : 0; + } + + bool mergeable(const ClosurePrimitive *other) const { + const WestinBackscatterClosure *comp = (const WestinBackscatterClosure *)other; + return m_N == comp->m_N && m_roughness == comp->m_roughness && + BSDFClosure::mergeable(other); + } + + size_t memsize() const { return sizeof(*this); } + + const char *name() const { return "westin_backscatter"; } + + void print_on(std::ostream &out) const + { + out << name() << " ("; + out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), "; + out << m_roughness; + out << ")"; + } + + float albedo(const Vec3 &omega_out) const + { + return 1.0f; + } + + Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float &pdf) const + { + // pdf is implicitly 0 (no indirect sampling) + float cosNO = m_N.dot(omega_out); + float cosNI = m_N.dot(omega_in); + if (cosNO > 0 && cosNI > 0) { + float cosine = omega_out.dot(omega_in); + pdf = cosine > 0 ? (m_invroughness + 1) * powf(cosine, m_invroughness) : 0; + pdf *= 0.5f * float(M_1_PI); + return Color3(pdf, pdf, pdf); + } + return Color3(0, 0, 0); + } + + Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float &pdf) const + { + return Color3(0, 0, 0); + } + + ustring sample(const Vec3 &Ng, + const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, + float randu, float randv, + Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, + float &pdf, Color3 &eval) const + { + float cosNO = m_N.dot(omega_out); + if (cosNO > 0) { + domega_in_dx = domega_out_dx; + domega_in_dy = domega_out_dy; + Vec3 T, B; + make_orthonormals(omega_out, T, B); + float phi = 2 * (float) M_PI * randu; + float cosTheta = powf(randv, 1 / (m_invroughness + 1)); + float sinTheta2 = 1 - cosTheta * cosTheta; + float sinTheta = sinTheta2 > 0 ? sqrtf(sinTheta2) : 0; + omega_in = (cosf(phi) * sinTheta) * T + + (sinf(phi) * sinTheta) * B + + (cosTheta) * omega_out; + if (Ng.dot(omega_in) > 0) + { + // common terms for pdf and eval + float cosNI = m_N.dot(omega_in); + // make sure the direction we chose is still in the right hemisphere + if (cosNI > 0) + { + pdf = 0.5f * (float) M_1_PI * powf(cosTheta, m_invroughness); + pdf = (m_invroughness + 1) * pdf; + eval.setValue(pdf, pdf, pdf); + // Since there is some blur to this reflection, make the + // derivatives a bit bigger. In theory this varies with the + // exponent but the exact relationship is complex and + // requires more ops than are practical. + domega_in_dx *= 10; + domega_in_dy *= 10; + } + } + } + return Labels::REFLECT; + } }; class WestinSheenClosure : public BSDFClosure { public: - Vec3 m_N; - float m_edginess; + Vec3 m_N; + float m_edginess; // float m_normalization; - WestinSheenClosure() : BSDFClosure(Labels::DIFFUSE) { } - - void setup() {}; - - bool mergeable (const ClosurePrimitive *other) const { - const WestinSheenClosure *comp = (const WestinSheenClosure *)other; - return m_N == comp->m_N && m_edginess == comp->m_edginess && - BSDFClosure::mergeable(other); - } - - size_t memsize () const { return sizeof(*this); } - - const char *name () const { return "westin_sheen"; } - - void print_on (std::ostream &out) const - { - out << name() << " ("; - out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), "; - out << m_edginess; - out << ")"; - } - - float albedo (const Vec3 &omega_out) const - { - return 1.0f; - } - - Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float &pdf) const - { - // pdf is implicitly 0 (no indirect sampling) - float cosNO = m_N.dot(omega_out); - float cosNI = m_N.dot(omega_in); - if (cosNO > 0 && cosNI > 0) { - float sinNO2 = 1 - cosNO * cosNO; - pdf = cosNI * float(M_1_PI); - float westin = sinNO2 > 0 ? powf(sinNO2, 0.5f * m_edginess) * pdf : 0; - return Color3 (westin, westin, westin); - } - return Color3 (0, 0, 0); - } - - Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float &pdf) const - { - return Color3 (0, 0, 0); - } - - ustring sample (const Vec3 &Ng, - const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, - float randu, float randv, - Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, - float &pdf, Color3 &eval) const - { - // we are viewing the surface from the right side - send a ray out with cosine - // distribution over the hemisphere - sample_cos_hemisphere (m_N, omega_out, randu, randv, omega_in, pdf); - if (Ng.dot(omega_in) > 0) { - // TODO: account for sheen when sampling - float cosNO = m_N.dot(omega_out); - float sinNO2 = 1 - cosNO * cosNO; - float westin = sinNO2 > 0 ? powf(sinNO2, 0.5f * m_edginess) * pdf : 0; - eval.setValue(westin, westin, westin); - // TODO: find a better approximation for the diffuse bounce - domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx; - domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy; - domega_in_dx *= 125; - domega_in_dy *= 125; - } else - pdf = 0; - return Labels::REFLECT; - } + WestinSheenClosure() : BSDFClosure(Labels::DIFFUSE) {} + + void setup() {}; + + bool mergeable(const ClosurePrimitive *other) const { + const WestinSheenClosure *comp = (const WestinSheenClosure *)other; + return m_N == comp->m_N && m_edginess == comp->m_edginess && + BSDFClosure::mergeable(other); + } + + size_t memsize() const { return sizeof(*this); } + + const char *name() const { return "westin_sheen"; } + + void print_on(std::ostream &out) const + { + out << name() << " ("; + out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), "; + out << m_edginess; + out << ")"; + } + + float albedo(const Vec3 &omega_out) const + { + return 1.0f; + } + + Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float &pdf) const + { + // pdf is implicitly 0 (no indirect sampling) + float cosNO = m_N.dot(omega_out); + float cosNI = m_N.dot(omega_in); + if (cosNO > 0 && cosNI > 0) { + float sinNO2 = 1 - cosNO * cosNO; + pdf = cosNI * float(M_1_PI); + float westin = sinNO2 > 0 ? powf(sinNO2, 0.5f * m_edginess) * pdf : 0; + return Color3(westin, westin, westin); + } + return Color3(0, 0, 0); + } + + Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float &pdf) const + { + return Color3(0, 0, 0); + } + + ustring sample(const Vec3 &Ng, + const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy, + float randu, float randv, + Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy, + float &pdf, Color3 &eval) const + { + // we are viewing the surface from the right side - send a ray out with cosine + // distribution over the hemisphere + sample_cos_hemisphere(m_N, omega_out, randu, randv, omega_in, pdf); + if (Ng.dot(omega_in) > 0) { + // TODO: account for sheen when sampling + float cosNO = m_N.dot(omega_out); + float sinNO2 = 1 - cosNO * cosNO; + float westin = sinNO2 > 0 ? powf(sinNO2, 0.5f * m_edginess) * pdf : 0; + eval.setValue(westin, westin, westin); + // TODO: find a better approximation for the diffuse bounce + domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx; + domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy; + domega_in_dx *= 125; + domega_in_dy *= 125; + } + else { + pdf = 0; + } + return Labels::REFLECT; + } }; ClosureParam bsdf_westin_backscatter_params[] = { - CLOSURE_VECTOR_PARAM(WestinBackscatterClosure, m_N), - CLOSURE_FLOAT_PARAM (WestinBackscatterClosure, m_roughness), - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM(WestinBackscatterClosure) }; + CLOSURE_VECTOR_PARAM(WestinBackscatterClosure, m_N), + CLOSURE_FLOAT_PARAM(WestinBackscatterClosure, m_roughness), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(WestinBackscatterClosure) +}; ClosureParam bsdf_westin_sheen_params[] = { - CLOSURE_VECTOR_PARAM(WestinSheenClosure, m_N), - CLOSURE_FLOAT_PARAM (WestinSheenClosure, m_edginess), - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM(WestinSheenClosure) }; + CLOSURE_VECTOR_PARAM(WestinSheenClosure, m_N), + CLOSURE_FLOAT_PARAM(WestinSheenClosure, m_edginess), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(WestinSheenClosure) +}; CLOSURE_PREPARE(bsdf_westin_backscatter_prepare, WestinBackscatterClosure) CLOSURE_PREPARE(bsdf_westin_sheen_prepare, WestinSheenClosure) diff --git a/intern/cycles/kernel/osl/bssrdf.cpp b/intern/cycles/kernel/osl/bssrdf.cpp index 66d7818e677..b195cf513cd 100644 --- a/intern/cycles/kernel/osl/bssrdf.cpp +++ b/intern/cycles/kernel/osl/bssrdf.cpp @@ -42,62 +42,63 @@ using namespace OSL; class BSSRDFCubicClosure : public BSSRDFClosure { public: - Color3 m_radius; - Color3 m_scale; - float m_max_radius; - - template <typename T> - static inline T pow3 (const T &x) { return x * x * x; } - - template <typename T> - static inline T pow5 (const T &x) { T x2 = x * x; return x2 * x2 * x; } - - BSSRDFCubicClosure() { } - - void setup() - { - // pre-compute some terms - m_max_radius = 0; - for (int i = 0; i < 3; i++) { - m_scale[i] = m_radius[i] > 0 ? 4 / pow5 (m_radius[i]) : 0; - m_max_radius = std::max (m_max_radius, m_radius[i]); - } - } - - bool mergeable (const ClosurePrimitive *other) const { - const BSSRDFCubicClosure *comp = (const BSSRDFCubicClosure *)other; - return m_radius == comp->m_radius && BSSRDFClosure::mergeable(other); - } - - size_t memsize () const { return sizeof(*this); } - - const char *name () const { return "bssrdf_cubic"; } - - void print_on (std::ostream &out) const - { - out << name() << " ((" << m_radius[0] << ", " << m_radius[1] << ", " << m_radius[2] << "), (" - << m_scale[0] << ", " << m_scale[1] << ", " << m_scale[2] << "))"; - } - - Color3 eval (float r) const - { - return Color3 ((r < m_radius.x) ? pow3 (m_radius.x - r) * m_scale.x : 0, - (r < m_radius.y) ? pow3 (m_radius.y - r) * m_scale.y : 0, - (r < m_radius.z) ? pow3 (m_radius.z - r) * m_scale.z : 0); - } - - float max_radius() const - { - return m_max_radius; - } + Color3 m_radius; + Color3 m_scale; + float m_max_radius; + + template <typename T> + static inline T pow3(const T &x) { return x * x * x; } + + template <typename T> + static inline T pow5(const T &x) { T x2 = x * x; return x2 * x2 * x; } + + BSSRDFCubicClosure() {} + + void setup() + { + // pre-compute some terms + m_max_radius = 0; + for (int i = 0; i < 3; i++) { + m_scale[i] = m_radius[i] > 0 ? 4 / pow5(m_radius[i]) : 0; + m_max_radius = std::max(m_max_radius, m_radius[i]); + } + } + + bool mergeable(const ClosurePrimitive *other) const { + const BSSRDFCubicClosure *comp = (const BSSRDFCubicClosure *)other; + return m_radius == comp->m_radius && BSSRDFClosure::mergeable(other); + } + + size_t memsize() const { return sizeof(*this); } + + const char *name() const { return "bssrdf_cubic"; } + + void print_on(std::ostream &out) const + { + out << name() << " ((" << m_radius[0] << ", " << m_radius[1] << ", " << m_radius[2] << "), (" + << m_scale[0] << ", " << m_scale[1] << ", " << m_scale[2] << "))"; + } + + Color3 eval(float r) const + { + return Color3((r < m_radius.x) ? pow3(m_radius.x - r) * m_scale.x : 0, + (r < m_radius.y) ? pow3(m_radius.y - r) * m_scale.y : 0, + (r < m_radius.z) ? pow3(m_radius.z - r) * m_scale.z : 0); + } + + float max_radius() const + { + return m_max_radius; + } }; ClosureParam closure_bssrdf_cubic_params[] = { - CLOSURE_COLOR_PARAM (BSSRDFCubicClosure, m_radius), - CLOSURE_STRING_KEYPARAM ("label"), - CLOSURE_FINISH_PARAM(BSSRDFCubicClosure) }; + CLOSURE_COLOR_PARAM(BSSRDFCubicClosure, m_radius), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(BSSRDFCubicClosure) +}; CLOSURE_PREPARE(closure_bssrdf_cubic_prepare, BSSRDFCubicClosure) diff --git a/intern/cycles/kernel/osl/debug.cpp b/intern/cycles/kernel/osl/debug.cpp index 8c3f8b2b323..768a9100e8a 100644 --- a/intern/cycles/kernel/osl/debug.cpp +++ b/intern/cycles/kernel/osl/debug.cpp @@ -49,30 +49,31 @@ using namespace OSL; class DebugClosure : public ClosurePrimitive { public: - ustring m_tag; + ustring m_tag; - DebugClosure () : ClosurePrimitive (Debug) { } + DebugClosure () : ClosurePrimitive(Debug) {} - bool mergeable (const ClosurePrimitive *other) const { - const DebugClosure *comp = (const DebugClosure *)other; - return m_tag == comp->m_tag && - ClosurePrimitive::mergeable(other); - } + bool mergeable(const ClosurePrimitive *other) const { + const DebugClosure *comp = (const DebugClosure *)other; + return m_tag == comp->m_tag && + ClosurePrimitive::mergeable(other); + } - size_t memsize () const { return sizeof(*this); } + size_t memsize() const { return sizeof(*this); } - const char *name () const { return "debug"; } + const char *name() const { return "debug"; } - void print_on (std::ostream &out) const { - out << name() << " (\"" << m_tag.c_str() << "\")"; - } + void print_on(std::ostream &out) const { + out << name() << " (\"" << m_tag.c_str() << "\")"; + } }; ClosureParam closure_debug_params[] = { - CLOSURE_STRING_PARAM(DebugClosure, m_tag), - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM(DebugClosure) }; + CLOSURE_STRING_PARAM(DebugClosure, m_tag), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(DebugClosure) +}; CLOSURE_PREPARE(closure_debug_prepare, DebugClosure) diff --git a/intern/cycles/kernel/osl/emissive.cpp b/intern/cycles/kernel/osl/emissive.cpp index 2d2d6e1fdde..0a582c3f558 100644 --- a/intern/cycles/kernel/osl/emissive.cpp +++ b/intern/cycles/kernel/osl/emissive.cpp @@ -49,57 +49,58 @@ using namespace OSL; /// class GenericEmissiveClosure : public EmissiveClosure { public: - GenericEmissiveClosure() { } - - void setup() { } - - size_t memsize () const { return sizeof(*this); } - - const char *name () const { return "emission"; } - - void print_on (std::ostream &out) const { - out << name() << "()"; - } - - Color3 eval (const Vec3 &Ng, const Vec3 &omega_out) const - { - float cosNO = fabsf(Ng.dot(omega_out)); - float res = cosNO > 0 ? 1.0f: 0.0f; - return Color3(res, res, res); - } - - void sample (const Vec3 &Ng, float randu, float randv, - Vec3 &omega_out, float &pdf) const - { - // We don't do anything sophisticated here for the step - // We just sample the whole cone uniformly to the cosine - Vec3 T, B; - make_orthonormals(Ng, T, B); - float phi = 2 * (float) M_PI * randu; - float cosTheta = sqrtf(1.0f - 1.0f * randv); - float sinTheta = sqrtf(1.0f - cosTheta * cosTheta); - omega_out = (cosf(phi) * sinTheta) * T + - (sinf(phi) * sinTheta) * B + - cosTheta * Ng; - pdf = 1.0f / float(M_PI); - } - - /// Return the probability distribution function in the direction omega_out, - /// given the parameters and the light's surface normal. This MUST match - /// the PDF computed by sample(). - float pdf (const Vec3 &Ng, - const Vec3 &omega_out) const - { - float cosNO = Ng.dot(omega_out); - return cosNO > 0 ? 1.0f: 0.0f; - } + GenericEmissiveClosure() { } + + void setup() {} + + size_t memsize() const { return sizeof(*this); } + + const char *name() const { return "emission"; } + + void print_on(std::ostream &out) const { + out << name() << "()"; + } + + Color3 eval(const Vec3 &Ng, const Vec3 &omega_out) const + { + float cosNO = fabsf(Ng.dot(omega_out)); + float res = cosNO > 0 ? 1.0f : 0.0f; + return Color3(res, res, res); + } + + void sample(const Vec3 &Ng, float randu, float randv, + Vec3 &omega_out, float &pdf) const + { + // We don't do anything sophisticated here for the step + // We just sample the whole cone uniformly to the cosine + Vec3 T, B; + make_orthonormals(Ng, T, B); + float phi = 2 * (float) M_PI * randu; + float cosTheta = sqrtf(1.0f - 1.0f * randv); + float sinTheta = sqrtf(1.0f - cosTheta * cosTheta); + omega_out = (cosf(phi) * sinTheta) * T + + (sinf(phi) * sinTheta) * B + + cosTheta * Ng; + pdf = 1.0f / float(M_PI); + } + + /// Return the probability distribution function in the direction omega_out, + /// given the parameters and the light's surface normal. This MUST match + /// the PDF computed by sample(). + float pdf(const Vec3 &Ng, + const Vec3 &omega_out) const + { + float cosNO = Ng.dot(omega_out); + return cosNO > 0 ? 1.0f : 0.0f; + } }; ClosureParam closure_emission_params[] = { - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM(GenericEmissiveClosure) }; + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(GenericEmissiveClosure) +}; CLOSURE_PREPARE(closure_emission_prepare, GenericEmissiveClosure) diff --git a/intern/cycles/kernel/osl/nodes/node_checker_texture.osl b/intern/cycles/kernel/osl/nodes/node_checker_texture.osl index 712d51333ad..a80242ad36a 100644 --- a/intern/cycles/kernel/osl/nodes/node_checker_texture.osl +++ b/intern/cycles/kernel/osl/nodes/node_checker_texture.osl @@ -42,9 +42,9 @@ float checker(point p) shader node_checker_texture( float Scale = 5.0, point Vector = P, - color Color1 = color(0.8, 0.8, 0.8); - color Color2 = color(0.2, 0.2, 0.2); - output float Fac = 0.0) + color Color1 = color(0.8, 0.8, 0.8), + color Color2 = color(0.2, 0.2, 0.2), + output float Fac = 0.0, output color Color = color(0.0, 0.0, 0.0)) { Fac = checker(Vector*Scale); diff --git a/intern/cycles/kernel/osl/nodes/node_color.h b/intern/cycles/kernel/osl/nodes/node_color.h index 37d092eae78..80786e4e369 100644 --- a/intern/cycles/kernel/osl/nodes/node_color.h +++ b/intern/cycles/kernel/osl/nodes/node_color.h @@ -18,18 +18,18 @@ float color_srgb_to_scene_linear(float c) { - if(c < 0.04045) - return (c < 0.0)? 0.0: c * (1.0/12.92); + if (c < 0.04045) + return (c < 0.0) ? 0.0 : c * (1.0 / 12.92); else - return pow((c + 0.055)*(1.0/1.055), 2.4); + return pow((c + 0.055) * (1.0 / 1.055), 2.4); } float color_scene_linear_to_srgb(float c) { - if(c < 0.0031308) - return (c < 0.0)? 0.0: c * 12.92; - else - return 1.055 * pow(c, 1.0/2.4) - 0.055; + if (c < 0.0031308) + return (c < 0.0) ? 0.0 : c * 12.92; + else + return 1.055 * pow(c, 1.0 / 2.4) - 0.055; } color color_srgb_to_scene_linear(color c) @@ -61,27 +61,27 @@ color rgb_to_hsv(color rgb) v = cmax; - if(cmax != 0.0) { - s = cdelta/cmax; + if (cmax != 0.0) { + s = cdelta / cmax; } else { s = 0.0; h = 0.0; } - if(s == 0.0) { + if (s == 0.0) { h = 0.0; } else { - c = (color(cmax, cmax, cmax) - rgb)/cdelta; + c = (color(cmax, cmax, cmax) - rgb) / cdelta; - if(rgb[0] == cmax) h = c[2] - c[1]; - else if(rgb[1] == cmax) h = 2.0 + c[0] - c[2]; + if (rgb[0] == cmax) h = c[2] - c[1]; + else if (rgb[1] == cmax) h = 2.0 + c[0] - c[2]; else h = 4.0 + c[1] - c[0]; h /= 6.0; - if(h < 0.0) + if (h < 0.0) h += 1.0; } @@ -97,26 +97,26 @@ color hsv_to_rgb(color hsv) s = hsv[1]; v = hsv[2]; - if(s==0.0) { + if (s == 0.0) { rgb = color(v, v, v); } else { - if(h==1.0) + if (h == 1.0) h = 0.0; h *= 6.0; i = floor(h); f = h - i; rgb = color(f, f, f); - p = v*(1.0-s); - q = v*(1.0-(s*f)); - t = v*(1.0-(s*(1.0-f))); - - if(i == 0.0) rgb = color(v, t, p); - else if(i == 1.0) rgb = color(q, v, p); - else if(i == 2.0) rgb = color(p, v, t); - else if(i == 3.0) rgb = color(p, q, v); - else if(i == 4.0) rgb = color(t, p, v); + p = v * (1.0 - s); + q = v * (1.0 - (s * f)); + t = v * (1.0 - (s * (1.0 - f))); + + if (i == 0.0) rgb = color(v, t, p); + else if (i == 1.0) rgb = color(q, v, p); + else if (i == 2.0) rgb = color(p, v, t); + else if (i == 3.0) rgb = color(p, q, v); + else if (i == 4.0) rgb = color(t, p, v); else rgb = color(v, p, q); } diff --git a/intern/cycles/kernel/osl/nodes/node_fresnel.h b/intern/cycles/kernel/osl/nodes/node_fresnel.h index 0c8a5276ede..0368c1910aa 100644 --- a/intern/cycles/kernel/osl/nodes/node_fresnel.h +++ b/intern/cycles/kernel/osl/nodes/node_fresnel.h @@ -7,11 +7,11 @@ float fresnel_dielectric(vector Incoming, normal Normal, float eta) float g = eta * eta - 1 + c * c; float result; - if(g > 0) { + if (g > 0) { g = sqrt(g); - float A =(g - c)/(g + c); - float B =(c *(g + c)- 1)/(c *(g - c)+ 1); - result = 0.5 * A * A *(1 + B * B); + float A = (g - c) / (g + c); + float B = (c * (g + c) - 1) / (c * (g - c) + 1); + result = 0.5 * A * A * (1 + B * B); } else result = 1.0; /* TIR (no refracted component) */ diff --git a/intern/cycles/kernel/osl/nodes/node_texture.h b/intern/cycles/kernel/osl/nodes/node_texture.h index e0ec8038ee4..d2dbd6db8b3 100644 --- a/intern/cycles/kernel/osl/nodes/node_texture.h +++ b/intern/cycles/kernel/osl/nodes/node_texture.h @@ -20,20 +20,20 @@ float voronoi_distance(string distance_metric, vector d, float e) { float result = 0.0; - if(distance_metric == "Distance Squared") + if (distance_metric == "Distance Squared") result = dot(d, d); - if(distance_metric == "Actual Distance") + if (distance_metric == "Actual Distance") result = length(d); - if(distance_metric == "Manhattan") + if (distance_metric == "Manhattan") result = fabs(d[0]) + fabs(d[1]) + fabs(d[2]); - if(distance_metric == "Chebychev") + if (distance_metric == "Chebychev") result = max(fabs(d[0]), max(fabs(d[1]), fabs(d[2]))); - if(distance_metric == "Minkovsky 1/2") + if (distance_metric == "Minkovsky 1/2") result = sqrt(fabs(d[0])) + sqrt(fabs(d[1])) + sqrt(fabs(d[1])); - if(distance_metric == "Minkovsky 4") - result = sqrt(sqrt(dot(d*d, d*d))); - if(distance_metric == "Minkovsky") - result = pow(pow(fabs(d[0]), e) + pow(fabs(d[1]), e) + pow(fabs(d[2]), e), 1.0/e); + if (distance_metric == "Minkovsky 4") + result = sqrt(sqrt(dot(d * d, d * d))); + if (distance_metric == "Minkovsky") + result = pow(pow(fabs(d[0]), e) + pow(fabs(d[1]), e) + pow(fabs(d[2]), e), 1.0 / e); return result; } @@ -63,9 +63,9 @@ void voronoi(point p, string distance_metric, float e, float da[4], point pa[4]) da[2] = 1e10; da[3] = 1e10; - for(xx = xi-1; xx <= xi+1; xx++) { - for(yy = yi-1; yy <= yi+1; yy++) { - for(zz = zi-1; zz <= zi+1; zz++) { + for (xx = xi - 1; xx <= xi + 1; xx++) { + for (yy = yi - 1; yy <= yi + 1; yy++) { + for (zz = zi - 1; zz <= zi + 1; zz++) { point ip = point(xx, yy, zz); point vp = (point)cellnoise_color(ip); point pd = p - (vp + ip); @@ -73,7 +73,7 @@ void voronoi(point p, string distance_metric, float e, float da[4], point pa[4]) vp += point(xx, yy, zz); - if(d < da[0]) { + if (d < da[0]) { da[3] = da[2]; da[2] = da[1]; da[1] = da[0]; @@ -84,7 +84,7 @@ void voronoi(point p, string distance_metric, float e, float da[4], point pa[4]) pa[1] = pa[0]; pa[0] = vp; } - else if(d < da[1]) { + else if (d < da[1]) { da[3] = da[2]; da[2] = da[1]; da[1] = d; @@ -93,14 +93,14 @@ void voronoi(point p, string distance_metric, float e, float da[4], point pa[4]) pa[2] = pa[1]; pa[1] = vp; } - else if(d < da[2]) { + else if (d < da[2]) { da[3] = da[2]; da[2] = d; pa[3] = pa[2]; pa[2] = vp; } - else if(d < da[3]) { + else if (d < da[3]) { da[3] = d; pa[3] = vp; } @@ -138,16 +138,16 @@ float voronoi_F1F2(point p) { return voronoi_FnFn(p, 0, 1); } float voronoi_Cr(point p) { /* crackle type pattern, just a scale/clamp of F2-F1 */ - float t = 10.0*voronoi_F1F2(p); - return (t > 1.0)? 1.0: t; + float t = 10.0 * voronoi_F1F2(p); + return (t > 1.0) ? 1.0 : t; } -float voronoi_F1S(point p) { return 2.0*voronoi_F1(p) - 1.0; } -float voronoi_F2S(point p) { return 2.0*voronoi_F2(p) - 1.0; } -float voronoi_F3S(point p) { return 2.0*voronoi_F3(p) - 1.0; } -float voronoi_F4S(point p) { return 2.0*voronoi_F4(p) - 1.0; } -float voronoi_F1F2S(point p) { return 2.0*voronoi_F1F2(p) - 1.0; } -float voronoi_CrS(point p) { return 2.0*voronoi_Cr(p) - 1.0; } +float voronoi_F1S(point p) { return 2.0 * voronoi_F1(p) - 1.0; } +float voronoi_F2S(point p) { return 2.0 * voronoi_F2(p) - 1.0; } +float voronoi_F3S(point p) { return 2.0 * voronoi_F3(p) - 1.0; } +float voronoi_F4S(point p) { return 2.0 * voronoi_F4(p) - 1.0; } +float voronoi_F1F2S(point p) { return 2.0 * voronoi_F1F2(p) - 1.0; } +float voronoi_CrS(point p) { return 2.0 * voronoi_Cr(p) - 1.0; } /* Noise Bases */ @@ -155,21 +155,21 @@ float noise_basis(point p, string basis) { float result = 0.0; - if(basis == "Perlin") + if (basis == "Perlin") result = noise(p); - if(basis == "Voronoi F1") + if (basis == "Voronoi F1") result = voronoi_F1S(p); - if(basis == "Voronoi F2") + if (basis == "Voronoi F2") result = voronoi_F2S(p); - if(basis == "Voronoi F3") + if (basis == "Voronoi F3") result = voronoi_F3S(p); - if(basis == "Voronoi F4") + if (basis == "Voronoi F4") result = voronoi_F4S(p); - if(basis == "Voronoi F2-F1") + if (basis == "Voronoi F2-F1") result = voronoi_F1F2S(p); - if(basis == "Voronoi Crackle") + if (basis == "Voronoi Crackle") result = voronoi_CrS(p); - if(basis == "Cell Noise") + if (basis == "Cell Noise") result = cellnoise(p); return result; @@ -180,7 +180,7 @@ float noise_basis(point p, string basis) float noise_basis_hard(point p, string basis, int hard) { float t = noise_basis(p, basis); - return (hard)? fabs(2.0*t - 1.0): t; + return (hard) ? fabs(2.0 * t - 1.0) : t; } /* Waves */ @@ -189,22 +189,22 @@ float noise_wave(string wave, float a) { float result = 0.0; - if(wave == "Sine") { - result = 0.5 + 0.5*sin(a); + if (wave == "Sine") { + result = 0.5 + 0.5 * sin(a); } - else if(wave == "Saw") { - float b = 2*M_PI; + else if (wave == "Saw") { + float b = 2 * M_PI; int n = (int)(a / b); - a -= n*b; - if(a < 0) a += b; + a -= n * b; + if (a < 0) a += b; result = a / b; } - else if(wave == "Tri") { - float b = 2*M_PI; + else if (wave == "Tri") { + float b = 2 * M_PI; float rmax = 1.0; - result = rmax - 2.0*fabs(floor((a*(1.0/b))+0.5) - (a*(1.0/b))); + result = rmax - 2.0 * fabs(floor((a * (1.0 / b)) + 0.5) - (a * (1.0 / b))); } return result; @@ -219,18 +219,18 @@ float noise_turbulence(point p, string basis, int octaves, int hard) float sum = 0.0; int i; - for(i = 0; i <= octaves; i++) { - float t = noise_basis(fscale*p, basis); + for (i = 0; i <= octaves; i++) { + float t = noise_basis(fscale * p, basis); - if(hard) - t = fabs(2.0*t - 1.0); + if (hard) + t = fabs(2.0 * t - 1.0); - sum += t*amp; + sum += t * amp; amp *= 0.5; fscale *= 2.0; } - sum *= ((float)(1 << octaves)/(float)((1 << (octaves+1)) - 1)); + sum *= ((float)(1 << octaves) / (float)((1 << (octaves + 1)) - 1)); return sum; } @@ -241,8 +241,8 @@ float nonzero(float f, float eps) { float r; - if(abs(f) < eps) - r = sign(f)*eps; + if (abs(f) < eps) + r = sign(f) * eps; else r = f; diff --git a/intern/cycles/kernel/osl/nodes/stdosl.h b/intern/cycles/kernel/osl/nodes/stdosl.h index e4a110e737c..0c07c501d69 100644 --- a/intern/cycles/kernel/osl/nodes/stdosl.h +++ b/intern/cycles/kernel/osl/nodes/stdosl.h @@ -163,241 +163,246 @@ vector normalize (vector v) BUILTIN; vector faceforward (vector N, vector I, vector Nref) BUILTIN; vector faceforward (vector N, vector I) BUILTIN; vector reflect (vector I, vector N) { return I - 2*dot(N,I)*N; } -vector refract (vector I, vector N, float eta) { - float IdotN = dot (I, N); - float k = 1 - eta*eta * (1 - IdotN*IdotN); - return (k < 0) ? vector(0,0,0) : (eta*I - N * (eta*IdotN + sqrt(k))); +vector refract(vector I, vector N, float eta) { + float IdotN = dot(I, N); + float k = 1 - eta * eta * (1 - IdotN * IdotN); + return (k < 0) ? vector(0, 0, 0) : (eta * I - N * (eta * IdotN + sqrt(k))); } -void fresnel (vector I, normal N, float eta, - output float Kr, output float Kt, - output vector R, output vector T) +void fresnel(vector I, normal N, float eta, + output float Kr, output float Kt, + output vector R, output vector T) { - float sqr(float x) { return x*x; } - float c = dot(I, N); - if (c < 0) - c = -c; - R = reflect(I, N); - float g = 1.0 / sqr(eta) - 1.0 + c * c; - if (g >= 0.0) { - g = sqrt (g); - float beta = g - c; - float F = (c * (g+c) - 1.0) / (c * beta + 1.0); - F = 0.5 * (1.0 + sqr(F)); - F *= sqr (beta / (g+c)); - Kr = F; - Kt = (1.0 - Kr) * eta*eta; - // OPT: the following recomputes some of the above values, but it - // gives us the same result as if the shader-writer called refract() - T = refract(I, N, eta); - } else { - // total internal reflection - Kr = 1.0; - Kt = 0.0; - T = vector (0,0,0); - } + float sqr(float x) { + return x * x; + } + float c = dot(I, N); + if (c < 0) + c = -c; + R = reflect(I, N); + float g = 1.0 / sqr(eta) - 1.0 + c * c; + if (g >= 0.0) { + g = sqrt(g); + float beta = g - c; + float F = (c * (g + c) - 1.0) / (c * beta + 1.0); + F = 0.5 * (1.0 + sqr(F)); + F *= sqr(beta / (g + c)); + Kr = F; + Kt = (1.0 - Kr) * eta * eta; + // OPT: the following recomputes some of the above values, but it + // gives us the same result as if the shader-writer called refract() + T = refract(I, N, eta); + } + else { + // total internal reflection + Kr = 1.0; + Kt = 0.0; + T = vector(0, 0, 0); + } #undef sqr } -void fresnel (vector I, normal N, float eta, - output float Kr, output float Kt) +void fresnel(vector I, normal N, float eta, + output float Kr, output float Kt) { - vector R, T; - fresnel(I, N, eta, Kr, Kt, R, T); + vector R, T; + fresnel(I, N, eta, Kr, Kt, R, T); } -point rotate (point q, float angle, point a, point b) BUILTIN; +point rotate(point q, float angle, point a, point b) BUILTIN; -normal transform (matrix Mto, normal p) BUILTIN; -vector transform (matrix Mto, vector p) BUILTIN; -point transform (matrix Mto, point p) BUILTIN; +normal transform(matrix Mto, normal p) BUILTIN; +vector transform(matrix Mto, vector p) BUILTIN; +point transform(matrix Mto, point p) BUILTIN; // Implementation of transform-with-named-space in terms of matrices: -point transform (string tospace, point x) +point transform(string tospace, point x) { - return transform (matrix ("common", tospace), x); + return transform(matrix("common", tospace), x); } -point transform (string fromspace, string tospace, point x) +point transform(string fromspace, string tospace, point x) { - return transform (matrix (fromspace, tospace), x); + return transform(matrix(fromspace, tospace), x); } -vector transform (string tospace, vector x) +vector transform(string tospace, vector x) { - return transform (matrix ("common", tospace), x); + return transform(matrix("common", tospace), x); } -vector transform (string fromspace, string tospace, vector x) +vector transform(string fromspace, string tospace, vector x) { - return transform (matrix (fromspace, tospace), x); + return transform(matrix(fromspace, tospace), x); } -normal transform (string tospace, normal x) +normal transform(string tospace, normal x) { - return transform (matrix ("common", tospace), x); + return transform(matrix("common", tospace), x); } -normal transform (string fromspace, string tospace, normal x) +normal transform(string fromspace, string tospace, normal x) { - return transform (matrix (fromspace, tospace), x); + return transform(matrix(fromspace, tospace), x); } -float transformu (string tounits, float x) BUILTIN; -float transformu (string fromunits, string tounits, float x) BUILTIN; +float transformu(string tounits, float x) BUILTIN; +float transformu(string fromunits, string tounits, float x) BUILTIN; // Color functions -float luminance (color c) { - return dot ((vector)c, vector(0.2126, 0.7152, 0.0722)); +float luminance(color c) { + return dot((vector)c, vector(0.2126, 0.7152, 0.0722)); } -color transformc (string to, color x) +color transformc(string to, color x) { - color rgb_to_hsv (color rgb) { // See Foley & van Dam - float r = rgb[0], g = rgb[1], b = rgb[2]; - float mincomp = min (r, min (g, b)); - float maxcomp = max (r, max (g, b)); - float delta = maxcomp - mincomp; // chroma - float h, s, v; - v = maxcomp; - if (maxcomp > 0) - s = delta / maxcomp; - else s = 0; - if (s <= 0) - h = 0; - else { - if (r >= maxcomp) h = (g-b) / delta; - else if (g >= maxcomp) h = 2 + (b-r) / delta; - else h = 4 + (r-g) / delta; - h /= 6; - if (h < 0) - h += 1; - } - return color (h, s, v); - } - - color rgb_to_hsl (color rgb) { // See Foley & van Dam - // First convert rgb to hsv, then to hsl - float minval = min (rgb[0], min (rgb[1], rgb[2])); - color hsv = rgb_to_hsv (rgb); - float maxval = hsv[2]; // v == maxval - float h = hsv[0], s, l = (minval+maxval) / 2; - if (minval == maxval) - s = 0; // special 'achromatic' case, hue is 0 - else if (l <= 0.5) - s = (maxval - minval) / (maxval + minval); - else - s = (maxval - minval) / (2 - maxval - minval); - return color (h, s, l); - } - - color r; - if (to == "rgb" || to == "RGB") - r = x; - else if (to == "hsv") - r = rgb_to_hsv (x); - else if (to == "hsl") - r = rgb_to_hsl (x); - else if (to == "YIQ") - r = color (dot (vector(0.299, 0.587, 0.114), (vector)x), - dot (vector(0.596, -0.275, -0.321), (vector)x), - dot (vector(0.212, -0.523, 0.311), (vector)x)); - else if (to == "xyz") - r = color (dot (vector(0.412453, 0.357580, 0.180423), (vector)x), - dot (vector(0.212671, 0.715160, 0.072169), (vector)x), - dot (vector(0.019334, 0.119193, 0.950227), (vector)x)); - else { - error ("Unknown color space \"%s\"", to); - r = x; - } - return r; + color rgb_to_hsv(color rgb) { // See Foley & van Dam + float r = rgb[0], g = rgb[1], b = rgb[2]; + float mincomp = min(r, min(g, b)); + float maxcomp = max(r, max(g, b)); + float delta = maxcomp - mincomp; // chroma + float h, s, v; + v = maxcomp; + if (maxcomp > 0) + s = delta / maxcomp; + else s = 0; + if (s <= 0) + h = 0; + else { + if (r >= maxcomp) h = (g - b) / delta; + else if (g >= maxcomp) h = 2 + (b - r) / delta; + else h = 4 + (r - g) / delta; + h /= 6; + if (h < 0) + h += 1; + } + return color(h, s, v); + } + + color rgb_to_hsl(color rgb) { // See Foley & van Dam + // First convert rgb to hsv, then to hsl + float minval = min(rgb[0], min(rgb[1], rgb[2])); + color hsv = rgb_to_hsv(rgb); + float maxval = hsv[2]; // v == maxval + float h = hsv[0], s, l = (minval + maxval) / 2; + if (minval == maxval) + s = 0; // special 'achromatic' case, hue is 0 + else if (l <= 0.5) + s = (maxval - minval) / (maxval + minval); + else + s = (maxval - minval) / (2 - maxval - minval); + return color(h, s, l); + } + + color r; + if (to == "rgb" || to == "RGB") + r = x; + else if (to == "hsv") + r = rgb_to_hsv(x); + else if (to == "hsl") + r = rgb_to_hsl(x); + else if (to == "YIQ") + r = color(dot(vector(0.299, 0.587, 0.114), (vector)x), + dot(vector(0.596, -0.275, -0.321), (vector)x), + dot(vector(0.212, -0.523, 0.311), (vector)x)); + else if (to == "xyz") + r = color(dot(vector(0.412453, 0.357580, 0.180423), (vector)x), + dot(vector(0.212671, 0.715160, 0.072169), (vector)x), + dot(vector(0.019334, 0.119193, 0.950227), (vector)x)); + else { + error("Unknown color space \"%s\"", to); + r = x; + } + return r; } -color transformc (string from, string to, color x) +color transformc(string from, string to, color x) { - color hsv_to_rgb (color c) { // Reference: Foley & van Dam - float h = c[0], s = c[1], v = c[2]; - color r; - if (s < 0.0001) { - r = v; - } else { - h = 6 * (h - floor(h)); // expand to [0..6) - int hi = (int)h; - float f = h - hi; - float p = v * (1-s); - float q = v * (1-s*f); - float t = v * (1-s*(1-f)); - if (hi == 0) r = color (v, t, p); - else if (hi == 1) r = color (q, v, p); - else if (hi == 2) r = color (p, v, t); - else if (hi == 3) r = color (p, q, v); - else if (hi == 4) r = color (t, p, v); - else r = color (v, p, q); - } - return r; - } - - color hsl_to_rgb (color c) { - float h = c[0], s = c[1], l = c[2]; - // Easiest to convert hsl -> hsv, then hsv -> RGB (per Foley & van Dam) - float v = (l <= 0.5) ? (l * (1 + s)) : (l * (1 - s) + s); - color r; - if (v <= 0) { - r = 0; - } else { - float min = 2 * l - v; - s = (v - min) / v; - r = hsv_to_rgb (color (h, s, v)); - } - return r; - } - - color r; - if (from == "rgb" || from == "RGB") - r = x; - else if (from == "hsv") - r = hsv_to_rgb (x); - else if (from == "hsl") - r = hsl_to_rgb (x); - else if (from == "YIQ") - r = color (dot (vector(1, 0.9557, 0.6199), (vector)x), - dot (vector(1, -0.2716, -0.6469), (vector)x), - dot (vector(1, -1.1082, 1.7051), (vector)x)); - else if (from == "xyz") - r = color (dot (vector( 3.240479, -1.537150, -0.498535), (vector)x), - dot (vector(-0.969256, 1.875991, 0.041556), (vector)x), - dot (vector( 0.055648, -0.204043, 1.057311), (vector)x)); - else { - error ("Unknown color space \"%s\"", to); - r = x; - } - return transformc (to, r); + color hsv_to_rgb(color c) { // Reference: Foley & van Dam + float h = c[0], s = c[1], v = c[2]; + color r; + if (s < 0.0001) { + r = v; + } + else { + h = 6 * (h - floor(h)); // expand to [0..6) + int hi = (int)h; + float f = h - hi; + float p = v * (1 - s); + float q = v * (1 - s * f); + float t = v * (1 - s * (1 - f)); + if (hi == 0) r = color(v, t, p); + else if (hi == 1) r = color(q, v, p); + else if (hi == 2) r = color(p, v, t); + else if (hi == 3) r = color(p, q, v); + else if (hi == 4) r = color(t, p, v); + else r = color(v, p, q); + } + return r; + } + + color hsl_to_rgb(color c) { + float h = c[0], s = c[1], l = c[2]; + // Easiest to convert hsl -> hsv, then hsv -> RGB (per Foley & van Dam) + float v = (l <= 0.5) ? (l * (1 + s)) : (l * (1 - s) + s); + color r; + if (v <= 0) { + r = 0; + } + else { + float min = 2 * l - v; + s = (v - min) / v; + r = hsv_to_rgb(color(h, s, v)); + } + return r; + } + + color r; + if (from == "rgb" || from == "RGB") + r = x; + else if (from == "hsv") + r = hsv_to_rgb(x); + else if (from == "hsl") + r = hsl_to_rgb(x); + else if (from == "YIQ") + r = color(dot(vector(1, 0.9557, 0.6199), (vector)x), + dot(vector(1, -0.2716, -0.6469), (vector)x), + dot(vector(1, -1.1082, 1.7051), (vector)x)); + else if (from == "xyz") + r = color(dot(vector(3.240479, -1.537150, -0.498535), (vector)x), + dot(vector(-0.969256, 1.875991, 0.041556), (vector)x), + dot(vector(0.055648, -0.204043, 1.057311), (vector)x)); + else { + error("Unknown color space \"%s\"", to); + r = x; + } + return transformc(to, r); } // Matrix functions -float determinant (matrix m) BUILTIN; -matrix transpose (matrix m) BUILTIN; +float determinant(matrix m) BUILTIN; +matrix transpose(matrix m) BUILTIN; // Pattern generation -float step (float edge, float x) BUILTIN; -color step (color edge, color x) BUILTIN; -point step (point edge, point x) BUILTIN; -vector step (vector edge, vector x) BUILTIN; -normal step (normal edge, normal x) BUILTIN; -float smoothstep (float edge0, float edge1, float x) BUILTIN; +float step(float edge, float x) BUILTIN; +color step(color edge, color x) BUILTIN; +point step(point edge, point x) BUILTIN; +vector step(vector edge, vector x) BUILTIN; +normal step(normal edge, normal x) BUILTIN; +float smoothstep(float edge0, float edge1, float x) BUILTIN; // Derivatives and area operators @@ -408,24 +413,26 @@ float smoothstep (float edge0, float edge1, float x) BUILTIN; // String functions -int strlen (string s) BUILTIN; -int startswith (string s, string prefix) BUILTIN; -int endswith (string s, string suffix) BUILTIN; -string substr (string s, int start, int len) BUILTIN; -string substr (string s, int start) { return substr (s, start, strlen(s)); } +int strlen(string s) BUILTIN; +int startswith(string s, string prefix) BUILTIN; +int endswith(string s, string suffix) BUILTIN; +string substr(string s, int start, int len) BUILTIN; +string substr(string s, int start) { + return substr(s, start, strlen(s)); +} // Define concat in terms of shorter concat -string concat (string a, string b, string c) { - return concat(concat(a,b), c); +string concat(string a, string b, string c) { + return concat(concat(a, b), c); } -string concat (string a, string b, string c, string d) { - return concat(concat(a,b,c), d); +string concat(string a, string b, string c, string d) { + return concat(concat(a, b, c), d); } -string concat (string a, string b, string c, string d, string e) { - return concat(concat(a,b,c,d), e); +string concat(string a, string b, string c, string d, string e) { + return concat(concat(a, b, c, d), e); } -string concat (string a, string b, string c, string d, string e, string f) { - return concat(concat(a,b,c,d,e), f); +string concat(string a, string b, string c, string d, string e, string f) { + return concat(concat(a, b, c, d, e), f); } @@ -438,7 +445,7 @@ closure color diffuse(normal N) BUILTIN; closure color oren_nayar(normal N, float sigma) BUILTIN; closure color translucent(normal N) BUILTIN; closure color reflection(normal N, float eta) BUILTIN; -closure color reflection(normal N) { return reflection (N, 0.0); } +closure color reflection(normal N) { return reflection(N, 0.0); } closure color refraction(normal N, float eta) BUILTIN; closure color dielectric(normal N, float eta) BUILTIN; closure color transparent() BUILTIN; @@ -446,7 +453,7 @@ closure color microfacet_ggx(normal N, float ag) BUILTIN; closure color microfacet_ggx_refraction(normal N, float ag, float eta) BUILTIN; closure color microfacet_beckmann(normal N, float ab) BUILTIN; closure color microfacet_beckmann_refraction(normal N, float ab, float eta) BUILTIN; -closure color ward(normal N, vector T,float ax, float ay) BUILTIN; +closure color ward(normal N, vector T, float ax, float ay) BUILTIN; closure color ashikhmin_velvet(normal N, float sigma) BUILTIN; closure color westin_backscatter(normal N, float roughness) BUILTIN; closure color westin_sheen(normal N, float edginess) BUILTIN; @@ -460,7 +467,7 @@ closure color holdout() BUILTIN; closure color subsurface(float eta, float g, float mfp, float albedo) BUILTIN; // Renderer state -int raytype (string typename) BUILTIN; +int raytype(string typename) BUILTIN; #undef BUILTIN #undef BUILTIN_DERIV diff --git a/intern/cycles/kernel/osl/osl_closures.cpp b/intern/cycles/kernel/osl/osl_closures.cpp index b87cdf8af86..0793b29d1ac 100644 --- a/intern/cycles/kernel/osl/osl_closures.cpp +++ b/intern/cycles/kernel/osl/osl_closures.cpp @@ -48,7 +48,7 @@ static void generic_closure_setup(OSL::RendererServices *, int id, void *data) prim->setup(); } -static bool generic_closure_mergeable(int id, const void *dataA, const void *dataB) +static bool generic_closure_compare(int id, const void *dataA, const void *dataB) { assert(dataA && dataB); @@ -59,11 +59,7 @@ static bool generic_closure_mergeable(int id, const void *dataA, const void *dat static void register_closure(OSL::ShadingSystem *ss, const char *name, int id, OSL::ClosureParam *params, OSL::PrepareClosureFunc prepare) { - int j; - for(j = 0; params[j].type != TypeDesc(); ++j) {} - int size = params[j].offset; - - ss->register_closure(name, id, params, size, prepare, generic_closure_setup, generic_closure_mergeable); + ss->register_closure(name, id, params, prepare, generic_closure_setup, generic_closure_compare); } void OSLShader::register_closures(OSL::ShadingSystem *ss) diff --git a/intern/cycles/kernel/osl/osl_services.cpp b/intern/cycles/kernel/osl/osl_services.cpp index 1b52a3e489b..12f3a377ef4 100644 --- a/intern/cycles/kernel/osl/osl_services.cpp +++ b/intern/cycles/kernel/osl/osl_services.cpp @@ -37,7 +37,7 @@ CCL_NAMESPACE_BEGIN /* RenderServices implementation */ -#define TO_MATRIX44(m) (*(OSL::Matrix44*)&(m)) +#define TO_MATRIX44(m) (*(OSL::Matrix44 *)&(m)) /* static ustrings */ ustring OSLRenderServices::u_distance("distance"); @@ -66,13 +66,13 @@ bool OSLRenderServices::get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr { /* this is only used for shader and object space, we don't really have a concept of shader space, so we just use object space for both. */ - if(xform) { + if (xform) { KernelGlobals *kg = kernel_globals; - const ShaderData *sd = (const ShaderData*)xform; + const ShaderData *sd = (const ShaderData *)xform; int object = sd->object; - if(object != ~0) { - Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM); + if (object != ~0) { + Transform tfm = object_fetch_transform(kg, object, time, OBJECT_TRANSFORM); tfm = transform_transpose(tfm); result = TO_MATRIX44(tfm); @@ -87,13 +87,13 @@ bool OSLRenderServices::get_inverse_matrix(OSL::Matrix44 &result, OSL::Transform { /* this is only used for shader and object space, we don't really have a concept of shader space, so we just use object space for both. */ - if(xform) { + if (xform) { KernelGlobals *kg = kernel_globals; - const ShaderData *sd = (const ShaderData*)xform; + const ShaderData *sd = (const ShaderData *)xform; int object = sd->object; - if(object != ~0) { - Transform tfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM); + if (object != ~0) { + Transform tfm = object_fetch_transform(kg, object, time, OBJECT_INVERSE_TRANSFORM); tfm = transform_transpose(tfm); result = TO_MATRIX44(tfm); @@ -108,22 +108,22 @@ bool OSLRenderServices::get_matrix(OSL::Matrix44 &result, ustring from, float ti { KernelGlobals *kg = kernel_globals; - if(from == u_ndc) { + if (from == u_ndc) { Transform tfm = transform_transpose(kernel_data.cam.ndctoworld); result = TO_MATRIX44(tfm); return true; } - else if(from == u_raster) { + else if (from == u_raster) { Transform tfm = transform_transpose(kernel_data.cam.rastertoworld); result = TO_MATRIX44(tfm); return true; } - else if(from == u_screen) { + else if (from == u_screen) { Transform tfm = transform_transpose(kernel_data.cam.screentoworld); result = TO_MATRIX44(tfm); return true; } - else if(from == u_camera) { + else if (from == u_camera) { Transform tfm = transform_transpose(kernel_data.cam.cameratoworld); result = TO_MATRIX44(tfm); return true; @@ -136,22 +136,22 @@ bool OSLRenderServices::get_inverse_matrix(OSL::Matrix44 &result, ustring to, fl { KernelGlobals *kg = kernel_globals; - if(to == u_ndc) { + if (to == u_ndc) { Transform tfm = transform_transpose(kernel_data.cam.worldtondc); result = TO_MATRIX44(tfm); return true; } - else if(to == u_raster) { + else if (to == u_raster) { Transform tfm = transform_transpose(kernel_data.cam.worldtoraster); result = TO_MATRIX44(tfm); return true; } - else if(to == u_screen) { + else if (to == u_screen) { Transform tfm = transform_transpose(kernel_data.cam.worldtoscreen); result = TO_MATRIX44(tfm); return true; } - else if(to == u_camera) { + else if (to == u_camera) { Transform tfm = transform_transpose(kernel_data.cam.worldtocamera); result = TO_MATRIX44(tfm); return true; @@ -161,56 +161,57 @@ bool OSLRenderServices::get_inverse_matrix(OSL::Matrix44 &result, ustring to, fl } bool OSLRenderServices::get_array_attribute(void *renderstate, bool derivatives, - ustring object, TypeDesc type, ustring name, - int index, void *val) + ustring object, TypeDesc type, ustring name, + int index, void *val) { return false; } static bool get_mesh_attribute(KernelGlobals *kg, const ShaderData *sd, - const OSLGlobals::Attribute& attr, bool derivatives, void *val) + const OSLGlobals::Attribute& attr, bool derivatives, void *val) { - if(attr.type == TypeDesc::TypeFloat) { - float *fval = (float*)val; + if (attr.type == TypeDesc::TypeFloat) { + float *fval = (float *)val; fval[0] = triangle_attribute_float(kg, sd, attr.elem, attr.offset, - (derivatives)? &fval[1]: NULL, (derivatives)? &fval[2]: NULL); + (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL); } else { /* todo: this won't work when float3 has w component */ - float3 *fval = (float3*)val; + float3 *fval = (float3 *)val; fval[0] = triangle_attribute_float3(kg, sd, attr.elem, attr.offset, - (derivatives)? &fval[1]: NULL, (derivatives)? &fval[2]: NULL); + (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL); } return true; } static bool get_mesh_attribute_convert(KernelGlobals *kg, const ShaderData *sd, - const OSLGlobals::Attribute& attr, const TypeDesc& type, bool derivatives, void *val) + const OSLGlobals::Attribute& attr, const TypeDesc& type, bool derivatives, void *val) { - if(attr.type == TypeDesc::TypeFloat) { + if (attr.type == TypeDesc::TypeFloat) { float tmp[3]; - float3 *fval = (float3*)val; + float3 *fval = (float3 *)val; get_mesh_attribute(kg, sd, attr, derivatives, tmp); fval[0] = make_float3(tmp[0], tmp[0], tmp[0]); - if(derivatives) { + if (derivatives) { fval[1] = make_float3(tmp[1], tmp[1], tmp[1]); fval[2] = make_float3(tmp[2], tmp[2], tmp[2]); } return true; } - else if(attr.type == TypeDesc::TypePoint || attr.type == TypeDesc::TypeVector || - attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor) { + else if (attr.type == TypeDesc::TypePoint || attr.type == TypeDesc::TypeVector || + attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor) + { float3 tmp[3]; - float *fval = (float*)val; + float *fval = (float *)val; get_mesh_attribute(kg, sd, attr, derivatives, tmp); fval[0] = average(tmp[0]); - if(derivatives) { + if (derivatives) { fval[1] = average(tmp[1]); fval[2] = average(tmp[2]); } @@ -226,29 +227,29 @@ static void get_object_attribute(const OSLGlobals::Attribute& attr, bool derivat size_t datasize = attr.value.datasize(); memcpy(val, attr.value.data(), datasize); - if(derivatives) - memset((char*)val + datasize, 0, datasize*2); + if (derivatives) + memset((char *)val + datasize, 0, datasize * 2); } bool OSLRenderServices::get_attribute(void *renderstate, bool derivatives, ustring object_name, - TypeDesc type, ustring name, void *val) + TypeDesc type, ustring name, void *val) { KernelGlobals *kg = kernel_globals; - const ShaderData *sd = (const ShaderData*)renderstate; + const ShaderData *sd = (const ShaderData *)renderstate; int object = sd->object; int tri = sd->prim; /* lookup of attribute on another object */ - if(object_name != u_empty) { + if (object_name != u_empty) { OSLGlobals::ObjectNameMap::iterator it = kg->osl.object_name_map.find(object_name); - if(it == kg->osl.object_name_map.end()) + if (it == kg->osl.object_name_map.end()) return false; object = it->second; tri = ~0; } - else if(object == ~0) { + else if (object == ~0) { /* no background attributes supported */ return false; } @@ -257,20 +258,23 @@ bool OSLRenderServices::get_attribute(void *renderstate, bool derivatives, ustri OSLGlobals::AttributeMap& attribute_map = kg->osl.attribute_map[object]; OSLGlobals::AttributeMap::iterator it = attribute_map.find(name); - if(it == attribute_map.end()) + if (it == attribute_map.end()) return false; /* type mistmatch? */ const OSLGlobals::Attribute& attr = it->second; - if(attr.elem != ATTR_ELEMENT_VALUE) { + if (attr.elem != ATTR_ELEMENT_VALUE) { /* triangle and vertex attributes */ - if(tri != ~0) { - if(attr.type == type || (attr.type == TypeDesc::TypeColor && - (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || type == TypeDesc::TypeNormal))) + if (tri != ~0) { + if (attr.type == type || (attr.type == TypeDesc::TypeColor && + (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || type == TypeDesc::TypeNormal))) + { return get_mesh_attribute(kg, sd, attr, derivatives, val); - else + } + else { return get_mesh_attribute_convert(kg, sd, attr, type, derivatives, val); + } } } else { @@ -283,7 +287,7 @@ bool OSLRenderServices::get_attribute(void *renderstate, bool derivatives, ustri } bool OSLRenderServices::get_userdata(bool derivatives, ustring name, TypeDesc type, - void *renderstate, void *val) + void *renderstate, void *val) { return false; /* disabled by lockgeom */ } @@ -294,7 +298,7 @@ bool OSLRenderServices::has_userdata(ustring name, TypeDesc type, void *renderst } void *OSLRenderServices::get_pointcloud_attr_query(ustring *attr_names, - TypeDesc *attr_types, int nattrs) + TypeDesc *attr_types, int nattrs) { #ifdef WITH_PARTIO m_attr_queries.push_back(AttrQuery()); @@ -308,28 +312,32 @@ void *OSLRenderServices::get_pointcloud_attr_query(ustring *attr_names, to the query. Just to prevent buffer overruns */ query.capacity = -1; - for(int i = 0; i < nattrs; ++i) - { + for (int i = 0; i < nattrs; ++i) { query.attr_names[i] = attr_names[i]; - TypeDesc element_type = attr_types[i].elementtype (); + TypeDesc element_type = attr_types[i].elementtype(); - if(query.capacity < 0) - query.capacity = attr_types[i].numelements(); + if (query.capacity < 0) + query.capacity = attr_types[i].numelements(); else - query.capacity = min(query.capacity, (int)attr_types[i].numelements()); + query.capacity = min(query.capacity, (int)attr_types[i].numelements()); /* convert the OSL (OIIO) type to the equivalent Partio type so we can do a fast check at query time. */ - if(element_type == TypeDesc::TypeFloat) - query.attr_partio_types[i] = Partio::FLOAT; - else if(element_type == TypeDesc::TypeInt) - query.attr_partio_types[i] = Partio::INT; - else if(element_type == TypeDesc::TypeColor || element_type == TypeDesc::TypePoint || - element_type == TypeDesc::TypeVector || element_type == TypeDesc::TypeNormal) - query.attr_partio_types[i] = Partio::VECTOR; - else - return NULL; /* report some error of unknown type */ + if (element_type == TypeDesc::TypeFloat) { + query.attr_partio_types[i] = Partio::FLOAT; + } + else if (element_type == TypeDesc::TypeInt) { + query.attr_partio_types[i] = Partio::INT; + } + else if (element_type == TypeDesc::TypeColor || element_type == TypeDesc::TypePoint || + element_type == TypeDesc::TypeVector || element_type == TypeDesc::TypeNormal) + { + query.attr_partio_types[i] = Partio::VECTOR; + } + else { + return NULL; /* report some error of unknown type */ + } } /* this is valid until the end of RenderServices */ @@ -348,18 +356,18 @@ Partio::ParticlesData *OSLRenderServices::get_pointcloud(ustring filename) #endif int OSLRenderServices::pointcloud(ustring filename, const OSL::Vec3 ¢er, float radius, - int max_points, void *_attr_query, void **attr_outdata) + int max_points, void *_attr_query, void **attr_outdata) { /* todo: this code has never been tested, and most likely does not work. it's based on the example code in OSL */ #ifdef WITH_PARTIO /* query Partio for this pointcloud lookup using cached attr_query */ - if(!_attr_query) + if (!_attr_query) return 0; AttrQuery *attr_query = (AttrQuery *)_attr_query; - if(attr_query->capacity < max_points) + if (attr_query->capacity < max_points) return 0; /* get the pointcloud entry for the given filename */ @@ -370,13 +378,13 @@ int OSLRenderServices::pointcloud(ustring filename, const OSL::Vec3 ¢er, flo int nattrs = attr_query->attr_names.size(); Partio::ParticleAttribute *attr = (Partio::ParticleAttribute *)alloca(sizeof(Partio::ParticleAttribute) * nattrs); - for(int i = 0; i < nattrs; ++i) { + for (int i = 0; i < nattrs; ++i) { /* special case attributes */ - if(attr_query->attr_names[i] == u_distance || attr_query->attr_names[i] == u_index) + if (attr_query->attr_names[i] == u_distance || attr_query->attr_names[i] == u_index) continue; /* lookup the attribute by name*/ - if(!cloud->attributeInfo(attr_query->attr_names[i].c_str(), attr[i])) { + if (!cloud->attributeInfo(attr_query->attr_names[i].c_str(), attr[i])) { /* issue an error here and return, types don't match */ Partio::endCachedAccess(cloud); cloud->release(); @@ -394,14 +402,14 @@ int OSLRenderServices::pointcloud(ustring filename, const OSL::Vec3 ¢er, flo int count = indices.size(); /* retrieve the attributes directly to user space */ - for(int j = 0; j < nattrs; ++j) { + for (int j = 0; j < nattrs; ++j) { /* special cases */ - if(attr_query->attr_names[j] == u_distance) { - for(int i = 0; i < count; ++i) + if (attr_query->attr_names[j] == u_distance) { + for (int i = 0; i < count; ++i) ((float *)attr_outdata[j])[i] = sqrtf(dist2[i]); } - else if(attr_query->attr_names[j] == u_index) { - for(int i = 0; i < count; ++i) + else if (attr_query->attr_names[j] == u_index) { + for (int i = 0; i < count; ++i) ((int *)attr_outdata[j])[i] = indices[i]; } else { diff --git a/intern/cycles/kernel/osl/osl_services.h b/intern/cycles/kernel/osl/osl_services.h index 85a01e54e5c..88735c073c2 100644 --- a/intern/cycles/kernel/osl/osl_services.h +++ b/intern/cycles/kernel/osl/osl_services.h @@ -57,19 +57,19 @@ public: bool get_inverse_matrix(OSL::Matrix44 &result, ustring to, float time); bool get_array_attribute(void *renderstate, bool derivatives, - ustring object, TypeDesc type, ustring name, - int index, void *val); + ustring object, TypeDesc type, ustring name, + int index, void *val); bool get_attribute(void *renderstate, bool derivatives, ustring object, - TypeDesc type, ustring name, void *val); + TypeDesc type, ustring name, void *val); bool get_userdata(bool derivatives, ustring name, TypeDesc type, - void *renderstate, void *val); + void *renderstate, void *val); bool has_userdata(ustring name, TypeDesc type, void *renderstate); void *get_pointcloud_attr_query(ustring *attr_names, - TypeDesc *attr_types, int nattrs); + TypeDesc *attr_types, int nattrs); int pointcloud(ustring filename, const OSL::Vec3 ¢er, float radius, - int max_points, void *attr_query, void **attr_outdata); + int max_points, void *attr_query, void **attr_outdata); private: KernelGlobals *kernel_globals; @@ -79,8 +79,7 @@ private: right now it only caches the types already converted to Partio constants. this is what get_pointcloud_attr_query returns */ - struct AttrQuery - { + struct AttrQuery { /* names of the attributes to query */ std::vector<ustring> attr_names; /* types as (enum Partio::ParticleAttributeType) of the diff --git a/intern/cycles/kernel/osl/osl_shader.cpp b/intern/cycles/kernel/osl/osl_shader.cpp index 18a8e974492..d8d510a7c9b 100644 --- a/intern/cycles/kernel/osl/osl_shader.cpp +++ b/intern/cycles/kernel/osl/osl_shader.cpp @@ -27,7 +27,6 @@ #include "util_foreach.h" #include <OSL/oslexec.h> -#include <oslexec_pvt.h> CCL_NAMESPACE_BEGIN @@ -37,7 +36,7 @@ tls_ptr(OSLGlobals::ThreadData, OSLGlobals::thread_data); void OSLShader::thread_init(KernelGlobals *kg) { - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl*)kg->osl.ss; + OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; OSLGlobals::ThreadData *tdata = new OSLGlobals::ThreadData(); @@ -46,12 +45,12 @@ void OSLShader::thread_init(KernelGlobals *kg) tls_set(kg->osl.thread_data, tdata); - ((OSLRenderServices*)ssi->renderer())->thread_init(kg); + ((OSLRenderServices *)ssi->renderer())->thread_init(kg); } void OSLShader::thread_free(KernelGlobals *kg) { - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl*)kg->osl.ss; + OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); @@ -62,12 +61,12 @@ void OSLShader::thread_free(KernelGlobals *kg) /* Globals */ -#define TO_VEC3(v) (*(OSL::Vec3*)&(v)) -#define TO_COLOR3(v) (*(OSL::Color3*)&(v)) +#define TO_VEC3(v) (*(OSL::Vec3 *)&(v)) +#define TO_COLOR3(v) (*(OSL::Color3 *)&(v)) #define TO_FLOAT3(v) make_float3(v[0], v[1], v[2]) static void shaderdata_to_shaderglobals(KernelGlobals *kg, ShaderData *sd, - int path_flag, OSL::ShaderGlobals *globals) + int path_flag, OSL::ShaderGlobals *globals) { /* copy from shader data to shader globals */ globals->P = TO_VEC3(sd->P); @@ -86,7 +85,7 @@ static void shaderdata_to_shaderglobals(KernelGlobals *kg, ShaderData *sd, globals->dvdy = sd->dv.dy; globals->dPdu = TO_VEC3(sd->dPdu); globals->dPdv = TO_VEC3(sd->dPdv); - globals->surfacearea = (sd->object == ~0)? 1.0f: object_surface_area(kg, sd->object); + globals->surfacearea = (sd->object == ~0) ? 1.0f : object_surface_area(kg, sd->object); /* booleans */ globals->raytype = path_flag; /* todo: add our own ray types */ @@ -109,35 +108,35 @@ static void shaderdata_to_shaderglobals(KernelGlobals *kg, ShaderData *sd, /* Surface */ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, - const OSL::ClosureColor *closure, float3 weight = make_float3(1.0f, 1.0f, 1.0f)) + const OSL::ClosureColor *closure, float3 weight = make_float3(1.0f, 1.0f, 1.0f)) { - /* OSL gives use a closure tree, we flatten it into arrays per + /* OSL gives us a closure tree, we flatten it into arrays per * closure type, for evaluation, sampling, etc later on. */ - if(closure->type == OSL::ClosureColor::COMPONENT) { - OSL::ClosureComponent *comp = (OSL::ClosureComponent*)closure; - OSL::ClosurePrimitive *prim = (OSL::ClosurePrimitive*)comp->data(); + if (closure->type == OSL::ClosureColor::COMPONENT) { + OSL::ClosureComponent *comp = (OSL::ClosureComponent *)closure; + OSL::ClosurePrimitive *prim = (OSL::ClosurePrimitive *)comp->data(); - if(prim) { + if (prim) { ShaderClosure sc; sc.prim = prim; sc.weight = weight; - switch(prim->category()) { + switch (prim->category()) { case ClosurePrimitive::BSDF: { - if(sd->num_closure == MAX_CLOSURE) + if (sd->num_closure == MAX_CLOSURE) return; - OSL::BSDFClosure *bsdf = (OSL::BSDFClosure*)prim; + OSL::BSDFClosure *bsdf = (OSL::BSDFClosure *)prim; ustring scattering = bsdf->scattering(); /* no caustics option */ - if(no_glossy && scattering == OSL::Labels::GLOSSY) + if (no_glossy && scattering == OSL::Labels::GLOSSY) return; /* sample weight */ float albedo = bsdf->albedo(TO_VEC3(sd->I)); - float sample_weight = fabsf(average(weight))*albedo; + float sample_weight = fabsf(average(weight)) * albedo; float sample_sum = sd->osl_closure.bsdf_sample_sum + sample_weight; sc.sample_weight = sample_weight; @@ -145,10 +144,10 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, sd->osl_closure.bsdf_sample_sum = sample_sum; /* scattering flags */ - if(scattering == OSL::Labels::DIFFUSE) - sd->flag |= SD_BSDF|SD_BSDF_HAS_EVAL; - else if(scattering == OSL::Labels::GLOSSY) - sd->flag |= SD_BSDF|SD_BSDF_HAS_EVAL|SD_BSDF_GLOSSY; + if (scattering == OSL::Labels::DIFFUSE) + sd->flag |= SD_BSDF | SD_BSDF_HAS_EVAL; + else if (scattering == OSL::Labels::GLOSSY) + sd->flag |= SD_BSDF | SD_BSDF_HAS_EVAL | SD_BSDF_GLOSSY; else sd->flag |= SD_BSDF; @@ -157,7 +156,7 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, break; } case ClosurePrimitive::Emissive: { - if(sd->num_closure == MAX_CLOSURE) + if (sd->num_closure == MAX_CLOSURE) return; /* sample weight */ @@ -175,7 +174,7 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, break; } case ClosurePrimitive::Holdout: - if(sd->num_closure == MAX_CLOSURE) + if (sd->num_closure == MAX_CLOSURE) return; sc.sample_weight = 0.0f; @@ -192,12 +191,12 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, } } } - else if(closure->type == OSL::ClosureColor::MUL) { - OSL::ClosureMul *mul = (OSL::ClosureMul*)closure; + else if (closure->type == OSL::ClosureColor::MUL) { + OSL::ClosureMul *mul = (OSL::ClosureMul *)closure; flatten_surface_closure_tree(sd, no_glossy, mul->closure, TO_FLOAT3(mul->weight) * weight); } - else if(closure->type == OSL::ClosureColor::ADD) { - OSL::ClosureAdd *add = (OSL::ClosureAdd*)closure; + else if (closure->type == OSL::ClosureColor::ADD) { + OSL::ClosureAdd *add = (OSL::ClosureAdd *)closure; flatten_surface_closure_tree(sd, no_glossy, add->closureA, weight); flatten_surface_closure_tree(sd, no_glossy, add->closureB, weight); } @@ -206,7 +205,7 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy, void OSLShader::eval_surface(KernelGlobals *kg, ShaderData *sd, float randb, int path_flag) { /* gather pointers */ - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl*)kg->osl.ss; + OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); OSL::ShaderGlobals *globals = &tdata->globals; OSL::pvt::ShadingContext *ctx = ssi->get_context(tdata->thread_info); @@ -218,14 +217,14 @@ void OSLShader::eval_surface(KernelGlobals *kg, ShaderData *sd, float randb, int /* execute shader for this point */ int shader = sd->shader & SHADER_MASK; - if(kg->osl.surface_state[shader]) + if (kg->osl.surface_state[shader]) ctx->execute(OSL::pvt::ShadUseSurface, *(kg->osl.surface_state[shader]), *globals); /* flatten closure tree */ sd->num_closure = 0; sd->randb_closure = randb; - if(globals->Ci) { + if (globals->Ci) { bool no_glossy = (path_flag & PATH_RAY_DIFFUSE) && kernel_data.integrator.no_caustics; flatten_surface_closure_tree(sd, no_glossy, globals->Ci); } @@ -235,27 +234,27 @@ void OSLShader::eval_surface(KernelGlobals *kg, ShaderData *sd, float randb, int static float3 flatten_background_closure_tree(const OSL::ClosureColor *closure) { - /* OSL gives use a closure tree, if we are shading for background there + /* OSL gives us a closure tree, if we are shading for background there * is only one supported closure type at the moment, which has no evaluation * functions, so we just sum the weights */ - if(closure->type == OSL::ClosureColor::COMPONENT) { - OSL::ClosureComponent *comp = (OSL::ClosureComponent*)closure; - OSL::ClosurePrimitive *prim = (OSL::ClosurePrimitive*)comp->data(); + if (closure->type == OSL::ClosureColor::COMPONENT) { + OSL::ClosureComponent *comp = (OSL::ClosureComponent *)closure; + OSL::ClosurePrimitive *prim = (OSL::ClosurePrimitive *)comp->data(); - if(prim && prim->category() == OSL::ClosurePrimitive::Background) + if (prim && prim->category() == OSL::ClosurePrimitive::Background) return make_float3(1.0f, 1.0f, 1.0f); } - else if(closure->type == OSL::ClosureColor::MUL) { - OSL::ClosureMul *mul = (OSL::ClosureMul*)closure; + else if (closure->type == OSL::ClosureColor::MUL) { + OSL::ClosureMul *mul = (OSL::ClosureMul *)closure; return TO_FLOAT3(mul->weight) * flatten_background_closure_tree(mul->closure); } - else if(closure->type == OSL::ClosureColor::ADD) { - OSL::ClosureAdd *add = (OSL::ClosureAdd*)closure; + else if (closure->type == OSL::ClosureColor::ADD) { + OSL::ClosureAdd *add = (OSL::ClosureAdd *)closure; return flatten_background_closure_tree(add->closureA) + - flatten_background_closure_tree(add->closureB); + flatten_background_closure_tree(add->closureB); } return make_float3(0.0f, 0.0f, 0.0f); @@ -264,7 +263,7 @@ static float3 flatten_background_closure_tree(const OSL::ClosureColor *closure) float3 OSLShader::eval_background(KernelGlobals *kg, ShaderData *sd, int path_flag) { /* gather pointers */ - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl*)kg->osl.ss; + OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); OSL::ShaderGlobals *globals = &tdata->globals; OSL::pvt::ShadingContext *ctx = ssi->get_context(tdata->thread_info); @@ -274,11 +273,11 @@ float3 OSLShader::eval_background(KernelGlobals *kg, ShaderData *sd, int path_fl shaderdata_to_shaderglobals(kg, sd, path_flag, globals); /* execute shader for this point */ - if(kg->osl.background_state) + if (kg->osl.background_state) ctx->execute(OSL::pvt::ShadUseSurface, *kg->osl.background_state, *globals); /* return background color immediately */ - if(globals->Ci) + if (globals->Ci) return flatten_background_closure_tree(globals->Ci); return make_float3(0.0f, 0.0f, 0.0f); @@ -287,23 +286,23 @@ float3 OSLShader::eval_background(KernelGlobals *kg, ShaderData *sd, int path_fl /* Volume */ static void flatten_volume_closure_tree(ShaderData *sd, - const OSL::ClosureColor *closure, float3 weight = make_float3(1.0f, 1.0f, 1.0f)) + const OSL::ClosureColor *closure, float3 weight = make_float3(1.0f, 1.0f, 1.0f)) { - /* OSL gives use a closure tree, we flatten it into arrays per + /* OSL gives us a closure tree, we flatten it into arrays per * closure type, for evaluation, sampling, etc later on. */ - if(closure->type == OSL::ClosureColor::COMPONENT) { - OSL::ClosureComponent *comp = (OSL::ClosureComponent*)closure; - OSL::ClosurePrimitive *prim = (OSL::ClosurePrimitive*)comp->data(); + if (closure->type == OSL::ClosureColor::COMPONENT) { + OSL::ClosureComponent *comp = (OSL::ClosureComponent *)closure; + OSL::ClosurePrimitive *prim = (OSL::ClosurePrimitive *)comp->data(); - if(prim) { + if (prim) { ShaderClosure sc; sc.prim = prim; sc.weight = weight; - switch(prim->category()) { + switch (prim->category()) { case ClosurePrimitive::Volume: { - if(sd->num_closure == MAX_CLOSURE) + if (sd->num_closure == MAX_CLOSURE) return; /* sample weight */ @@ -329,12 +328,12 @@ static void flatten_volume_closure_tree(ShaderData *sd, } } } - else if(closure->type == OSL::ClosureColor::MUL) { - OSL::ClosureMul *mul = (OSL::ClosureMul*)closure; + else if (closure->type == OSL::ClosureColor::MUL) { + OSL::ClosureMul *mul = (OSL::ClosureMul *)closure; flatten_volume_closure_tree(sd, mul->closure, TO_FLOAT3(mul->weight) * weight); } - else if(closure->type == OSL::ClosureColor::ADD) { - OSL::ClosureAdd *add = (OSL::ClosureAdd*)closure; + else if (closure->type == OSL::ClosureColor::ADD) { + OSL::ClosureAdd *add = (OSL::ClosureAdd *)closure; flatten_volume_closure_tree(sd, add->closureA, weight); flatten_volume_closure_tree(sd, add->closureB, weight); } @@ -343,7 +342,7 @@ static void flatten_volume_closure_tree(ShaderData *sd, void OSLShader::eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int path_flag) { /* gather pointers */ - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl*)kg->osl.ss; + OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); OSL::ShaderGlobals *globals = &tdata->globals; OSL::pvt::ShadingContext *ctx = ssi->get_context(tdata->thread_info); @@ -355,7 +354,7 @@ void OSLShader::eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int /* execute shader */ int shader = sd->shader & SHADER_MASK; - if(kg->osl.volume_state[shader]) + if (kg->osl.volume_state[shader]) ctx->execute(OSL::pvt::ShadUseSurface, *(kg->osl.volume_state[shader]), *globals); /* retrieve resulting closures */ @@ -363,7 +362,7 @@ void OSLShader::eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int sd->osl_closure.num_volume = 0; sd->osl_closure.randb = randb; - if(globals->Ci) + if (globals->Ci) flatten_volume_closure_tree(sd, globals->Ci); } @@ -372,7 +371,7 @@ void OSLShader::eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int void OSLShader::eval_displacement(KernelGlobals *kg, ShaderData *sd) { /* gather pointers */ - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl*)kg->osl.ss; + OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); OSL::ShaderGlobals *globals = &tdata->globals; OSL::pvt::ShadingContext *ctx = ssi->get_context(tdata->thread_info); @@ -384,7 +383,7 @@ void OSLShader::eval_displacement(KernelGlobals *kg, ShaderData *sd) /* execute shader */ int shader = sd->shader & SHADER_MASK; - if(kg->osl.displacement_state[shader]) + if (kg->osl.displacement_state[shader]) ctx->execute(OSL::pvt::ShadUseSurface, *(kg->osl.displacement_state[shader]), *globals); /* get back position */ @@ -393,17 +392,17 @@ void OSLShader::eval_displacement(KernelGlobals *kg, ShaderData *sd) void OSLShader::release(KernelGlobals *kg, const ShaderData *sd) { - OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl*)kg->osl.ss; + OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss; OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data); - ssi->release_context((OSL::pvt::ShadingContext*)sd->osl_ctx, tdata->thread_info); + ssi->release_context((OSL::pvt::ShadingContext *)sd->osl_ctx, tdata->thread_info); } /* BSDF Closure */ int OSLShader::bsdf_sample(const ShaderData *sd, const ShaderClosure *sc, float randu, float randv, float3& eval, float3& omega_in, differential3& domega_in, float& pdf) { - OSL::BSDFClosure *sample_bsdf = (OSL::BSDFClosure*)sc->prim; + OSL::BSDFClosure *sample_bsdf = (OSL::BSDFClosure *)sc->prim; int label = LABEL_NONE; pdf = 0.0f; @@ -412,27 +411,27 @@ int OSLShader::bsdf_sample(const ShaderData *sd, const ShaderClosure *sc, float ustring ulabel; ulabel = sample_bsdf->sample(TO_VEC3(sd->Ng), - TO_VEC3(sd->I), TO_VEC3(sd->dI.dx), TO_VEC3(sd->dI.dy), - randu, randv, - TO_VEC3(omega_in), TO_VEC3(domega_in.dx), TO_VEC3(domega_in.dy), - pdf, TO_COLOR3(eval)); + TO_VEC3(sd->I), TO_VEC3(sd->dI.dx), TO_VEC3(sd->dI.dy), + randu, randv, + TO_VEC3(omega_in), TO_VEC3(domega_in.dx), TO_VEC3(domega_in.dy), + pdf, TO_COLOR3(eval)); /* convert OSL label */ - if(ulabel == OSL::Labels::REFLECT) + if (ulabel == OSL::Labels::REFLECT) label = LABEL_REFLECT; - else if(ulabel == OSL::Labels::TRANSMIT) + else if (ulabel == OSL::Labels::TRANSMIT) label = LABEL_TRANSMIT; else - return LABEL_NONE; /* sampling failed */ + return LABEL_NONE; /* sampling failed */ /* convert scattering to our bitflag label */ ustring uscattering = sample_bsdf->scattering(); - if(uscattering == OSL::Labels::DIFFUSE) + if (uscattering == OSL::Labels::DIFFUSE) label |= LABEL_DIFFUSE; - else if(uscattering == OSL::Labels::GLOSSY) + else if (uscattering == OSL::Labels::GLOSSY) label |= LABEL_GLOSSY; - else if(uscattering == OSL::Labels::SINGULAR) + else if (uscattering == OSL::Labels::SINGULAR) label |= LABEL_SINGULAR; else label |= LABEL_TRANSPARENT; @@ -442,10 +441,10 @@ int OSLShader::bsdf_sample(const ShaderData *sd, const ShaderClosure *sc, float float3 OSLShader::bsdf_eval(const ShaderData *sd, const ShaderClosure *sc, const float3& omega_in, float& pdf) { - OSL::BSDFClosure *bsdf = (OSL::BSDFClosure*)sc->prim; + OSL::BSDFClosure *bsdf = (OSL::BSDFClosure *)sc->prim; OSL::Color3 bsdf_eval; - if(dot(sd->Ng, omega_in) >= 0.0f) + if (dot(sd->Ng, omega_in) >= 0.0f) bsdf_eval = bsdf->eval_reflect(TO_VEC3(sd->I), TO_VEC3(omega_in), pdf); else bsdf_eval = bsdf->eval_transmit(TO_VEC3(sd->I), TO_VEC3(omega_in), pdf); @@ -457,7 +456,7 @@ float3 OSLShader::bsdf_eval(const ShaderData *sd, const ShaderClosure *sc, const float3 OSLShader::emissive_eval(const ShaderData *sd, const ShaderClosure *sc) { - OSL::EmissiveClosure *emissive = (OSL::EmissiveClosure*)sc->prim; + OSL::EmissiveClosure *emissive = (OSL::EmissiveClosure *)sc->prim; OSL::Color3 emissive_eval = emissive->eval(TO_VEC3(sd->Ng), TO_VEC3(sd->I)); eval += TO_FLOAT3(emissive_eval); @@ -468,9 +467,9 @@ float3 OSLShader::emissive_eval(const ShaderData *sd, const ShaderClosure *sc) float3 OSLShader::volume_eval_phase(const ShaderData *sd, const ShaderClosure *sc, const float3 omega_in, const float3 omega_out) { - OSL::VolumeClosure *volume = (OSL::VolumeClosure*)sc->prim; + OSL::VolumeClosure *volume = (OSL::VolumeClosure *)sc->prim; OSL::Color3 volume_eval = volume->eval_phase(TO_VEC3(omega_in), TO_VEC3(omega_out)); - return TO_FLOAT3(volume_eval)*sc->weight; + return TO_FLOAT3(volume_eval) * sc->weight; } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/osl/osl_shader.h b/intern/cycles/kernel/osl/osl_shader.h index 6b1d402989b..815557ed203 100644 --- a/intern/cycles/kernel/osl/osl_shader.h +++ b/intern/cycles/kernel/osl/osl_shader.h @@ -68,15 +68,15 @@ public: /* sample & eval */ static int bsdf_sample(const ShaderData *sd, const ShaderClosure *sc, - float randu, float randv, - float3& eval, float3& omega_in, differential3& domega_in, float& pdf); + float randu, float randv, + float3& eval, float3& omega_in, differential3& domega_in, float& pdf); static float3 bsdf_eval(const ShaderData *sd, const ShaderClosure *sc, - const float3& omega_in, float& pdf); + const float3& omega_in, float& pdf); static float3 emissive_eval(const ShaderData *sd, const ShaderClosure *sc); static float3 volume_eval_phase(const ShaderData *sd, const ShaderClosure *sc, - const float3 omega_in, const float3 omega_out); + const float3 omega_in, const float3 omega_out); /* release */ static void release(KernelGlobals *kg, const ShaderData *sd); diff --git a/intern/cycles/kernel/osl/vol_subsurface.cpp b/intern/cycles/kernel/osl/vol_subsurface.cpp index 0cd3060051b..818a057b6cc 100644 --- a/intern/cycles/kernel/osl/vol_subsurface.cpp +++ b/intern/cycles/kernel/osl/vol_subsurface.cpp @@ -46,88 +46,90 @@ using namespace OSL; class SubsurfaceClosure : public VolumeClosure { public: - float m_g; - float m_eta; - Color3 m_mfp, m_albedo; - static float root_find_Rd(const float Rd0, const float A) { - // quick exit for trivial cases - if (Rd0 <= 0) return 0; - const float A43 = A * 4.0f / 3.0f; - // Find alpha such that f(alpha) = Rd (see eq.15). A simple bisection - // method can be used because this function is monotonicaly increasing. - float lo = 0, hi = 1; - for (int i = 0; i < 20; i++) { // 2^20 divisions should be sufficient - // eval function at midpoint - float alpha = 0.5f * (lo + hi); - float a1 = sqrtf(3 * (1 - alpha)); - float e1 = expf(-a1); - float e2 = expf(-A43 * a1); - float Rd = 0.5f * alpha * (1 + e2) * e1 - Rd0; - if (fabsf(Rd) < 1e-6f) - return alpha; // close enough - else if (Rd > 0) - hi = alpha; // root is on left side - else - lo = alpha; // root is on right side - } - // didn't quite converge, pick result in the middle of remaining interval - return 0.5f * (lo + hi); - } - SubsurfaceClosure() { } - - void setup() - { - ior(m_eta); - - if (m_g >= 0.99f) m_g = 0.99f; - if (m_g <= -0.99f) m_g = -0.99f; - - // eq.10 - float inv_eta = 1 / m_eta; - float Fdr = -1.440f * inv_eta * inv_eta + 0.710 * inv_eta + 0.668f + 0.0636 * m_eta; - float A = (1 + Fdr) / (1 - Fdr); - // compute sigma_s, sigma_a (eq.16) - Color3 alpha_prime = Color3 (root_find_Rd(m_albedo[0], A), - root_find_Rd(m_albedo[1], A), - root_find_Rd(m_albedo[2], A)); - Color3 sigma_t_prime = Color3 (m_mfp.x > 0 ? 1.0f / (m_mfp[0] * sqrtf(3 * (1 - alpha_prime[0]))) : 0.0f, - m_mfp.y > 0 ? 1.0f / (m_mfp[1] * sqrtf(3 * (1 - alpha_prime[1]))) : 0.0f, - m_mfp.z > 0 ? 1.0f / (m_mfp[2] * sqrtf(3 * (1 - alpha_prime[2]))) : 0.0f); - Color3 sigma_s_prime = alpha_prime * sigma_t_prime; - - sigma_s((1.0f / (1 - m_g)) * sigma_s_prime); - sigma_a(sigma_t_prime - sigma_s_prime); - } - - bool mergeable (const ClosurePrimitive *other) const { - const SubsurfaceClosure *comp = (const SubsurfaceClosure *)other; - return m_g == comp->m_g && VolumeClosure::mergeable(other); - } - - size_t memsize () const { return sizeof(*this); } - - const char *name () const { return "subsurface"; } - - void print_on (std::ostream &out) const { - out << name() << " ()"; - } - - virtual Color3 eval_phase(const Vec3 &omega_in, const Vec3 &omega_out) const { - float costheta = omega_in.dot(omega_out); - float ph = 0.25f * float(M_1_PI) * ((1 - m_g * m_g) / powf(1 + m_g * m_g - 2.0f * m_g * costheta, 1.5f)); - return Color3 (ph, ph, ph); - } + float m_g; + float m_eta; + Color3 m_mfp, m_albedo; + static float root_find_Rd(const float Rd0, const float A) { + // quick exit for trivial cases + if (Rd0 <= 0) return 0; + const float A43 = A * 4.0f / 3.0f; + // Find alpha such that f(alpha) = Rd (see eq.15). A simple bisection + // method can be used because this function is monotonicaly increasing. + float lo = 0, hi = 1; + for (int i = 0; i < 20; i++) { // 2^20 divisions should be sufficient + // eval function at midpoint + float alpha = 0.5f * (lo + hi); + float a1 = sqrtf(3 * (1 - alpha)); + float e1 = expf(-a1); + float e2 = expf(-A43 * a1); + float Rd = 0.5f * alpha * (1 + e2) * e1 - Rd0; + if (fabsf(Rd) < 1e-6f) + return alpha; // close enough + else if (Rd > 0) + hi = alpha; // root is on left side + else + lo = alpha; // root is on right side + } + // didn't quite converge, pick result in the middle of remaining interval + return 0.5f * (lo + hi); + } + SubsurfaceClosure() { + } + + void setup() + { + ior(m_eta); + + if (m_g >= 0.99f) m_g = 0.99f; + if (m_g <= -0.99f) m_g = -0.99f; + + // eq.10 + float inv_eta = 1 / m_eta; + float Fdr = -1.440f * inv_eta * inv_eta + 0.710 * inv_eta + 0.668f + 0.0636 * m_eta; + float A = (1 + Fdr) / (1 - Fdr); + // compute sigma_s, sigma_a (eq.16) + Color3 alpha_prime = Color3(root_find_Rd(m_albedo[0], A), + root_find_Rd(m_albedo[1], A), + root_find_Rd(m_albedo[2], A)); + Color3 sigma_t_prime = Color3(m_mfp.x > 0 ? 1.0f / (m_mfp[0] * sqrtf(3 * (1 - alpha_prime[0]))) : 0.0f, + m_mfp.y > 0 ? 1.0f / (m_mfp[1] * sqrtf(3 * (1 - alpha_prime[1]))) : 0.0f, + m_mfp.z > 0 ? 1.0f / (m_mfp[2] * sqrtf(3 * (1 - alpha_prime[2]))) : 0.0f); + Color3 sigma_s_prime = alpha_prime * sigma_t_prime; + + sigma_s((1.0f / (1 - m_g)) * sigma_s_prime); + sigma_a(sigma_t_prime - sigma_s_prime); + } + + bool mergeable(const ClosurePrimitive *other) const { + const SubsurfaceClosure *comp = (const SubsurfaceClosure *)other; + return m_g == comp->m_g && VolumeClosure::mergeable(other); + } + + size_t memsize() const { return sizeof(*this); } + + const char *name() const { return "subsurface"; } + + void print_on(std::ostream &out) const { + out << name() << " ()"; + } + + virtual Color3 eval_phase(const Vec3 &omega_in, const Vec3 &omega_out) const { + float costheta = omega_in.dot(omega_out); + float ph = 0.25f * float(M_1_PI) * ((1 - m_g * m_g) / powf(1 + m_g * m_g - 2.0f * m_g * costheta, 1.5f)); + return Color3(ph, ph, ph); + } }; ClosureParam closure_subsurface_params[] = { - CLOSURE_FLOAT_PARAM (SubsurfaceClosure, m_eta), - CLOSURE_FLOAT_PARAM (SubsurfaceClosure, m_g), - CLOSURE_COLOR_PARAM (SubsurfaceClosure, m_mfp), - CLOSURE_COLOR_PARAM (SubsurfaceClosure, m_albedo), - CLOSURE_STRING_KEYPARAM("label"), - CLOSURE_FINISH_PARAM(SubsurfaceClosure) }; + CLOSURE_FLOAT_PARAM(SubsurfaceClosure, m_eta), + CLOSURE_FLOAT_PARAM(SubsurfaceClosure, m_g), + CLOSURE_COLOR_PARAM(SubsurfaceClosure, m_mfp), + CLOSURE_COLOR_PARAM(SubsurfaceClosure, m_albedo), + CLOSURE_STRING_KEYPARAM("label"), + CLOSURE_FINISH_PARAM(SubsurfaceClosure) +}; CLOSURE_PREPARE(closure_subsurface_prepare, SubsurfaceClosure) diff --git a/intern/cycles/kernel/svm/emissive.h b/intern/cycles/kernel/svm/emissive.h index e3f99e9b729..0b0218674b8 100644 --- a/intern/cycles/kernel/svm/emissive.h +++ b/intern/cycles/kernel/svm/emissive.h @@ -34,14 +34,6 @@ CCL_NAMESPACE_BEGIN /* EMISSION CLOSURE */ -__device float3 emissive_eval(const float3 Ng, const float3 I) -{ - float cosNO = fabsf(dot(Ng, I)); - float res = (cosNO > 0.0f)? 1.0f: 0.0f; - - return make_float3(res, res, res); -} - /// Return the probability distribution function in the direction I, /// given the parameters and the light's surface normal. This MUST match /// the PDF computed by sample(). @@ -51,6 +43,13 @@ __device float emissive_pdf(const float3 Ng, const float3 I) return (cosNO > 0.0f)? 1.0f: 0.0f; } +__device float3 emissive_eval(const float3 Ng, const float3 I) +{ + float res = emissive_pdf(Ng, I); + + return make_float3(res, res, res); +} + __device float3 svm_emissive_eval(ShaderData *sd, ShaderClosure *sc) { return emissive_eval(sd->Ng, sd->I); diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp index 267cb8e6d3a..1bf1cde4a1c 100644 --- a/intern/cycles/render/light.cpp +++ b/intern/cycles/render/light.cpp @@ -109,6 +109,9 @@ Light::Light() map_resolution = 512; + spot_angle = M_PI_F/4.0f; + spot_smooth = 0.0f; + cast_shadow = true; shader = 0; } @@ -451,6 +454,17 @@ void LightManager::device_update_points(Device *device, DeviceScene *dscene, Sce light_data[i*LIGHT_SIZE + 2] = make_float4(0.0f, axisv.x, axisv.y, axisv.z); light_data[i*LIGHT_SIZE + 3] = make_float4(0.0f, dir.x, dir.y, dir.z); } + else if(light->type == LIGHT_SPOT) { + shader_id &= ~SHADER_AREA_LIGHT; + + float spot_angle = cosf(light->spot_angle*0.5f); + float spot_smooth = (1.0f - spot_angle)*light->spot_smooth; + + light_data[i*LIGHT_SIZE + 0] = make_float4(__int_as_float(light->type), co.x, co.y, co.z); + light_data[i*LIGHT_SIZE + 1] = make_float4(__int_as_float(shader_id), light->size, dir.x, dir.y); + light_data[i*LIGHT_SIZE + 2] = make_float4(dir.z, spot_angle, spot_smooth, 0.0f); + light_data[i*LIGHT_SIZE + 3] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + } } device->tex_alloc("__light_data", dscene->light_data); diff --git a/intern/cycles/render/light.h b/intern/cycles/render/light.h index 0ed143f5ad1..fb8684fa59b 100644 --- a/intern/cycles/render/light.h +++ b/intern/cycles/render/light.h @@ -48,6 +48,9 @@ public: int map_resolution; + float spot_angle; + float spot_smooth; + bool cast_shadow; int shader; diff --git a/intern/cycles/util/util_math.h b/intern/cycles/util/util_math.h index fee2f10085b..cd44b7e8cda 100644 --- a/intern/cycles/util/util_math.h +++ b/intern/cycles/util/util_math.h @@ -162,6 +162,12 @@ __device_inline float nonzerof(float f, float eps) return f; } +__device_inline float smoothstepf(float f) +{ + float ff = f*f; + return (3.0f*ff - 2.0f*ff*f); +} + /* Float2 Vector */ #ifndef __KERNEL_OPENCL__ diff --git a/intern/ghost/intern/GHOST_DisplayManagerNULL.h b/intern/ghost/intern/GHOST_DisplayManagerNULL.h index eb116e30d2d..4d5a0b008dc 100644 --- a/intern/ghost/intern/GHOST_DisplayManagerNULL.h +++ b/intern/ghost/intern/GHOST_DisplayManagerNULL.h @@ -41,7 +41,7 @@ public: GHOST_TSuccess getNumDisplaySettings( GHOST_TUns8 display, GHOST_TInt32& numSettings ) const{ return GHOST_kFailure; } GHOST_TSuccess getDisplaySetting( GHOST_TUns8 display, GHOST_TInt32 index, GHOST_DisplaySetting& setting ) const { return GHOST_kFailure; } GHOST_TSuccess getCurrentDisplaySetting( GHOST_TUns8 display, GHOST_DisplaySetting& setting ) const { return getDisplaySetting(display,GHOST_TInt32(0),setting); } - GHOST_TSuccess setCurrentDisplaySetting( GHOST_TUns8 display, const GHOST_DisplaySetting& setting ){ return GHOST_kSuccess; } + GHOST_TSuccess setCurrentDisplaySetting( GHOST_TUns8 display, const GHOST_DisplaySetting& setting ) { return GHOST_kSuccess; } private: GHOST_SystemNULL * m_system; diff --git a/intern/ghost/intern/GHOST_WindowNULL.h b/intern/ghost/intern/GHOST_WindowNULL.h index cde2cb0ba76..dcbb7d2b346 100644 --- a/intern/ghost/intern/GHOST_WindowNULL.h +++ b/intern/ghost/intern/GHOST_WindowNULL.h @@ -60,27 +60,27 @@ public: } protected: - GHOST_TSuccess installDrawingContext( GHOST_TDrawingContextType type ){ return GHOST_kSuccess; } - GHOST_TSuccess removeDrawingContext( ){ return GHOST_kSuccess; } - GHOST_TSuccess setWindowCursorGrab( GHOST_TGrabCursorMode mode ){ return GHOST_kSuccess; } - GHOST_TSuccess setWindowCursorShape( GHOST_TStandardCursor shape ){ return GHOST_kSuccess; } + GHOST_TSuccess installDrawingContext( GHOST_TDrawingContextType type ) { return GHOST_kSuccess; } + GHOST_TSuccess removeDrawingContext( ) { return GHOST_kSuccess; } + GHOST_TSuccess setWindowCursorGrab( GHOST_TGrabCursorMode mode ) { return GHOST_kSuccess; } + GHOST_TSuccess setWindowCursorShape( GHOST_TStandardCursor shape ) { return GHOST_kSuccess; } GHOST_TSuccess setWindowCustomCursorShape( GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], int hotX, int hotY ) { return GHOST_kSuccess; } - GHOST_TSuccess setWindowCustomCursorShape( GHOST_TUns8 *bitmap, GHOST_TUns8 *mask, int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color ){ return GHOST_kSuccess; } + GHOST_TSuccess setWindowCustomCursorShape( GHOST_TUns8 *bitmap, GHOST_TUns8 *mask, int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color ) { return GHOST_kSuccess; } bool getValid( ) const { return true; } - void setTitle( const STR_String& title ){ /* nothing */ } + void setTitle( const STR_String& title ) { /* nothing */ } void getTitle( STR_String& title ) const { title= "untitled"; } void getWindowBounds( GHOST_Rect& bounds ) const { getClientBounds(bounds); } void getClientBounds( GHOST_Rect& bounds ) const { /* nothing */ } - GHOST_TSuccess setClientWidth( GHOST_TUns32 width ){ return GHOST_kFailure; } - GHOST_TSuccess setClientHeight( GHOST_TUns32 height ){ return GHOST_kFailure; } - GHOST_TSuccess setClientSize( GHOST_TUns32 width, GHOST_TUns32 height ){ return GHOST_kFailure; } + GHOST_TSuccess setClientWidth( GHOST_TUns32 width ) { return GHOST_kFailure; } + GHOST_TSuccess setClientHeight( GHOST_TUns32 height ) { return GHOST_kFailure; } + GHOST_TSuccess setClientSize( GHOST_TUns32 width, GHOST_TUns32 height ) { return GHOST_kFailure; } void screenToClient( GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY ) const { outX = inX; outY = inY; } void clientToScreen( GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY ) const { outX = inX; outY = inY; } - GHOST_TSuccess swapBuffers( ){ return GHOST_kFailure; } - GHOST_TSuccess activateDrawingContext( ){ return GHOST_kFailure; } - ~GHOST_WindowNULL( ){ /* nothing */ } - GHOST_TSuccess setWindowCursorVisibility( bool visible ){ return GHOST_kSuccess; } + GHOST_TSuccess swapBuffers( ) { return GHOST_kFailure; } + GHOST_TSuccess activateDrawingContext( ) { return GHOST_kFailure; } + ~GHOST_WindowNULL( ) { /* nothing */ } + GHOST_TSuccess setWindowCursorVisibility( bool visible ) { return GHOST_kSuccess; } GHOST_TSuccess setState(GHOST_TWindowState state) { return GHOST_kSuccess; } GHOST_TWindowState getState() const { return GHOST_kWindowStateNormal; } GHOST_TSuccess invalidate() { return GHOST_kSuccess; } diff --git a/intern/ghost/test/multitest/EventToBuf.c b/intern/ghost/test/multitest/EventToBuf.c index f988f0fb86a..034fbe04447 100644 --- a/intern/ghost/test/multitest/EventToBuf.c +++ b/intern/ghost/test/multitest/EventToBuf.c @@ -36,7 +36,7 @@ char *eventtype_to_string(GHOST_TEventType type) { - switch(type) { + switch (type) { case GHOST_kEventCursorMove: return "CursorMove"; case GHOST_kEventButtonDown: return "ButtonDown"; case GHOST_kEventButtonUp: return "ButtonUp"; diff --git a/intern/itasc/Armature.cpp b/intern/itasc/Armature.cpp index 916b0bc7bf3..dd5c1921a98 100644 --- a/intern/itasc/Armature.cpp +++ b/intern/itasc/Armature.cpp @@ -369,11 +369,13 @@ int Armature::addEndEffector(const std::string& name) return m_neffector++; } -void Armature::finalize() +bool Armature::finalize() { unsigned int i, j, c; if (m_finalized) - return; + return true; + if (m_njoint == 0) + return false; initialize(m_njoint, m_noutput, m_neffector); for (i=c=0; i<m_nconstraint; i++) { JointConstraint_struct* pConstraint = m_constraints[i]; @@ -410,6 +412,7 @@ void Armature::finalize() if (m_armlength < KDL::epsilon) m_armlength = KDL::epsilon; m_finalized = true; + return true; } void Armature::pushCache(const Timestamp& timestamp) diff --git a/intern/itasc/Armature.hpp b/intern/itasc/Armature.hpp index 0f4abeab4f0..63d1899f4e9 100644 --- a/intern/itasc/Armature.hpp +++ b/intern/itasc/Armature.hpp @@ -31,7 +31,7 @@ public: bool getSegment(const std::string& segment_name, const unsigned int q_size, const Joint* &p_joint, double &q_rest, double &q, const Frame* &p_tip); bool getRelativeFrame(Frame& result, const std::string& segment_name, const std::string& base_name=m_root); - virtual void finalize(); + virtual bool finalize(); virtual int addEndEffector(const std::string& name); virtual const Frame& getPose(const unsigned int end_effector); diff --git a/intern/itasc/FixedObject.cpp b/intern/itasc/FixedObject.cpp index 9dc4d69878a..2a1e66f9c6f 100644 --- a/intern/itasc/FixedObject.cpp +++ b/intern/itasc/FixedObject.cpp @@ -53,12 +53,13 @@ int FixedObject::addEndEffector(const std::string& name) return -1; } -void FixedObject::finalize() +bool FixedObject::finalize() { if (m_finalized) - return; + return true; initialize(0, m_nframe); m_finalized = true; + return true; } const Frame& FixedObject::getPose(const unsigned int frameIndex) diff --git a/intern/itasc/FixedObject.hpp b/intern/itasc/FixedObject.hpp index b4279d9adcb..ad26e7cb2d6 100644 --- a/intern/itasc/FixedObject.hpp +++ b/intern/itasc/FixedObject.hpp @@ -23,7 +23,7 @@ public: virtual void updateCoordinates(const Timestamp& timestamp) {}; virtual int addEndEffector(const std::string& name); - virtual void finalize(); + virtual bool finalize(); virtual const Frame& getPose(const unsigned int frameIndex); virtual void updateKinematics(const Timestamp& timestamp) {}; virtual void pushCache(const Timestamp& timestamp) {}; diff --git a/intern/itasc/MovingFrame.cpp b/intern/itasc/MovingFrame.cpp index 3b0ee7842ca..90ebe091eb5 100644 --- a/intern/itasc/MovingFrame.cpp +++ b/intern/itasc/MovingFrame.cpp @@ -27,9 +27,10 @@ MovingFrame::~MovingFrame() { } -void MovingFrame::finalize() +bool MovingFrame::finalize() { updateJacobian(); + return true; } void MovingFrame::initCache(Cache *_cache) diff --git a/intern/itasc/MovingFrame.hpp b/intern/itasc/MovingFrame.hpp index 21cb344980a..d2a956d7312 100644 --- a/intern/itasc/MovingFrame.hpp +++ b/intern/itasc/MovingFrame.hpp @@ -28,7 +28,7 @@ public: virtual void updateKinematics(const Timestamp& timestamp); virtual void pushCache(const Timestamp& timestamp); virtual void initCache(Cache *_cache); - virtual void finalize(); + virtual bool finalize(); protected: virtual void updateJacobian(); diff --git a/intern/itasc/Object.hpp b/intern/itasc/Object.hpp index 5aa4346fc4b..bf80d83e5aa 100644 --- a/intern/itasc/Object.hpp +++ b/intern/itasc/Object.hpp @@ -33,7 +33,7 @@ public: virtual ~Object(){}; virtual int addEndEffector(const std::string& name){return 0;}; - virtual void finalize(){}; + virtual bool finalize(){return true;}; virtual const KDL::Frame& getPose(const unsigned int end_effector=0){return m_internalPose;}; virtual const ObjectType getType(){return m_type;}; virtual const unsigned int getNrOfCoordinates(){return 0;}; diff --git a/intern/itasc/Scene.cpp b/intern/itasc/Scene.cpp index 16f8551bfc7..877cd883208 100644 --- a/intern/itasc/Scene.cpp +++ b/intern/itasc/Scene.cpp @@ -91,7 +91,8 @@ bool Scene::setParam(SceneParam paramId, double value) bool Scene::addObject(const std::string& name, Object* object, UncontrolledObject* base, const std::string& baseFrame) { // finalize the object before adding - object->finalize(); + if (!object->finalize()) + return false; //Check if Object is controlled or uncontrolled. if(object->getType()==Object::Controlled){ int baseFrameIndex = base->addEndEffector(baseFrame); diff --git a/intern/memutil/MEM_Allocator.h b/intern/memutil/MEM_Allocator.h index 9541604b680..0020094ebbb 100644 --- a/intern/memutil/MEM_Allocator.h +++ b/intern/memutil/MEM_Allocator.h @@ -72,7 +72,7 @@ struct MEM_Allocator } // __p is not permitted to be a null pointer. - void deallocate(pointer __p, size_type){ + void deallocate(pointer __p, size_type) { MEM_freeN(__p); } diff --git a/intern/memutil/MEM_RefCountPtr.h b/intern/memutil/MEM_RefCountPtr.h index 4f475345076..ffdf927b551 100644 --- a/intern/memutil/MEM_RefCountPtr.h +++ b/intern/memutil/MEM_RefCountPtr.h @@ -98,7 +98,7 @@ * * static * MEM_RefCountPtr<RcUsefullClass> - * New(...){ + * New(...) { * return MEM_RefCountPtr<RcUsefullClass> output( * new UsefullClass(...) * ); diff --git a/intern/memutil/MEM_SmartPtr.h b/intern/memutil/MEM_SmartPtr.h index 6a0dc1723c4..722a0a8fd3b 100644 --- a/intern/memutil/MEM_SmartPtr.h +++ b/intern/memutil/MEM_SmartPtr.h @@ -119,7 +119,7 @@ public : MEM_SmartPtr( const MEM_SmartPtr &rhs - ){ + ) { m_val = rhs.Release(); } diff --git a/intern/mikktspace/mikktspace.c b/intern/mikktspace/mikktspace.c index 24c77c439a7..cba4c406759 100644 --- a/intern/mikktspace/mikktspace.c +++ b/intern/mikktspace/mikktspace.c @@ -258,7 +258,7 @@ tbool genTangSpace(const SMikkTSpaceContext * pContext, const float fAngularThre { const int verts = pContext->m_pInterface->m_getNumVerticesOfFace(pContext, f); if (verts==3) ++iNrTrianglesIn; - else if(verts==4) iNrTrianglesIn += 2; + else if (verts==4) iNrTrianglesIn += 2; } if (iNrTrianglesIn<=0) return TFALSE; @@ -470,11 +470,11 @@ static void GenerateSharedVerticesIndexList(int piTriList_in_and_out[], const SM const SVec3 vP = GetPosition(pContext, index); if (vMin.x > vP.x) vMin.x = vP.x; - else if(vMax.x < vP.x) vMax.x = vP.x; + else if (vMax.x < vP.x) vMax.x = vP.x; if (vMin.y > vP.y) vMin.y = vP.y; - else if(vMax.y < vP.y) vMax.y = vP.y; + else if (vMax.y < vP.y) vMax.y = vP.y; if (vMin.z > vP.z) vMin.z = vP.z; - else if(vMax.z < vP.z) vMax.z = vP.z; + else if (vMax.z < vP.z) vMax.z = vP.z; } vDim = vsub(vMax,vMin); @@ -485,7 +485,7 @@ static void GenerateSharedVerticesIndexList(int piTriList_in_and_out[], const SM iChannel=1; fMin = vMin.y, fMax=vMax.y; } - else if(vDim.z>vDim.x) + else if (vDim.z>vDim.x) { iChannel=2; fMin = vMin.z, fMax=vMax.z; @@ -590,7 +590,7 @@ static void MergeVertsFast(int piTriList_in_and_out[], STmpVert pTmpVert[], cons for (l=(iL_in+1); l<=iR_in; l++) for (c=0; c<3; c++) if (fvMin[c]>pTmpVert[l].vert[c]) fvMin[c]=pTmpVert[l].vert[c]; - else if(fvMax[c]<pTmpVert[l].vert[c]) fvMax[c]=pTmpVert[l].vert[c]; + else if (fvMax[c]<pTmpVert[l].vert[c]) fvMax[c]=pTmpVert[l].vert[c]; dx = fvMax[0]-fvMin[0]; dy = fvMax[1]-fvMin[1]; @@ -598,7 +598,7 @@ static void MergeVertsFast(int piTriList_in_and_out[], STmpVert pTmpVert[], cons channel = 0; if (dy>dx && dy>dz) channel=1; - else if(dz>dx) channel=2; + else if (dz>dx) channel=2; fSep = 0.5f*(fvMax[channel]+fvMin[channel]); @@ -626,7 +626,7 @@ static void MergeVertsFast(int piTriList_in_and_out[], STmpVert pTmpVert[], cons const SVec3 vT2 = GetTexCoord(pContext, index2); i2rec=i2; - //if(vP==vP2 && vN==vN2 && vT==vT2) + //if (vP==vP2 && vN==vN2 && vT==vT2) if (vP.x==vP2.x && vP.y==vP2.y && vP.z==vP2.z && vN.x==vN2.x && vN.y==vN2.y && vN.z==vN2.z && vT.x==vT2.x && vT.y==vT2.y && vT.z==vT2.z) @@ -812,7 +812,7 @@ static int GenerateInitialVerticesIndexList(STriInfo pTriInfos[], int piTriList_ tbool bQuadDiagIs_02; if (distSQ_02<distSQ_13) bQuadDiagIs_02 = TTRUE; - else if(distSQ_13<distSQ_02) + else if (distSQ_13<distSQ_02) bQuadDiagIs_02 = TFALSE; else { @@ -1027,7 +1027,7 @@ static void InitTriInfo(STriInfo pTriInfos[], const int piTriListIn[], const SMi //printf("found quad with bad mapping\n"); tbool bChooseOrientFirstTri = TFALSE; if ((pTriInfos[t+1].iFlag&GROUP_WITH_ANY)!=0) bChooseOrientFirstTri = TTRUE; - else if( CalcTexArea(pContext, &piTriListIn[t*3+0]) >= CalcTexArea(pContext, &piTriListIn[(t+1)*3+0]) ) + else if ( CalcTexArea(pContext, &piTriListIn[t*3+0]) >= CalcTexArea(pContext, &piTriListIn[(t+1)*3+0]) ) bChooseOrientFirstTri = TTRUE; // force match @@ -1142,13 +1142,13 @@ static tbool AssignRecur(const int piTriListIn[], STriInfo psTriInfos[], const int * pVerts = &piTriListIn[3*iMyTriIndex+0]; int i=-1; if (pVerts[0]==iVertRep) i=0; - else if(pVerts[1]==iVertRep) i=1; - else if(pVerts[2]==iVertRep) i=2; + else if (pVerts[1]==iVertRep) i=1; + else if (pVerts[2]==iVertRep) i=2; assert(i>=0 && i<3); // early out if (pMyTriInfo->AssignedGroup[i] == pGroup) return TTRUE; - else if(pMyTriInfo->AssignedGroup[i]!=NULL) return TFALSE; + else if (pMyTriInfo->AssignedGroup[i]!=NULL) return TFALSE; if ((pMyTriInfo->iFlag&GROUP_WITH_ANY)!=0) { // first to group with a group-with-anything triangle @@ -1232,8 +1232,8 @@ static tbool GenerateTSpaces(STSpace psTspace[], const STriInfo pTriInfos[], con tbool bFound; SVec3 n, vOs, vOt; if (pTriInfos[f].AssignedGroup[0]==pGroup) index=0; - else if(pTriInfos[f].AssignedGroup[1]==pGroup) index=1; - else if(pTriInfos[f].AssignedGroup[2]==pGroup) index=2; + else if (pTriInfos[f].AssignedGroup[1]==pGroup) index=1; + else if (pTriInfos[f].AssignedGroup[2]==pGroup) index=2; assert(index>=0 && index<3); iVertIndex = piTriListIn[f*3+index]; @@ -1381,8 +1381,8 @@ static STSpace EvalTspace(int face_indices[], const int iFaces, const int piTriL float fCos, fAngle, fMagS, fMagT; int i=-1, index=-1, i0=-1, i1=-1, i2=-1; if (piTriListIn[3*f+0]==iVertexRepresentitive) i=0; - else if(piTriListIn[3*f+1]==iVertexRepresentitive) i=1; - else if(piTriListIn[3*f+2]==iVertexRepresentitive) i=2; + else if (piTriListIn[3*f+1]==iVertexRepresentitive) i=1; + else if (piTriListIn[3*f+2]==iVertexRepresentitive) i=2; assert(i>=0 && i<3); // project @@ -1404,8 +1404,8 @@ static STSpace EvalTspace(int face_indices[], const int iFaces, const int piTriL v2 = vsub(p2,p1); // project - v1 = vsub(v1, vscale(vdot(n,v1),n)); if( VNotZero(v1) ) v1 = Normalize(v1); - v2 = vsub(v2, vscale(vdot(n,v2),n)); if( VNotZero(v2) ) v2 = Normalize(v2); + v1 = vsub(v1, vscale(vdot(n,v1),n)); if ( VNotZero(v1) ) v1 = Normalize(v1); + v2 = vsub(v2, vscale(vdot(n,v2),n)); if ( VNotZero(v2) ) v2 = Normalize(v2); // weight contribution by the angle // between the two edge vectors @@ -1647,7 +1647,7 @@ static void QuickSortEdges(SEdge * pSortBuffer, int iLeft, int iRight, const int SEdge sTmp; const int iElems = iRight-iLeft+1; if (iElems<2) return; - else if(iElems==2) + else if (iElems==2) { if (pSortBuffer[iLeft].array[channel] > pSortBuffer[iRight].array[channel]) { @@ -1868,8 +1868,8 @@ static void DegenEpilogue(STSpace psTspace[], STriInfo pTriInfos[], int piTriLis int iFlag = (1<<pV[0]) | (1<<pV[1]) | (1<<pV[2]); int iMissingIndex = 0; if ((iFlag&2)==0) iMissingIndex=1; - else if((iFlag&4)==0) iMissingIndex=2; - else if((iFlag&8)==0) iMissingIndex=3; + else if ((iFlag&4)==0) iMissingIndex=2; + else if ((iFlag&8)==0) iMissingIndex=3; iOrgF = pTriInfos[t].iOrgFaceNumber; vDstP = GetPosition(pContext, MakeIndex(iOrgF, iMissingIndex)); diff --git a/intern/raskter/raskter.c b/intern/raskter/raskter.c index 152efb05cf0..26fec52dc80 100644 --- a/intern/raskter/raskter.c +++ b/intern/raskter/raskter.c @@ -28,8 +28,7 @@ * \ingroup RASKTER */ -#include <stdio.h> -#include <malloc.h> +#include <stdlib.h> #include "raskter.h" /* from BLI_utildefines.h */ @@ -307,7 +306,7 @@ int rast_scan_fill(struct r_fill_context *ctx, struct poly_vert *verts, int num_ if ((y_curr >= 0) && (y_curr < ctx->rb.sizey)) { /* draw the pixels. */ - for (; cpxl <= mpxl; *cpxl++ = 1.0f); + for (; cpxl <= mpxl; *cpxl++ = 1.0f); } } diff --git a/intern/utfconv/utfconv.c b/intern/utfconv/utfconv.c index 189141e487d..a9b2920111d 100644 --- a/intern/utfconv/utfconv.c +++ b/intern/utfconv/utfconv.c @@ -34,7 +34,7 @@ size_t count_utf_8_from_16(const wchar_t *string16) return 0; } - for (i = 0; (u = string16[i]); i++) { + for (i = 0; (u = string16[i]); i++) { if (u < 0x0080) { count += 1; } diff --git a/release/scripts/modules/bpy_extras/keyconfig_utils.py b/release/scripts/modules/bpy_extras/keyconfig_utils.py index 287cd81eff2..f8b0abd03ea 100644 --- a/release/scripts/modules/bpy_extras/keyconfig_utils.py +++ b/release/scripts/modules/bpy_extras/keyconfig_utils.py @@ -95,7 +95,7 @@ KM_HIERARCHY = [ ('Clip', 'CLIP_EDITOR', 'WINDOW', [ ('Clip Editor', 'CLIP_EDITOR', 'WINDOW', []), ('Clip Graph Editor', 'CLIP_EDITOR', 'WINDOW', []), - ('Mask Editor', 'EMPTY', 'WINDOW', []), # image (reverse order, UVEdit before Image + ('Mask Editing', 'EMPTY', 'WINDOW', []), # image (reverse order, UVEdit before Image ]), ('View3D Gesture Circle', 'EMPTY', 'WINDOW', []), diff --git a/release/scripts/startup/bl_ui/space_clip.py b/release/scripts/startup/bl_ui/space_clip.py index 0450e0c615c..6b238f1b28c 100644 --- a/release/scripts/startup/bl_ui/space_clip.py +++ b/release/scripts/startup/bl_ui/space_clip.py @@ -45,13 +45,13 @@ class CLIP_HT_header(Header): sub.menu("CLIP_MT_clip") if clip: - if sc.mode == 'MASKEDITING': + if sc.mode == 'MASKEDIT': sub.menu("CLIP_MT_mask") else: sub.menu("CLIP_MT_track") sub.menu("CLIP_MT_reconstruction") - if sc.mode != 'MASKEDITING': + if sc.mode != 'MASKEDIT': layout.prop(sc, "view", text="", expand=True) if clip: @@ -59,13 +59,15 @@ class CLIP_HT_header(Header): layout.prop(sc, "mode", text="") layout.prop(sc, "pivot_point", text="", icon_only=True) - if sc.mode == 'MASKEDITING': + if sc.mode == 'MASKEDIT': toolsettings = context.tool_settings row = layout.row(align=True) - row.prop(toolsettings, "use_proportional_edit_mask", text="", icon_only=True) + row.prop(toolsettings, "use_proportional_edit_mask", + text="", icon_only=True) if toolsettings.use_proportional_edit_objects: - row.prop(toolsettings, "proportional_edit_falloff", text="", icon_only=True) + row.prop(toolsettings, "proportional_edit_falloff", + text="", icon_only=True) elif sc.view == 'GRAPH': row = layout.row(align=True) @@ -85,7 +87,7 @@ class CLIP_HT_header(Header): row = layout.row() row.template_ID(sc, "clip", open='clip.open') - if sc.mode == 'MASKEDITING': + if sc.mode == 'MASKEDIT': row = layout.row() row.template_ID(sc, "mask", new="mask.new") @@ -127,7 +129,7 @@ class CLIP_PT_mask_view_panel: sc = context.space_data clip = sc.clip - return clip and sc.view == 'CLIP' and sc.mode == 'MASKEDITING' + return clip and sc.view == 'CLIP' and sc.mode == 'MASKEDIT' class CLIP_PT_tracking_panel: @@ -278,7 +280,8 @@ class CLIP_PT_tools_solve(CLIP_PT_tracking_panel, Panel): col.prop(settings, "keyframe_b") col = layout.column(align=True) - col.active = tracking_object.is_camera and not settings.use_tripod_solver + col.active = (tracking_object.is_camera and + not settings.use_tripod_solver) col.label(text="Refine:") col.prop(settings, "refine_intrinsics", text="") @@ -389,6 +392,8 @@ class CLIP_PT_tools_mask(CLIP_PT_mask_view_panel, Panel): col.operator("transform.translate") col.operator("transform.rotate") col.operator("transform.resize", text="Scale") + props = col.operator("transform.transform", text="Shrink/Fatten") + props.mode = 'MASK_SHRINKFATTEN' col = layout.column(align=True) col.label(text="Spline:") @@ -417,7 +422,7 @@ class CLIP_PT_tools_grease_pencil(Panel): if sc.mode == 'DISTORTION': return sc.view == 'CLIP' - elif sc.mode == 'MASKEDITING': + elif sc.mode == 'MASKEDIT': return True return False @@ -607,7 +612,7 @@ class CLIP_PT_tracking_camera(Panel): col.prop(clip.tracking.camera, "k3") -class CLIP_PT_mask_objects(Panel): +class CLIP_PT_mask_layers(Panel): bl_space_type = 'CLIP_EDITOR' bl_region_type = 'UI' bl_label = "Mask Layers" @@ -616,7 +621,7 @@ class CLIP_PT_mask_objects(Panel): def poll(cls, context): sc = context.space_data - return sc.mask and sc.mode == 'MASKEDITING' + return sc.mask and sc.mode == 'MASKEDIT' def draw(self, context): layout = self.layout @@ -655,7 +660,7 @@ class CLIP_PT_active_mask_spline(Panel): sc = context.space_data mask = sc.mask - if mask and sc.mode == 'MASKEDITING': + if mask and sc.mode == 'MASKEDIT': return mask.layers.active and mask.layers.active.splines.active return False @@ -682,7 +687,7 @@ class CLIP_PT_active_mask_point(Panel): sc = context.space_data mask = sc.mask - if mask and sc.mode == 'MASKEDITING': + if mask and sc.mode == 'MASKEDIT': return mask.layers.active and mask.layers.active.splines.active_point return False @@ -711,13 +716,16 @@ class CLIP_PT_active_mask_point(Panel): clip = parent.id tracking = clip.tracking - col.prop_search(parent, "parent", tracking, "objects", icon='OBJECT_DATA', text="Object:") + col.prop_search(parent, "parent", tracking, + "objects", icon='OBJECT_DATA', text="Object:") if parent.parent and parent.parent in tracking.objects: - object = clip.tracking.objects[parent.parent] - col.prop_search(parent, "sub_parent", object, "tracks", icon='ANIM_DATA', text="Track:") + object = tracking.objects[parent.parent] + col.prop_search(parent, "sub_parent", object, + "tracks", icon='ANIM_DATA', text="Track:") else: - col.prop_search(parent, "sub_parent", clip.tracking, "tracks", icon='ANIM_DATA', text="Track:") + col.prop_search(parent, "sub_parent", tracking, + "tracks", icon='ANIM_DATA', text="Track:") class CLIP_PT_display(CLIP_PT_clip_view_panel, Panel): @@ -764,7 +772,7 @@ class CLIP_PT_display(CLIP_PT_clip_view_panel, Panel): row = col.row() row.prop(clip, "display_aspect", text="") - if sc.mode == 'MASKEDITING': + if sc.mode == 'MASKEDIT': col = layout.column() col.prop(sc, "mask_draw_type", text="") col.prop(sc, "show_mask_smooth") @@ -779,7 +787,7 @@ class CLIP_PT_marker_display(CLIP_PT_clip_view_panel, Panel): def poll(cls, context): sc = context.space_data - return sc.mode != 'MASKEDITING' + return sc.mode != 'MASKEDIT' def draw(self, context): layout = self.layout @@ -938,11 +946,11 @@ class CLIP_PT_footage(CLIP_PT_clip_view_panel, Panel): sc = context.space_data clip = sc.clip - if clip: - layout.template_movieclip(sc, "clip", compact=True) - else: - layout.operator("clip.open", icon='FILESEL') - + col = layout.column() + col.template_movieclip(sc, "clip", compact=True) + col.prop(clip, "use_custom_start_frame") + if clip.use_custom_start_frame: + col.prop(clip, "start_frame") class CLIP_PT_tools_clip(CLIP_PT_clip_view_panel, Panel): @@ -1126,7 +1134,7 @@ class CLIP_MT_select(Menu): layout = self.layout sc = context.space_data - if sc.mode == 'MASKEDITING': + if sc.mode == 'MASKEDIT': layout.operator("mask.select_border") layout.operator("mask.select_circle") @@ -1198,18 +1206,16 @@ class CLIP_MT_mask(Menu): layout.separator() layout.operator("mask.cyclic_toggle") layout.operator("mask.switch_direction") + layout.operator("mask.feather_weight_clear") # TODO, better place? layout.separator() layout.operator("mask.parent_clear") layout.operator("mask.parent_set") layout.separator() - layout.operator("mask.shape_key_clear") - layout.operator("mask.shape_key_insert") - - layout.separator() layout.menu("CLIP_MT_mask_visibility") layout.menu("CLIP_MT_mask_transform") + layout.menu("CLIP_MT_mask_animation") class CLIP_MT_mask_visibility(Menu): @@ -1234,6 +1240,19 @@ class CLIP_MT_mask_transform(Menu): layout.operator("transform.translate") layout.operator("transform.rotate") layout.operator("transform.resize") + props = layout.operator("transform.transform", text="Shrink/Fatten") + props.mode = 'MASK_SHRINKFATTEN' + + +class CLIP_MT_mask_animation(Menu): + bl_label = "Animation" + + def draw(self, context): + layout = self.layout + + layout.operator("mask.shape_key_clear") + layout.operator("mask.shape_key_insert") + layout.operator("mask.shape_key_feather_reset") class CLIP_MT_camera_presets(Menu): diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index 24386730ddb..6fccf819d05 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -42,7 +42,7 @@ extern "C" { * and keep comment above the defines. * Use STRINGIFY() rather than defining with quotes */ #define BLENDER_VERSION 263 -#define BLENDER_SUBVERSION 8 +#define BLENDER_SUBVERSION 9 #define BLENDER_MINVERSION 250 #define BLENDER_MINSUBVERSION 0 diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index ac3daef77f7..279ec272fe8 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -157,6 +157,7 @@ void BKE_image_assign_ibuf(struct Image *ima, struct ImBuf *ibuf); void BKE_image_user_frame_calc(struct ImageUser *iuser, int cfra, int fieldnr); void BKE_image_user_check_frame_calc(struct ImageUser *iuser, int cfra, int fieldnr); int BKE_image_user_frame_get(const struct ImageUser *iuser, int cfra, int fieldnr); +void BKE_image_user_file_path(struct ImageUser *iuser, struct Image *ima, int cfra, char *path); /* sets index offset for multilayer files */ struct RenderPass *BKE_image_multilayer_index(struct RenderResult *rr, struct ImageUser *iuser); diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h index 3f837f995ce..19feb4d8f2e 100644 --- a/source/blender/blenkernel/BKE_mask.h +++ b/source/blender/blenkernel/BKE_mask.h @@ -69,7 +69,14 @@ float (*BKE_mask_spline_feather_points(struct MaskSpline *spline, int *tot_feath void BKE_mask_point_direction_switch(struct MaskSplinePoint *point); void BKE_mask_spline_direction_switch(struct MaskLayer *masklay, struct MaskSpline *spline); -float BKE_mask_spline_project_co(struct MaskSpline *spline, struct MaskSplinePoint *point, float start_u, const float co[2]); + +typedef enum { + MASK_PROJ_NEG = -1, + MASK_PROJ_ANY = 0, + MASK_PROJ_POS = 1 +} eMaskSign; +float BKE_mask_spline_project_co(struct MaskSpline *spline, struct MaskSplinePoint *point, + float start_u, const float co[2], const eMaskSign sign); /* point */ int BKE_mask_point_has_handle(struct MaskSplinePoint *point); @@ -91,6 +98,7 @@ float *BKE_mask_point_segment_feather_diff_with_resolution(struct MaskSpline *sp void BKE_mask_point_segment_co(struct MaskSpline *spline, struct MaskSplinePoint *point, float u, float co[2]); void BKE_mask_point_normal(struct MaskSpline *spline, struct MaskSplinePoint *point, float u, float n[2]); +float BKE_mask_point_weight_scalar(struct MaskSpline *spline, struct MaskSplinePoint *point, const float u); float BKE_mask_point_weight(struct MaskSpline *spline, struct MaskSplinePoint *point, float u); struct MaskSplinePointUW *BKE_mask_point_sort_uw(struct MaskSplinePoint *point, struct MaskSplinePointUW *uw); void BKE_mask_point_add_uw(struct MaskSplinePoint *point, float u, float w); @@ -133,11 +141,13 @@ void BKE_mask_layer_shape_to_mask_interp(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape_a, struct MaskLayerShape *masklay_shape_b, const float fac); -struct MaskLayerShape *BKE_mask_layer_shape_find_frame(struct MaskLayer *masklay, int frame); -int BKE_mask_layer_shape_find_frame_range(struct MaskLayer *masklay, int frame, +struct MaskLayerShape *BKE_mask_layer_shape_find_frame(struct MaskLayer *masklay, const int frame); +int BKE_mask_layer_shape_find_frame_range(struct MaskLayer *masklay, const int frame, struct MaskLayerShape **r_masklay_shape_a, struct MaskLayerShape **r_masklay_shape_b); -struct MaskLayerShape *BKE_mask_layer_shape_varify_frame(struct MaskLayer *masklay, int frame); +struct MaskLayerShape *BKE_mask_layer_shape_alloc(struct MaskLayer *masklay, const int frame); +void BKE_mask_layer_shape_free(struct MaskLayerShape *masklay_shape); +struct MaskLayerShape *BKE_mask_layer_shape_varify_frame(struct MaskLayer *masklay, const int frame); void BKE_mask_layer_shape_unlink(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape); void BKE_mask_layer_shape_sort(struct MaskLayer *masklay); diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 3748a474ddd..9dc5463edab 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -2084,8 +2084,7 @@ static void image_initialize_after_load(Image *ima, ImBuf *ibuf) static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame) { struct ImBuf *ibuf; - unsigned short numlen; - char name[FILE_MAX], head[FILE_MAX], tail[FILE_MAX]; + char name[FILE_MAX]; int flag; /* XXX temp stuff? */ @@ -2093,11 +2092,7 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame) ima->tpageflag |= IMA_TPAGE_REFRESH; ima->lastframe = frame; - BLI_strncpy(name, ima->name, sizeof(name)); - BLI_stringdec(name, head, tail, &numlen); - BLI_stringenc(name, head, tail, numlen, frame); - - BLI_path_abs(name, ID_BLEND_PATH(G.main, &ima->id)); + BKE_image_user_file_path(iuser, ima, frame, name); flag = IB_rect | IB_multilayer; if (ima->flag & IMA_DO_PREMUL) @@ -2209,8 +2204,7 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) if (ima->anim == NULL) { char str[FILE_MAX]; - BLI_strncpy(str, ima->name, FILE_MAX); - BLI_path_abs(str, ID_BLEND_PATH(G.main, &ima->id)); + BKE_image_user_file_path(iuser, ima, frame, str); /* FIXME: make several stream accessible in image editor, too*/ ima->anim = openanim(str, IB_rect, 0); @@ -2273,8 +2267,7 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) flag |= IB_premul; /* get the right string */ - BLI_strncpy(str, ima->name, sizeof(str)); - BLI_path_abs(str, ID_BLEND_PATH(G.main, &ima->id)); + BKE_image_user_file_path(iuser, ima, cfra, str); /* read ibuf */ ibuf = IMB_loadiffname(str, flag); @@ -2748,6 +2741,29 @@ void BKE_image_user_check_frame_calc(ImageUser *iuser, int cfra, int fieldnr) } } +void BKE_image_user_file_path(ImageUser *iuser, Image *ima, int cfra, char *filepath) +{ + BLI_strncpy(filepath, ima->name, FILE_MAX); + + if (ima->source == IMA_SRC_SEQUENCE) { + char head[FILE_MAX], tail[FILE_MAX]; + unsigned short numlen; + int frame; + + if(iuser) { + BKE_image_user_frame_calc(iuser, cfra, 0); + frame = iuser->framenr; + } + else { + } + + BLI_stringdec(filepath, head, tail, &numlen); + BLI_stringenc(filepath, head, tail, numlen, frame); + } + + BLI_path_abs(filepath, ID_BLEND_PATH(G.main, &ima->id)); +} + int BKE_image_has_alpha(struct Image *image) { ImBuf *ibuf; diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 0abeb483745..c81e607ce93 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -1142,7 +1142,7 @@ static ID *is_dupid(ListBase *lb, ID *id, const char *name) * Normally the ID that's being check is already in the ListBase, so ID *id * points at the new entry. The Python Library module needs to know what * the name of a datablock will be before it is appended; in this case ID *id - * id is NULL; + * id is NULL */ static int check_for_dupid(ListBase *lb, ID *id, char *name) diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index 870a84df66a..aaefa558c9b 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -58,6 +58,68 @@ #include "raskter.h" +static MaskSplinePoint *mask_spline_point_next(MaskSpline *spline, MaskSplinePoint *points_array, MaskSplinePoint *point) +{ + if (point == &points_array[spline->tot_point - 1]) { + if (spline->flag & MASK_SPLINE_CYCLIC) { + return &points_array[0]; + } + else { + return NULL; + } + } + else { + return point + 1; + } +} + +static MaskSplinePoint *mask_spline_point_prev(MaskSpline *spline, MaskSplinePoint *points_array, MaskSplinePoint *point) +{ + if (point == points_array) { + if (spline->flag & MASK_SPLINE_CYCLIC) { + return &points_array[spline->tot_point - 1]; + } + else { + return NULL; + } + } + else { + return point - 1; + } +} + +static BezTriple *mask_spline_point_next_bezt(MaskSpline *spline, MaskSplinePoint *points_array, MaskSplinePoint *point) +{ + if (point == &points_array[spline->tot_point - 1]) { + if (spline->flag & MASK_SPLINE_CYCLIC) { + return &(points_array[0].bezt); + } + else { + return NULL; + } + } + else { + return &((point + 1))->bezt; + } +} + +#if 0 +static BezTriple *mask_spline_point_prev_bezt(MaskSpline *spline, MaskSplinePoint *points_array, MaskSplinePoint *point) +{ + if (point == points_array) { + if (spline->flag & MASK_SPLINE_CYCLIC) { + return &(points_array[0].bezt); + } + else { + return NULL; + } + } + else { + return &((point - 1))->bezt; + } +} +#endif + MaskSplinePoint *BKE_mask_spline_point_array(MaskSpline *spline) { return spline->points_deform ? spline->points_deform : spline->points; @@ -163,26 +225,20 @@ static int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height) for (i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; - MaskSplinePoint *next_point; - BezTriple *bezt, *next_bezt; + BezTriple *bezt, *bezt_next; float a, b, c, len; int cur_resol; - if (i == spline->tot_point - 1) { - if (spline->flag & MASK_SPLINE_CYCLIC) - next_point = &spline->points[0]; - else - break; - } - else - next_point = &spline->points[i + 1]; - bezt = &point->bezt; - next_bezt = &next_point->bezt; + bezt_next = mask_spline_point_next_bezt(spline, spline->points, point); + + if (bezt_next == NULL) { + break; + } a = len_v3v3(bezt->vec[1], bezt->vec[2]); - b = len_v3v3(bezt->vec[2], next_bezt->vec[0]); - c = len_v3v3(next_bezt->vec[0], next_bezt->vec[1]); + b = len_v3v3(bezt->vec[2], bezt_next->vec[0]); + c = len_v3v3(bezt_next->vec[0], bezt_next->vec[1]); len = a + b + c; cur_resol = len / max_segment; @@ -383,28 +439,33 @@ void BKE_mask_point_direction_switch(MaskSplinePoint *point) const int tot_uw_half = tot_uw / 2; int i; - if (tot_uw < 2) { - return; - } + float co_tmp[2]; - /* count */ - for (i = 0; i < tot_uw_half; i++) { - MaskSplinePointUW *uw_a = &point->uw[i]; - MaskSplinePointUW *uw_b = &point->uw[tot_uw - (i + 1)]; - SWAP(MaskSplinePointUW, *uw_a, *uw_b); + /* swap handles */ + copy_v2_v2(co_tmp, point->bezt.vec[0]); + copy_v2_v2(point->bezt.vec[0], point->bezt.vec[2]); + copy_v2_v2(point->bezt.vec[2], co_tmp); + /* in this case the flags are unlikely to be different but swap anyway */ + SWAP(char, point->bezt.f1, point->bezt.f3); + SWAP(char, point->bezt.h1, point->bezt.h2); + + + /* swap UW's */ + if (tot_uw > 1) { + /* count */ + for (i = 0; i < tot_uw_half; i++) { + MaskSplinePointUW *uw_a = &point->uw[i]; + MaskSplinePointUW *uw_b = &point->uw[tot_uw - (i + 1)]; + SWAP(MaskSplinePointUW, *uw_a, *uw_b); + } } + for (i = 0; i < tot_uw; i++) { MaskSplinePointUW *uw = &point->uw[i]; uw->u = 1.0f - uw->u; } } -//typedef (float)[MASK_OBJECT_SHAPE_ELEM_SIZE] MaskLayerShapeElem; - -typedef struct MaskLayerShapeElem { - float value[MASK_OBJECT_SHAPE_ELEM_SIZE]; -} MaskLayerShapeElem; - void BKE_mask_spline_direction_switch(MaskLayer *masklay, MaskSpline *spline) { const int tot_point = spline->tot_point; @@ -456,7 +517,8 @@ void BKE_mask_spline_direction_switch(MaskLayer *masklay, MaskSpline *spline) } -float BKE_mask_spline_project_co(MaskSpline *spline, MaskSplinePoint *point, float start_u, const float co[2]) +float BKE_mask_spline_project_co(MaskSpline *spline, MaskSplinePoint *point, + float start_u, const float co[2], const eMaskSign sign) { const float proj_eps = 1e-3; const float proj_eps_squared = proj_eps * proj_eps; @@ -464,6 +526,8 @@ float BKE_mask_spline_project_co(MaskSpline *spline, MaskSplinePoint *point, flo float u = -1.0f, du = 1.0f / N, u1 = start_u, u2 = start_u; float ang = -1.0f; + BLI_assert(ABS(sign) <= 1); /* (-1, 0, 1) */ + while (u1 > 0.0f || u2 < 1.0f) { float n1[2], n2[2], co1[2], co2[2]; float v1[2], v2[2]; @@ -474,20 +538,26 @@ float BKE_mask_spline_project_co(MaskSpline *spline, MaskSplinePoint *point, flo BKE_mask_point_normal(spline, point, u1, n1); sub_v2_v2v2(v1, co, co1); - if (len_squared_v2(v1) > proj_eps_squared) { - ang1 = angle_v2v2(v1, n1); - if (ang1 > M_PI / 2.0f) - ang1 = M_PI - ang1; + if ((sign == MASK_PROJ_ANY) || + ((sign == MASK_PROJ_NEG) && (dot_v2v2(v1, n1) <= 0.0f)) || + ((sign == MASK_PROJ_POS) && (dot_v2v2(v1, n1) >= 0.0f))) + { + + if (len_squared_v2(v1) > proj_eps_squared) { + ang1 = angle_v2v2(v1, n1); + if (ang1 > M_PI / 2.0f) + ang1 = M_PI - ang1; - if (ang < 0.0f || ang1 < ang) { - ang = ang1; + if (ang < 0.0f || ang1 < ang) { + ang = ang1; + u = u1; + } + } + else { u = u1; + break; } } - else { - u = u1; - break; - } } if (u2 <= 1.0f) { @@ -495,20 +565,26 @@ float BKE_mask_spline_project_co(MaskSpline *spline, MaskSplinePoint *point, flo BKE_mask_point_normal(spline, point, u2, n2); sub_v2_v2v2(v2, co, co2); - if (len_squared_v2(v2) > proj_eps_squared) { - ang2 = angle_v2v2(v2, n2); - if (ang2 > M_PI / 2.0f) - ang2 = M_PI - ang2; + if ((sign == MASK_PROJ_ANY) || + ((sign == MASK_PROJ_NEG) && (dot_v2v2(v2, n2) <= 0.0f)) || + ((sign == MASK_PROJ_POS) && (dot_v2v2(v2, n2) >= 0.0f))) + { + + if (len_squared_v2(v2) > proj_eps_squared) { + ang2 = angle_v2v2(v2, n2); + if (ang2 > M_PI / 2.0f) + ang2 = M_PI - ang2; - if (ang2 < ang) { - ang = ang2; + if (ang2 < ang) { + ang = ang2; + u = u2; + } + } + else { u = u2; + break; } } - else { - u = u2; - break; - } } u1 -= du; @@ -611,21 +687,14 @@ float *BKE_mask_point_segment_diff_with_resolution(MaskSpline *spline, MaskSplin { MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point); - BezTriple *bezt, *next; + BezTriple *bezt, *bezt_next; float *diff_points, *fp; int j, resol = BKE_mask_spline_resolution(spline, width, height); bezt = &point->bezt; + bezt_next = mask_spline_point_next_bezt(spline, points_array, point); - if (point == &points_array[spline->tot_point - 1]) { - if (spline->flag & MASK_SPLINE_CYCLIC) - next = &(points_array[0].bezt); - else - next = NULL; - } - else next = &((point + 1))->bezt; - - if (!next) + if (!bezt_next) return NULL; /* resol+1 because of 'forward_diff_bezier' function */ @@ -634,11 +703,11 @@ float *BKE_mask_point_segment_diff_with_resolution(MaskSpline *spline, MaskSplin for (j = 0; j < 2; j++) { BKE_curve_forward_diff_bezier(bezt->vec[1][j], bezt->vec[2][j], - next->vec[0][j], next->vec[1][j], + bezt_next->vec[0][j], bezt_next->vec[1][j], fp + j, resol, 2 * sizeof(float)); } - copy_v2_v2(fp + 2 * resol, next->vec[1]); + copy_v2_v2(fp + 2 * resol, bezt_next->vec[1]); return diff_points; } @@ -652,25 +721,19 @@ void BKE_mask_point_segment_co(MaskSpline *spline, MaskSplinePoint *point, float { MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point); - BezTriple *bezt = &point->bezt, *next; + BezTriple *bezt = &point->bezt, *bezt_next; float q0[2], q1[2], q2[2], r0[2], r1[2]; - if (point == &points_array[spline->tot_point - 1]) { - if (spline->flag & MASK_SPLINE_CYCLIC) - next = &(points_array[0].bezt); - else - next = NULL; - } - else next = &((point + 1))->bezt; + bezt_next = mask_spline_point_next_bezt(spline, points_array, point); - if (!next) { + if (!bezt_next) { copy_v2_v2(co, bezt->vec[1]); return; } interp_v2_v2v2(q0, bezt->vec[1], bezt->vec[2], u); - interp_v2_v2v2(q1, bezt->vec[2], next->vec[0], u); - interp_v2_v2v2(q2, next->vec[0], next->vec[1], u); + interp_v2_v2v2(q1, bezt->vec[2], bezt_next->vec[0], u); + interp_v2_v2v2(q2, bezt_next->vec[0], bezt_next->vec[1], u); interp_v2_v2v2(r0, q0, q1, u); interp_v2_v2v2(r1, q1, q2, u); @@ -682,20 +745,12 @@ void BKE_mask_point_normal(MaskSpline *spline, MaskSplinePoint *point, float u, { MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point); - BezTriple *bezt = &point->bezt, *next; + BezTriple *bezt = &point->bezt, *bezt_next; float q0[2], q1[2], q2[2], r0[2], r1[2], vec[2]; - if (point == &points_array[spline->tot_point - 1]) { - if (spline->flag & MASK_SPLINE_CYCLIC) - next = &(points_array[0].bezt); - else - next = NULL; - } - else { - next = &((point + 1))->bezt; - } + bezt_next = mask_spline_point_next_bezt(spline, points_array, point); - if (!next) { + if (!bezt_next) { BKE_mask_point_handle(point, vec); sub_v2_v2v2(n, vec, bezt->vec[1]); @@ -704,8 +759,8 @@ void BKE_mask_point_normal(MaskSpline *spline, MaskSplinePoint *point, float u, } interp_v2_v2v2(q0, bezt->vec[1], bezt->vec[2], u); - interp_v2_v2v2(q1, bezt->vec[2], next->vec[0], u); - interp_v2_v2v2(q2, next->vec[0], next->vec[1], u); + interp_v2_v2v2(q1, bezt->vec[2], bezt_next->vec[0], u); + interp_v2_v2v2(q2, bezt_next->vec[0], bezt_next->vec[1], u); interp_v2_v2v2(r0, q0, q1, u); interp_v2_v2v2(r1, q1, q2, u); @@ -718,60 +773,89 @@ void BKE_mask_point_normal(MaskSpline *spline, MaskSplinePoint *point, float u, normalize_v2(n); } -float BKE_mask_point_weight(MaskSpline *spline, MaskSplinePoint *point, float u) +static float mask_point_interp_weight(BezTriple *bezt, BezTriple *bezt_next, const float u) { - MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point); + return (bezt->weight * (1.0f - u)) + (bezt_next->weight * u); +} +float BKE_mask_point_weight_scalar(MaskSpline *spline, MaskSplinePoint *point, const float u) +{ + MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point); BezTriple *bezt = &point->bezt, *bezt_next; - float cur_u, cur_w, next_u, next_w, fac; - int i; - if (point == &points_array[spline->tot_point - 1]) { - if (spline->flag & MASK_SPLINE_CYCLIC) { - bezt_next = &(points_array[0].bezt); - } - else { - bezt_next = NULL; - } + bezt_next = mask_spline_point_next_bezt(spline, points_array, point); + + if (!bezt_next) { + return bezt->weight; + } + else if (u <= 0.0) { + return bezt->weight; + } + else if (u >= 1.0f) { + return bezt_next->weight; } else { - bezt_next = &((point + 1))->bezt; + return mask_point_interp_weight(bezt, bezt_next, u); } +} - if (!bezt_next) +float BKE_mask_point_weight(MaskSpline *spline, MaskSplinePoint *point, const float u) +{ + MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point); + BezTriple *bezt = &point->bezt, *bezt_next; + + bezt_next = mask_spline_point_next_bezt(spline, points_array, point); + + if (!bezt_next) { return bezt->weight; + } + else if (u <= 0.0) { + return bezt->weight; + } + else if (u >= 1.0f) { + return bezt_next->weight; + } + else { + float cur_u, cur_w, next_u, next_w, fac; + int i; - for (i = 0; i < point->tot_uw + 1; i++) { + for (i = 0; i < point->tot_uw + 1; i++) { - if (i == 0) { - cur_u = 0.0f; - cur_w = bezt->weight; - } - else { - cur_u = point->uw[i - 1].u; - cur_w = point->uw[i - 1].w; + if (i == 0) { + cur_u = 0.0f; + cur_w = 1.0f; /* mask_point_interp_weight will scale it */ + } + else { + cur_u = point->uw[i - 1].u; + cur_w = point->uw[i - 1].w; + } + + if (i == point->tot_uw) { + next_u = 1.0f; + next_w = 1.0f; /* mask_point_interp_weight will scale it */ + } + else { + next_u = point->uw[i].u; + next_w = point->uw[i].w; + } + + if (u >= cur_u && u <= next_u) { + break; + } } - if (i == point->tot_uw) { - next_u = 1.0f; - next_w = bezt_next->weight; + fac = (u - cur_u) / (next_u - cur_u); + + cur_w *= mask_point_interp_weight(bezt, bezt_next, cur_u); + next_w *= mask_point_interp_weight(bezt, bezt_next, next_u); + + if (spline->weight_interp == MASK_SPLINE_INTERP_EASE) { + return cur_w + (next_w - cur_w) * (3.0f * fac * fac - 2.0f * fac * fac * fac); } else { - next_u = point->uw[i].u; - next_w = point->uw[i].w; - } - - if (u >= cur_u && u <= next_u) { - break; + return (1.0f - fac) * cur_w + fac * next_w; } } - - fac = (u - cur_u) / (next_u - cur_u); - - if (spline->weight_interp == MASK_SPLINE_INTERP_EASE) - return cur_w + (next_w - cur_w) * (3.0f * fac * fac - 2.0f * fac * fac * fac); - else - return (1.0f - fac) * cur_w + fac * next_w; } MaskSplinePointUW *BKE_mask_point_sort_uw(MaskSplinePoint *point, MaskSplinePointUW *uw) @@ -920,6 +1004,20 @@ MaskSpline *BKE_mask_spline_copy(MaskSpline *spline) return nspline; } +/* note: does NOT add to the list */ +MaskLayerShape *BKE_mask_layer_shape_alloc(MaskLayer *masklay, const int frame) +{ + MaskLayerShape *masklay_shape; + int tot_vert = BKE_mask_layer_shape_totvert(masklay); + + masklay_shape = MEM_mallocN(sizeof(MaskLayerShape), __func__); + masklay_shape->frame = frame; + masklay_shape->tot_vert = tot_vert; + masklay_shape->data = MEM_mallocN(tot_vert * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE, __func__); + + return masklay_shape; +} + void BKE_mask_layer_shape_free(MaskLayerShape *masklay_shape) { MEM_freeN(masklay_shape->data); @@ -1084,28 +1182,28 @@ int BKE_mask_evaluate_parent_delta(MaskParent *parent, float ctime, float r_delt } } -static void mask_calc_point_handle(MaskSplinePoint *point, MaskSplinePoint *prev_point, MaskSplinePoint *next_point) +static void mask_calc_point_handle(MaskSplinePoint *point, MaskSplinePoint *point_prev, MaskSplinePoint *point_next) { BezTriple *bezt = &point->bezt; - BezTriple *prev_bezt = NULL, *next_bezt = NULL; + BezTriple *bezt_prev = NULL, *bezt_next = NULL; //int handle_type = bezt->h1; - if (prev_point) - prev_bezt = &prev_point->bezt; + if (point_prev) + bezt_prev = &point_prev->bezt; - if (next_point) - next_bezt = &next_point->bezt; + if (point_next) + bezt_next = &point_next->bezt; #if 1 - if (prev_bezt || next_bezt) { - BKE_nurb_handle_calc(bezt, prev_bezt, next_bezt, 0); + if (bezt_prev || bezt_next) { + BKE_nurb_handle_calc(bezt, bezt_prev, bezt_next, 0); } #else if (handle_type == HD_VECT) { - BKE_nurb_handle_calc(bezt, prev_bezt, next_bezt, 0); + BKE_nurb_handle_calc(bezt, bezt_prev, bezt_next, 0); } else if (handle_type == HD_AUTO) { - BKE_nurb_handle_calc(bezt, prev_bezt, next_bezt, 0); + BKE_nurb_handle_calc(bezt, bezt_prev, bezt_next, 0); } else if (handle_type == HD_ALIGN) { float v1[3], v2[3]; @@ -1133,37 +1231,12 @@ static void mask_calc_point_handle(MaskSplinePoint *point, MaskSplinePoint *prev void BKE_mask_get_handle_point_adjacent(Mask *UNUSED(mask), MaskSpline *spline, MaskSplinePoint *point, MaskSplinePoint **r_point_prev, MaskSplinePoint **r_point_next) { - MaskSplinePoint *prev_point, *next_point; int i = (int)(point - spline->points); - BLI_assert(i >= i && i < spline->tot_point); + (void)i; /* quiet release builds */ - if (i == 0) { - if (spline->flag & MASK_SPLINE_CYCLIC) { - prev_point = &spline->points[spline->tot_point - 1]; - } - else { - prev_point = NULL; - } - } - else { - prev_point = point - 1; - } - - if (i == spline->tot_point - 1) { - if (spline->flag & MASK_SPLINE_CYCLIC) { - next_point = &spline->points[0]; - } - else { - next_point = NULL; - } - } - else { - next_point = point + 1; - } - - *r_point_prev = prev_point; - *r_point_next = next_point; + *r_point_prev = mask_spline_point_prev(spline, spline->points, point); + *r_point_next = mask_spline_point_next(spline, spline->points, point); } /* calculates the tanget of a point by its previous and next @@ -1172,21 +1245,21 @@ void BKE_mask_calc_tangent_polyline(Mask *mask, MaskSpline *spline, MaskSplinePo { float tvec_a[2], tvec_b[2]; - MaskSplinePoint *prev_point, *next_point; + MaskSplinePoint *point_prev, *point_next; BKE_mask_get_handle_point_adjacent(mask, spline, point, - &prev_point, &next_point); + &point_prev, &point_next); - if (prev_point) { - sub_v2_v2v2(tvec_a, point->bezt.vec[1], prev_point->bezt.vec[1]); + if (point_prev) { + sub_v2_v2v2(tvec_a, point->bezt.vec[1], point_prev->bezt.vec[1]); normalize_v2(tvec_a); } else { zero_v2(tvec_a); } - if (next_point) { - sub_v2_v2v2(tvec_b, next_point->bezt.vec[1], point->bezt.vec[1]); + if (point_next) { + sub_v2_v2v2(tvec_b, point_next->bezt.vec[1], point->bezt.vec[1]); normalize_v2(tvec_b); } else { @@ -1199,12 +1272,12 @@ void BKE_mask_calc_tangent_polyline(Mask *mask, MaskSpline *spline, MaskSplinePo void BKE_mask_calc_handle_point(Mask *mask, MaskSpline *spline, MaskSplinePoint *point) { - MaskSplinePoint *prev_point, *next_point; + MaskSplinePoint *point_prev, *point_next; BKE_mask_get_handle_point_adjacent(mask, spline, point, - &prev_point, &next_point); + &point_prev, &point_next); - mask_calc_point_handle(point, prev_point, next_point); + mask_calc_point_handle(point, point_prev, point_next); } static void enforce_dist_v2_v2fl(float v1[2], const float v2[2], const float dist) @@ -1226,31 +1299,31 @@ void BKE_mask_calc_handle_adjacent_interp(Mask *mask, MaskSpline *spline, MaskSp float weight_average = 0.0f; - MaskSplinePoint *prev_point, *next_point; + MaskSplinePoint *point_prev, *point_next; BLI_assert(u >= 0.0f && u <= 1.0f); BKE_mask_get_handle_point_adjacent(mask, spline, point, - &prev_point, &next_point); + &point_prev, &point_next); - if (prev_point && next_point) { - length_average = ((len_v2v2(prev_point->bezt.vec[0], prev_point->bezt.vec[1]) * (1.0f - u)) + - (len_v2v2(next_point->bezt.vec[2], next_point->bezt.vec[1]) * u)); + if (point_prev && point_next) { + length_average = ((len_v2v2(point_prev->bezt.vec[0], point_prev->bezt.vec[1]) * (1.0f - u)) + + (len_v2v2(point_next->bezt.vec[2], point_next->bezt.vec[1]) * u)); - weight_average = (prev_point->bezt.weight * (1.0f - u) + - next_point->bezt.weight * u); + weight_average = (point_prev->bezt.weight * (1.0f - u) + + point_next->bezt.weight * u); length_tot = 1; } else { - if (prev_point) { - length_average += len_v2v2(prev_point->bezt.vec[0], prev_point->bezt.vec[1]); - weight_average += prev_point->bezt.weight; + if (point_prev) { + length_average += len_v2v2(point_prev->bezt.vec[0], point_prev->bezt.vec[1]); + weight_average += point_prev->bezt.weight; length_tot++; } - if (next_point) { - length_average += len_v2v2(next_point->bezt.vec[2], next_point->bezt.vec[1]); - weight_average += next_point->bezt.weight; + if (point_next) { + length_average += len_v2v2(point_next->bezt.vec[2], point_next->bezt.vec[1]); + weight_average += point_next->bezt.weight; length_tot++; } } @@ -1274,18 +1347,18 @@ void BKE_mask_calc_handle_adjacent_interp(Mask *mask, MaskSpline *spline, MaskSp void BKE_mask_calc_handle_point_auto(Mask *mask, MaskSpline *spline, MaskSplinePoint *point, const short do_recalc_length) { - MaskSplinePoint *prev_point, *next_point; + MaskSplinePoint *point_prev, *point_next; const char h_back[2] = {point->bezt.h1, point->bezt.h2}; const float length_average = (do_recalc_length) ? 0.0f /* dummy value */ : (len_v3v3(point->bezt.vec[0], point->bezt.vec[1]) + len_v3v3(point->bezt.vec[1], point->bezt.vec[2])) / 2.0f; BKE_mask_get_handle_point_adjacent(mask, spline, point, - &prev_point, &next_point); + &point_prev, &point_next); point->bezt.h1 = HD_AUTO; point->bezt.h2 = HD_AUTO; - mask_calc_point_handle(point, prev_point, next_point); + mask_calc_point_handle(point, point_prev, point_next); point->bezt.h1 = h_back[0]; point->bezt.h2 = h_back[1]; @@ -1633,7 +1706,7 @@ void BKE_mask_layer_shape_to_mask_interp(MaskLayer *masklay, } } -MaskLayerShape *BKE_mask_layer_shape_find_frame(MaskLayer *masklay, int frame) +MaskLayerShape *BKE_mask_layer_shape_find_frame(MaskLayer *masklay, const int frame) { MaskLayerShape *masklay_shape; @@ -1653,7 +1726,7 @@ MaskLayerShape *BKE_mask_layer_shape_find_frame(MaskLayer *masklay, int frame) } /* when returning 2 - the frame isnt found but before/after frames are */ -int BKE_mask_layer_shape_find_frame_range(MaskLayer *masklay, int frame, +int BKE_mask_layer_shape_find_frame_range(MaskLayer *masklay, const int frame, MaskLayerShape **r_masklay_shape_a, MaskLayerShape **r_masklay_shape_b) { @@ -1688,22 +1761,15 @@ int BKE_mask_layer_shape_find_frame_range(MaskLayer *masklay, int frame, return 0; } -MaskLayerShape *BKE_mask_layer_shape_varify_frame(MaskLayer *masklay, int frame) +MaskLayerShape *BKE_mask_layer_shape_varify_frame(MaskLayer *masklay, const int frame) { MaskLayerShape *masklay_shape; masklay_shape = BKE_mask_layer_shape_find_frame(masklay, frame); if (masklay_shape == NULL) { - int tot_vert = BKE_mask_layer_shape_totvert(masklay); - - masklay_shape = MEM_mallocN(sizeof(MaskLayerShape), __func__); - masklay_shape->frame = frame; - masklay_shape->tot_vert = tot_vert; - masklay_shape->data = MEM_mallocN(tot_vert * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE, __func__); - + masklay_shape = BKE_mask_layer_shape_alloc(masklay, frame); BLI_addtail(&masklay->splines_shapes, masklay_shape); - BKE_mask_layer_shape_sort(masklay); } @@ -1972,15 +2038,6 @@ void BKE_mask_rasterize(Mask *mask, int width, int height, float *buffer) /* temp blending buffer */ const int buffer_size = width * height; float *buffer_tmp = MEM_mallocN(sizeof(float) * buffer_size, __func__); - float max_dseg_len = 0.0f; - - if (width >= height) { - max_dseg_len = (float)(width); - } - else { - max_dseg_len = (float)(height); - } - max_dseg_len = 1.0f / max_dseg_len; for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { MaskSpline *spline; @@ -1999,51 +2056,56 @@ void BKE_mask_rasterize(Mask *mask, int width, int height, float *buffer) float (*diff_feather_points)[2]; int tot_diff_feather_points; - diff_points = BKE_mask_spline_differentiate_with_resolution(spline, width, height, &tot_diff_point); + diff_points = BKE_mask_spline_differentiate_with_resolution(spline, width, height, + &tot_diff_point); + if (tot_diff_point) { diff_feather_points = BKE_mask_spline_feather_differentiated_points_with_resolution(spline, width, height, &tot_diff_feather_points); - } - /* TODO, make this optional! */ - if (width != height) { - float *fp; - float *ffp; - int i; - float asp; - - if (width < height) { - fp = &diff_points[0][0]; - ffp = &diff_feather_points[0][0]; - asp = (float)width / (float)height; - } - else { - fp = &diff_points[0][1]; - ffp = &diff_feather_points[0][1]; - asp = (float)height / (float)width; - } + /* TODO, make this optional! */ + if (width != height) { + float *fp; + float *ffp; + int i; + float asp; + + if (width < height) { + fp = &diff_points[0][0]; + ffp = tot_diff_feather_points ? &diff_feather_points[0][0] : NULL; + asp = (float)width / (float)height; + } + else { + fp = &diff_points[0][1]; + ffp = tot_diff_feather_points ? &diff_feather_points[0][1] : NULL; + asp = (float)height / (float)width; + } - for (i = 0; i < tot_diff_point; i++, fp += 2) { - (*fp) = (((*fp) - 0.5f) / asp) + 0.5f; - } - for (i = 0; i < tot_diff_feather_points; i++, ffp += 2) { - (*ffp) = (((*ffp) - 0.5f) / asp) + 0.5f; - } - } + for (i = 0; i < tot_diff_point; i++, fp += 2) { + (*fp) = (((*fp) - 0.5f) / asp) + 0.5f; + } - if (tot_diff_point) { - PLX_raskterize((float (*)[2])diff_points, tot_diff_point, - buffer_tmp, width, height); - - if (tot_diff_feather_points) { - PLX_raskterize_feather((float (*)[2])diff_points, tot_diff_point, - (float (*)[2])diff_feather_points, tot_diff_feather_points, - buffer_tmp, width, height); - MEM_freeN(diff_feather_points); + if (tot_diff_feather_points) { + for (i = 0; i < tot_diff_feather_points; i++, ffp += 2) { + (*ffp) = (((*ffp) - 0.5f) / asp) + 0.5f; + } + } } - MEM_freeN(diff_points); + if (tot_diff_point) { + PLX_raskterize(diff_points, tot_diff_point, + buffer_tmp, width, height); + + if (tot_diff_feather_points) { + PLX_raskterize_feather(diff_points, tot_diff_point, + diff_feather_points, tot_diff_feather_points, + buffer_tmp, width, height); + MEM_freeN(diff_feather_points); + } + + MEM_freeN(diff_points); + } } } diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index e0239cde86d..22eae912967 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -153,9 +153,15 @@ static void get_sequence_fname(MovieClip *clip, int framenr, char *name) BLI_strncpy(name, clip->name, sizeof(clip->name)); BLI_stringdec(name, head, tail, &numlen); - /* movieclips always points to first image from sequence, - * autoguess offset for now. could be something smarter in the future */ - offset = sequence_guess_offset(clip->name, strlen(head), numlen); + if (clip->flag & MCLIP_CUSTOM_START_FRAME) { + offset = clip->start_frame; + } + else { + /* movieclips always points to first image from sequence, + * autoguess offset for now. could be something smarter in the future + */ + offset = sequence_guess_offset(clip->name, strlen(head), numlen); + } if (numlen) BLI_stringenc(name, head, tail, numlen, offset + framenr - 1); @@ -250,6 +256,10 @@ static ImBuf *movieclip_load_movie_file(MovieClip *clip, MovieClipUser *user, in dur = IMB_anim_get_duration(clip->anim, tc); fra = framenr - 1; + if (clip->flag & MCLIP_CUSTOM_START_FRAME) { + fra += clip->start_frame - 1; + } + if (fra < 0) fra = 0; @@ -443,6 +453,8 @@ static MovieClip *movieclip_alloc(const char *name) IMB_TC_RECORD_RUN_NO_GAPS; clip->proxy.quality = 90; + clip->start_frame = 1; + return clip; } diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index d818ca09f20..4cbfb4f0f3e 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -1058,7 +1058,8 @@ static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm /* if needed, reallocate multires paint mask */ if (gpm && gpm->level < key.level) { gpm->level = key.level; - MEM_freeN(gpm->data); + if (gpm->data) + MEM_freeN(gpm->data); gpm->data = MEM_callocN(sizeof(float) * key.grid_area, "gpm.data"); } diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index cdedd818b43..f19dfe74a36 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -2674,7 +2674,7 @@ static void basic_force_cb(void *efdata_v, ParticleKey *state, float *force, flo force[2] += (BLI_frand()-0.5f) * part->brownfac; } - if(part->flag & PART_ROT_DYN && epoint.ave) + if (part->flag & PART_ROT_DYN && epoint.ave) copy_v3_v3(pa->state.ave, epoint.ave); } /* gathers all forces that effect particles and calculates a new state for the particle */ diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index 7a5465edf02..ebc31517524 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -150,6 +150,7 @@ static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs) struct WTURBULENCE *smoke_turbulence_init(int *UNUSED(res), int UNUSED(amplify), int UNUSED(noisetype)) { return NULL; } struct FLUID_3D *smoke_init(int *UNUSED(res), float *UNUSED(p0)) { return NULL; } void smoke_free(struct FLUID_3D *UNUSED(fluid)) {} +float *smoke_get_density(struct FLUID_3D *UNUSED(fluid)) { return NULL; } void smoke_turbulence_free(struct WTURBULENCE *UNUSED(wt)) {} void smoke_initWaveletBlenderRNA(struct WTURBULENCE *UNUSED(wt), float *UNUSED(strength)) {} void smoke_initBlenderRNA(struct FLUID_3D *UNUSED(fluid), float *UNUSED(alpha), float *UNUSED(beta), float *UNUSED(dt_factor), float *UNUSED(vorticity), int *UNUSED(border_colli)) {} diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index 91e93bbd05d..40471514b48 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -1003,9 +1003,11 @@ void BKE_ffmpeg_end(void) fprintf(stderr, "Closing ffmpeg...\n"); -/* if (audio_stream) { SEE UPPER - write_audio_frames(); - }*/ +#if 0 + if (audio_stream) { /* SEE UPPER */ + write_audio_frames(); + } +#endif #ifdef WITH_AUDASPACE if (audio_mixdown_device) { diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c index 9433cfd31df..5b034bd2872 100644 --- a/source/blender/blenlib/intern/math_color.c +++ b/source/blender/blenlib/intern/math_color.c @@ -285,8 +285,8 @@ void rgb_to_hsl(float r, float g, float b, float *lh, float *ls, float *ll) else { h = (r - g) / d + 4.0f; } - } - h /= 6.0f; + } + h /= 6.0f; *lh = h; *ls = s; @@ -634,23 +634,23 @@ void BLI_init_srgb_conversion(void) } static float inverse_srgb_companding(float v) { - if (v > 0.04045f) { - return powf((v + 0.055f) / 1.055f, 2.4); - } - else { - return v / 12.92f; - } + if (v > 0.04045f) { + return powf((v + 0.055f) / 1.055f, 2.4); + } + else { + return v / 12.92f; + } } void rgb_to_xyz(float r, float g, float b, float *x, float *y, float *z) { - r = inverse_srgb_companding(r) * 100.0f; - g = inverse_srgb_companding(g) * 100.0f; - b = inverse_srgb_companding(b) * 100.0f; + r = inverse_srgb_companding(r) * 100.0f; + g = inverse_srgb_companding(g) * 100.0f; + b = inverse_srgb_companding(b) * 100.0f; - *x = r * 0.4124 + g * 0.3576 + b * 0.1805; - *y = r * 0.2126 + g * 0.7152 + b * 0.0722; - *z = r * 0.0193 + g * 0.1192 + b * 0.9505; + *x = r * 0.4124 + g * 0.3576 + b * 0.1805; + *y = r * 0.2126 + g * 0.7152 + b * 0.0722; + *z = r * 0.0193 + g * 0.1192 + b * 0.9505; } static float xyz_to_lab_component(float v) diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index e9bccd4244b..9795d4dea2d 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -335,9 +335,9 @@ size_t BLI_strncpy_wchar_from_utf8(wchar_t *dst_w, const char *src_c, const size int BLI_str_utf8_size(const char *p) { int mask = 0, len; - unsigned char c = (unsigned char) *p; + unsigned char c = (unsigned char) *p; - UTF8_COMPUTE (c, mask, len); + UTF8_COMPUTE (c, mask, len); (void)mask; /* quiet warning */ diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 4c82e10d717..532488ba2d2 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -6228,7 +6228,7 @@ static void lib_link_mask(FileData *fd, Main *main) mask = main->mask.first; while (mask) { - if(mask->id.flag & LIB_NEEDLINK) { + if (mask->id.flag & LIB_NEEDLINK) { MaskLayer *masklay; if (mask->adt) @@ -6725,6 +6725,11 @@ static void do_versions_nodetree_multi_file_output_format_2_62_1(Scene *sce, bNo char basepath[FILE_MAXDIR]; char filename[FILE_MAXFILE]; + /* ugly, need to remove the old inputs list to avoid bad pointer checks when adding new sockets. + * sock->storage is expected to contain path info in ntreeCompositOutputFileAddSocket. + */ + node->inputs.first = node->inputs.last = NULL; + node->storage = nimf; /* split off filename from the old path, to be used as socket sub-path */ @@ -6898,6 +6903,22 @@ static void do_versions_nodetree_frame_2_64_6(bNodeTree *ntree) } } +static void do_version_ntree_image_user_264(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree) +{ + bNode *node; + + for (node = ntree->nodes.first; node; node = node->next) { + if (ELEM(node->type, SH_NODE_TEX_IMAGE, SH_NODE_TEX_ENVIRONMENT)) { + NodeTexImage *tex = node->storage; + + tex->iuser.frames= 1; + tex->iuser.sfra= 1; + tex->iuser.fie_ima= 2; + tex->iuser.ok= 1; + } + } +} + static void do_versions(FileData *fd, Library *lib, Main *main) { /* WATCH IT!!!: pointers from libdata have not been converted */ @@ -7606,6 +7627,13 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } } + if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 9)) { + bNodeTreeType *ntreetype = ntreeGetType(NTREE_SHADER); + + if (ntreetype && ntreetype->foreach_nodetree) + ntreetype->foreach_nodetree(main, NULL, do_version_ntree_image_user_264); + } + /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */ { diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index 195057817dd..45d7d4a7684 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -804,7 +804,7 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node, 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(root) : object_map.find(node->getUniqueId())->second; + Object *ob = is_joint ? armature_importer->get_armature_for_joint(root) : object_map.find(node->getUniqueId())->second; if (!ob) { fprintf(stderr, "cannot find Object for Node with id=\"%s\"\n", node->getOriginalId().c_str()); return; diff --git a/source/blender/compositor/nodes/COM_ViewerNode.cpp b/source/blender/compositor/nodes/COM_ViewerNode.cpp index db4fd115d73..679589a7ce1 100644 --- a/source/blender/compositor/nodes/COM_ViewerNode.cpp +++ b/source/blender/compositor/nodes/COM_ViewerNode.cpp @@ -37,7 +37,7 @@ void ViewerNode::convertToOperations(ExecutionSystem *graph, CompositorContext * Image *image = (Image*)this->getbNode()->id; ImageUser * imageUser = (ImageUser*) this->getbNode()->storage; bNode *editorNode = this->getbNode(); - if (imageSocket->isConnected() && (editorNode->flag & NODE_DO_OUTPUT)) { + if (imageSocket->isConnected()) { ViewerOperation *viewerOperation = new ViewerOperation(); viewerOperation->setColorManagement(context->getScene()->r.color_mgt_flag & R_COLOR_MANAGEMENT); viewerOperation->setColorPredivide(context->getScene()->r.color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE); diff --git a/source/blender/compositor/operations/COM_BlurBaseOperation.cpp b/source/blender/compositor/operations/COM_BlurBaseOperation.cpp index babea459d6a..2280ee3a435 100644 --- a/source/blender/compositor/operations/COM_BlurBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_BlurBaseOperation.cpp @@ -101,7 +101,10 @@ void BlurBaseOperation::deinitExecution() void BlurBaseOperation::updateSize(MemoryBuffer **memoryBuffers) { - float result[4]; - this->getInputSocketReader(1)->read(result, 0, 0, COM_PS_NEAREST, memoryBuffers); - this->size = result[0]; + if (!this->sizeavailable) { + float result[4]; + this->getInputSocketReader(1)->read(result, 0, 0, COM_PS_NEAREST, memoryBuffers); + this->size = result[0]; + this->sizeavailable = true; + } } diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp index ad8f3b12387..ad58631f2c1 100644 --- a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp @@ -26,13 +26,12 @@ FastGaussianBlurOperation::FastGaussianBlurOperation(): BlurBaseOperation() { - this->iirgaus = false; + this->iirgaus = NULL; } void FastGaussianBlurOperation::executePixel(float *color,int x, int y, MemoryBuffer *inputBuffers[], void *data) { MemoryBuffer *newData = (MemoryBuffer*)data; - newData->read(color, x, y); } @@ -51,10 +50,7 @@ bool FastGaussianBlurOperation::determineDependingAreaOfInterest(rcti *input, Re } else { if (this->iirgaus) { - newInput.xmax = input->xmax + (sx); - newInput.xmin = input->xmin - (sx); - newInput.ymax = input->ymax + (sy); - newInput.ymin = input->ymin - (sy); + return false; } else { newInput.xmin = 0; @@ -66,38 +62,51 @@ bool FastGaussianBlurOperation::determineDependingAreaOfInterest(rcti *input, Re } } -void *FastGaussianBlurOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers) +void FastGaussianBlurOperation::initExecution() { - MemoryBuffer *newBuf = (MemoryBuffer*)this->inputProgram->initializeTileData(rect, memoryBuffers); - MemoryBuffer *copy = newBuf->duplicate(); - updateSize(memoryBuffers); - - int c; - sx = data->sizex * this->size/2.0f; - sy = data->sizey * this->size/2.0f; - this->iirgaus = true; - - if ((sx == sy) && (sx > 0.f)) { - for (c=0; c<COM_NUMBER_OF_CHANNELS; ++c) - IIR_gauss(copy, sx, c, 3); + BlurBaseOperation::initExecution(); + BlurBaseOperation::initMutex(); +} + +void FastGaussianBlurOperation::deinitExecution() +{ + if (this->iirgaus) { + delete this->iirgaus; + this->iirgaus = NULL; } - else { - if (sx > 0.f) { + BlurBaseOperation::deinitMutex(); +} + +void *FastGaussianBlurOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers) +{ + BLI_mutex_lock(this->getMutex()); + if (!iirgaus) { + MemoryBuffer *newBuf = (MemoryBuffer*)this->inputProgram->initializeTileData(rect, memoryBuffers); + MemoryBuffer *copy = newBuf->duplicate(); + updateSize(memoryBuffers); + + int c; + sx = data->sizex * this->size/2.0f; + sy = data->sizey * this->size/2.0f; + + if ((sx == sy) && (sx > 0.f)) { for (c=0; c<COM_NUMBER_OF_CHANNELS; ++c) - IIR_gauss(copy, sx, c, 1); + IIR_gauss(copy, sx, c, 3); } - if (sy > 0.f) { - for (c=0; c<COM_NUMBER_OF_CHANNELS; ++c) - IIR_gauss(copy, sy, c, 2); + else { + if (sx > 0.f) { + for (c=0; c<COM_NUMBER_OF_CHANNELS; ++c) + IIR_gauss(copy, sx, c, 1); + } + if (sy > 0.f) { + for (c=0; c<COM_NUMBER_OF_CHANNELS; ++c) + IIR_gauss(copy, sy, c, 2); + } } + this->iirgaus = copy; } - return copy; -} - -void FastGaussianBlurOperation::deinitializeTileData(rcti *rect, MemoryBuffer **memoryBuffers, void *data) -{ - MemoryBuffer *newData = (MemoryBuffer*)data; - delete newData; + BLI_mutex_unlock(this->getMutex()); + return iirgaus; } void FastGaussianBlurOperation::IIR_gauss(MemoryBuffer *src, float sigma, int chan, int xy) diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h index 6c3e373472b..1f71fe7f9ed 100644 --- a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h +++ b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h @@ -30,7 +30,7 @@ class FastGaussianBlurOperation: public BlurBaseOperation { private: float sx; float sy; - bool iirgaus; + MemoryBuffer* iirgaus; public: FastGaussianBlurOperation(); bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); @@ -38,7 +38,8 @@ public: static void IIR_gauss(MemoryBuffer *src, float sigma, int channel, int xy); void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers); - void deinitializeTileData(rcti *rect, MemoryBuffer **memoryBuffers, void *data); + void deinitExecution(); + void initExecution(); }; #endif diff --git a/source/blender/compositor/operations/COM_ImageOperation.cpp b/source/blender/compositor/operations/COM_ImageOperation.cpp index 020dfdbdc14..04cd91d3c3a 100644 --- a/source/blender/compositor/operations/COM_ImageOperation.cpp +++ b/source/blender/compositor/operations/COM_ImageOperation.cpp @@ -99,8 +99,8 @@ void BaseImageOperation::determineResolution(unsigned int resolution[], unsigned { ImBuf *stackbuf = getImBuf(); - resolution[0] = 0; - resolution[1] = 0; + resolution[0] = 0; + resolution[1] = 0; if (stackbuf) { resolution[0] = stackbuf->x; diff --git a/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp b/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp index 44b4c26fb64..71fc53e8f8e 100644 --- a/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp @@ -50,8 +50,9 @@ ViewerBaseOperation::ViewerBaseOperation() : NodeOperation() void ViewerBaseOperation::initExecution() { - // When initializing the tree during initial load the width and height can be zero. - initImage(); + if (isActiveViewerOutput()) { + initImage(); + } } void ViewerBaseOperation::initImage() @@ -79,7 +80,6 @@ void ViewerBaseOperation::initImage() } void ViewerBaseOperation:: updateImage(rcti *rect) { - /// @todo: introduce new event to update smaller area WM_main_add_notifier(NC_WINDOW|ND_DRAW, NULL); } diff --git a/source/blender/compositor/operations/COM_ViewerBaseOperation.h b/source/blender/compositor/operations/COM_ViewerBaseOperation.h index 58101911550..f5f30809f65 100644 --- a/source/blender/compositor/operations/COM_ViewerBaseOperation.h +++ b/source/blender/compositor/operations/COM_ViewerBaseOperation.h @@ -42,7 +42,7 @@ protected: bool doColorPredivide; public: - bool isOutputOperation(bool rendering) const {return true;} + bool isOutputOperation(bool rendering) const {return isActiveViewerOutput();} void initExecution(); void deinitExecution(); void setImage(Image *image) {this->image = image;} diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 48743c68ff5..ea3c8685525 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -756,7 +756,7 @@ static int pose_visual_transform_apply_exec(bContext *C, wmOperator *UNUSED(op)) * * TODO, loop over children before parents if multiple bones * at once are to be predictable*/ - CTX_DATA_BEGIN (C, bPoseChannel *, pchan, selected_pose_bones) + CTX_DATA_BEGIN(C, bPoseChannel *, pchan, selected_pose_bones) { float delta_mat[4][4]; @@ -923,7 +923,7 @@ int join_armature_exec(bContext *C, wmOperator *UNUSED(op)) pose = ob->pose; ob->mode &= ~OB_MODE_POSE; - CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) + CTX_DATA_BEGIN(C, Base *, base, selected_editable_bases) { if ((base->object->type == OB_ARMATURE) && (base->object != ob)) { bArmature *curarm = base->object->data; @@ -1195,7 +1195,7 @@ static int separate_armature_exec(bContext *C, wmOperator *UNUSED(op)) /* 1) only edit-base selected */ // TODO: use context iterators for this? - CTX_DATA_BEGIN (C, Base *, base, visible_bases) + CTX_DATA_BEGIN(C, Base *, base, visible_bases) { if (base->object == obedit) base->flag |= 1; else base->flag &= ~1; @@ -2848,7 +2848,7 @@ static int armature_fill_bones_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; /* loop over all bones, and only consider if visible */ - CTX_DATA_BEGIN (C, EditBone *, ebone, visible_bones) + CTX_DATA_BEGIN(C, EditBone *, ebone, visible_bones) { if (!(ebone->flag & BONE_CONNECTED) && (ebone->flag & BONE_ROOTSEL)) fill_add_joint(ebone, 0, &points); @@ -3562,7 +3562,7 @@ static int armature_subdivide_exec(bContext *C, wmOperator *op) /* loop over all editable bones */ // XXX the old code did this in reverse order though! - CTX_DATA_BEGIN (C, EditBone *, ebone, selected_editable_bones) + CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) { for (i = numcuts + 1; i > 1; i--) { /* compute cut ratio first */ @@ -3851,7 +3851,7 @@ static int armature_parent_set_exec(bContext *C, wmOperator *op) */ /* parent selected bones to the active one */ - CTX_DATA_BEGIN (C, EditBone *, ebone, selected_editable_bones) + CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) { if (ELEM(ebone, actbone, actmirb) == 0) { if (ebone->flag & BONE_SELECTED) @@ -3877,7 +3877,7 @@ static int armature_parent_set_invoke(bContext *C, wmOperator *UNUSED(op), wmEve uiLayout *layout = uiPupMenuLayout(pup); int allchildbones = 0; - CTX_DATA_BEGIN (C, EditBone *, ebone, selected_editable_bones) + CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) { if (ebone != actbone) { if (ebone->parent != actbone) allchildbones = 1; @@ -3937,7 +3937,7 @@ static int armature_parent_clear_exec(bContext *C, wmOperator *op) bArmature *arm = (bArmature *)ob->data; int val = RNA_enum_get(op->ptr, "type"); - CTX_DATA_BEGIN (C, EditBone *, ebone, selected_editable_bones) + CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) { editbone_clear_parent(ebone, val); } @@ -3974,7 +3974,7 @@ void ARMATURE_OT_parent_clear(wmOperatorType *ot) static int armature_select_inverse_exec(bContext *C, wmOperator *UNUSED(op)) { /* Set the flags */ - CTX_DATA_BEGIN (C, EditBone *, ebone, visible_bones) + CTX_DATA_BEGIN(C, EditBone *, ebone, visible_bones) { /* ignore bone if selection can't change */ if ((ebone->flag & BONE_UNSELECTABLE) == 0) { @@ -4017,7 +4017,7 @@ static int armature_de_select_all_exec(bContext *C, wmOperator *op) } /* Set the flags */ - CTX_DATA_BEGIN (C, EditBone *, ebone, visible_bones) + CTX_DATA_BEGIN(C, EditBone *, ebone, visible_bones) { /* ignore bone if selection can't change */ if ((ebone->flag & BONE_UNSELECTABLE) == 0) { @@ -4437,7 +4437,7 @@ static int armature_align_bones_exec(bContext *C, wmOperator *op) */ /* align selected bones to the active one */ - CTX_DATA_BEGIN (C, EditBone *, ebone, selected_editable_bones) + CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) { if (ELEM(ebone, actbone, actmirb) == 0) { if (ebone->flag & BONE_SELECTED) @@ -4523,7 +4523,9 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor * note, special exception for armature mode so we can do multi-select * we could check for multi-select explicitly but think its fine to * always give predictable behavior in weight paint mode - campbell */ - if ((!extend && !deselect && !toggle)|| ((ob_act && (ob_act != ob) && (ob_act->mode & OB_MODE_WEIGHT_PAINT) == 0))) { + if ((!extend && !deselect && !toggle) || + ((ob_act && (ob_act != ob) && (ob_act->mode & OB_MODE_WEIGHT_PAINT) == 0))) + { ED_pose_deselectall(ob, 0); nearBone->flag |= (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); arm->act_bone = nearBone; @@ -5134,7 +5136,7 @@ static int pose_clear_transform_generic_exec(bContext *C, wmOperator *op, } /* only clear relevant transforms for selected bones */ - CTX_DATA_BEGIN (C, bPoseChannel *, pchan, selected_pose_bones) + CTX_DATA_BEGIN(C, bPoseChannel *, pchan, selected_pose_bones) { /* run provided clearing function */ clear_func(pchan); @@ -5278,7 +5280,7 @@ static int pose_de_select_all_exec(bContext *C, wmOperator *op) } /* Set the flags */ - CTX_DATA_BEGIN (C, bPoseChannel *, pchan, visible_pose_bones) + CTX_DATA_BEGIN(C, bPoseChannel *, pchan, visible_pose_bones) { /* select pchan only if selectable, but deselect works always */ switch (action) { @@ -5674,7 +5676,7 @@ static int armature_flip_names_exec(bContext *C, wmOperator *UNUSED(op)) arm = ob->data; /* loop through selected bones, auto-naming them */ - CTX_DATA_BEGIN (C, EditBone *, ebone, selected_editable_bones) + CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) { flip_side_name(newname, ebone->name, TRUE); // 1 = do strip off number extensions ED_armature_bone_rename(arm, ebone->name, newname); @@ -5719,7 +5721,7 @@ static int armature_autoside_names_exec(bContext *C, wmOperator *op) arm = ob->data; /* loop through selected bones, auto-naming them */ - CTX_DATA_BEGIN (C, EditBone *, ebone, selected_editable_bones) + CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) { BLI_strncpy(newname, ebone->name, sizeof(newname)); if (bone_autoside_name(newname, 1, axis, ebone->head[axis], ebone->tail[axis])) @@ -5742,7 +5744,8 @@ void ARMATURE_OT_autoside_names(wmOperatorType *ot) {0, "XAXIS", 0, "X-Axis", "Left/Right"}, {1, "YAXIS", 0, "Y-Axis", "Front/Back"}, {2, "ZAXIS", 0, "Z-Axis", "Top/Bottom"}, - {0, NULL, 0, NULL, NULL}}; + {0, NULL, 0, NULL, NULL} + }; /* identifiers */ ot->name = "AutoName by Axis"; diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c index d642ee57c57..27c40095348 100644 --- a/source/blender/editors/curve/curve_ops.c +++ b/source/blender/editors/curve/curve_ops.c @@ -141,14 +141,14 @@ void ED_operatormacros_curve(void) wmOperatorTypeMacro *otmacro; ot = WM_operatortype_append_macro("CURVE_OT_duplicate_move", "Add Duplicate", "Duplicate curve and move", - OPTYPE_UNDO|OPTYPE_REGISTER); + OPTYPE_UNDO | OPTYPE_REGISTER); WM_operatortype_macro_define(ot, "CURVE_OT_duplicate"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); RNA_enum_set(otmacro->ptr, "proportional", 0); RNA_boolean_set(otmacro->ptr, "mirror", FALSE); ot = WM_operatortype_append_macro("CURVE_OT_extrude_move", "Extrude Curve and Move", - "Extrude curve and move result", OPTYPE_UNDO|OPTYPE_REGISTER); + "Extrude curve and move result", OPTYPE_UNDO | OPTYPE_REGISTER); WM_operatortype_macro_define(ot, "CURVE_OT_extrude"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); RNA_enum_set(otmacro->ptr, "proportional", 0); @@ -189,8 +189,8 @@ void ED_keymap_curve(wmKeyConfig *keyconf) RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", ENDKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", LINE_END); RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_CHAR); RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_CHAR); - RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", PREV_WORD); - RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", NEXT_WORD); + RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0)->ptr, "type", PREV_WORD); + RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0)->ptr, "type", NEXT_WORD); RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", UPARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_LINE); RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", DOWNARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_LINE); RNA_enum_set(WM_keymap_add_item(keymap, "FONT_OT_move_select", PAGEUPKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_PAGE); @@ -224,9 +224,9 @@ void ED_keymap_curve(wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "CURVE_OT_vertex_add", LEFTMOUSE, KM_CLICK, KM_CTRL, 0); kmi = WM_keymap_add_item(keymap, "CURVE_OT_select_all", AKEY, KM_PRESS, 0, 0); - RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE); + RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE); kmi = WM_keymap_add_item(keymap, "CURVE_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0); - RNA_enum_set(kmi->ptr, "action", SEL_INVERT); + RNA_enum_set(kmi->ptr, "action", SEL_INVERT); WM_keymap_add_item(keymap, "CURVE_OT_select_row", RKEY, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "CURVE_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0); diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index b94d3653f60..2fa7b4b2126 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -3530,7 +3530,8 @@ void CURVE_OT_spline_type_set(wmOperatorType *ot) // {CU_CARDINAL, "CARDINAL", 0, "Cardinal", ""}, // {CU_BSPLINE, "B_SPLINE", 0, "B-Spline", ""}, {CU_NURBS, "NURBS", 0, "NURBS", ""}, - {0, NULL, 0, NULL, NULL}}; + {0, NULL, 0, NULL, NULL} + }; /* identifiers */ ot->name = "Set Spline Type"; @@ -3573,7 +3574,8 @@ void CURVE_OT_handle_type_set(wmOperatorType *ot) {5, "ALIGNED", 0, "Aligned", ""}, {6, "FREE_ALIGN", 0, "Free", ""}, {3, "TOGGLE_FREE_ALIGN", 0, "Toggle Free/Align", ""}, - {0, NULL, 0, NULL, NULL}}; + {0, NULL, 0, NULL, NULL} + }; /* identifiers */ ot->name = "Set Handle Type"; @@ -4886,7 +4888,8 @@ void CURVE_OT_cyclic_toggle(wmOperatorType *ot) static EnumPropertyItem direction_items[] = { {0, "CYCLIC_U", 0, "Cyclic U", ""}, {1, "CYCLIC_V", 0, "Cyclic V", ""}, - {0, NULL, 0, NULL, NULL}}; + {0, NULL, 0, NULL, NULL} + }; /* identifiers */ ot->name = "Toggle Cyclic"; @@ -6007,7 +6010,8 @@ void CURVE_OT_delete(wmOperatorType *ot) {0, "SELECTED", 0, "Select", ""}, {1, "SEGMENT", 0, "Segment", ""}, {2, "ALL", 0, "All", ""}, - {0, NULL, 0, NULL, NULL}}; + {0, NULL, 0, NULL, NULL} + }; /* identifiers */ ot->name = "Delete"; @@ -6101,7 +6105,7 @@ int join_curve_exec(bContext *C, wmOperator *UNUSED(op)) /* trasnform all selected curves inverse in obact */ invert_m4_m4(imat, ob->obmat); - CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) + CTX_DATA_BEGIN(C, Base *, base, selected_editable_bases) { if (base->object->type == ob->type) { if (base->object != ob) { diff --git a/source/blender/editors/curve/lorem.c b/source/blender/editors/curve/lorem.c index 66b358e04e5..7823be3df6d 100644 --- a/source/blender/editors/curve/lorem.c +++ b/source/blender/editors/curve/lorem.c @@ -25,7 +25,7 @@ #include "curve_intern.h" -const char ED_lorem[]= { +const char ED_lorem[] = { 76, 111, 114, 101, 109, 32, 105, 112, 115, 117, 109, 32, 100, 111, 108, 111, 114, 32, 115, 105, 116, 32, 97, 109, 101, 116, 44, 32, 99, 111, 110, 115, 101, 99, 116, 101, 116, 117, 101, 114, 32, 97, 100, 105, 112, 105, 115, 99, 105, 110, 103, 32, 101, 108, 105, 116, 46, 32, 65, 108, 105, 113, 117, 97, 109, 32, 116, 114, 105, 115, 116, 105, 113, 117, 101, 32, 105, 110, 116, 101, 114, 100, 117, 109, 32, 115, 101, 109, 46, 32, 78, 117, 108, diff --git a/source/blender/editors/include/ED_clip.h b/source/blender/editors/include/ED_clip.h index 7e1505b652f..f7fb1709ce7 100644 --- a/source/blender/editors/include/ED_clip.h +++ b/source/blender/editors/include/ED_clip.h @@ -49,8 +49,8 @@ int ED_space_clip_view_clip_poll(struct bContext *C); int ED_space_clip_tracking_poll(struct bContext *C); int ED_space_clip_tracking_size_poll(struct bContext *C); int ED_space_clip_tracking_frame_poll(struct bContext *C); -int ED_space_clip_maskediting_poll(struct bContext *C); -int ED_space_clip_maskediting_mask_poll(bContext *C); +int ED_space_clip_maskedit_poll(struct bContext *C); +int ED_space_clip_maskedit_mask_poll(bContext *C); void ED_space_clip_set(struct bContext *C, struct bScreen *screen, struct SpaceClip *sc, struct MovieClip *clip); struct MovieClip *ED_space_clip(struct SpaceClip *sc); diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h index d867532b273..c4d7197bfa1 100644 --- a/source/blender/editors/include/ED_transform.h +++ b/source/blender/editors/include/ED_transform.h @@ -71,6 +71,7 @@ enum { TFM_BONESIZE, TFM_BONE_ENVELOPE, TFM_CURVE_SHRINKFATTEN, + TFM_MASK_SHRINKFATTEN, TFM_BONE_ROLL, TFM_TIME_TRANSLATE, TFM_TIME_SLIDE, diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 21f87029cb0..7f9a998e6d0 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -166,13 +166,14 @@ static int panels_re_align(ScrArea *sa, ARegion *ar, Panel **r_pa) static void panels_collapse_all(ScrArea *sa, ARegion *ar) { - Panel *pa; - int flag = ((panel_aligned(sa, ar)==BUT_HORIZONTAL)? PNL_CLOSEDX: PNL_CLOSEDY); + Panel *pa; + int flag = ((panel_aligned(sa, ar) == BUT_HORIZONTAL) ? PNL_CLOSEDX : PNL_CLOSEDY); - for (pa= ar->panels.first; pa; pa= pa->next) { - if (pa->type && !(pa->type->flag & PNL_NO_HEADER)) - pa->flag = flag; - } + for (pa = ar->panels.first; pa; pa = pa->next) { + if (pa->type && !(pa->type->flag & PNL_NO_HEADER)) { + pa->flag = flag; + } + } } diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index daba096696c..2d9c6ee7657 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2242,7 +2242,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe } } else if (itemptr->type == &RNA_MaskLayer) { - split = uiLayoutSplit(sub, 0.66f, 0); + split = uiLayoutSplit(sub, 0.5f, 0); uiItemL(split, name, icon); diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 1a7fc98ef74..004c5306d65 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -162,9 +162,10 @@ static unsigned int scroll_circle_face[14][3] = { }; -static float menu_tria_vert[6][2]= { -{-0.33, 0.16}, {0.33, 0.16}, {0, 0.82}, -{0, -0.82}, {-0.33, -0.16}, {0.33, -0.16}}; +static float menu_tria_vert[6][2] = { + {-0.33, 0.16}, {0.33, 0.16}, {0, 0.82}, + {0, -0.82}, {-0.33, -0.16}, {0.33, -0.16} +}; @@ -1168,7 +1169,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b #if 0 ui_rasterpos_safe(x, y, but->aspect); - if (but->type == IDPOIN) transopts = 0; // no translation, of course! + if (but->type == IDPOIN) transopts = 0; // no translation, of course! else transopts = ui_translate_buttons(); #endif @@ -3133,7 +3134,7 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct if (but->drawflag & UI_BUT_DRAW_ENUM_ARROWS) wt = widget_type(UI_WTYPE_MENU_RADIO); /* with arrows */ else - wt = widget_type(UI_WTYPE_MENU_ICON_RADIO); /* no arrows */ + wt = widget_type(UI_WTYPE_MENU_ICON_RADIO); /* no arrows */ } /* with menu arrows */ else diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index f2ea81abcbf..2e70a941a54 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -783,8 +783,8 @@ void ui_theme_init_default(void) /* space nla */ btheme->tnla = btheme->tact; - rgba_char_args_set(btheme->tnla.anim_active, 204, 112, 26, 102); /* same as for dopesheet; duplicate here for easier reference */ - rgba_char_args_set(btheme->tnla.anim_non_active,153, 135, 97, 77); + rgba_char_args_set(btheme->tnla.anim_active, 204, 112, 26, 102); /* same as for dopesheet; duplicate here for easier reference */ + rgba_char_args_set(btheme->tnla.anim_non_active, 153, 135, 97, 77); rgba_char_args_set(btheme->tnla.nla_tweaking, 77, 243, 26, 77); rgba_char_args_set(btheme->tnla.nla_tweakdupli, 217, 0, 0, 255); diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c index c2c2ebbfe42..f8c36e866d7 100644 --- a/source/blender/editors/mask/mask_add.c +++ b/source/blender/editors/mask/mask_add.c @@ -31,12 +31,9 @@ #include "MEM_guardedalloc.h" -#include "BLI_utildefines.h" -#include "BLI_listbase.h" #include "BLI_math.h" #include "BKE_context.h" -#include "BKE_curve.h" #include "BKE_depsgraph.h" #include "BKE_mask.h" @@ -47,10 +44,7 @@ #include "WM_api.h" #include "WM_types.h" -#include "ED_screen.h" -#include "ED_mask.h" -#include "ED_clip.h" -#include "ED_keyframing.h" +#include "ED_mask.h" /* own include */ #include "RNA_access.h" #include "RNA_define.h" @@ -156,7 +150,7 @@ static int find_nearest_diff_point(bContext *C, Mask *mask, const float normal_c *point_r = point; if (u_r) { - u = BKE_mask_spline_project_co(point_spline, point, u, normal_co); + u = BKE_mask_spline_project_co(point_spline, point, u, normal_co, MASK_PROJ_ANY); *u_r = u; } @@ -630,7 +624,7 @@ void MASK_OT_add_vertex(wmOperatorType *ot) /* api callbacks */ ot->exec = add_vertex_exec; ot->invoke = add_vertex_invoke; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -660,6 +654,11 @@ static int add_feather_vertex_exec(bContext *C, wmOperator *op) if (find_nearest_diff_point(C, mask, co, threshold, TRUE, &masklay, &spline, &point, &u, NULL)) { Scene *scene = CTX_data_scene(C); float w = BKE_mask_point_weight(spline, point, u); + float weight_scalar = BKE_mask_point_weight_scalar(spline, point, u); + + if (weight_scalar != 0.0f) { + w = w / weight_scalar; + } BKE_mask_point_add_uw(point, u, w); @@ -696,7 +695,7 @@ void MASK_OT_add_feather_vertex(wmOperatorType *ot) /* api callbacks */ ot->exec = add_feather_vertex_exec; ot->invoke = add_feather_vertex_invoke; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/mask/mask_draw.c b/source/blender/editors/mask/mask_draw.c index e580088e25b..a26ae5ea3c0 100644 --- a/source/blender/editors/mask/mask_draw.c +++ b/source/blender/editors/mask/mask_draw.c @@ -32,7 +32,6 @@ #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" -#include "BLI_math.h" #include "BKE_context.h" #include "BKE_mask.h" @@ -40,10 +39,8 @@ #include "DNA_mask_types.h" #include "DNA_object_types.h" /* SELECT */ -#include "ED_mask.h" - +#include "ED_mask.h" /* own include */ #include "BIF_gl.h" -#include "BIF_glutil.h" #include "UI_resources.h" diff --git a/source/blender/editors/mask/mask_edit.c b/source/blender/editors/mask/mask_edit.c index 0b8551ddd4c..9bfcd2a9886 100644 --- a/source/blender/editors/mask/mask_edit.c +++ b/source/blender/editors/mask/mask_edit.c @@ -29,9 +29,7 @@ * \ingroup edmask */ -#include "MEM_guardedalloc.h" -#include "BLI_utildefines.h" #include "BLI_math.h" #include "BKE_context.h" @@ -41,7 +39,7 @@ #include "WM_types.h" #include "ED_screen.h" -#include "ED_mask.h" +#include "ED_mask.h" /* own include */ #include "ED_object.h" /* ED_keymap_proportional_maskmode only */ #include "ED_clip.h" #include "ED_transform.h" @@ -52,23 +50,23 @@ /********************** generic poll functions *********************/ -int ED_maskediting_poll(bContext *C) +int ED_maskedit_poll(bContext *C) { SpaceClip *sc = CTX_wm_space_clip(C); if (sc) { - return ED_space_clip_maskediting_poll(C); + return ED_space_clip_maskedit_poll(C); } return FALSE; } -int ED_maskediting_mask_poll(bContext *C) +int ED_maskedit_mask_poll(bContext *C) { SpaceClip *sc = CTX_wm_space_clip(C); if (sc) { - return ED_space_clip_maskediting_mask_poll(C); + return ED_space_clip_maskedit_mask_poll(C); } return FALSE; @@ -214,6 +212,9 @@ void ED_operatortypes_mask(void) WM_operatortype_append(MASK_OT_hide_view_clear); WM_operatortype_append(MASK_OT_hide_view_set); + /* feather */ + WM_operatortype_append(MASK_OT_feather_weight_clear); + /* shape */ WM_operatortype_append(MASK_OT_slide_point); WM_operatortype_append(MASK_OT_cyclic_toggle); @@ -226,6 +227,7 @@ void ED_operatortypes_mask(void) /* shapekeys */ WM_operatortype_append(MASK_OT_shape_key_insert); WM_operatortype_append(MASK_OT_shape_key_clear); + WM_operatortype_append(MASK_OT_shape_key_feather_reset); } void ED_keymap_mask(wmKeyConfig *keyconf) @@ -233,8 +235,8 @@ void ED_keymap_mask(wmKeyConfig *keyconf) wmKeyMap *keymap; wmKeyMapItem *kmi; - keymap = WM_keymap_find(keyconf, "Mask Editor", 0, 0); - keymap->poll = ED_maskediting_poll; + keymap = WM_keymap_find(keyconf, "Mask Editing", 0, 0); + keymap->poll = ED_maskedit_poll; WM_keymap_add_item(keymap, "MASK_OT_new", NKEY, KM_PRESS, KM_ALT, 0); @@ -295,6 +297,9 @@ void ED_keymap_mask(wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "MASK_OT_cyclic_toggle", CKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "MASK_OT_slide_point", LEFTMOUSE, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "MASK_OT_handle_type_set", VKEY, KM_PRESS, 0, 0); + // WM_keymap_add_item(keymap, "MASK_OT_feather_weight_clear", SKEY, KM_PRESS, KM_ALT, 0); + /* ... matches curve editmode */ + RNA_enum_set(WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", TFM_MASK_SHRINKFATTEN); /* relationships */ WM_keymap_add_item(keymap, "MASK_OT_parent_set", PKEY, KM_PRESS, KM_CTRL, 0); diff --git a/source/blender/editors/mask/mask_intern.h b/source/blender/editors/mask/mask_intern.h index 70f13abd44f..fc6089238a1 100644 --- a/source/blender/editors/mask/mask_intern.h +++ b/source/blender/editors/mask/mask_intern.h @@ -54,6 +54,7 @@ void MASK_OT_delete(struct wmOperatorType *ot); void MASK_OT_hide_view_clear(struct wmOperatorType *ot); void MASK_OT_hide_view_set(struct wmOperatorType *ot); +void MASK_OT_feather_weight_clear(struct wmOperatorType *ot); void MASK_OT_switch_direction(struct wmOperatorType *ot); void MASK_OT_handle_type_set(struct wmOperatorType *ot); @@ -92,8 +93,8 @@ void ED_mask_select_toggle_all(struct Mask *mask, int action); void ED_mask_select_flush_all(struct Mask *mask); /* mask_editor.c */ -int ED_maskediting_poll(struct bContext *C); -int ED_maskediting_mask_poll(struct bContext *C); +int ED_maskedit_poll(struct bContext *C); +int ED_maskedit_mask_poll(struct bContext *C); void ED_mask_size(struct bContext *C, int *width, int *height); void ED_mask_aspect(struct bContext *C, float *aspx, float *aspy); @@ -107,5 +108,6 @@ void ED_mask_point_pos__reverse(struct bContext *C, float x, float y, float *xr, /* mask_shapekey.c */ void MASK_OT_shape_key_insert(struct wmOperatorType *ot); void MASK_OT_shape_key_clear(struct wmOperatorType *ot); +void MASK_OT_shape_key_feather_reset(struct wmOperatorType *ot); #endif /* __MASK_INTERN_H__ */ diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c index cf3a72bdc78..c9f2450afc3 100644 --- a/source/blender/editors/mask/mask_ops.c +++ b/source/blender/editors/mask/mask_ops.c @@ -31,12 +31,10 @@ #include "MEM_guardedalloc.h" -#include "BLI_utildefines.h" #include "BLI_listbase.h" #include "BLI_math.h" #include "BKE_context.h" -#include "BKE_curve.h" #include "BKE_depsgraph.h" #include "BKE_mask.h" @@ -315,7 +313,7 @@ void MASK_OT_layer_new(wmOperatorType *ot) /* api callbacks */ ot->exec = masklay_new_exec; - ot->poll = ED_maskediting_poll; + ot->poll = ED_maskedit_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -349,7 +347,7 @@ void MASK_OT_layer_remove(wmOperatorType *ot) /* api callbacks */ ot->exec = masklay_remove_exec; - ot->poll = ED_maskediting_poll; + ot->poll = ED_maskedit_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -357,10 +355,12 @@ void MASK_OT_layer_remove(wmOperatorType *ot) /******************** slide *********************/ -#define SLIDE_ACTION_NONE 0 -#define SLIDE_ACTION_POINT 1 -#define SLIDE_ACTION_HANDLE 2 -#define SLIDE_ACTION_FEATHER 3 +enum { + SLIDE_ACTION_NONE = 0, + SLIDE_ACTION_POINT = 1, + SLIDE_ACTION_HANDLE = 2, + SLIDE_ACTION_FEATHER = 3 +}; typedef struct SlidePointData { int action; @@ -387,15 +387,18 @@ static int slide_point_check_initial_feather(MaskSpline *spline) for (i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; - int j; if (point->bezt.weight != 0.0f) return FALSE; + /* comment for now. if all bezt weights are zero - this is as good-as initial */ +#if 0 + int j; for (j = 0; j < point->tot_uw; j++) { if (point->uw[j].w != 0.0f) return FALSE; } +#endif } return TRUE; @@ -454,25 +457,21 @@ static void *slide_point_customdata(bContext *C, wmOperator *op, wmEvent *event) if (uw) { float co[2]; - - customdata->weight = point->bezt.weight; + float weight_scalar = BKE_mask_point_weight_scalar(spline, point, uw->u); customdata->weight = uw->w; BKE_mask_point_segment_co(spline, point, uw->u, co); BKE_mask_point_normal(spline, point, uw->u, customdata->no); - customdata->feather[0] = co[0] + customdata->no[0] * uw->w; - customdata->feather[1] = co[1] + customdata->no[1] * uw->w; + madd_v2_v2v2fl(customdata->feather, co, customdata->no, uw->w * weight_scalar); } else { BezTriple *bezt = &point->bezt; + customdata->weight = bezt->weight; BKE_mask_point_normal(spline, point, 0.0f, customdata->no); - customdata->feather[0] = bezt->vec[1][0] + customdata->no[0] * bezt->weight; - customdata->feather[1] = bezt->vec[1][1] + customdata->no[1] * bezt->weight; - - customdata->weight = bezt->weight; + madd_v2_v2v2fl(customdata->feather, bezt->vec[1], customdata->no, bezt->weight); } if (customdata->action == SLIDE_ACTION_FEATHER) @@ -533,17 +532,20 @@ static void slide_point_delta_all_feather(SlidePointData *data, float delta) for (i = 0; i < data->spline->tot_point; i++) { MaskSplinePoint *point = &data->spline->points[i]; MaskSplinePoint *orig_point = &data->orig_spline->points[i]; - int j; point->bezt.weight = orig_point->bezt.weight + delta; if (point->bezt.weight < 0.0f) point->bezt.weight = 0.0f; + /* not needed anymore */ +#if 0 + int j; for (j = 0; j < point->tot_uw; j++) { point->uw[j].w = orig_point->uw[j].w + delta; if (point->uw[j].w < 0.0f) point->uw[j].w = 0.0f; } +#endif } } @@ -645,24 +647,53 @@ static int slide_point_modal(bContext *C, wmOperator *op, wmEvent *event) else if (data->action == SLIDE_ACTION_FEATHER) { float vec[2], no[2], p[2], c[2], w, offco[2]; float *weight = NULL; + float weight_scalar = 1.0f; int overall_feather = data->overall_feather || data->initial_feather; add_v2_v2v2(offco, data->feather, dco); if (data->uw) { - float u = BKE_mask_spline_project_co(data->spline, data->point, data->uw->u, offco); + /* project on both sides and find the closest one, + * prevents flickering when projecting onto both sides can happen */ + const float u_pos = BKE_mask_spline_project_co(data->spline, data->point, + data->uw->u, offco, MASK_PROJ_NEG); + const float u_neg = BKE_mask_spline_project_co(data->spline, data->point, + data->uw->u, offco, MASK_PROJ_POS); + float dist_pos = FLT_MAX; + float dist_neg = FLT_MAX; + float co_pos[2]; + float co_neg[2]; + float u; + + if (u_pos > 0.0f && u_pos < 1.0f) { + BKE_mask_point_segment_co(data->spline, data->point, u_pos, co_pos); + dist_pos = len_squared_v2v2(offco, co_pos); + } + + if (u_neg > 0.0f && u_neg < 1.0f) { + BKE_mask_point_segment_co(data->spline, data->point, u_neg, co_neg); + dist_neg = len_squared_v2v2(offco, co_neg); + } + + u = dist_pos < dist_neg ? u_pos : u_neg; if (u > 0.0f && u < 1.0f) { data->uw->u = u; data->uw = BKE_mask_point_sort_uw(data->point, data->uw); weight = &data->uw->w; + weight_scalar = BKE_mask_point_weight_scalar(data->spline, data->point, u); + if (weight_scalar != 0.0f) { + weight_scalar = 1.0f / weight_scalar; + } + BKE_mask_point_normal(data->spline, data->point, data->uw->u, no); BKE_mask_point_segment_co(data->spline, data->point, data->uw->u, p); } } else { weight = &bezt->weight; + /* weight_scalar = 1.0f; keep as is */ copy_v2_v2(no, data->no); copy_v2_v2(p, bezt->vec[1]); } @@ -685,7 +716,7 @@ static int slide_point_modal(bContext *C, wmOperator *op, wmEvent *event) /* restore weight for currently sliding point, so orig_spline would be created * with original weights used */ - *weight = data->weight; + *weight = data->weight * weight_scalar; data->orig_spline = BKE_mask_spline_copy(data->spline); } @@ -704,7 +735,9 @@ static int slide_point_modal(bContext *C, wmOperator *op, wmEvent *event) data->orig_spline = NULL; } - *weight = w; + if (weight_scalar != 0.0f) { + *weight = w * weight_scalar; + } } } } @@ -756,12 +789,12 @@ void MASK_OT_slide_point(wmOperatorType *ot) /* api callbacks */ ot->invoke = slide_point_invoke; ot->modal = slide_point_modal; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - RNA_def_boolean(ot->srna, "slide_feather", 0, "Slide Feather", "First try to slide slide feather instead of vertex"); + RNA_def_boolean(ot->srna, "slide_feather", 0, "Slide Feather", "First try to slide feather instead of vertex"); } /******************** toggle cyclic *********************/ @@ -799,7 +832,7 @@ void MASK_OT_cyclic_toggle(wmOperatorType *ot) /* api callbacks */ ot->exec = cyclic_toggle_exec; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -943,7 +976,7 @@ void MASK_OT_delete(wmOperatorType *ot) /* api callbacks */ ot->invoke = WM_operator_confirm; ot->exec = delete_exec; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -994,7 +1027,7 @@ void MASK_OT_switch_direction(wmOperatorType *ot) /* api callbacks */ ot->exec = mask_switch_direction_exec; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -1053,7 +1086,7 @@ void MASK_OT_handle_type_set(wmOperatorType *ot) /* api callbacks */ ot->invoke = WM_menu_invoke; ot->exec = set_handle_type_exec; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -1100,7 +1133,7 @@ void MASK_OT_hide_view_clear(wmOperatorType *ot) /* api callbacks */ ot->exec = mask_hide_view_clear_exec; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -1161,11 +1194,67 @@ void MASK_OT_hide_view_set(wmOperatorType *ot) /* api callbacks */ ot->exec = mask_hide_view_set_exec; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected layers"); +} + + +static int mask_feather_weight_clear_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Mask *mask = CTX_data_edit_mask(C); + MaskLayer *masklay; + int changed = FALSE; + int i; + + for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { + MaskSpline *spline; + + if (masklay->restrictflag & (MASK_RESTRICT_SELECT | MASK_RESTRICT_VIEW)) { + continue; + } + + for (spline = masklay->splines.first; spline; spline = spline->next) { + for (i = 0; i < spline->tot_point; i++) { + MaskSplinePoint *point = &spline->points[i]; + + if (MASKPOINT_ISSEL_ANY(point)) { + BezTriple *bezt = &point->bezt; + bezt->weight = 0.0f; + changed = TRUE; + } + } + } + } + + if (changed) { + /* TODO: only update edited splines */ + BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra); + + WM_event_add_notifier(C, NC_MASK | ND_DRAW, mask); + DAG_id_tag_update(&mask->id, 0); + + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } +} +void MASK_OT_feather_weight_clear(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Clear Feather Weight"; + ot->description = "Reset the feather weight to zero"; + ot->idname = "MASK_OT_feather_weight_clear"; + + /* api callbacks */ + ot->exec = mask_feather_weight_clear_exec; + ot->poll = ED_maskedit_mask_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } diff --git a/source/blender/editors/mask/mask_relationships.c b/source/blender/editors/mask/mask_relationships.c index 8a8427c024b..0e893ee2f9f 100644 --- a/source/blender/editors/mask/mask_relationships.c +++ b/source/blender/editors/mask/mask_relationships.c @@ -29,31 +29,22 @@ * \ingroup edmask */ -#include "MEM_guardedalloc.h" -#include "BLI_utildefines.h" -#include "BLI_listbase.h" #include "BLI_math.h" #include "BKE_context.h" -#include "BKE_curve.h" #include "BKE_depsgraph.h" #include "BKE_mask.h" #include "BKE_tracking.h" #include "DNA_mask_types.h" -#include "DNA_scene_types.h" #include "DNA_object_types.h" /* SELECT */ #include "WM_api.h" #include "WM_types.h" #include "ED_screen.h" -#include "ED_mask.h" -#include "ED_clip.h" - -#include "RNA_access.h" -#include "RNA_define.h" +#include "ED_mask.h" /* own include */ #include "mask_intern.h" /* own include */ @@ -91,13 +82,13 @@ void MASK_OT_parent_clear(wmOperatorType *ot) { /* identifiers */ ot->name = "Clear Parent"; - ot->description = "Clear the masks parenting"; + ot->description = "Clear the mask's parenting"; ot->idname = "MASK_OT_parent_clear"; /* api callbacks */ ot->exec = mask_parent_clear_exec; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -169,14 +160,14 @@ void MASK_OT_parent_set(wmOperatorType *ot) { /* identifiers */ ot->name = "Make Parent"; - ot->description = "Set the masks parenting"; + ot->description = "Set the mask's parenting"; ot->idname = "MASK_OT_parent_set"; /* api callbacks */ //ot->invoke = mask_parent_set_invoke; ot->exec = mask_parent_set_exec; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/mask/mask_select.c b/source/blender/editors/mask/mask_select.c index 18d745dcf7b..55e09529320 100644 --- a/source/blender/editors/mask/mask_select.c +++ b/source/blender/editors/mask/mask_select.c @@ -32,14 +32,10 @@ #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" -#include "BLI_listbase.h" #include "BLI_rect.h" #include "BLI_lasso.h" -#include "BLI_math.h" #include "BKE_context.h" -#include "BKE_curve.h" -#include "BKE_depsgraph.h" #include "BKE_mask.h" #include "DNA_mask_types.h" @@ -49,8 +45,8 @@ #include "WM_types.h" #include "ED_screen.h" -#include "ED_mask.h" #include "ED_clip.h" +#include "ED_mask.h" /* own include */ #include "RNA_access.h" #include "RNA_define.h" @@ -212,13 +208,13 @@ static int select_all_exec(bContext *C, wmOperator *op) void MASK_OT_select_all(wmOperatorType *ot) { /* identifiers */ - ot->name = "Select or Deselect All"; + ot->name = "(De)select All"; ot->description = "Change selection of all curve points"; ot->idname = "MASK_OT_select_all"; /* api callbacks */ ot->exec = select_all_exec; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -366,7 +362,7 @@ void MASK_OT_select(wmOperatorType *ot) /* api callbacks */ ot->exec = select_exec; ot->invoke = select_invoke; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_UNDO; @@ -458,7 +454,7 @@ void MASK_OT_select_border(wmOperatorType *ot) ot->invoke = WM_border_select_invoke; ot->exec = border_select_exec; ot->modal = WM_border_select_modal; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_UNDO; @@ -554,7 +550,7 @@ void MASK_OT_select_lasso(wmOperatorType *ot) ot->invoke = WM_gesture_lasso_invoke; ot->modal = WM_gesture_lasso_modal; ot->exec = clip_lasso_select_exec; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; ot->cancel = WM_gesture_lasso_cancel; /* flags */ @@ -655,7 +651,7 @@ void MASK_OT_select_circle(wmOperatorType *ot) ot->invoke = WM_gesture_circle_invoke; ot->modal = WM_gesture_circle_modal; ot->exec = circle_select_exec; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -712,7 +708,7 @@ void MASK_OT_select_linked_pick(wmOperatorType *ot) /* api callbacks */ ot->invoke = mask_select_linked_pick_invoke; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -763,7 +759,7 @@ void MASK_OT_select_linked(wmOperatorType *ot) /* api callbacks */ ot->exec = mask_select_linked_exec; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/mask/mask_shapekey.c b/source/blender/editors/mask/mask_shapekey.c index 94aebb9f3a1..38e8ed627f2 100644 --- a/source/blender/editors/mask/mask_shapekey.c +++ b/source/blender/editors/mask/mask_shapekey.c @@ -29,30 +29,20 @@ * \ingroup edmask */ -#include "MEM_guardedalloc.h" - #include "BLI_utildefines.h" -#include "BLI_listbase.h" -#include "BLI_math.h" #include "BKE_context.h" -#include "BKE_curve.h" #include "BKE_depsgraph.h" #include "BKE_mask.h" +#include "DNA_object_types.h" #include "DNA_mask_types.h" #include "DNA_scene_types.h" -#include "DNA_object_types.h" /* SELECT */ #include "WM_api.h" #include "WM_types.h" -#include "ED_screen.h" -#include "ED_mask.h" -#include "ED_clip.h" - -#include "RNA_access.h" -#include "RNA_define.h" +#include "ED_mask.h" /* own include */ #include "mask_intern.h" /* own include */ @@ -96,7 +86,7 @@ void MASK_OT_shape_key_insert(wmOperatorType *ot) /* api callbacks */ ot->exec = mask_shape_key_insert_exec; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -145,7 +135,7 @@ void MASK_OT_shape_key_clear(wmOperatorType *ot) /* api callbacks */ ot->exec = mask_shape_key_clear_exec; - ot->poll = ED_maskediting_mask_poll; + ot->poll = ED_maskedit_mask_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -166,3 +156,96 @@ int ED_mask_layer_shape_auto_key_all(Mask *mask, const int frame) return change; } + + +static int mask_shape_key_feather_reset_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Scene *scene = CTX_data_scene(C); + const int frame = CFRA; + Mask *mask = CTX_data_edit_mask(C); + MaskLayer *masklay; + int change = FALSE; + + for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { + + if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { + continue; + } + + if (masklay->splines_shapes.first) { + MaskLayerShape *masklay_shape_reset; + MaskLayerShape *masklay_shape; + + /* get the shapekey of the current state */ + masklay_shape_reset = BKE_mask_layer_shape_alloc(masklay, frame); + /* initialize from mask - as if inseting a keyframe */ + BKE_mask_layer_shape_from_mask(masklay, masklay_shape_reset); + + for (masklay_shape = masklay->splines_shapes.first; + masklay_shape; + masklay_shape = masklay_shape->next) + { + + if (masklay_shape_reset->tot_vert == masklay_shape->tot_vert) { + int i_abs = 0; + int i; + MaskSpline *spline; + MaskLayerShapeElem *shape_ele_src; + MaskLayerShapeElem *shape_ele_dst; + + shape_ele_src = (MaskLayerShapeElem *)masklay_shape_reset->data; + shape_ele_dst = (MaskLayerShapeElem *)masklay_shape->data; + + for (spline = masklay->splines.first; spline; spline = spline->next) { + for (i = 0; i < spline->tot_point; i++) { + MaskSplinePoint *point = &spline->points[i]; + + if (MASKPOINT_ISSEL_ANY(point)) { + /* TODO - nicer access here */ + shape_ele_dst->value[6] = shape_ele_src->value[6]; + } + + shape_ele_src++; + shape_ele_dst++; + + i_abs++; + } + } + + } + else { + // printf("%s: skipping\n", __func__); + } + + change = TRUE; + } + + BKE_mask_layer_shape_free(masklay_shape_reset); + } + } + + if (change) { + WM_event_add_notifier(C, NC_MASK | ND_DATA, mask); + DAG_id_tag_update(&mask->id, 0); + + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } +} + +void MASK_OT_shape_key_feather_reset(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Feather Reset Animation"; + ot->description = "Resets fearther weights on all selected points animation values"; + ot->idname = "MASK_OT_shape_key_feather_reset"; + + /* api callbacks */ + ot->exec = mask_shape_key_feather_reset_exec; + ot->poll = ED_maskedit_mask_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index cad6c23eb74..93ed7d37235 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -4830,13 +4830,11 @@ static int edbm_inset_modal(bContext *C, wmOperator *op, wmEvent *event) mdiff[1] = opdata->mcenter[1] - event->mval[1]; if (opdata->modify_depth) { - amount = opdata->old_depth + (len_v2(mdiff) - - opdata->initial_length) / opdata->initial_length; + amount = opdata->old_depth + (len_v2(mdiff) - opdata->initial_length) / opdata->initial_length; RNA_float_set(op->ptr, "depth", amount); } else { - amount = opdata->old_thickness - (len_v2(mdiff) - - opdata->initial_length) / opdata->initial_length; + amount = opdata->old_thickness - (len_v2(mdiff) - opdata->initial_length) / opdata->initial_length; amount = MAX2(amount, 0.0f); RNA_float_set(op->ptr, "thickness", amount); diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 24dd56a4834..3d7dd01bf30 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -180,7 +180,7 @@ static int object_hide_view_set_exec(bContext *C, wmOperator *op) short changed = 0; const int unselected = RNA_boolean_get(op->ptr, "unselected"); - CTX_DATA_BEGIN (C, Base *, base, visible_bases) + CTX_DATA_BEGIN(C, Base *, base, visible_bases) { if (!unselected) { if (base->flag & SELECT) { @@ -240,7 +240,7 @@ static int object_hide_render_clear_exec(bContext *C, wmOperator *UNUSED(op)) short changed = 0; /* XXX need a context loop to handle such cases */ - CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) + CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects) { if (ob->restrictflag & OB_RESTRICT_RENDER) { ob->restrictflag &= ~OB_RESTRICT_RENDER; @@ -275,7 +275,7 @@ static int object_hide_render_set_exec(bContext *C, wmOperator *op) { const int unselected = RNA_boolean_get(op->ptr, "unselected"); - CTX_DATA_BEGIN (C, Base *, base, visible_bases) + CTX_DATA_BEGIN(C, Base *, base, visible_bases) { if (!unselected) { if (base->flag & SELECT) { @@ -1114,7 +1114,7 @@ void ED_objects_recalculate_paths(bContext *C, Scene *scene) ListBase targets = {NULL, NULL}; /* loop over objects in scene */ - CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) + CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects) { /* set flag to force recalc, then grab path(s) from object */ ob->avs.recalc |= ANIMVIZ_RECALC_PATHS; @@ -1157,7 +1157,7 @@ static int object_calculate_paths_exec(bContext *C, wmOperator *op) int end = RNA_int_get(op->ptr, "end_frame"); /* set up path data for bones being calculated */ - CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) + CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects) { bAnimVizSettings *avs = &ob->avs; @@ -1196,9 +1196,9 @@ void OBJECT_OT_paths_calculate(wmOperatorType *ot) /* properties */ RNA_def_int(ot->srna, "start_frame", 1, MINAFRAME, MAXFRAME, "Start", - "First frame to calculate object paths on", MINFRAME, MAXFRAME/2.0); + "First frame to calculate object paths on", MINFRAME, MAXFRAME / 2.0); RNA_def_int(ot->srna, "end_frame", 250, MINAFRAME, MAXFRAME, "End", - "Last frame to calculate object paths on", MINFRAME, MAXFRAME/2.0); + "Last frame to calculate object paths on", MINFRAME, MAXFRAME / 2.0); } /* --------- */ @@ -1231,7 +1231,7 @@ void OBJECT_OT_paths_update(wmOperatorType *ot) ot->poll = ED_operator_object_active_editable; /* TODO: this should probably check for existing paths */ /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* --------- */ @@ -1240,7 +1240,7 @@ void OBJECT_OT_paths_update(wmOperatorType *ot) void ED_objects_clear_paths(bContext *C) { /* loop over objects in scene */ - CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) + CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects) { if (ob->mpath) { animviz_free_motionpath(ob->mpath); @@ -1288,7 +1288,7 @@ static int shade_smooth_exec(bContext *C, wmOperator *op) int clear = (strcmp(op->idname, "OBJECT_OT_shade_flat") == 0); int done = FALSE; - CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) + CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects) { if (ob->type == OB_MESH) { @@ -1666,10 +1666,12 @@ static EnumPropertyItem game_properties_copy_operations[] = { {COPY_PROPERTIES_REPLACE, "REPLACE", 0, "Replace Properties", ""}, {COPY_PROPERTIES_MERGE, "MERGE", 0, "Merge Properties", ""}, {COPY_PROPERTIES_COPY, "COPY", 0, "Copy a Property", ""}, - {0, NULL, 0, NULL, NULL}}; + {0, NULL, 0, NULL, NULL} +}; -static EnumPropertyItem gameprops_items[]= { - {0, NULL, 0, NULL, NULL}}; +static EnumPropertyItem gameprops_items[] = { + {0, NULL, 0, NULL, NULL} +}; static EnumPropertyItem *gameprops_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free) { @@ -1706,7 +1708,7 @@ static int game_property_copy_exec(bContext *C, wmOperator *op) prop = BLI_findlink(&ob->prop, propid - 1); if (prop) { - CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) + CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects) { if (ob != ob_iter) set_ob_property(ob_iter, prop); @@ -1715,7 +1717,7 @@ static int game_property_copy_exec(bContext *C, wmOperator *op) } else { - CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) + CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects) { if (ob != ob_iter) { if (type == COPY_PROPERTIES_REPLACE) @@ -1756,7 +1758,7 @@ void OBJECT_OT_game_property_copy(wmOperatorType *ot) static int game_property_clear_exec(bContext *C, wmOperator *UNUSED(op)) { - CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) + CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects) { free_properties(&ob_iter->prop); } @@ -1786,7 +1788,7 @@ static int logicbricks_copy_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = ED_object_active_context(C); - CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) + CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects) { if (ob != ob_iter) { /* first: free all logic */ @@ -1843,7 +1845,7 @@ static int game_physics_copy_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = ED_object_active_context(C); - CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) + CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects) { if (ob != ob_iter) { ob_iter->gameflag = ob->gameflag; diff --git a/source/blender/editors/object/object_lattice.c b/source/blender/editors/object/object_lattice.c index f6e8ccf4ec9..0a9944debe1 100644 --- a/source/blender/editors/object/object_lattice.c +++ b/source/blender/editors/object/object_lattice.c @@ -344,18 +344,17 @@ int mouse_lattice(bContext *C, const int mval[2], int extend, int deselect, int bp = findnearestLattvert(&vc, mval, 1); if (bp) { - if (extend) { - bp->f1 |= SELECT; - } - else if (deselect) { - bp->f1 &= ~SELECT; - } + if (extend) { + bp->f1 |= SELECT; + } + else if (deselect) { + bp->f1 &= ~SELECT; + } else if (toggle) { bp->f1 ^= SELECT; /* swap */ } - else - { - ED_setflagsLatt(vc.obedit, 0); + else { + ED_setflagsLatt(vc.obedit, 0); bp->f1 |= SELECT; } diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 89c7896d53c..4e98d2ae967 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -1951,7 +1951,7 @@ static int keyframe_jump_exec(bContext *C, wmOperator *op) { SpaceClip *sc = CTX_wm_space_clip(C); if (sc) { - if ((sc->mode == SC_MODE_MASKEDITING) && sc->mask) { + if ((sc->mode == SC_MODE_MASKEDIT) && sc->mask) { MaskLayer *masklay = BKE_mask_layer_active(sc->mask); mask_to_keylist(&ads, masklay, &keys); } diff --git a/source/blender/editors/space_clip/clip_buttons.c b/source/blender/editors/space_clip/clip_buttons.c index 5b2c3530aa4..ca2ae6e8461 100644 --- a/source/blender/editors/space_clip/clip_buttons.c +++ b/source/blender/editors/space_clip/clip_buttons.c @@ -168,7 +168,7 @@ void uiTemplateTrack(uiLayout *layout, PointerRNA *ptr, const char *propname) scopes->track_preview_height = (scopes->track_preview_height <= UI_UNIT_Y)?UI_UNIT_Y : scopes->track_preview_height; uiDefBut(block, TRACKPREVIEW, 0, "", rect.xmin, rect.ymin, rect.xmax - rect.xmin, - scopes->track_preview_height, scopes, 0, 0, 0, 0, ""); + scopes->track_preview_height, scopes, 0, 0, 0, 0, ""); } /********************* Marker Template ************************/ diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index 003fa5c5cef..47825462565 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -198,7 +198,7 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc clip_draw_curfra_label(sc, x, 8.0f); /* movie clip animation */ - if ((sc->mode == SC_MODE_MASKEDITING) && sc->mask) { + if ((sc->mode == SC_MODE_MASKEDIT) && sc->mask) { MaskLayer *masklay = BKE_mask_layer_active(sc->mask); if (masklay) { MaskLayerShape *masklay_shape; diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c index f16ef21b707..3349a61cd86 100644 --- a/source/blender/editors/space_clip/clip_editor.c +++ b/source/blender/editors/space_clip/clip_editor.c @@ -129,7 +129,7 @@ int ED_space_clip_tracking_frame_poll(bContext *C) return FALSE; } -int ED_space_clip_maskediting_poll(bContext *C) +int ED_space_clip_maskedit_poll(bContext *C) { SpaceClip *sc = CTX_wm_space_clip(C); @@ -140,9 +140,9 @@ int ED_space_clip_maskediting_poll(bContext *C) return FALSE; } -int ED_space_clip_maskediting_mask_poll(bContext *C) +int ED_space_clip_maskedit_mask_poll(bContext *C) { - if (ED_space_clip_maskediting_poll(C)) { + if (ED_space_clip_maskedit_poll(C)) { MovieClip *clip = CTX_data_edit_movieclip(C); if (clip) { @@ -282,7 +282,7 @@ void ED_space_clip_mask_aspect(SpaceClip *sc, float *aspx, float *aspy) *aspy *= (float)h; #endif - if(*aspx < *aspy) { + if (*aspx < *aspy) { *aspy= *aspy / *aspx; *aspx= 1.0f; } @@ -329,7 +329,7 @@ void ED_space_clip_aspect_dimension_aware(SpaceClip *sc, float *aspx, float *asp *aspx *= (float)w; *aspy *= (float)h; - if(*aspx < *aspy) { + if (*aspx < *aspy) { *aspy= *aspy / *aspx; *aspx= 1.0f; } @@ -544,7 +544,10 @@ typedef struct SpaceClipDrawContext { struct ImBuf *texture_ibuf; /* image buffer for which texture was created */ int image_width, image_height; /* image width and height for which texture was created */ unsigned last_texture; /* ID of previously used texture, so it'll be restored after clip drawing */ - int framenr; + + /* fields to check if cache is still valid */ + int framenr, start_frame; + short custom_start_frame; } SpaceClipDrawContext; int ED_space_clip_texture_buffer_supported(SpaceClip *sc) @@ -583,6 +586,14 @@ int ED_space_clip_load_movieclip_buffer(SpaceClip *sc, ImBuf *ibuf) need_rebind |= context->texture_ibuf != ibuf; need_rebind |= context->framenr != sc->user.framenr; + if (clip->flag & MCLIP_CUSTOM_START_FRAME) { + need_rebind |= context->custom_start_frame != TRUE; + need_rebind |= context->start_frame != clip->start_frame; + } + else { + need_rebind |= context->custom_start_frame != FALSE; + } + if (need_rebind) { int width = ibuf->x, height = ibuf->y; int need_recreate = 0; @@ -636,6 +647,8 @@ int ED_space_clip_load_movieclip_buffer(SpaceClip *sc, ImBuf *ibuf) context->image_width = ibuf->x; context->image_height = ibuf->y; context->framenr = sc->user.framenr; + context->start_frame = clip->start_frame; + context->custom_start_frame = (clip->flag & MCLIP_CUSTOM_START_FRAME) ? TRUE : FALSE; } else { /* displaying exactly the same image which was loaded t oa texture, @@ -681,7 +694,7 @@ int ED_space_clip_show_trackedit(SpaceClip *sc) int ED_space_clip_show_maskedit(SpaceClip *sc) { if (sc) { - return sc->mode == SC_MODE_MASKEDITING; + return sc->mode == SC_MODE_MASKEDIT; } return FALSE; @@ -691,9 +704,11 @@ void ED_space_clip_set_mask(bContext *C, SpaceClip *sc, Mask *mask) { sc->mask = mask; - if(sc->mask && sc->mask->id.us==0) + if (sc->mask && sc->mask->id.us==0) { sc->clip->id.us = 1; + } - if(C) + if (C) { WM_event_add_notifier(C, NC_MASK|NA_SELECTED, mask); + } } diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c index b24db67cfc2..51157bc2ed4 100644 --- a/source/blender/editors/space_clip/space_clip.c +++ b/source/blender/editors/space_clip/space_clip.c @@ -367,14 +367,14 @@ static void clip_listener(ScrArea *sa, wmNotifier *wmn) } break; case NC_MASK: - switch(wmn->data) { + switch (wmn->data) { case ND_SELECT: case ND_DATA: case ND_DRAW: ED_area_tag_redraw(sa); break; } - switch(wmn->action) { + switch (wmn->action) { case NA_SELECTED: clip_scopes_tag_refresh(sa); ED_area_tag_redraw(sa); @@ -1050,7 +1050,7 @@ static void clip_main_area_init(wmWindowManager *wm, ARegion *ar) UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy); /* own keymap */ - keymap= WM_keymap_find(wm->defaultconf, "Mask Editor", 0, 0); + keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0); WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); keymap = WM_keymap_find(wm->defaultconf, "Clip", SPACE_CLIP, 0); @@ -1100,7 +1100,7 @@ static void clip_main_area_draw(const bContext *C, ARegion *ar) /* Grease Pencil */ clip_draw_grease_pencil((bContext *)C, 1); - if(sc->mode == SC_MODE_MASKEDITING) { + if (sc->mode == SC_MODE_MASKEDIT) { int x, y; int width, height; float zoomx, zoomy, aspx, aspy; @@ -1326,7 +1326,7 @@ static void clip_header_area_listener(ARegion *ar, wmNotifier *wmn) /* for proportional editmode only */ case ND_TOOLSETTINGS: /* TODO - should do this when in mask mode only but no datas available */ - // if(sc->mode == SC_MODE_MASKEDITING) + // if (sc->mode == SC_MODE_MASKEDIT) { ED_region_tag_redraw(ar); } diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 801b6c9001c..b75b3e6aeb3 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -1114,7 +1114,7 @@ static void node_draw_reroute(const bContext *C, ARegion *ar, SpaceNode *UNUSED( glDisable(GL_BLEND); /* outline active and selected emphasis */ - if( node->flag & (NODE_ACTIVE|SELECT) ) { + if (node->flag & (NODE_ACTIVE | SELECT)) { glEnable(GL_BLEND); glEnable( GL_LINE_SMOOTH ); /* using different shades of TH_TEXT_HI for the empasis, like triangle */ @@ -1132,7 +1132,7 @@ static void node_draw_reroute(const bContext *C, ARegion *ar, SpaceNode *UNUSED( /* only draw input socket. as they all are placed on the same position. * highlight also if node itself is selected, since we don't display the node body separately! */ - for(sock= node->inputs.first; sock; sock= sock->next) { + for (sock= node->inputs.first; sock; sock= sock->next) { node_socket_circle_draw(ntree, sock, socket_size, (sock->flag & SELECT) || (node->flag & SELECT)); } @@ -1188,6 +1188,47 @@ static void node_common_set_butfunc(bNodeType *ntype) } /* ****************** BUTTON CALLBACKS FOR SHADER NODES ***************** */ + +static void node_buts_image_user(uiLayout *layout, bContext *C, PointerRNA *imaptr, PointerRNA *iuserptr) +{ + uiLayout *col; + int source; + + if(!imaptr->data) + return; + + col = uiLayoutColumn(layout, 0); + + uiItemR(col, imaptr, "source", 0, "", ICON_NONE); + + source = RNA_enum_get(imaptr, "source"); + + if (source == IMA_SRC_SEQUENCE) { + /* don't use iuser->framenr directly because it may not be updated if auto-refresh is off */ + Scene *scene = CTX_data_scene(C); + ImageUser *iuser = iuserptr->data; + char numstr[32]; + const int framenr = BKE_image_user_frame_get(iuser, CFRA, 0); + BLI_snprintf(numstr, sizeof(numstr), IFACE_("Frame: %d"), framenr); + uiItemL(layout, numstr, ICON_NONE); + } + + if (ELEM(source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) { + col = uiLayoutColumn(layout, 1); + uiItemR(col, iuserptr, "frame_duration", 0, NULL, ICON_NONE); + uiItemR(col, iuserptr, "frame_start", 0, NULL, ICON_NONE); + uiItemR(col, iuserptr, "frame_offset", 0, NULL, ICON_NONE); + uiItemR(col, iuserptr, "use_cyclic", 0, NULL, ICON_NONE); + uiItemR(col, iuserptr, "use_auto_refresh", UI_ITEM_R_ICON_ONLY, NULL, ICON_NONE); + } + + col = uiLayoutColumn(layout, 0); + + if (RNA_enum_get(imaptr, "type") == IMA_TYPE_MULTILAYER) + uiItemR(col, iuserptr, "layer", 0, NULL, ICON_NONE); + +} + static void node_shader_buts_material(uiLayout *layout, bContext *C, PointerRNA *ptr) { bNode *node = ptr->data; @@ -1259,16 +1300,25 @@ static void node_shader_buts_attribute(uiLayout *layout, bContext *UNUSED(C), Po static void node_shader_buts_tex_image(uiLayout *layout, bContext *C, PointerRNA *ptr) { + PointerRNA imaptr = RNA_pointer_get(ptr, "image"); + PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user"); + uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL); uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE); -} + node_buts_image_user(layout, C, &imaptr, &iuserptr); +} static void node_shader_buts_tex_environment(uiLayout *layout, bContext *C, PointerRNA *ptr) { + PointerRNA imaptr = RNA_pointer_get(ptr, "image"); + PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user"); + uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL); uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE); uiItemR(layout, ptr, "projection", 0, "", ICON_NONE); + + node_buts_image_user(layout, C, &imaptr, &iuserptr); } static void node_shader_buts_tex_sky(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) @@ -1391,11 +1441,9 @@ static void node_shader_set_butfunc(bNodeType *ntype) static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiLayout *col; bNode *node = ptr->data; PointerRNA imaptr; PropertyRNA *prop; - int source; uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL); @@ -1405,35 +1453,7 @@ static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA * if (!prop || RNA_property_type(prop) != PROP_POINTER) return; imaptr = RNA_property_pointer_get(ptr, prop); - col = uiLayoutColumn(layout, 0); - - uiItemR(col, &imaptr, "source", 0, NULL, ICON_NONE); - - source = RNA_enum_get(&imaptr, "source"); - - if (source == IMA_SRC_SEQUENCE) { - /* don't use iuser->framenr directly because it may not be updated if auto-refresh is off */ - Scene *scene = CTX_data_scene(C); - ImageUser *iuser = node->storage; - char numstr[32]; - const int framenr = BKE_image_user_frame_get(iuser, CFRA, 0); - BLI_snprintf(numstr, sizeof(numstr), IFACE_("Frame: %d"), framenr); - uiItemL(layout, numstr, ICON_NONE); - } - - if (ELEM(source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) { - col = uiLayoutColumn(layout, 1); - uiItemR(col, ptr, "frame_duration", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "frame_start", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "frame_offset", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "use_cyclic", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "use_auto_refresh", UI_ITEM_R_ICON_ONLY, NULL, ICON_NONE); - } - - col = uiLayoutColumn(layout, 0); - - if (RNA_enum_get(&imaptr, "type") == IMA_TYPE_MULTILAYER) - uiItemR(col, ptr, "layer", 0, NULL, ICON_NONE); + node_buts_image_user(layout, C, &imaptr, ptr); } static void node_composit_buts_renderlayers(uiLayout *layout, bContext *C, PointerRNA *ptr) diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 1b229c78e0f..b4e07546fa9 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -2756,11 +2756,11 @@ static int add_reroute_intersect_check(bNodeLink *link, float mcoords[][2], int float coord_array[LINK_RESOL+1][2]; int i, b; - if(node_link_bezier_points(NULL, NULL, link, coord_array, LINK_RESOL)) { + if (node_link_bezier_points(NULL, NULL, link, coord_array, LINK_RESOL)) { - for(i=0; i<tot-1; i++) - for(b=0; b<LINK_RESOL; b++) - if(isect_line_line_v2(mcoords[i], mcoords[i+1], coord_array[b], coord_array[b+1]) > 0) { + for (i=0; i<tot-1; i++) + for (b=0; b<LINK_RESOL; b++) + if (isect_line_line_v2(mcoords[i], mcoords[i+1], coord_array[b], coord_array[b+1]) > 0) { result[0] = (mcoords[i][0]+mcoords[i+1][0])/2.0f; result[1] = (mcoords[i][1]+mcoords[i+1][1])/2.0f; return 1; @@ -2783,18 +2783,18 @@ static int add_reroute_exec(bContext *C, wmOperator *op) UI_view2d_region_to_view(&ar->v2d, (short)loc[0], (short)loc[1], &mcoords[i][0], &mcoords[i][1]); i++; - if(i>= 256) break; + if (i>= 256) break; } RNA_END; - if(i>1) { + if (i>1) { bNodeLink *link; float insertPoint[2]; ED_preview_kill_jobs(C); - for(link= snode->edittree->links.first; link; link=link->next) { - if(add_reroute_intersect_check(link, mcoords, i, insertPoint)) { + for (link= snode->edittree->links.first; link; link=link->next) { + if (add_reroute_intersect_check(link, mcoords, i, insertPoint)) { bNodeTemplate ntemp; bNode *rerouteNode; diff --git a/source/blender/editors/space_node/node_select.c b/source/blender/editors/space_node/node_select.c index 0a3678ca901..e7be750928d 100644 --- a/source/blender/editors/space_node/node_select.c +++ b/source/blender/editors/space_node/node_select.c @@ -76,7 +76,7 @@ static bNode *node_under_mouse_tweak(bNodeTree *ntree, int mx, int my) { bNode *node; - for(node=ntree->nodes.last; node; node=node->prev) { + for (node=ntree->nodes.last; node; node=node->prev) { if (node->typeinfo->tweak_area_func) { if (node->typeinfo->tweak_area_func(node, mx, my)) return node; diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c index a752a7d71ae..e5f7b8fd76d 100644 --- a/source/blender/editors/space_outliner/outliner_edit.c +++ b/source/blender/editors/space_outliner/outliner_edit.c @@ -1503,7 +1503,12 @@ static int parent_drop_invoke(bContext *C, wmOperator *op, wmEvent *event) scene = (Scene *)outliner_search_back(soops, te_found, ID_SCE); if (scene == NULL) { - return OPERATOR_CANCELLED; + /* currently outlier organized in a way, that if there's no parent scene + * element for object it means that all displayed objects belong to + * active scene and parenting them is allowed (sergey) + */ + + scene = CTX_data_scene(C); } if ((par->type != OB_ARMATURE) && (par->type != OB_CURVE) && (par->type != OB_LATTICE)) { diff --git a/source/blender/editors/space_outliner/space_outliner.c b/source/blender/editors/space_outliner/space_outliner.c index 4d45be561c6..c78be8bd223 100644 --- a/source/blender/editors/space_outliner/space_outliner.c +++ b/source/blender/editors/space_outliner/space_outliner.c @@ -98,7 +98,16 @@ static int outliner_parent_drop_poll(bContext *C, wmDrag *drag, wmEvent *event) if (te_valid) { /* check that parent/child are both in the same scene */ Scene *scene = (Scene *)outliner_search_back(soops, te_valid, ID_SCE); - if (BKE_scene_base_find(scene, (Object *)id)) { + + if (!scene) { + /* currently outlier organized in a way, that if there's no parent scene + * element for object it means that all displayed objects belong to + * active scene and parenting them is allowed (sergey) + */ + return 1; + } + + if (scene && BKE_scene_base_find(scene, (Object *)id)) { return 1; } } diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 006704e26bf..7a8c2cde074 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -1728,6 +1728,9 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int case TFM_CURVE_SHRINKFATTEN: initCurveShrinkFatten(t); break; + case TFM_MASK_SHRINKFATTEN: + initMaskShrinkFatten(t); + break; case TFM_TRACKBALL: initTrackball(t); break; @@ -3927,8 +3930,77 @@ int CurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) continue; if (td->val) { - // *td->val= ratio; *td->val= td->ival*ratio; + /* apply PET */ + *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival); + if (*td->val <= 0.0f) *td->val = 0.001f; + } + } + + recalcData(t); + + ED_area_headerprint(t->sa, str); + + return 1; +} + + +void initMaskShrinkFatten(TransInfo *t) +{ + t->mode = TFM_MASK_SHRINKFATTEN; + t->transform = MaskShrinkFatten; + + initMouseInputMode(t, &t->mouse, INPUT_SPRING); + + t->idx_max = 0; + t->num.idx_max = 0; + t->snap[0] = 0.0f; + t->snap[1] = 0.1f; + t->snap[2] = t->snap[1] * 0.1f; + + t->num.increment = t->snap[1]; + + t->flag |= T_NO_ZERO; + t->num.flag |= NUM_NO_ZERO; + + t->flag |= T_NO_CONSTRAINT; +} + +int MaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) +{ + TransData *td = t->data; + float ratio; + int i; + char str[50]; + + ratio = t->values[0]; + + snapGrid(t, &ratio); + + applyNumInput(&t->num, &ratio); + + /* header print for NumInput */ + if (hasNumInput(&t->num)) { + char c[20]; + + outputNumInput(&(t->num), c); + sprintf(str, "Shrink/Fatten: %s", c); + } + else { + sprintf(str, "Shrink/Fatten: %3f", ratio); + } + + for (i = 0 ; i < t->total; i++, td++) { + if (td->flag & TD_NOACTION) + break; + + if (td->flag & TD_SKIP) + continue; + + if (td->val) { + *td->val = td->ival * ratio; + /* apply PET */ + *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival); if (*td->val <= 0.0f) *td->val = 0.001f; } } diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 59688f1436e..32a4d4ab1a3 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -494,6 +494,9 @@ int Tilt(TransInfo *t, const int mval[2]); void initCurveShrinkFatten(TransInfo *t); int CurveShrinkFatten(TransInfo *t, const int mval[2]); +void initMaskShrinkFatten(TransInfo *t); +int MaskShrinkFatten(TransInfo *t, const int mval[2]); + void initTrackball(TransInfo *t); int Trackball(TransInfo *t, const int mval[2]); diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 8a7caeb3060..c1d2cf2c2a8 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -5918,8 +5918,16 @@ static void MaskPointToTransData(SpaceClip *sc, MaskSplinePoint *point, memset(td->axismtx, 0, sizeof(td->axismtx)); td->axismtx[2][2] = 1.0f; - td->ext= NULL; - td->val= NULL; + td->ext = NULL; + + if (i == 1) { + /* scaling weights */ + td->val = &bezt->weight; + td->ival = *td->val; + } + else { + td->val = NULL; + } if (is_sel_any) { td->flag |= TD_SELECTED; @@ -5981,6 +5989,11 @@ static void createTransMaskingData(bContext *C, TransInfo *t) int count = 0, countsel = 0; int propmode = t->flag & T_PROP_EDIT; + t->total = 0; + + if (!mask) + return; + /* count */ for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { MaskSpline *spline = masklay->splines.first; @@ -6066,7 +6079,7 @@ void flushTransMasking(TransInfo *t) invy = 1.0f/aspy; /* flush to 2d vector from internally used 3d vector */ - for(a=0, td = t->data2d, tdm = t->customData; a<t->total; a++, td++, tdm++) { + for (a=0, td = t->data2d, tdm = t->customData; a<t->total; a++, td++, tdm++) { td->loc2d[0]= td->loc[0]*invx; td->loc2d[1]= td->loc[1]*invy; diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index 870f8c742e1..4ea89de9070 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -135,6 +135,7 @@ EnumPropertyItem transform_mode_types[] = {TFM_BONESIZE, "BONE_SIZE", 0, "Bonesize", ""}, {TFM_BONE_ENVELOPE, "BONE_ENVELOPE", 0, "Bone_Envelope", ""}, {TFM_CURVE_SHRINKFATTEN, "CURVE_SHRINKFATTEN", 0, "Curve_Shrinkfatten", ""}, + {TFM_MASK_SHRINKFATTEN, "MASK_SHRINKFATTEN", 0, "Mask_Shrinkfatten", ""}, {TFM_BONE_ROLL, "BONE_ROLL", 0, "Bone_Roll", ""}, {TFM_TIME_TRANSLATE, "TIME_TRANSLATE", 0, "Time_Translate", ""}, {TFM_TIME_SLIDE, "TIME_SLIDE", 0, "Time_Slide", ""}, diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c index 4c6ead3d3f4..75ed7d7eb19 100644 --- a/source/blender/gpu/intern/gpu_buffers.c +++ b/source/blender/gpu/intern/gpu_buffers.c @@ -1151,7 +1151,7 @@ void GPU_buffer_unbind(void) glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); } } - GLStates &= !(GPU_BUFFER_VERTEX_STATE | GPU_BUFFER_NORMAL_STATE | + GLStates &= ~(GPU_BUFFER_VERTEX_STATE | GPU_BUFFER_NORMAL_STATE | GPU_BUFFER_TEXCOORD_STATE | GPU_BUFFER_COLOR_STATE | GPU_BUFFER_ELEMENT_STATE); @@ -1191,7 +1191,7 @@ void GPU_color_switch(int mode) else { if (GLStates & GPU_BUFFER_COLOR_STATE) glDisableClientState(GL_COLOR_ARRAY); - GLStates &= (!GPU_BUFFER_COLOR_STATE); + GLStates &= ~GPU_BUFFER_COLOR_STATE; } } diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 31008ff8685..78b5219206d 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -772,7 +772,7 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la GPU_link(mat, "mtex_value_invert", shadfac, &shadfac); GPU_link(mat, "mix_mult", shadfac, rgb, GPU_uniform(lamp->shadow_color), &rgb); GPU_link(mat, "mtex_value_invert", shadfac, &shadfac); - add_to_diffuse(mat, ma, shi, is, rgb, &shr->diff); + add_to_diffuse(mat, ma, shi, is, rgb, &shr->diff); } } diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index 65c0bcb3c63..b9bd7e961f8 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -1105,7 +1105,7 @@ void mtex_normal(vec3 texco, sampler2D ima, out vec3 normal) // It needs to be done because in Blender // the normal used points inward. // Should this ever change this negate must be removed. - vec4 color = texture2D(ima, texco.xy); + vec4 color = texture2D(ima, texco.xy); normal = 2.0*(vec3(-color.r, color.g, color.b) - vec3(-0.5, 0.5, 0.5)); } @@ -1190,7 +1190,7 @@ void mtex_bump_init_viewspace( vec3 surf_pos, vec3 surf_norm, } void mtex_bump_tap3( vec3 texco, sampler2D ima, float hScale, - out float dBs, out float dBt ) + out float dBs, out float dBt ) { vec2 STll = texco.xy; vec2 STlr = texco.xy + dFdx(texco.xy) ; @@ -1945,22 +1945,23 @@ void shade_alpha_obcolor(vec4 col, vec4 obcol, out vec4 outcol) float fresnel_dielectric(vec3 Incoming, vec3 Normal, float eta) { - /* compute fresnel reflectance without explicitly computing - the refracted direction */ - float c = abs(dot(Incoming, Normal)); - float g = eta * eta - 1.0 + c * c; - float result; - - if(g > 0.0) { - g = sqrt(g); - float A =(g - c)/(g + c); - float B =(c *(g + c)- 1.0)/(c *(g - c)+ 1.0); - result = 0.5 * A * A *(1.0 + B * B); - } - else - result = 1.0; /* TIR (no refracted component) */ + /* compute fresnel reflectance without explicitly computing + * the refracted direction */ + float c = abs(dot(Incoming, Normal)); + float g = eta * eta - 1.0 + c * c; + float result; + + if(g > 0.0) { + g = sqrt(g); + float A =(g - c)/(g + c); + float B =(c *(g + c)- 1.0)/(c *(g - c)+ 1.0); + result = 0.5 * A * A *(1.0 + B * B); + } + else { + result = 1.0; /* TIR (no refracted component) */ + } - return result; + return result; } float hypot(float x, float y) @@ -2135,13 +2136,13 @@ void node_tex_environment_empty(vec3 co, out vec4 color) void node_tex_image(vec3 co, sampler2D ima, out vec4 color, out float alpha) { color = texture2D(ima, co.xy); - alpha = color.a; + alpha = color.a; } void node_tex_image_empty(vec3 co, out vec4 color, out float alpha) { color = vec4(0.0); - alpha = 0.0; + alpha = 0.0; } void node_tex_magic(vec3 p, float scale, float distortion, out vec4 color, out float fac) diff --git a/source/blender/imbuf/intern/dds/ColorBlock.cpp b/source/blender/imbuf/intern/dds/ColorBlock.cpp index 42bec5874ca..0b9f5c163fb 100644 --- a/source/blender/imbuf/intern/dds/ColorBlock.cpp +++ b/source/blender/imbuf/intern/dds/ColorBlock.cpp @@ -176,7 +176,7 @@ bool ColorBlock::isSingleColorNoAlpha() const int i; for (i = 0; i < 16; i++) { - if (m_color[i].a != 0) c = m_color[i]; + if (m_color[i].a != 0) c = m_color[i]; } Color32 mask(0xFF, 0xFF, 0xFF, 0x00); diff --git a/source/blender/makesdna/DNA_mask_types.h b/source/blender/makesdna/DNA_mask_types.h index 28fc9466613..c036369c692 100644 --- a/source/blender/makesdna/DNA_mask_types.h +++ b/source/blender/makesdna/DNA_mask_types.h @@ -97,6 +97,15 @@ typedef struct MaskLayerShape { char pad[7]; } MaskLayerShape; +/* cast to this for convenience, not saved */ +#define MASK_OBJECT_SHAPE_ELEM_SIZE 8 /* 3x 2D points + weight + radius == 8 */ + +# +# +typedef struct MaskLayerShapeElem { + float value[MASK_OBJECT_SHAPE_ELEM_SIZE]; +} MaskLayerShapeElem; + typedef struct MaskLayer { struct MaskLayer *next, *prev; @@ -129,8 +138,6 @@ typedef struct MaskLayer { #define MASK_SPLINE_INTERP_LINEAR 1 #define MASK_SPLINE_INTERP_EASE 2 -#define MASK_OBJECT_SHAPE_ELEM_SIZE 8 /* 3x 2D points + weight + radius == 8 */ - /* ob->restrictflag */ #define MASK_RESTRICT_VIEW 1 #define MASK_RESTRICT_SELECT 2 diff --git a/source/blender/makesdna/DNA_movieclip_types.h b/source/blender/makesdna/DNA_movieclip_types.h index f073a1957dc..81d532fd247 100644 --- a/source/blender/makesdna/DNA_movieclip_types.h +++ b/source/blender/makesdna/DNA_movieclip_types.h @@ -85,6 +85,8 @@ typedef struct MovieClip { int flag; int len; /* length of movie */ + + int start_frame, pad; } MovieClip; typedef struct MovieClipScopes { @@ -121,6 +123,7 @@ typedef struct MovieClipScopes { /* MovieClip->flag */ #define MCLIP_USE_PROXY (1<<0) #define MCLIP_USE_PROXY_CUSTOM_DIR (1<<1) +#define MCLIP_CUSTOM_START_FRAME (1<<2) #define MCLIP_TIMECODE_FLAGS (MCLIP_USE_PROXY|MCLIP_USE_PROXY_CUSTOM_DIR) diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 39f3fda1157..38622569590 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -563,6 +563,7 @@ typedef struct NodeTexSky { typedef struct NodeTexImage { NodeTexBase base; + ImageUser iuser; int color_space, pad; } NodeTexImage; @@ -572,6 +573,7 @@ typedef struct NodeTexChecker { typedef struct NodeTexEnvironment { NodeTexBase base; + ImageUser iuser; int color_space, projection; } NodeTexEnvironment; diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index b1e64641985..8935268cb91 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -1048,7 +1048,7 @@ typedef enum eSpaceClip_Mode { SC_MODE_TRACKING = 0, SC_MODE_RECONSTRUCTION, SC_MODE_DISTORTION, - SC_MODE_MASKEDITING, + SC_MODE_MASKEDIT, } eSpaceClip_Mode; /* SpaceClip->view */ diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index e7f9977d040..82c0757456d 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -209,6 +209,10 @@ if(WITH_FFTW3) add_definitions(-DWITH_FFTW3) endif() +if(WITH_MOD_SMOKE) + add_definitions(-DWITH_SMOKE) +endif() + if(WITH_MOD_OCEANSIM) add_definitions(-DWITH_OCEANSIM) endif() @@ -253,6 +257,7 @@ blender_include_dirs( ../../../../intern/cycles/blender ../../../../intern/guardedalloc ../../../../intern/memutil + ../../../../intern/smoke/extern ) blender_include_dirs_sys( diff --git a/source/blender/makesrna/intern/SConscript b/source/blender/makesrna/intern/SConscript index 99fab18b4bf..d26de50fae0 100644 --- a/source/blender/makesrna/intern/SConscript +++ b/source/blender/makesrna/intern/SConscript @@ -35,7 +35,11 @@ incs += ' ../../windowmanager ../../editors/include ../../blenfont' incs += ' ../../render/extern/include ../../bmesh' incs += ' #/intern/audaspace/intern #/intern/cycles/blender' incs += ' #/extern/glew/include ' +incs += ' #/intern/smoke/extern' +if env['WITH_BF_SMOKE']: + defs.append('WITH_SMOKE') + if env['WITH_BF_OPENEXR']: defs.append('WITH_OPENEXR') diff --git a/source/blender/makesrna/intern/rna_mask.c b/source/blender/makesrna/intern/rna_mask.c index c356cae81af..51d370d5a88 100644 --- a/source/blender/makesrna/intern/rna_mask.c +++ b/source/blender/makesrna/intern/rna_mask.c @@ -324,7 +324,7 @@ static void rna_def_maskParent(BlenderRNA *brna) {0, NULL, 0, NULL, NULL}}; srna = RNA_def_struct(brna, "MaskParent", NULL); - RNA_def_struct_ui_text(srna, "Mask Parent", "Parenting settings for maskign element"); + RNA_def_struct_ui_text(srna, "Mask Parent", "Parenting settings for masking element"); /* use_parent */ prop = RNA_def_property(srna, "use_parent", PROP_BOOLEAN, PROP_NONE); @@ -497,7 +497,7 @@ static void rna_def_maskSpline(BlenderRNA *brna) rna_def_maskSplinePoint(brna); srna = RNA_def_struct(brna, "MaskSpline", NULL); - RNA_def_struct_ui_text(srna, "Mask spline", "Single spline used for defining mash shape"); + RNA_def_struct_ui_text(srna, "Mask spline", "Single spline used for defining mask shape"); /* weight interpolation */ prop = RNA_def_property(srna, "weight_interpolation", PROP_ENUM, PROP_NONE); @@ -583,7 +583,7 @@ static void rna_def_mask_layer(BlenderRNA *brna) prop = RNA_def_property(srna, "invert", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "blend_flag", MASK_BLENDFLAG_INVERT); - RNA_def_property_ui_text(prop, "Restrict View", "Restrict visibility in the viewport"); + RNA_def_property_ui_text(prop, "Restrict View", "Invert the mask black/white"); RNA_def_property_update(prop, NC_MASK | NA_EDITED, NULL); } diff --git a/source/blender/makesrna/intern/rna_movieclip.c b/source/blender/makesrna/intern/rna_movieclip.c index 13c11f6402f..26d967dfb42 100644 --- a/source/blender/makesrna/intern/rna_movieclip.c +++ b/source/blender/makesrna/intern/rna_movieclip.c @@ -285,6 +285,19 @@ static void rna_def_movieclip(BlenderRNA *brna) RNA_def_property_struct_type(prop, "GreasePencil"); RNA_def_property_ui_text(prop, "Grease Pencil", "Grease pencil data for this movie clip"); RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL); + + /* use custom offset */ + prop = RNA_def_property(srna, "use_custom_start_frame", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", MCLIP_CUSTOM_START_FRAME); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Custom Start Frame", "Use custom first frame offset instead of automatic frame number"); + RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_MovieClip_reload_update"); + + /* frame offset */ + prop = RNA_def_property(srna, "start_frame", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "start_frame"); + RNA_def_property_ui_text(prop, "Start Frame", "Number of frame from sequence or movie displaying at scene frame #1"); + RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_MovieClip_reload_update"); } void RNA_def_movieclip(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 1f574ba2473..ae489790825 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -1429,6 +1429,12 @@ static void def_sh_tex_environment(StructRNA *srna) RNA_def_property_ui_text(prop, "Projection", "Projection of the input image"); RNA_def_property_update(prop, 0, "rna_Node_update"); + prop = RNA_def_property(srna, "image_user", PROP_POINTER, PROP_NONE); + RNA_def_property_flag(prop, PROP_NEVER_NULL); + RNA_def_property_pointer_sdna(prop, NULL, "iuser"); + RNA_def_property_ui_text(prop, "Image User", + "Parameters defining which layer, pass and frame of the image is displayed"); + RNA_def_property_update(prop, 0, "rna_Node_update"); } static void def_sh_tex_image(StructRNA *srna) @@ -1458,6 +1464,13 @@ static void def_sh_tex_image(StructRNA *srna) RNA_def_property_enum_items(prop, prop_color_space_items); RNA_def_property_ui_text(prop, "Color Space", "Image file color space"); RNA_def_property_update(prop, 0, "rna_Node_update"); + + prop = RNA_def_property(srna, "image_user", PROP_POINTER, PROP_NONE); + RNA_def_property_flag(prop, PROP_NEVER_NULL); + RNA_def_property_pointer_sdna(prop, NULL, "iuser"); + RNA_def_property_ui_text(prop, "Image User", + "Parameters defining which layer, pass and frame of the image is displayed"); + RNA_def_property_update(prop, 0, "rna_Node_update"); } static void def_sh_tex_gradient(StructRNA *srna) @@ -1830,29 +1843,10 @@ static void def_cmp_levels(StructRNA *srna) RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); } -static void def_cmp_image(StructRNA *srna) +static void def_node_image_user(StructRNA *srna) { PropertyRNA *prop; - -#if 0 - static EnumPropertyItem type_items[] = { - {IMA_SRC_FILE, "IMAGE", 0, "Image", ""}, - {IMA_SRC_MOVIE, "MOVIE", "Movie", ""}, - {IMA_SRC_SEQUENCE, "SEQUENCE", "Sequence", ""}, - {IMA_SRC_GENERATED, "GENERATED", "Generated", ""}, - {0, NULL, 0, NULL, NULL} - }; -#endif - - prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, NULL, "id"); - RNA_def_property_struct_type(prop, "Image"); - RNA_def_property_flag(prop, PROP_EDITABLE); - RNA_def_property_ui_text(prop, "Image", ""); - RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); - - RNA_def_struct_sdna_from(srna, "ImageUser", "storage"); - + prop = RNA_def_property(srna, "frame_duration", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "frames"); RNA_def_property_range(prop, 0, MAXFRAMEF); @@ -1893,6 +1887,31 @@ static void def_cmp_image(StructRNA *srna) RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_image_layer_update"); } +static void def_cmp_image(StructRNA *srna) +{ + PropertyRNA *prop; + +#if 0 + static EnumPropertyItem type_items[] = { + {IMA_SRC_FILE, "IMAGE", 0, "Image", ""}, + {IMA_SRC_MOVIE, "MOVIE", "Movie", ""}, + {IMA_SRC_SEQUENCE, "SEQUENCE", "Sequence", ""}, + {IMA_SRC_GENERATED, "GENERATED", "Generated", ""}, + {0, NULL, 0, NULL, NULL} + }; +#endif + + prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "id"); + RNA_def_property_struct_type(prop, "Image"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Image", ""); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); + + RNA_def_struct_sdna_from(srna, "ImageUser", "storage"); + def_node_image_user(srna); +} + static void def_cmp_render_layers(StructRNA *srna) { PropertyRNA *prop; @@ -3515,7 +3534,7 @@ static void def_tex_image(StructRNA *srna) RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Image", ""); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); - + /* is this supposed to be exposed? not sure.. */ #if 0 prop = RNA_def_property(srna, "settings", PROP_POINTER, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_sequencer_api.c b/source/blender/makesrna/intern/rna_sequencer_api.c index bdbd153b1e2..2fb882d96a1 100644 --- a/source/blender/makesrna/intern/rna_sequencer_api.c +++ b/source/blender/makesrna/intern/rna_sequencer_api.c @@ -327,7 +327,12 @@ static void rna_SequenceElements_pop(ID *id, Sequence *seq, ReportList *reports, return; } - if (seq->len <= index) { + /* python style negative indexing */ + if (index < 0) { + index += seq->len; + } + + if (seq->len <= index || index < 0) { BKE_report(reports, RPT_ERROR, "SequenceElements.pop: index out of range"); return; } @@ -335,6 +340,7 @@ static void rna_SequenceElements_pop(ID *id, Sequence *seq, ReportList *reports, new_seq = MEM_callocN(sizeof(StripElem) * (seq->len - 1), "SequenceElements_pop"); seq->len--; + /* TODO - simply use 2 memcpy calls */ for (i = 0, se = seq->strip->stripdata; i < seq->len; i++, se++) { if (i == index) se++; @@ -394,7 +400,7 @@ void RNA_api_sequence_elements(BlenderRNA *brna, PropertyRNA *cprop) func = RNA_def_function(srna, "pop", "rna_SequenceElements_pop"); RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID); RNA_def_function_ui_description(func, "Pop an image off the collection"); - parm = RNA_def_int(func, "index", 0, 0, INT_MAX, "", "Index of image to remove", 0, INT_MAX); + parm = RNA_def_int(func, "index", -1, INT_MIN, INT_MAX, "", "Index of image to remove", INT_MIN, INT_MAX); RNA_def_property_flag(parm, PROP_REQUIRED); } diff --git a/source/blender/makesrna/intern/rna_smoke.c b/source/blender/makesrna/intern/rna_smoke.c index 19925546de3..c0efff2d179 100644 --- a/source/blender/makesrna/intern/rna_smoke.c +++ b/source/blender/makesrna/intern/rna_smoke.c @@ -51,6 +51,8 @@ #include "BKE_depsgraph.h" #include "BKE_particle.h" +#include "smoke_API.h" + static void rna_Smoke_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { @@ -111,6 +113,35 @@ static char *rna_SmokeCollSettings_path(PointerRNA *ptr) return BLI_sprintfN("modifiers[\"%s\"].coll_settings", md->name); } +static int rna_SmokeModifier_density_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION]) +{ + SmokeDomainSettings *settings = (SmokeDomainSettings *)ptr->data; + + if (settings->fluid) + { + float *density = smoke_get_density(settings->fluid); + unsigned int size = settings->res[0] * settings->res[1] * settings->res[2]; + + if(density) + length[0] = size; + else + length[0] = 0; + } + else + length[0] = 0; // No smoke domain created yet + + return length[0]; +} + +static void rna_SmokeModifier_density_get(PointerRNA *ptr, float *values) +{ + SmokeDomainSettings *settings = (SmokeDomainSettings *)ptr->data; + float *density = smoke_get_density(settings->fluid); + unsigned int size = settings->res[0] * settings->res[1] * settings->res[2]; + + memcpy(values, density, size * sizeof(float)); +} + #else static void rna_def_smoke_domain_settings(BlenderRNA *brna) @@ -282,6 +313,33 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Vorticity", "Amount of turbulence/rotation in fluid"); RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_Smoke_reset"); + prop = RNA_def_property(srna, "density", PROP_FLOAT, PROP_NONE); + RNA_def_property_array(prop, 32); + RNA_def_property_flag(prop, PROP_DYNAMIC); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_dynamic_array_funcs(prop, "rna_SmokeModifier_density_get_length"); + RNA_def_property_float_funcs(prop, "rna_SmokeModifier_density_get", NULL, NULL); + RNA_def_property_ui_text(prop, "Density", "Smoke density"); + + prop = RNA_def_property(srna, "cell_size", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "dx"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "dx", "Cell Size"); + + prop = RNA_def_property(srna, "start_point", PROP_FLOAT, PROP_XYZ); + RNA_def_property_float_sdna(prop, NULL, "p0"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "p0", "Start point"); + + prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "scale"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "scale", "Domain scale factor"); + + prop = RNA_def_property(srna, "domain_resolution", PROP_INT, PROP_XYZ); + RNA_def_property_int_sdna(prop, NULL, "res"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "res", "Smoke Grid Resolution"); } static void rna_def_smoke_flow_settings(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 5e1a17b8e1d..a57c39967fc 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -2983,7 +2983,7 @@ static void rna_def_space_clip(BlenderRNA *brna) {SC_MODE_RECONSTRUCTION, "RECONSTRUCTION", ICON_SNAP_FACE, "Reconstruction", "Show tracking/reconstruction tools"}, {SC_MODE_DISTORTION, "DISTORTION", ICON_GRID, "Distortion", "Show distortion tools"}, - {SC_MODE_MASKEDITING, "MASKEDITING", ICON_MOD_MASK, "Mask editing", "Show mask editing tools"}, + {SC_MODE_MASKEDIT, "MASKEDIT", ICON_MOD_MASK, "Mask editing", "Show mask editing tools"}, {0, NULL, 0, NULL, NULL} }; diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index ec215120f0c..84723e95e80 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -1992,27 +1992,27 @@ static void rna_def_userdef_theme_space_nla(BlenderRNA *brna) prop = RNA_def_property(srna, "meta_strips", PROP_FLOAT, PROP_COLOR_GAMMA); RNA_def_property_float_sdna(prop, NULL, "nla_meta"); RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "Meta Strips", "Meta Strip - Unselected. For grouping related strips"); + RNA_def_property_ui_text(prop, "Meta Strips", "Meta Strip - Unselected (for grouping related strips)"); RNA_def_property_update(prop, 0, "rna_userdef_update"); prop = RNA_def_property(srna, "meta_strips_selected", PROP_FLOAT, PROP_COLOR_GAMMA); RNA_def_property_float_sdna(prop, NULL, "nla_meta_sel"); RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "Meta Strips Selected", "Meta Strip - Selected. For grouping related strips"); + RNA_def_property_ui_text(prop, "Meta Strips Selected", "Meta Strip - Selected (for grouping related strips)"); RNA_def_property_update(prop, 0, "rna_userdef_update"); prop = RNA_def_property(srna, "sound_strips", PROP_FLOAT, PROP_COLOR_GAMMA); RNA_def_property_float_sdna(prop, NULL, "nla_sound"); RNA_def_property_array(prop, 3); RNA_def_property_ui_text(prop, "Sound Strips", - "Sound Strip - Unselected. For timing speaker sounds"); + "Sound Strip - Unselected (for timing speaker sounds)"); RNA_def_property_update(prop, 0, "rna_userdef_update"); prop = RNA_def_property(srna, "sound_strips_selected", PROP_FLOAT, PROP_COLOR_GAMMA); RNA_def_property_float_sdna(prop, NULL, "nla_sound_sel"); RNA_def_property_array(prop, 3); RNA_def_property_ui_text(prop, "Sound Strips Selected", - "Sound Strip - Selected. For timing speaker sounds"); + "Sound Strip - Selected (for timing speaker sounds)"); RNA_def_property_update(prop, 0, "rna_userdef_update"); prop = RNA_def_property(srna, "tweak", PROP_FLOAT, PROP_COLOR_GAMMA); @@ -2984,7 +2984,7 @@ static void rna_def_userdef_system(BlenderRNA *brna) {10, "CATALAN", 0, "Catalan (Català )", "ca_AD"}, {16, "CROATIAN", 0, "Croatian (Hrvatski)", "hr_HR"}, {11, "CZECH", 0, "Czech (ÄŒeský)", "cs_CZ"}, -/* { 3, "DUTCH", 0, "Dutch (Nederlandse taal)", "nl_NL"}, */ /* XXX No po's yet. */ + { 3, "DUTCH", 0, "Dutch (Nederlandse taal)", "nl_NL"}, { 6, "FINNISH", 0, "Finnish (Suomi)", "fi_FI"}, { 5, "GERMAN", 0, "German (Deutsch)", "de_DE"}, {23, "GREEK", 0, "Greek (Ελληνικά)", "el_GR"}, diff --git a/source/blender/modifiers/intern/MOD_edgesplit.c b/source/blender/modifiers/intern/MOD_edgesplit.c index eb3334d31ce..1b3e3c16486 100644 --- a/source/blender/modifiers/intern/MOD_edgesplit.c +++ b/source/blender/modifiers/intern/MOD_edgesplit.c @@ -79,7 +79,11 @@ static DerivedMesh *doEdgeSplit(DerivedMesh *dm, EdgeSplitModifierData *emd, Obj if ((l1 = e->l) && (l2 = e->l->radial_next) != l1) { - if (dot_v3v3(l1->f->no, l2->f->no) < threshold) { + if (/* 3+ faces on thsi edge, always split */ + UNLIKELY(l1 != l2->radial_next) || + /* 2 face edge - check angle*/ + (dot_v3v3(l1->f->no, l2->f->no) < threshold)) + { BMO_elem_flag_enable(bm, e, EDGE_MARK); } } diff --git a/source/blender/modifiers/intern/MOD_explode.c b/source/blender/modifiers/intern/MOD_explode.c index b69f167f876..b9593353288 100644 --- a/source/blender/modifiers/intern/MOD_explode.c +++ b/source/blender/modifiers/intern/MOD_explode.c @@ -205,12 +205,12 @@ static MFace *get_dface(DerivedMesh *dm, DerivedMesh *split, int cur, int i, MFa return df; } -#define SET_VERTS(a, b, c, d) \ - v[0] = mf->v##a; uv[0] = a - 1; \ - v[1] = mf->v##b; uv[1] = b - 1; \ - v[2] = mf->v##c; uv[2] = c - 1; \ - v[3] = mf->v##d; uv[3] = d - 1; \ - (void)0 +#define SET_VERTS(a, b, c, d) { \ + v[0] = mf->v##a; uv[0] = a - 1; \ + v[1] = mf->v##b; uv[1] = b - 1; \ + v[2] = mf->v##c; uv[2] = c - 1; \ + v[3] = mf->v##d; uv[3] = d - 1; \ + } (void)0 #define GET_ES(v1, v2) edgecut_get(eh, v1, v2) #define INT_UV(uvf, c0, c1) interp_v2_v2v2(uvf, mf->uv[c0], mf->uv[c1], 0.5f) diff --git a/source/blender/modifiers/intern/MOD_remesh.c b/source/blender/modifiers/intern/MOD_remesh.c index 57966b5824b..2b55471be3d 100644 --- a/source/blender/modifiers/intern/MOD_remesh.c +++ b/source/blender/modifiers/intern/MOD_remesh.c @@ -87,6 +87,7 @@ static void init_dualcon_mesh(DualConInput *mesh, DerivedMesh *dm) mesh->face_stride = sizeof(MFace); mesh->totface = dm->getNumTessFaces(dm); + INIT_MINMAX(mesh->min, mesh->max); dm->getMinMax(dm, mesh->min, mesh->max); } diff --git a/source/blender/modifiers/intern/MOD_smooth.c b/source/blender/modifiers/intern/MOD_smooth.c index 99a5dcb5ef5..1313f5aa3ef 100644 --- a/source/blender/modifiers/intern/MOD_smooth.c +++ b/source/blender/modifiers/intern/MOD_smooth.c @@ -244,6 +244,7 @@ ModifierTypeInfo modifierType_Smooth = { /* structSize */ sizeof(SmoothModifierData), /* type */ eModifierTypeType_OnlyDeform, /* flags */ eModifierTypeFlag_AcceptsMesh | + eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_SupportsEditmode, /* copyData */ copyData, diff --git a/source/blender/modifiers/intern/MOD_solidify.c b/source/blender/modifiers/intern/MOD_solidify.c index 745cf1304bd..6f8e65a6e8e 100644 --- a/source/blender/modifiers/intern/MOD_solidify.c +++ b/source/blender/modifiers/intern/MOD_solidify.c @@ -435,7 +435,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, if (ofs_orig != 0.0f) { scalar_short = scalar_short_vgroup = ofs_orig / 32767.0f; - mv = mvert + (((ofs_new >= ofs_orig) == do_flip) ? 0 : numVerts); /* as above but swapped, intentional use 'ofs_new' */ + mv = mvert + (((ofs_new >= ofs_orig) == do_flip) ? 0 : numVerts); /* as above but swapped */ dv = dvert; for (i = 0; i < numVerts; i++, mv++) { if (dv) { diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c index 9f458678ae0..3d1b656fc4e 100644 --- a/source/blender/nodes/intern/node_common.c +++ b/source/blender/nodes/intern/node_common.c @@ -857,7 +857,7 @@ ListBase node_reroute_internal_connect(bNodeTree *ntree, bNode *node) ret.first = ret.last = NULL; /* Security check! */ - if(!ntree) + if (!ntree) return ret; link = MEM_callocN(sizeof(bNodeLink), "internal node link"); 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 e5dc64aca05..e3300c89a01 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c @@ -46,6 +46,10 @@ static void node_shader_init_tex_environment(bNodeTree *UNUSED(ntree), bNode* no default_color_mapping(&tex->base.color_mapping); tex->color_space = SHD_COLORSPACE_COLOR; tex->projection = SHD_PROJ_EQUIRECTANGULAR; + tex->iuser.frames= 1; + tex->iuser.sfra= 1; + tex->iuser.fie_ima= 2; + tex->iuser.ok= 1; node->storage = tex; } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_image.c b/source/blender/nodes/shader/nodes/node_shader_tex_image.c index db1c9081471..d4d43c1430c 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_image.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_image.c @@ -46,6 +46,10 @@ static void node_shader_init_tex_image(bNodeTree *UNUSED(ntree), bNode* node, bN default_tex_mapping(&tex->base.tex_mapping); default_color_mapping(&tex->base.color_mapping); tex->color_space = SHD_COLORSPACE_COLOR; + tex->iuser.frames= 1; + tex->iuser.sfra= 1; + tex->iuser.fie_ima= 2; + tex->iuser.ok= 1; node->storage = tex; } diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index 6ca4ad15859..053dac71fe6 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -2099,7 +2099,7 @@ static struct PyMethodDef bpy_bmesh_methods[] = { {"select_flush_mode", (PyCFunction)bpy_bmesh_select_flush_mode, METH_NOARGS, bpy_bmesh_select_flush_mode_doc}, {"select_flush", (PyCFunction)bpy_bmesh_select_flush, METH_O, bpy_bmesh_select_flush_doc}, {"normal_update", (PyCFunction)bpy_bmesh_normal_update, METH_VARARGS, bpy_bmesh_normal_update_doc}, - {"transform", (PyCFunction)bpy_bmesh_transform, METH_VARARGS|METH_KEYWORDS, bpy_bmesh_transform_doc}, + {"transform", (PyCFunction)bpy_bmesh_transform, METH_VARARGS | METH_KEYWORDS, bpy_bmesh_transform_doc}, {NULL, NULL, 0, NULL} }; @@ -2141,7 +2141,7 @@ static struct PyMethodDef bpy_bmface_methods[] = { {"copy_from", (PyCFunction)bpy_bm_elem_copy_from, METH_O, bpy_bm_elem_copy_from_doc}, {"copy_from_face_interp", (PyCFunction)bpy_bmface_copy_from_face_interp, METH_O, bpy_bmface_copy_from_face_interp_doc}, - {"copy", (PyCFunction)bpy_bmface_copy, METH_VARARGS|METH_KEYWORDS, bpy_bmface_copy_doc}, + {"copy", (PyCFunction)bpy_bmface_copy, METH_VARARGS | METH_KEYWORDS, bpy_bmface_copy_doc}, {"calc_area", (PyCFunction)bpy_bmface_calc_area, METH_NOARGS, bpy_bmface_calc_area_doc}, {"calc_perimeter", (PyCFunction)bpy_bmface_calc_perimeter, METH_NOARGS, bpy_bmface_calc_perimeter_doc}, diff --git a/source/blender/python/intern/bpy_library.c b/source/blender/python/intern/bpy_library.c index 1d02acbe983..d34bdfe9448 100644 --- a/source/blender/python/intern/bpy_library.c +++ b/source/blender/python/intern/bpy_library.c @@ -170,18 +170,18 @@ static PyTypeObject bpy_lib_Type = { }; PyDoc_STRVAR(bpy_lib_load_doc, - ".. method:: load(filepath, link=False, relative=False)\n" - "\n" - " Returns a context manager which exposes 2 library objects on entering.\n" - " Each object has attributes matching bpy.data which are lists of strings to be linked.\n" - "\n" - " :arg filepath: The path to a blend file.\n" - " :type filepath: string\n" - " :arg link: When False reference to the original file is lost.\n" - " :type link: bool\n" - " :arg relative: When True the path is stored relative to the open blend file.\n" - " :type relative: bool\n" - ); +".. method:: load(filepath, link=False, relative=False)\n" +"\n" +" Returns a context manager which exposes 2 library objects on entering.\n" +" Each object has attributes matching bpy.data which are lists of strings to be linked.\n" +"\n" +" :arg filepath: The path to a blend file.\n" +" :type filepath: string\n" +" :arg link: When False reference to the original file is lost.\n" +" :type link: bool\n" +" :arg relative: When True the path is stored relative to the open blend file.\n" +" :type relative: bool\n" +); static PyObject *bpy_lib_load(PyObject *UNUSED(self), PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"filepath", "link", "relative", NULL}; diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c index c6bfeff1651..4d05b837952 100644 --- a/source/blender/python/mathutils/mathutils_geometry.c +++ b/source/blender/python/mathutils/mathutils_geometry.c @@ -807,6 +807,7 @@ PyDoc_STRVAR(M_Geometry_intersect_point_quad_2d_doc, "\n" " Takes 5 vectors (using only the x and y coordinates): one is the point and the next 4 define the quad, \n" " only the x and y are used from the vectors. Returns 1 if the point is within the quad, otherwise 0.\n" +" Works only with convex quads without singular edges." "\n" " :arg pt: Point\n" " :type pt: :class:`mathutils.Vector`\n" diff --git a/source/blender/render/intern/raytrace/rayobject_octree.cpp b/source/blender/render/intern/raytrace/rayobject_octree.cpp index dc7b6dd6e8d..538c5493282 100644 --- a/source/blender/render/intern/raytrace/rayobject_octree.cpp +++ b/source/blender/render/intern/raytrace/rayobject_octree.cpp @@ -51,18 +51,15 @@ #define BRANCH_ARRAY 1024 #define NODE_ARRAY 4096 -typedef struct Branch -{ +typedef struct Branch { struct Branch *b[8]; } Branch; -typedef struct OcVal -{ +typedef struct OcVal { short ocx, ocy, ocz; } OcVal; -typedef struct Node -{ +typedef struct Node { struct RayFace *v[8]; struct OcVal ov[8]; struct Node *next; @@ -73,7 +70,7 @@ typedef struct Octree { struct Branch **adrbranch; struct Node **adrnode; - float ocsize; /* ocsize: mult factor, max size octree */ + float ocsize; /* ocsize: mult factor, max size octree */ float ocfacx, ocfacy, ocfacz; float min[3], max[3]; int ocres; @@ -121,8 +118,8 @@ static RayObjectAPI octree_api = /* **************** ocval method ******************* */ /* within one octree node, a set of 3x15 bits defines a 'boundbox' to OR with */ -#define OCVALRES 15 -#define BROW16(min, max) (((max)>=OCVALRES? 0xFFFF: (1<<(max+1))-1) - ((min>0)? ((1<<(min))-1):0) ) +#define OCVALRES 15 +#define BROW16(min, max) (((max) >= OCVALRES ? 0xFFFF : (1 << (max + 1)) - 1) - ((min > 0) ? ((1 << (min)) - 1) : 0)) static void calc_ocval_face(float *v1, float *v2, float *v3, float *v4, short x, short y, short z, OcVal *ov) { @@ -137,17 +134,17 @@ static void calc_ocval_face(float *v1, float *v2, float *v3, float *v4, short x, DO_MINMAX(v4, min, max); } - ocmin= OCVALRES*(min[0]-x); - ocmax= OCVALRES*(max[0]-x); - ov->ocx= BROW16(ocmin, ocmax); - - ocmin= OCVALRES*(min[1]-y); - ocmax= OCVALRES*(max[1]-y); - ov->ocy= BROW16(ocmin, ocmax); - - ocmin= OCVALRES*(min[2]-z); - ocmax= OCVALRES*(max[2]-z); - ov->ocz= BROW16(ocmin, ocmax); + ocmin = OCVALRES * (min[0] - x); + ocmax = OCVALRES * (max[0] - x); + ov->ocx = BROW16(ocmin, ocmax); + + ocmin = OCVALRES * (min[1] - y); + ocmax = OCVALRES * (max[1] - y); + ov->ocy = BROW16(ocmin, ocmax); + + ocmin = OCVALRES * (min[2] - z); + ocmax = OCVALRES * (max[2] - z); + ov->ocz = BROW16(ocmin, ocmax); } @@ -155,35 +152,35 @@ static void calc_ocval_ray(OcVal *ov, float xo, float yo, float zo, float *vec1, { int ocmin, ocmax; - if (vec1[0]<vec2[0]) { - ocmin= OCVALRES*(vec1[0] - xo); - ocmax= OCVALRES*(vec2[0] - xo); + if (vec1[0] < vec2[0]) { + ocmin = OCVALRES * (vec1[0] - xo); + ocmax = OCVALRES * (vec2[0] - xo); } else { - ocmin= OCVALRES*(vec2[0] - xo); - ocmax= OCVALRES*(vec1[0] - xo); + ocmin = OCVALRES * (vec2[0] - xo); + ocmax = OCVALRES * (vec1[0] - xo); } - ov->ocx= BROW16(ocmin, ocmax); + ov->ocx = BROW16(ocmin, ocmax); - if (vec1[1]<vec2[1]) { - ocmin= OCVALRES*(vec1[1] - yo); - ocmax= OCVALRES*(vec2[1] - yo); + if (vec1[1] < vec2[1]) { + ocmin = OCVALRES * (vec1[1] - yo); + ocmax = OCVALRES * (vec2[1] - yo); } else { - ocmin= OCVALRES*(vec2[1] - yo); - ocmax= OCVALRES*(vec1[1] - yo); + ocmin = OCVALRES * (vec2[1] - yo); + ocmax = OCVALRES * (vec1[1] - yo); } - ov->ocy= BROW16(ocmin, ocmax); + ov->ocy = BROW16(ocmin, ocmax); - if (vec1[2]<vec2[2]) { - ocmin= OCVALRES*(vec1[2] - zo); - ocmax= OCVALRES*(vec2[2] - zo); + if (vec1[2] < vec2[2]) { + ocmin = OCVALRES * (vec1[2] - zo); + ocmax = OCVALRES * (vec2[2] - zo); } else { - ocmin= OCVALRES*(vec2[2] - zo); - ocmax= OCVALRES*(vec1[2] - zo); + ocmin = OCVALRES * (vec2[2] - zo); + ocmax = OCVALRES * (vec1[2] - zo); } - ov->ocz= BROW16(ocmin, ocmax); + ov->ocz = BROW16(ocmin, ocmax); } /* ************* octree ************** */ @@ -195,17 +192,17 @@ static Branch *addbranch(Octree *oc, Branch *br, short ocb) if (br->b[ocb]) return br->b[ocb]; oc->branchcount++; - index= oc->branchcount>>12; + index = oc->branchcount >> 12; - if (oc->adrbranch[index]==NULL) - oc->adrbranch[index]= (Branch*)MEM_callocN(4096*sizeof(Branch), "new oc branch"); + if (oc->adrbranch[index] == NULL) + oc->adrbranch[index] = (Branch *)MEM_callocN(4096 * sizeof(Branch), "new oc branch"); - if (oc->branchcount>= BRANCH_ARRAY*4096) { + if (oc->branchcount >= BRANCH_ARRAY * 4096) { printf("error; octree branches full\n"); - oc->branchcount=0; + oc->branchcount = 0; } - return br->b[ocb]= oc->adrbranch[index]+(oc->branchcount & 4095); + return br->b[ocb] = oc->adrbranch[index] + (oc->branchcount & 4095); } static Node *addnode(Octree *oc) @@ -213,17 +210,17 @@ static Node *addnode(Octree *oc) int index; oc->nodecount++; - index= oc->nodecount>>12; + index = oc->nodecount >> 12; - if (oc->adrnode[index]==NULL) - oc->adrnode[index]= (Node*)MEM_callocN(4096*sizeof(Node), "addnode"); + if (oc->adrnode[index] == NULL) + oc->adrnode[index] = (Node *)MEM_callocN(4096 * sizeof(Node), "addnode"); - if (oc->nodecount> NODE_ARRAY*NODE_ARRAY) { + if (oc->nodecount > NODE_ARRAY * NODE_ARRAY) { printf("error; octree nodes full\n"); - oc->nodecount=0; + oc->nodecount = 0; } - return oc->adrnode[index]+(oc->nodecount & 4095); + return oc->adrnode[index] + (oc->nodecount & 4095); } static int face_in_node(RayFace *face, short x, short y, short z, float rtf[][3]) @@ -234,33 +231,33 @@ static int face_in_node(RayFace *face, short x, short y, short z, float rtf[][3] // 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]; + d = -nor[0] * rtf[0][0] - nor[1] * rtf[0][1] - nor[2] * rtf[0][2]; return 0; } - fx= x; - fy= y; - fz= z; - - if ((fx)*nor[0] + (fy)*nor[1] + (fz)*nor[2] + d > 0.0f) { - if ((fx+1)*nor[0] + (fy )*nor[1] + (fz )*nor[2] + d < 0.0f) return 1; - if ((fx )*nor[0] + (fy+1)*nor[1] + (fz )*nor[2] + d < 0.0f) return 1; - if ((fx+1)*nor[0] + (fy+1)*nor[1] + (fz )*nor[2] + d < 0.0f) return 1; - - if ((fx )*nor[0] + (fy )*nor[1] + (fz+1)*nor[2] + d < 0.0f) return 1; - if ((fx+1)*nor[0] + (fy )*nor[1] + (fz+1)*nor[2] + d < 0.0f) return 1; - 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; + fx = x; + fy = y; + fz = z; + + if ((fx) * nor[0] + (fy) * nor[1] + (fz) * nor[2] + d > 0.0f) { + if ((fx + 1) * nor[0] + (fy ) * nor[1] + (fz ) * nor[2] + d < 0.0f) return 1; + if ((fx ) * nor[0] + (fy + 1) * nor[1] + (fz ) * nor[2] + d < 0.0f) return 1; + if ((fx + 1) * nor[0] + (fy + 1) * nor[1] + (fz ) * nor[2] + d < 0.0f) return 1; + + if ((fx ) * nor[0] + (fy ) * nor[1] + (fz + 1) * nor[2] + d < 0.0f) return 1; + if ((fx + 1) * nor[0] + (fy ) * nor[1] + (fz + 1) * nor[2] + d < 0.0f) return 1; + 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; } else { - if ((fx+1)*nor[0] + (fy )*nor[1] + (fz )*nor[2] + d > 0.0f) return 1; - if ((fx )*nor[0] + (fy+1)*nor[1] + (fz )*nor[2] + d > 0.0f) return 1; - if ((fx+1)*nor[0] + (fy+1)*nor[1] + (fz )*nor[2] + d > 0.0f) return 1; - - if ((fx )*nor[0] + (fy )*nor[1] + (fz+1)*nor[2] + d > 0.0f) return 1; - if ((fx+1)*nor[0] + (fy )*nor[1] + (fz+1)*nor[2] + d > 0.0f) return 1; - 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; + if ((fx + 1) * nor[0] + (fy ) * nor[1] + (fz ) * nor[2] + d > 0.0f) return 1; + if ((fx ) * nor[0] + (fy + 1) * nor[1] + (fz ) * nor[2] + d > 0.0f) return 1; + if ((fx + 1) * nor[0] + (fy + 1) * nor[1] + (fz ) * nor[2] + d > 0.0f) return 1; + + if ((fx ) * nor[0] + (fy ) * nor[1] + (fz + 1) * nor[2] + d > 0.0f) return 1; + if ((fx + 1) * nor[0] + (fy ) * nor[1] + (fz + 1) * nor[2] + d > 0.0f) return 1; + 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; @@ -272,163 +269,163 @@ static void ocwrite(Octree *oc, RayFace *face, int quad, short x, short y, short Node *no; short a, oc0, oc1, oc2, oc3, oc4, oc5; - x<<=2; - y<<=1; + x <<= 2; + y <<= 1; - br= oc->adrbranch[0]; + br = oc->adrbranch[0]; - if (oc->ocres==512) { - oc0= ((x & 1024)+(y & 512)+(z & 256))>>8; - br= addbranch(oc, br, oc0); + if (oc->ocres == 512) { + oc0 = ((x & 1024) + (y & 512) + (z & 256)) >> 8; + br = addbranch(oc, br, oc0); } - if (oc->ocres>=256) { - oc0= ((x & 512)+(y & 256)+(z & 128))>>7; - br= addbranch(oc, br, oc0); + if (oc->ocres >= 256) { + oc0 = ((x & 512) + (y & 256) + (z & 128)) >> 7; + br = addbranch(oc, br, oc0); } - if (oc->ocres>=128) { - oc0= ((x & 256)+(y & 128)+(z & 64))>>6; - br= addbranch(oc, br, oc0); + if (oc->ocres >= 128) { + oc0 = ((x & 256) + (y & 128) + (z & 64)) >> 6; + br = addbranch(oc, br, oc0); } - oc0= ((x & 128)+(y & 64)+(z & 32))>>5; - oc1= ((x & 64)+(y & 32)+(z & 16))>>4; - oc2= ((x & 32)+(y & 16)+(z & 8))>>3; - oc3= ((x & 16)+(y & 8)+(z & 4))>>2; - oc4= ((x & 8)+(y & 4)+(z & 2))>>1; - oc5= ((x & 4)+(y & 2)+(z & 1)); - - br= addbranch(oc, br, oc0); - br= addbranch(oc, br, oc1); - br= addbranch(oc, br, oc2); - br= addbranch(oc, br, oc3); - br= addbranch(oc, br, oc4); - no= (Node *)br->b[oc5]; - if (no==NULL) br->b[oc5]= (Branch *)(no= addnode(oc)); + oc0 = ((x & 128) + (y & 64) + (z & 32)) >> 5; + oc1 = ((x & 64) + (y & 32) + (z & 16)) >> 4; + oc2 = ((x & 32) + (y & 16) + (z & 8)) >> 3; + oc3 = ((x & 16) + (y & 8) + (z & 4)) >> 2; + oc4 = ((x & 8) + (y & 4) + (z & 2)) >> 1; + oc5 = ((x & 4) + (y & 2) + (z & 1)); + + br = addbranch(oc, br, oc0); + br = addbranch(oc, br, oc1); + br = addbranch(oc, br, oc2); + br = addbranch(oc, br, oc3); + br = addbranch(oc, br, oc4); + no = (Node *)br->b[oc5]; + if (no == NULL) br->b[oc5] = (Branch *)(no = addnode(oc)); while (no->next) no = no->next; - a= 0; - if (no->v[7]) { /* node full */ - no->next= addnode(oc); - no= no->next; + a = 0; + if (no->v[7]) { /* node full */ + no->next = addnode(oc); + no = no->next; } else { while (no->v[a] != NULL) a++; } - no->v[a]= (RayFace*) RE_rayobject_align(face); + 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]); + calc_ocval_face(rtf[0], rtf[1], rtf[2], rtf[3], x >> 2, y >> 1, z, &no->ov[a]); else - calc_ocval_face(rtf[0], rtf[1], rtf[2], NULL, x>>2, y>>1, z, &no->ov[a]); + calc_ocval_face(rtf[0], rtf[1], rtf[2], NULL, x >> 2, y >> 1, z, &no->ov[a]); } static void d2dda(Octree *oc, short b1, short b2, short c1, short c2, char *ocface, short rts[][3], float rtf[][3]) { int ocx1, ocx2, ocy1, ocy2; - int x, y, dx=0, dy=0; + int x, y, dx = 0, dy = 0; float ox1, ox2, oy1, oy2; float labda, labdao, labdax, labday, ldx, ldy; - ocx1= rts[b1][c1]; - ocy1= rts[b1][c2]; - ocx2= rts[b2][c1]; - ocy2= rts[b2][c2]; + ocx1 = rts[b1][c1]; + ocy1 = rts[b1][c2]; + ocx2 = rts[b2][c1]; + ocy2 = rts[b2][c2]; - if (ocx1==ocx2 && ocy1==ocy2) { - ocface[oc->ocres*ocx1+ocy1]= 1; + if (ocx1 == ocx2 && ocy1 == ocy2) { + ocface[oc->ocres * ocx1 + ocy1] = 1; return; } - ox1= rtf[b1][c1]; - oy1= rtf[b1][c2]; - ox2= rtf[b2][c1]; - oy2= rtf[b2][c2]; + ox1 = rtf[b1][c1]; + oy1 = rtf[b1][c2]; + ox2 = rtf[b2][c1]; + oy2 = rtf[b2][c2]; - if (ox1!=ox2) { - if (ox2-ox1>0.0f) { - labdax= (ox1-ocx1-1.0f)/(ox1-ox2); - ldx= -1.0f/(ox1-ox2); - dx= 1; + if (ox1 != ox2) { + if (ox2 - ox1 > 0.0f) { + labdax = (ox1 - ocx1 - 1.0f) / (ox1 - ox2); + ldx = -1.0f / (ox1 - ox2); + dx = 1; } else { - labdax= (ox1-ocx1)/(ox1-ox2); - ldx= 1.0f/(ox1-ox2); - dx= -1; + labdax = (ox1 - ocx1) / (ox1 - ox2); + ldx = 1.0f / (ox1 - ox2); + dx = -1; } } else { - labdax=1.0f; - ldx=0; + labdax = 1.0f; + ldx = 0; } - if (oy1!=oy2) { - if (oy2-oy1>0.0f) { - labday= (oy1-ocy1-1.0f)/(oy1-oy2); - ldy= -1.0f/(oy1-oy2); - dy= 1; + if (oy1 != oy2) { + if (oy2 - oy1 > 0.0f) { + labday = (oy1 - ocy1 - 1.0f) / (oy1 - oy2); + ldy = -1.0f / (oy1 - oy2); + dy = 1; } else { - labday= (oy1-ocy1)/(oy1-oy2); - ldy= 1.0f/(oy1-oy2); - dy= -1; + labday = (oy1 - ocy1) / (oy1 - oy2); + ldy = 1.0f / (oy1 - oy2); + dy = -1; } } else { - labday=1.0f; - ldy=0; + labday = 1.0f; + ldy = 0; } - x=ocx1; y=ocy1; - labda= MIN2(labdax, labday); + x = ocx1; y = ocy1; + labda = MIN2(labdax, labday); while (TRUE) { - if (x<0 || y<0 || x>=oc->ocres || y>=oc->ocres); - else ocface[oc->ocres*x+y]= 1; + if (x < 0 || y < 0 || x >= oc->ocres || y >= oc->ocres) ; + else ocface[oc->ocres * x + y] = 1; - labdao=labda; - if (labdax==labday) { - labdax+=ldx; - x+=dx; - labday+=ldy; - y+=dy; + labdao = labda; + if (labdax == labday) { + labdax += ldx; + x += dx; + labday += ldy; + y += dy; } else { - if (labdax<labday) { - labdax+=ldx; - x+=dx; + if (labdax < labday) { + labdax += ldx; + x += dx; } else { - labday+=ldy; - y+=dy; + labday += ldy; + y += dy; } } - labda=MIN2(labdax, labday); - if (labda==labdao) break; - if (labda>=1.0f) break; + labda = MIN2(labdax, labday); + if (labda == labdao) break; + if (labda >= 1.0f) break; } - ocface[oc->ocres*ocx2+ocy2]=1; + ocface[oc->ocres * ocx2 + ocy2] = 1; } static void filltriangle(Octree *oc, short c1, short c2, char *ocface, short *ocmin, short *ocmax) { int a, x, y, y1, y2; - for (x=ocmin[c1];x<=ocmax[c1];x++) { - a= oc->ocres*x; - for (y=ocmin[c2];y<=ocmax[c2];y++) { - if (ocface[a+y]) { + for (x = ocmin[c1]; x <= ocmax[c1]; x++) { + a = oc->ocres * x; + for (y = ocmin[c2]; y <= ocmax[c2]; y++) { + if (ocface[a + y]) { y++; - while (ocface[a+y] && y!=ocmax[c2]) y++; - for (y1=ocmax[c2];y1>y;y1--) { - if (ocface[a+y1]) { - for (y2=y;y2<=y1;y2++) ocface[a+y2]=1; - y1=0; + while (ocface[a + y] && y != ocmax[c2]) y++; + for (y1 = ocmax[c2]; y1 > y; y1--) { + if (ocface[a + y1]) { + for (y2 = y; y2 <= y1; y2++) ocface[a + y2] = 1; + y1 = 0; } } - y=ocmax[c2]; + y = ocmax[c2]; } } } @@ -436,7 +433,7 @@ static void filltriangle(Octree *oc, short c1, short c2, char *ocface, short *oc static void RE_rayobject_octree_free(RayObject *tree) { - Octree *oc= (Octree*)tree; + Octree *oc = (Octree *)tree; #if 0 printf("branches %d nodes %d\n", oc->branchcount, oc->nodecount); @@ -448,28 +445,28 @@ static void RE_rayobject_octree_free(RayObject *tree) MEM_freeN(oc->ocface); if (oc->adrbranch) { - int a= 0; + int a = 0; while (oc->adrbranch[a]) { MEM_freeN(oc->adrbranch[a]); - oc->adrbranch[a]= NULL; + oc->adrbranch[a] = NULL; a++; } MEM_freeN(oc->adrbranch); - oc->adrbranch= NULL; + oc->adrbranch = NULL; } - oc->branchcount= 0; + oc->branchcount = 0; if (oc->adrnode) { - int a= 0; + int a = 0; while (oc->adrnode[a]) { MEM_freeN(oc->adrnode[a]); - oc->adrnode[a]= NULL; + oc->adrnode[a] = NULL; a++; } MEM_freeN(oc->adrnode); - oc->adrnode= NULL; + oc->adrnode = NULL; } - oc->nodecount= 0; + oc->nodecount = 0; MEM_freeN(oc); } @@ -477,29 +474,29 @@ static void RE_rayobject_octree_free(RayObject *tree) 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 */ + 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 = (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); + return RE_rayobject_unalignRayAPI((RayObject *) oc); } static void RE_rayobject_octree_add(RayObject *tree, RayObject *node) { - Octree *oc = (Octree*)tree; + Octree *oc = (Octree *)tree; - assert( RE_rayobject_isRayFace(node) ); - assert( oc->ro_nodes_used < oc->ro_nodes_size ); - oc->ro_nodes[ oc->ro_nodes_used++ ] = (RayFace*)RE_rayobject_align(node); + assert(RE_rayobject_isRayFace(node) ); + assert(oc->ro_nodes_used < oc->ro_nodes_size); + oc->ro_nodes[oc->ro_nodes_used++] = (RayFace *)RE_rayobject_align(node); } static void octree_fill_rayface(Octree *oc, RayFace *face) @@ -508,14 +505,14 @@ static void octree_fill_rayface(Octree *oc, RayFace *face) float co1[3], co2[3], co3[3], co4[3]; short rts[4][3]; short ocmin[3], ocmax[3]; - char *ocface= oc->ocface; // front, top, size view of face, to fill in + char *ocface = oc->ocface; // front, top, size view of face, to fill in int a, b, c, oc1, oc2, oc3, oc4, x, y, z, ocres2; - ocfac[0]= oc->ocfacx; - ocfac[1]= oc->ocfacy; - ocfac[2]= oc->ocfacz; + ocfac[0] = oc->ocfacx; + ocfac[1] = oc->ocfacy; + ocfac[2] = oc->ocfacz; - ocres2= oc->ocres*oc->ocres; + ocres2 = oc->ocres * oc->ocres; copy_v3_v3(co1, face->v1); copy_v3_v3(co2, face->v2); @@ -523,7 +520,7 @@ static void octree_fill_rayface(Octree *oc, RayFace *face) if (face->v4) copy_v3_v3(co4, face->v4); - for (c=0;c<3;c++) { + for (c = 0; c < 3; c++) { rtf[0][c] = (co1[c] - oc->min[c]) * ocfac[c]; rts[0][c] = (short)rtf[0][c]; rtf[1][c] = (co2[c] - oc->min[c]) * ocfac[c]; @@ -536,62 +533,62 @@ static void octree_fill_rayface(Octree *oc, RayFace *face) } } - for (c=0;c<3;c++) { - oc1= rts[0][c]; - oc2= rts[1][c]; - oc3= rts[2][c]; + for (c = 0; c < 3; c++) { + oc1 = rts[0][c]; + oc2 = rts[1][c]; + oc3 = rts[2][c]; if (!RE_rayface_isQuad(face)) { - ocmin[c]= MIN3(oc1, oc2, oc3); - ocmax[c]= MAX3(oc1, oc2, oc3); + ocmin[c] = MIN3(oc1, oc2, oc3); + ocmax[c] = MAX3(oc1, oc2, oc3); } else { - oc4= rts[3][c]; - ocmin[c]= MIN4(oc1, oc2, oc3, oc4); - ocmax[c]= MAX4(oc1, oc2, oc3, oc4); + oc4 = rts[3][c]; + ocmin[c] = MIN4(oc1, oc2, oc3, oc4); + ocmax[c] = MAX4(oc1, oc2, oc3, oc4); } - if (ocmax[c]>oc->ocres-1) ocmax[c]=oc->ocres-1; - if (ocmin[c]<0) ocmin[c]=0; + 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]) { + 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, 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); - d2dda(oc, 1, 2, 0, 1, ocface+ocres2, rts, rtf); + d2dda(oc, 0, 1, 1, 2, ocface + 2 * ocres2, rts, rtf); + d2dda(oc, 1, 2, 0, 1, ocface + ocres2, rts, rtf); d2dda(oc, 1, 2, 0, 2, ocface, rts, rtf); - d2dda(oc, 1, 2, 1, 2, ocface+2*ocres2, rts, rtf); + d2dda(oc, 1, 2, 1, 2, ocface + 2 * ocres2, rts, rtf); if (!RE_rayface_isQuad(face)) { - d2dda(oc, 2, 0, 0, 1, ocface+ocres2, rts, rtf); + d2dda(oc, 2, 0, 0, 1, ocface + ocres2, rts, rtf); d2dda(oc, 2, 0, 0, 2, ocface, rts, rtf); - d2dda(oc, 2, 0, 1, 2, ocface+2*ocres2, rts, rtf); + d2dda(oc, 2, 0, 1, 2, ocface + 2 * ocres2, rts, rtf); } else { - d2dda(oc, 2, 3, 0, 1, ocface+ocres2, rts, rtf); + d2dda(oc, 2, 3, 0, 1, ocface + ocres2, rts, rtf); d2dda(oc, 2, 3, 0, 2, ocface, rts, rtf); - d2dda(oc, 2, 3, 1, 2, ocface+2*ocres2, rts, rtf); - d2dda(oc, 3, 0, 0, 1, ocface+ocres2, rts, rtf); + d2dda(oc, 2, 3, 1, 2, ocface + 2 * ocres2, rts, rtf); + d2dda(oc, 3, 0, 0, 1, ocface + ocres2, rts, rtf); d2dda(oc, 3, 0, 0, 2, ocface, rts, rtf); - d2dda(oc, 3, 0, 1, 2, ocface+2*ocres2, rts, rtf); + d2dda(oc, 3, 0, 1, 2, ocface + 2 * ocres2, rts, rtf); } /* nothing todo with triangle..., just fills :) */ - filltriangle(oc, 0, 1, ocface+ocres2, ocmin, ocmax); + filltriangle(oc, 0, 1, ocface + ocres2, ocmin, ocmax); filltriangle(oc, 0, 2, ocface, ocmin, ocmax); - filltriangle(oc, 1, 2, ocface+2*ocres2, 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++) { - if (ocface[a+y+ocres2]) { - b= oc->ocres*y+2*ocres2; - for (z=ocmin[2];z<=ocmax[2];z++) { - if (ocface[b+z] && ocface[a+z]) { + for (x = ocmin[0]; x <= ocmax[0]; x++) { + a = oc->ocres * x; + for (y = ocmin[1]; y <= ocmax[1]; y++) { + if (ocface[a + y + ocres2]) { + b = oc->ocres * y + 2 * ocres2; + for (z = ocmin[2]; z <= ocmax[2]; z++) { + if (ocface[b + z] && ocface[a + z]) { if (face_in_node(NULL, x, y, z, rtf)) ocwrite(oc, face, RE_rayface_isQuad(face), x, y, z, rtf); } @@ -601,18 +598,18 @@ 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; - for (y=ocmin[1];y<=ocmax[1];y++) { + for (x = ocmin[0]; x <= ocmax[0]; x++) { + a = oc->ocres * x; + for (y = ocmin[1]; y <= ocmax[1]; y++) { /* x-y */ - ocface[a+y+ocres2]= 0; + ocface[a + y + ocres2] = 0; - b= oc->ocres*y + 2*ocres2; - for (z=ocmin[2];z<=ocmax[2];z++) { + b = oc->ocres * y + 2 * ocres2; + for (z = ocmin[2]; z <= ocmax[2]; z++) { /* y-z */ - ocface[b+z]= 0; + ocface[b + z] = 0; /* x-z */ - ocface[a+z]= 0; + ocface[a + z] = 0; } } } @@ -621,44 +618,44 @@ static void octree_fill_rayface(Octree *oc, RayFace *face) static void RE_rayobject_octree_done(RayObject *tree) { - Octree *oc = (Octree*)tree; + Octree *oc = (Octree *)tree; int c; float t00, t01, t02; - int ocres2 = oc->ocres*oc->ocres; + 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); + 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 = (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"); + 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); + oc->ocface = (char *)MEM_callocN(3 * ocres2 + 8, "ocface"); + memset(oc->ocface, 0, 3 * ocres2); - for (c=0;c<3;c++) { /* octree enlarge, still needed? */ - oc->min[c]-= 0.01f; - oc->max[c]+= 0.01f; + for (c = 0; c < 3; c++) { /* octree enlarge, still needed? */ + oc->min[c] -= 0.01f; + oc->max[c] += 0.01f; } - t00= oc->max[0]-oc->min[0]; - t01= oc->max[1]-oc->min[1]; - t02= oc->max[2]-oc->min[2]; + 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.1)/t00; - oc->ocfacy= (oc->ocres-0.1)/t01; - oc->ocfacz= (oc->ocres-0.1)/t02; + oc->ocfacx = (oc->ocres - 0.1) / t00; + oc->ocfacy = (oc->ocres - 0.1) / t01; + oc->ocfacz = (oc->ocres - 0.1) / t02; - oc->ocsize= sqrt(t00*t00+t01*t01+t02*t02); /* global, max size octree */ + oc->ocsize = sqrt(t00 * t00 + t01 * t01 + t02 * t02); /* global, max size octree */ - for (c=0; c<oc->ro_nodes_used; c++) { + for (c = 0; c < oc->ro_nodes_used; c++) { octree_fill_rayface(oc, oc->ro_nodes[c]); } @@ -667,14 +664,14 @@ static void RE_rayobject_octree_done(RayObject *tree) MEM_freeN(oc->ro_nodes); oc->ro_nodes = NULL; - printf("%f %f - %f\n", oc->min[0], oc->max[0], oc->ocfacx ); - printf("%f %f - %f\n", oc->min[1], oc->max[1], oc->ocfacy ); - printf("%f %f - %f\n", oc->min[2], oc->max[2], oc->ocfacz ); + printf("%f %f - %f\n", oc->min[0], oc->max[0], oc->ocfacx); + printf("%f %f - %f\n", oc->min[1], oc->max[1], oc->ocfacy); + printf("%f %f - %f\n", oc->min[2], oc->max[2], oc->ocfacz); } static void RE_rayobject_octree_bb(RayObject *tree, float *min, float *max) { - Octree *oc = (Octree*)tree; + Octree *oc = (Octree *)tree; DO_MINMAX(oc->min, min, max); DO_MINMAX(oc->max, min, max); } @@ -687,7 +684,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 (; no; no = no->next) { for (nr = 0; nr < 8; nr++) { RayFace *face = no->v[nr]; OcVal *ov = no->ov + nr; @@ -695,7 +692,7 @@ static int testnode(Octree *UNUSED(oc), Isect *is, Node *no, OcVal ocval) if (!face) break; if ( (ov->ocx & ocval.ocx) && (ov->ocy & ocval.ocy) && (ov->ocz & ocval.ocz) ) { - if ( RE_rayobject_intersect( RE_rayobject_unalignRayFace(face), is) ) + if (RE_rayobject_intersect(RE_rayobject_unalignRayFace(face), is) ) return 1; } } @@ -703,9 +700,9 @@ 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; + int found = 0; - for ( ; no; no = no->next) { + for (; no; no = no->next) { for (nr = 0; nr < 8; nr++) { RayFace *face = no->v[nr]; OcVal *ov = no->ov + nr; @@ -713,7 +710,7 @@ static int testnode(Octree *UNUSED(oc), Isect *is, Node *no, OcVal ocval) if (!face) break; if ( (ov->ocx & ocval.ocx) && (ov->ocy & ocval.ocy) && (ov->ocz & ocval.ocz) ) { - if ( RE_rayobject_intersect( RE_rayobject_unalignRayFace(face), is) ) { + if (RE_rayobject_intersect(RE_rayobject_unalignRayFace(face), is) ) { found = 1; } } @@ -732,49 +729,49 @@ static Node *ocread(Octree *oc, int x, int y, int z) Branch *br; int oc1; - x<<=2; - y<<=1; + x <<= 2; + y <<= 1; - br= oc->adrbranch[0]; + br = oc->adrbranch[0]; - if (oc->ocres==512) { - oc1= ((x & 1024)+(y & 512)+(z & 256))>>8; - br= br->b[oc1]; - if (br==NULL) { + if (oc->ocres == 512) { + oc1 = ((x & 1024) + (y & 512) + (z & 256)) >> 8; + br = br->b[oc1]; + if (br == NULL) { return NULL; } } - if (oc->ocres>=256) { - oc1= ((x & 512)+(y & 256)+(z & 128))>>7; - br= br->b[oc1]; - if (br==NULL) { + if (oc->ocres >= 256) { + oc1 = ((x & 512) + (y & 256) + (z & 128)) >> 7; + br = br->b[oc1]; + if (br == NULL) { return NULL; } } - if (oc->ocres>=128) { - oc1= ((x & 256)+(y & 128)+(z & 64))>>6; - br= br->b[oc1]; - if (br==NULL) { + if (oc->ocres >= 128) { + oc1 = ((x & 256) + (y & 128) + (z & 64)) >> 6; + br = br->b[oc1]; + if (br == NULL) { return NULL; } } - oc1= ((x & 128)+(y & 64)+(z & 32))>>5; - br= br->b[oc1]; + oc1 = ((x & 128) + (y & 64) + (z & 32)) >> 5; + br = br->b[oc1]; if (br) { - oc1= ((x & 64)+(y & 32)+(z & 16))>>4; - br= br->b[oc1]; + oc1 = ((x & 64) + (y & 32) + (z & 16)) >> 4; + br = br->b[oc1]; if (br) { - oc1= ((x & 32)+(y & 16)+(z & 8))>>3; - br= br->b[oc1]; + oc1 = ((x & 32) + (y & 16) + (z & 8)) >> 3; + br = br->b[oc1]; if (br) { - oc1= ((x & 16)+(y & 8)+(z & 4))>>2; - br= br->b[oc1]; + oc1 = ((x & 16) + (y & 8) + (z & 4)) >> 2; + br = br->b[oc1]; if (br) { - oc1= ((x & 8)+(y & 4)+(z & 2))>>1; - br= br->b[oc1]; + oc1 = ((x & 8) + (y & 4) + (z & 2)) >> 1; + br = br->b[oc1]; if (br) { - oc1= ((x & 4)+(y & 2)+(z & 1)); + oc1 = ((x & 4) + (y & 2) + (z & 1)); return (Node *)br->b[oc1]; } } @@ -789,24 +786,24 @@ static int cliptest(float p, float q, float *u1, float *u2) { float r; - if (p<0.0f) { - if (q<p) return 0; - else if (q<0.0f) { - r= q/p; - if (r>*u2) return 0; - else if (r>*u1) *u1=r; + if (p < 0.0f) { + if (q < p) return 0; + else if (q < 0.0f) { + r = q / p; + if (r > *u2) return 0; + else if (r > *u1) *u1 = r; } } else { - if (p>0.0f) { - if (q<0.0f) return 0; - else if (q<p) { - r= q/p; - if (r<*u1) return 0; - else if (r<*u2) *u2=r; + if (p > 0.0f) { + if (q < 0.0f) return 0; + else if (q < p) { + r = q / p; + if (r < *u1) return 0; + else if (r < *u2) *u2 = r; } } - else if (q<0.0f) return 0; + else if (q < 0.0f) return 0; } return 1; } @@ -816,16 +813,16 @@ static int cliptest(float p, float q, float *u1, float *u2) #if 0 -in top: static int coh_nodes[16*16*16][6]; -in makeoctree: memset(coh_nodes, 0, sizeof(coh_nodes)); +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; + 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; } @@ -833,9 +830,9 @@ static int do_coherence_test(int ocx1, int ocx2, int ocy1, int ocy2, int ocz1, i { 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; + 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; return 0; } @@ -845,7 +842,7 @@ static int do_coherence_test(int ocx1, int ocx2, int ocy1, int ocy2, int ocz1, i /* starts with is->orig.face */ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) { - Octree *oc= (Octree*)tree; + Octree *oc = (Octree *)tree; Node *no; OcVal ocval; float vec1[3], vec2[3], start[3], end[3]; @@ -853,47 +850,47 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) float labdao, labdax, ldx, labday, ldy, labdaz, ldz, ddalabda; float olabda = 0; int dx, dy, dz; - int xo, yo, zo, c1=0; + int xo, yo, zo, c1 = 0; int ocx1, ocx2, ocy1, ocy2, ocz1, ocz2; /* clip with octree */ - if (oc->branchcount==0) return 0; + if (oc->branchcount == 0) return 0; /* do this before intersect calls */ #if 0 - is->facecontr= NULL; /* to check shared edge */ - is->obcontr= 0; - is->faceisect= is->isect= 0; /* shared edge, quad half flag */ - is->userdata= oc->userdata; + is->facecontr = NULL; /* to check shared edge */ + is->obcontr = 0; + is->faceisect = is->isect = 0; /* shared edge, quad half flag */ + is->userdata = oc->userdata; #endif - copy_v3_v3( start, is->start ); - madd_v3_v3v3fl( end, is->start, is->dir, is->dist ); - ldx= is->dir[0]*is->dist; + copy_v3_v3(start, is->start); + madd_v3_v3v3fl(end, is->start, is->dir, is->dist); + ldx = is->dir[0] * is->dist; olabda = is->dist; - u1= 0.0f; - u2= 1.0f; + 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)) { - ldy= is->dir[1]*is->dist; - if (cliptest(-ldy, start[1]-oc->min[1], &u1, &u2)) { - if (cliptest(ldy, oc->max[1]-start[1], &u1, &u2)) { - ldz = is->dir[2]*is->dist; - if (cliptest(-ldz, start[2]-oc->min[2], &u1, &u2)) { - if (cliptest(ldz, oc->max[2]-start[2], &u1, &u2)) { - c1=1; - if (u2<1.0f) { - end[0] = start[0]+u2*ldx; - end[1] = start[1]+u2*ldy; - end[2] = start[2]+u2*ldz; + if (cliptest(-ldx, start[0] - oc->min[0], &u1, &u2)) { + if (cliptest(ldx, oc->max[0] - start[0], &u1, &u2)) { + ldy = is->dir[1] * is->dist; + if (cliptest(-ldy, start[1] - oc->min[1], &u1, &u2)) { + if (cliptest(ldy, oc->max[1] - start[1], &u1, &u2)) { + ldz = is->dir[2] * is->dist; + if (cliptest(-ldz, start[2] - oc->min[2], &u1, &u2)) { + if (cliptest(ldz, oc->max[2] - start[2], &u1, &u2)) { + c1 = 1; + if (u2 < 1.0f) { + end[0] = start[0] + u2 * ldx; + end[1] = start[1] + u2 * ldy; + end[2] = start[2] + u2 * ldz; } - if (u1>0.0f) { - start[0] += u1*ldx; - start[1] += u1*ldy; - start[2] += u1*ldz; + if (u1 > 0.0f) { + start[0] += u1 * ldx; + start[1] += u1 * ldy; + start[2] += u1 * ldz; } } } @@ -902,34 +899,34 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) } } - if (c1==0) return 0; + if (c1 == 0) return 0; /* reset static variables in ocread */ //ocread(oc, oc->ocres, 0, 0); /* setup 3dda to traverse octree */ - ox1= (start[0]-oc->min[0])*oc->ocfacx; - oy1= (start[1]-oc->min[1])*oc->ocfacy; - oz1= (start[2]-oc->min[2])*oc->ocfacz; - ox2= (end[0]-oc->min[0])*oc->ocfacx; - oy2= (end[1]-oc->min[1])*oc->ocfacy; - oz2= (end[2]-oc->min[2])*oc->ocfacz; - - ocx1= (int)ox1; - ocy1= (int)oy1; - ocz1= (int)oz1; - ocx2= (int)ox2; - ocy2= (int)oy2; - ocz2= (int)oz2; + ox1 = (start[0] - oc->min[0]) * oc->ocfacx; + oy1 = (start[1] - oc->min[1]) * oc->ocfacy; + oz1 = (start[2] - oc->min[2]) * oc->ocfacz; + ox2 = (end[0] - oc->min[0]) * oc->ocfacx; + oy2 = (end[1] - oc->min[1]) * oc->ocfacy; + oz2 = (end[2] - oc->min[2]) * oc->ocfacz; + + ocx1 = (int)ox1; + ocy1 = (int)oy1; + ocz1 = (int)oz1; + ocx2 = (int)ox2; + ocy2 = (int)oy2; + ocz2 = (int)oz2; - if (ocx1==ocx2 && ocy1==ocy2 && ocz1==ocz2) { - no= ocread(oc, ocx1, ocy1, ocz1); + if (ocx1 == ocx2 && ocy1 == ocy2 && ocz1 == ocz2) { + no = ocread(oc, ocx1, ocy1, ocz1); if (no) { /* exact intersection with node */ - vec1[0]= ox1; vec1[1]= oy1; vec1[2]= oz1; - vec2[0]= ox2; vec2[1]= oy2; vec2[2]= oz2; + vec1[0] = ox1; vec1[1] = oy1; vec1[2] = oz1; + vec2[0] = ox2; vec2[1] = oy2; vec2[2] = oz2; calc_ocval_ray(&ocval, (float)ocx1, (float)ocy1, (float)ocz1, vec1, vec2); - if ( testnode(oc, is, no, ocval) ) return 1; + if (testnode(oc, is, no, ocval) ) return 1; } } else { @@ -939,153 +936,153 @@ static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) int eqval; /* calc labda en ld */ - dox= ox1-ox2; - doy= oy1-oy2; - doz= oz1-oz2; - - if (dox<-FLT_EPSILON) { - ldx= -1.0f/dox; - labdax= (ocx1-ox1+1.0f)*ldx; - dx= 1; + dox = ox1 - ox2; + doy = oy1 - oy2; + doz = oz1 - oz2; + + if (dox < -FLT_EPSILON) { + ldx = -1.0f / dox; + labdax = (ocx1 - ox1 + 1.0f) * ldx; + dx = 1; } - else if (dox>FLT_EPSILON) { - ldx= 1.0f/dox; - labdax= (ox1-ocx1)*ldx; - dx= -1; + else if (dox > FLT_EPSILON) { + ldx = 1.0f / dox; + labdax = (ox1 - ocx1) * ldx; + dx = -1; } else { - labdax=1.0f; - ldx=0; - dx= 0; + labdax = 1.0f; + ldx = 0; + dx = 0; } - if (doy<-FLT_EPSILON) { - ldy= -1.0f/doy; - labday= (ocy1-oy1+1.0f)*ldy; - dy= 1; + if (doy < -FLT_EPSILON) { + ldy = -1.0f / doy; + labday = (ocy1 - oy1 + 1.0f) * ldy; + dy = 1; } - else if (doy>FLT_EPSILON) { - ldy= 1.0f/doy; - labday= (oy1-ocy1)*ldy; - dy= -1; + else if (doy > FLT_EPSILON) { + ldy = 1.0f / doy; + labday = (oy1 - ocy1) * ldy; + dy = -1; } else { - labday=1.0f; - ldy=0; - dy= 0; + labday = 1.0f; + ldy = 0; + dy = 0; } - if (doz<-FLT_EPSILON) { - ldz= -1.0f/doz; - labdaz= (ocz1-oz1+1.0f)*ldz; - dz= 1; + if (doz < -FLT_EPSILON) { + ldz = -1.0f / doz; + labdaz = (ocz1 - oz1 + 1.0f) * ldz; + dz = 1; } - else if (doz>FLT_EPSILON) { - ldz= 1.0f/doz; - labdaz= (oz1-ocz1)*ldz; - dz= -1; + else if (doz > FLT_EPSILON) { + ldz = 1.0f / doz; + labdaz = (oz1 - ocz1) * ldz; + dz = -1; } else { - labdaz=1.0f; - ldz=0; - dz= 0; + labdaz = 1.0f; + ldz = 0; + dz = 0; } - xo=ocx1; yo=ocy1; zo=ocz1; - ddalabda= MIN3(labdax, labday, labdaz); + xo = ocx1; yo = ocy1; zo = ocz1; + ddalabda = MIN3(labdax, labday, labdaz); - vec2[0]= ox1; - vec2[1]= oy1; - vec2[2]= oz1; + 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 ddalabda==1.0f or larger */ while (TRUE) { - no= ocread(oc, xo, yo, zo); + no = ocread(oc, xo, yo, zo); if (no) { /* calculate ray intersection with octree node */ copy_v3_v3(vec1, vec2); // dox, y, z is negative - vec2[0]= ox1-ddalabda*dox; - vec2[1]= oy1-ddalabda*doy; - vec2[2]= oz1-ddalabda*doz; + vec2[0] = ox1 - ddalabda * dox; + vec2[1] = oy1 - ddalabda * doy; + vec2[2] = oz1 - ddalabda * doz; calc_ocval_ray(&ocval, (float)xo, (float)yo, (float)zo, vec1, vec2); //is->dist = (u1+ddalabda*(u2-u1))*olabda; - if ( testnode(oc, is, no, ocval) ) + if (testnode(oc, is, no, ocval) ) found = 1; - if (is->dist < (u1+ddalabda*(u2-u1))*olabda) + if (is->dist < (u1 + ddalabda * (u2 - u1)) * olabda) return found; } - labdao= ddalabda; + labdao = ddalabda; /* traversing ocree nodes need careful detection of smallest values, with proper * exceptions for equal labdas */ - eqval= (labdax==labday); - if (labday==labdaz) eqval += 2; - if (labdax==labdaz) eqval += 4; - - if (eqval) { // only 4 cases exist! - if (eqval==7) { // x=y=z - xo+=dx; labdax+=ldx; - yo+=dy; labday+=ldy; - zo+=dz; labdaz+=ldz; + eqval = (labdax == labday); + if (labday == labdaz) eqval += 2; + if (labdax == labdaz) eqval += 4; + + if (eqval) { // only 4 cases exist! + if (eqval == 7) { // x=y=z + xo += dx; labdax += ldx; + yo += dy; labday += ldy; + zo += dz; labdaz += ldz; } - else if (eqval==1) { // x=y + else if (eqval == 1) { // x=y if (labday < labdaz) { - xo+=dx; labdax+=ldx; - yo+=dy; labday+=ldy; + xo += dx; labdax += ldx; + yo += dy; labday += ldy; } else { - zo+=dz; labdaz+=ldz; + zo += dz; labdaz += ldz; } } - else if (eqval==2) { // y=z + else if (eqval == 2) { // y=z if (labdax < labday) { - xo+=dx; labdax+=ldx; + xo += dx; labdax += ldx; } else { - yo+=dy; labday+=ldy; - zo+=dz; labdaz+=ldz; + yo += dy; labday += ldy; + zo += dz; labdaz += ldz; } } else { // x=z if (labday < labdax) { - yo+=dy; labday+=ldy; + yo += dy; labday += ldy; } else { - xo+=dx; labdax+=ldx; - zo+=dz; labdaz+=ldz; + xo += dx; labdax += ldx; + zo += dz; labdaz += ldz; } } } - else { // all three different, just three cases exist - eqval= (labdax<labday); - if (labday<labdaz) eqval += 2; - if (labdax<labdaz) eqval += 4; + else { // all three different, just three cases exist + eqval = (labdax < labday); + if (labday < labdaz) eqval += 2; + if (labdax < labdaz) eqval += 4; - if (eqval==7 || eqval==5) { // x smallest - xo+=dx; labdax+=ldx; + if (eqval == 7 || eqval == 5) { // x smallest + xo += dx; labdax += ldx; } - else if (eqval==2 || eqval==6) { // y smallest - yo+=dy; labday+=ldy; + else if (eqval == 2 || eqval == 6) { // y smallest + yo += dy; labday += ldy; } else { // z smallest - zo+=dz; labdaz+=ldz; + zo += dz; labdaz += ldz; } } - ddalabda=MIN3(labdax, labday, labdaz); - if (ddalabda==labdao) break; + ddalabda = MIN3(labdax, labday, labdaz); + if (ddalabda == labdao) break; /* to make sure the last node is always checked */ - if (labdao>=1.0f) break; + if (labdao >= 1.0f) break; } } diff --git a/source/blender/render/intern/source/envmap.c b/source/blender/render/intern/source/envmap.c index 0f3a3111a13..61de4d39585 100644 --- a/source/blender/render/intern/source/envmap.c +++ b/source/blender/render/intern/source/envmap.c @@ -74,49 +74,49 @@ static void envmap_split_ima(EnvMap *env, ImBuf *ibuf) /* after lock we test cube[1], if set the other thread has done it fine */ BLI_lock_thread(LOCK_IMAGE); - if (env->cube[1]==NULL) { + if (env->cube[1] == NULL) { BKE_free_envmapdata(env); - dx= ibuf->y; - dx/= 2; - if (3*dx == ibuf->x) { + dx = ibuf->y; + dx /= 2; + if (3 * dx == ibuf->x) { env->type = ENV_CUBE; - env->ok= ENV_OSA; + env->ok = ENV_OSA; } else if (ibuf->x == ibuf->y) { env->type = ENV_PLANE; - env->ok= ENV_OSA; + env->ok = ENV_OSA; } else { printf("Incorrect envmap size\n"); - env->ok= 0; - env->ima->ok= 0; + 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); + 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, - 0, 0, 0, 0, dx, dx); + 0, 0, 0, 0, dx, dx); IMB_rectcpy(env->cube[1], ibuf, - 0, 0, dx, 0, dx, dx); + 0, 0, dx, 0, dx, dx); IMB_rectcpy(env->cube[2], ibuf, - 0, 0, 2*dx, 0, dx, dx); + 0, 0, 2 * dx, 0, dx, dx); IMB_rectcpy(env->cube[3], ibuf, - 0, 0, 0, dx, dx, dx); + 0, 0, 0, dx, dx, dx); IMB_rectcpy(env->cube[4], ibuf, - 0, 0, dx, dx, dx, dx); + 0, 0, dx, dx, dx, dx); IMB_rectcpy(env->cube[5], ibuf, - 0, 0, 2*dx, dx, dx, dx); + 0, 0, 2 * dx, dx, dx, dx); } else { /* ENV_PLANE */ - env->cube[1]= IMB_dupImBuf(ibuf); + env->cube[1] = IMB_dupImBuf(ibuf); IMB_float_from_rect(env->cube[1]); } } @@ -134,53 +134,53 @@ static Render *envmap_render_copy(Render *re, EnvMap *env) float viewscale; int cuberes; - envre= RE_NewRender("Envmap"); + envre = RE_NewRender("Envmap"); - env->lastsize= re->r.size; + 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; + envre->flag = re->flag; /* set up renderdata */ - envre->r= re->r; + envre->r = re->r; envre->r.mode &= ~(R_BORDER | R_PANORAMA | R_ORTHO | R_MBLUR); - envre->r.layers.first= envre->r.layers.last= NULL; - envre->r.filtertype= 0; - envre->r.xparts= envre->r.yparts= 2; - envre->r.size= 100; - envre->r.yasp= envre->r.xasp= 1; + envre->r.layers.first = envre->r.layers.last = NULL; + envre->r.filtertype = 0; + envre->r.xparts = envre->r.yparts = 2; + envre->r.size = 100; + envre->r.yasp = envre->r.xasp = 1; RE_InitState(envre, NULL, &envre->r, NULL, cuberes, cuberes, NULL); - envre->scene= re->scene; /* unsure about this... */ - envre->lay= re->lay; + envre->scene = re->scene; /* unsure about this... */ + envre->lay = re->lay; /* view stuff in env render */ - viewscale= (env->type == ENV_PLANE)? env->viewscale: 1.0f; + viewscale = (env->type == ENV_PLANE) ? env->viewscale : 1.0f; RE_SetEnvmapCamera(envre, env->object, viewscale, env->clipsta, env->clipend); /* callbacks */ - envre->display_draw= re->display_draw; - envre->ddh= re->ddh; - envre->test_break= re->test_break; - envre->tbh= re->tbh; + envre->display_draw = re->display_draw; + envre->ddh = re->ddh; + envre->test_break = re->test_break; + envre->tbh = re->tbh; /* and for the evil stuff; copy the database... */ - envre->totvlak= re->totvlak; - envre->totvert= re->totvert; - envre->tothalo= re->tothalo; - envre->totstrand= re->totstrand; - envre->totlamp= re->totlamp; - envre->sortedhalos= re->sortedhalos; - envre->lights= re->lights; - envre->objecttable= re->objecttable; - envre->customdata_names= re->customdata_names; - envre->raytree= re->raytree; - envre->totinstance= re->totinstance; - envre->instancetable= re->instancetable; - envre->objectinstance= re->objectinstance; - envre->qmcsamplers= re->qmcsamplers; + envre->totvlak = re->totvlak; + envre->totvert = re->totvert; + envre->tothalo = re->tothalo; + envre->totstrand = re->totstrand; + envre->totlamp = re->totlamp; + envre->sortedhalos = re->sortedhalos; + envre->lights = re->lights; + envre->objecttable = re->objecttable; + envre->customdata_names = re->customdata_names; + envre->raytree = re->raytree; + envre->totinstance = re->totinstance; + envre->instancetable = re->instancetable; + envre->objectinstance = re->objectinstance; + envre->qmcsamplers = re->qmcsamplers; return envre; } @@ -188,20 +188,20 @@ static Render *envmap_render_copy(Render *re, EnvMap *env) static void envmap_free_render_copy(Render *envre) { - envre->totvlak= 0; - envre->totvert= 0; - envre->tothalo= 0; - envre->totstrand= 0; - envre->totlamp= 0; - envre->totinstance= 0; - envre->sortedhalos= NULL; - envre->lights.first= envre->lights.last= NULL; - envre->objecttable.first= envre->objecttable.last= NULL; - envre->customdata_names.first= envre->customdata_names.last= NULL; - envre->raytree= NULL; - envre->instancetable.first= envre->instancetable.last= NULL; - envre->objectinstance= NULL; - envre->qmcsamplers= NULL; + envre->totvlak = 0; + envre->totvert = 0; + envre->tothalo = 0; + envre->totstrand = 0; + envre->totlamp = 0; + envre->totinstance = 0; + envre->sortedhalos = NULL; + envre->lights.first = envre->lights.last = NULL; + envre->objecttable.first = envre->objecttable.last = NULL; + envre->customdata_names.first = envre->customdata_names.last = NULL; + envre->raytree = NULL; + envre->instancetable.first = envre->instancetable.last = NULL; + envre->objectinstance = NULL; + envre->qmcsamplers = NULL; RE_FreeRender(envre); } @@ -212,28 +212,28 @@ static void envmap_transmatrix(float mat[][4], int part) { float tmat[4][4], eul[3], rotmat[4][4]; - eul[0]= eul[1]= eul[2]= 0.0; + eul[0] = eul[1] = eul[2] = 0.0; - if (part==0) { /* neg z */ + if (part == 0) { /* neg z */ ; } - else if (part==1) { /* pos z */ - eul[0]= M_PI; + else if (part == 1) { /* pos z */ + eul[0] = M_PI; } - else if (part==2) { /* pos y */ - eul[0]= M_PI/2.0; + else if (part == 2) { /* pos y */ + eul[0] = M_PI / 2.0; } - else if (part==3) { /* neg x */ - eul[0]= M_PI/2.0; - eul[2]= M_PI/2.0; + else if (part == 3) { /* neg x */ + eul[0] = M_PI / 2.0; + eul[2] = M_PI / 2.0; } - else if (part==4) { /* neg y */ - eul[0]= M_PI/2.0; - eul[2]= M_PI; + else if (part == 4) { /* neg y */ + eul[0] = M_PI / 2.0; + eul[2] = M_PI; } - else { /* pos x */ - eul[0]= M_PI/2.0; - eul[2]= -M_PI/2.0; + else { /* pos x */ + eul[0] = M_PI / 2.0; + eul[2] = -M_PI / 2.0; } copy_m4_m4(tmat, mat); @@ -255,7 +255,7 @@ static void env_rotate_scene(Render *re, float mat[][4], int mode) float imat[3][3], pmat[4][4], smat[4][4], tmat[4][4], cmat[3][3], tmpmat[4][4]; int a; - if (mode==0) { + if (mode == 0) { invert_m4_m4(tmat, mat); copy_m3_m4(imat, tmat); } @@ -264,13 +264,13 @@ static void env_rotate_scene(Render *re, float mat[][4], int mode) copy_m3_m4(imat, mat); } - for (obi=re->instancetable.first; obi; obi=obi->next) { + for (obi = re->instancetable.first; obi; obi = obi->next) { /* append or set matrix depending on dupli */ if (obi->flag & R_DUPLI_TRANSFORMED) { copy_m4_m4(tmpmat, obi->mat); mult_m4_m4m4(obi->mat, tmat, tmpmat); } - else if (mode==1) + else if (mode == 1) copy_m4_m4(obi->mat, tmat); else unit_m4(obi->mat); @@ -280,24 +280,24 @@ static void env_rotate_scene(Render *re, float mat[][4], int mode) transpose_m3(obi->nmat); /* indicate the renderer has to use transform matrices */ - if (mode==0) + if (mode == 0) obi->flag &= ~R_ENV_TRANSFORMED; else obi->flag |= R_ENV_TRANSFORMED; } - 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]; + 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); } } - for (go=re->lights.first; go; go= go->next) { - lar= go->lampren; + for (go = re->lights.first; go; go = go->next) { + lar = go->lampren; /* removed here some horrible code of someone in NaN who tried to fix * prototypes... just solved by introducing a correct cmat[3][3] instead @@ -308,14 +308,14 @@ static void env_rotate_scene(Render *re, float mat[][4], int mode) mul_m3_v3(imat, lar->vec); mul_m4_v3(tmat, lar->co); - lar->sh_invcampos[0]= -lar->co[0]; - lar->sh_invcampos[1]= -lar->co[1]; - lar->sh_invcampos[2]= -lar->co[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; + lar->sh_invcampos[2] *= lar->sh_zfac; if (lar->shb) { - if (mode==1) { + if (mode == 1) { invert_m4_m4(pmat, mat); mult_m4_m4m4(smat, lar->shb->viewmat, pmat); mult_m4_m4m4(lar->shb->persmat, lar->shb->winmat, smat); @@ -342,12 +342,12 @@ static void env_layerflags(Render *re, unsigned int notlay) * now (face & ~not) is true */ - notlay= ~notlay; + notlay = ~notlay; - for (obr=re->objecttable.first; obr; obr=obr->next) { - if ((obr->lay & notlay)==0) { - for (a=0; a<obr->totvlak; a++) { - if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak; + for (obr = re->objecttable.first; obr; obr = obr->next) { + if ((obr->lay & notlay) == 0) { + for (a = 0; a < obr->totvlak; a++) { + if ((a & 255) == 0) vlr = obr->vlaknodes[a >> 8].vlak; else vlr++; vlr->flag |= R_HIDDEN; @@ -362,9 +362,9 @@ static void env_hideobject(Render *re, Object *ob) 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; + 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; else vlr++; if (obr->ob == ob) @@ -379,9 +379,9 @@ static void env_showobjects(Render *re) 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; + 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; else vlr++; vlr->flag &= ~R_HIDDEN; @@ -396,12 +396,12 @@ static void env_set_imats(Render *re) Base *base; float mat[4][4]; - base= re->scene->base.first; + base = re->scene->base.first; while (base) { mult_m4_m4m4(mat, re->viewmat, base->object->obmat); invert_m4_m4(base->object->imat, mat); - base= base->next; + base = base->next; } } @@ -420,7 +420,7 @@ static void render_envmap(Render *re, EnvMap *env) /* need a recalc: ortho-render has no correct viewinv */ invert_m4_m4(oldviewinv, re->viewmat); - envre= envmap_render_copy(re, env); + envre = envmap_render_copy(re, env); /* precalc orthmat for object */ copy_m4_m4(orthmat, env->object->obmat); @@ -431,8 +431,8 @@ static void render_envmap(Render *re, EnvMap *env) invert_m4_m4(tmat, mat); copy_m3_m4(env->obimat, tmat); - for (part=0; part<6; part++) { - if (env->type==ENV_PLANE && part!=1) + for (part = 0; part < 6; part++) { + if (env->type == ENV_PLANE && part != 1) continue; re->display_clear(re->dch, envre->result); @@ -456,7 +456,7 @@ static void render_envmap(Render *re, EnvMap *env) env_hideobject(envre, env->object); env_set_imats(envre); - if (re->test_break(re->tbh)==0) { + if (re->test_break(re->tbh) == 0) { RE_TileProcessor(envre); } @@ -464,23 +464,23 @@ static void render_envmap(Render *re, EnvMap *env) env_showobjects(envre); env_rotate_scene(envre, tmat, 0); - if (re->test_break(re->tbh)==0) { - RenderLayer *rl= envre->result->layers.first; + if (re->test_break(re->tbh) == 0) { + RenderLayer *rl = envre->result->layers.first; int y; float *alpha; - ibuf= IMB_allocImBuf(envre->rectx, envre->recty, 24, IB_rect|IB_rectfloat); + ibuf = IMB_allocImBuf(envre->rectx, envre->recty, 24, IB_rect | IB_rectfloat); memcpy(ibuf->rect_float, rl->rectf, ibuf->channels * ibuf->x * ibuf->y * sizeof(float)); if (re->scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) ibuf->profile = IB_PROFILE_LINEAR_RGB; /* envmap renders without alpha */ - alpha= ((float *)ibuf->rect_float)+3; - for (y= ibuf->x*ibuf->y - 1; y>=0; y--, alpha+=4) - *alpha= 1.0; + alpha = ((float *)ibuf->rect_float) + 3; + for (y = ibuf->x * ibuf->y - 1; y >= 0; y--, alpha += 4) + *alpha = 1.0; - env->cube[part]= ibuf; + env->cube[part] = ibuf; } if (re->test_break(re->tbh)) break; @@ -489,9 +489,9 @@ static void render_envmap(Render *re, EnvMap *env) if (re->test_break(re->tbh)) BKE_free_envmapdata(env); else { - if (envre->r.mode & R_OSA) env->ok= ENV_OSA; - else env->ok= ENV_NORMAL; - env->lastframe= re->scene->r.cfra; + if (envre->r.mode & R_OSA) env->ok = ENV_OSA; + else env->ok = ENV_NORMAL; + env->lastframe = re->scene->r.cfra; } /* restore */ @@ -505,27 +505,27 @@ static void render_envmap(Render *re, EnvMap *env) void make_envmaps(Render *re) { Tex *tex; - int do_init = FALSE, depth= 0, trace; + int do_init = FALSE, 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); + trace = (re->r.mode & R_RAYTRACE); re->r.mode &= ~R_RAYTRACE; - re->i.infostr= "Creating Environment maps"; + re->i.infostr = "Creating Environment maps"; re->stats_draw(re->sdh, &re->i); /* 5 = hardcoded max recursion level */ - while (depth<5) { - tex= re->main->tex.first; + while (depth < 5) { + tex = re->main->tex.first; while (tex) { - if (tex->id.us && tex->type==TEX_ENVMAP) { + if (tex->id.us && tex->type == TEX_ENVMAP) { if (tex->env && tex->env->object) { - EnvMap *env= tex->env; + EnvMap *env = tex->env; if (env->object->lay & re->lay) { - if (env->stype==ENV_LOAD) { + if (env->stype == ENV_LOAD) { float orthmat[4][4], mat[4][4], tmat[4][4]; /* precalc orthmat for object */ @@ -545,31 +545,31 @@ void make_envmaps(Render *re) /* 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) + /* free when OSA, and old one isn't OSA */ + if ((re->r.mode & R_OSA) && env->ok == ENV_NORMAL) BKE_free_envmapdata(env); - /* free when size larger */ + /* free when size larger */ else if (env->lastsize < re->r.size) BKE_free_envmapdata(env); - /* free when env is in recalcmode */ + /* free when env is in recalcmode */ else if (env->recalc) BKE_free_envmapdata(env); } - if (env->ok==0 && depth==0) env->recalc= 1; + if (env->ok == 0 && depth == 0) env->recalc = 1; - if (env->ok==0) { + if (env->ok == 0) { do_init = TRUE; render_envmap(re, env); - if (depth==env->depth) env->recalc= 0; + if (depth == env->depth) env->recalc = 0; } } } } } } - tex= tex->id.next; + tex = tex->id.next; } depth++; } @@ -591,55 +591,55 @@ static int envcube_isect(EnvMap *env, const float vec[3], float answ[2]) float labda; int face; - if (env->type==ENV_PLANE) { - face= 1; + if (env->type == ENV_PLANE) { + face = 1; - labda= 1.0f/vec[2]; - answ[0]= env->viewscale*labda*vec[0]; - answ[1]= -env->viewscale*labda*vec[1]; + labda = 1.0f / vec[2]; + answ[0] = env->viewscale * labda * vec[0]; + answ[1] = -env->viewscale * labda * vec[1]; } else { /* which face */ - if ( vec[2] <= -fabsf(vec[0]) && vec[2] <= -fabsf(vec[1]) ) { - face= 0; - labda= -1.0f/vec[2]; - answ[0]= labda*vec[0]; - answ[1]= labda*vec[1]; + if (vec[2] <= -fabsf(vec[0]) && vec[2] <= -fabsf(vec[1]) ) { + face = 0; + labda = -1.0f / vec[2]; + answ[0] = labda * vec[0]; + answ[1] = labda * vec[1]; } else if (vec[2] >= fabsf(vec[0]) && vec[2] >= fabsf(vec[1])) { - face= 1; - labda= 1.0f/vec[2]; - answ[0]= labda*vec[0]; - answ[1]= -labda*vec[1]; + face = 1; + labda = 1.0f / vec[2]; + answ[0] = labda * vec[0]; + answ[1] = -labda * vec[1]; } else if (vec[1] >= fabsf(vec[0])) { - face= 2; - labda= 1.0f/vec[1]; - answ[0]= labda*vec[0]; - answ[1]= labda*vec[2]; + face = 2; + labda = 1.0f / vec[1]; + answ[0] = labda * vec[0]; + answ[1] = labda * vec[2]; } else if (vec[0] <= -fabsf(vec[1])) { - face= 3; - labda= -1.0f/vec[0]; - answ[0]= labda*vec[1]; - answ[1]= labda*vec[2]; + face = 3; + labda = -1.0f / vec[0]; + answ[0] = labda * vec[1]; + answ[1] = labda * vec[2]; } else if (vec[1] <= -fabsf(vec[0])) { - face= 4; - labda= -1.0f/vec[1]; - answ[0]= -labda*vec[0]; - answ[1]= labda*vec[2]; + face = 4; + labda = -1.0f / vec[1]; + answ[0] = -labda * vec[0]; + answ[1] = labda * vec[2]; } else { - face= 5; - labda= 1.0f/vec[0]; - answ[0]= -labda*vec[1]; - answ[1]= labda*vec[2]; + face = 5; + labda = 1.0f / vec[0]; + answ[0] = -labda * vec[1]; + answ[1] = labda * vec[2]; } } - answ[0]= 0.5f+0.5f*answ[0]; - answ[1]= 0.5f+0.5f*answ[1]; + answ[0] = 0.5f + 0.5f * answ[0]; + answ[1] = 0.5f + 0.5f * answ[1]; return face; } @@ -647,23 +647,23 @@ static int envcube_isect(EnvMap *env, const float vec[3], float answ[2]) static void set_dxtdyt(float *dxts, float *dyts, float *dxt, float *dyt, int face) { - if (face==2 || face==4) { - dxts[0]= dxt[0]; - dyts[0]= dyt[0]; - dxts[1]= dxt[2]; - dyts[1]= dyt[2]; + if (face == 2 || face == 4) { + dxts[0] = dxt[0]; + dyts[0] = dyt[0]; + dxts[1] = dxt[2]; + dyts[1] = dyt[2]; } - else if (face==3 || face==5) { - dxts[0]= dxt[1]; - dxts[1]= dxt[2]; - dyts[0]= dyt[1]; - dyts[1]= dyt[2]; + else if (face == 3 || face == 5) { + dxts[0] = dxt[1]; + dxts[1] = dxt[2]; + dyts[0] = dyt[1]; + dyts[1] = dyt[2]; } else { - dxts[0]= dxt[0]; - dyts[0]= dyt[0]; - dxts[1]= dxt[1]; - dyts[1]= dyt[1]; + dxts[0] = dxt[0]; + dyts[0] = dyt[0]; + dxts[1] = dxt[1]; + dyts[1] = dyt[1]; } } @@ -671,34 +671,34 @@ static void set_dxtdyt(float *dxts, float *dyts, float *dxt, float *dyt, int fac int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexResult *texres) { - extern Render R; /* only in this call */ + extern Render R; /* only in this call */ /* texvec should be the already reflected normal */ EnvMap *env; 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; + 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->stype == ENV_LOAD) { + env->ima = tex->ima; if (env->ima && env->ima->ok) { - if (env->cube[1]==NULL) { - ImBuf *ibuf_ima= BKE_image_get_ibuf(env->ima, NULL); + if (env->cube[1] == NULL) { + ImBuf *ibuf_ima = BKE_image_get_ibuf(env->ima, NULL); if (ibuf_ima) envmap_split_ima(env, ibuf_ima); else - env->ok= 0; + env->ok = 0; } } } - if (env->ok==0) { - texres->tin= 0.0; + if (env->ok == 0) { + texres->tin = 0.0; return 0; } @@ -707,8 +707,8 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe if (env->object) mul_m3_v3(env->obimat, vec); else mul_mat3_m4_v3(R.viewinv, vec); - face= envcube_isect(env, vec, sco); - ibuf= env->cube[face]; + face = envcube_isect(env, vec, sco); + ibuf = env->cube[face]; if (osatex) { if (env->object) { @@ -724,45 +724,45 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe /* edges? */ - if (texres->ta<1.0f) { + if (texres->ta < 1.0f) { TexResult texr1, texr2; - texr1.nor= texr2.nor= NULL; - texr1.talpha= texr2.talpha= texres->talpha; /* boxclip expects this initialized */ + 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); + face1 = envcube_isect(env, vec, sco); sub_v3_v3(vec, dxt); - if (face!=face1) { - ibuf= env->cube[face1]; + if (face != face1) { + ibuf = env->cube[face1]; set_dxtdyt(dxts, dyts, dxt, dyt, face1); imagewraposa(tex, NULL, ibuf, sco, dxts, dyts, &texr1); } - else texr1.tr= texr1.tg= texr1.tb= texr1.ta= 0.0; + 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); + face1 = envcube_isect(env, vec, sco); sub_v3_v3(vec, dyt); - if (face!=face1) { - ibuf= env->cube[face1]; + if (face != face1) { + ibuf = env->cube[face1]; set_dxtdyt(dxts, dyts, dxt, dyt, face1); imagewraposa(tex, NULL, ibuf, sco, dxts, dyts, &texr2); } - else texr2.tr= texr2.tg= texr2.tb= texr2.ta= 0.0; + 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; + fac = (texres->ta + texr1.ta + texr2.ta); + if (fac != 0.0f) { + fac = 1.0f / fac; - texres->tr= fac*(texres->ta*texres->tr + texr1.ta*texr1.tr + texr2.ta*texr2.tr ); - texres->tg= fac*(texres->ta*texres->tg + texr1.ta*texr1.tg + texr2.ta*texr2.tg ); - texres->tb= fac*(texres->ta*texres->tb + texr1.ta*texr1.tb + texr2.ta*texr2.tb ); + texres->tr = fac * (texres->ta * texres->tr + texr1.ta * texr1.tr + texr2.ta * texr2.tr); + texres->tg = fac * (texres->ta * texres->tg + texr1.ta * texr1.tg + texr2.ta * texr2.tg); + texres->tb = fac * (texres->ta * texres->tb + texr1.ta * texr1.tb + texr2.ta * texr2.tb); } - texres->ta= 1.0; + texres->ta = 1.0; } } else { @@ -771,7 +771,3 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe return 1; } - -/* ------------------------------------------------------------------------- */ - -/* eof */ diff --git a/source/blender/render/intern/source/volumetric.c b/source/blender/render/intern/source/volumetric.c index b599da48803..75748696a72 100644 --- a/source/blender/render/intern/source/volumetric.c +++ b/source/blender/render/intern/source/volumetric.c @@ -71,7 +71,7 @@ extern struct Render R; /* luminance rec. 709 */ BLI_INLINE float luminance(const float col[3]) { - return (0.212671f*col[0] + 0.71516f*col[1] + 0.072169f*col[2]); + return (0.212671f * col[0] + 0.71516f * col[1] + 0.072169f * col[2]); } /* tracing */ @@ -80,7 +80,7 @@ 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}; + 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); } @@ -89,7 +89,7 @@ static float vol_get_shadow(ShadeInput *shi, LampRen *lar, const float co[3]) Isect is; copy_v3_v3(is.start, co); - if (lar->type==LA_SUN || lar->type==LA_HEMI) { + if (lar->type == LA_SUN || lar->type == LA_HEMI) { is.dir[0] = -lar->vec[0]; is.dir[1] = -lar->vec[1]; is.dir[2] = -lar->vec[2]; @@ -97,17 +97,17 @@ static float vol_get_shadow(ShadeInput *shi, LampRen *lar, const float co[3]) } else { sub_v3_v3v3(is.dir, lar->co, is.start); - is.dist = normalize_v3(is.dir ); + is.dist = normalize_v3(is.dir); } 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; + if (lar->mode & (LA_LAYER | LA_LAYER_SHADOW)) + is.lay = lar->lay; else - is.lay= -1; + is.lay = -1; is.orig.ob = NULL; is.orig.face = NULL; @@ -117,7 +117,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; + lar->last_hit[shi->thread] = is.last_hit; } return visibility; } @@ -128,26 +128,26 @@ static int vol_get_bounds(ShadeInput *shi, const float co[3], const float vec[3] copy_v3_v3(isect->start, co); copy_v3_v3(isect->dir, vec); isect->dist = FLT_MAX; - isect->mode= RE_RAY_MIRROR; + isect->mode = RE_RAY_MIRROR; isect->last_hit = NULL; - isect->lay= -1; - isect->check= RE_CHECK_VLR_NONE; + 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; - isect->orig.ob = (void*)shi->obi; + isect->orig.face = (void *)shi->vlr; + isect->orig.ob = (void *)shi->obi; } else { // if (intersect_type == VOL_BOUNDS_SS) { - isect->skip= 0; - isect->orig.face= NULL; + isect->skip = 0; + isect->orig.face = NULL; isect->orig.ob = NULL; } if (RE_rayobject_raycast(R.raytree, isect)) { - hitco[0] = isect->start[0] + isect->dist*isect->dir[0]; - hitco[1] = isect->start[1] + isect->dist*isect->dir[1]; - hitco[2] = isect->start[2] + isect->dist*isect->dir[2]; + hitco[0] = isect->start[0] + isect->dist * isect->dir[0]; + hitco[1] = isect->start[1] + isect->dist * isect->dir[1]; + hitco[2] = isect->start[2] + isect->dist * isect->dir[2]; return 1; } else { @@ -162,18 +162,18 @@ static void shade_intersection(ShadeInput *shi, float col_r[4], Isect *is) memset(&shi_new, 0, sizeof(ShadeInput)); - shi_new.mask= shi->mask; - shi_new.osatex= shi->osatex; - shi_new.thread= shi->thread; + shi_new.mask = shi->mask; + shi_new.osatex = shi->osatex; + shi_new.thread = shi->thread; shi_new.depth = shi->depth + 1; - shi_new.volume_depth= shi->volume_depth + 1; - shi_new.xs= shi->xs; - shi_new.ys= shi->ys; - shi_new.lay= shi->lay; - shi_new.passflag= SCE_PASS_COMBINED; /* result of tracing needs no pass info */ - shi_new.combinedflag= 0xFFFFFF; /* ray trace does all options */ - shi_new.light_override= shi->light_override; - shi_new.mat_override= shi->mat_override; + shi_new.volume_depth = shi->volume_depth + 1; + shi_new.xs = shi->xs; + shi_new.ys = shi->ys; + shi_new.lay = shi->lay; + shi_new.passflag = SCE_PASS_COMBINED; /* result of tracing needs no pass info */ + 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); @@ -196,13 +196,13 @@ static void vol_trace_behind(ShadeInput *shi, VlakRen *vlr, const float co[3], f copy_v3_v3(isect.dir, shi->view); isect.dist = FLT_MAX; - isect.mode= RE_RAY_MIRROR; + isect.mode = RE_RAY_MIRROR; isect.check = RE_CHECK_VLR_NONE; isect.skip = RE_SKIP_VLR_NEIGHBOUR; - isect.orig.ob = (void*) shi->obi; - isect.orig.face = (void*)vlr; + isect.orig.ob = (void *) shi->obi; + isect.orig.face = (void *)vlr; isect.last_hit = NULL; - isect.lay= -1; + isect.lay = -1; /* check to see if there's anything behind the volume, otherwise shade the sky */ if (RE_rayobject_raycast(R.raytree, &isect)) { @@ -241,11 +241,11 @@ static void vol_get_precached_scattering(Render *re, ShadeInput *shi, float scat /* 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]) +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; + MetaBall *mb = (MetaBall *)ob->data; + MetaElem *ml; /* transform co to meta-element */ float tco[3] = {co[0], co[1], co[2]}; @@ -253,13 +253,13 @@ static float metadensity(Object* ob, const float co[3]) invert_m4_m4(imat, mat); mul_m4_v3(imat, tco); - for (ml = mb->elems.first; ml; ml=ml->next) { + 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); - transpose_m3(bmat); // rot.only, so inverse == transpose + transpose_m3(bmat); // rot.only, so inverse == transpose mul_m3_v3(bmat, tp); /* MB_BALL default */ @@ -269,10 +269,10 @@ static float metadensity(Object* ob, const float co[3]) break; case MB_CUBE: tp[2] = (tp[2] > ml->expz) ? (tp[2] - ml->expz) : ((tp[2] < -ml->expz) ? (tp[2] + ml->expz) : 0.f); - // no break, xy as plane + // no break, xy as plane case MB_PLANE: tp[1] = (tp[1] > ml->expy) ? (tp[1] - ml->expy) : ((tp[1] < -ml->expy) ? (tp[1] + ml->expy) : 0.f); - // no break, x as tube + // no break, x as tube case MB_TUBE: tp[0] = (tp[0] > ml->expx) ? (tp[0] - ml->expx) : ((tp[0] < -ml->expx) ? (tp[0] + ml->expx) : 0.f); } @@ -280,7 +280,7 @@ static float metadensity(Object* ob, const float co[3]) /* ml->rad2 is not set */ dist2 = 1.0f - (dot_v3v3(tp, tp) / (ml->rad * ml->rad)); if (dist2 > 0.f) - dens += (ml->flag & MB_NEGATIVE) ? -ml->s*dist2*dist2*dist2 : ml->s*dist2*dist2*dist2; + dens += (ml->flag & MB_NEGATIVE) ? -ml->s * dist2 * dist2 * dist2 : ml->s * dist2 * dist2 * dist2; } dens -= mb->thresh; @@ -299,7 +299,7 @@ float vol_get_density(struct ShadeInput *shi, const float co[3]) 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; } @@ -311,11 +311,11 @@ float vol_get_density(struct ShadeInput *shi, const float co[3]) 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; + 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); + 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)) @@ -333,8 +333,8 @@ 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); + 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; @@ -353,8 +353,8 @@ static void vol_get_sigma_t(ShadeInput *shi, float sigma_t[3], const float co[3] 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); + 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; @@ -378,13 +378,13 @@ static float vol_get_phasefunc(ShadeInput *UNUSED(shi), float g, const float w[3 * until Blender's shading system supports this better. --matt */ - if (g == 0.f) { /* isotropic */ + if (g == 0.f) { /* isotropic */ return normalize * 1.f; } - else { /* schlick */ + else { /* schlick */ const float k = 1.55f * g - .55f * g * g * g; const float kcostheta = k * dot_v3v3(w, wp); - return normalize * (1.f - k*k) / ((1.f - kcostheta) * (1.f - kcostheta)); + return normalize * (1.f - k * k) / ((1.f - kcostheta) * (1.f - kcostheta)); } /* not used, but here for reference: */ @@ -395,14 +395,14 @@ static float vol_get_phasefunc(ShadeInput *UNUSED(shi), float g, const float w[3 case MA_VOL_PH_MIEMURKY: return normalize * (0.5f + 16.5f * powf(0.5 * (1.f + costheta), 32.f)); case MA_VOL_PH_RAYLEIGH: - return normalize * 3.f/4.f * (1 + costheta * costheta); + return normalize * 3.f / 4.f * (1 + costheta * costheta); case MA_VOL_PH_HG: return normalize * (1.f - g * g) / powf(1.f + g * g - 2.f * g * costheta, 1.5f); case MA_VOL_PH_SCHLICK: { const float k = 1.55f * g - .55f * g * g * g; const float kcostheta = k * costheta; - return normalize * (1.f - k*k) / ((1.f - kcostheta) * (1.f - kcostheta)); + return normalize * (1.f - k * k) / ((1.f - kcostheta) * (1.f - kcostheta)); } case MA_VOL_PH_ISOTROPIC: default: @@ -471,20 +471,20 @@ static void vol_get_transmittance(ShadeInput *shi, float tr[3], const float co[3 static void vol_shade_one_lamp(struct ShadeInput *shi, const float co[3], const float view[3], LampRen *lar, float lacol[3]) { float visifac, lv[3], lampdist; - float tr[3]={1.0, 1.0, 1.0}; + 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->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; + 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; + shi->osatex = 0; do_lamp_tex(lar, lv, shi, lacol, LA_TEXTURE); } @@ -519,7 +519,7 @@ static void vol_shade_one_lamp(struct ShadeInput *shi, const float co[3], const if (ELEM(lar->type, LA_SUN, LA_HEMI)) /* infinite lights, can never be inside volume */ atten_co = hitco; - else if ( lampdist < dist ) { + else if (lampdist < dist) { atten_co = lar->co; } else @@ -558,10 +558,10 @@ void vol_get_scattering(ShadeInput *shi, float scatter_col[3], const float co[3] zero_v3(scatter_col); - lights= get_lights(shi); - for (go=lights->first; go; go= go->next) { + lights = get_lights(shi); + for (go = lights->first; go; go = go->next) { float lacol[3] = {0.f, 0.f, 0.f}; - lar= go->lampren; + lar = go->lampren; if (lar) { vol_shade_one_lamp(shi, co, view, lar, lacol); @@ -598,7 +598,7 @@ static void volumeintegrate(struct ShadeInput *shi, float col[4], const float co float t0 = 0.f; float pt0 = t0; - float t1 = normalize_v3(step_vec); /* returns vector length */ + 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]; @@ -656,7 +656,7 @@ static void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr, int in float hitco[3], col[4] = {0.f, 0.f, 0.f, 0.f}; float *startco, *endco; int trace_behind = 1; - const int ztransp= ((shi->depth==0) && (shi->mat->mode & MA_TRANSP) && (shi->mat->mode & MA_ZTRANSP)); + const int ztransp = ((shi->depth == 0) && (shi->mat->mode & MA_TRANSP) && (shi->mat->mode & MA_ZTRANSP)); Isect is; /* check for shading an internal face a volume object directly */ @@ -669,7 +669,7 @@ static void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr, int in if (ztransp && inside_volume == VOL_SHADE_INSIDE) { MatInside *mi; - int render_this=0; + int render_this = 0; /* don't render the backfaces of ztransp volume materials. * @@ -683,9 +683,9 @@ static void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr, int in * 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) { + for (mi = R.render_volumes_inside.first; mi; mi = mi->next) { /* weak... */ - if (mi->ma == shi->mat) render_this=1; + if (mi->ma == shi->mat) render_this = 1; } if (!render_this) return; } @@ -733,7 +733,7 @@ static void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr, int in } if (ztransp) - col[3] = col[3]>1.f?1.f:col[3]; + col[3] = col[3] > 1.f ? 1.f : col[3]; else col[3] = 1.f; @@ -749,7 +749,7 @@ void shade_volume_shadow(struct ShadeInput *shi, struct ShadeResult *shr, struct { float hitco[3]; float tr[3] = {1.0, 1.0, 1.0}; - Isect is= {{0}}; + Isect is = {{0}}; float *startco, *endco; memset(shr, 0, sizeof(ShadeResult)); @@ -825,5 +825,3 @@ void shade_volume_inside(ShadeInput *shi, ShadeResult *shr) shi->obi = obi_backup; shi->obr = obi_backup->obr; } - - diff --git a/source/blender/render/intern/source/voxeldata.c b/source/blender/render/intern/source/voxeldata.c index 90e6594d888..7d54f77fc90 100644 --- a/source/blender/render/intern/source/voxeldata.c +++ b/source/blender/render/intern/source/voxeldata.c @@ -66,10 +66,10 @@ static int is_vd_res_ok(VoxelData *vd) { /* arbitrary large value so corrupt headers don't break */ - const int min= 1, max= 100000; - return (vd->resol[0] >= min && vd->resol[0] <= max) && - (vd->resol[1] >= min && vd->resol[1] <= max) && - (vd->resol[2] >= min && vd->resol[2] <= max); + const int min = 1, max = 100000; + return (vd->resol[0] >= min && vd->resol[0] <= max) && + (vd->resol[1] >= min && vd->resol[1] <= max) && + (vd->resol[2] >= min && vd->resol[2] <= max); } /* use size_t because the result may exceed INT_MAX */ @@ -86,10 +86,10 @@ static int load_frame_blendervoxel(VoxelData *vd, FILE *fp, int frame) if (is_vd_res_ok(vd) == FALSE) return 0; - vd->dataset = MEM_mapallocN(sizeof(float)*size, "voxel dataset"); + vd->dataset = MEM_mapallocN(sizeof(float) * size, "voxel dataset"); if (vd->dataset == NULL) return 0; - if (fseek(fp, frame*size*sizeof(float)+offset, 0) == -1) + if (fseek(fp, frame * size * sizeof(float) + offset, 0) == -1) return 0; if (fread(vd->dataset, sizeof(float), size, fp) != size) return 0; @@ -108,29 +108,29 @@ static int load_frame_raw8(VoxelData *vd, FILE *fp, int frame) if (is_vd_res_ok(vd) == FALSE) return 0; - vd->dataset = MEM_mapallocN(sizeof(float)*size, "voxel dataset"); + vd->dataset = MEM_mapallocN(sizeof(float) * size, "voxel dataset"); if (vd->dataset == NULL) return 0; - data_c = (char *)MEM_mallocN(sizeof(char)*size, "temporary voxel file reading storage"); + data_c = (char *)MEM_mallocN(sizeof(char) * size, "temporary voxel file reading storage"); if (data_c == NULL) { MEM_freeN(vd->dataset); - vd->dataset= NULL; + vd->dataset = NULL; return 0; } - if (fseek(fp, (frame-1)*size*sizeof(char), 0) == -1) { + if (fseek(fp, (frame - 1) * size * sizeof(char), 0) == -1) { MEM_freeN(data_c); MEM_freeN(vd->dataset); - vd->dataset= NULL; + vd->dataset = NULL; return 0; } if (fread(data_c, sizeof(char), size, fp) != size) { MEM_freeN(data_c); MEM_freeN(vd->dataset); - vd->dataset= NULL; + vd->dataset = NULL; return 0; } - for (i=0; i<size; i++) { + for (i = 0; i < size; i++) { vd->dataset[i] = (float)data_c[i] / 255.f; } MEM_freeN(data_c); @@ -146,7 +146,7 @@ static void load_frame_image_sequence(VoxelData *vd, Tex *tex) Image *ima = tex->ima; ImageUser *tiuser = &tex->iuser; ImageUser iuser = *(tiuser); - int x=0, y=0, z=0; + int x = 0, y = 0, z = 0; float *rf; if (!ima || !tiuser) return; @@ -157,10 +157,10 @@ static void load_frame_image_sequence(VoxelData *vd, Tex *tex) /* find the first valid ibuf and use it to initialize the resolution of the data set */ /* need to do this in advance so we know how much memory to allocate */ - ibuf= BKE_image_get_ibuf(ima, &iuser); + ibuf = BKE_image_get_ibuf(ima, &iuser); while (!ibuf && (iuser.framenr < iuser.frames)) { iuser.framenr++; - ibuf= BKE_image_get_ibuf(ima, &iuser); + ibuf = BKE_image_get_ibuf(ima, &iuser); } if (!ibuf) return; if (!ibuf->rect_float) IMB_float_from_rect(ibuf); @@ -169,23 +169,23 @@ static void load_frame_image_sequence(VoxelData *vd, Tex *tex) 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"); + vd->dataset = MEM_mapallocN(sizeof(float) * vd_resol_size(vd), "voxel dataset"); - for (z=0; z < iuser.frames; z++) { + for (z = 0; z < iuser.frames; z++) { /* get a new ibuf for each frame */ if (z > 0) { iuser.framenr++; - ibuf= BKE_image_get_ibuf(ima, &iuser); + ibuf = BKE_image_get_ibuf(ima, &iuser); if (!ibuf) break; 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++) { + for (y = 0; y < ibuf->y; y++) { + for (x = 0; x < ibuf->x; x++) { /* currently averaged to monchrome */ - vd->dataset[ BLI_VOXEL_INDEX(x, y, z, vd->resol) ] = (rf[0] + rf[1] + rf[2]) * 0.333f; - rf +=4; + vd->dataset[BLI_VOXEL_INDEX(x, y, z, vd->resol)] = (rf[0] + rf[1] + rf[2]) * 0.333f; + rf += 4; } } @@ -198,7 +198,7 @@ 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"); + VoxelDataHeader *h = (VoxelDataHeader *)MEM_mallocN(sizeof(VoxelDataHeader), "voxel data header"); rewind(fp); if (fread(h, sizeof(VoxelDataHeader), 1, fp) != 1) { @@ -206,9 +206,9 @@ static int read_voxeldata_header(FILE *fp, struct VoxelData *vd) return 0; } - vd->resol[0]=h->resolX; - vd->resol[1]=h->resolY; - vd->resol[2]=h->resolZ; + vd->resol[0] = h->resolX; + vd->resol[1] = h->resolY; + vd->resol[2] = h->resolZ; MEM_freeN(h); return 1; @@ -221,8 +221,8 @@ static void init_frame_smoke(VoxelData *vd, float cfra) ModifierData *md; vd->dataset = NULL; - if (vd->object == NULL) return; - ob= vd->object; + if (vd->object == NULL) return; + ob = vd->object; /* draw code for smoke */ if ((md = (ModifierData *)modifiers_findByType(ob, eModifierType_Smoke))) { @@ -231,23 +231,23 @@ static void init_frame_smoke(VoxelData *vd, float cfra) if (smd->domain && smd->domain->fluid) { if (cfra < smd->domain->point_cache[0]->startframe) - ; /* don't show smoke before simulation starts, this could be made an option in the future */ + ; /* don't show smoke before simulation starts, this could be made an option in the future */ else if (vd->smoked_type == TEX_VD_SMOKEHEAT) { size_t totRes; size_t i; float *heat; copy_v3_v3_int(vd->resol, smd->domain->res); - totRes= vd_resol_size(vd); + totRes = vd_resol_size(vd); // scaling heat values from -2.0-2.0 to 0.0-1.0 - vd->dataset = MEM_mapallocN(sizeof(float)*(totRes), "smoke data"); + vd->dataset = MEM_mapallocN(sizeof(float) * (totRes), "smoke data"); heat = smoke_get_heat(smd->domain->fluid); - for (i=0; i<totRes; i++) { - vd->dataset[i] = (heat[i]+2.0f)/4.0f; + for (i = 0; i < totRes; i++) { + vd->dataset[i] = (heat[i] + 2.0f) / 4.0f; } //vd->dataset = smoke_get_heat(smd->domain->fluid); @@ -258,17 +258,17 @@ static void init_frame_smoke(VoxelData *vd, float cfra) float *xvel, *yvel, *zvel; copy_v3_v3_int(vd->resol, smd->domain->res); - totRes= vd_resol_size(vd); + totRes = vd_resol_size(vd); // scaling heat values from -2.0-2.0 to 0.0-1.0 - vd->dataset = MEM_mapallocN(sizeof(float)*(totRes), "smoke data"); + vd->dataset = MEM_mapallocN(sizeof(float) * (totRes), "smoke data"); xvel = smoke_get_velocity_x(smd->domain->fluid); yvel = smoke_get_velocity_y(smd->domain->fluid); zvel = smoke_get_velocity_z(smd->domain->fluid); - for (i=0; i<totRes; i++) { - vd->dataset[i] = sqrt(xvel[i]*xvel[i] + yvel[i]*yvel[i] + zvel[i]*zvel[i])*3.0f; + for (i = 0; i < totRes; i++) { + vd->dataset[i] = sqrt(xvel[i] * xvel[i] + yvel[i] * yvel[i] + zvel[i] * zvel[i]) * 3.0f; } } @@ -286,10 +286,10 @@ static void init_frame_smoke(VoxelData *vd, float cfra) } /* TODO: is_vd_res_ok(rvd) doesnt check this resolution */ - totRes= vd_resol_size(vd); + totRes = vd_resol_size(vd); /* always store copy, as smoke internal data can change */ - vd->dataset = MEM_mapallocN(sizeof(float)*(totRes), "smoke data"); - memcpy(vd->dataset, density, sizeof(float)*totRes); + vd->dataset = MEM_mapallocN(sizeof(float) * (totRes), "smoke data"); + memcpy(vd->dataset, density, sizeof(float) * totRes); } // end of fluid condition } } @@ -300,7 +300,7 @@ static void init_frame_smoke(VoxelData *vd, float cfra) (void)vd; (void)cfra; - vd->dataset= NULL; + vd->dataset = NULL; #endif } @@ -342,7 +342,7 @@ void cache_voxeldata(Tex *tex, int scene_frame) if (!fp) return; if (read_voxeldata_header(fp, vd)) - load_frame_blendervoxel(vd, fp, curframe-1); + load_frame_blendervoxel(vd, fp, curframe - 1); fclose(fp); return; @@ -362,17 +362,17 @@ void make_voxeldata(struct Render *re) { Tex *tex; - re->i.infostr= "Loading voxel datasets"; + re->i.infostr = "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) { + 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->i.infostr = NULL; re->stats_draw(re->sdh, &re->i); } @@ -383,7 +383,7 @@ int voxeldatatex(struct Tex *tex, const float texvec[3], struct TexResult *texre VoxelData *vd = tex->vd; float co[3], offset[3] = {0.5, 0.5, 0.5}; - if (vd->dataset==NULL) { + if (vd->dataset == NULL) { texres->tin = 0.0f; return 0; } @@ -448,5 +448,3 @@ int voxeldatatex(struct Tex *tex, const float texvec[3], struct TexResult *texre return retval; } - - diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index d7d55885f37..1cf58b4345b 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -2174,8 +2174,8 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) /* Options panel */ selected = RNA_boolean_get(op->ptr, "selected"); apply_modifiers = RNA_boolean_get(op->ptr, "apply_modifiers"); - include_bone_children = RNA_boolean_get(op->ptr, "include_bone_children"); - use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation"); + include_bone_children = RNA_boolean_get(op->ptr, "include_bone_children"); + use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation"); second_life = RNA_boolean_get(op->ptr, "second_life"); /* get editmode results */ diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp index d0d940a2e42..ce183b37498 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp +++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp @@ -91,10 +91,10 @@ void SCA_PropertySensor::PrecalculateRangeExpression() //The context is needed to retrieve the property at runtime but it creates //loop of references pars.SetContext(this->AddRef()); - STR_String checkstr = "(" + m_checkpropval + " <= " - + m_checkpropname + ") && ( " - + m_checkpropname + " <= " - + m_checkpropmaxval + ")"; + STR_String checkstr = ("(" + m_checkpropval + " <= " + + m_checkpropname + ") && ( " + + m_checkpropname + " <= " + + m_checkpropmaxval + ")"); m_range_expr = pars.ProcessText(checkstr); } diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp index 40dba3bf03a..b0fc1431482 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp +++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp @@ -141,8 +141,7 @@ bool SCA_RandomActuator::Update() int res; /* The [0, 1] interval is projected onto the [min, max+1] domain, */ /* and then rounded. */ - res = (int) floor( ((m_parameter2 - m_parameter1 + 1) * m_base->DrawFloat()) - + m_parameter1); + res = (int)floor( ((m_parameter2 - m_parameter1 + 1) * m_base->DrawFloat()) + m_parameter1); tmpval = new CIntValue(res); } break; @@ -172,8 +171,7 @@ bool SCA_RandomActuator::Update() } break; case KX_RANDOMACT_FLOAT_UNIFORM: { - float res = ((m_parameter2 - m_parameter1) * m_base->DrawFloat()) - + m_parameter1; + float res = ((m_parameter2 - m_parameter1) * m_base->DrawFloat()) + m_parameter1; tmpval = new CFloatValue(res); } break; @@ -239,8 +237,7 @@ bool SCA_RandomActuator::Update() /* controlling parameter. Using the 'normal' exponent is not very */ /* intuitive... */ /* tmpval = new CFloatValue( (1.0 / m_parameter1) */ - tmpval = new CFloatValue( (m_parameter1) - * (-log(1.0 - m_base->DrawFloat())) ); + tmpval = new CFloatValue((m_parameter1) * (-log(1.0 - m_base->DrawFloat()))); } break; diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 4f0ae4261c9..695ad1f945c 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -2267,10 +2267,10 @@ KX_PYMETHODDEF_DOC(KX_Scene, addObject, !ConvertPythonToGameObject(pyother, &other, false, "scene.addObject(object, other, time): KX_Scene (second argument)") ) return NULL; - if (!m_inactivelist->SearchValue(ob)) { - PyErr_Format(PyExc_ValueError, "scene.addObject(object, other, time): KX_Scene (second argument): object does not belong to scene"); - return NULL; - } + if (!m_inactivelist->SearchValue(ob)) { + PyErr_Format(PyExc_ValueError, "scene.addObject(object, other, time): KX_Scene (second argument): object does not belong to scene"); + return NULL; + } SCA_IObject* replica = AddReplicaObject((SCA_IObject*)ob, other, time); // release here because AddReplicaObject AddRef's diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 767d99583b8..343cb549337 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -719,8 +719,8 @@ void CcdPhysicsEnvironment::processFhSprings(double curTime,float interval) { if (ctrl->getConstructionInfo().m_do_fh) { - btVector3 lspot = cl_object->getCenterOfMassPosition() - + rayDirLocal * resultCallback.m_closestHitFraction; + btVector3 lspot = cl_object->getCenterOfMassPosition() + + rayDirLocal * resultCallback.m_closestHitFraction; diff --git a/source/gameengine/VideoTexture/FilterColor.h b/source/gameengine/VideoTexture/FilterColor.h index 9b1976cf40f..cd61900bbda 100644 --- a/source/gameengine/VideoTexture/FilterColor.h +++ b/source/gameengine/VideoTexture/FilterColor.h @@ -91,9 +91,9 @@ protected: /// calculate one color component unsigned char calcColor (unsigned int val, short idx) { - return (((m_matrix[idx][0] * (VT_R(val)) + m_matrix[idx][1] * (VT_G(val)) - + m_matrix[idx][2] * (VT_B(val)) + m_matrix[idx][3] * (VT_A(val)) - + m_matrix[idx][4]) >> 8) & 0xFF); + return (((m_matrix[idx][0] * (VT_R(val)) + m_matrix[idx][1] * (VT_G(val)) + + m_matrix[idx][2] * (VT_B(val)) + m_matrix[idx][3] * (VT_A(val)) + + m_matrix[idx][4]) >> 8) & 0xFF); } /// filter pixel template, source int buffer |