1 -- Textures for raymarcher
5 local function make_phong(lights, colour, amb, spec, shiny)
6 return function (location, ray_dir, normal, count)
7 local thiscol = {0, 0, 0}
8 local reflected_ray = V.normalize(normal*(ray_dir*normal*2) - ray_dir)
9 for _,light in ipairs(lights) do
10 local light_dir = V.normalize(light-location)
11 local Iamb = math.max(normal*light_dir, 0)
12 local Ispec = math.pow(math.max(light_dir*reflected_ray,0),shiny)
14 thiscol[1] = thiscol[1] + colour[1]*Iamb*amb + Ispec*spec
15 thiscol[2] = thiscol[2] + colour[2]*Iamb*amb + Ispec*spec
16 thiscol[3] = thiscol[3] + colour[3]*Iamb*amb + Ispec*spec
23 local function make_count_texture()
24 return function (location, ray_dir, normal, count)
25 return {count/10, count/10, count/10}
31 make_phong = make_phong,
32 make_count_texture = make_count_texture