I know this question has been answered many times but the answer is an 2D matrix which I don't know how to use.
I want an 1D array of weight's which I can sample in my fragment shader. I have divided my gaussian blur into Horizontal & Vertical Blur Shader's and now I wan't an 1D array of gaussian kernel weight's to sample at each step but the previous answer's state's an 2D matrix which gives incorrect result's when sampled at each blur shader[Entire Scene becomes whited out]
This is my vertex shader code
# version 430 core
in vec3 vertex;
uniform int fboWidth; /*FrameBuffer Width(Texture Width)*/
uniform int fboHeight; /*FrameBuffer Height(Texture Height)*/
uniform int mode; /*Blur Mode(0=Horizontal,1=Vertical)*/
in vec2 texCoord; /*Texture Coordinates of full screen quad*/
out vec2 vertexTexCoords[11];/*Outgoing neighbour texels to be sampled*/
void main()
{
gl_Position=vec4(vertex,1.0);
vec2 realTexCoord=vec2(texCoord.x,1.0f-texCoord.y);
if(mode==0)
{
vec2 offset=vec2(1.0f/fboWidth,0);
for(int i=-5;i<=5;i++){vertexTexCoords[i+5]=realTexCoord+(offset*i);}
}
else if(mode==1)
{
vec2 offset=vec2(0,1.0f/fboHeight);
for(int i=-5;i<=5;i++){vertexTexCoords[i+5]=realTexCoord+(offset*i);}
}
}
This is my fragment shader code
# version 430 core
in vec2 vertexTexCoords[11];
uniform sampler2D texture; /*Brightest part's of my scene*/
uniform float gaussianWeights[11];/*The weight's I wish to calculate(but don't know how)
out vec4 pixelColor;
void main()
{
vec4 finalColor=vec4(0.0);
for(int i=0;i<11;i++){finalColor+=texture(texture,vertexTexCoords[i])*gaussianWeights[i];}
pixelColor=finalColor;
}
What I do is render my scene to an texture and use an full screen quad to sample that texture and blur out it's brightest part's
In the fragment shader
uniform float gaussianWeights[11];
is the expected kernel weights I want to calculate for an kernel of Width=5 and Height=5 but don't know how.
So far I am using the weight's calculated by the online gaussian kernel calculator but don't understand it's code written in java script.
An java function that can calculate these kernel weights for any kernel size would be appreciated.
Thank u