8 ms·
Primer: Shaders
- fotcorn 13y agoWhat shader languages are used in cross-platform games? PS3 uses Cg, PS4 PSSL, Xbox & Windows use HLSL and OpenGL on Mac/Linux/Smartphones/Tablets use GLSL. Are there converters from one to the other language? How do big engines like Unreal oder CryEngine handle this?
- ceautery 13y agoNice, thanks a lot. Great animations. "Shader" was a term I was confused about at first when I was learning WebGL. In fact, in the WebGL world, it seems like one is expected to come from an OpenGL background and be familiar with whatever popular 3rd party libraries are en vogue. I never found a thorough guide that didn't presume one of those two things, so I built one: https://curtisautery.appspot.com/5898536285634560 https://curtisautery.appspot.com/5898536285634560 (Sorry, also jumping on the self-promotion bandwagon.)
- fescue 13y agoThis guide has helped me unbend my mind about shaders: http://pixelshaders.com/ http://pixelshaders.com/
- svantana 13y agoWhile I appreciate the effort, I think this primer is lacking what most other shader tutorials also lack: any information on how to actually do something useful. Shaders are used because they are faster than the cpu. So why isn't everything done with shaders? Because of limitations. So what are those? Most GPU tutorials only include examples of the form FragColor = <some algebraic expression containing x & y> That's nice, but hardly useful. To do anything of worth, I would need data from the CPU. How do I do that? What are the most common bottlenecks? What are some ways around the limitation of working with one fragment at a time? Those are the sort of questions I would like to see answered in a primer. A sort of "GPU introduction for competent CPU devs" - any recommendations?
- mattdesl 13y agoBottlenecks and multi-sample output are complex subjects, and also uncommon for a beginner to deal with. Nevertheless, gonna just pimp my own tutorials since they also cover practical implentations, like blurs for desktop and mobile, normal mapping for 2D games, vignettes, etc. https://github.com/mattdesl/lwjgl-basics/wiki/Shaders https://github.com/mattdesl/lwjgl-basics/wiki/Shaders
- mattdesl 13y agoNice intro. Shaders definitely seem a lot more elusive than they really are. Also gonna jump on the bandwagon with my own tutorials, using Java/LibGDX and mostly focusing on 2D applications. https://github.com/mattdesl/lwjgl-basics/wiki/Shaders https://github.com/mattdesl/lwjgl-basics/wiki/Shaders
- sillysaurus3 13y agoPart of the confusion is the confusing terminology. "Shader" is a bad name. How do you "shade" a vertex? That implies color, when in fact vertex "shading" is really about deforming the position of vertices. It has nothing to do with color! "Vertex program" is a better term. That brings us to "pixel shader." That's actually a good name in order for beginners to learn the concept, but it's imprecise. OpenGL insists on calling it a "fragment program" because with certain forms of antialiasing, there are multiple "fragments" per pixel. "Program" is also a better name than "shader" because there are things you can do per-pixel other than change the color. For example you could change the depth written to the Z-buffer, or you could cause the pixel to be skipped based on some criteria, like whether the texture color is pink. Anyway, it's just a tiny program that executes either per-vertex or per-pixel. For example you could write a vertex program which moves each vertex in a sinewave pattern based on time. Or you could write a fragment program to change the color of each pixel from red to green and back based on time. Then there are more advanced/recent concepts like a "geometry program," which lets you generate triangles based on vertices or edges. Sometimes I wonder if it's overly complicated, or if the problem domain is just complicated. It took me years as a kid to finally grok this, but once I learned it, it turned out to be very simple. Honestly it wasn't until I got up enough courage to sit down with the OpenGL specs and read through them that everything clicked. They're dry reading but not difficult.
- wcarss 13y ago"Anyway, it's just a tiny program that executes either per-vertex or per-pixel." Thank you. I have never understood the concept of a <thing>-shader; I just knew they were useful and somehow caused neat effects. Even having pasted some shader code into a program once (for a barrel distortion for my rift), I never thought much about them, likely because of the opacity of the name. Just ... magic. Your description has just made the entire concept click. I'm now actually interested in learning about them, because it's such a simple, sensible idea. Thanks. side-note: I wish the world had more one-sentence intuitive sum-ups of jargon-laden concepts, even if they are a little 'leaky' as abstractions. Just to give people disconnected from the topic a place to start thinking about it.
- 13y ago
- Jemaclus 13y agoAs someone who is not well-versed in graphics or graphics programming, this was a very well-explained primer. I very thoroughly enjoyed it, and learned something in the process!
- greggman 13y agoself promotion: Here's some more. http://greggman.github.io/webgl-fundamentals/ http://greggman.github.io/webgl-fundamentals/ In particular http://greggman.github.io/webgl-fundamentals/webgl/lessons/webgl-how-it-works.html http://greggman.github.io/webgl-fundamentals/webgl/lessons/w...
- ceautery 13y agoHey, I found these when I was untangling WebGL, and found them pretty useful. Thanks for making them.
- drifkin 13y agoI was just going over these the other day. Thank you!
- Skoofoo 13y agoHave been going through those to learn how to build out the rendering for my game framework. Awesome stuff! Your tutorials have saved me a lot of grokking time.
- neals 13y agoTo me, the thing with shaders always is: I need them at some stage in a project. I have used them before, but too long ago to remember, so I need to look up most it. I work with it a for a few weeks. That part of the project is done and I move on. A year later, a new project comes along. It requires shaders. I don't remember how to use then and have to look it up again... Repeat.