Browse Source

Swizzle clean-up

athile 14 năm trước cách đây
mục cha
commit
44bd721a41
2 tập tin đã thay đổi với 99 bổ sung352 xóa
  1. 67 18
      glm/core/_swizzle.hpp
  2. 32 334
      test/core/core_type_vec3.cpp

+ 67 - 18
glm/core/_swizzle.hpp

@@ -56,9 +56,12 @@ namespace detail
         Template parameters:
 
         ValueType = type of scalar values (e.g. float, double)
-        VecType   = class the swizzle is applies to (e.g. vector3f)
+        VecType   = class the swizzle is applies to (e.g. tvec3<float>)
         N         = number of components in the vector (e.g. 3)
         E0...3    = what index the n-th element of this swizzle refers to in the unswizzled vec
+        
+        DUPLICATE_ELEMENTS = 1 if there is a repeated element, 0 otherwise (used to specialize swizzles
+            containing duplicate elements so that they cannot be used as r-values).            
     */
     template <typename DerivedType, typename ValueType, typename VecType, int N, int E0, int E1, int E2, int E3, int DUPLICATE_ELEMENTS>
     struct swizzle_base
@@ -69,11 +72,8 @@ namespace detail
 
         swizzle_base& operator= (const ValueType& t)
         {
-            static const int offset_dst[4] = { E0, E1, E2, E3 };
-
             for (int i = 0; i < N; ++i)
-                elem(offset_dst[i]) = t;
-
+                (*this)[i] = t;
             return *this;
         }
 
@@ -118,18 +118,29 @@ namespace detail
             _apply_op(that, op());
         }
 
+        value_type& operator[]  (size_t i)
+        {
+            static const int offset_dst[4] = { E0, E1, E2, E3 };
+            return elem(offset_dst[i]);
+        }
+        value_type  operator[]  (size_t) const
+        {
+            static const int offset_dst[4] = { E0, E1, E2, E3 };
+            return elem(offset_dst[i]);
+        }
+
     protected:
         template <typename T>
         void _apply_op(const VecType& that, T op)
         {
-            static const int offset_dst[4] = { E0, E1, E2, E3 };
-
-            // Make a copy of the data in this == &that
+            // Make a copy of the data in this == &that.
+            // The copier should optimize out the copy in cases where the function is
+            // properly inlined and the copy is not necessary.
             ValueType t[N];
             for (int i = 0; i < N; ++i)
                 t[i] = that[i];
             for (int i = 0; i < N; ++i)
-                op( elem(offset_dst[i]), t[i] );
+                op( (*this)[i], t[i] );
         }
 
         value_type&         elem   (size_t i)       { return (reinterpret_cast<value_type*>(_buffer))[i]; }
@@ -141,6 +152,7 @@ namespace detail
         char    _buffer[sizeof(value_type) * N];
     };
 
+    //! Specialization for swizzles containing duplicate elements.  These cannot be modified.
     template <typename DerivedType, typename ValueType, typename VecType, int N, int E0, int E1, int E2, int E3>
     struct swizzle_base<DerivedType,ValueType,VecType,N,E0,E1,E2,E3,1>
     {
@@ -150,6 +162,12 @@ namespace detail
 
         struct Stub {};
         swizzle_base& operator= (const Stub& that) {}
+
+        value_type  operator[]  (size_t) const
+        {
+            static const int offset_dst[4] = { E0, E1, E2, E3 };
+            return elem(offset_dst[i]);
+        }
           
     protected:
         value_type&         elem   (size_t i)       { return (reinterpret_cast<value_type*>(_buffer))[i]; }
@@ -257,6 +275,9 @@ namespace detail
 #define _GLM_SWIZZLE_TYPE1       glm::detail::swizzle_base<S0,T,P,N,E0,E1,E2,E3,D0>
 #define _GLM_SWIZZLE_TYPE2       glm::detail::swizzle_base<S1,T,P,N,F0,F1,F2,F3,D1>
 
+//
+// Wrapper for a binary operator (e.g. u.yy + v.zy)
+//
 #define _GLM_SWIZZLE_VECTOR_BINARY_OPERATOR_IMPLEMENTATION(OPERAND)\
     _GLM_SWIZZLE_TEMPLATE2 \
     typename P operator OPERAND ( const _GLM_SWIZZLE_TYPE1& a, const _GLM_SWIZZLE_TYPE2& b) \
@@ -274,6 +295,9 @@ namespace detail
         return a OPERAND static_cast<const S0&>(b).cast(); \
     }
 
