Dear GLSL programmers,
I am trying to develop effects like sharpening,blurring and Edge detection using GLSL In some cases, I am getting result (but not desired one) and in some other case no output Image is displayed(black screen is getting displayed ). The following is my code.Please advice.
uniform sampler2D tex1;
const float step_w = 1/width;
const float step_h = 1/height;
vec2 offset[9] = {vec2(-step_w,-step_h),vec2(0.0,-step_h),vec2(step_w,-step_h),vec2(-step_w,0.0),vec2(0.0,0.0),vec2(step_w,0.0),vec2(-step_w,step_h),vec2(0.0,step_h),vec2(step_w,step_h)};
//First kernel - This is for gaussian smoothing
//Image is getting displayed,but not smoothed
float kernel2[9] = {0.0,1.0,0.0,1.0,-4.0,1.0,0.0,1.0,0.0};
//Second Kernel - Nothing is getting displayed.
float kernel2[9] = {-1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,-1.0};
//Third kernel - For Detecting Edge
//Edges are not properly displayed
float kernel2[9] = {-1.0,-1.0,-1.0,0.0,0.0,0.0,1.0,1.0,1.0};
//Shader code
void main()
{
int i=0;
vec4 vsum;
for(i=0;i<9;i++)
{
vec4 tmp = texture2D(tex1,gl_TexCoord[0].st,+ offset[i]);
vsum += tmp.rgba * kernel2[i];
ksum += kernel2[i];
}
if(ksum < 0)
ksum = 1.0;
vec4 vavg = vsum/ksum;
gl_FragColor = vavg;
}
In the application code, I am using tga loader to load images.
Please advice
RAJESH.R