So, I was thinking I could solve this by doing my 'light distance' equation in the fragment shader. To do this however, I need to do a 'ray to sphere' calculation, and I am a little lost. I ripped a ray to sphere function from HexiDave's spherical atmosphere shader...

Code: Select all

```
getNearIntersection( camPos, camToAtmoRay, camHeightSqr, atmoRadiusSqr );
float getNearIntersection(float3 v3Pos, float3 v3Ray, float fDistance2, float fRadius2)
{
float B = 2.0 * dot(v3Pos, v3Ray);
float C = fDistance2 - fRadius2;
float fDet = max(0.0, B*B - 4.0 * C);
return 0.5 * (-B - sqrt(fDet));
}
```

Thanks for any help!