POV-Ray : Newsgroups : povray.advanced-users : Isosurface Rocks, using a single iso; could use a bit of help : Re: Isosurface Rocks, using a single iso; could use a bit of help Server Time
25 Apr 2024 09:40:55 EDT (-0400)
  Re: Isosurface Rocks, using a single iso; could use a bit of help  
From: [GDS|Entropy]
Date: 9 Dec 2016 08:15:01
Message: <web.584aadff916cc6b41c3f31c90@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> I guess you mean this:
>
> // Single Rock.
> // #local RockPosition = <0, 0, 0>;
> // IsoRock(RockPosition, 4)

No, I wrote all of that...I guess I wasn't clear. The only part I didn't write
is the base Isosurface math, everything else I coded.

The part I didn't write is the following, and it uses a single Isosurface which
produces many rocks, whereas my rock maker uses one Isosurface for *every* rock.

Here is the code which uses the single iso but gives many rocks, what I am
trying to do is combine the Isosurface function from my bit that I adapted from
Tek with the single iso method below so I can use a single iso and get many
rocks but using my algorithm.

//Stone parameters
#declare GridSize = 4;            //Total number of stones =
#local GridSize = GridSize * GridSize;
#declare Width = 1 / GridSize;      //Cell width.
#declare Radius = Width * 0.70;      //Stone radius
#declare DRate = 0.875 / Radius;     //Radius deformation rate
#declare Height = 0.55;            //Stone height

//---Functions------------------------------------------------

//    Positive modulus: never returns negative values
#declare smod =
function(A, B)
{
    mod(B + mod(A, B), B)
}

//    Centered modulus
#declare cmod =
function(A, B)
{
    smod(A, 2 * B) - B
}

//    2D cells: returns a random value for each unit square
#declare f_cell2D =
function(x, z)
{
    f_snoise3d(floor(x), 0, floor(z))
}

//    Noisy modulus. Makes a random centre for each stone
#declare f_modnoise =
function(x,z)
{
    cmod(x, Width) + (Width - Radius) * f_cell2D(x * 0.5 / Width, z * 0.5 /
Width)
}


//    Randomized radius for tumbled stone shape
#declare f_Rad =
function
{
    1 + 0.45 * f_snoise3d(x * DRate, y * DRate, z * DRate)
}

//Displaced, vertically squashed spheres
#declare f_Stone =
function
{
    f_r(f_modnoise(x, z), y / Height, f_modnoise(-z, x))
}


//    The stones. Scaled so that textures appears the same,
//    no matter how many stones are done.
isosurface
{

    function
    {
        f_Stone(x, y, z) - Radius * f_Rad(x, y, z)
    }

    //    This doesn't really work, as such:
    /*
    function
    {
        (f_Stone(x, y, z) * (P(x, z, y).grey * 2.5)) - Radius * f_Rad(x, y, z)
    }
    */

    //    Many orbs.
    /*
    function
    {
        f_r(cmod(x, Width), y / Height, cmod(z, Width)) - Radius
    }
    */

    contained_by
    {
        box
        {
            <-1, -Width * Height, -1>,
            <1, Width * Height, 1>
        }
    }

    max_gradient 30
    accuracy 5e-3

    //texture{MultiStone scale 2*Width}

    scale 5.7             //Fill view with stones
    rotate -3*y
    translate <0, 0.35 * Radius * Height - 1, 1>
}


Post a reply to this message

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