Jump to content
  • Advertisement
Sign in to follow this  
Subotron

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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;

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?

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
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 :(

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!