GLSL Tips for noobs

edited April 2014 in GLSL / Shaders

Last few days i'm starting with shaders. It's kinda hard to find a good entrance. You don't want to read stuff for day's, but trying out and figure out nothing works is also not motivating. So i thought a Tip topic might be nice, i will start.

1. You can not call methods you create in a shader file from processing. But you can set values with set: http://processing.org/reference/PShader_set_.html

2. Let's say you have a uniform vec4 targetColor; and want to set the color from processing to red. This will give no errors, it also gives a result, but not what you want:

colorRange.set("targetColor", new PVector(1.0, 0.0, 0.0));

The 4th value has to be set so use:

colorRange.set("targetColor", 1.0, 0.0, 0.0, 1.0);

3. You can create methods but at the parameters there are qualifiers: in, out and inout.

float norm(in float value, in float start, in float stop) {
    return (value - start) / (stop - start);
}

http://relativity.net.au/gaming/glsl/Functions.html

4. Make sure to use shader(theShader); and not filter(theShader);, processing won't throw an error, but you keep wondering why nothing works...

That's about it for now.

Comments

  • Thanks for posting your experience with shaders in Processing, please feel free to update as you move along and find other tricks/quirks.

    I admit that the tutorial might not be the best way to get started quickly, the included shader examples could offer a faster way to play with code and see results, but the problem remains that GLSL is an entirely new language that also requires at least some understanding of how the GPU works in order to use properly. This "high barrier" to shader programming will likely remain until we can add some other way to add shaders into a Processing sketch.

  • I think a tutorial where you first make the effects on the cpu and then the gpu would be better. This way people get a better understanding. I do it myself like that as well. Maybe just recreating all filters in processing: http://processing.org/reference/filter_.html First on the cpu, so you can learn how the filter works, then as a shader so you already know how it works and your mind goes more out of how the glsl works.

    I might make it myself when i have time (will be in 3 months).

  • Please continue with the noob tips!

Sign In or Register to comment.