/* textured_fog.pov 2010 Samuel Benge This is an example of how textured fog can be achieved in POV-Ray. The effect behaves as if the fog is sampled from a sky_sphere pigment. The main functions require you to #declare the camera position beforehand, and to also wrap all the objects' textures inside a special macro. Contents Macros central_projection( cp_pigment ) * cp_pigment = a pigment to project radially This transforms a pigment so that it radiates outward in all directions. Use it as you would use any sky_sphere pigment. It returns pigment_pattern (grayscale, to avoid longer render times). fog_wrap( this_texture, this_sky ) * this_texture = this object's texture * this_sky = the sky pigment Every object's texture will use this to participate with the 'fog.' It returns a texture. lerp( a, b, c ) Blend a with b by amount c. Not really necessary for fog, but a useful function regardless. Pigment polar This pigment is used to make coronas. At -y it is black, gradually increasing in intensity until it becomes white at +y. It radiates from <0,0,0> in all directions and is conical in nature. Declarables c_pos The camera's location. It must be declared. fog_distance_near The fog effect's starting distance from the camera. Default: 0 fog_distance_far The fog effect's ending distance from the camera. Default: 200 */ #declare show_example = 2; // 1 = basic fog, 2 = bright horizon, 3 = basic & cloudy #declare global_illumination = on; #declare version_above_37_37 = true; // change to 'false' if using 3.7.beta.37 or below #include "transforms.inc" #default{ finish{ ambient 0 } } // camera and light positions #declare c_pos = <0,5,-200>; #declare l_pos = <1,.25,1>*1e9; // a very distant light_source // minimum/maximum fog distances #declare fog_distance_near = 100; #declare fog_distance_far = 1000; // some colors #declare rgb_sun = rgb 2*<1,.8,.6>; #declare rgb_sky = rgb <.1,.3,.5>; //ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ// // textured_fog.inc // //__________________// #ifndef(fog_distance_near) #declare fog_distance_near = 0; #end #ifndef(fog_distance_far) #declare fog_distance_far = 200; #end #macro central_projection( cp_pigment ) #local cpf = function{ pigment{ cp_pigment } } pigment_pattern{ function{ cpf( x/sqrt(x*x+y*y+z*z), y/sqrt(x*x+y*y+z*z), z/sqrt(x*x+y*y+z*z) ).gray } } #end #macro fog_wrap( this_texture, this_sky ) texture{ pigment_pattern{spherical scale fog_distance_far} texture_map{ [0 pigment{this_sky} finish{ #if(version_above_37_37) emission #else ambient #end 1 diffuse 0 } ] [1-1/fog_distance_far*fog_distance_near this_texture ] } translate c_pos } #end #macro lerp( a, b, c ) a*(1-c)+b*c #end #declare polar = pigment{ function{ abs( atan2(sqrt(x*x+z*z),-y)/pi ) } } //ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ// // end textured_fog.inc // //______________________// //ŻŻŻŻŻŻŻ// // scene // //_______// camera{ location c_pos look_at y*40 } light_source{ l_pos, rgb_sun #if(1) // area_light switch #local al_res = 2; #local al_size = 0.02*(1e9); area_light x*al_size, z*al_size, al_res, al_res jitter adaptive 1 #end } // this will be used for the sky_sphere pigment and the fog_wrap textures #declare sky_pigment = pigment{ #local corona = pigment{ polar // the polar pigment is pointing toward the 'sun' Point_At_Trans(l_pos) color_map{ [0 rgb_sky] [1 rgb_sun] } } #switch(show_example) #case(1) // thick fog layer corona poly_wave 5 #break #case(2) // fog brightening towards the horizon central_projection( pigment{ planar poly_wave 5 } ) pigment_map{ [0 corona poly_wave 5] [1 corona poly_wave 3] } #break #case(3) // cloudy central_projection( pigment{ bumps scale .2 poly_wave 2 turbulence .3 lambda 3 translate 10 } ) pigment_map{ [0 corona poly_wave 5] [1 corona poly_wave 2] } #break #end } sky_sphere{ pigment{sky_pigment} } #declare earth_texture = texture{ #local earth_pattern = pigment{ pigment_pattern{ bumps turbulence 1 lambda 3 scale<15,2.5,10> } rotate y*67 } pigment{ earth_pattern color_map{ #local rgb_earthy = rgb<1,.55,.3>; [0 rgb_earthy*.5] [1 rgb_earthy] } } normal{pigment_pattern{earth_pattern} 1 accuracy .001} finish{diffuse 1} } #declare hf = height_field{ function 256*2, 2*256{ pigment{ pigment_pattern{ cylindrical rotate x*90 translate (x+y) scale 1/2 cubic_wave } pigment_map{ [0 rgb 0] [1 crackle scale .2 poly_wave .125 turbulence .2 lambda 2.75 ] } } } translate-(x+z)/2 scale<400,40,400> } // mountains, plain union{ plane{y,0} #declare R = seed(1002); #declare V = 0; #while(V<100) #declare X = rand(R)*2-1; #declare Z = rand(R); object{hf scale (.5+rand(R))*<1,lerp(.1,1,(pow(X*2,2)+Z)/2),1> rotate y*rand(R)*420 translate< 400*X, 0, 50+300*Z > } #declare V = V + 1; #end // invoking the fog_wrap macro // any object transformations should take place before fog_wrap is called fog_wrap( earth_texture, sky_pigment ) } global_settings{ #if(global_illumination) radiosity{ #switch( 0 ) // radiosity quality (0 or 1) #case(0) count 25 nearest_count 1 #break #case(1) count 100 nearest_count 5 #break #end error_bound .1 pretrace_start .08 pretrace_end .02 recursion_limit 1 normal on brightness 1 gray_threshold 0 adc_bailout 1/256 } #end } //ŻŻŻŻŻŻŻŻŻŻŻ// // end scene // //___________//