X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=Textures.lua;h=324a2d24287b0d487e15590abb998932e2da0816;hb=06059eb522f33574680bb75bb73f28e2b0f6e836;hp=bfa12625f87823a907fc9c1a6d0f5bdf35e7a9ec;hpb=13e125dc80612c40964a06888ac750095752dbac;p=raymarcher.git diff --git a/Textures.lua b/Textures.lua index bfa1262..324a2d2 100644 --- a/Textures.lua +++ b/Textures.lua @@ -3,6 +3,9 @@ require "Vector" local V = Vector +require "Colours" +local C = Colours + local function make_phong_texture(lights, mapped_pigment, amb, diff, spec, shiny) local normalize = V.normalize @@ -29,6 +32,7 @@ local function make_phong_texture(lights, mapped_pigment, amb, diff, spec, shiny local light_dir = (light-location)/light_dist local vis = light_visibility(location + light_dir*eps, light_dir, eps, light_dist, 1, sdf) + -- local vis = 1.0 local Idiff = math.max(normal*light_dir, 0) local Ispec = math.pow(math.max(light_dir*reflected_ray,0),shiny) @@ -139,6 +143,18 @@ local function make_mandelbrot_pigment(set_pigment, nonset_pigment, max_iter) end end +local function make_rainbow_pigment(scale) + return function (x,y) + + local Ired = math.sin(x/math.pi/scale)^2 * math.sin(y/math.pi/scale)^2 + local Igreen = math.cos(x/math.pi/scale)^2 * math.sin(y/math.pi/scale)^2 + local Iblue = math.sin(x/math.pi/scale)^2 * math.cos(y/math.pi/scale)^2 + + return C.red*Ired + C.green*Igreen + C.blue*Iblue + end +end + + -- Mapping functions -- These functions define mappings from 3D world coordinates to 2D @@ -169,6 +185,7 @@ Textures = { make_solid_pigment = make_solid_pigment, make_checkered_pigment = make_checkered_pigment, make_image_pigment = make_image_pigment, + make_rainbow_pigment = make_rainbow_pigment, make_mandelbrot_pigment = make_mandelbrot_pigment, map_rectangular = map_rectangular, map_spherical = map_spherical