r/GraphicsProgramming • • May 04 '26

Physically Based Rendering With General Relativity

Thumbnail
gallery
350 Upvotes

These are some pictures from a general relativistic ray tracer I'm working on (or ray marcher? I'm not sure the right name for what I've made).

Design/Architecture:

I wrote it in Julia, because I'm weird like that.

I initialize the rays with a pinhole camera model at a position and velocity, with a camera direction relative to the velocity. This is all 4D (time + xyz), and uses a bunch of matrices to convert the rays from the camera frame to the coordinates of the simulation.

Once I have my rays, I integrate them backwards in time using an adaptive step size RK45 scheme (Dormand-Prince). It can automatically determine the step size using error estimation, but I find it helpful to give it a manually coded maximum step size function to help it handle sharp edges, strong spacetime curvature, and coordinate singularities (e.g. the poles of a spherical coordinate system). I also have to switch to Euler's method to cross poles. Integration stops when a ray hits a simulation boundary (e.g. skybox, event horizon) or high optical depth.

Currently there are two programs used to integrate the rays: "LttM" for the CPU and "5P" for Nvidia GPUs (uses CUDA). I will probably add another to try to make it run on other GPUs eventually. The GPU kernel seems fairly efficient: ~30s integration for a 2000p image, which seems to be the same order of magnitude as the RAPTOR ray tracer that does this in microwaves.

Light emission and absorption are calculated at each sample to solve a relativistic form of the radiative transfer equation. I calculate the 'GR dot product' of the ray and fluid velocity to get the redshift. I ignore scattering for now because I think it'd be hard to implement and I think it probably shouldn't matter too much for a lot of the things I want to render.

The post-processing converts the spectrum to colors, with the option to use a skybox and (some) anti-aliasing.

The code is structured such that it's relatively easy to add different spacetime shapes and light emitting structures. This comes at the cost of not always having the most efficient or accurate integration.

