 	mat2 jacob_t = mat2(jacob[0][0], jacob[1][0], jacob[0][1], jacob[1][1]);
 	mat2 sigma_f_inv = (4.*PI*PI*params.filterSigma*params.filterSigma)*(jacob*jacob_t);
 	mat2 sigma_f = inv2x2(sigma_f_inv);
-	mat2 sigma_g_inv = (2.*PI*params.ainv*params.ainv)* id2x2();
+	mat2 sigma_g_inv = (2.*PI*im_params.ainv*im_params.ainv)* id2x2();
 	mat2 sigma_g = inv2x2(sigma_g_inv);
 	mat2 sigma_fg_inv = sigma_f_inv + sigma_g_inv;
 	mat2 sigma_fg = inv2x2(sigma_fg_inv);
 	
 	//filter params
-	params.filter = sigma_fg * sigma_g_inv;	
-	params.sigma_f_plus_g_inv = inv2x2(sigma_f + sigma_g);
-	params.a_prime_square = 2.*PI*sqrt(det2x2(sigma_fg));
-	
-	params.octaves = params.sector.y;//log2(params.sector.y/params.sector.x);
+	im_params.filter = sigma_fg * sigma_g_inv;	
+	im_params.sigma_f_plus_g_inv = inv2x2(sigma_f + sigma_g);
+	im_params.a_prime_square = 2.*PI*sqrt(det2x2(sigma_fg));
 
 	float value = 
-		eval_cell(cpos, gpos, ivec2(-1, -1), params) +
-		eval_cell(cpos, gpos, ivec2(-1,  0), params) +
-		eval_cell(cpos, gpos, ivec2(-1,  1), params) +
-		eval_cell(cpos, gpos, ivec2( 0, -1), params) +
-		eval_cell(cpos, gpos, ivec2( 0,  0), params) +
-		eval_cell(cpos, gpos, ivec2( 0,  1), params) +
-		eval_cell(cpos, gpos, ivec2( 1, -1), params) +
-		eval_cell(cpos, gpos, ivec2( 1,  0), params) +
-		eval_cell(cpos, gpos, ivec2( 1,  1), params);
+		eval_cell(cpos, gpos, ivec2(-1, -1), params, im_params) +
+		eval_cell(cpos, gpos, ivec2(-1,  0), params, im_params) +
+		eval_cell(cpos, gpos, ivec2(-1,  1), params, im_params) +
+		eval_cell(cpos, gpos, ivec2( 0, -1), params, im_params) +
+		eval_cell(cpos, gpos, ivec2( 0,  0), params, im_params) +
+		eval_cell(cpos, gpos, ivec2( 0,  1), params, im_params) +
+		eval_cell(cpos, gpos, ivec2( 1, -1), params, im_params) +
+		eval_cell(cpos, gpos, ivec2( 1,  0), params, im_params) +
+		eval_cell(cpos, gpos, ivec2( 1,  1), params, im_params);
 	
-	//float lambda = params.a*params.a*params.density;
 	
 	//ad hoc attempt to normalize
-	//value/=log2(2.+2.*params.density);
-	value*=(1./PI)*pow(params.density+1., -.5);
-	//value*=(1./3.)/log2(params.density+2.);
-	float octexp = pow(2., params.octaves);
-	value*= (1.+params.octaves)*octexp/(2.*octexp-1.);
+	value*=.5*pow(params.density+1., -.5);
+	float octexp = pow(2., params.sector.y);
+	value*= (1.+params.sector.y)*octexp/(2.*octexp-1.);
 	
 	return value;
 }

 }
 
 //annular sector of pink noise
float gnoise(vec2 pos, gnoise_params params) {
	//compute positions for this fragment
	vec2 temp = pos*params.a; 
	vec2 cpos = fract(temp);

#endif

#define PI 3.1415926535897932384626
#define IMPULSE_CAP 128
#define IMOD 4096

struct gnoise_params{ //struct for input params to gabor noise
	float a, density, filterSigma, octaves;
	vec4 sector;
	mat2 jacob;
};

struct gnoise_im_params{ //struct to pass intermediate values within gnoise
	mat2 filter, sigma_f_plus_g_inv;
	float ainv, a_prime_square;
};

ivec2 bound_grid(const ivec2 gpos){
	return gpos + IMOD*(1 - gpos/IMOD);
}

//hash based on Blum, Blum & Shub 1986
//and Sharpe http://briansharpe.wordpress.com/2011/10/01/gpu-texture-free-noise/
const float bbsm = 137023.;//magic product of two primes chosen to have high period without float precision issues
vec2 bbsmod( const vec2 a ) {
	return a - floor( a * ( 1.0 / bbsm ) ) * bbsm;
}
vec2 bbs(const vec2 a) {
	return bbsmod(a*a);
}
float bbsopt( const float a ) {
	return fract( a * a * ( 1.0 / bbsm ) ) * bbsm;
}
float seed(const ivec2 p){
	vec2 h = bbs(vec2(p.xy));
	return bbsopt(h.x+bbsopt(h.y))*(1./bbsm);
}

//permutation polynomial
