This is what I end up with for now. Not sure how efficient this thing are.
Would be nice to see some comments on how to make it better, faster…
In the video there 256 iterations. It’s gives good quality for plane, some kind of 2d light.
But for the projection on sphere there is 64 iterations perfectly enough.
Also the smaler the object is, the lower iteration count needed.
It’s all based on simple version of the code from official video about ray traced metaballs.
Here’s the thing:
Material Setup:
Custom Node: Evaluate DistanceField
return GetDistanceToNearestSurfaceGlobal(curpos);
Custom Node: Raytracer
float3 RayDir = normalize(WorldPos-ActorPos);
float3 curpos = ActorPos;
float maxDist = distance(ActorPos, WorldPos);
float curdist;
float minstepsize = Radius/maxsteps;
int i = 0;
float res = 1;
float t =0;
float dist = distance(ActorPos, curpos);
while((i < maxsteps)&&(dist < maxDist))
{
dist = distance(ActorPos, curpos);
curdist = CustomExpression0(Parameters, curpos);
if (curdist < thresh ) {
return 0;
}
curpos += RayDir * minstepsize;
res = min(res, (curdist-thresh)*(dist/100)/t/Softness);
t += 1/curdist;
i++;
}
return res;
