Thorsten https://thesiteabout.me/gaming/rediscovering-shaders-pt1

Rediscovering Shaders - Pt.1

How I jumped back into learning shaders, nearly two decades after first learning about them.

gaming

Rediscovering Shaders after two Decades - Pt.1

I first started playing around with shaders in the mid-2000s while developing a game for Ogre3D, a FOSS 3D engine which amazingly still exists today. Since I learned I could program the behaviour of my GPU, I was enamoured by the seemingly endless possibilities. I learnt all about vertex and fragment shaders and even dabbled a bit in general purpose GPU programming with CUDA. I felt like I knew my stuff pretty well. In the past decade, however, I haven't really used shaders much for any of my projects. Modern game engines like Unity and Godot just let you do so much already without even touching any custom shader code. But with one of my recent side-projects, I ran into a problem, which I seemingly couldn't solve. It was just about displaying a sprite animation in a TextureRect as part of the UI, but the dedicated class for it is deprecated and there is no replacement. Seriously bad practice btw, dear Godot maintainers. I still love you, though! 💙

My mind began to search for alternatives and soon I recalled what I had learned almost two decades ago: this sounds like a job for a fragment shader! So I fired up the shader editor and got to work. Aaaaand I was immediately stumped. Long story short, it turns out I've forgotten all the basics. I managed to make it work in the end, but it all felt slow and clunky and ugly and like I didn't know what I was doing - because that last part was sadly true. I decided that I need to dive back into modern shaders to refresh my skills a bit.

Seeking the ancient Knowledge

Back in the days, I had learned shaders best from books, such as the 'GPU Gems' series, so I tried looking if that is still around. They are indeed now freely available online, and still contain a treasure trove of knowledge. However, the series stopped at the 3rd book, which is as old as my knowledge was, so something more recent would be lovely. I'm pretty sure some new techniques entered the scene in the past fifteen years.

One thing you find pretty quickly is The Book of Shaders, which looks like a brilliant start. It is not finished, however, and I don't know if it ever will be, with the last commits on their Github being merged years ago at the time I checked it out. So I decided to give that a pass, to not get into something that is good, but ultimately frustrating, because it stops right in the middle of things, like your favourite TV show being cancelled. The 2nd book I came across was The Godot Shaders Bible by Fabrizio Espíndola. It looks up-to-date, follows the same structure as the GPU Gems series, with separate chapters for each concept, and even uses the game engine I'm used to. I was sold! It's targeted at beginners, whereas I already know a bit more about the ins and outs of the render pipeline. But I assumed a little refresher can't hurt.

The Godot Shaders Bible - A mixed bag

A 3D view of the eyes of an anime-style character. The pupil seems to distort and follow the camera, a shader effect.

One of the cool effects covered in The Godot Shaders Bible. An anime-style eye effect where the pupil looks like it's following you.

This book assumes you know the Godot editor already. Luckily, I do. Every example the book covers comes with pre-packaged material, like the models or textures to use, which is really helpful. Sadly, the included scene and resources are from the finished examples, which I'm torn about. On one hand, it is nice to have the finished thing provided, in case you just want to look at it. On the other hand, it is confusing as hell when you're told to do a bunch of steps, for example to create a resource, to find out it's already there in your project, because you copied one file too many from the resources. Fabrizio is sadly also not always clear about what to include and what not, but at least there is a system to it, which you'll figure out after five or six examples. From then, you can skip the setup sections basically entirely, as it is always the same. I would have liked it if Fabrizio just provided two directories with the book material, one for the finished examples to look at and one workbook to work along. Then instead of spending a solid page for each exercise that tells you "first, create xyz in the assets folder, then...", he could have just said "open the folder chapter_01 in your workbook".

But let's get to the actual meat of the book: the shaders. Fabrizio definitely knows his craft. Sadly, he kinda assumes, you do, too. There are several instances when working with the book, where I felt like I had missed a page or two that explain some concept. Even worse, Fabrizio is inconsistent in what he explains and what he doesn't. For example, he does a good job explaining the Lambertian lighting model and also what specularity is. But then comes the anisotropic effect, which is "introduced" as follows:

When working with an anisotropic reflection model, the first question you should ask is: Which model will work best for my project? While it is true that several models can produce similar visual results under certain conditions, the differences can become significant when considering factors like visual finish, computational cost, or optimization.

Some common anisotropic specular models include:

  • ...

I would argue the first question I should ask is "What the hell is the anisotropic lighting model?" And given you explained specularity to me, a less advanced concept, why don't you explain it here? This is where I put the book away for the first time, being somewhat overwhelmed and frustrated. I picked it back up the next day, figuring I won't really need to understand the exact maths behind it all to simply apply it, and I could follow along just fine. But it does leave you feeling like you missed something that should have been explained to you.

There are a handful of spots in the book that had me stumbling like that. And keep in mind, I am not a beginner in computer graphics. My knowledge may be rusty and twenty years old in places, but I know what quaternions are and how vector maths work. I can only imagine it's even harder to follow for an actual beginner.

On a positive side, the book does demonstrate some very nice visual effects that have the potential to spice up any game project instantly. However note that I'm choosing my wording quite carefully here: it demonstrates, not necessarily teaches them. I worked along with the code and think I can recreate them - but I don't feel I necessarily got enough background information so I can adapt the concept and make something inspired by it.

I would only recommend the Godot Shaders bible, if you're really desperate to get a few cool shader recipes for your game, and already know a bit about working with shaders. But if that's worth the money for the book, you decide for yourself. To actually learn, especially for beginners, look somewhere else.

Looking somewhere else

I've yet to work through chapter 4 of the book, which is, ironically, the stuff that actually interests me the most. However, I have lost faith The Godot Shaders Bible can provide what I'm searching for, so I looked for different sources of learning, with different formats. That will be discussed in Part 2 of this blog post.


© All content hosted on here is mine, unless otherwise stated, and you can't use it anywhere else without my permission.

 

 

An IndieWeb Webring 🕸💍
Thorsten Schillo

Thorsten Schillo

Wien Austria

I'm a history nerd and wannabe explorer of cold places. I also love the mountains, taking photos, playing video games, doing ancient Greek reenactment and occasionally Larp.