Coder Social home page Coder Social logo

tarptaeya / path_tracer Goto Github PK

View Code? Open in Web Editor NEW
39.0 39.0 1.0 2.99 MB

Accelerated path tracing in pure Ruby

Ruby 100.00%
aabb bvh bvh-tree parallel-processing path-tracing pathtracing procedural-textures ray-tracing raytracing reflection refraction texture-mapping wavefront-obj

path_tracer's People

Contributors

tarptaeya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

architecture

path_tracer's Issues

Parallel processing

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.