Text archives Help
- From: bigler@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1421 - trunk/Core/Math
- Date: Fri, 22 Jun 2007 15:33:49 -0600 (MDT)
Author: bigler
Date: Fri Jun 22 15:33:49 2007
New Revision: 1421
Modified:
trunk/Core/Math/Noise.cc
trunk/Core/Math/Noise.h
Log:
Core/Math/Noise.cc
Core/Math/Noise.h
Start of SSE scalar noise function.
Modified: trunk/Core/Math/Noise.cc
==============================================================================
--- trunk/Core/Math/Noise.cc (original)
+++ trunk/Core/Math/Noise.cc Fri Jun 22 15:33:49 2007
@@ -3,6 +3,10 @@
#include <Core/Math/MiscMath.h>
#include <Core/Math/Noise.h>
+#ifdef MANTA_SSE
+# include <SSEDefs.h>
+#endif
+
using namespace SCIRun;
using namespace std;
@@ -325,6 +329,31 @@
return Interpolate( value_0, value_1, fade_x );
}
+ // This will return a random hash number from 0 to 255
+ static __m128i permutationSSE(cosnt __m128i& index)
+ {
+// if (val & 1)
+// val = (val >> 1) ^ mask;
+// else
+// val = val >> 1;
+ __m128i index_masked = _mm_and_si128(index, _mm_set_epi32(0xFF));
+ __m128i ifmask = _mm_cmpeq_epi32(_mm_and_si128(index_masked,
_mm_set_epi32(1)), _mm_set_epi32(1));
+ return _mm_xor_si128(_mm_srli_epi32(index_masked, _mm_srli_epi32(1)),
_mm_and_si128(ifmask, _mm_set_epi32(0xB8)));
+ }
+
+ __m128 ScalarNoiseSSE( const __m128& location_x,
+ const __m128& location_y,
+ const __m128& location_z)
+ {
+ __m128 offset_of_x = fracSSE(location_x);
+ __m128i integer_of_x = _mm_cvttps_epi32(_mm_sub_ps(location_x,
offset_of_x));
+ __m128 fade_x = _mm_mul_ps(_mm_mul_ps(offset_of_x, offset_of_x),
_mm_mul_ps(offset_of_x, _mm_add_ps(_mm_mul_ps(offset_of_x,
_mm_sub_ps(_mm_mul_ps(offset_of_x, _mm_set_ps1(6.f)), _mm_set_ps1(15.f))),
_mm_set_ps1(10.f))));
+ __m128i hash_0 = permutationSSE(integer_of_x);
+ __m128i hash_00 = permutationSSE(_mm_add_ps(hash_0, integer_of_y));
+ __m128i hash_000 = permutationSSE(_mm_add_ps(hash_00, integer_of_z));
+ __m128i hash_001 = permutationSSE(_mm_add_ps(_mm_add_ps(hash_00,
integer_of_z), _mm_set_epi32(1)));
+ }
+
Vector const VectorNoise( Vector const& location )
{
int integer_of_x = Floor( location.x() );
Modified: trunk/Core/Math/Noise.h
==============================================================================
--- trunk/Core/Math/Noise.h (original)
+++ trunk/Core/Math/Noise.h Fri Jun 22 15:33:49 2007
@@ -3,6 +3,7 @@
#include <MantaTypes.h>
#include <Core/Geometry/Vector.h>
+#include <MantaSSE.h>
namespace Manta {
@@ -17,6 +18,18 @@
* @return a signed scalar noise value
*/
Real ScalarNoise( Vector const& location );
+
+#ifdef MANTA_SSE
+ /**
+ * This doesn't use any precomputed tables, but explitly computes
+ * the random number index (P) and the gradient (G).
+ *
+ * The gradient table is the one from Perlin's improved noise paper.
+ */
+ __m128 ScalarNoiseSSE( const __m128& location_x,
+ const __m128& location_y,
+ const __m128& location_z);
+#endif
/**
* Computes the vector-valued Perlin noise for a given point. The
- [MANTA] r1421 - trunk/Core/Math, bigler, 06/22/2007
Archive powered by MHonArc 2.6.16.