0

I encountered a very strange problem while learning Raymarching. My equation cannot be displayed well. It can be displayed well in matlab. But it can't be shown on Shadertoy at all.

My equation:

f(x,y,z) = (x^2+y^2+z^2)^2+2*y*(x^2+y^2+z^2)+2*(x^2+z^2);

code in matlab:

f =@(x,y,z) (x.^2+y.^2+z.^2)^2+2*y*(x.^2+y.^2+z.^2)+2*(x.^2+z.^2);
fimplicit3(f)

matlab displays a normal picture

code in shadertoy:

float sdRound(vec3 p)
{
   float lengthXYZ = (p.x * p.x+p.y * p.y+p.z * p.z); 
   return lengthXYZ * lengthXYZ+2.0 * p.y * lengthXYZ+2.0 * (p.x * p.x+p.z * p.z);
}

I learned, practiced, and modified the iq code. (https://www.shadertoy.com/view/Xds3zN).

But it cannot be displayed normally. Shadertoy displays abnormal pictures Shadertoy displays abnormal pictures

I don't know where the problem occurred. Please help me. Has troubled me for a long time.

Forgive my poor English. I use Google Translate.

Joy900
  • 1

1 Answers1

0

Your problem seems to lay in the very understanding of what raymarching is.
Your formula mathematically describes a surface (that is why it is displayed nicely in matlab), but this is not how raymarching works.
Defining an object for raymarching means defining a distance function for your object (which is different from a function mathematically describing its surface). These functions are identical for zero-returned values (which means coordinates are on the surface), but they are different for other values.
To create something similar to your object, I would suggest to explore the sdRoundCone method from iq's Raymarching primitives, as it seems the closest to what you want to achieve.

Astor Bizard
  • 231
  • 1
  • 3
  • 11