Coder Social home page Coder Social logo

d-k-e / raytracing-gl Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 2.0 1.16 MB

OpenGL compute shader port of 'Raytracing ...' series by P. Shirley

License: MIT License

CMake 0.28% GLSL 19.55% C++ 6.24% C 73.93%
opengl4 raytracer raytracing-one-weekend raytracing compute-shader compute-shaders cpp cplusplus cpp17

raytracing-gl's Introduction

raytracing-gl

OpenGL compute shader port of Raytracing in One Weekend by P. Shirley

This repository follows closely the examples introduced by the phenomenal "Raytracing in One Weekend" by P. Shirley, plus couple of other examples from "Raytracing Next Week".

I did unfortunately not document the code much, since Shirley gives a through explanation of how everything works. Assuming you have basic knowledge of opengl and glsl, it should be fairly easy to understand what's going on in the shader code.

Due to the imperative nature of glsl, I have, from time to time, diverged from the implementation of Shirley.

Requirements

These requirements basically mimick my development environment. Some of them can probably be lowered.

  • Cmake >= 3.0.2

  • OpenGL >= 4.3

  • GLFW: Path to its shared library .so file is hardcoded to CMakeLists.txt, as set( GLFW_SHARED_LIB "${PROJECT_SOURCE_DIR}/libs/glfw/src/libglfw.so") because I could not come up with a more generic solution. Please change it, point yours, or make a suggestion via issues.

  • Glad function pointers for OpenGL 4.3

  • C++ 17 for using <filesystem>

  • Clang >= 9 again for using <filesystem>.

If you are willing to use <boost/filesystem> instead of standard library, the compiler requirement can be drop to clang > 5.5, you can also use gcc with boost. If you decided to pursue this path, you should also change the filesystem header in window.hpp.

Compiling the code

  • Create "build" directory in main folder containing this README.md
  • cd build
  • cmake ..
  • make install

There will be two copies of executables one in build folder another in bin folder. Use the ones in bin folder since reference to any media is hardcoded inside the code with respect to bin.

I use cmake-gui to specifically select the compiler during the configuration process, I suggest you do the same if you have multiple compilers with different versions in your machine.

Remarks

You'll notice that most of the implementation files, .cpps, are same in nature maybe diverging 1 or 2 lines somewhere. The boilerplate code for rendering a full screen quad is in window.hpp. It can be thought of as the equivalent of .ppm output in the original book. Most of the real work happens inside compute shaders named compute01.comp or compute02.comp. The numbers suggest complexity. 01 is the simplest, 02 is a little more difficult than 01 etc.

During the execution of compute02.out and onwards gpu might start to choke. Try lowering the size of the workgroups in the shader, if that does not help, try lowering the psample and depth that is passed on to ray_color function.

Unless you have a very very good machine or a particular reason DO NOT LAUNCH ./weekend.out. It is there as a proof of concept. Ray tracing 485 object naively, that is with no acceleration structure whatsoever, would surely choke your gpu. If you really want to see something similar in cover picture. I suggest you to lover the amount of spheres in the random_scene loop, and change the SCENE_OBJ_NB accordingly.

Screenshots

  • The executable compute01.out should give you this:

  • The executable compute02.out should give you this:

  • The executable compute03.out should give you this:

  • The executable compute04.out should give you this:

  • The executable compute05.out should give you this:

raytracing-gl's People

Contributors

d-k-e avatar rjkilpatrick avatar

Stargazers

 avatar

Watchers

 avatar  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.