POV-Ray : Newsgroups : povray.binaries.images : Greenfingers Server Time
18 Nov 2024 08:16:20 EST (-0500)
  Greenfingers (Message 1 to 7 of 7)  
From: Bill Pragnell
Subject: Greenfingers
Date: 3 Oct 2005 11:45:01
Message: <web.43415118a04cd996731f01d10@news.povray.org>
I've been trying to write some macros to generate grass, and a couple of my
experiments have turned out reasonably pretty so I thought I'd share.

The grass is formed clump by clump, each clump having an adjustable width
and height and composed of a specified number of curved leaves built from
triangles. The curves are parabolas, I guess - as each blade is generated
it "falls" away from the central axis. At first I put the macro calls
inside one large mesh, but this turned out to be inefficient, so now I
define a single clump as a mesh and then copy it wherever I want (using
trace() in these examples). Rendering time is reasonable even with 10,000 -
20,000 clumps; these examples were slowed down by the isosurface scenery as
much as anything else.

Of course, there are plenty of grass macros knocking around but it's so much
more satisfying and customisable when you do-it-yourself!

Bill


Post a reply to this message


Attachments:
Download 'grass3.jpg' (284 KB)

Preview of image 'grass3.jpg'
grass3.jpg


 

From: Bill Pragnell
Subject: Re: Greenfingers
Date: 3 Oct 2005 11:50:01
Message: <web.43415260c3fd9719731f01d10@news.povray.org>
And t'other


Post a reply to this message


Attachments:
Download 'grass4.jpg' (156 KB)

Preview of image 'grass4.jpg'
grass4.jpg


 

From: Paolo Gibellini
Subject: Re: Greenfingers
Date: 4 Oct 2005 04:33:42
Message: <43423e66$1@news.povray.org>
Nice reflections!
Is a slow- or fast-render macro?
;-)
Paolo

> I've been trying to write some macros to generate grass, and a couple of
my
> experiments have turned out reasonably pretty so I thought I'd share.
>
[...]
> Bill
>


Post a reply to this message

From: Bill Pragnell
Subject: Re: Greenfingers
Date: 4 Oct 2005 09:40:00
Message: <web.434285f2c3fd9719731f01d10@news.povray.org>
> Nice reflections!
Thanks!

> Is a slow- or fast-render macro?
Don't know. I wasn't trying for speed, just realistic medium-detail grass. I
can specify fewer steps in the curve of each blade, and fewer blades in the
clump, but then I'd need more clumps for the same coverage. I have no idea
which would be faster.

For all I know everyone else's grass grows just as slowly as mine. And is
probably greener, too... :)

B


Post a reply to this message

From: Rick Measham
Subject: Re: Greenfingers
Date: 4 Oct 2005 20:42:34
Message: <4343217a$1@news.povray.org>
Bill Pragnell wrote:
> I've been trying to write some macros to generate grass, and a couple of my
> experiments have turned out reasonably pretty so I thought I'd share.

G'day Bill,

This grass looks spectacular .. I love the clump idea rather than the 
individual blade .. any chance of freeing the source?

My current house just has a small bump with a large y scale, which is 
very fast and looks fine from a distance, but I'd love to be able to 
swap in a really nice grass like this for close-up renders.

Cheers!
Rick Measham


Post a reply to this message

From: Bill Pragnell
Subject: Re: Greenfingers
Date: 5 Oct 2005 07:25:00
Message: <web.4343b6f2c3fd9719731f01d10@news.povray.org>
Rick Measham <rickm*at%isite.net.au> wrote:
> This grass looks spectacular .. I love the clump idea rather than the
> individual blade .. any chance of freeing the source?
No problem at all. I almost included it on the original post, but couldn't
be bothered to prune it! Naturally, it could probably do with some
refining, and it should be simple to play with the precise blade geometry
if you want it to more closely resemble real grass. Note that GrassBlade()
or GrassClump() calls must be inside a mesh { } definition.

Also note that this grass isn't really suitable for modelling e.g.
spider-plants, where the leaves can hang down - these blades only grow
upwards.
Enjoy!

#declare r1 = seed(1);

