POV-Ray : Newsgroups : povray.binaries.images : Beach Scene : Re: Beach Scene Server Time
20 Oct 2021 16:58:23 EDT (-0400)
  Re: Beach Scene  
From: BayashiPascal
Date: 23 Jul 2021 23:10:00
Message: <web.60fb8394115c8a23a3e088d5e0f8c582@news.povray.org>
"Chris R" <car### [at] comcastnet> wrote:

> I like the sand in your image as well.  Mind sharing how you generated it?
>
> -- Chris R


Hi Chris,

I've looked for the code of my "beach" scene, could find the POV-Ray script but
not the code for the generation of the beach itself. So I've re-written a script
using the idea I've (probably) used back then. See the attached image for an
example of the result it produces. Initially I've certainly written it in C,
generating a mesh, but I don't know if you're familiar with this language so I
thought a POV-Ray script would be easier. However this wouldn't be scalable to a
large scene, you'd need then to implement it in a more efficient language.
You'll also have to tweak the parameters to bring it to the aesthetic you like,
but I hope the script is enough to get the idea.

Enjoy, and ask for details if needed.

Pascal


##############################################################################


#version 3.8;

// Parametric function defining the global shape of the beach
// Return the height at (u, v)
#declare BeachShape = function (u, v) {
  // Use a simple paraboloid centered on (0.5, 0.5) as an example
  pow(u - 0.5, 2.0) * pow(v - 0.5, 2.0)
}

// Random number seed
#declare RndSeed = seed(0);

// Macro generating the beach using CSG to carve randomly placed cones
// from a box
#declare Beach = difference {

  // The box to be carved
  box { <0.0, -0.5, 0.0> <1.0, 0.5, 1.0> }

  // Number of holes to be carved
  #declare nbHole = 500;

  // Parameters controlling the radius and depth of the holes
  // bigger value for maxSizeHole gives a smoother surface
  // smaller value for maxDepthHole gives a smoother surface
  #declare maxSizeHole = 0.05;
  #declare maxDepthHole = 0.02;

  // Loop on the holes
  #declare iHole = 0;
  #while (iHole < nbHole)

    // Place randomly the hole
    #declare cu = rand(RndSeed);
    #declare cv = rand(RndSeed);

    // Get the depth and size of the hole
    #declare depthHole = BeachShape(cu, cv) - maxDepthHole * rand(RndSeed);
    #declare sizeHole = maxSizeHole * (0.5 + rand(RndSeed));

    // Create the cone carving the hole in the box
    cone {
      <cu, depthHole, cv>, 0.0
      <cu, depthHole + 1.0, cv>, sizeHole / maxDepthHole
    }

    // Step to the next hole
    #declare iHole = iHole + 1;
  #end

}

// Instanciate the beach
object {
  Beach
  // Default grey texture for test
  texture{ pigment {color rgb 0.75}}
}


// Light and Camera

global_settings {assumed_gamma 1.0}
camera {
  location 0.5 * y
  look_at 0.5 * (x + z)
}
light_source {
  y
  rgb 1.0
}
background { color rgb 1.0 }


##############################################################################


Post a reply to this message


Attachments:
Download 'test.png' (50 KB)

Preview of image 'test.png'
test.png


 

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