home/ atoms/ sky-gradient-ray-direction

The y-component of the ray direction provides a natural UV for sky gradient and cloud placement

In a raymarcher the sky is rendered for rays that escape the scene. The ray direction’s y-component (rd.y) naturally ranges from -1 (looking straight down) to +1 (looking straight up), with 0 at the horizon. This gives a free parameterization for the sky: blend from a bright desaturated grey at rd.y=0 (horizon haze) to deep blue at rd.y=1. For clouds, intersect a virtual horizontal plane at height H with the ray to get 2D UVs (uv = rd.xz / rd.y) and evaluate a smooth-stepped sine pattern on those UVs.

Examples

vec3 sky = mix(horizonColor, zenithColor, clamp(rd.y,0.,1.)); vec2 cloudUV = rd.xz/rd.y;

Assessment

Explain why rd.xz / rd.y gives the correct horizontal coordinates at height H for cloud UVs regardless of camera position.

“rd xc divided by rd dot y, so redirection xc divided by y, and then some offsets based on world space, all the genes, but you can neglect those if you are in an infinite cube map anyways”
corpus · inigo-quilez-live-coding-happy-jumping-video · chunk 21