Jump to content

Ray SOP ignore backfaces


Rikrok

Recommended Posts

you probably can't do that in Ray SOP

but you can use intersect_all() VEX function or VOP to get all intersections along the line, then check in for loop for first one that is not back facing

Edited by anim
Link to comment
Share on other sites

  • 4 years later...

if you want your ray to continue through all backfaces and hit something behind you'd need to do something along the lines suggested in previous posts

vector t = chv("t");
vector dir = normalize(chv("dir"));
float maxlength = chf("maxlength");

// get all intersection
int prims[];
vector hitPs[], primuvs[];
intersect_all(1, t, dir*maxlength, hitPs, prims, primuvs, .001, .001);

// filter out backface intersections and stop at first frontface
vector outP = t + dir*maxlength;
foreach(int i; vector hitP; hitPs){
    int prim = prims[i];
    vector primuv = primuvs[i];
    vector hitN = primuv(1, "N", prim, primuv);
    
    float dot = dot(dir, hitN);
    if (dot < 0){
        outP = hitP;
        break;
    }
}

// create line
int pt0 = addpoint(0, t);
int pt1 = addpoint(0, outP);
addprim(0, "polyline", pt0, pt1);

 

ts_intersect_ignore_backfaces.hip

Edited by anim
  • Like 2
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...