The objective is to write an XQuery that can convert a scene (represented in XML) that looks something like this:
<scene>
<background r="0" g="0" b="0" />
<shapes>
<plane offset="0" surface="checkerboard">
<normal x="0" y="1" z="0" />
</plane>
<sphere radius="1" surface="shiny">
<center x="0" y="1" z="0" />
</sphere>
<sphere radius=".5" surface="shiny">
<center x="-1" y=".5" z="1.5" />
</sphere>
</shapes>
<camera>
<position x="3" y="2" z="4" />
<look-at x="-1" y="0.5" z="0" />
</camera>
<light>
<position x="-2" y="2.5" z="0" />
<color r=".49" g=".07" b=".07" />
</light>
<light>
<position x="1.5" y="2.5" z="1.5" />
<color r=".07" g=".07" b=".49" />
</light>
<light>
<position x="1.5" y="2.5" z="-1.5" />
<color r=".07" g=".49" b=".07" />
</light>
<light>
<position x="0" y="3.5" z="0" />
<color r=".21" g=".21" b=".35" />
</light>
</scene>
into an image that looks something like this:
This sample was inspired by A Ray Tracer in C#3.0.
This tutorial is rather long, so it has been divided into a number of sections. Each section builds on the previous one, so it is intended that they be read in order.