Sunday, July 8, 2018

opengl - Fixed-Function vs Shaders: Which for beginner?


I'm currently going to college for computer science. Although I do plan on utilizing an existing engine at some point to create a small game, my aim right now is towards learning the fundamentals: namely, 3D programming. I've already done some research regarding the choice between DirectX and OpenGL, and the general sentiment that came out of that was that whether you choose OpenGL or DirectX as your training-wheels platform, a lot of the knowledge is transferrable to the other platform. Therefore, since OpenGL is supported by more systems (probably a silly reason to choose what to learn), I decided that I'm going to learn OpenGL first.


After I made this decision to learn OpenGL, I did some more research and found out about a dichotomy that I was somehow unaware of all this time: fixed-function OpenGL vs. modern programmable shader-based OpenGL. At first, I thought it was an obvious choice that I should choose to learn shader-based OpenGL since that's what's most commonly used in the industry today. However, I then stumbled upon the very popular Learning Modern 3D Graphics Programming by Jason L. McKesson, located here: http://www.arcsynthesis.org/gltut/


I read through the introductory bits, and in the "About This Book" section, the author states:




"First, much of what is learned with this approach must be inevitably abandoned when the user encounters a graphics problem that must be solved with programmability. Programmability wipes out almost all of the fixed function pipeline, so the knowledge does not easily transfer."



yet at the same time also makes the case that fixed-functionality provides an easier, more immediate learning curve for beginners by stating:



"It is generally considered easiest to teach neophyte graphics programmers using the fixed function pipeline."



Naturally, you can see why I might be conflicted about which paradigm to learn: Do I spend a lot of time learning (and then later unlearning) the ways of fixed-functionality, or do I choose to start out with shaders? My primary concern is that modern programmable shaders somehow require the programmer to already understand the fixed-function pipeline, but I doubt that's the case.


TL;DR = As an aspiring game graphics programmer, is it in my best interest to learn 3D programming through fixed-functionality or modern shader-based programming?



Answer




I don't buy the argument that it's easier to start with the fixed-function stuff. It might be the case that the fixed-function lets you do certain things with less code - in fixed-function OpenGL, for instance, you can get some very basic lighting/shading going by doing glEnable(GL_LIGHTING) and a few other calls. The trouble is that as soon as you want something slightly different - per-pixel lighting, say, instead of per-vertex lighting - you have to abandon the fixed-function stuff entirely and write a shader to implement both whatever fixed functionality you were using before, plus whatever you wanted to change.


It just seems like it would be simpler and less confusing to be using shaders the whole time. Shaders do need a bit more setup work as you have a separate source file that needs to be loaded and compiled, some extra C calls to look up and set parameters, etc. But once you've got a shader going, it's the easiest thing to code a few different effects, try out different ideas, etc. And you don't need to care about where the limits of the fixed-function system are and whether it can or can't do what you want; shaders can do whatever you can write code for, modulo the usual limits of performance and memory.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...