Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/BKE_attribute_math.hh
| Show All 11 Lines | |||||
| * You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
| * along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| */ | */ | ||||
| #include "BLI_color.hh" | #include "BLI_color.hh" | ||||
| #include "BLI_float2.hh" | #include "BLI_float2.hh" | ||||
| #include "BLI_float3.hh" | #include "BLI_float3.hh" | ||||
| #include "BLI_hash.h" | |||||
| #include "DNA_customdata_types.h" | #include "DNA_customdata_types.h" | ||||
| namespace blender::attribute_math { | namespace blender::attribute_math { | ||||
| /** | /** | ||||
| * Utility function that simplifies calling a templated function based on a custom data type. | * Utility function that simplifies calling a templated function based on a custom data type. | ||||
| */ | */ | ||||
| template<typename Func> | template<typename Func> | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
| template<> | template<> | ||||
| inline Color4f mix3(const float3 &weights, const Color4f &v0, const Color4f &v1, const Color4f &v2) | inline Color4f mix3(const float3 &weights, const Color4f &v0, const Color4f &v1, const Color4f &v2) | ||||
| { | { | ||||
| Color4f result; | Color4f result; | ||||
| interp_v4_v4v4v4(result, v0, v1, v2, weights); | interp_v4_v4v4v4(result, v0, v1, v2, weights); | ||||
| return result; | return result; | ||||
| } | } | ||||
| static float noise_from_index_and_mutator(const uint32_t seed, const uint32_t mutator) | |||||
| { | |||||
| const int combined_hash = BLI_hash_int_2d(seed, mutator); | |||||
| return BLI_hash_int_01(combined_hash); | |||||
| } | |||||
| /* Return a random value based on the two hashes. */ | |||||
JacquesLucke: Comment is at wrong place. | |||||
| template<typename T> T random_value(const uint32_t seed); | |||||
JacquesLuckeUnsubmitted Done Inline ActionsThe naming is a bit tricky here. random_value has different meanings for different type. The behavior is basically determined by the needs of the Random Attribute node and might not apply to different contexts. Therefore it might be better to leave these functions in node_geo_attribute_random.cc. JacquesLucke: The naming is a bit tricky here. `random_value` has different meanings for different type. The… | |||||
| template<> inline bool random_value(const uint32_t seed) | |||||
| { | |||||
| return BLI_hash_int_01(seed) > 0.5f; | |||||
| } | |||||
| template<> inline int random_value(const uint32_t seed) | |||||
JacquesLuckeUnsubmitted Done Inline ActionsThat doesn't seem to make too much sense.. Not sure if the seed is randomized before already. JacquesLucke: That doesn't seem to make too much sense.. Not sure if the seed is randomized before already. | |||||
| { | |||||
| return seed; | |||||
| } | |||||
| template<> inline float random_value(const uint32_t seed) | |||||
| { | |||||
| return BLI_hash_int_01(seed); | |||||
| } | |||||
| template<> inline float3 random_value(const uint32_t seed) | |||||
| { | |||||
| const float x = noise_from_index_and_mutator(seed, 435109); | |||||
| const float y = noise_from_index_and_mutator(seed, 380867); | |||||
| const float z = noise_from_index_and_mutator(seed, 1059217); | |||||
| return float3(x, y, z); | |||||
| } | |||||
| template<> inline Color4f random_value(const uint32_t seed) | |||||
JacquesLuckeUnsubmitted Done Inline ActionsRandom colors shouldn't be generated like this. Usually you don't want transparency to be random. JacquesLucke: Random colors shouldn't be generated like this. Usually you don't want transparency to be… | |||||
| { | |||||
| const float r = noise_from_index_and_mutator(seed, 1283591); | |||||
| const float g = noise_from_index_and_mutator(seed, 850177); | |||||
| const float b = noise_from_index_and_mutator(seed, 735391); | |||||
| const float a = noise_from_index_and_mutator(seed, 442319); | |||||
| return Color4f(r, g, b, a); | |||||
| } | |||||
| } // namespace blender::attribute_math | } // namespace blender::attribute_math | ||||
Comment is at wrong place.