Per-pixel blending in Cg and OpenGL
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.
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. :)
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 ;)
P.S. if anyone has another (free) solution I could still use it of course ;)
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.
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.
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.
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;
There are 2 possible tesselations of your quad:
Your problem is that the results look different in each of these cases? Can you post a screenshot?
There are 2 possible tesselations of your quad:
|----||\ || \ || \ || \|------and |----|| /|| / || / ||/ |------
Your problem is that the results look different in each of these cases? Can you post a screenshot?
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 :)
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.
Quote:Original post by dbzprogrammer
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.
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 :(
oops Kincaid = subotron :)
Edit: Screenie:
[Edited by - Kincaid on October 24, 2005 4:03:44 PM]
Edit: Screenie:
[Edited by - Kincaid on October 24, 2005 4:03:44 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement