X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=Render.lua;h=f690ab77d33630cd8822f9b542b45d470ded8bd7;hb=HEAD;hp=17f244d47e5c1e3cc0dc4230ed82adac2dd59f3d;hpb=ef4dde6203d251741131f06824200c3d7f01f56d;p=raymarcher.git diff --git a/Render.lua b/Render.lua index 17f244d..f690ab7 100644 --- a/Render.lua +++ b/Render.lua @@ -12,12 +12,12 @@ local O = Operations require "Textures" local T = Textures -local eps = 0.01 +local eps = 0.001 local max_dist2 = 30^2 local bg_col = {0.1,0.1,0.1} local function calculate_normal(sdf, l) - local delta = 1e-3; + local delta = eps/10 return V.new{sdf(l+V.x*delta).dist-sdf(l-V.x*delta).dist, sdf(l+V.y*delta).dist-sdf(l-V.y*delta).dist, sdf(l+V.z*delta).dist-sdf(l-V.z*delta).dist}/(2*delta) @@ -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) @@ -54,7 +54,6 @@ local function render(scene, width, height, filename) local normalize = V.normalize -- optimization for y=1,height do - if y % math.floor(height/10) == 0 then print(y/math.floor(height/10) * 10 .. "%") end @@ -64,15 +63,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()