View Full Version : Blending Options
07-04-2004, 09:17 AM
Hey. I'm trying to do some lighting effects and basically I was wondering if there is a way where you can use blending and it will show up blended if the quad is within a certain distance of the destination, but if the source is too far from the dest then it won't show up at all. I know that sounds kind of vague so I'll try to explain it better. Like if you have a wall and you draw a quad .1 infront of the wall, with the same normal as the wall, it will blend the source quad and show up, but if you then drew that quad 1.0 away from the wall it would just be completely transparent because it's too far from the dest. Is that at all possible? If not what's an alternative to that? Thanks.
07-04-2004, 09:41 AM
That works for most cases, yeah. But the real problem is if half of the source quad is infront of the wall and the other half is in front of a wall further away. In that case I would only want the half in front of the close wall to show up, that's pretty much what I'm faced with. But thanks for the input there, that would work based on what I said before, I just have this problem to work with as well.
07-04-2004, 09:41 AM
as the object is farther away it is more opaque? Well. Have the translate distance as a variable. depending on where you translate from changes how you handle this. If you are going farther from the wall in your translation, then as the bigger the variable(say 1.0) then make that variable the alpha value
glRectf(/*points x1,y1,x2,y2*/);this will work until one distance away, after that the alpha value is clamped to 1.0, no biggie still works the way you want(fully opaque). and the opposite is true. If it is negative it will be clamped to 0. Does this help you?
07-04-2004, 09:42 AM
I just read what you wrote above my code I just wrote. So the wall and the quad are not parralell? If so, is the wall translucent at all? If it is, then I would suggest a clip plane. I don't know how to make certain areas of primitives certain opacities, only a whole one.
07-04-2004, 10:05 AM
Here's a picture of what I'm trying to do.
The wall with the red dot if the front one and see how the red dot cuts off as soon as it's not toucing the wall anymore, yet there's still another wall behind it. With your method, unless I'm mistaken, there would still be a somewhat transparent part showing up on the other wall because it extends past the first quad's edges and turning the quad transparent wouldn't allow it to show up on the first wall. I hope that helps clearify what I'm trying to do. Thanks.
07-04-2004, 12:20 PM
I am not familiar with fragment programs or shading language stuff, but it sounds like something that could handle this.
basically you would need the "difference" depth value ie depth buffer value of pixel before you draw it and afterwards.
if you use a single quad you would always have the problem of not being able to set the alpha properly or inaccurately, you could tessalate it but not really a pixel accurate solution
another hack would be changing order of how things are rendered and not allow the blended thing write into depth buffer, but that would basically be an "on/off" effect.
hopefully some shading guru will find his way in here
07-04-2004, 03:02 PM
This is indeed relatively easy to implement using a fragment program.
First make sure your graphics card supports the GL_ARB_fragment_program extension.
The fragment program itself would be something like this:
First copy the color and depth buffer to textures 0 and 1 respectively using coptexsubimage.
const char fp =
//read previous color
"TEX R0, fragment.texcoord, texture, 2D;\n"
//read previous depth
"TEX R1, fragment.texcoord, texture, 2D;\n"
//subtract depth of the incoming fragment from the previous depth
//multiply by a user specified factor and saturate to the range [0,1]
//perform a linear interpolation of the previous color with the color of the incoming fragment based on the valu stored in R1
"END";You can set the user specified value for the fragment program width glLocalParameter4d(...)
You will also have to set the texgen so that the correct pixels are adressed. It's easiest to use a texture_rectangle, then you can skip the texgen and replace the first 2 lines of the fragment program to
"TEX R0, fragment.position, texture, RECT;\n"
"TEX R1, fragment.position, texture, RECT;\n"The specification of this extension can be found at http://oss.sgi.com/projects/ogl-sample/registry/ARB/fragment_program.txt
It's possible that I made some mistakes in the code above, but I'm rather tired at the moment :)
Just thought I might put you on the right track with this.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.