Giter Club home page Giter Club logo

raytracing-slow-sol's Introduction

raytracing-slow-sol

A quick experiment on how raytraced primitives look like if they could move faster than light

Demonstrated below is a sphere and a couple of boxes. The sphere moves periodically along the X axis according to sin function. The left box is doing the same. The right box rotates around the Y axis.

Sphere diameter is 2 units, box dimensions are 1.4 x 1.4 x 1.4 units.

Speed of light is 30 units/s (fast enough to not matter a lot)

normal.mp4

Speed of light is 0.5 units/s (slow enough to matter a lot, since crossing objects takes multiple seconds now)

slow.mp4

This repository doesn't contain build scripts. Dependencies are:

  • CUDA
  • SDL2
  • spdlog

Notes

The code is ugly, contains copy pasta of itself, etc. I don't care in this case, since I just wanted to get a quick prototype. Up/Down buttons change the speed of light.

The approach taken here is to iteratively trace rays which are limited in length (say, 1cm at a time), while also moving objects in space(and time). Shadows are only casted on the ground plane, also accounting for the finite speed of light. This is quite inefficient, but it's easy to code. The alternative approach would be to derive a solution of the ray-OBB & ray-sphere intersection equations accounting for the fact that the ray speed is finite and that objects move in time. The key challenge here is that the equation becomes quite ugly and depends on a particular function of time describing the object movement. E.g. if a sphere is moving according to sin function, the equation to solve will no longer be a quadratic one. Instead, it's going to look something like a*t^2 + b*t + c + d * sin^2(t) + e * sin(t), which is a PITA to solve. Another idea would be to define a function describing an object movement as a piece-wise function, which is compatible with animation. In this case the solution will require iterating over all intervals of the function and solving a more or less classical quadratic equation (in the case of ray-sphere intersection) on each such interval. On RTX 3070 Mobility though the iterative approach works relatively quickly, enough to understand how things look like.

raytracing-slow-sol's People

Contributors

dmitryduka avatar

Watchers

James Cloos 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.