The Korn shell RayTracer
krt [-s sqrt] [-n nearest]
krt is the beginning of a raytracer written in pure shell.
There is actually nothing particularly korny about it, this is just a reference to my other project kbf.
It is currently compatible with ksh and bash, and probably with any shell implementing the local
keyword.
The option -s
allows to select among three algorithms to calculate the square root of a given number: heron
, newton
and bakhshali
.
All three are implemented in sqrt.sh
.
The default algorithm is newton
and was picked at random.
The option -n
allows to select two methods of finding the nearest approximation of square root: dynamic
and fixed
.
The first method, dynamic
, is extremely slow and should not be used.
The second, fixed
, is the default but required a pre-generated list of squares named perfect_squares.txt
.
Such a list can be generated beforehand using this helper script:
$ perfect_squares.sh > perfect_squares.txt
For now there are no scene, no floor, no lights, just a hanging red sphere on a blue background. This is the same as section 5 of Ray Tracing in One Weekend.
Here it is:
It took my laptop 47 minutes to generate it.
- Any a-bit-more-than-POSIX shell.
There is a makefile available, just run make
.
Note that there are no install
rule.
Either send send GitHub pull requests or send patches on SourceHut.
All the code is licensed under the ISC License.