From c3e1fce77552b5626d2939710cb6d0020891d218 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 21 May 2012 12:52:28 +0000 Subject: Cycles: add Object Info node, with outputs object location, object/material pass index, and a random number unique to the instance of the object. This can be useful to give some variation to a single material assigned to multiple instances, either manually controlled through the object index, based on the object location, or randomized for each instance. http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/More#Object_Info --- intern/cycles/util/util_hash.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'intern/cycles/util/util_hash.h') diff --git a/intern/cycles/util/util_hash.h b/intern/cycles/util/util_hash.h index 16901dab38e..c31b46e1580 100644 --- a/intern/cycles/util/util_hash.h +++ b/intern/cycles/util/util_hash.h @@ -19,13 +19,15 @@ #ifndef __UTIL_HASH_H__ #define __UTIL_HASH_H__ +#include "util_types.h" + CCL_NAMESPACE_BEGIN -static inline unsigned int hash_int_2d(unsigned int kx, unsigned int ky) +static inline uint hash_int_2d(uint kx, uint ky) { #define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) - unsigned int a, b, c; + uint a, b, c; a = b = c = 0xdeadbeef + (2 << 2) + 13; a += kx; @@ -44,11 +46,21 @@ static inline unsigned int hash_int_2d(unsigned int kx, unsigned int ky) #undef rot } -static inline unsigned int hash_int(unsigned int k) +static inline uint hash_int(uint k) { return hash_int_2d(k, 0); } +static inline uint hash_string(const char *str) +{ + uint i = 0, c; + + while ((c = *str++)) + i = i * 37 + c; + + return i; +} + CCL_NAMESPACE_END #endif /* __UTIL_HASH_H__ */ -- cgit v1.2.3