Hi guys!
I’m trying to expand the blur shader in the wiki page into a convolution shader, and I’ve encountered some issues.

-
The blur kernel is the only one that works, but using multiple passes would result in a darker output, although the weights seem correct.
-
The sharpen/edge kernels don’t work as expected.
-
Is there a way to write to a texture buffer that you could adress (exclusively) inside the glslTOP without using a TOP network? (without a render pass that you’d feed back to the glslTOP)?
glsl_convolution.toe (5.68 KB)
On line 18 in your shader, I think you want a different expression.
int row = j+1; // make it zero indexed
int col = i+1; // make it zero indexed
int myIndex = col + row*3;
// now myIndex goes from 0 to 8
Then you’d use
_kernel[myIndex]
Also refer to en.wikipedia.org/wiki/Kernel_(image_processing
The kerEdge should probably have an 8 in its center. Edge detection kernels sum to 0 but blur kernels sum to 1.
The indexing did the trick, thanks!
Now they work as intended.
Is there any way I could make all of them work in the same glslTOP?
For example applying the blur three times (ideally without using the ‘passes’ slider)
Right now the convolution is happening on a 2D input.
Is there any way to write to a framebuffer and then read from it without using external TOPs?
You could do this
layout (location=0) out vec4 fragColor1;
layout (location=1) out vec4 fragColor2;
layout (location=1) out vec4 fragColor3;
then
fragColor1 = color1;
fragColor2 = color2;
fragColor3 = color3;
You’d set the numcolorbufs parameter on the GLSL TOP to 3 and then use Render Select TOPs.
Can you blur three times without using the passes slider? No, I don’t think so. Perhaps you’d be interested in my gaussian blur tox viewtopic.php?f=4&t=9330&p=35278&hilit=gaussian#p35278
I’m not sure I understand your third question.
I’m pretty new to GLSL. Tried out a few GLSL viewers and they handle frame buffers differently, so I was wondering how it works in TD.
I was thinking if I want to apply a blur and then a sharpen in the same GLSL TOP, I’d have to use a Render Select TOP just to feed that back as a 2nd input to my GLSL TOP, so I was wondering if there was a better way to do it.
I was reading of texture buffers on the wiki.
What is the difference between these and color buffers?
Sometimes it’s great to use multiple passes, but in this situation I think you should have a unique GLSL TOP for each step of the process.
However, you can do something like this:
if (uTDPass == 0) {
// do your blur stuff and set color to something else
} else {
// do your sharpen stuff and set color.
}[/code]
I've read from a few sources that this conditional if-else branching is slow for the GPU. It's as if the GPU computes the blur and sharpen every pass.
As far as I know, you can do texelFetch on sTD2DInputs[], like
[code]
vec4 color = texelFetch(sTD2DInputs[0], ivec2(gl_FragCoord.xy),0);
[/code]
and texelFetch on a samplerBuffer that has been put on the Arrays page of the GLSL TOP.
[code]uniform samplerBuffer posBuffer;
void main() {
int id = 0; // an integer
fragColor = texelFetch(posBuffer, id);
}