Jump to content
Rikrok

Ray SOP ignore backfaces

Recommended Posts

Is there any way for the ray sop to register a hit only on the front face of a primitive and pass through backfaces?

Share this post


Link to post
Share on other sites

Have you tried setting the Ray Combiner to "Shortest" ray?

Share this post


Link to post
Share on other sites

Have you tried setting the Ray Combiner to "Shortest" ray?

 

That doesn't work (and I wouldn't expect it to, it's not how shooting multiple rays works).

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Alternatively you can extract the hit normal and do a dot check against the the initial point normals (if dot is larger than 0, it is a backface)

and if needed, you could start a new ray at this point to check for subsequent front/backfaces

  • Like 1

Share this post


Link to post
Share on other sites

Did it myself. Works.

vector dir = v@N*1000;
vector pos;
vector uvw;

int hit_prim = intersect(@OpInput2, @P, dir, pos, uvw);
v@primN = prim_normal(1,hit_prim,uvw);

if(dot(@primN,@N) < 0){
	@P = pos;
}

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×