  * @return              A uniformly random direction in the hemisphere
  */
 __device__ float3 CreateUniformDirectionInHemisphere(float3 normal, curandState *randState) {	
+	// Create a random coordinate in spherical space
+	// Then calculate the cartesian equivalent
+	float z = curand_uniform(randState);
+	float r = sqrt(1.0f - z * z);
+    float phi = TWO_PI * curand_uniform(randState);
+	float x = cos(phi) * r;
+	float y = sin(phi) * r;
+
 	// Find an axis that is not parallel to normal
 	float3 majorAxis;
 	if (abs(normal.x) < INV_SQRT_THREE) { 

	float3 v = cross(normal, u);
	float3 w = normal;

	// Create random coordinates in the local coordinate system
	float rand = curand_uniform(randState);
	float r = sqrt(rand);
	float theta = curand_uniform(randState) * TWO_PI; 
	
	float x = r * cos(theta);
	float y = r * sin(theta);
    

	// Transform from local coordinates to world coordinates
    return normalize(u * x +

 * @return              A cosine weighted random direction in the hemisphere
 */
__device__ float3 CreateCosineWeightedDirectionInHemisphere(float3 normal, curandState *randState) {
	// Create random coordinates in the local coordinate system
	float rand = curand_uniform(randState);
	float r = sqrt(rand);
	float theta = curand_uniform(randState) * TWO_PI; 
	
	float x = r * cos(theta);
	float y = r * sin(theta);
    

	// Find an axis that is not parallel to normal
	float3 majorAxis;
	if (abs(normal.x) < INV_SQRT_THREE) { 