+//
+// Wrapper for a operand between a swizzle and a binary (e.g. 1.0f - u.xyz)
+//
 #define _GLM_SWIZZLE_SCALAR_BINARY_OPERATOR_IMPLEMENTATION(OPERAND)\
     _GLM_SWIZZLE_TEMPLATE1 \
     typename P operator OPERAND ( const _GLM_SWIZZLE_TYPE1& a, const typename T& b) \
@@ -286,6 +310,10 @@ namespace detail
         return a OPERAND static_cast<const S0&>(b).cast(); \
     }
 
+//
+// Macro for wrapping a function taking one argument (e.g. abs())
+// Needs to wrap all 12 swizzle types.
+//
 #define _GLM_SWIZZLE_FUNCTION_1_ARGS(RETURN_TYPE,FUNCTION)\
     template <typename T, typename P, int E0, int E1> \
     typename glm::detail::swizzle2<T,P,E0,E1>::RETURN_TYPE FUNCTION(const glm::detail::swizzle2<T,P,E0,E1>& a)  \
@@ -333,6 +361,14 @@ namespace detail
         return FUNCTION(a.cast()); \
     } 
 
+//
+// Macro for wrapping a function taking two vector arguments (e.g. dot()).
+//
+// Needs to wrap all 12 swizzle types when the same type is passed as
+// both arguments (u.xyz, v.xyz), wrappers for when the arguments are 
+// different types (u.xyz, v.yyx), and lastly wrappers for swizzle/unswizzled
+// combinations (u.xyz, v).
+//
 #define _GLM_SWIZZLE_FUNCTION_2_ARGS(RETURN_TYPE,FUNCTION)\
     _GLM_SWIZZLE_TEMPLATE2\
     typename S0::RETURN_TYPE FUNCTION(const typename _GLM_SWIZZLE_TYPE1& a, const typename _GLM_SWIZZLE_TYPE2& b)\
@@ -400,6 +436,9 @@ namespace detail
         return FUNCTION(a.cast(), b.cast()); \
     }
 
+//
+// Macro for wrapping a function take 2 vec arguments followed by a scalar (e.g. mix()).
+//
 #define _GLM_SWIZZLE_FUNCTION_2_ARGS_SCALAR(RETURN_TYPE,FUNCTION)\
     _GLM_SWIZZLE_TEMPLATE2\
     typename S0::RETURN_TYPE FUNCTION(const typename _GLM_SWIZZLE_TYPE1& a, const typename _GLM_SWIZZLE_TYPE2& b, const typename S0::value_type& c)\
@@ -483,16 +522,26 @@ namespace glm
         _GLM_SWIZZLE_VECTOR_BINARY_OPERATOR_IMPLEMENTATION(/)
     }
 
-    _GLM_SWIZZLE_FUNCTION_1_ARGS(vec_type,    abs);
-    _GLM_SWIZZLE_FUNCTION_1_ARGS(vec_type,    acos);
-    _GLM_SWIZZLE_FUNCTION_1_ARGS(vec_type,    acosh);
-    _GLM_SWIZZLE_FUNCTION_1_ARGS(vec_type,    all);
-    _GLM_SWIZZLE_FUNCTION_1_ARGS(vec_type,    any);
+    //
+    // Swizzles are distinct types from the unswizzled type.  The below macros will
+    // provide template specializations for the swizzle types for the given functions
+    // so that the compiler does not have any ambiguity to choosing how to handle
+    // the function.
+    //
+    // The alternative is to use the operator()() when calling the function in order
+    // to explicitly convert the swizzled type to the unswizzled type.
+    //
+
+    //_GLM_SWIZZLE_FUNCTION_1_ARGS(vec_type,    abs);
+    //_GLM_SWIZZLE_FUNCTION_1_ARGS(vec_type,    acos);
+    //_GLM_SWIZZLE_FUNCTION_1_ARGS(vec_type,    acosh);
+    //_GLM_SWIZZLE_FUNCTION_1_ARGS(vec_type,    all);
+    //_GLM_SWIZZLE_FUNCTION_1_ARGS(vec_type,    any);
     
