News for hackers. Stuff that matters.
Re:The Book of Shaders by anon4 on Tuesday March 17, 2015 @06:28AM (#9217112)
A very small piece of advice which I don't see mentioned here: OpenGL works in linear RGB (which is very convenient), while your monitor displays sRGB (which gives you better colour resolution due to how eyes work). This means that outputting the result of OpenGL directly on your screen is wrong (a lot dimmer than it should be). Use this little fragment in all your shaders to convert the final output to sRGB:

    vec3 srgb(vec3 rgb) {
        vec3 mask = vec3(greaterThan(rgb, vec3(0.0031308)));
        return mix(rgb * 12.92,
                   pow(rgb, vec3(1.0 / 2.4)) * 1.055 - 0.055,
                   mask);
    }
Edit: Here's a very good example of the difference https://imgur.com/a/g6qNI

Edit 2: And of course when you load textures you must tell OpenGL they're in sRGB colourspace (most probably they are, if you created them on a normal monitor), so it will do the reverse transformation when reading from the texture. All this trouble could have been avoided if monitors were 30bit linear RGB colourspace to begin with, but that's history now. C'est la vie.

Re:The Book of Shaders by socialist_coder on Tuesday March 17, 2015 @08:54AM (#9217538)
So you're saying that in my shaders, as long as I have GL_FRAMEBUFFER_SRGB enabled, this conversion takes place automatically? Am I understanding the docs right?

I'm asking because I'm a mobile game developer using Unity3d, and we have a fair amount of custom shaders, and I've never heard about this sRGB vs RGB colorspace thing before so I want to investigate. There's not much on google for GL_FRAMEBUFFER_SRGB + Unity3d. Maybe it's handled automatically or it's not even possible with openGL ES 2.0.

Re:The Book of Shaders by topkekz on Tuesday March 17, 2015 @07:54PM (#9222510)
The implicit conversion only happens when the internal format of the destination buffer is GL_SRGB8 or GL_SRGB8_ALPHA8
Re:The Book of Shaders by dtf on Tuesday March 17, 2015 @10:25AM (#9218103)
Here's a bunch of shader code and examples for different tone-mapping operators. I really like the Hejl/Burgess-Dawson one as a simple Linear -> sRGRB-ish output function.

http://filmicgames.com/archives/75

Re:The Book of Shaders by adsche on Tuesday March 17, 2015 @02:56AM (#9216619)
What I read so far is great, but I noticed this gem about preprocessor directives:

    All the macro comands begin with a hashtag (#). 
Do we really call every hash character a hashtag now?! :)
Re:The Book of Shaders by fit2rule on Tuesday March 17, 2015 @04:20AM (#9216800)
Welcome to the rolling wave of civilization. Did we really used to call the number sign a "hash character"?
Re:The Book of Shaders by pmjordan on Tuesday March 17, 2015 @04:59AM (#9216880)
UK & Ireland: Yes, and still do, although it's apparently a corruption of "hatch" (as in cross-hatch).

http://en.wikipedia.org/wiki/Number_sign#Usage_in_the_United...

Re:The Book of Shaders by e12e on Tuesday March 17, 2015 @09:20AM (#9217661)
Vaguely related:

From The Devil's Dictionary (1881-1906) [devil]:

    HASH, x.  There is no definition for this word -- 
    nobody knows what hash is.
Re:The Book of Shaders by pjc50 on Tuesday March 17, 2015 @05:34AM (#9216973)
Better than calling it the pound symbol. It was always a source of minor confusion, as people used it rarely and had all sorts of different names for it.
Re:The Book of Shaders by timdiggerm on Tuesday March 17, 2015 @07:56AM (#9217328)
No matter what I do, this is what my students call it. hashtag include iostream
Re:The Book of Shaders by smoyer on Tuesday March 17, 2015 @06:26AM (#9217105)
You mean the octothorpe character? [1] That symbol seems to go by a lot of names!

[1] https://en.wikipedia.org/wiki/Number_sign

Re:The Book of Shaders by gaius on Tuesday March 17, 2015 @07:03AM (#9217197)
It's a "sharp", hence why #! is often called a "shebang". Tho' I call ! a "pling".
Re:The Book of Shaders by ThatOtherPerson on Tuesday March 17, 2015 @07:26AM (#9217250)
The sharp sign (♯) [1] is actually a different symbol than the number sign (#) [2].

[1] https://en.wikipedia.org/wiki/Sharp_%28music%29

[2] https://en.wikipedia.org/wiki/Number_sign

Re:The Book of Shaders by mrspeaker on Tuesday March 17, 2015 @09:19AM (#9217654)
In Australia (or maybe it was just me?!) we called it "hash" not "sharp"... so #! was "hashbang". The beauty of this system is that #| is "hashpipe", so it _must_ be correct.
Re:The Book of Shaders by GuiA on Monday March 16, 2015 @11:28PM (#9216115)
Toby Schachman made a similar attempt at writing an interactive book about shader programming, but sadly it hasn't been updated in a long time.

http://pixelshaders.com

Hopefully this site won't meet the same fate!

Re:The Book of Shaders by ash on Tuesday March 17, 2015 @09:46AM (#9217826)
I think it was because Toby Schachman couldn't think of good exercises on more advanced topics. I would guess this struggle influenced his later work - Shadershop:

http://tobyschachman.com/Shadershop/

(Check it out, it's super cool.)

Re:The Book of Shaders by nos4A2 on Monday March 16, 2015 @10:00PM (#9215834)
This is awesome! As someone who just spent a ton of time navigating a patchwork of information about GLSL, this looks like an oasis :) (I can't seem to access all the chapters though, I guess its a work in progress).
Re:The Book of Shaders by BinaryIdiot on Monday March 16, 2015 @10:38PM (#9215962)
This looks great. Is there a way to easily take it offline so I can read it on my Kindle? Also...

> If you are reading this book in a browser the previous block of code is interactive. That means you can click and change any part of the code you want to explore.

Now that's pretty damn cool!

Re:The Book of Shaders by nos4A2 on Monday March 16, 2015 @11:16PM (#9216082)
Re:The Book of Shaders by cfrs on Tuesday March 17, 2015 @08:53AM (#9217535)
For those who don't want to install texlive, pandoc and glslViewer, here is PDF: https://www.dropbox.com/s/uc6g1pkrswjrvhj/TheBookofShaders-P...
Re:The Book of Shaders by BinaryIdiot on Monday March 16, 2015 @11:51PM (#9216176)
Well that's handy, thanks!
Re:The Book of Shaders by sp332 on Tuesday March 17, 2015 @09:57AM (#9217907)
Re:The Book of Shaders by monsterix on Tuesday March 17, 2015 @02:00AM (#9216502)
Kindle or on iPad Safari? I don't know about people in your vicinity but kids in my area are off Kindle completely. This is anecdotal evidence obviously.

The experience of reading books with lifeless text/images sounds like a retrogressive proposition to me. I think e-books will have to move up the tool chain, enter browser with alternative reading experiences.

Re:The Book of Shaders by lemming on Tuesday March 17, 2015 @03:02AM (#9216635)
I don't know about the kids near you but I gave my iPad away, and you can claw my Kindle from my cold, dead hands.
Re:The Book of Shaders by Sophistifunk on Tuesday March 17, 2015 @01:14AM (#9216389)
This really needs an email list for updates as more content is added. And maybe a Patreon account as well :D
Re:The Book of Shaders by aikah on Tuesday March 17, 2015 @02:43AM (#9216602)
> This really needs an email list for updates as more content is added. And maybe a Patreon account as well :D

or you know,support simple Atom syndication ...

Re:The Book of Shaders by Aldo_MX on Tuesday March 17, 2015 @01:31AM (#9216434)
In the meantime you can watch the github repo and get notified of updates.
Re:The Book of Shaders by Sophistifunk on Friday March 20, 2015 @08:48AM (#9237320)
good idea!
Re:The Book of Shaders by endymi0n on Tuesday March 17, 2015 @02:30AM (#9216577)
Finally. 50 Shaders of Grey.
Re:The Book of Shaders by kowdermeister on Tuesday March 17, 2015 @07:56AM (#9217329)
I can only encourage the author to continue. It's a really enjoyable way to learn things. I like how he challenges my in a tutorial.

Although I haven't tried it, here is an NPM package for learning shaders: https://www.npmjs.com/package/shader-school

Re:The Book of Shaders by WhitneyLand on Tuesday March 17, 2015 @07:55AM (#9217326)
Great work, it's apparent a lot of thought went into the presentation and teachings.

I'm guessing there are lots of developers out there who don't realize that shaders are quite accessible for simple tasks even without much of a math or graphics background and/or that power is now available is most web browsers.

Re:The Book of Shaders by mykolasmith on Monday March 16, 2015 @11:15PM (#9216077)
Thanks for this!

Edit: great illustrations, too!

Re:The Book of Shaders by guncheck on Tuesday March 17, 2015 @11:59AM (#9218828)
This is pretty cool. I'll read this. Thanks!
Re:The Book of Shaders by telekid on Monday March 16, 2015 @10:47PM (#9215985)
What an incredibly beautiful piece of design. I can't remember the last time I was so inspired by careful use of typesetting and white space.
[dead]
Re:The Book of Shaders by daeken on Tuesday March 17, 2015 @12:28PM (#9219088)
Um... what? How does this in any way relate to 50 Shades, except for the word 'shade' being contained in 'shaders'? There doesn't even appear to be a reference to it in any of the text.

Put down the pitchforks.

Re:The Book of Shaders by fWnApHU2PY6CPA on Monday March 16, 2015 @10:47PM (#9215984)
What an incredibly beautiful piece of design. I can't remember the last time I was so inspired by careful use of typesetting and white space.
Re:The Book of Shaders by lobo_tuerto on Tuesday March 17, 2015 @01:41AM (#9216455)
This would be great material for a GitBook: https://www.gitbook.com/
Re:The Book of Shaders by adsche on Tuesday March 17, 2015 @03:00AM (#9216632)
Why? What about the iteractive shaders?
Re:The Book of Shaders by lobo_tuerto on Tuesday March 17, 2015 @10:19AM (#9218058)
That could be used in-browser as it is right now.

But going to a publishing platform could also earn his efforts some money for a work well done. Open a channel to receive donations (or sells). Supporting the book through economic means might motivate the author enough to see through its completion.