]> Dogcows Code - chaz/rasterize/commitdiff
add external supersampling to animate script
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Tue, 21 Feb 2012 22:00:22 +0000 (15:00 -0700)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Tue, 21 Feb 2012 22:00:22 +0000 (15:00 -0700)
animate.lua

index a1c7389f8af95fe33b24e95999812140de178078..b9fb1be73c995bf31013172f8e2bcceac4e7e4bd 100755 (executable)
@@ -11,9 +11,6 @@
 -- installed, the frames will also be combined into a video file.  This script
 -- must be called from the same directory where the rasterize program is.
 
 -- installed, the frames will also be combined into a video file.  This script
 -- must be called from the same directory where the rasterize program is.
 
--- Set the width and height of the viewport.
-local size = {w = 640, h = 480}
-
 -- Set the number of frames to be rendered for the animation.
 local frames = 360
 
 -- Set the number of frames to be rendered for the animation.
 local frames = 360
 
@@ -58,6 +55,16 @@ t -2 -1 2
 s 10 10 10
 ]]
 
 s 10 10 10
 ]]
 
+-- Set the number of samples for supersampling.  If this is set to a value of
+-- two or greater, each frame will be rendered larger by the factor specified.
+-- ImageMagick is used to scale the frames back down to size; if ImageMagick
+-- is not installed, the resulting frames will end up bigger than they should
+-- be and the aliasing problem will not be fixed.
+local supersample = 4
+
+-- Set the width and height of the viewport.
+local size = {w = 640, h = 480}
+
 -- Set the number of concurrent renderings (for multi-core machines).
 local jobs = 6
 
 -- Set the number of concurrent renderings (for multi-core machines).
 local jobs = 6
 
@@ -66,7 +73,8 @@ local jobs = 6
 ---------------------------------------------------------------------------
 
 local fmt   = string.format
 ---------------------------------------------------------------------------
 
 local fmt   = string.format
-local write = function(...) io.write(fmt(...)) end
+local write = function(...) return io.write(fmt(...)) end
+local run   = function(...) return os.execute(fmt(...)) end
 
 function vec_new(x, y, z)
     return {x = x, y = y, z = z}
 
 function vec_new(x, y, z)
     return {x = x, y = y, z = z}
@@ -82,6 +90,11 @@ end
 
 function render(i)
     while i do
 
 function render(i)
     while i do
+        local w, h = size.w, size.h
+        if 1 < supersample then
+            w = w * supersample
+            h = h * supersample
+        end
         local filename  = fmt("frames/anim%04d.bmp", i)
         local command   = fmt("./rasterize -o %s >/dev/null", filename)
         local out = io.popen(command, "w")
         local filename  = fmt("frames/anim%04d.bmp", i)
         local command   = fmt("./rasterize -o %s >/dev/null", filename)
         local out = io.popen(command, "w")
@@ -97,9 +110,12 @@ U3
 1.57 %f 0.1 1000
 %s
 X
 1.57 %f 0.1 1000
 %s
 X
-]], size.w, size.h, e.x, e.y, e.z, l.x, l.y, l.z, size.w/size.h, scene))
+]], w, h, e.x, e.y, e.z, l.x, l.y, l.z, size.w/size.h, scene))
         i = coroutine.yield()
         out:close()
         i = coroutine.yield()
         out:close()
+        if 1 < supersample then
+            run("convert %s -scale %dx%d %s", filename, size.w, size.h, filename)
+        end
     end
 end
 
     end
 end
 
@@ -110,14 +126,14 @@ for i = 1,jobs do
     table.insert(threads, coroutine.wrap(render))
 end
 
     table.insert(threads, coroutine.wrap(render))
 end
 
-os.execute("rm -rf frames && mkdir frames >/dev/null 2>&1")
+run("rm -rf frames && mkdir frames >/dev/null 2>&1")
 for i = 0,(frames-1) do
     threads[1 + (i % jobs)](i)
 end
 for _,thread in ipairs(threads) do thread(null) end
 print()
 
 for i = 0,(frames-1) do
     threads[1 + (i % jobs)](i)
 end
 for _,thread in ipairs(threads) do thread(null) end
 print()
 
-if os.execute("ffmpeg -i frames/anim%04d.bmp -b 1024k -y -an scene.avi") == 0 then
+if run("ffmpeg -i frames/anim%04d.bmp -b 1024k -y -an scene.avi") == 0 then
     print("Animation written to scene.avi.")
 end
 
     print("Animation written to scene.avi.")
 end
 
This page took 0.020976 seconds and 4 git commands to generate.