Jump to content

  • Log In with Google      Sign In   
  • Create Account


GL_ONE_MINUS_SRC_COLOR using GLSL


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
3 replies to this topic

#1 AlricDoRei   Members   -  Reputation: 147

Like
0Likes
Like

Posted 30 October 2012 - 03:45 AM

Here is my code:

glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, myTexture);
  glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
  glEnable(GL_BLEND);
  glColor3f(1.0f, 1.0f, 1.0f);
  glBegin(GL_QUADS);
   glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
   glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f, 0.0f);
   glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, 1.0f);
   glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 1.0f);
  glEnd();
  glDisable(GL_BLEND);
  glBindTexture(GL_TEXTURE_2D, 0);
  glDisable(GL_TEXTURE_2D);

How to emulate these lines using glsl?
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
  glEnable(GL_BLEND);

Here is my shader program:

vertex shader
void main(void)
{
		gl_TexCoord[0] = gl_Vertex;
		gl_Position = gl_Vertex * 2.0 - 1.0;
}

fragment shader:
uniform sampler2D Texture;
void main()
{
		vec3 Color  = texture2D(Texture, gl_TexCoord[0].st).rgb;
		gl_FragColor = vec4(Color, 1.0);
}

Edited by AlricDoRei, 30 October 2012 - 03:46 AM.


Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 7784

Like
0Likes
Like

Posted 30 October 2012 - 04:00 AM

Unless it has changed in a very recent version, you cannot do blending in the shaders. The blending has to be done using the blending functions.

#3 joew   Crossbones+   -  Reputation: 3555

Like
0Likes
Like

Posted 30 October 2012 - 12:13 PM

Unless it has changed in a very recent version, you cannot do blending in the shaders. The blending has to be done using the blending functions.

The only platform I know of right now that supports programmable blending with extensions is iOS using APPLE_shader_framebuffer_fetch and it was just recently added with the latest version of the OS 6.0. The shader receives the built-in variable gl_LastFragData which is read-only but allows you to use it when rendering to the framebuffer.

#4 powly k   Members   -  Reputation: 632

Like
0Likes
Like

Posted 30 October 2012 - 02:38 PM

You can render all the things you want into textures with an FBO and blend them in the pixel shader, if you want exact control over what's going on. This won't work for more than a few things, though, so if you want to do lots of blending, just use the glblendfunc(separate) and glblendequation functions. You can't do everything with them, but even GPUs can't do everything :)




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