1 -- Textures for raymarcher
5 local function make_phong_texture(lights, pigment, amb, diff, spec, shiny)
6 local normalize = V.normalize
7 return function (location, ray_dir, normal, count)
8 local colour = pigment(location[1],location[3])
9 local thiscol = {colour[1]*amb, colour[2]*amb, colour[3]*amb}
11 local reflected_ray = ray_dir - normal*(ray_dir*normal*2)
12 for _,light in ipairs(lights) do
13 local light_dir = V.normalize(light-location)
14 local Idiff = math.max(normal*light_dir, 0)
15 local Ispec = math.pow(math.max(light_dir*reflected_ray,0),shiny)
17 thiscol[1] = thiscol[1] + colour[1]*Idiff*diff + Ispec*spec
18 thiscol[2] = thiscol[2] + colour[2]*Idiff*diff + Ispec*spec
19 thiscol[3] = thiscol[3] + colour[3]*Idiff*diff + Ispec*spec
26 local function make_count_texture(scale)
27 return function (location, ray_dir, normal, count)
28 return {count*scale, count*scale, count*scale}
32 local function make_flat_texture(pigment)
33 return function (location, ray_dir, normal, count)
34 return pigment(location[1], location[2])
38 local function make_solid_pigment(colour)
44 local function make_checkered_pigment(colour1, colour2)
46 if (x%1 < 0.5 and y%1 < 0.5) or (x%1 > 0.5 and y%1 > 0.5) then
55 make_phong_texture = make_phong_texture,
56 make_flat_texture = make_flat_texture,
57 make_count_texture = make_count_texture,
58 make_solid_pigment = make_solid_pigment,
59 make_checkered_pigment = make_checkered_pigment