Ray - Ray Tracing - Shader Learning

Ray Tracing

Ray

Task

Let's assume that the lower left corner of the screen corresponds to (-1.0, -1.0) and the upper right corner is (1.0, 1.0). The z coordinate is 0.0:



A ray extends from the origin O to the point with coordinates of the current fragment:



Calculate the length of the ray for each fragment and output the value as the red color channel. Consider the aspect ratio of the screen.

Theory

A ray is a line having an origin point O and extending to infinity in a given direction D:


P(t) = O + D * t

where t is allowed to be greater than or equal to zero.