// pos = position vector of blade base
// dir = direction vector of central axis
// hgt = max blade height
// wid = max blade "radius"
// thick = width of blade base
// segments = number of straight lines ni curve
#macro GrassBlade(pos, dir, hgt, wid, thick, segments)
  #local seg = 1;
  #local ri = wid / segments;
  #local r = ri;
  #local yi = dir * hgt / segments;
  #local yp = yi;
  #local ux = vnormalize(vcross(<rand(r1),rand(r1),rand(r1)>, dir));
  #local uy = vnormalize(vcross(ux, dir));
  #local ang = rand(r1)*360;
  #local opos = pos;
  #local npos = pos + ux*r*sin(radians(ang)) + yp + uy*r*cos(radians(ang));
  #local opvec = vnormalize(vcross(npos-pos, dir))*thick;
  #local npvec = opvec * (segments-1) / segments;
  #while (seg <= segments)
    triangle { opos+opvec, opos-opvec, npos-npvec }
    triangle { opos+opvec, npos-npvec, npos+npvec }
    #local r = r + ri;
    #local ri = ri * 1.25;
    #local yp = yp + yi;
    #local opos = npos;
    #local npos = pos + ux*r*sin(radians(ang)) + yp +
uy*r*cos(radians(ang));
    #local opvec = npvec;
    #local npvec = npvec * (segments-seg) / segments;
    #local seg = seg + 1;
  #end
#end

// p, d, mh, mw, thick, segments as above
// blade = no of blades
#macro GrassClump(p, d, mh, mw, thick, segments, blades)
  #local n = 0;
  #while (n < blades)
    GrassBlade(p, d, rand(r1)*mh+mh*0.2, rand(r1)*mw+mw*0.2, thick,
segments)
    #local n = n + 1;
  #end
#end

#declare Clump = mesh {
  GrassClump(<0,0,0>, <0,1,0>, 0.08, 0.08, 0.005, 5, 10)
  pigment { color rgb <0.7,1,0.5> }
  finish { ambient 0 phong 0.75 phong_size 10 } }

// gradient-dependent grass
// TestThing = some landscape, i.e. isosurface
// tweak the line commented 'coverage angle' below for different gradients:
// currently no grass is laid if the slope is < 70 degrees from the vertical
// (i.e., > 30 degrees from the horizontal)
#declare n = 0;
#while (n < 150000)
  #declare direct = <0,0,0>;
  #declare raypos = <rand(r1)*9.95-5, 0, rand(r1)*9.95-5>;
  #declare position = trace(TestThing, <raypos.x,1,raypos.z>, <0,-1,0>,
direct);
  #declare a = 90;
  #if (vlength(<direct.x,0,direct.z>) > 0.001)
    #declare a = degrees(acos(vdot(direct,<direct.x,0,direct.z>)
/(vlength(direct)*vlength(<direct.x,0,direct.z>))));
  #end
  #if ((a > 70) & (position.y > 0)) // coverage angle
    #declare rotz = -degrees(atan2(vlength(<direct.x,0,direct.z>),
direct.y));
    #if ((direct.x=0) & (direct.z=0))
      #declare roty = 0;
    #else
      #declare roty = -degrees(atan2(direct.z,direct.x));
    #end
    object { Clump rotate <0, rand(r1)*360, 0>
                   rotate <0, 0, rotz>
                   rotate <0, roty, 0>
                   translate position }
  #end
  #declare n = n + 1;
#end
object { TestThing }

// mini-planet grass
// LittlePlanet = some closed convex surface, i.e. sphere, isosurface
#declare n = 0;
#while (n < 10000)
  #declare direct = <0,0,0>;
  #declare position = trace(LittlePlanet, <0,0,0>, <rand(r1)-0.5,
rand(r1)-0.5, rand(r1)-0.5>, direct);
  #declare rotz = -degrees(atan2(vlength(<direct.x,0,direct.z>), direct.y));
  #if ((direct.x=0) & (direct.z=0))
    #declare roty = 0;
  #else
    #declare roty = -degrees(atan2(direct.z,direct.x));
  #end
  object { Clump rotate <0, rand(r1)*360, 0>
                 rotate <0, 0, rotz>
                 rotate <0, roty, 0>
                 translate position }
  #declare n = n + 1;
#end
object { LittlePlanet }

--Bill


Post a reply to this message

From: Ken Hutson
Subject: Re: Greenfingers
Date: 7 Oct 2005 14:57:13
Message: <4346c509@news.povray.org>
"Bill Pragnell" <bil### [at] hotmailcom> wrote in message 
news:web.43415260c3fd9719731f01d10@news.povray.org...
> And t'other
>

Bill,
Excellent! My first thought was of a green tribble. Could be adapted to 
resemble coarse hair.
Kenneth

--------------------------------------------------------------------------------


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.