Swapping a fragment shader

Komat,

I followed your suggestion but the texture isn’t changed at all:

Here is my fragment shader…

// image to be convolved
uniform sampler2D BaseImage;

void main()
{

    vec4 tmp = texture2D(BaseImage, gl_TexCoord[0].st);

 //   gl_FragColor = vec4(tmp.x/2, tmp.y, tmp.z, 1);
   gl_FragColor = vec4(0.8, 0.0, 0.0, 1.0);

}

…and my OpenGL code:

uint fb = glGenFramebuffersEXT();

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

glBindTexture(GL_TEXTURE_2D, shadowTextureName);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, shadowTextureSize, shadowTextureSize, 0,
              GL_BGRA, GL_UNSIGNED_BYTE, null);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
                           gl.COLOR_ATTACHMENT0_EXT,
                           GL_TEXTURE_2D, shadowTextureName, 0);




glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

DrawShadow();


// till here everything fine, the code below doesn't change the texture

if (myProgram > 0)
{
    
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, shadowTextureName);
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, blurredTextureName, 0);
   
    glUseProgram(Viewport.myProgram);

    glUniform1i(gl.GetUniformLocation(Viewport.myProgram, "BaseImage"), 0);

    DrawShadow();

    gl.UseProgram(0);
}

It is enough. Where I said anything about rendering everything twice?

Which texture did not change? The blurredTextureName? The shadowTextureName will be not changed. If the blurredTextureName did not change, check if there is any OpenGL error reported. Also check that you are correctly drawing the bluring quad.

Hi Komat,

Looks like I cannot get the original texture colors.

Here is the fragment shader code. If I uncomment the last line I see red quads on the blurred texture, otherwise it is unchanged. I also double checked all the uniforms via GetUnioformiv/fv and everything looks fine. What is the problem in your opinion?

Thanks!!!

Alberto

// maximum size supported by this shader
const int MaxKernelSize = 25; 

// size of kernel (width * height) for this execution
uniform int KernelSize;

// array of offsets for accessing the base image
uniform vec2 Offset[MaxKernelSize];

// value for each location in the convolution kernel
uniform vec4 KernelValue[MaxKernelSize];

// image to be convolved
uniform sampler2D BaseImage;

void main()
{

    vec4 tmp = texture2D(BaseImage, gl_TexCoord[0].st);

    gl_FragColor = tmp;
    // gl_FragColor = vec4(0.8, 0.0, 0.0, 1.0);

}

and the OpenGL Code is:

gl.ActiveTexture(GL_TEXTURE0);
gl.BindTexture(GL_TEXTURE_2D, shadowTextureName);
gl.FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, blurredTextureName, 0);
        
gl.UseProgram(myProgram);

int loc1 = gl.GetUniformLocation(myProgram, "BaseImage");
int loc2 = gl.GetUniformLocation(myProgram, "KernelSize");
int loc3 = gl.GetUniformLocation(myProgram, "Offset");
int loc4 = gl.GetUniformLocation(myProgram, "KernelValue");

gl.Uniform1i(loc1, 0);

DrawShadow(entList, globalMin, modelWidth, modelDepth);

gl.UseProgram(0);

What exactly does the DrawShadow function? It should draw a single quad with proper texture coordinates.

Komat,

You are most special teacher on earth for me.

Without your help we never get this shader to work.

Now it is only a matter of passing correct parameters.

When you come to Italy, you have a Pizza and Beer payed, bet on it!

Thanks so much again,

Alberto

What do you mean by “it is unchanged”? I mean, with the actual shader, you should see in the texture blurredTextureName the same thing as in the texture shadowTextureName.

What do you see exactly in the blurredTextureName texture with the current fragment shader?

dletozeun,

Thanks for your help but I solved drawing a quad with relevant texture coordinates.

Now I have a new problem :frowning:

http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=242817#Post242817

Thanks,

Alberto

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.