VEX intersect(): Sending rays after rays

   1576   2   0
User Avatar
Member
196 posts
Joined: Aug. 2011
Offline
Hi all,


I'm struggling to understand how I can use an attr wrangle node (detail mode) to send rays and then evaluate the result (without a solver that loops over frames).

From m points, I need to n rays each, check if they intersect; then if they intersect send more rays from that new point (different direction) and so on. Similar to global illumination, with the concept of 'ray depth'.

Can somebody give me a pointer in how I would structure such an approach using VEX? Is this even possible in an attr wrangle node?


Thanks for any input & cheers,
Matt
User Avatar
Member
686 posts
Joined: Sept. 2013
Online
Hi Matt,

try a do-while-loop in a point wrangle. It would update shooting positions and ray directions only when it has hit something.

int prim_hit;
vector uvw_hit;

vector pos = v@P;
vector dir = v@N;

int hit = 0;
int depth = 10;

int pts[] = array(i@ptnum);

do{
    prim_hit = intersect(1, pos + dir * 1e-3, dir * 1e3, pos, uvw_hit);
    vector nml = prim_normal(1, prim_hit, uvw_hit);
    dir = reflect(dir, nml);
    
    int pt_add = addpoint(0, pos);
    append(pts, pt_add);
    
    hit = prim_hit >= 0;
    depth--;
}

while(hit == 1 && depth > 0);

addprim(0, 'polyline', pts);
Edited by Konstantin Magnus - Dec. 8, 2021 09:24:58
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
196 posts
Joined: Aug. 2011
Offline
Hi Konstantin,

Awesome, thanks for the reply! I'll look into this!
  • Quick Links