You can achieve the effect you are looking for by setting the color value to non-pure red. In the picture below I have drawn a circle with additive blending multiple times with small offsets. On the left the color is pure red (255, 0, 0) and on the right it is (255, 20, 5). From these you can calculate that to get full yellow, you need 255/20=13 overlapping ...
With the introduction of programmable blending units, the intuitive meaning of alpha being a measure of opaqueness doesn't always hold.
In the two-operand blend you have two contributing fragments:
the source (what you're blending, the new fragment),
the destination (what already exists in the spot you're blending to).
You have two independent blending ...
In your first example (glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)), you're telling it to blend colors based on the alpha of the image which gets drawn on top (the "Foreground" one). So when you're blending 50% between the foreground color (38,50,168) and the background color (38,50,168) in the bottom left corner of the image, you unsurprisingly get ...
Missed mentioning that my intention is for clusters of point sprites with the same pigment (red) to additive blend to yellow and white.
That right there is indicative of your problem.
You cannot take a color value of (0.25, 0, 0), and add it to itself and get anything besides more red. It will not magically become yellow, then white. It will always be red, ...
Lets look at what your blend setup is actually doing:
This means that your colors are calculated by:
ScreenPixel = OldPixel + NewPixel * NewPixel.a
So expanding your blend sequence gives you:
color += texture1 * texture1.a;
color += ...
To build upon Sean's answer, you don't need to make a separate FBO in order to render the effect you're looking for. Unfortunately, you cannot do it in a single pass because you're asking for two different blending operations for the pixels depending on whether or not your orange triangle is overlapping the light blue one. Fortunately, this is an excellent ...
Turning Sam's comment into an answer, you need to do all your rending in two passes.
For your first pass, draw only the foreground objects into an off-screen buffer/FBO. If you're using multiplicative blending you might get your desired effect with a white background; with additive blending, you may want a black background. Remember to clear to and update ...
One way that this can be done is to divide your materials into layer slots. As one example, REDengine 3, powering the Witcher 3, uses a background layer and an overlay layer for its terrain materials.
You can store your material data in control map textures as in the case above, or in your vertex data. Either way, you end up storing the identity of the ...
OpenGL blend funcs are just a means of specifying a mathematical formula as follows:
src: the output from your fragment shader.
dst: the colour in the framebuffer.
sfactor: multiply src by this.
dfactor: multiply dst by this.
And add the two results together.
(As a simplifying assumption I'm ignoring blend equation, blend func separate and ...
Well, your glBlendFunc(GL_ONE, GL_ONE) is likely to blame.
The 1st argument to glBlendFunc is how much of the source (new pixel) to use. The 2nd arg is how much of the destination (pixel already there in the frame buffer) to use. You said to just add 100% of the source pixel with 100% of the destination pixel. That's probably not how you want to blend ...
Depending on the shader language/version you're using, you can use conditionals in your shader program to cover the 100% transparent case explicitly.
Alpha testing really seems like it should be like a distinct shader from alpha blending. It doesn't seem like you can use it with premultiplied alpha, since the equations for alpha testing involve a ...
One thing you should avoid for sure is to query the uniform locations every frame with glGetUniformLocation. This might be hurting the performance a little bit. Cache the locations in any data structure of your choice or plain variables once the shader program is created.
Also you've mentioned that for each light a fullscreen quad is drawn. This is likely ...
Have a look at Reoriented Normal Mapping, it will allow you to blend several normal maps on top of each other and give the intuitively expected result. The main idea is to transform the the normal to blend to the local space of the surface your blending on, or in this scenario, the normal mapped space of the surface.
On your first pass, you're additively blending your object into the stuff that's already in the render target. Since your object is presumably opaque, you want to make sure the stuff that's in the render target beneath your object is occluded. You could do this by setting your blend mode to glBlendFunc(GL_ONE, GL_ZERO) and rendering the object completely ...
It's a simple interpolation. Let's assume that your heights span -1 to 1, 0 is water surface and you have 3 colours: dark green, light green and white. A way to do what you want is to have the following color_from_height function in the pixel or fragment shader (depending on how efficient you want to be). In my shader below I visualize the gradient, but the ...
This article seems to imply that the most efficient method is the latter: multiply by alpha, then convert to SRGB.
As far as correctness, I realized that if your texture and framebuffer are SRGB, the GPU does SRGB conversion and then blends in linear space. Therefore if you are using SRGB textures and framebuffers, you should premultiply alpha in linear ...
What that means is that the GL implementation is pretty much free to do whatever it wants. It might change nothing, it might reset to the defaults, it might make a best guess, it might do something else entirely different, and which of these it chooses might depend on other state set elsewhere. Also, you can't depend on somebody else's ...
There is an inverse kinematic method for blending animation with physics, it basicly tries to keep the same position and rotation of bone structure of another animated object with the ragdoll, after physics applied to the ragdoll it updates the bones in the late update. Link is here: Active Ragdoll
But I found another way around for this problem its not ...
You can do this with 3ds Max.
Create a plane.
Subdivide it in to a lot of segments.
Select your heightmap.
Select Create -> Splines -> Section.
Create a bunch of these "sections"; one for every height.
Convert all your "sections" to "Editable Splines"
Select Create -> Compound Objects -> Terrain.
Fur further explanation, here is a YouTube ...
Modern hardware often lacks the ability to actually draw quads. If you're using a legacy API like OpenGL, the drivers will generally just emulate quad support by asking the hardware to draw two triangles.
With general edge smoothing, you'd get pretty much exactly what you're seeing. Of course, polygon smoothing itself is a legacy artifact of OpenGL's ...
After playing around with things, I've decided to use Blender's stencil map feature (which is a reduced sort of splat map). It allows me to blend between two tileable textures on the same surface using a third as a stencil without having to use huge textures.
I also had to write a custom shader in unity to have my stencil material display, but that wasn't ...
Although it may not be what you are looking for, I generated this to show how to use the stencil buffer to achieve what you want:
The "black-shader" could just return (0,0,0,1); but could also sample from a texture (animated gradient, etc.)
A couple days of googling, testing, coding and I have it all figured out.
1. Shadows on Sprites..
There is a work around to having sprites cast and receive shadows. This thread in the unity forum has a way to do it with sprites: http://forum.unity3d.com/threads/why-cant-sprites-gameobjects-cast-shadows.215461/
The other way is to create your own sprite ...
I think I understand what you are trying to do. You want the sum of all layers' alpha to be 1 so that there the total color is overdrawn.
You are on the right track. But your error seems in the way you compute the alphas.
Take for example this starting point:
Now you apply 0.5 on layer 3, the result should look something like:
Your own idea isn't that far off. However, you'll have to multiply the final color, not the light color alone:
final_light = (color1 * factor1 + color2 * factor2) / 2;
To elaborate a bit more, both factor1 and factor2 are based on the distance to the light sources, their range, etc. I just picked multiplication over division - in your example, you could ...
I think you may not entirely understand how destination blending works.
You claim that you set your output to (r*a, g*a, b*a, 0.0) and then use GL_ONE_MINUS_SRC_ALPHA for the destination blend factor. Because source alpha is constant (0.0) in this example, that works out to be equivalent to GL_ONE.
Likewise, if you apply GL_ONE, GL_ONE_MINUS_SRC_ALPHA in ...
Tuns out that this is not accurate, as it's for a different alpha blend type.
I'm going to give this one a shot, primarily since there aren't any answers for you yet. I'm not completely certain that my answer is accurate or complete, but it's going to be too big to supply as a comment, so here we go.
The biggest feature you need to preserve is the order-...
Check out this link(Archive.org mirror), it should work for you (massive terrain + blended textures). Has a huge demo project size since he uses a big static mesh, but he applies the textures using a shader as well so you can take a peek at his blending algorithm. He also managed to make it seamless with multiple meshes.