Why does the sphere rendered by my shader code on the model appear distorted (not a perfect circle), especially at the edges/corners of the model?

Knight_Steven
Mon, 23 Mar 2026 01:05:05 +0000
Rendering

If you’re familiar with ray marching in Unreal Engine 5.7:Why does the sphere rendered via my ray marching shader code on 3D models (e.g., cylinders, cubes) appear distorted (not a perfect circle), with obvious deformation at the edges/corners of the model surfaces?

float3 rayOrigin = worldPos;

float3 rayStep = viewDir * 1;

for (int i = 0; i < 256; i++)

{

float dist = length(rayOrigin - sphereCenter) - sphereRadius;

if (dist < 0.01)

{

opacityMask = 1;

return float3(1, 0, 0);

}

rayOrigin += rayStep;

}

opacityMask = 0;

return float3(0, 0, 0);

3 posts - 3 participants