// Persistence of Vision Ray Tracer Scene Description File
// File: cloudtest.pov
// Vers: 3.5
// Desc: Clouds and Atmosphere made with media
// Date: 18.10.2002
// Auth: Thies Heidecke

#version 3.5;
#include "transforms.inc"
// place all settings of globally influenced features here
global_settings {
  assumed_gamma 1.0
  max_trace_level 10
}

#declare myclock = sqrt(clock);

camera {
	location (30-29*myclock)*<-26,20,-80>
	rotate 360*clock*y
	//location (20-19*clock)*<7,15,-80>
	look_at  1.0*<0,15,0>
	right image_width/image_height*x
	up y
}

//#declare LPos = 10000*<-12, 19, -11>/vlength(<-12, 19, -11>);
//#declare LPos = 10000*<2, 13, 40>/vlength(<2, 13, 40>);
#declare LPos = 10000*<1, 23, 2>/vlength(<1, 23, 2>);
#declare LPos = 10000*vaxis_rotate(<-33,0,-10>, <10,10,-33>, 3.0+176*myclock)/vlength(<-33, 0, -10>);
#declare LightCompression = 1.0;
light_source {
  0*x
  color rgb (1/LightCompression)*<1.00, 0.97, 0.92>//1
  //fade_power 2
  //fade_distance vlength( LPos )
  translate LPos
}

//*
#declare h__0_37 = 2500;//2500;	// height at which atmosphere density is 1/e = 37 % of ground-level
#declare atmo_dens = 0.0000175*LightCompression;//0.0000175*LightCompression
media {    // atmospheric media sample
  intervals 1
  method 3
  scattering { 4, rgb (0.8 + 0.2*<0.00, 0.35, 1.00>) }
  //scattering { 4, rgb 0.00001 }
  samples 3
  aa_threshold 0.001     // accuracy threshold for method 3 [0.1]
  aa_level 1           // maximum recursion depth for method 3 [4]
  ratio 0.5
  density{function{atmo_dens*exp(-abs(y)/h__0_37)}}
}
//*/

// Sigmoid Function
// Bias : greater value => more(bigger) clouds
#declare fn_sigmoid = function(x,power,bias) { 1/(1+exp(power*(-2*x+1-bias))) }
#declare fn_bounds = function {
	pigment {
		planar
		/*
		turbulence 0//1.3
		octaves 4
		lambda 1.0
		omega 0.6*/
		color_map {
			[0.00 color rgb 0.0000]
			[0.75 color rgb 0.8000]
			[1.00 color rgb 1.0000]
		}
	}
};
#declare fn_area = function {
	pigment {
		//dents
		bozo
		turbulence 0.3*<1.0, 1.0, 1.0>//0.7
		octaves 7
		lambda  2.5
		omega   0.7
		scale 200
		color_map {
		  [0.00 color rgb 0.0000]
			[1.00 color rgb 1.0000]
		}
	}
};




#declare Clouds_Altitude  = 250;
#declare Clouds_Height		= 160;
#declare Clouds_LowBound  = Clouds_Altitude-.5*Clouds_Height;
#declare Clouds_HighBound = Clouds_Altitude+.5*Clouds_Height;

#declare clouds =
intersection {
	plane{ y,  Clouds_HighBound}
	plane{-y, -Clouds_LowBound}
	hollow on
	pigment{rgbt 1}
	
	interior{
		media {
		  intervals 1           // number of intervals used for sampling [10]
		  samples 5            // minimum and maximum number of samples taken per interval [1,1]
		  ratio 0.9              // distribution between lit and unlit areas [0.9]
		  //*
		  scattering {           // scattering media
		    2,                   // scattering type 1=isotropic; 2=Mie haze; 3=Mie murky
		                         // 4=Rayleigh; 5=Henyey-Greenstein
		    rgb <1,1,1>           // color
		    extinction 0.7			// for balancing amount of absorption [1.0]0
		  }//*/
		  method 3              // adaptive sampling
		  aa_threshold 0.01			//0.001     // accuracy threshold for method 3 [0.1]
		  aa_level 3						//5           // maximum recursion depth for method 3 [4]
		  //jitter 0.01         // randomness for method 2&3
		  density {
		  	function{ 0.020*LightCompression*fn_sigmoid( min(1, fn_area(x,0.7*y,z).red) * pow(fn_bounds(x,(y-Clouds_Altitude)*2/Clouds_Height,z).red, 1/5) , 1.5*3.5, -0.20)}  //0.25 0.28
		  	//function{ 0.080 }// }  //0.25 0.28
		  	
		  	//function{ 0.002*LightCompression*fn_sigmoid( min(1, fn_area(x,0.6*y,z).red) * fn_bounds(x,(y-Clouds_Altitude)*2/Clouds_Height,z).red , 5.0*3.5, -0.20) }
		  	
				//turbulence 0.3//0.7
				//octaves 7
				//lambda  2.5
				//omega   0.7
				//scale 200//<200, 100, 200>
		  }
		}
	}
};

object{ clouds }

/*
plane{
	-y, -200
	rotate 90*x
	texture {
		//pigment{ checker color rgb 0 color rgb 1 }
		pigment {
		  	function{ fn_sigmoid( min(1, fn_area(x,1.0*y,z).red) * pow(fn_bounds(x,(y-Clouds_Altitude)*2/Clouds_Height,z).red, 1/5) , 5*3.5, -0.20)}  //0.25 0.28
		  	//rotate 90*x
		  	//0.008*LightCompression*
		}

		finish {ambient 1 diffuse 0}
	}
}//
*/
//*
plane {
	y, 0
	material {
		texture {
			pigment {
				checker rgb 0 rgb 1
				scale 25
			}/*
			normal {
				bozo 0.4
				scale 6
				//turbulence .1
			}*/
			finish {
				ambient 0
				diffuse LightCompression
				//reflection{ 0.02 0.97 fresnel}
			}
		}
		//interior { ior 1.3 }
	}
}
//*/
union{cylinder{0, 30*y, 3 pigment{rgb <1,0,0>}} cone{30*y, 6, 39*y, 0 pigment{rgb 2}}finish{ambient 0.5 diffuse .5*LightCompression} Reorient_Trans(y,LPos)}
//cylinder{100*z, 100*z+30*y, 5 pigment{rgb 1}}

sphere{0, 1 inverse
	pigment{blue 0.5}
	/*
  pigment {
    gradient y
    frequency .5
    phase 0
    color_map {
    	[0.0 color rgb <0.8,0.91,1.0>]
    	[0.5 color blue 0.5]
    	[1.0 color rgb <0.8,0.91,1.0>]
    	//[1.0 color rgb <0.9,0.95,1.0>]
    }
    turbulence 0.1	
  }
  //
  */
  finish{ambient 1.0 diffuse 0}
  scale 100000
}