-    _GLM_SWIZZLE_FUNCTION_2_ARGS(value_type,  dot);
-    _GLM_SWIZZLE_FUNCTION_2_ARGS(vec_type,    cross);
-    _GLM_SWIZZLE_FUNCTION_2_ARGS(vec_type,    step);    
-    _GLM_SWIZZLE_FUNCTION_2_ARGS_SCALAR(vec_type, mix);
+    //_GLM_SWIZZLE_FUNCTION_2_ARGS(value_type,  dot);
+    //_GLM_SWIZZLE_FUNCTION_2_ARGS(vec_type,    cross);
+    //_GLM_SWIZZLE_FUNCTION_2_ARGS(vec_type,    step);    
+    //_GLM_SWIZZLE_FUNCTION_2_ARGS_SCALAR(vec_type, mix);
 }
 
 

+ 32 - 334
test/core/core_type_vec3.cpp

@@ -200,347 +200,45 @@ int test_vec3_swizzle_functions()
 {
     int Error = 0;
 
-    // vec3 - working as expected
+    //
+    // NOTE: template functions cannot pick up the implicit conversion from
+    // a swizzle to the unswizzled type, therefore the operator() must be 
+    // used.  E.g.:
+    //
+    // glm::dot(u.xy, v.xy);        <--- Compile error
+    // glm::dot(u.xy(), v.xy());    <--- Compiles correctly
+    //
+
+    float r;
+
+    // vec2
+    glm::vec2 a(1, 2);
+    glm::vec2 b(10, 20);
+    r = glm::dot(a, b);                 Error += (int(r) == 50) ? 0 : 1;
+    r = glm::dot(a.xy(), b.xy());       Error += (int(r) == 50) ? 0 : 1;
+    r = glm::dot(a.xy(), b.yy());       Error += (int(r) == 60) ? 0 : 1;
+
+    // vec3
     glm::vec3 q, u, v;
     u = glm::vec3(1, 2, 3);
     v = glm::vec3(10, 20, 30);
-    glm::dot(u, v);
-    glm::dot(u.xyz, v.zyz);
-    glm::dot(u, v.zyx);
-    glm::dot(u.xyz, v);
-
-    // vec2 - not working! how is vec3 working and not vec2?
-    glm::vec2 a, b;
-    glm::dot(a, b);
-    glm::dot(a.xy, b.yy);
-    glm::dot(a.xy, b.xy);
-    glm::dot(u.xy, v.xy);
-
-    glm::dot(glm::vec4(1,2,3,4).xyz, v);
-
-    glm::vec4 r, s, t;
-
-    r = glm::vec4(1, 2, 3, 4);
-    s = glm::vec4(10, 20, 30, 40);
-
-    glm::dot(r, s);
-    glm::dot(r.xyzw, s.xyzw);
-    glm::dot(r.xyz, s.xyz);
-
-    glm::cross(u, v);
-    glm::cross(u.zyx, v);
-    glm::cross(u.xxz, v.yyx);
+    r = glm::dot(u, v);                 Error += (int(r) == 140) ? 0 : 1;
+    r = glm::dot(u.xyz(), v.zyz());     Error += (int(r) == 160) ? 0 : 1;
+    r = glm::dot(u, v.zyx());           Error += (int(r) == 100) ? 0 : 1;
+    r = glm::dot(u.xyz(), v);           Error += (int(r) == 140) ? 0 : 1;
+    r = glm::dot(u.xy(), v.xy());       Error += (int(r) == 50) ? 0 : 1;
+
+    // vec4
+    glm::vec4 s, t;
+    s = glm::vec4(1, 2, 3, 4);
+    t = glm::vec4(10, 20, 30, 40);
+    r = glm::dot(s, t);                 Error += (int(r) == 300) ? 0 : 1;
+    r = glm::dot(s.xyzw(), t.xyzw());   Error += (int(r) == 300) ? 0 : 1;
+    r = glm::dot(s.xyz(), t.xyz());     Error += (int(r) == 140) ? 0 : 1;
 
     return Error;
 }
 
