pouët.net

Go to bottom

Where to start shader?

category: code [glöplog]
What I'm looking for is advice where to start learning and writing shaders for demomaking purposes? Which tutorial/book/whatever?
Visual Studio 2010, C++, Win32, OpenGL, GLSL is preferred.
I have written a few basic fragment shaders to post process media player's output.
I know some basic OpenGl.

I'm sure this was asked before but I couldn't find it with search tool.
added on the 2012-05-22 10:10:01 by musk musk
I use RenderMonkey and ShaderToy.
added on the 2012-05-22 10:27:18 by mudlord mudlord
I started with shadertoy too, then switched to glsl.heroku.com.

You do not need more :)
added on the 2012-05-22 10:34:47 by rez rez
http://www.opengl.org/wiki/Getting_started

Some "Tools"
WebGL playground with a lot of GLSL ES shaders
FX Composer (no GLSL but NV CG stuff)
RenderMonkey

Both FXComposer and RenderMonkey are not really up to date. But at least you can write #version 400 (+) shaders in RenderMonkey if you setup the out locations properly (But you don't have proper MRT support for GL - and no non power of two rendertargets :().
In case you have a better shader editor - let us know.

Decide for an OpenGL version first (I would go for the most current stuff) - then get the specification for both GL and the corresponding GLSL version - read it (!) - and try to write specification correct code. Get used to the fact that shader compilers suck.
added on the 2012-05-22 10:39:14 by las las
Speaking of sucky shader compilers.
Get GPU ShaderAnalyzer from AMD's site. At least then you have some idea if your shader needs modding if it doesn't work on ATI cards, and you have a nvidia. Not sure if nvidia has a similar tool.
added on the 2012-05-22 10:42:15 by mudlord mudlord
I started from scratch a few weeks ago, after being away from mainstream PC demo effect coding for something like 15 years. This was sometime after Revision 2012, where Rale of the Demoscene Youth Division implied something along the lines that it's not the most enjoyable situation for a scene person to just sit and not create anything anymore. ;) I thought, yeah, that's actually true, I want to get my lazy ass going once again, so I went to Google and typed something like "how to code 4k intros", and I found
- Iq's great intro framework
- Pouet's "raymarching" threads (which I had actively avoided because I thought it was some un-fun scene fashion for the c00l kids)
- 4klang (which I had heard of but didn't really know or care about)
- Crinkler
- Shader Minifier
- Visual Studio 2010 Express.... I was like, WHAT, this thing is FREE now???

In a couple of weeks, to my surprise, I was up and running, toying around with ray marching and GLSL shaders. It's about as easy and fun as anything can be! I even managed to make and release this 4k intro in the Stream intro compo
http://www.pouet.net/prod.php?which=59280
That's my second released 4k intro ever, the first one being at Assembly 1994. It's hard to describe how good it felt to make the quantum leap from the "release-nothing" space into the "release-something" space. I released SOMETHING and, with all respect, at this point I don't even care much about what anybody thinks of it.

For some reason, I did not use any of the shader editors, Shadertoy etc. Just editing text in Visual Studio 2010, and running it through Shader Minifier. Worked great. Mind you, I didn't and still don't even have a PC with a GPU. Software-rendering only. I run the stuff in a 300x160 window (or something), and it seems to work reasonably fine, and totally flies with a modern computer and GPU.
added on the 2012-05-22 11:07:57 by yzi yzi
Actually what we us is the approach gopher is using for a quite long time already.
Write a basic shader framework. For raytracing stuff a fullscreen quad is almost enough.
Store your shaders as textfiles before you merge them intro headers or whatever you want to do - reload your shaders automatically on file change.
Then you can have your "shaderviewer" opened + some editor (Notepad++ here) just write your code there - press ctrl+s and see it directly in your minimal viewer.

Some improvements I can recommend:
- If you are on a low end machine - setting "toggle single frame mode" with spacebar if the viewer is active is a good idea. Such that in case you save your shader - it only renders on frame and goes back to idle after that.
- Parsing the error message and finding the line number might be a cool idea - you then can "activate" the editor window from the viewer and send keys to go to the line with the error. (pageups + home + linedowns - that's a really bad hack ;) but sometimes works good enough.)
- An additional console window for error output and things like that is highly recommended
added on the 2012-05-22 11:34:02 by las las
Unless your PC is 10+ years old, there's a GPU (yes, the intel ones count). And SR fallback for shaders? Sounds painful. :)
added on the 2012-05-22 11:42:20 by tomaes tomaes
Btw, is there a way to properly debug shaders yet? I hated the "black screen, wtf is wrong?" situations.
added on the 2012-05-22 11:44:29 by tomaes tomaes
What las said, that's more or less what I do as well. I used to use GLSL Devil, but support fell behind a bit and it got to be too much of a PITA.
added on the 2012-05-22 11:44:56 by Subi Subi
nobody here mentioned a SR fallback for shaders. no no no.
The single frame mode is a really good thing if computing ONE SINGLE FRAME takes more than a half second on your slow GPU and might be pretty damn useful for procedural graphics anyways.
added on the 2012-05-22 11:45:35 by las las
Quote:
nobody here mentioned a SR fallback for shaders

I was referring to yzi's last paragraph. Gotta use quote tags in fast moving threads:
Quote:
I didn't and still don't even have a PC with a GPU. Software-rendering only. I run the stuff in a 300x160 window (or something), and it seems to work reasonably fine, and totally flies with a modern computer and GPU
added on the 2012-05-22 11:49:24 by tomaes tomaes
I guess he wanted to tell us that he is using a slow onboard GPU.
added on the 2012-05-22 11:53:17 by las las
That's my guess as well, although google tells me his claim is not as impossible as i thought. ;)
added on the 2012-05-22 11:56:27 by tomaes tomaes
http://lomont.org/Software/

good demo to start)
Yes, of course the PC has "a GPU". Integrated Intel chip. I stand corrected.
added on the 2012-05-22 12:15:26 by yzi yzi
Quote:
Btw, is there a way to properly debug shaders yet? I hated the "black screen, wtf is wrong?" situations.

#ifdef DEBUG_SHADERS
if (((PFNGLISSHADERPROC)wglGetProcAddress("glIsShader"))(s))
{ ((PFNGLGETSHADERINFOLOGPROC)wglGetProcAddress("glGetShaderInfoLog"))(s, 1024, &infologLength, infoLog);
if(infologLength>0)
{
MessageBox(0, infoLog, "ERROR Fragment Shader", MB_OK|MB_TOPMOST);
}
}
#endif

Where s is the shader program. Do it for both vs and fs.
added on the 2012-05-22 12:29:02 by rale rale
I recall once having drivers that said "Shader compiled succesfully!" with the said code. I don't know if it happens anymore but it's probably a good idea to leave that out of the release build of your demo, or then output it to a debug log or something :)
added on the 2012-05-22 12:37:13 by Preacher Preacher
Quote:
Yes, of course the PC has "a GPU". Integrated Intel chip. I stand corrected.


