go to: [home]
This title isn't a typo: the ray tracer requires a shader for light calculation and this is implemented in a GPU shader program. In the shader, a lighting equation is used (for example Phong lighting model) to shade ray-object intersection points. In the shader rays are also reflected and can be used in another "instance" of the ray tracer. Material information is stored in a texture, but for simplification and sake of clarity it is implemented as a list of "if" statements here.
pixel3 ray_shade( PixelShaderInput IN )
{
pixel3 OUT;
vec4 raydir = tex2D(tex0,IN.texCoord);
vec4 raypos = tex2D(tex1,IN.texCoord);
vec4 uvt = tex2D(tex4,IN.texCoord);
vec4 colorbuf = tex2D(tex5,IN.texCoord);
float r=0.0;
float shininess = 20;
vec3 diffuse = vec3(1,1,1);
vec3 specular = vec3(1,1,1);
vec3 ambient = vec3(0.1,0.1,0.2);
vec2 EDcoord = Coord2D(4*TRIANGLE_ELEMENTS*uvt.w, EDsize);
//vec4 Vertex1 = tex2D(ED, EDcoord);
float material = tex2D(ED, EDcoord).w;
vec3 Normal1 = tex2D(ED, vec2(EDcoord.x+1.0/EDsize,EDcoord.y));
//vec3 Vertex2 = tex2D(ED, vec2(EDcoord.x+2.0/EDsize,EDcoord.y));
vec3 Normal2 = tex2D(ED, vec2(EDcoord.x+3.0/EDsize,EDcoord.y));
//vec3 Vertex3 = tex2D(ED, vec2(EDcoord.x+4.0/EDsize,EDcoord.y));
vec3 Normal3 = tex2D(ED, vec2(EDcoord.x+5.0/EDsize,EDcoord.y)); |

Output of a scene calculated on the GPU

Triangle based spheres
Reflecting room, calculated with shadows