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.
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.
I use RenderMonkey and ShaderToy.
I started with shadertoy too, then switched to glsl.heroku.com.
You do not need more :)
You do not need more :)
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.
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.
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.
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.
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.
- 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.
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
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
Unless your PC is 10+ years old, there's a GPU (yes, the intel ones count). And SR fallback for shaders? Sounds painful. :)
Btw, is there a way to properly debug shaders yet? I hated the "black screen, wtf is wrong?" situations.
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.
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.
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.
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
I guess he wanted to tell us that he is using a slow onboard GPU.
That's my guess as well, although google tells me his claim is not as impossible as i thought. ;)
http://lomont.org/Software/
good demo to start)
good demo to start)
Yes, of course the PC has "a GPU". Integrated Intel chip. I stand corrected.
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.
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 :)
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..
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.
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
}
kzInt status;
glGetShaderiv(s, KZS_GL_COMPILE_STATUS, &status);
if(status==0)
{
// Info log crap I posted earler
}
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.
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
}
glInt status;
glGetShaderiv(s, GL_COMPILE_STATUS, &status);
if(status==0)
{
// Info log crap rale posted earlier
}
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.
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.