which is about the same has having no GPU sadly. :/
btw, it raises the question, do the majority of sceners use laptops to watch prods nowadays or do they still have good old desktop with decent graphics hardware? It's interesting to know what "part" of the PC platform we're trying to target..
added on the 2012-05-22 13:32:40 by nystep nystep
Preacher: Are you sure you didn't ONLY check the info-log? The info-log is allowed to contain something even if the shader compiled. It's very useful for warnings, for instance. Some drivers also put some additional (usually pretty useless, though) information in the log.
added on the 2012-05-22 13:46:33 by kusma kusma
What Kusma is saying in copy+paste friendly version:
kzInt status;
glGetShaderiv(s, KZS_GL_COMPILE_STATUS, &status);
if(status==0)
{
// Info log crap I posted earler
}
added on the 2012-05-22 14:01:15 by rale rale
I honestly can't remember, it was years ago. I saw it happen with other people's code as well (I remember one demo that hid the messageboxes under a black OpenGL screen... nice). You're probably right.
added on the 2012-05-22 15:02:19 by Preacher Preacher
What rale is saying in somewhat more portable form, because people wondering how to get started with shaders probably haven't defined their own types:

glInt status;
glGetShaderiv(s, GL_COMPILE_STATUS, &status);
if(status==0)
{
// Info log crap rale posted earlier
}
added on the 2012-05-22 15:11:29 by Pope Pope
So from what I understant there is no straightforward way to start. I just have to read bunch of random stuff and/or read the specification.
added on the 2012-05-22 17:28:03 by musk musk
I don't think any of the suggested things were random or the spec. Download Iq's intro framework, it has everything set up and commented so you can compile, run and tweak the shaders. I don't think it can get any more straightforward.
added on the 2012-05-22 18:09:29 by yzi yzi

login

Go to top