CUDA, Unity, Unreal, Hair simulation - and learning new lessons alongside lessons learned
So you might as well know now, that I'm not a hardcore gamer (and lots of people who love graphics level programmer aren't), but I'm always fascinated by the rendering and performance, even the beauty, of graphics. I am a huge fan of anime and manga (and books in general), though that doesn't mean I love it all. I generally prefer ones that have some adventure and humor to them - even if the beauty of the art can vary with those. My favorites include Mob Psycho 100, Noragami, Kakuriyo and lots of others that are more well-known like Black Clover and Demon Slayer. In fact, my love of anime/manga and art/books was what drew me toward NPR (non-photorealistic rendering) and AR/VR, which drew me into shader coding.
This time I'm going to delve into a series of experiments, loosely described as a project. The goal is to understand how parallel programming (compute shaders) can help you improve code speed. In covering this topic, it's easier to look at a current project and investigate how it works, and how it could be improved. Most of the experiments/prototypes will likely fail the 'real-time' test, but like the best of coding, lessons will be learned and valuable insights gained.
So I'm going to start with hair simulation and shading, since the last year and a half of my life has been immersed in that, namely AMD's TressFX (version 4.1) which released in December 2019 as both a standalone engine integration (using AMD's Cauldron engine framework for samples) and as an engine integration into Unreal 4.22.3 (not a plugin, it was necessary to tap into the engine rendering pipeline directly).
In fact, one fun experiment will be looking at how we might take advantage of Unity engine's plugin system - more challenging when you need access to their rendering pipeline, but in my opinion, easier than other engines/frameworks, if you just want to write some custom shaders.
What's this got to do with augmented reality? After all, that is why I started this blog. Well, it isn't going to care too much about OpenCV or ARCore/ARKit usage at this point - that is true. But understanding how to optimize code using profilers, how to take advantage of parallel programming, how to wade through some of the issues (like engine integration and overhead) in order to speed up your code - all that helps when you try to go beyond 'make it run' and now 'make it run fast'.
And while I want to do many little experiments, especially as programming in CUDA is a lot of fun, it's good to have an overarching goal. In this case, looking at something as difficult as hair simulation and hair rendering and seeing what might work in those arenas - and what doesn't - gives you a better feel than overly simplified code examples.
And all of this is a long, complicated tough process - again something overly simple code examples and short blogposts never cover. Real programming is difficult and can take a long time, even when using someone else's library or engine. Pushing past current limitations is also a long, arduous process. So that's why I want this grounded, and as I just spent a good chunk of my life on a hair rendering and simulation system...
So I will be forking the current TressFX 4.1 off GitHub, and exploring Unreal and Unity engine integration/plugin strategies, but I'll also be looking at other solutions, algorithms, libraries, and even just doing some CUDA stuff when exploring ideas. And all code experiments will be on my GitHub page.
That will all start next post. I'm going to do this in bite-size chunks, since even forking and cloning a complicated GitHub repository that depends on other GitHub repositories deserves some explanation. Each post will have a different theme, so it can stand by itself but also fit into the long-term goal, which is to explore optimization and parallelization.
So get ready, and if you want to prep, get yourself a GitHub account, a developer account with Epic Unreal (for access to their GitHub repository), a copy of the latest Unity, and while you're at it, the CUDA toolkit. (If your graphics card isn't CUDA capable, I will also try to discuss OpenCL, but I recommend CUDA since it's very well documented, supported and easy to use.) As for ML (machine learning, like Tensorflow) that may come later. But learning to optimize and take advantage of the GPU is a key need, even with AI/ML projects.
Images are clipped from TressFX 4.1 documentation, sample code and/or blogposts, FEMFX sample code assets and sample scenes, and Columbia University's LibWetHair. Please see their websites (AMD GPUOpen, http://www.cs.columbia.edu/cg/liquidhair/ ) for more information and to respect their copyright/trademarks and/or licensing requirements.
My opinions are my own, and no one else's. Anything I talk about is either my own opinion and/or research, or public knowledge. As for copyright, all copyright is reserved unless explicitly noted, this includes my work or any references I make to papers, websites, libraries, engines or similar, which belongs to the original copyright/license holder. Always remember to cite your references, and observe copyright and licensing when using or referencing any code or words or images or anything that isn't your original work. 'Nuff said, I hope. Let's get coding!
Comments
Post a Comment