tarptaeya / path_tracer Goto Github PK
View Code? Open in Web Editor NEWAccelerated path tracing in pure Ruby
Accelerated path tracing in pure Ruby
Using the parallel gem:
require 'parallel'
module PathTracer
class Scene
# ...
def render(ns=1, file="output.ppm")
puts "writing #{file}"
# produce a 2d array of all pixels:
pixels = (0...@height).to_a.product((0...@width).to_a)
# use all CPU cores for the heavy lifting:
data = Parallel.map(pixels) do |y,x|
col = Vector[0, 0, 0]
(1..ns).each do |s1|
(1..ns).each do |s2|
i = (x + (s1 - Random.rand) / ns) / @width.to_f
j = (y + (s2 - Random.rand) / ns) / @height.to_f
ray = @camera.ray(i, j)
col += color(ray)
end
end
percentage = (y * @width + x) * 100 / (@width * @height - 1)
printf("\r[%-20s] %d%%", "=" * (percentage / 5), percentage)
col /= (ns * ns).to_f
end
# Write the file as before...
Running on a 12 core linux box:
[nix-shell:~/src/path_tracer]$ time ruby -Ilib ./examples/cover.rb && convert cover.ppm cover.png
writing cover.ppm
[=================== ] 99%%
real 1m36.414s
user 17m6.289s
sys 0m3.612s
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.