Want to learn about shaders? - new ebook


It has a code project that goes with it, with about 10 example shaders (link in the ebook)

If you know something about meshes, you should be able to understand it, but it’s not for complete beginners

Looks Good,
Thanks for uploading @Ignatz

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!

If it’s useful, I’ll follow up with one on lighting shaders…

Nice work Ignatz. Read till the part before the examples and I feel much better about shaders now.

I had tried learning shaders before, through your tutorials, but maybe it was too early at that time.

@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!

Sounds promising, I’ll definitely read it!

@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!

Thank you @Luatee. :">

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!)

Thanks @ignatz =D>

=D> =D> =D> =D>

Wow, very nice! I actually understand shaders now!

@Andrew_Stacey - good post sir!

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…).

Out of curiosity, can you give us a few examples?

Nice, though naturally I missed the matrices …


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.

@Andrew_Stacey +1

I noticed vec3 was missing, and thought the same thing to myself about changing a pixel position.

One more thing, though. I thought that, with shards, you’re not sampling each pixel of the texture, but each pixel of the mesh that is visible?

@Andrew_Stacey - thank you for taking the time to review it

I am happy to have got away with so few corrections, not being a shader (or C) expert.


@Andrew_Stacey - I’d also like to see some examples of using math instead of conditionals, eg
if X then Y else Z
if (col.a>0.0) then X else Y

This page

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.

@Jmv38 I’m thinking of maybe getting a bunch of tutorial-like comments I made and putting them all together… But here’s one on string matching.