Image descriptions:

  1. A wormhole geometrically identical to the one in Interstellar. Skybox on the near side is the Milky Way, far side is a nebula skybox from opengameart.org . I had to use Gaussian anti-aliasing/'ray-bundles' like those used in Interstellar to get it to look right.

  2. A black hole spinning at 99.8% of the maximum possible speed (that's why the shadow is asymmetrical). I have an extremely crude model of an accretion disk orbiting it: constant density, constant temperature (= to surface of sun), black-body spectrum, thin-disk geometry.

  3. The same black hole and disc from before, but with the camera closer to the black hole and pointing prograde. And the disk is 10 times denser, because I thought it looked cool.

  4. A view from inside a cylinder of synchrotron emitting plasma. This is a test leading towards a better accretion model based on modern simulations, with a thick disk and jets. The doughnut shape is mostly from the preference of electrons in the plasma to move parallel to the magnetic field combined with the fact that electrons actually moving exactly parallel don't emit any light.

Code: https://github.com/nullgeodesic/R.T.W.C.A.. (Warning: not yet well documented or user friendly, so I wouldn't try to run it. That's something I'm going to work on.)

Some stuff I've used:

  • The two papers Kip Thorne wrote for Interstellar were pretty helpful.

  • RAPTOR (Bronzwaer et. al. 2017, 2020) was the main inspiration for the integration algorithm.

  • Gray (Chan et. al. 2013) for singularity handling

  • Catalogue of Spacetimes by Thomas Müller and Frank Grave

  • Gravity by James B. Hartle

  • General Relativity, Black Holes, and Cosmology by Andrew J. S. Hamilton

  • Wyman et. al. 2013 for color-matching.

Inspiration

  • Interstellar

  • Singularity + Kcalbeloh Mods for Kerbal Space Program.

Edit: Fixed Github link.


r/GraphicsProgramming • • Feb 08 '25

I built a Vulkan Renderer for Procedural Image Generation

Thumbnail
gallery
349 Upvotes

r/GraphicsProgramming • • Nov 05 '19

Really fun effect. I kinda want to try implementing it myself.

348 Upvotes

r/GraphicsProgramming • • 9d ago

breakdown of a real-time stream, shallow water equations on the GPU, advected ripples and caustics from the flow

346 Upvotes

my own project, one 512 x 512 shallow water grid runs in compute shaders with 8 substeps per frame, and every layer in the video is read from it, depth, velocity, foam where the flow converges, ripple coordinates advected by the velocity and a caustics pass projected on the bed

solver is Chentanez and Müller 2010 on a staggered grid, three.js WebGPU with TSL

live (WebGPU) : https://stream.mulualem.com

ai disclosure : I built this with claude code, it wrote most of the code under my direction and helped draft this post too


r/GraphicsProgramming • • Jun 07 '26

After 4 years of struggle I finally figured out particles

346 Upvotes

This is what peak performance looks like.

Did this really take me 4 years? Maybe yes. Maybe no. Maybe did a little bit of procrastination.

Turns out that if you just store different data types for each particle (like uhhh numbers and uhhh vectors) and then store mathematical operations for each of them, you can make any particle effect that you can think of. No literally, you just need numbers and operations for them. I have no idea why I didn't think of that sooner.


r/GraphicsProgramming • • Jul 25 '25

Platform for learning Shaders

Post image
345 Upvotes

Hi everyone!

I want to share a project I’ve been building and refining for over two years - Shader-Learning.com - a platform built to help you learn and practice GPU programming. It offers interactive tasks alongside the theory you’ll need, all in one place.

Shader-Learning.com combines theory and tasks in one place, offering over 250 interactive challenges that guide you through key shader concepts step-by-step.

On Shader Learning, you will explore:

  • The role of fragment shaders in the graphics pipeline and a large collection of built-in GLSL functions.

  • Core math and geometry behind shaders, from vectors and matrices to shape intersections and coordinate systems.

  • Techniques for manipulating 2D images using fragment shader capabilities

  • How to implement lighting and shadows to enhance your scenes

  • Real-time grass and water rendering techniques

  • Using noise functions and texture mapping to add rich details and variety to your visuals

  • Advanced techniques such as billboards, soft particles, MRT, deferred rendering, HDR, fog, and more

Here is an example of tasks on the platform

Additional features

  1. Result Difference feature introduces a third canvas that displays the difference between the expected result and the user's output. It helps users easily spot mistakes and make improvements:

2. Evaluate simple GLSL expressions. This makes it easier to debug and understand how GLSL built-in functions behave:

If you encounter any questions or difficulties during the course, the platform creators are ready to help. You can reach out for support and ask any questions in the platform’s discord channel.

I hope you find the platform useful. I’d be glad to see new faces join us!


r/GraphicsProgramming • • Apr 17 '25

Source Code My Shadertoy Pathtracing scenes

Thumbnail
gallery
342 Upvotes

Shadertoy playlist link - to what on screenshots.

P.S. I can not post first - purple screenshot on reddit - because this reason.


r/GraphicsProgramming • • Jun 30 '26

1 year of game engine development

341 Upvotes

r/GraphicsProgramming • • Sep 18 '26 Bravo

Video I made a lightning strike VFX with Three.js (running in browser)

340 Upvotes

I wrote up the VFX breakdown here, in case you're interested: https://threevfx.com/labs/lightning-strike/


r/GraphicsProgramming • • Nov 12 '24

Video Recreating PS1 graphics in the browser to de-make games

339 Upvotes

r/GraphicsProgramming • • Oct 17 '25

Black and white manga-style rendering

Post image
338 Upvotes

Would a 3D game rendered in this style be playable and enjoyable without causing and mental or visual strain? If so is it achievale and do you have any idea how I achieve it? Thanks!


r/GraphicsProgramming • • Jan 01 '25

Average stochastic technique fan

Post image
338 Upvotes

r/GraphicsProgramming • • Jun 12 '26

Real-time hybrid ray-traced ocean in C++, FFT waves, RT shadows/reflections/GI, no shadow maps (open source)

Post image
336 Upvotes

This is the updated ocean demo from threepp, an open-source C++ library I maintain. A scene-graph API in the spirit of three.js, but with its own Vulkan backend that uses hardware ray tracing (plus OpenGL and WebGPU backends sharing the same scene API).

What's in the shot:

  • FFT ocean - multi-cascade spectrum synthesis on the GPU, with an adaptive mesh that concentrates vertex density around the vessel, and world-anchored foam so it doesn't move with the geometry

  • Hybrid pipeline - raster G-buffer for primary visibility; everything lighting-related is hardware ray queries against the scene BVH: shadows, reflections, AO/GI, emissive occlusion. No shadow maps, no SSR, no light probes. (A full path-tracing mode exists as ground-truth reference.)

  • Ray-traced water - real reflections of the hull in the waves, Beer–Lambert absorption in the water body

At 1080p this scene runs at 40 FPS on laptop RTX4060 and 110 FPS on desktop RTX4070.

Disclosure: AI has been involved with creating these results.

Video: https://www.youtube.com/watch?v=Uxn-DVcFhvI

Code: https://github.com/markaren/threepp. Demo is examples/vulkan/vulkan_ocean


r/GraphicsProgramming • • Oct 22 '24

WebGPU Renderer Devlog 3: Frustum & Occlusion Culling on Compute Shaders

336 Upvotes

Implemented frustum and occlusion culling for my WebGPU renderer. 4000 tree instances. Realtime soft shadows.


r/GraphicsProgramming • • Sep 28 '26

may I join the triangle group?

Thumbnail
gallery
335 Upvotes

I wanted to give graphics programming a try and boooy am I happy seeing my own triangle on the screen! :)

