Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9219717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:10:47+00:00 2026-06-18T03:10:47+00:00

I currently have implemented a gaussian blur shader in Opengl using C++. The gaussian

  • 0

I currently have implemented a gaussian blur shader in Opengl using C++. The gaussian blur works. However the results seems to be a bit displaced compared to the original image. The resulting blur image seems to be placed some what higher and placed some what to the left. And not centered on the same place as the original.

The gaussian blur which I am using is a two pass calculation.
I based the gaussian calculation on demo code which I found on the web.

The gaussian kernel calculation looks like this:

    for(i = 0; i <= center; ++i)
    {
        result            = exp(-(i*i)/(double)(2*_sigma*_sigma));
        _kernel[center+i]  = _kernel[center-i] = (float)result;
        sum              += (float)result;
        if(i != 0) sum   += (float)result;

    }

    // normalize kernel
    for(i = 0; i <= center; ++i)
    {
        _kernel[center+i] = _kernel[center-i] /= sum;
    }

The offset calculation looks like this:

_offsets        = new float [_kernelSize * 2 + 1];
_offsetSize     = _kernelSize * 2 + 1;

float xInc      = 0;

if(_shaderType == S2DGaussianComponentBlurShaderHorizontal)
{
    xInc        = 1.0f / (float)_width;
}
else
{
    xInc        = 1.0f / (float)_height;
}

int   index     = 0;
for (int i = -_kernelSize; i < _kernelSize + 1; ++i)
{
    index            = i + _kernelSize;
    _offsets [index] = i * xInc;
}

The frag shader looks like this:

#version 120   \n                               \
uniform sampler2D texture;                      \
varying vec4 texcoord;                          \
                                                \
                                                \
uniform int kernelSize;                         \
uniform float weight[50];                       \
uniform float offsets[50];                      \
void main(void)                                 \
{                                               \
vec2 uv  = texcoord.xy;                         \
vec4 sum = vec4(0.0);                           \
for (int i = 0; i< kernelSize; i++)             \
{                                               \
vec4 tmp       = texture2D( texture,  uv + vec2(0.0, offsets[i]) ); \
sum           += tmp * weight[i];               \
}                                               \
                                                \
gl_FragColor = sum;                             \
}"

The texture input are using these:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);

Any thoughts what might be wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:10:48+00:00Added an answer on June 18, 2026 at 3:10 am

    I figured it out.

    It seems that the ‘_offsets’ must be the same size as the kernel. The main reason for this is that the center position of the offsets must be at the same position as the center position of the kernel. If you don’t do this, then the gaussian will not be aligned properly with the texture.

    One way of doing this is to make the ‘_offsets’ the same size as the kernel.

    I have been looking for this solution for days -_-‘

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently building a PHP application using the MVC pattern. I have implemented
I currently have healthmonitoring implemented for a public facing website. I am using the
I currently have implemented an overlay item that shows an icon for Geo-point on
Currently I have implemented a Javascript Ajax search where if user types a city
Backgroup: We are looking at SAS BI Dashboard. We have currently implemented almost all
I have implemented a table view with multiple threads. Currently when a user taps
I have implemented a UISearchDisplayController that allows users to search a table. Currently the
I am currently writing a Java compiler and have implemented section 15.12.2.7. of the
I currently have implemented an ImageSwitcher in my app, which slides through an array
Building an Android application using Google's GCM service. I have implemented the onRegistered method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.