Jump to content

  • Log In with Google      Sign In   
  • Create Account

[GLSL] How to invert texture RGB components?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 ak09   Members   -  Reputation: 131

Like
0Likes
Like

Posted 08 May 2013 - 12:23 PM

 I found that a simple fragment shader for that would be something like:
 

 

uniform sampler2D Mtexture;

void main()
{
    vec4 color = texture2D(Mtexture, gl_TexCoord[0].st);
    gl_FragColor = vec4(1.0 - color.r, 1.0 - color.g, 1.0 - color.b, color.a);
}


And the OGL code:
 

    glUseProgram(prog);
    glBindFramebuffer(GL_FRAMEBUFFER, fbo);

    glColor4f(1, 1, 1, 1);
    glBindTexture(GL_TEXTURE_2D, tex);

    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 1.0f);  glVertex2i(0,0);    
    glTexCoord2f(1.0f, 1.0f);  glVertex2i(width,0);  
    glTexCoord2f(1.0f, 0.0f);  glVertex2i(width,height);  
    glTexCoord2f(0.0f, 0.0f);  glVertex2i(0,height);
    glEnd();

    glBindTexture(GL_TEXTURE_2D, 0);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glUseProgram(0);

However, it's not giving me the expected results, and this is driving me crazy.
Should I disable GL_BLEND before applying the filter? Case not, which function to use?
Should I clear my texture before using a shader on it? <-- Never understood this



Sponsor:

#2 hdxpete   Members   -  Reputation: 491

Like
0Likes
Like

Posted 08 May 2013 - 07:00 PM

your mixing old school and new school. i've never done that so i don't know how the driver will react. but where is your vertex shader? what results are you getting? if you comment out the color invert and just return the texture color do you the texture as expected? more info is needed bro.



#3 Kaptein   Prime Members   -  Reputation: 2180

Like
0Likes
Like

Posted 09 May 2013 - 04:13 AM

mixing old and new works just fine anywhere, but there's certain restrictions, like you're stuck with the old VAO format
but, i'm guessing you are writing to the texture you're reading from
which if i was a driver maker would crash your computer, just to give you that good reason to read the manual :9

it's not allowed, because the gpu is a huge parallell thingie, and it can't guarantee the results

if you wanted to permanently change the components, you could do it many ways:
1. read texture data to memory and change them with code
2. write to new texture
3. just change the colors on the fly with a shader..

the last one is the easiest, and fastest, since vec4(vec3(1.0) - color.rgb, color.a) is not really slow...

Edited by Kaptein, 09 May 2013 - 05:30 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS