Giter VIP home page Giter VIP logo

blackstar's Introduction

blackstar

A black hole ray tracer written in Haskell.

An example image

Goals

  • Fast, parallel ray tracing
  • Render Schwarzschild black holes
  • Gracefully deal with coordinate singularities - maybe switch to Cartesian coordinates? Now using Cartesian coordinates for Schwarzschild
  • Render accretion disks
  • Use a star catalog for the celestial sphere
  • Produce wallpaper quality material by smoothing the images
  • Use automatic differentiation to compute the Christoffel symbols from a user-supplied metric As an idea this is fine, but it was painfully slow. Probably will return to that some day

What about the name?

It is a tribute to David Bowie, referring to his last album.

Building

Use stack to build this. First clone the repo, then run stack build and follow the instructions given by stack. You should be able to build blackstar on any platform where you can install stack.

This repository includes a star lookup tree (stars.kdt), which has been generated from the PPM star catalog. The prebuilt tree in binary form is included for convenience, but you can also build it yourself. First, remove stars.kdt. Download this archive and extract the file PPM to the root folder of this project. Then run blackstar and the tree should be automatically generated and saved.

Usage

When blackstar has been built with stack, you can run it with

stack exec blackstar -- [-p|--preview] [scenename]

Notice the two dashes (--) which are required to terminate stack's argument list.

Scenes are defined using YAML config files. Look in the scenes folder for examples. blackstar looks for scenes under the scenes folder, so you'll have to put your scenes there, too. The scene file name should be passed to blackstar without the .yaml ending. If no scene name is passed, blackstar will render the default scene. The example image is exactly this scene.

The rendered files go into the folder output, named scenename.png and scenename-bloomed.png. The --preview flag can be used to render small-sized previews of the scene while adjusting the parameters.

Better images can be achieved by rendering larger than the target size and then scaling down (some antialiasing is achieved).

Profiling

Thanks to stack, profiling is incredibly easy. Rebuild blackstar by running

stack build --profile

and then run it with

stack exec blackstar -- +RTS -p

The profile will be generated to blackstar.prof.

Implementation

JuicyPixels and repa were used for fast, parallel computation of the image.

kdt was used for fast lookups into a star catalog. I had to customise the library just a tiny bit to be able to serialize and store the trees, so currently stack will download and use my fork of kdt.

Things I've learnt

  • Using explicit Double datatypes instead of polymorphism via the Floating typeclass can make a huge difference in terms of speed
  • Automatic differentiation is a really elegant idea but comes with an overhead
  • How to spell Schwarzchild correctly

Inspiration

This project was heavily inspired by this excellent article and the Python code by rantonels. Without him, this project would never have born. You'll most certainly notice some similarities but also differences.

The movie Interstellar did an excellent rendition of a black hole. They also published a paper describing their discoveries.

This project was started when I was taking a general relativity course. On the course, Sean Carroll's lecture notes were followed and proved very helpful for me.

TODO

As always, there's a plenty of room for improvement. For example:

  • Implement supersampling
  • Investigate different integrators
  • Redshifting of the accretion disk?
  • Learn more about GHC and optimize the heck out of this
  • Faster Gaussian blur (a minor thing but become restrictive on larger image sizes)
  • Better progress reporting (might be hard to do)

Pull requests are welcome! If you find some cool scenes, I'd appreciate if you contributed them to this repository.

blackstar's People

Contributors

flannelhead avatar

Watchers

 avatar  avatar

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.