0

NOTE: I say glistening to not be confused with bloom, glow or emissive, which are well defined blending techniques.

I have emulated 2D lighting by simply blending an offscreen image over the final image. What I get is actually what should be expected, and it looks correct:

enter image description here

But I want to blending that looks as in Halfway (this is a snippet of a screenshot):

enter image description here

How can I achieve that hazy blooming glow effect with just blending?

This is what I've tried so far:

Light quads are rendered to an offscreen image with these blending settings:

srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
colorBlendOp = VK_BLEND_OP_ADD;
srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
alphaBlendOp = VK_BLEND_OP_ADD;

If it's relevant, the offscreen buffer has the same format as the final image, which is on this dev machine VK_FORMAT_R8G8B8A8_SRGB (but it may change on other client machines).

The offscreen image is then overlayed on the final image with this shader:

outColor = inAmbientLight + texture(lightImageSampler, inUV);

The pipeline for this step has following blending settings:

srcColorBlendFactor = VK_BLEND_FACTOR_DST_COLOR;
dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
colorBlendOp = VK_BLEND_OP_ADD;
srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
alphaBlendOp = VK_BLEND_OP_ADD;

Also, I wonder, are if() and discard still very expensive in shaders? I've seen some hardlight shaders which use if(). I'd rather avoid these.

I've also tried to use the VK_BLEND_OP_HARDLIGHT_EXT, but I can't make the VK_EXT_blend_operation_advanced extension work. Is this maybe the right way to go?

Also, do I maybe need HDR (or 16 bit color channels)? Note that I don't want to use a bloom/glow shader. The result should be achievable by simply "emulating" blur through simple blending, but with "overexposure", as if the final overlay would "overdrive" colors beyond the 0-255 range and thus boost into white glistening lights.

I'm okay with pointers to a tutorial or just terms to search, I don't expect others to solve my problems. I just need a nudge in the right direction! Thanks for every bit of help!

Corrections such as better title or tags are also welcome.

pid
  • 10,769
  • 5
  • 33
  • 57
  • You might want to limit your question to one question. I don't think you can achieve it with only blending; that would require you to have something in the source. Maybe then show what you have in the buffers and the result and how it differs from what you want. From top of my head, maybe rendering the lights offscreen, growing the result, then bluring it, and overlaying the effect on the scene might result in similar effect... – krOoze May 27 '21 at 21:43
  • [discard and if()](https://stackoverflow.com/questions/37827216/do-conditional-statements-slow-down-shaders) aren't slow if whole warp takes one path, or for discard if you don't have depth tests. I don't exactly understand what images are used where (there is texture, lights and final image, rigt?). Also why can't you do lighting calculations in the last shader, if the blending you use just overwrites last value anyway? – user369070 May 28 '21 at 13:50

0 Answers0