I used glad (OpenGL) and RGFW (GLFW alternative; I like single header libraries)


r/GraphicsProgramming • • Jul 02 '25

After all this time, I've finally entered the realm of modern rendering!

334 Upvotes

Proud to say I had a really productive week 🌟🌟🌟
Ported my GLTF rendering code from SDL3 GPU to Vulkan and Metal, implemented tiled light culling, and then added raytraced hard shadows

The repo: https://github.com/painfulexistence/project-vapor

-
-
Fun fact: I'm using Metal-cpp for the Metal backend.

There aren’t many open-source rendering projects using Metal (compared to Vulkan and DX12), and it’s even rarer to find ones that use Metal-cpp, especially for hardware ray tracing features in Metal 3 and later--most examples out there are in Objective-C. So I hope this project will be helpful, or at least interesting, to someone passing by. Happy coding everyone!👩‍💻🧑‍💻


r/GraphicsProgramming • • Feb 02 '25

I made a large collection of Interactive(WebAssembly) Creative Coding Examples/Games/Algorithms/Visualizers written purely in C99 + OpenGL/WebGL (link in comments)

334 Upvotes

r/GraphicsProgramming • • Jul 31 '24

Video Realistic black hole simulation using OpenGL

333 Upvotes

r/GraphicsProgramming • • Sep 28 '24 Take My Silver

Video Finaaallyy got my ReSTIR DI implementation in a decent state

332 Upvotes

r/GraphicsProgramming • • Jun 16 '26

Rendering 4D space in an intuitively understandable way

331 Upvotes

(By 4D space, I mean four-dimensional Euclidean space R4. Not spacetime or space of higher dimension in any physical sense.)

Let us first think about how we understand 3D space. Through vision, our retinas receive 2D information; after being processed by the brain, that information becomes our understanding of 3D space.

I imagine that if humans living in 4D space had vision, what their eyes received would be 3D information. In other words, if we could somehow see a "3D photograph," we would be able to simulate, to some extent, the vision of a 4D being. But this is very difficult. Imagine a 3D cuboid divided into billions of voxels, each carrying information about color and brightness. This comes close to how we might imagine vision in 4D, but to us it would be almost impossible to understand, because we can only see the outermost layer of voxels. Even with translucent voxels, it would still be difficult for our 3D vision to capture the information inside.

However, our perception of 3D space does not have to be based on pixel images. A geometric outline drawn with lines is often enough for us to reconstruct a great deal of spatial information. (Left in the GIF). Applying the same idea to 4D space, we can obtain a 3D line rendering of a 4D space (right). Since lines rarely occlude one another, we can capture the information in this 3D image with much greater precision, and in this way simulate the vision of a four-dimensional being.

If we add some basic "physics" in this 4D space and make it interactable like a game, as shown in the GIF, humans may gradually adapt to this kind of 3D image, find patterns within it, and begin to interpret the geometry of the 4D space behind it. With enough practice, this may even become part of your spatial intuition.

Based on this idea, I designed the game 4D Intuition. It now has a free demo on Steam. You are welcome to try it out and I would be glad to hear your thoughts on my attempt.


r/GraphicsProgramming • • Sep 01 '26

Backrooms pool

330 Upvotes

Made a small Backrooms pool demo in Natiny. I’m not sure I fully captured the atmosphere I was going for, but overall I’m pretty happy with how it turned out.

The caustics are probably a bit too bright, but I think they make the scene more interesting.

What do you think?


r/GraphicsProgramming • • Aug 14 '22

Finally!!!!! Red Triangle%

Post image
330 Upvotes

r/GraphicsProgramming • • Feb 12 '25

Source Code Built a real-time rust simulation with mesh deformation in S&box - C#, compute shaders

329 Upvotes

r/GraphicsProgramming • • Jun 23 '26

WIP Real-time volumetric clouds in OpenGL

Thumbnail
gallery
323 Upvotes

I've been working on this for the past 4 months. I don't have much experience in computer graphics, so this is my first full-fledged project.

Core idea lies in ray marching through clouds and density accumulation, along with light scattering. Weather map generated as warped perlin noise. Also there are 2d high altitude clouds, which don't cost anything, but make the sky look less empty.

Plan to implement some optimization (temporial reprojection) and procedural weather system.

Github repo: https://github.com/kotivas/skygl