erichlof/THREE.js-PathTracing-Renderer

How to use this pathtracer in Freeciv 3D version?

andreasrosdal opened this issue · 2 comments

Hello!
I would like to use this THREE.js-PathTracing-Renderer to render the 3D version of Freeciv:

https://www.fciv.net/
https://github.com/fciv-net/fciv-net

How should I go about upgrading the renderer to use this pathtracer?

Hello @andreasrosdal,

Thank you for your inquiry. Your Freeciv game looks really cool! It's impressive how many components it has going on at the same time!

Unfortunately at this point in time, my path tracing engine is not up to the task of handling multiple game objects and multiple materials. I have made 2 very simple games with it - a 3d pong game and a anti-gravity billiards game. But these were more proof-of-concept in nature, to show that we could have real-time pathtracing in the browser. These simple games work only because I carefully cherry-picked the genre - Pong only needing 1 sphere and 2 rectangular boxes, and the anti-gravity billiards needing 16 objects, but they are all simple small spheres of the same size (ray tracers handle spheres and boxes rather efficiently, so I leveraged this feature).

I noticed while trying your game that you have real 3d models and environments (terrain). Even if you limited your on-screen objects to a handful (which would stifle your level design I'm sure), each and every model would need its own acceleration structure, namely a BVH. Now I have tested single triangle meshes and my system has been able to efficiently walk the BVH tree for a single model in the scene, but I haven't fully handled multiple models and animation support yet (which most 3d game characters need), as this would require rebuilding the entire trees each animation frame. Something like this has been done in the past for the Brigade 3 engine, but they were using C++ and multiple GPUs to achieve this monumental feat. NVIDIA is slowly creeping up to real-time path tracing for games, but all of their software is proprietary and the end user must have a powerful RTX card to make anything run on their systems.

In other words, if you just threw all of your game objects and terrain into a scene to be pathtraced, it would probably crash the browser, especially on mobile. If it did happen to run, it would probably crawl at <5 fps. An active area of my research is trying to get cell phones and tablets to be able to path trace multiple triangle models, but I'm just not quite there yet.

I have made some baby steps in tracing multiple models, but it's not optimized enough. You can see some of the progress on my Sentinel clone project - 'The Sentinel: 2nd Look'. It has very simple triangle models (<30 triangles per model) and no animation support, just rigid rotation and translation of a stiff model in 1 pose. But there is a ton of work to do before a full game with all of its objects and their various materials could be handled at interactive framerates, let alone 30-60 fps.

I'm sorry to disappoint you with all these reasons why you can't just 'make it run' with my engine. But having said that, honestly I really like your game's current graphics and visual style! I tried it out on desktop and my phone, and it runs very smoothly on both, and the graphics are stylistic and clear. I'm not so sure that path tracing would add much to what you've already got working and looking so well.

I hope someday that we will have true path traced full games on all devices in the browser, but either I or someone else will have to make several more breakthroughs - or, we'll have to wait until the physical hardware gets way faster, like RTX cell phone chips, ha!

Thanks again for the questions and best of luck with your project!
-Erich

Thank you for the detailed reply about your path tracing engine. An ideal raytracer renderer for Three.js games could be implemented as a drop-in replacement for WebGLRenderer, called eg. PathTracingRenderer or RayTracerRenderer.

I hope someday that we will have true path traced full games on all devices in the browser, but either I or someone else will have to make several more breakthroughs - or, we'll have to wait until the physical hardware gets way faster, like RTX cell phone chips, ha!

I would advice to make a prototype raytracer renderer for Three.js as a replacement for WebGLRenderer, as simple and crude as possible, and then optimizing performance of this can be done in the future with Moore's law.