Jump to content

Caustics - not able to accumulate light contribution because of Parallelism?


drido

Recommended Posts

Hi, I try to accumulate refracted light through a water surface on the ground with a detail vex wrangle.

My code so far is this, with the ground being input 0 and the water surface being input 1:

vector sunDir = {0, -1, 0};
float ior = 1.33;
int numpt1 = npoints(1);
vector hitPoint;
float u, v;

for(int i = 0; i<numpt1; i++)
{
  vector Psurf = point(1,"P", i);
  vector Nsurf = normalize(point(1,"N", i));
  vector refractRay = refract(sunDir, Nsurf, ior);
  int hitPrim = intersect(0, Psurf, refractRay, hitPoint, u, v);
  int nearPoint = nearpoint(0, hitPoint);
  vector cdTemp = pointattrib(0, "Cd", nearPoint, 0);
  cdTemp += 0.1;
  setpointattrib(0, "Cd", nearPoint, cdTemp, "set");
}
 

While I do get the caustic pattern on the ground, it doesn't seem to accumulate the light as I intend to do with the last 3 lines.

Instead of adding 0.1 to the current Cd value each time a point gets hit in a loop step, it only ever outputs 0 or 0.1 as final color value.

I suspect this being due to some parallel execution when I read from/write to points on the second input.

I also tried a foreach loop as well as collecting the hit points in a detail array and iterate over that, with the same result.

When I did a nested loop to run over every point on the second input for each hit point it does yield the desired result, but becomes really slow at a grid resolution of about 100x100. Which is understandable as it runs 10.000 times 10.000  = 100 Million times according to my understanding.

 

Would anyone know how I can set this up so I can accumulate the color values efficiently on the hit points of the ground surface?

 

thx+cheers

hendrik

Link to comment
Share on other sites

Thanks a lot Yunus!

I guess you take a much more elegant approach and shuffled the inputs around a bit compared to mine.

Your technique seems to be proven and part of your course, so I'll give it a try understanding, thanks a lot again.

Btw, I am am intrigued of how you embedded the video, as the first image before starting shows the code, yet that image is nowhere to be found in the video :) 

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...