# OpenGL Per-pixel blending in Cg and OpenGL

This topic is 4627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Because I really can't stand the 'errors' in normal per-vertex blending done by opengl (if you blend a quad with one corner at a=0.0f, and the rest a=1.0f, it blends differently according to how the two triangles that make up the quad are drawn), I tried to write a per-pixel blending shader in Cg and OpenGL. It works, but all it does is replace normal blending, it doesn't fix my problem. Now I'm not exactly a shader wizard (yet :)), so I could really use some help on how to fix this blending problem using shaders. Who can point me in the right direction? Thanks in advance.

##### Share on other sites
I'm not quite a Cg expert myself, so the best I can do is reccomend this book called The Cg Tutorial. I have it and it is a good book for beginners. You can also look through the NVIDIA developer pages and find more info there. I hope this helps you. :)

##### Share on other sites
thanks a lot. I didn't find a lot of useful stuff in the nvidia pages, (first thing I check of course :)) but I'll have another look. The book seems good, so when I got my paycheck I'll probably buy it. Awwww shouldn't have bought that guitar a few weeks ago, then I wouldn't be stuck with programming now :p

P.S. if anyone has another (free) solution I could still use it of course ;)

##### Share on other sites
The easist solution is to not draw quads. Tesselate it yourself, then the results will be consistant.

That being said, I haven't read what the GL spec says about quads, so I don't know if this problem is a GL problem, or specific to your renderer.

##### Share on other sites
Thanks for the reply, but I'm not sure what you mean with 'tesselate it yourself'. I tried drawing other polygons than quads (GL_POLYGON, GL_TRIANGLE, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, etc. etc.) but all methods use triangles at some point.

##### Share on other sites
Just to make sure I understand the problem, lets say you are drawing a quad, the top left corner has a=0.0f, and the other 3 corners have a=1.0f;

|----||\   || \  ||  \ ||   \|------and |----||   /||  / || /  ||/   |------

Your problem is that the results look different in each of these cases? Can you post a screenshot?

##### Share on other sites
you got it exactly right. I cant really post a screenshot anytime soon, since I dont have internet on my pc, I log in at the university. Ill try to think of taking one on my usb stick :)

##### Share on other sites
I think your looking for a 2 pass system. One pass displays the first quad with it's alpha intensity and then in the second pass it displays the other with its alpha. Should blend just fine... Don't put your money on me, but I think that's what you want.

##### Share on other sites
Quote:
 Original post by dbzprogrammerI think your looking for a 2 pass system. One pass displays the first quad with it's alpha intensity and then in the second pass it displays the other with its alpha. Should blend just fine... Don't put your money on me, but I think that's what you want.

well, I tried that. But it didn't work out right, so either I did it wrong (highly unlikely :p) or it's not the solution :(

##### Share on other sites
oops Kincaid = subotron :)

Edit: Screenie:

[Edited by - Kincaid on October 24, 2005 4:03:44 PM]

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 13
• 9
• 12
• 9
• ### Forum Statistics

• Total Topics
631438
• Total Posts
3000073
×