Search code examples
openglsignedblending

Signed additive blending in Opengl


I'm trying to port some code from DX9 to Opengl, and it uses a signed additive blend operation

pd3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADDSIGNED);

Is there a way to do this with opengl glBlendFunc?

I have something workable by splitting the texture into additive and subtractive textures, and drawing them in 2 passes (additive, then subtractive). Luckily I can batch the adds and subtracts without too much range clipping (adds hitting 1.0 or subtracts hitting 0.0) so it's a workable solution if I can't find a simple blendfunction that can work signed...


Solution

  • OpenGL GL_FUNC_ADD can already subtract, it's only the matter of what's the output of the shader. You may want to look at the GL_RGBA8_SNORM if you want to store negative and positive values inside the same 8-bit texture.