 	return vec3(X, Y, Z); 
 }
 
-float gainF(vec3 K1, vec3 K2){
-	float gF = 1.0 - dot(K1,K2);
-	gF = gF*gF; 
-	float ww = K1.z - K2.z;
+//gain factor as described in the thesis
+//consisting of C = F*G/w^2
+//where F is the fesnel number
+//    G is the geometric term
+//    w is the 3rd component of (u,v,w)
+//for further details I refer to my thesis,
+//in the chapter 'derivations'.
+//@param incident light direction
+//@param viewing direction
+//@return F*G/w^2
+float gainFactor(vec3 k1, vec3 k2){
+	// This side is not visible
+	if (k1.z > 0.0 || k2.z < 0.0){
+		return 0.0;
+	}
+	float ww2 = k1.z - k2.z;
+	ww2 = ww2*ww2;
+	
+	float geometricalTerm = 1.0 - dot(k1,k2);
+	geometricalTerm *= (geometricalTerm/(k2.z*ww2)); 
 	 
-	 
-	if(K1.z > 0.0 || K2.z < 0.0){
-		return 0.0; // This side is not visible
-	}
-	 
-	ww = ww*ww;
-
-	gF = gF / K2.z;
-	gF = gF / ww;
-	 
-	float fFac = getFresnelFactor(K1, K2); 
-	return fFac*gF;
-}
-
+	float fresnelTerm = getFresnelFactor(k1, k2); 
+	return fresnelTerm*geometricalTerm;
+}
+
+//performs gamma correction applied on a vector containing rgb colors
+//see http://en.wikipedia.org/wiki/Gamma_correction
 vec3 gammaCorrect(vec3 inRGB, float gamma){
 	float clLim = 0.0031308;
 	float clScale = 1.055;

	return coord;
}

float getGaussWeightAtDistance(float distU, float distV){
	// note that distU and distV are in textureCoordinateUnits
	distU = distU * distU / varX_InTxtUnits;
	distV = distV * distV / varY_InTxtUnits;
	return exp((-distU - distV)/2.0f);
}

float getSincWeightAtDistance(float distU, float distV){
	// note that distU and distV are in textureCoordinateUnits
	distU = distU * distU / varX_InTxtUnits;

void coneMain();
void gemMain();

const float eps_pq = 1.0*pow(10.0, -5.0); 

// computes p-part of pq factor
// see derivations: T_i*w_i is a multiple of 2*PI
// using some trigo-complex number magic
// @param w_i angular frequency
// @param T_i period
// @param N_i iteration according to period
// @return p factor
float get_p_factor(float w_i, float T_i, float N_i){
	float tmp = 1.0;
	if (abs(1.0-cos(T_i*w_i)) < eps_pq){
