gaussFactorForOffset cannot call a non-function how to fixed this code?

Started by jhovarie, April 18, 2018, 01:23:04

Previous topic - Next topic

jhovarie

Crossposted https://computergraphics.stackexchange.com/questions/7522/gaussfactorforoffset-cannot-call-a-non-function-how-to-fixed-this-code

Hello guys I am trying to blur image using fragment shader but it is not smooth.. I search the internet and I found similar problem... some one answer his question but unfortunately I cannot fallow it..

The question here are similar to my problem. this one https://stackoverflow.com/questions/33778381/how-to-blur-image-using-glsl-shader-without-squares and this one
https://stackoverflow.com/questions/44829671/smooth-blur-gaussian-in-opengl-es-2-0

Now I am trying this code but I got error. cannot call a non-function

#version 120

uniform sampler2D sampler;
varying vec2 tex_coords;

vec4 funcBlurTexture() {
	float blur = 1.0/387.; //?? original settings: 2.0/720.; 
	//float blur = 1.0/1280.;
	 
	 vec4 sum = vec4(0.0);
     vec2 tc = tex_coords;
   
     float hstep = tex_coords.x;
     float vstep = tex_coords.y;
     
     float horizontalOffset = 2.0;
     float radius = 2.0;
     float verticalOffset = 2.0;
     float gaussFactorForOffset = 1.0;
     
     //Trying to use this
     for(horizontalOffset = -radius; horizontalOffset<radius; horizontalOffset  += step) {
    	for(verticalOffset = -radius; verticalOffset<radius; verticalOffset += step) {
        	sum += texture2D(sampler, tex_coords+vec2(horizontalOffset, verticalOffset))*gaussFactorForOffset(sqrt(horizontalOffset*horizontalOffset + verticalOffset*verticalOffset)/radius);
    	}
	 }

     /*
    //Old Code
     sum += texture2D(sampler, vec2(tc.x - 4.0*blur*hstep, tc.y)) * 0.0162162162;
     sum += texture2D(sampler, vec2(tc.x - 3.0*blur*hstep, tc.y)) * 0.0540540541;
     sum += texture2D(sampler, vec2(tc.x - 2.0*blur*hstep, tc.y)) * 0.1216216216;
     sum += texture2D(sampler, vec2(tc.x - 1.0*blur*hstep, tc.y)) * 0.1945945946;
     sum += texture2D(sampler, vec2(tc.x, tc.y)) * 0.2270270270;
     sum += texture2D(sampler, vec2(tc.x + 1.0*blur*hstep, tc.y)) * 0.1945945946;
     sum += texture2D(sampler, vec2(tc.x + 2.0*blur*hstep, tc.y)) * 0.1216216216; 
     sum += texture2D(sampler, vec2(tc.x + 3.0*blur*hstep, tc.y)) * 0.0540540541;
     sum += texture2D(sampler, vec2(tc.x + 4.0*blur*hstep, tc.y)) * 0.0162162162;
     */

        vec4 vColor = texture2D(sampler, tex_coords); 
        vec4 bluredTexture = vColor * vec4(sum.rgb, 1.0);
	return bluredTexture;
}

void main() {
	gl_FragColor = funcBlurTexture();
}


How to apply this code in my shader?

for(horizontalOffset = -radius; horizontalOffset<radius; horizontalOffset  += step) {
    for(verticalOffset = -radius; verticalOffset<radius; verticalOffset += step) {
        sum += texture2D(texture, textureCoordinate+vec2(horizontalOffset, verticalOffset))*gaussFactorForOffset(sqrt(horizontalOffset*horizontalOffset + verticalOffset*verticalOffset)/radius);
    }
}


Any Help?