Jump to content

Vex random in ripple sop


Recommended Posts

I was looking at the ripple sop and wanted to add some extra noise, I found that you can't just dive inside but it is compiled vex code so I figured it can't be too hard to recreate.
Well I got pretty close but for some reason I am missing the high frequency displacement the original ripple has.
Attached is an example of the ripple Sop vs my pointvop


I guess I'll post the whole code first and then point out where my struggle lies:
 

#include <math.h>

#pragma oplabel         "Ripple"
#pragma opname          "ripple"
#pragma opicon          SOP_ripple
#pragma opmininputs     1
#pragma opmaxinputs     1

#define random0(xxx)    (random(xxx)*2.0 - 1.0)


#pragma label   usecenter       "Use Center"
#pragma label   t               "Center"
#pragma label   freq            "Frequency"
#pragma label   height          "Height"
#pragma label   decay           "Wave Decay"
#pragma label   scale           "Scale"
#pragma label   speed           "Wave Speed"
#pragma label   nripples        "Num. Ripples"
#pragma label   seed            "Random Seed"
#pragma label   up              "Up Direction"

#pragma export  freq            all
#pragma export  height          all
#pragma export  nripples        all
#pragma export  decay           dialog
#pragma export  scale           dialog
#pragma export  speed           dialog

#pragma hint    usecenter       toggle
#pragma hint    t               vector
#pragma hint    up              vector          // Direction vector

#pragma disablewhen t           { usecenter off }

#pragma range   nripples        1       10
#pragma range   decay           0.01    10

#pragma bindhandle tx           xform   "Center"    tx
#pragma bindhandle ty           xform   "Center"    ty
#pragma bindhandle tz           xform   "Center"    tz
#pragma bindhandle usecenter    xform   "Center"    onoff
#pragma bindhandle height       ladder  "Height"    parm0
#pragma bindhandle scale        xform   "Scale"     sx
#pragma bindhandle up1          vector  "Up"        vx      invisible(1)
#pragma bindhandle up2          vector  "Up"        vy      invisible(1)
#pragma bindhandle up3          vector  "Up"        vz      invisible(1)

#pragma bindselectorreserved vex_group points "Ripple Points" \
        "Select the points for Ripple and press Enter to complete" \
        all 0 "" 0 0 1

sop
ripple(int      usecenter = 0;
       vector   t = {0, 0, 0};
       float    freq = 1;
       float    height = 0.15;
       float    decay = 0.75;
       float    scale = 1;
       float    speed = 3;
       int      nripples = 3;
       int      seed=0;
       vector   up = {0, 1, 0};
    )
{
    float       xc, yc, phase;
    float       dist, len;
    vector      pos;
    vector      origin;
    vector      offset;
    int         i;

    if (usecenter)
    {
        origin = set(scale*random0(seed), scale*random0(seed+1000), 0);
        offset = t - origin;
    }
    else
    {
        offset = { 0, 0, 0 };
    }

    for (i = 0; i < nripples; i++)
    {
        xc    = scale * random0(i+seed);
        yc    = scale * random0(i+(seed+1000));
        phase =  M_PI * random(i - (seed+1000));

        pos = set(xc, yc, 0);
        pos -= P;
        pos += offset;
        len = length(pos);

        dist = height * exp(-decay*len)
                      * sin(len*(freq*M_PI*2) - Time*speed + phase);
        P += up * dist;
    }
}

I am thinking the high freq noise is coming from the phase and there seems to be a distinction between random0 and random
xc and yc are being generated with random0 and phase with random.
Also if you look at the code in houdini the random is colored blue (whatever that means.. I always wonder what all the colors mean but I guess that's for another post)

This part of the code: 
 

        xc    = scale * random0(i+seed);
        yc    = scale * random0(i+(seed+1000));
        phase =  M_PI * random(i - (seed+1000));

 

How do I translate this into VOPs is the big question for me.
Thanks in advance!

ripple.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...