Ahh… On page 6 right now on my iPhone. So far it’s clearing up the basics of shaders. I think this is just that one resource I needed to get a grasp on shaders.
Thanks a ton!
@Ignatz, Looks great! I love the bit where you say fader shader, it just has such an awesome ring to it! I feel like I knew the majority of it, but I learnt a few things here and there! It’s a great resource!
@Ignatz good read thanks, learnt what other beginner tutorials miss, a good ‘explanation’ of the pipeline and a good view of the vertex shader, good work!
It’s a shame there aren’t more easy tutorials for this kind of thing anywhere on the internet (that I could find, anyway - I would have saved myself a lot of time if I had found some!)
I’m particularly interested in your last point. I guess you’re implying that mathematically you can simplify a set of conditionals to an elegant mathematical solution? (e.g. setting limits and ranges etc…).
p1 You can’t change the position of a pixel in a fragment shader. You can change its texture coordinate.
p3 Last sentence is missing an “and”. I’m not sure I agree with that sentence though. Perhaps: “OpenGL interpolates them into pixels on the screen and colours for those pixels.”
p8 vec3 exists as well (you mention mat3 so it’s odd you don’t mention the vector equivalent)
p13 How about using some of the += and *= type operators?
Shouldn’t yellow have 255 for alpha?
You are inconsistent with your symbol for multiplication.
p16 This would be a great place for *=: col.rgb *= lighting
p20 vColor = color * lighting;
p24 “we would have a mess is our fragment shader” should be “in”
The mod function is a little more powerful than you make out here. Also, for this situation you should use the fract function.
I recommend typesetting maths and inline code differently to the running text to make them clearer.
You use conditionals in your shaders a lot. These should be avoided in favour of mathematics.
has some interesting recommendations, and (at the bottom) indicates the speed of various functions. Conditionals seem to come out OK. I realise this wasn’t benchmarked on an iPad, but I had understood that current shader software had overcome the earlier limitations of shaders wrt things like conditionals.
@Ignatz i really like the sample shaders project you have shared. This is very simple and usable, in assiciation with the ebook. Thank you so much for this!
I wish someone would do the same with captures and patterns…
@Ignatz Well, I was just repeating what I’d read about conditionals and loops in shaders. Maybe we should do some tests.
Here’s an example of how to convert a conditional to a mathematical statement. In one of your shaders you have a boolean to flip the x-coordinate of a texture. I think you do:
if (flip) then v.x = 1. - v.x;
You could instead make flip a float with possible values 0 or 1 and write
v.x = flip + (1. - 2.*flip)*v.x
But if I’m wrong about conditionals then maybe it’s not worth doing stuff like that. One thing I do know is that you can’t evaluate conditionals outside the main function, and the flip conditional is really a one-time conditional. Indeed, it is probably quicker to have two distinct shaders and install the right one for the task at hand.