-- Textures for raymarcher require "Vector" local V = Vector local function make_phong(lights, colour, amb, spec, shiny) return function (location, ray_dir, normal, count) local thiscol = {0, 0, 0} local reflected_ray = V.normalize(normal*(ray_dir*normal*2) - ray_dir) for _,light in ipairs(lights) do local light_dir = V.normalize(light-location) local Iamb = math.max(normal*light_dir, 0) local Ispec = math.pow(math.max(light_dir*reflected_ray,0),shiny) thiscol[1] = thiscol[1] + colour[1]*Iamb*amb + Ispec*spec thiscol[2] = thiscol[2] + colour[2]*Iamb*amb + Ispec*spec thiscol[3] = thiscol[3] + colour[3]*Iamb*amb + Ispec*spec end return thiscol end end local function make_count_texture() return function (location, ray_dir, normal, count) return {count/10, count/10, count/10} end end Textures = { make_phong = make_phong, make_count_texture = make_count_texture } return Textures