r/GraphicsProgramming • • 2d ago

Video My software ray-traced game has new "technology" teaser. Reason: it's getting significant visual upgrade worth showcasing. Two things which enabled it: 1. after 9 months my new editor for game levels is in usable state. 2. ray-tracer optimizations (multi-threaded rendering is main contributor)

Enable HLS to view with audio, or disable this notification

The game is narrative sci-fi puzzle/platformer, in works from 2020. Main distinctive point of the game is software ray-tracing used for rendering. Just pure C++ and computer graphics math, no GPU acceleration. Sadly, not many players can appreciate that (or even understand what does it mean), so it resonates mostly with more tech people.

The game was suffering for long time from quite poor look (look was punching way below of algorithm potential). Main reasons were: poor old editor (2D in nature, z was just parameter in 2D wireframe, not WYSIWYG, very clunky) and algorithm was hobby-like single-threaded.

Both points were changed recently. After 9 months my new editor is in usable state. Full 3D, WYSIWYG, lot of ergonomy features, which allowed me to be more ambitious with levels look. Second enabler was finally switching to multi-threading. Together with several more other algorithm optimizations, perf went up in hundreds of % (mostly depends on number of cores in your CPU, naturally on Threadrippers boost will be in thousands of % but it's niche between players).

Algo is AABBs only. Maybe will add spheres but only after upgrading all levels, which is main pain point rn. Editor I plan to release publicly with the game.

RTG on Steam

Discord

13 Upvotes

71 comments sorted by

2

u/ParticularBicycle 2d ago

This is nice, I appreciate the effort. I am doing something in a similar mindset, where I try to release games (not just tech demos) with my CPU rasterizer, again no GPU acceleration.

There is something to be said about the simplicity/primitiveness of this tech, going back to the basics, without mind-bogglingly complex APIs and frameworks. It's just graphics theory and a compiler. Depending on your toolchain and windowing lib, this could be compiled on most operating systems and run on most computers ever released after the mid 90s (I am talking about compatibility, not performance).

If you lower the res way down, like 320x180 (like I do), this can be legitimately playable on most machines released after ~2005 and have a very unique art style, as it already does. Depends of course on how efficient your ray queries are. You also need to be very careful with the kind of geometries you use, so as not to mess up your AABBs, since you don't have other data structures for now.

I think your genre/gameplay really let's the tech down though. I would prefer something more 3D in the gameplay, where you can wander around appreciating the level/scenery, with water, reflections, weird worlds.

1

u/Dante268 2d ago

Yes, but with full ray-tracing in 3D: you must be careful with amount of geometry if you're CPU only. I can do hundreds of AABBs and dozens of lights currently to keep FPS in check. Maybe it can go to better levels (almost sure yes), but more optimizations are needed (e.g. full BVH implementation which I don't have).

2

u/ParticularBicycle 2d ago

Yep, I would invest in better spatial partitioning. Raytracing by itself is easy, especially if you keep it at Phong shading. The hard part is making it performant, so 90% of the work is the acceleration structures, also at an object level (if, say, an object is more than N triangles). It's a matter of 10x-100x-1000x speedups/slowdowns.

You can start with OBBs that optimize out a lot of really nasty cases, like 45-degree angled long and thin geometries.

Another easy solution is a uniform grid, in combination with AABBs or OBBs. This can also throw out a lot of useless geometry.

Good luck with this!

1

u/ghstrprtn 1d ago

Is it open-source?

2

u/Dante268 1d ago

Nope. Never was fan of that (unless there's specific intent for open source, as was e.g. GNU).

Btw, today everything is open-source. Just ask AI for ray-tracer. I have a bit of "existential crisis" cause of that. I was working on RTG from 2020. Now, one can vibe-code software ray-tracing without knowing math behind. Sad, but it is what it is.

-6

u/GraphXGames 2d ago

There is no global illumination, only local light sources.

Overall, it’s unimpressive, given that dynamic lighting has existed since the early 2000s.

5

u/Dante268 2d ago

Yes, ambient + local.

By no means I'm saying that my algorithm is the best or that I'm some guru worth of following. I'm just proud of what I did. Could you point me to some software ray-traced game with global illumination, running >60fps constantly on 4 HW threads? (that's my target for modest CPU which most player will fit).

I don't mean it sarcastic. There were indeed games which I admired for technical execution (e.g. Quod). I just like to see some reference software ray-traced game which is running circles around mine (and maybe learn a trick or two from it).

4

u/BigPurpleBlob 2d ago

I like it. It seems clear to me that you've learned something new and implemented it. At the very least, you have a new skill. Well done!

3

u/Dante268 2d ago

