|
|
Following is an excerpt from my "Floating Skyscrapers" scene, unfinished, to
illustrate a way of making hilly terrain geometry
It's up to you do define a nice GrassyHill texture!
See also my message in povray.general in reply to JR Lummox
/*
=========================================================
FSLAND.POVI
Defines land, hills, woods, roads for Floating
Skyscrapers
(c) Daren Scot Wilson, 1999
=========================================================
*/
/*
BULGE - basic hill/valley form used to build hillfunc
Takes <x,y> vector and params, returns z value
center = <x,y> center of hill
radius = sort of more or less the radius
- oops, radius is a keyword, use "radioo"
elong = 0 for round, 1.0 extreme elongation
elway = angle (degrees) direction of major axix
- elongation is 2nd rank symmetric tensor, trace=1.0
shape = power of ratio, normally 1 to 2 or more
decay = power for root, normally 0.5 to 1.0
- increase shape will sorta cancel decrease in decay
lop = <x,y> lopsidedness.
<0,0> is symmetric. Max is unit vector in any dir.
If lop is nonzero, is best to have shape > 2
*/
#macro bulge(pt, center, radioo, elong, elway, shape, decay, lop)
#local dx = pt.x - center.x;
#local dy = pt.x - center.y;
#local ec = elong*cosd(elway*2);
#local es = elong*sind(elway*2);
#local dd = (1+ec)*dx*dx + 2*es*dx*dy + (1-ec)*dy*dy;
#local term = pow(dd/(radioo*radioo), shape);
#local lopterm = - min(1.0, (lop.x*dx + lop.y*dy)/radioo/(term+1));
pow( term + 1.0 + lopterm, -decay)
#end
/*
hillfunc returns z for given <x,y>
*/
#macro hillfunc(point)
#local xx=point.x;
#local yy=point.y;
zgroundzero
+ 5*sin(xx/350-yy/250)
+ 3*sin(xx/83+yy/331)
+ 5*sin(xx/222+yy/46)
+ 5*sin(-xx/154-yy/37)
+ 3*sin(xx/40+yy/91)
+ 2*sin(xx/17+yy/59)
+ 4*sin(xx/188-yy/35)
+ 3*sin(xx/164-yy/31)
-40*bulge(point, < -900, 100>, 700, .3, 60, 1.8, .5, <.2,0> )
+55*bulge(point, < -600, 1100>, 240, 0, 0, 3.3, 1.1, <0,-1> )
-20*bulge(point, < -250, 1300>, 360, .5, 45, 2.0, 0.7, <-.5,-.4> )
+45*bulge(point, <-1500, 1300>, 500, .3, -10, 2.0, 1.0, <0, .2> )
// distance mountains
+500*bulge(point, <-4000, 1500>, 150, .3, 95, 7.0, 0.3, <.5,0> )
+280*bulge(point, <-3800, 2200>, 130, .3, 95, 3.0, 0.3, <-.5,.1> )
+270*bulge(point, <-3700, 2250>, 100, .3, 25, 2.0, 0.5, <0,1> )
#end
#declare hillscale = 1.5;
#macro hillpoint(xx, yy)
<xx, yy, hillscale *hillfunc(<xx,yy>)*0 >
#end
#macro hillnorm(xx,yy)
// find gradient by finite diff
#local d = 2.5;
#local gx = hillfunc(<xx+d,yy,0>) - hillfunc(<xx-d,yy,0>);
#local gy = hillfunc(<xx,yy+d,0>) - hillfunc(<xx,yy-d,0>);
< -gx/2/d, -gy/2/d, 1.0>
#end
// Check the syntax of macros
#declare yayay = hillfunc(<200,300,0>);
#declare znonzo = hillpoint(222,333);
#declare nranra = hillnorm(333,444);
// Create ground as a bezier mesh
// grid points are <hx, hy> and are nonuniformly spaced
//#declare minstep = 5; // too fine, too slow
#declare minstep = 25; // final scene
//#declare minstep = 75; // faster, fairly good
//#declare minstep = 50; // faster, fairly good
//#declare minstep = 250; // faster for testing
#if (1) // enable hilly ground
#declare hx = FinalEye.x + 100;
#while (hx > -4000)
#declare dx = minstep + abs(hx-FinalEye.x)*.20;
#declare hy = FinalEye.y;
#while (hy<4000)
#declare dy = minstep + abs(hy-FinalEye.y)*.2;
#declare se = hillpoint(hx, hy);
#declare sw = hillpoint(hx-dx, hy);
#declare ne = hillpoint(hx, hy+dy);
#declare nw = hillpoint(hx-dx, hy+dy);
#declare mm = hillpoint(hx-.5*dx, hy+.5*dy);
// normal vectors at these places
#declare nse = hillnorm(hx, hy);
#declare nsw = hillnorm(hx-dx, hy);
#declare nne = hillnorm(hx, hy+dy);
#declare nnw = hillnorm(hx-dx, hy+dy);
#declare nmm = hillnorm(hx-.5*dx, hy+.5*dy);
#if (0) // test objects to mark grid squares
sphere { se+z, 2 pigment {color rgb 1} finish {ambient .2 diffuse .7 phong
4}}
sphere { se+z+5*x, 2 pigment {color rgb 1} finish {ambient .2 diffuse .7
phong .4}}
sphere { se+z+10*x, 2 pigment {color rgb 1} finish {ambient .2 diffuse .7
phong .4}}
sphere { se+z+15*x, 2 pigment {color rgb 1} finish {ambient .2 diffuse .7
phong .4}}
sphere { se+z+15*y, 2 pigment {color rgb 1} finish {ambient .2 diffuse .7
phong .4}}
cone { se,1, sw,6 texture {GaudyWhite}}
cone { se,1, ne,6 texture {GaudyGreen}}
cone { se,1, mm,6 texture {GaudyGreen}}
#endif
#if (1) // choose mesh or bezier
mesh {
#if (1)
smooth_triangle { nw,nnw, mm,nmm, ne,nne }
smooth_triangle { ne,nne, mm,nmm, se,nse }
smooth_triangle { se,nse, mm,nmm, sw,nsw }
smooth_triangle { sw,nsw, mm,nmm, nw,nnw }
#else
triangle { nw, mm, ne }
triangle { ne, mm, se }
triangle { se, mm, sw }
triangle { sw, mm, nw }
#endif
texture { GroundTex }
}
#else
bicubic_patch {
type 1 // 0=min mem,slow 1=uses more mem, lots faster
u_steps 3
v_steps 3
flatness .1
hillpoint(hx, hy ),
hillpoint(hx-.4*dx, hy ),
hillpoint(hx-.6*dx, hy ),
hillpoint(hx-1*dx, hy ),
hillpoint(hx, hy+.4*dy ),
hillpoint(hx-.4*dx, hy+.4*dy ),
hillpoint(hx-.6*dx, hy+.4*dy ),
hillpoint(hx-1*dx, hy+.4*dy ),
hillpoint(hx, hy+.6*dy ),
hillpoint(hx-.4*dx, hy+.6*dy ),
hillpoint(hx-.6*dx, hy+.6*dy ),
hillpoint(hx-1*dx, hy+.6*dy ),
hillpoint(hx, hy+dy ),
hillpoint(hx-.4*dx, hy+dy ),
hillpoint(hx-.6*dx, hy+dy ),
hillpoint(hx-1*dx, hy+dy )
texture { GroundTex }
}
#endif // mesh/bezier enable
#declare hy=hy+dy;
#end
#declare hx = hx-dx;
#end
#end // enable hilly ground
/*----------------- Final Catch-All ground plane ----------*/
#if (1)
plane { z, -250
texture { GroundTex }
}
#endif
--
Daren Scot Wilson
dar### [at] pipelineocm
www.newcolor.com
Post a reply to this message
|
|