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