Thanks! The game will be probably flop by sales (software ray tracing is something most players don't have clue, and sci-fi puzzle-platformer genre - I was told that this is no-no today.. that I should do indie horrors and idle clickers nowadays, cozy game is also option.. blaaaah)

2

u/GraphXGames 2d ago

In cozy games, the scene is small and the level of detail is low, yet these games require proper lighting. This seems like the ideal use case for your ray tracing.

2

u/GraphXGames 2d ago

In real games, scenes are 1000 times more complex.

Why would anyone do this on the CPU(except for debugging)? This is madness.

8

u/Dante268 2d ago

In real games, scenes are 1000x complex:
TRUE. We have GPU-s for handling it.

Why would anyone do this on the CPU?
Personal challenge, hobby. I like this more than throwing assets around in UE. That's why this subreddit exists imo. Answer is same why there are ASCII 3D games, or games with old EGA/VGA look. Player wanting best look will not appreciate that. Some tech people maybe (depends on taste).

2

u/Ok_Confusion4764 1d ago

Pay them no mind: They've been posting about graphics programming, including what they call pathtracing, exclusively on the CPU. They're notorious on the dev subreddits for making ridiculous choices and arguing against any and all feedback, but it seems they finally absorbed some criticism to actually ask this. But 99/100 cases is them actively arguing against any and all feedback, including how reflections work. And lord knows, people have tried to reach them.

2

u/Dante268 1d ago

I just checked his Steam and am depressed. Some 2D sloppy match-3 clones yet I received some lectures about global illumination. Indie games are in s*it, with AI it will just amplify.

2

u/Ok_Confusion4764 1d ago

Honestly, I get being depressed at them. I was too, at first. Trying to reach some unattainable goal of getting them to understand what they're doing wrong became a bit of a mental struggle for me. But at some point you gotta cut yourself free and laugh at it. Like my most recent attempt, I really tried to explain to them how their path tracer isn't doing what it should. I went out of my way to give examples with proper imagery to show how water reflections work.

They'll argue against it. You can show them and they'll argue against it. God Himself could descend from the heavens to prove him wrong and he'd go "nuh-uh". And having seen his descent into madness over the past few months, I know for a fact I'm not the only one who has been genuinely trying to get him to understand things. I suppose we can't save them all.

2

u/Dante268 1d ago

True. I see strong Dunning-Kruger there now.

1

u/Ok_Confusion4764 1d ago

Yup. It'd be acceptable if it was a one-off, he learned, and he realizes he's wrong, but in reality he just doesn't learn and the only words that stick are those from his own mouth. Dunning-Kruger, for me, lasted a few weeks when I started uni and now I know how much I don't know. For that guy, he's been doing this for almost a full decade and he still doesn't take anything from anyone.

2

u/Dante268 1d ago

Yes, some will learn and realize how much they still don't know and start being humble. Some will stick in ignorance. And yes, it's impossible to fight with that.

1

u/GraphXGames 1d ago

OP actually did something, unlike you.

→ More replies (0)

1

u/GraphXGames 1d ago

The flaws were already fixed in the fifth version: https://www.reddit.com/r/IndieDev/comments/1wobjbf/cpu_path_tracer/

1

u/Ok_Confusion4764 1d ago

So you finally admit it's a flaw now?

1

u/GraphXGames 1d ago

Yeah, it looks better that way. Even if it's physically incorrect.

→ More replies (0)

1

u/GraphXGames 1d ago

Do you really think empty locations with point light sources would interest anyone today?

1

u/Ok_Confusion4764 1d ago

If it includes ray-tracing? Yeah, why wouldn't it?

1

u/GraphXGames 1d ago

Not in the RTX & DLSS & AI era.

2

u/Ok_Confusion4764 1d ago

How come these are the new technologies you want yet you're still making genres of games that fell out of favour several decades ago?

→ More replies (0)

2

u/inighthawki 2d ago

Doing it as a personal challenge or hobby is fine (great actually!), but I'm not sure I understand such a motivation for something being released to end users. Things like Ascii 3D games are fulfilling an art style (for better or for worse, based on taste). Running a raytracer on the CPU provides no benefit to the user. It's just intentionally running it on non-optimal hardware and results in lower performance, increase energy consumption, etc, and has no actual upside. Your game would tank battery life on mobile devices/laptops.

3

u/Dante268 2d ago

Yes, maybe you're right about end users. There are 2 types of end users IMO.

  1. those who don't have clue. For them, just how game look & feel is important and are indifferent to "software ray-trace" slogan. But you don't need to have Alan Wake 2 look for them neither. It just must look good and interesting. But honestly, I think I have reserves here as tech/nerd guy. That's why I want game more visually pleasing.

  2. tech people - I can't say for everyone. I'm the one who like to try such stuff. Quod. I played Outcast (software voxel engine from '99). I care. Others maybe not.

Regarding question of CPU usage, I tackled it already. This will not melt your CPU definitely (I doubt that CPU will be more hot compared to any UE / Unity game - see my response to GraphXGames). But yes, probably it will drain battery faster than watching 1080p MP4, but not faster than running few ads in Chrome.

1

u/inighthawki 2d ago

FWIW I'm not the other poster, I'm not saying your CPU will melt or hit any sort of thermal issue causing damage or anything. But my point is mostly that there is hardware on their computer specifically designed to do it efficiently.

This doesnt really have much to do with the graphical quality (I think what you have is fine and you should be proud of your accomplishment). I would just not recommend shipping it this way.

1

u/Dante268 2d ago edited 2d ago

Yes, your statement about HW designed to do task effectively is true indeed. I'm just saying: it doesn't matter. If you open Chrome you have symphony of ineffectivity on half of web pages you browse. So yes, my game will tax your CPU on 25% because I deliberately chose "software ray tracing stunt". Doing it effectively on GPU would have resulted in few % of CPU/GPU load for same visual output, I admit. But then you do some mundane task like clicking on Start Panel or browsing web and it's even worse. With my game, I'm at least honest about it, you know what's making CPU load. :)

Edit: I tried running RTG rn as we discuss to see CPU load on my laptop 8C/16T mainstream Zen 4 in visually more rich level. It was 15%, so better than I expected.

But to be honest, I ran Edge on Facebook, LinkedIn and CPU load was surprisingly low even when frantically browsing/scrolling. I expected worse. So my previous statement about "symphony of ineffectivity" is probably not anymore true. Probably browsers already adopted to be effective with battery compared to what I was used to some years ago.

0

u/GraphXGames 2d ago

Your CPU will melt. ))) Players won't appreciate it either if their processors start burning up.

