I made a better Ray-Tracing engine



Two years ago, I showed you how I created a simple ray-tracer from scratch. This is my attempt at improving my first version and showing you how I did it!

► My new Discord server: https://discord.gg/FJqqvqHaZS

► My first Ray-tracing attempt: https://youtu.be/lKIytgt3KXM

► Source code: https://github.com/carl-vbn/opengl-raytracing

► Valuable resources:
– OpenGL tutorials: https://learnopengl.com/
– Ray-tracing blog post: http://three-eyed-games.com/2018/05/03/gpu-ray-tracing-in-unity-part-1/
– ImGUI Library: https://github.com/ocornut/imgui
– TheCherno’s Bloom video: https://youtu.be/tI70-HIc5ro

🎵 Music from Epidemic Sound, register with my link to support the channel and get a discount:
https://www.epidemicsound.com/referral/tgmxaf

Detailed description:
In this video, I explain how I created a ray tracing engine in C++ using OpenGL. Raytracing is a rendering algorithm that can be used to generate photorealistic images with nice shadows and reflections. The technology has recently been made accessible to many when NVIDIA announced their RTX graphics cards. I successfully implemented lighting, soft shadows, ray-traced global illumination, progressive rendering, reflections and more.

Chapters:
0:00 – Intro
1:23 – GPU acceleration
2:06 – Ray-tracing recap
3:10 – Direct illumination
4:37 – First result
4:42 – Soft shadows
5:20 – New result
5:39 – User interface
6:27 – Indirect illumination
8:18 – Progressive rendering
9:42 – Reflections
10:24 – Skybox
10:51 – Recursion problem
13:50 – Anti-aliasing
14:33 – Bloom
15:24 – Final results & conclusion

#Raytracing
#OpenGL

source

