Writing the Blend-Color in the fragment shader

As suggested, i re-post this thread in this forum.

OpenGL does have an extra blend-color, which can be used in the blend-function with GL_CONSTANT_COLOR (especially GL_CONSTANT_ALPHA). What i like about this is, that i can thus use my alpha-channel for other data, and still get blending with some blend-factor. I don’t waste the alpha-channel to write a value, that i will never ever use again.

The problem however is, that the color is indeed fixed. When i use the alpha-channel, i can modulate the blend-factor with textures etc., but when using the constant blend color, it is all the same over the entire rendered object.

Since we seem not to get the blend-shader any time soon, i would at least like to see this addition: Allow to write the blend-color in the fragment shader. It would actually only be a temporary factor for this particular fragment and will be discarded afterwards. If the FS does not write the value, use the value, that was set in the application.

Of course one would need to be able to write different values for each render-target (since the blend-function can be different for each RT on modern hardware).

This would allow to do proper blending with different factors per fragment, and use the alpha-channel for something completely different.

Jan.

Sound like a great idea which could even same quite come memory band wise!

I’d like to see something similar to DX11’s unordered resource views, which expose something similar in the form of generic R/W texture and buffer access from within fragment (& compute) shaders.

What could be cooler?

DX10 has something similar. It’s called Dual Source Color Blending and allows to output two RGBA values from a pixel shader and use them in the blend-function. There is a limitation that no more than one rendertarget can be bound.

AFAIK dual source color blending got dropped in DX 10.1 or DX 11