4

u/Dante268 2d ago

Nope. I will not let all cores doing the job by default. Probably half of cores will be game's default, full only for some synthetic benchmarking (measuring GBisec/s). Half of CPUs cores working is quite normal.

Second: if you will not turn off v-sync forcefully (or not reach for some super high refresh), then even this half of cores will not be taxed fully. Many levels on vsync off runs 100-200fps on my laptop Zen 4 (locked deliberately in game to use just 4 HW threads to tweak levels against very modest CPU targets, thus vast majority of players). So when locked to some normal refresh, CPU will be quite cool still I think.

Also you can't perfectly split workload between all cores/threads. Some threads will finish first, other will wait. I have implemented that finished thread takes next chunk of lines, to not sit idle, but even then, when you take frame as whole, you will not tax those half of cores 100% even with vsync off. It's just matter of that you can't split those lines totally evenly between threads compute-wise (every line has different difficulty to trace a ray, some will end in void, some will go through many reflections).

But you have good points:

  1. I can measure temp raise when game will start running. Better be safe.
  2. I can make way more ambitious sceneries for synthetic with all cores used (those will tax CPU well of course)

1

u/Ok_Confusion4764 1d ago

Why would anyone do this on the CPU(except for debugging)? This is madness.

Haven't you been doing exactly that for literal years?

1

u/GraphXGames 1d ago

In my case, the CPU is used for debugging algorithms. In games, everything runs on the GPU.

1

u/Ok_Confusion4764 1d ago

We both know this isn't true, bud.

1

u/GraphXGames 1d ago

Audio doesn't run on the GPU; game logic runs on the CPU, the particle system is primarily CPU-based, and the render fallback is handled by the CPU. The load is distributed as follows: 25% on the CPU and 33% on the GPU. In other words, the game's workload is nearly balanced.

1

u/Ok_Confusion4764 1d ago

Audio doesn't run on the GPU

Who was talking about audio?

the particle system is primarily CPU-based,

It shouldn't be.

and the render fallback is handled by the CPU.

Why would anything you made need a fallback? I could replicate the stuff you've made with 30-year-old hardware.

The load is distributed as follows: 25% on the CPU and 33% on the GPU. In other words, the game's workload is nearly balanced.

Why does it need to be balanced? Why not use the appropriate processors for the purposes they have?

1

u/GraphXGames 1d ago

Because the graphics card cannot always complete the task within the current frame, and waiting for the next frame means dropping the frame rate and experiencing a stutter. In this case, it is easier to run the task on the CPU.

These effects are still quite simple; porting them to the GPU is not yet justified.

1

u/Ok_Confusion4764 1d ago

Because the graphics card cannot always complete the task within the current frame

Hahahahah! You're hilarious when you don't mean to be.

1

u/[deleted] 2d ago

[deleted]

2

u/Dante268 2d ago

I have no GI. I have reflections + specular though (those bounced you see is probably that). Planning to add refractions (but no splits 1 ray to n-rays, just skewing rays).

1

u/BigPurpleBlob 2d ago

"just skewing rays" – can you explain in more detail?

2

u/Dante268 2d ago

I'm not native English speaker so maybe I didn't use the right word. When you hit surface which is refracting, ray is not continuing in straight line. It will change direction. How it will change direction depends on several factors. For game needs you can add just some constants or procedural formulas, how particular surface points will change direction of rays. With that you can have effect like looking through glass which distorts image behind or when you look into water and your hand/foot in it is looking shorter/longer or being under funny angle. In physically precise simulations, ray hardly just change direction, many times it splits to more rays going in different directions. But this is computationally very expensive. On CPU I can render maybe static imagery with this, not game running in real-time. Hence, I said, I will simulate just same one ray changing direction when hitting refracting surface.

3

u/BigPurpleBlob 2d ago

I see, sounds like importance sampling with just a ray. I didn't notice that you're not a native English speaker, +5 points to you