Add Spherical Effect to a PNG
Apply a realistic 3D spherical lens distortion effect to any PNG image with adjustable refraction, specular highlights, and export options.
About
Mapping a flat image onto a sphere requires solving the ray-surface intersection equation for every output pixel. A naive warp produces barrel distortion; a physically accurate approach traces refracted rays through a virtual glass sphere using Snell's law, where the refraction index n controls how light bends at the surface boundary. Getting this wrong produces flat-looking results indistinguishable from a cheap fisheye filter. This tool computes per-pixel surface normals, applies Phong specular reflection with configurable shininess exponent s, and uses bilinear interpolation to avoid aliasing artifacts at sub-pixel sample coordinates. The computation runs in a dedicated Web Worker thread so large images (up to 4096×4096) render without freezing your browser. Note: the model assumes a single point light source and uniform refractive medium. Real caustics and chromatic aberration are not simulated.
Formulas
For each output pixel at coordinates (x, y), we cast a ray from the camera and test intersection with a unit sphere. The parametric ray is:
where O is the ray origin and D is the normalized direction. The intersection discriminant is:
If Δ ≥ 0, the ray hits the sphere. At the hit point, the surface normal N equals the normalized position vector. The refracted direction follows Snell's law:
The refracted vector T is computed as:
where η = n1n2. The specular highlight uses the Phong model:
where ks is specular intensity, R is the reflection of the light vector about the normal, V is the view direction, and s is the shininess exponent. Texture sampling uses bilinear interpolation across the four nearest integer pixel coordinates to avoid aliasing.
Reference Data
| Material | Refractive Index (n) | Visual Effect |
|---|---|---|
| Vacuum / Air | 1.00 | No distortion (flat) |
| Water | 1.33 | Mild curvature |
| Crown Glass | 1.52 | Classic glass marble |
| Flint Glass | 1.62 | Dense optical glass |
| Crystal (Lead) | 1.80 | Strong refraction, sparkle |
| Cubic Zirconia | 2.15 | Gemstone-like bending |
| Diamond | 2.42 | Extreme distortion |
| Silicon | 3.50 | Inverted / mirrored |
| Germanium | 4.00 | Near-total internal reflection |
| Specular Exponent | 10 - 200 | Broad vs. sharp highlight spot |
| Ambient Light | 0.0 - 0.5 | Shadow depth on sphere edges |
| Small PNG (< 512px) | - | Renders in < 1s |
| Medium PNG (512-2048px) | - | Renders in 2 - 8s |
| Large PNG (2048-4096px) | - | Renders in 10 - 30s |