This is what I have done so far. I followed this video as closely as I can.
[link text][1]
The custom hlsl code they use is
///////////MetaBalls Simple
float3 CamVec = normalize(WorldPos-View.ViewOrigin);
float3 curpos = WorldPos;
float3 normal = 0;
int maxsteps = 16;
float curdist, accum = 0;
float minstepsize = 0.01;
int i = 0;
while(i < maxsteps)
{
curdist = CustomExpression0(Parameters, curpos, k, Sphere1, Sphere2, Sphere3, t);
if(curdist < tresh)
{
return float4(1,1,1,1);
}
curpos += CamVec * max(minstepsize, curdist);
minstepsize += 0.02;
i++;
}
return 0;
and
//////// evaluate the distance
float s1 = distance(Sphere1.xyz, curpos)-Sphere1.w;
float s2 = distance(Sphere2.xyz, curpos)-Sphere2.w;
float s3 = distance(Sphere3.xyz, curpos)-Sphere3.w;
float dot1 = dot( normalize(curpos-Sphere1.xyz), float3(0.707,0.707,0) )-1;
float dot2 = sin( dot1*2 + (t*2) ) * 1.5;
dot2 += sin( dot1*24 + (t*8) ) * 0.07;
s1 -= dot2;
float h = saturate( 0.5+0.5*(s2-s1)/k );
s2 = lerp( s2, s1, h ) - k*h*(1.0-h);
h = saturate( 0.5+0.5*(s3-s2)/k );
float curdf = lerp( s3, s2, h ) - k*h*(1.0-h);
return curdf;
I have been trouble shooting for a couple of hours now and I can’t seem to find any reason to why mine has error and the one they show of in the video works.
This is my errors.