//isosurface ridged_mf - can it make nice looking water? //- yes apparently it can, so I made it into a full picture! :) //by Tekno Frannansa #version unofficial megapov 1.21; //not actually using any megapov features I think #include "rad_def.inc" #include "functions.inc" #include "transforms.inc" #declare rad=off; //doesn't affect the water apart from the foam, but massively increases render times! So leave it switched off global_settings { max_trace_level 5 assumed_gamma 1 #if (rad) radiosity { Rad_Settings(Radiosity_Fast,on,on) pretrace_end 1/160 } #end } #default { pigment { rgb 1 } finish { diffuse .9 ambient 0 } } //camera very important, must be orthographic for tiled texture, but for perspective with moveable edges of window perhaps spherical? #local H=image_width/sqrt(image_height*image_width); #local V=image_height/sqrt(image_height*image_width); camera { spherical angle H*30,V*30 #declare camPos = <.4,-.5,-15>; location camPos look_at x-y*1.3-z*8.5//+y*5 } //some debug stuff, paint things black to examine the media #macro pigOverride() //pigment { rgb <.02,.06,.15> } #end #macro texOverride() //texture { pigOverride() finish { diffuse 0 ambient 1 } } //override textures to debug media #end #declare water = isosurface { #local Q=0; //randomize the water function { y+(3- f_ridged_mf( (x+y*.2)/4,Q+y*.4,z/4, .5, //H negative exponent of multiplier, magnitude scale per octave. lower this to emphasize higher gain values 3, //1/omega = frequence multiplier per octave, H^ exponent is seeded by this 6, //octaves 1, //offset sets the clip point, or phase, or something, 1 = default, 0 = no clip (no ridges) .8, //gain - 0 means see nothing from higher freqs, 1 higher freqs only at tips, inf -> lower freqs added at all heights [like granite] 3 //noise generator ))*.57 +(f_spotted(x/5+y/5,0,z/5)-.5)*1 } contained_by { box { <-20,-10,-20>,<160,2,240> } } max_gradient 6 accuracy 1/10000 //still get a few black spots, but less texture { //foam pattern, see through where not foaming #local bubbly = .2; pigment_pattern { pigment_pattern { average pigment_map { [1-bubbly pigment_pattern { function { //modified version of the function from above //tweak gain and H settings to make foam lie along ridges //tweak position (if desired) to make it lag behind a bit f_ridged_mf( (x+y*.2)/4,Q+y*.4,z/4, .5, //H negative exponent of multiplier, magnitude scale per octave. lower this to emphasize higher gain values 3, //1/omega = frequence multiplier per octave, H^ exponent is seeded by this 6, //octaves 1, //offset sets the clip point, or phase, or something, 1 = default, 0 = no clip (no ridges) 3, //gain - 0 means see nothing from higher freqs, 1 higher freqs only at tips, inf -> lower freqs added at all heights [like granite] 3 //noise generator )/3 } colour_map { [.55 rgb 0] [.71 rgb 1] } } poly_wave 2 ] [bubbly crackle form <1,0,0> scale .005 cubic_wave colour_map { [0 rgb 0][1 rgb 1] } ] } } colour_map { [0+bubbly rgb 0] [1-bubbly/2 rgb 1] } } #local goodTex = on; texture_map { [0 //water, totally see through and fresnel reflective #if (goodTex) pigment { rgbt 1 } finish { diffuse 0 ambient 1 reflection { 0, 1 fresnel } conserve_energy //phong 1 phong_size 500 //too big? } #else pigment { rgb <.05,.1,.2> } #end ] [1 #if (goodTex) pigment { rgb 1 transmit .3 } //lots of internal reflections make it bright finish { brilliance .5 reflection { 0, 1 fresnel } conserve_energy } normal { crackle -2 form <1,0,0> scale .003 poly_wave 2 } #else pigment { rgb 1 } finish { brilliance .5 } normal { crackle -2 form <1,0,0> scale .003 poly_wave 2 } #end ] } } interior { ior 1.33 media { absorption rgb 1/<.1,1,.7> //the 1/ lets us control the colour things appear, which is more intuitive emission rgb .1*<.0,.1,.2> //this will be tinted by the absorption, making a kind of teal colour density { rgb .2 } } }// */ texOverride() rotate -30*y hollow } sphere { y*(-5000-10.01), 5000 //leave it white so it blends in with the sky & foam pigment { spherical cubic_wave scale 100 translate -y*10 colour_map { [0 rgb 1] [1 rgb 0] } } texOverride() } #declare boat= union { #local hullBase= superellipsoid { <.1,1> rotate z*45 rotate x*10 //sharpen the bow, flatten the stern. scale (x+y)*.73 + z //not quite 1/sqrt(2) because it's not quite square cross section } intersection { object { hullBase scale <1.5,6,8> } plane { y, 0 } plane { -y, 3 } intersection { object { hullBase scale <1.48,6,7.98> } plane { -y, .5 } pigment { rgb .1 } inverse } texture { pigment { gradient y translate -y*.9 scale 6 colour_map { [.825 rgb .3] [.825 rgb .7] [.85 rgb .7] [.85 rgb <.01,.1,.2>] } } normal { dents -1 scale 1/30 } } texture { pigment { rgbt 1 } finish { reflection { .03, .5 falloff 5 } conserve_energy } normal { dents -1 scale 1/30 } } texture { //dirt layer pigment { pigment_pattern { average pigment_map { [1 gradient -y scale 6 poly_wave 1] [.3 granite scale <.1,1,.1> cubic_wave] } } cubic_wave colour_map { [0 rgb <.1,.02,0> transmit 1] [1 rgb <.1,.02,0>] } } finish { brilliance 2 } normal { granite .1 scale <.1,1,.1> } } texOverride() } //metal rim at the top of the hull. intersection { //torus { 1,.002 scale <1.5,5,8> superellipsoid { <.1,1> rotate z*45 rotate x*10 //sharpen the bow, flatten the stern. scale (x+y)*.73 + z //not quite 1/sqrt(2) because it's not quite square cross section scale <1.51,6,8.01> } superellipsoid { <.1,1> rotate z*45 rotate x*10 //sharpen the bow, flatten the stern. scale (x+y)*.73 + z //not quite 1/sqrt(2) because it's not quite square cross section scale <1.49,7,7.99> inverse } plane { y, .01 } plane { -y, .01 } pigment { rgb 1 } finish { brilliance 8 diffuse .25 phong .4 phong_size 2 metallic specular 1 roughness 1/500 reflection { .2, .5 falloff 5 } } //fake curve, because we're not using a torus any more. normal { pigment_pattern { planar colour_map { [0 rgb 1][1 rgb 0] } } -1 poly_wave 2 scale .01 } texOverride() } difference { box { -1, 1 scale <1.3,.4,3> translate z*1+y*.2 } box { -1, 1 scale <.1,.2,.3> translate <-1.3,.35,-1.65> pigment { rgb <.5,.4,.2> } } box { -1, 1 scale <.1,.2,.3> translate <-1.3,.35,-1.0> pigment { rgb <.5,.4,.2> } } box { -1, 1 scale <.1,.2,.3> translate <-1.3,.35,-.25> pigment { rgb <.5,.4,.2> } } box { -1, 1 scale <.3,.41,2> translate <0,.2,-2> } pigment { rgb .5 } normal { granite -.2 scale 1/100 } texOverride() } box { -1, 1 scale <1.32,.01,3.22> translate z*.8+y*.6 pigment { rgb .1 } texOverride() } difference { box { -1, 1 scale <1.2,.2,2.7> translate z*1.1+y*.8 } box { -1, 1 scale <.1,.15,.3> translate <-1.2,.8,-1.25> pigment { rgb <.5,.4,.2> }} box { -1, 1 scale <.1,.15,.3> translate <-1.2,.8,-.6> pigment { rgb <.5,.4,.2> } } box { -1, 1 scale <.1,.15,.3> translate <-1.2,.8,.15> pigment { rgb <.5,.4,.2> } } box { -1, 1 scale <.2,.21,2> translate <0,.8,-1.6> } pigment { rgb .5 } normal { granite -.2 scale 1/100 } texOverride() } union { #macro win() //smashed window difference { box { -1, 1 } #local s=seed(11); #local i=0; #while ( i<8 ) box { <-1.1,0,-1>, <1.1,1,1> scale <1,rand(s),rand(s)*.5> translate z*(rand(s)-.5)*.2 rotate x*rand(s)*360 } #local i=i+1; #end #end win() scale <.01,.2,.3> translate <-1.28,.35,-1.65> } win() scale <.01,.2,.3> translate <-1.28,.35,-1.0> } win() scale <.01,.2,.3> translate <-1.28,.35,-.25> } win() scale <.01,.15,.3> translate <-1.18,.8,-1.25> } win() scale <.01,.15,.3> translate <-1.18,.8,-.6> } win() scale <.01,.15,.3> translate <-1.18,.8,.15> } pigment { rgb 0 transmit .5 } finish { reflection { .2, 1 falloff 5 } conserve_energy } texOverride() } union { difference { superellipsoid { <1,.15> rotate x*90 } cylinder { -y*2,y*2,.9 pigment { rgb .05 } } translate y scale y*2.3/2 } difference { superellipsoid { <1,.15> rotate x*90 } cylinder { -y*2,y*2,.9 pigment { rgb .05 } } translate y+z*2.5 scale y*2.3/2 } texture { pigment { planar scale .2 translate y*2 colour_map { [.4 rgb .5] [.4 rgb <.01,.1,.2>] [.6 rgb <.01,.1,.2>] [.6 rgb .8] } } normal { dents -1 scale 1/30 } } texture { pigment { rgbt 1 } finish { reflection { .03, .5 falloff 5 } conserve_energy } normal { dents -1 scale 1/30 } } texOverride() Shear_Trans(x/2,y+z/4,z) } box { -1, 1 scale <1.22,.01,2.92> translate z*1+y pigment { rgb .1 } texOverride() } } //object { boat scale 1.5 rotate -z*30 rotate 13*x-y*18 translate <0,-3.2,5> } //closer position object { boat scale 1 rotate -z*30 rotate 12*x-y*20 translate <3,-2,8> } //life ring torus { .2,.05 texture { pigment_pattern { gradient y translate -.3 scale 2 warp { turbulence .6 lambda 3.3 octaves 3 } scale 1/2 scale .08*2 } #declare ringTex = texture { pigment { checker rgb <.6,.05,.03>, rgb .8 } finish { brilliance 2 phong .1 phong_size 20 } } texOverride() #declare wetRingTex = texture { ringTex } texture { pigment { rgb 0 transmit .9 } //fake up the conserve energy a bit, to make the water line more visible. finish { phong .5 phong_size 200 reflection { 0, 1 fresnel } conserve_energy } normal { pigment_pattern { pigment_pattern { gradient y translate -.3 scale 2 warp { turbulence .6 lambda 3.3 octaves 3 } scale 1/2 scale .08*2 } colour_map { [.45 rgb 0] [.5 rgb 1] } } -.02 poly_wave 2 accuracy 1/100 } } texOverride() texture_map { [.5 //wet bit wetRingTex ] [.5 //dry bit ringTex ] } }// */ interior { ior 1.33 } //for fresnel rotate -y*30 translate y*.02 //float above 1/2 way point, very bouyant when unladen #local norm = <0,0,0>; #local pos = <.4,0,-10.6>; #local pos = trace ( water, pos+y*20, -y, norm ); Reorient_Trans(y,norm) translate pos } light_source { #declare sunDir=<-1,1,-1>; sunDir*1000, rgb <2.2,2,1.7>*.9 } #if (!rad) light_source { <2,3,-1>*1000, rgb <.1,.2,.5> shadowless } light_source { <-1,2,-3>*1000, rgb <.1,.2,.5> shadowless } light_source { <-3,2,1>*1000, rgb <.1,.2,.5> shadowless } light_source { <1,-2,-1>*1000, rgb .2 shadowless } #end sky_sphere { pigment { planar poly_wave 2 colour_map { [0 rgb <0,.2,.8>*2] [1 rgb <0,.4,1>*2] } } #macro Cloud(c1,c2,s) pigment { pigment_pattern { pigment_pattern { granite turbulence 1 scale 1 poly_wave 1 scale s //fake parallax, squished towards top of dome relative to next layer translate y } pigment_map { [0 rgb 0] [.8 //stick a break in the clouds above, so the ocean's less grey planar poly_wave 2 ] } } cubic_wave colour_map { [0 c1] [1 c2] } } #end #local sh=.1; Cloud(rgb <4,4.2,5> transmit 1,rgb sh,<1,.298,1>*4) Cloud(rgb <4,4.2,5> transmit 1,rgb sh,<1,.298,1>) Cloud(rgb sh transmit 1,rgb sh,<1,.3,1>*4) Cloud(rgb sh transmit 1,rgb sh,<1,.3,1>) pigOverride() } object { water #declare waterOn=1; } //plane { y, -1.5 #declare waterOn=1; pigment { rgb <.05,.1,.2> } } //cheaper placeholder #ifdef (waterOn) //this looks dumb if the water's off. //mist from waves cylinder { -y*2, -.6*y, 50 hollow on no_reflection no_shadow //no time wasting pigment { rgbt 1 } interior { media { emission rgb <.8,.87,1> /* *.2scattering { 1, rgb .3 extinction 0 }*/ absorption .5 density { pigment_pattern { pigment_pattern { average pigment_map { [1 planar scale .7 //- stop this low quality media interfering with the sky translate -y*.8 scale 1/3 warp { turbulence .2 octaves 3 } scale 3 poly_wave 3 //cubic_wave ] [1 pigment_pattern { granite scale 8 scale 1/3 warp { turbulence 2 octaves 3 } scale 3 scale 10 warp { turbulence .5 } scale 1/10 //scale <1,.2,1> Shear_Trans(x,y/3+x/3,z) colour_map { [0 rgb 1] [.3 rgb 0] } } poly_wave 3 ] } } colour_map { [.5 rgb 0] [1 rgb 1] } } cubic_wave //poly_wave 4 density_map { [0 rgb 0] [1 rgb 8] } translate z*1 } intervals 6 aa_threshold 1/256 } } }// */ #end //general fogging //pov's fog effect is visible under water. turning the water white. //so instead, fill a volume that stops just below the water line intersection { sphere { 0, 200 scale <1,.1,1> } plane { -y, 2 } hollow no_shadow no_reflection pigment { rgbt 1 } interior { media { absorption .02 density { planar scale 3 translate 0 poly_wave 2 } intervals 4 } //fog, dark to support godrays media { //"god rays" - fake rays of light shining through gaps in clouds using emissive media and nice pattern emission rgb <1,1.2,1.2>*.12 absorption 0 density { pigment_pattern { #declare light_x = sunDir.x; #declare light_y = sunDir.y; #declare light_z = sunDir.z; function { max(0, 2*f_granite(x-y*light_x/light_y,0,z-y*light_z/light_y) -1 ) } cubic_wave scale 20 } density_map { [-.0 rgb 0] //-ve indices => don't quite hit black, so we get some overall fog. [1 planar scale 3 translate 0 poly_wave 2] } } intervals 6 aa_threshold 1/256 jitter .03 } } }// */