So the way i was doing it i was sending a list of all planets position to the fragment shader but instead i needed to send them individualy and the list of all the planets why? Simple because for each planet we need to check if there is an intersection within their ray direction so ultimately my theory was to check where the ray would intersect with the UV coordinates but later i find out that it was because of the computation t += dist looks susceptible to floating point inaccuracies.
vec3 computeShadow(in vec3 lightPos) {
float t = 0.0;
vec3 ro = lightPos;
vec3 rd = normalize(sphereOrigin - lightPos);
float maxDistToSphere = length(lightPos - sphereOrigin) - sphereRadius;
for (int i = 0; i < 100 && t < maxDistToSphere; i++) {
vec3 p = ro + t * rd; // Position along the ray
float minDist = 1e9;
// Check to each sphere (planet)
for (int k = 0; k < planetCount; k++) {
vec3 toPlanet = normalize(spheresOrigin[k] - lightPos);
// Check if the planet is roughly in the ray direction
if (dot(rd, toPlanet) > 0.99) { // Allowing a slight tolerance
float dist = SDF(p, spheresOrigin[k], spheresRadius[k]);
minDist = min(minDist, dist);
}
}
// If the ray is close enough to a surface, consider it in shadow
if (minDist < 0.01) return vec3(t / float(80) * 4.0); // Soft shadow effect
t += minDist; // Step forward along the ray
}
// If no shadow encountered, return light
return vec3(1.0);
}
the maxDistToSphere is the length between the sun and a planet point in the sphere
and in the if condition here if (dot(rd, toPlanet) > 0.99)
we check the direction of those planets if they align with the planet that we are currently checking if they are perfectly align we calculate their distance and return soft shadow if t reaches a distance higher than maxDistToSphere so no planet were in the same direction