46 thoughts on “I made a better Ray-Tracing engine”

  1. Sorry for the short break 🙂
    I hope this video was worth the wait!
    Also, thank you so much for 10k subscribers!!

    EDIT: At around 1:17, I called OpenGL a graphics "library" which isn't the right word. OpenGL is an API, not a library!

    Reply
  2. Super stuff – always wanted to create a raytracer myself, did a bit of work but I think that the hardest bit to do quickly, is sorting the objects and determining the nearest collision.

    Reply
  3. I wonder why you didn't just try fork your past Java-based ray tracer by implementing global illumination using a graphics API this time around. Modifying your previous ray tracer not only would've saved a lot of time, but it would've also been a good way to show that you can achieve results that are on par with C# and C++ by using Java with a graphics API. Why do I get the impression that everyone has a stigma that Java is somehow worse than C++? Even if I'm not a programmer (I'm a cartoonist), I still get frustrated by this mentality because c'mon! Look at those Minecraft Java Edition shaders that use experimental, real-time implementations of path tracing with global illumination and they look spectacular! These things are already enough proof that Java is capable of achieving beautiful computer graphics that are on par with Blender's Cycles, Autodesk's Arnold, and LuxCoreRender.

    Reply
  4. Those read, listen to / bugged / eavesdrop / overheared / tapped, watched, spied, copied and steal many of my ideas (=inventions) initiated by me:

    + open, transparent 360° sunlight Buildings, construction methods, architectures, designs, concepts;

    + Step-floor / -storey / -level / -tier pyramid (e.g., as a residential building);

    + 360° stepped floors / storey / level / tier buildings (constructions, architectures, construction methods, designs, concepts, 2D, 3D, models);

    + 3D 360° environment (surround), volume, space (room) audio / sound;

    + 360° environment (surround), volume, room screens (displays), monitors, TVs;

    + Screens (displays), monitors, TVs without backlighting;

    + many things with magnets like Micro-OLED;

    + 360° screens, monitors, TVs, panels, glass;

    + curved screens, monitors, TVs, panels, glass;

    + 360° reflections and light digital: "ENB", "Ray-Tracing" / "RTX", “Lumen illumination” and whatever renaming!

    + Short Throw Projectors;

    + dark backgrounds / themes / skins for windows, browser windows, internet sites, programs / apps, etc.;

    + fanless, passive cooling; +thermal pads; + Water cooling (unwanted, because it conducts electricity) and liquid cooling (wanted) for the computer and personal computer / PC application area!

    – I am not the inventor of refrigeration by nitrogen, instant- / blast-freeze / -freezing;

    + 360° open, transparent PC cases;

    + 360° Sphere, Ball as a Wheel (2D, 3D) “Omniwheel” / “Omni-Wheel”;

    + From a standing position / standing a 360° turn / rotation in any direction on all objects, including logically and of course vehicles, transporters, robots of all kinds;

    + Flying objects, planes that take off and land vertically, for example by hot air, example fighter jet;

    + skyscraper up to the weightlessness of space ("space scraper") – "mega construction";

    + LED lights (at least its implementation and intended use outside of tv and pc-monitor); RGB LED “Nanoleaf”, etc.

    + and much more!

    + I'm not the inventor of VR, but of "AR", AR glass, AR glasses;

    It was only later that I realized that they derived a lot from my ideas (=inventions), a lot came about that has to do with color and light, through me as an initiator, booster / catalyst, e.g., through my idea, invention of the Screens without a backlight and without a built-in / integrated backlight! It is no coincidence that only afterwards, after I initiated this, they built, built and are building those inventions thanks to my impetus! They sell my ideas (inventions) as theirs! They are not the inventors, but the first technical implementers of my ideas (=inventions)! And those are not the inventors, but the thieves of my ideas (=inventions) initiated by me, because those act as if I wasn't the first hand and the first domino, and they take unjustly, undeservedly a lot of money, stolen money (blood money), recognitions, awards, certificates, fame and history, they boast of my laurels / merits!

    Before me they all were stucked at LCD, Plasma TV and less lights!

    I have made a deep impact in evolution!

    Those manipulate, sabotage, falsify, distort images, paintings, digitized and real, animations, videos, films, also composed of many images, even the publication dates of mine, others and their posts, images, videos, etc.!

    You have to understand, those can distort everything that can be heard and seen in real life and digitally!

    They block and delete my pictures, videos, posts, comments, comments-answers and answers!

    They are poisoning and murdering the world with fake diseases, treatments, "vaccinations"/ "vaccines" and injections by syringe!

    Now they also make it out as if they haven't been ripping off, cheating, enslaving, murdering other countries with the money currency, money exchange by even -99% for more than two centuries! And as if I'm not the first to disclose that and more! As if I didn't disclose and initiate > 1.00 Ruble (₽) = 1.00 asian Yen (¥) = 1.00 Euro (€) = 1.00 Dollar ($) = any (X) any country < years ago!

    Each and every non-civilian you hear and see on TV is involved! You can hear and see their > blue <, grinning speakers / talkers every day on TV!

    Those are white, > blue <, blond / blond-haired, bald, red-haired, grey-eyed, blue-eyed, Christian, Jewish, fascists, Nazi-pigs, child murderers, mass murderers, people murderers (genocides)!

    To all dark-haired, black-haired people, defend yourself against the white, > blue <, blond / blond-haired, bald-headed, red-haired, Christians, Jews, because those are the real terrorists, mass murderers, people's mass murderers (genocides), child murderers, fascists, Nazi-pigs!

    "Can you back up these claims?"

    – "They block and delete my pictures, videos, posts, comments, comments-answers and answers!" certain ones a lot very often!

    They block my profile links! Go to my Youtube channel / profile, there you should see a link to my main profile for free, the language of the free site can be set to english on the site in the settings. On my free main site you can read my public posts for free, some with pictures, links and dates.

    Reply
  5. Interesting preoccupation. However retracing the footsteps of others without original insight or contribution is an excellent way to stuck yourself in a similar rut of obstacles caused by their thinking. For your next project — build an optical gpu. This is your logical next step. Optical computations are instantaneous and easy as to perform as you will discover. I will provide an insight: for years I struggled to find a way of caching optical computations. The answer: Varistors. Variable resistors. That is the key. Once the optical computation is performed you can use a varistor to calibrate an equivalent opposite wavelength in current which whitens the light. In optics, resistor and register are phonemes.

    Reply
  6. I made a very similar raytracing engine with OpenGL and C++ a few years ago. The speed of software raytracing is very limited though. I'm currently rewriting it using Vulkan and Rust. I can use Nvidia's hardware accelerated raytracing extensions to speed things up drastically.

    Reply
  7. You can do an optimisation by rendering into sparse voxel space instead of screen space. All of those dot products you calculated from the lights are still the same within voxel space, you can just cull the non visble voxels and recalculate whatever lights are in screen space if they move / change intensity. It just becomes a data management task which is much faster. Lumen works like this AFAIK.

    Reply
  8. I have a question. When I rotate an image on a 2-dimension plane, and I get the point to show at its new location as being 2.43, 3.76; can the color to copy be calculated as ((0.57 + 0.24) * color at 2,3 + (0.57 + 0.76) * color at 2,4 + (0.43 + 0.24) * color at 3,3 + (0.43 + 0.76) * color at 3,4)/4? With a coordinate being 2.43, I figured that since I was 43 percent of the way from there to 2 and 57 percent of the way from there to 3 that I need to put a 43 percent weight towards 3 and a 57 percent weight toward 2. Is that a good idea?

    Reply
  9. I recommend adding something called "fresnel" to the engine since the ground plane is looking a bit flat near the horizon. The steeper a ray comes in the more reflective the object gets. This effect gets weaker the rougher the object is. It is also a mandatory feature if you want photorealism since our brains know something is off.

    I also recommend adding caustics because it also affects realism. When computing indirect lighting, you should make rays bounce off reflective surfaces and if it reaches a light or a bright surface, you light the original surface accordingly.

    Reply
  10. If you want even more realistic material behaviour, try looking into GGX scattering, it's a microfacet distribution, meaning it models the materials as a ton of microscopic mirrors oriented depending on smoothness etc. Great video btw!

    Reply
  11. If you ever do this again, You should use Vulkan. It’s way more efficient than OpenGL from what I hear. I use SDL mostly so I wouldn’t know. But still, if you are to do this again, try Vulkan.

    Reply

Leave a Comment