/* textured_fog.pov v0.2 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. Oct 3. - added support for ground fog, added a new pigment: 'planar2', and changed the description of 'polar' 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, sky_pigment ) * this_texture = this object's texture * sky_pigment = the sky pigment Every object's texture will use this to participate with the 'fog.' It returns a texture. fog_wrap_ground( this_texture, sky_pigment, fog_height, fog_falloff) * this_texture = this object's texture * sky_pigment = the sky pigment * fog_height = the ground fog's height (recommended values: 0 to 1) * fog_falloff = amount of falloff This version of fog_wrap tries to simulate ground fog. If fog_height is more than zero, then ground fog will be activated. Small values are recommended. High fog_falloff values will cause the effect to taper off a greater rate. lerp( a, b, c ) Blend a with b by amount c. Not really necessary for fog, but a useful function regardless. Pigments polar This pigment is used to make coronas. It's like a 3D radial pattern, with a bright cone of intensity pointing at <0,n,0>, diminishing in intensity as it wraps around toward <0,-n,0>. planar2 This is similar to the traditional planar pigment, only it doesn't get darker at <0,-1,0>. 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 example_type = 2; // 1 = homogenous fog, 2 = ground fog #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 = 0; #declare fog_distance_far = 700; // some colors #declare rgb_sun = rgb 2*<1,.8,.6>; #declare rgb_sky = rgb <.1,.3,.5>-.3; //ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ// // 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, sky_pigment) fog_wrap_base( this_texture, sky_pigment, 0, 0 ) #end #macro fog_wrap_ground( this_texture, sky_pigment, fog_height, fog_falloff) fog_wrap_base( this_texture, sky_pigment, fog_height, fog_falloff ) #end #macro fog_wrap_base( this_texture, sky_pigment, fog_height, fog_falloff ) texture{ pigment_pattern{ spherical scale fog_distance_far #if(fog_height>0) // ground fog pigment_map{ [0 central_projection(pigment{planar2 scale fog_height poly_wave fog_falloff color_map{[0 rgb 1][1 rgb 0]}})] [1 rgb 1] } #end } texture_map{ [0 pigment{sky_pigment} 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 ) } } #declare planar2 = pigment{function{min(1, max(1-y, 0))}} //ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ// // 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 2] } #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} //sphere{y*50,50} #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 #switch(example_type) #case(1) // homogenous fog fog_wrap( earth_texture, sky_pigment ) #break #case(2) // ground fog fog_wrap_ground( earth_texture, sky_pigment, 0.5, 8 ) #break #end } 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 // //___________//