From: Tim Vaughan Date: Fri, 24 Feb 2023 13:22:39 +0000 (+0100) Subject: Switched output format to P6. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=13e125dc80612c40964a06888ac750095752dbac;p=raymarcher.git Switched output format to P6. --- diff --git a/Render.lua b/Render.lua index 17f244d..57cb407 100644 --- a/Render.lua +++ b/Render.lua @@ -43,7 +43,7 @@ local function render(scene, width, height, filename) print("Rendering to file " .. filename .. "...") local f = io.open(filename, "w") - f:write("P3 ", width, " ", height, " 255\n") + f:write("P6 ", width, " ", height, " 255\n") local c = scene.camera local cam_dir = V.normalize(c.point_at - c.location) @@ -64,15 +64,13 @@ local function render(scene, width, height, filename) for x=1,width do local ray_dir = normalize(rayy + right*((x/width - 0.5)*c.fov)) local col = march(c.location, c.location, ray_dir, scene.sdf, 0) - col = {math.min(col[1]*255, 255), - math.min(col[2]*255, 255), - math.min(col[3]*255, 255)} + col = {math.floor(math.min(col[1]*255, 255)), + math.floor(math.min(col[2]*255, 255)), + math.floor(math.min(col[3]*255, 255))} - f:write(math.floor(col[1]), " ", math.floor(col[2]), " ", math.floor(col[3]), " ") + f:write(string.char(col[1]), string.char(col[2]), string.char(col[3])) end - f:write("\n") end - f:write("\n") f:close() diff --git a/Textures.lua b/Textures.lua index ccc7dbc..bfa1262 100644 --- a/Textures.lua +++ b/Textures.lua @@ -168,6 +168,7 @@ Textures = { make_count_texture = make_count_texture, make_solid_pigment = make_solid_pigment, make_checkered_pigment = make_checkered_pigment, + make_image_pigment = make_image_pigment, make_mandelbrot_pigment = make_mandelbrot_pigment, map_rectangular = map_rectangular, map_spherical = map_spherical diff --git a/mandel_wall.lua b/mandel_wall.lua index 3c1f741..7f55cda 100644 --- a/mandel_wall.lua +++ b/mandel_wall.lua @@ -25,22 +25,12 @@ local scene = { T.make_phong_texture(lights, T.map_rectangular( T.make_mandelbrot_pigment( - make_image_pigment("images/wood1.ppm",1), - make_image_pigment("images/wood2.ppm",1), + T.make_image_pigment("images/wood1.ppm",1), + T.make_image_pigment("images/wood2.ppm",1), 20), texture_x, texture_y), 0.2, 1.0, 0, 1)), - -- sdf = P.make_plane(V.origin, plane_normal, - -- T.make_phong_texture( - -- lights, - -- T.map_rectangular( - -- -- T.make_solid_pigment({0.5,0.2,1.0}), - -- T.make_checkered_pigment( - -- make_image_pigment("images/wood1.ppm", 1), - -- make_image_pigment("images/wood2.ppm", 1)), - -- texture_x, texture_y), 0.2, 1.0, 0.5, 20)), - camera = {location = V.new{0,-5,0}, point_at = V.new{0,0,0}, right = V.x,