#macro make_blade(LOC,THICK,HEIGHT,CURVE,STEPS) #local g_p1 = spline { natural_spline 0, <-THICK,0,0>+LOC, 1/3, <-THICK*2/3,HEIGHT/3,0>+LOC, 2/3, vrotate(<-THICK*1/3,HEIGHT*2/3,0>,x*CURVE/2)+LOC, 1, vrotate(<0,HEIGHT,0>,x*CURVE)+LOC } #local g_p2 = spline { natural_spline 0, +LOC, 1/3, +LOC, 2/3, vrotate(,x*CURVE/3)+LOC, 1, vrotate(<0,HEIGHT,0>,x*CURVE)+LOC } #local incr = 1.0/STEPS; #local mb_steps = 0; #while (mb_steps < STEPS) #local st = mb_steps/STEPS; #local pa = g_p1(st); #local pb = g_p2(st); #local pc = g_p1(st+incr); #local pd = g_p2(st+incr); #local center = (pa + pb + pc + pd)/4; #local na = vnormalize(pa-center); #local nb = vnormalize(pb-center); #local nc = vnormalize(pa-center); #local nd = vnormalize(pb-center); smooth_triangle {pa, na, pb, nb, pc, nc} smooth_triangle {pc, nc, pb, nb, pd, nd} #local mb_steps = mb_steps + 1; #end #end #declare GRASS_PATCH_SIZE = 20; #declare GRASS_PATCH_DENSITY = 10; #declare grass_rnd = seed(1234); #debug "Generating Grass Patch mesh!\n" #declare Grass_Patch = mesh { #local gp_c = 0; #while (gp_c < GRASS_PATCH_SIZE*GRASS_PATCH_SIZE*GRASS_PATCH_DENSITY) #local gp_x = (rand(grass_rnd)*2-1)*GRASS_PATCH_SIZE; #local gp_z = (rand(grass_rnd)*2-1)*GRASS_PATCH_SIZE; make_blade(, 1/6, 2/3, 5-rand(grass_rnd)*20, 8) #local gp_c = gp_c + 1; #end } #debug "Finished generating mesh!\n" #macro make_grass(MIN, MAX, Density, Seed) #local rnd = seed(Seed); #local M1 = MIN+(x+z)*GRASS_PATCH_SIZE; #local M2 = MAX-(x+z)*GRASS_PATCH_SIZE; #if (grass_method=1) #local area_size = M2-M1; #else #local area_size = MAX-MIN; #end #local area = (area_size.x * area_size.z); union { #local grass_count = 0; #while (grass_count < area*Density) #if (grass_method=1) #local trans = *area_size+M1; object {Grass_Patch translate trans} #else #local trans = *area_size+MIN; #local clip = false; #if (trans.x < M1.x) #local clip = true; #end #if (trans.x > M2.x) #local clip = true; #end #if (trans.z < M1.z) #local clip = true; #end #if (trans.z > M2.z) #local clip = true; #end #if (clip = true) object {Grass_Patch translate trans clipped_by {box {MIN, MAX+y}} bounded_by {box {MIN, MAX+y}}} #else object {Grass_Patch translate trans} #end #end #local grass_count = grass_count + 1; #end texture {pigment {color rgb y} finish {specular 1}} } #end