#declare WaterScumStartWidth = ( max_extent( FinalHoverCraft ).x - min_extent( FinalHoverCraft ).x ) * 0.55;

#declare WaterScumEndWidth = WaterScumStartWidth * 1.4;

#declare WaterScumLength = ViewSize / 2.2;

#declare WaterScumPrism =
prism{ linear_sweep linear_spline 1, 0, 5,
	< -WaterScumStartWidth / 2, 0 >,
	< WaterScumStartWidth / 2, 0 >,
	< WaterScumEndWidth / 2, WaterScumLength >,
	< -WaterScumEndWidth / 2, WaterScumLength >,
	< -WaterScumStartWidth / 2, 0 >
	rotate 180 * z
	translate 0.5 * y
	rotate 180 * y
	scale < 1, 4, 1 >
}

#declare FadeDensity = 
density{ gradient z density_map{ 
	[ 0 color srgb 0 ]
	[ 0.2 color srgb 0.65 ]
	[ 1 color srgb 1 ] } 
	scale < 1, 1, WaterScumLength > 
}

#declare PlaneFunc = function{ y - 1 }

#macro PlaceWaterScum(Frame, TotalFramesNumber, Transform, ScumIntensity)
	#local WrinklesFunc = 
		function{ pattern{ wrinkles scale < 0.25, 1, 0.25 >
			warp{ repeat WaterScumLength * z flip z }
			warp{ turbulence < 1, 0, 1 > lambda 8 }  
			translate -Frame / TotalFramesNumber * WaterScumLength * z } 
		}
	
	intersection{
		isosurface{
			function{ PlaneFunc(x,y,z) - WrinklesFunc(x,y,z) * 0.2 }
			threshold 0
			accuracy 0.01
			contained_by{ box{ < -WaterScumEndWidth / 2, 1.05, 0 >,< WaterScumEndWidth / 2, 1.75, -WaterScumLength > } } 
			max_gradient 80
			max_trace 2
		}
		object{ WaterScumPrism }
		hollow no_shadow
		texture{ pigment{ color srgbt 1 } }
		interior{
			media{ emission ScumIntensity intervals 3
				density{ FadeDensity }
			}
		}
		translate -0.75 * y
		transform{ Transform }
	}
#end

#macro PlaceWaterScumBorder(Frame, TotalFramesNumber, Transform, ScumIntensity, XDelta)
	
	#local IsoXScale = 1 + ( XDelta + 1 ) / 8;
	#local DiffPrismXScale = 1 + XDelta / 8;
	
	#local WrinklesFunc = 
		function{ pattern{ wrinkles scale < 0.25, 1, 0.25 >
			warp{ repeat WaterScumLength * z flip z }
			warp{ turbulence < 1, 0, 1 > lambda 8 }  
			translate -Frame / TotalFramesNumber * WaterScumLength * z } 
		}
	
	difference{
		intersection{
			isosurface{
				function{ PlaneFunc(x,y,z) - WrinklesFunc(x,y,z) * 0.2 }
				threshold 0
				accuracy 0.01
				contained_by{ box{ < -WaterScumEndWidth / 2 * IsoXScale, 1.05, 0 >,
									< WaterScumEndWidth / 2 * IsoXScale, 1.75, -WaterScumLength > } } 
				max_gradient 80
				max_trace 2
			}
			object{ WaterScumPrism scale < IsoXScale, 1, 1.1 > }
		}
		object{ WaterScumPrism scale < DiffPrismXScale, 4, 1.2 > }
		hollow no_shadow
		texture{ pigment{ color srgbt 1 } }
		interior{
			media{ emission ScumIntensity intervals 3
				density{ FadeDensity }
			}
		}
		translate -0.75 * y
		transform{ Transform }
	}
#end