-#if 1
-using namespace glm;
-
-//
-// GLSL textureless classic 4D noise "cnoise",
-// with an RSL-style periodic variant "pnoise".
-// Author:  Stefan Gustavson ([email protected])
-// Version: 2011-08-22
-//
-// Many thanks to Ian McEwan of Ashima Arts for the
-// ideas for permutation and gradient selection.
-//
-// Copyright (c) 2011 Stefan Gustavson. All rights reserved.
-// Distributed under the MIT license. See LICENSE file.
-// https://github.com/ashima/webgl-noise
-//
-
-vec4 mod289(vec4 x)
-{
-  return x - floor(x * (1.0 / 289.0)) * 289.0;
-}
-
-vec4 permute(vec4 x)
-{
-  return mod289(((x*34.0)+1.0)*x);
-}
-
-vec4 taylorInvSqrt(vec4 r)
-{
-  return 1.79284291400159 - 0.85373472095314 * r;
-}
-
-vec4 fade(vec4 t) {
-  return t*t*t*(t*(t*6.0-15.0)+10.0);
-}
-
-// Classic Perlin noise
-float cnoise(vec4 P)
-{
-  vec4 Pi0 = floor(P); // Integer part for indexing
-  vec4 Pi1 = Pi0 + 1.0; // Integer part + 1
-  Pi0 = mod289(Pi0);
-  Pi1 = mod289(Pi1);
-  vec4 Pf0 = fract(P); // Fractional part for interpolation
-  vec4 Pf1 = Pf0 - 1.0; // Fractional part - 1.0
-  vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
-  vec4 iy = vec4(Pi0.yy(), Pi1.yy());
-  vec4 iz0 = vec4(Pi0.zzzz());
-  vec4 iz1 = vec4(Pi1.zzzz());
-  vec4 iw0 = vec4(Pi0.wwww());
-  vec4 iw1 = vec4(Pi1.wwww);
-
-  vec4 ixy = permute(permute(ix) + iy);
-  vec4 ixy0 = permute(ixy + iz0);
-  vec4 ixy1 = permute(ixy + iz1);
-  vec4 ixy00 = permute(ixy0 + iw0);
-  vec4 ixy01 = permute(ixy0 + iw1);
-  vec4 ixy10 = permute(ixy1 + iw0);
-  vec4 ixy11 = permute(ixy1 + iw1);
-
-  vec4 gx00 = ixy00 * (1.0 / 7.0);
-  vec4 gy00 = floor(gx00) * (1.0 / 7.0);
-  vec4 gz00 = floor(gy00) * (1.0 / 6.0);
-  gx00 = fract(gx00) - 0.5;
-  gy00 = fract(gy00) - 0.5;
-  gz00 = fract(gz00) - 0.5;
-  vec4 gw00 = vec4(0.75) - abs(gx00) - abs(gy00) - abs(gz00);
-  vec4 sw00 = step(gw00, vec4(0.0));
-  gx00 -= sw00 * (step(0.0, gx00) - 0.5);
-  gy00 -= sw00 * (step(0.0, gy00) - 0.5);
-
-  vec4 gx01 = ixy01 * (1.0 / 7.0);
-  vec4 gy01 = floor(gx01) * (1.0 / 7.0);
-  vec4 gz01 = floor(gy01) * (1.0 / 6.0);
-  gx01 = fract(gx01) - 0.5;
-  gy01 = fract(gy01) - 0.5;
-  gz01 = fract(gz01) - 0.5;
-  vec4 gw01 = vec4(0.75) - abs(gx01) - abs(gy01) - abs(gz01);
-  vec4 sw01 = step(gw01, vec4(0.0));
-  gx01 -= sw01 * (step(0.0, gx01) - 0.5);
-  gy01 -= sw01 * (step(0.0, gy01) - 0.5);
-
-  vec4 gx10 = ixy10 * (1.0 / 7.0);
-  vec4 gy10 = floor(gx10) * (1.0 / 7.0);
-  vec4 gz10 = floor(gy10) * (1.0 / 6.0);
-  gx10 = fract(gx10) - 0.5;
-  gy10 = fract(gy10) - 0.5;
-  gz10 = fract(gz10) - 0.5;
-  vec4 gw10 = vec4(0.75) - abs(gx10) - abs(gy10) - abs(gz10);
-  vec4 sw10 = step(gw10, vec4(0.0));
-  gx10 -= sw10 * (step(0.0, gx10) - 0.5);
-  gy10 -= sw10 * (step(0.0, gy10) - 0.5);
-
-  vec4 gx11 = ixy11 * (1.0 / 7.0);
-  vec4 gy11 = floor(gx11) * (1.0 / 7.0);
-  vec4 gz11 = floor(gy11) * (1.0 / 6.0);
-  gx11 = fract(gx11) - 0.5;
-  gy11 = fract(gy11) - 0.5;
-  gz11 = fract(gz11) - 0.5;
-  vec4 gw11 = vec4(0.75) - abs(gx11) - abs(gy11) - abs(gz11);
-  vec4 sw11 = step(gw11, vec4(0.0));
-  gx11 -= sw11 * (step(0.0, gx11) - 0.5);
-  gy11 -= sw11 * (step(0.0, gy11) - 0.5);
-
-  vec4 g0000 = vec4(gx00.x,gy00.x,gz00.x,gw00.x);
-  vec4 g1000 = vec4(gx00.y,gy00.y,gz00.y,gw00.y);
-  vec4 g0100 = vec4(gx00.z,gy00.z,gz00.z,gw00.z);
-  vec4 g1100 = vec4(gx00.w,gy00.w,gz00.w,gw00.w);
-  vec4 g0010 = vec4(gx10.x,gy10.x,gz10.x,gw10.x);
-  vec4 g1010 = vec4(gx10.y,gy10.y,gz10.y,gw10.y);
-  vec4 g0110 = vec4(gx10.z,gy10.z,gz10.z,gw10.z);
-  vec4 g1110 = vec4(gx10.w,gy10.w,gz10.w,gw10.w);
-  vec4 g0001 = vec4(gx01.x,gy01.x,gz01.x,gw01.x);
-  vec4 g1001 = vec4(gx01.y,gy01.y,gz01.y,gw01.y);
-  vec4 g0101 = vec4(gx01.z,gy01.z,gz01.z,gw01.z);
-  vec4 g1101 = vec4(gx01.w,gy01.w,gz01.w,gw01.w);
-  vec4 g0011 = vec4(gx11.x,gy11.x,gz11.x,gw11.x);
-  vec4 g1011 = vec4(gx11.y,gy11.y,gz11.y,gw11.y);
-  vec4 g0111 = vec4(gx11.z,gy11.z,gz11.z,gw11.z);
-  vec4 g1111 = vec4(gx11.w,gy11.w,gz11.w,gw11.w);
-
-  vec4 norm00 = taylorInvSqrt(vec4(dot(g0000, g0000), dot(g0100, g0100), dot(g1000, g1000), dot(g1100, g1100)));
-  g0000 *= norm00.x;
-  g0100 *= norm00.y;
-  g1000 *= norm00.z;
-  g1100 *= norm00.w;
-
-  vec4 norm01 = taylorInvSqrt(vec4(dot(g0001, g0001), dot(g0101, g0101), dot(g1001, g1001), dot(g1101, g1101)));
-  g0001 *= norm01.x;
-  g0101 *= norm01.y;
-  g1001 *= norm01.z;
-  g1101 *= norm01.w;
-
-  vec4 norm10 = taylorInvSqrt(vec4(dot(g0010, g0010), dot(g0110, g0110), dot(g1010, g1010), dot(g1110, g1110)));
-  g0010 *= norm10.x;
-  g0110 *= norm10.y;
-  g1010 *= norm10.z;
-  g1110 *= norm10.w;
-
-  vec4 norm11 = taylorInvSqrt(vec4(dot(g0011, g0011), dot(g0111, g0111), dot(g1011, g1011), dot(g1111, g1111)));
-  g0011 *= norm11.x;
-  g0111 *= norm11.y;
-  g1011 *= norm11.z;
-  g1111 *= norm11.w;
-
-  float n0000 = dot(g0000, Pf0);
-  float n1000 = dot(g1000, vec4(Pf1.x, Pf0.yzw()));
-  float n0100 = dot(g0100, vec4(Pf0.x, Pf1.y, Pf0.zw()));
-  float n1100 = dot(g1100, vec4(Pf1.xy(), Pf0.zw()));
-  float n0010 = dot(g0010, vec4(Pf0.xy(), Pf1.z, Pf0.w));
-  float n1010 = dot(g1010, vec4(Pf1.x, Pf0.y, Pf1.z, Pf0.w));
-  float n0110 = dot(g0110, vec4(Pf0.x, Pf1.yz(), Pf0.w));
-  float n1110 = dot(g1110, vec4(Pf1.xyz(), Pf0.w));
-  float n0001 = dot(g0001, vec4(Pf0.xyz(), Pf1.w));
-  float n1001 = dot(g1001, vec4(Pf1.x, Pf0.yz(), Pf1.w));
-  float n0101 = dot(g0101, vec4(Pf0.x, Pf1.y, Pf0.z, Pf1.w));
-  float n1101 = dot(g1101, vec4(Pf1.xy(), Pf0.z, Pf1.w));
-  float n0011 = dot(g0011, vec4(Pf0.xy(), Pf1.zw()));
-  float n1011 = dot(g1011, vec4(Pf1.x, Pf0.y, Pf1.zw()));
-  float n0111 = dot(g0111, vec4(Pf0.x, Pf1.yzw()));
-  float n1111 = dot(g1111, Pf1);
-
-  vec4 fade_xyzw = fade(Pf0);
-  vec4 n_0w = mix(vec4(n0000, n1000, n0100, n1100), vec4(n0001, n1001, n0101, n1101), fade_xyzw.w);
-  vec4 n_1w = mix(vec4(n0010, n1010, n0110, n1110), vec4(n0011, n1011, n0111, n1111), fade_xyzw.w);
-  vec4 n_zw = mix(n_0w, n_1w, fade_xyzw.z);
-  vec2 n_yzw = mix(n_zw.xy, n_zw.zw, fade_xyzw.y);
-  float n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x);
-  return 2.2 * n_xyzw;
-}
-
-// Classic Perlin noise, periodic version
-float pnoise(vec4 P, vec4 rep)
-{
-  vec4 Pi0 = mod(floor(P), rep); // Integer part modulo rep
-  vec4 Pi1 = mod(Pi0 + 1.0, rep); // Integer part + 1 mod rep
-  Pi0 = mod289(Pi0);
-  Pi1 = mod289(Pi1);
-  vec4 Pf0 = fract(P); // Fractional part for interpolation
-  vec4 Pf1 = Pf0 - 1.0; // Fractional part - 1.0
-  vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
-  vec4 iy = vec4(Pi0.yy(), Pi1.yy());
-  vec4 iz0 = vec4(Pi0.zzzz());
-  vec4 iz1 = vec4(Pi1.zzzz());
-  vec4 iw0 = vec4(Pi0.wwww());
-  vec4 iw1 = vec4(Pi1.wwww());
-
-  vec4 ixy = permute(permute(ix) + iy);
-  vec4 ixy0 = permute(ixy + iz0);
-  vec4 ixy1 = permute(ixy + iz1);
-  vec4 ixy00 = permute(ixy0 + iw0);
-  vec4 ixy01 = permute(ixy0 + iw1);
-  vec4 ixy10 = permute(ixy1 + iw0);
-  vec4 ixy11 = permute(ixy1 + iw1);
-
-  vec4 gx00 = ixy00 * (1.0 / 7.0);
-  vec4 gy00 = floor(gx00) * (1.0 / 7.0);
-  vec4 gz00 = floor(gy00) * (1.0 / 6.0);
-  gx00 = fract(gx00) - 0.5;
-  gy00 = fract(gy00) - 0.5;
-  gz00 = fract(gz00) - 0.5;
-  vec4 gw00 = vec4(0.75) - abs(gx00) - abs(gy00) - abs(gz00);
-  vec4 sw00 = step(gw00, vec4(0.0));
-  gx00 -= sw00 * (step(0.0, gx00) - 0.5);
-  gy00 -= sw00 * (step(0.0, gy00) - 0.5);
-
-  vec4 gx01 = ixy01 * (1.0 / 7.0);
-  vec4 gy01 = floor(gx01) * (1.0 / 7.0);
-  vec4 gz01 = floor(gy01) * (1.0 / 6.0);
-  gx01 = fract(gx01) - 0.5;
-  gy01 = fract(gy01) - 0.5;
-  gz01 = fract(gz01) - 0.5;
-  vec4 gw01 = vec4(0.75) - abs(gx01) - abs(gy01) - abs(gz01);
-  vec4 sw01 = step(gw01, vec4(0.0));
-  gx01 -= sw01 * (step(0.0, gx01) - 0.5);
-  gy01 -= sw01 * (step(0.0, gy01) - 0.5);
-
-  vec4 gx10 = ixy10 * (1.0 / 7.0);
-  vec4 gy10 = floor(gx10) * (1.0 / 7.0);
-  vec4 gz10 = floor(gy10) * (1.0 / 6.0);
-  gx10 = fract(gx10) - 0.5;
-  gy10 = fract(gy10) - 0.5;
-  gz10 = fract(gz10) - 0.5;
-  vec4 gw10 = vec4(0.75) - abs(gx10) - abs(gy10) - abs(gz10);
-  vec4 sw10 = step(gw10, vec4(0.0));
-  gx10 -= sw10 * (step(0.0, gx10) - 0.5);
-  gy10 -= sw10 * (step(0.0, gy10) - 0.5);
-
-  vec4 gx11 = ixy11 * (1.0 / 7.0);
-  vec4 gy11 = floor(gx11) * (1.0 / 7.0);
-  vec4 gz11 = floor(gy11) * (1.0 / 6.0);
-  gx11 = fract(gx11) - 0.5;
-  gy11 = fract(gy11) - 0.5;
-  gz11 = fract(gz11) - 0.5;
-  vec4 gw11 = vec4(0.75) - abs(gx11) - abs(gy11) - abs(gz11);
-  vec4 sw11 = step(gw11, vec4(0.0));
-  gx11 -= sw11 * (step(0.0, gx11) - 0.5);
-  gy11 -= sw11 * (step(0.0, gy11) - 0.5);
-
-  vec4 g0000 = vec4(gx00.x,gy00.x,gz00.x,gw00.x);
-  vec4 g1000 = vec4(gx00.y,gy00.y,gz00.y,gw00.y);
-  vec4 g0100 = vec4(gx00.z,gy00.z,gz00.z,gw00.z);
-  vec4 g1100 = vec4(gx00.w,gy00.w,gz00.w,gw00.w);
-  vec4 g0010 = vec4(gx10.x,gy10.x,gz10.x,gw10.x);
-  vec4 g1010 = vec4(gx10.y,gy10.y,gz10.y,gw10.y);
-  vec4 g0110 = vec4(gx10.z,gy10.z,gz10.z,gw10.z);
-  vec4 g1110 = vec4(gx10.w,gy10.w,gz10.w,gw10.w);
-  vec4 g0001 = vec4(gx01.x,gy01.x,gz01.x,gw01.x);
-  vec4 g1001 = vec4(gx01.y,gy01.y,gz01.y,gw01.y);
-  vec4 g0101 = vec4(gx01.z,gy01.z,gz01.z,gw01.z);
-  vec4 g1101 = vec4(gx01.w,gy01.w,gz01.w,gw01.w);
-  vec4 g0011 = vec4(gx11.x,gy11.x,gz11.x,gw11.x);
-  vec4 g1011 = vec4(gx11.y,gy11.y,gz11.y,gw11.y);
-  vec4 g0111 = vec4(gx11.z,gy11.z,gz11.z,gw11.z);
-  vec4 g1111 = vec4(gx11.w,gy11.w,gz11.w,gw11.w);
-
-  vec4 norm00 = taylorInvSqrt(vec4(dot(g0000, g0000), dot(g0100, g0100), dot(g1000, g1000), dot(g1100, g1100)));
-  g0000 *= norm00.x;
-  g0100 *= norm00.y;
-  g1000 *= norm00.z;
-  g1100 *= norm00.w;
-
-  vec4 norm01 = taylorInvSqrt(vec4(dot(g0001, g0001), dot(g0101, g0101), dot(g1001, g1001), dot(g1101, g1101)));
-  g0001 *= norm01.x;
-  g0101 *= norm01.y;
-  g1001 *= norm01.z;
-  g1101 *= norm01.w;
-
-  vec4 norm10 = taylorInvSqrt(vec4(dot(g0010, g0010), dot(g0110, g0110), dot(g1010, g1010), dot(g1110, g1110)));
-  g0010 *= norm10.x;
-  g0110 *= norm10.y;
-  g1010 *= norm10.z;
-  g1110 *= norm10.w;
-
-  vec4 norm11 = taylorInvSqrt(vec4(dot(g0011, g0011), dot(g0111, g0111), dot(g1011, g1011), dot(g1111, g1111)));
-  g0011 *= norm11.x;
-  g0111 *= norm11.y;
-  g1011 *= norm11.z;
-  g1111 *= norm11.w;
-
-  float n0000 = dot(g0000, Pf0);
-  float n1000 = dot(g1000, vec4(Pf1.x, Pf0.yzw()));
-  float n0100 = dot(g0100, vec4(Pf0.x, Pf1.y, Pf0.zw()));
-  float n1100 = dot(g1100, vec4(Pf1.xy(), Pf0.zw()));
-  float n0010 = dot(g0010, vec4(Pf0.xy(), Pf1.z, Pf0.w));
-  float n1010 = dot(g1010, vec4(Pf1.x, Pf0.y, Pf1.z, Pf0.w));
-  float n0110 = dot(g0110, vec4(Pf0.x, Pf1.yz(), Pf0.w));
-  float n1110 = dot(g1110, vec4(Pf1.xyz(), Pf0.w));
-  float n0001 = dot(g0001, vec4(Pf0.xyz(), Pf1.w));
-  float n1001 = dot(g1001, vec4(Pf1.x, Pf0.yz(), Pf1.w));
-  float n0101 = dot(g0101, vec4(Pf0.x, Pf1.y, Pf0.z, Pf1.w));
-  float n1101 = dot(g1101, vec4(Pf1.xy(), Pf0.z, Pf1.w));
-  float n0011 = dot(g0011, vec4(Pf0.xy(), Pf1.zw()));
-  float n1011 = dot(g1011, vec4(Pf1.x, Pf0.y, Pf1.zw()));
-  float n0111 = dot(g0111, vec4(Pf0.x, Pf1.yzw()));
-  float n1111 = dot(g1111, Pf1);
-
-  vec4 fade_xyzw = fade(Pf0);
-  vec4 n_0w = mix(vec4(n0000, n1000, n0100, n1100), vec4(n0001, n1001, n0101, n1101), fade_xyzw.w);
-  vec4 n_1w = mix(vec4(n0010, n1010, n0110, n1110), vec4(n0011, n1011, n0111, n1111), fade_xyzw.w);
-  vec4 n_zw = mix(n_0w, n_1w, fade_xyzw.z);
-  vec2 n_yzw = mix(n_zw.xy, n_zw.zw, fade_xyzw.y);
-  float n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x);
-  return 2.2 * n_xyzw;
-  }
-#endif
-
 int main()
 {
 	int Error = 0;