# HLSL Vignetting [SOLVED]

This topic is 2106 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi guys!

So lately I've been messing around with some post processing effects, and came across the Vignetting effect, which makes the user focus in the middle, giving this cinematic effect. But, it's not working properly.

The result: (The corners are fine, but as I'm approaching the middle, it goes horribly wrong)

The shader itself is rather simple:

struct VS_Output
{
float4 Pos : SV_POSITION;
float2 Tex : TEXCOORD0;
};

{
VS_Output Output;
Output.Tex = float2((id << 1) & 2, id & 2);
Output.Pos = float4(Output.Tex * float2(2,-2) + float2(-1,1), 0, 1);

return Output;
}

{
float4 color = float4(0, 0, 0, 1);
float2 dist = input.Tex - 0.5f;
dist.x = 1 - dot(dist, dist);
color.a *= 1.0f - saturate(pow(dist.x, 5.5f));
return color;
}


PS. I hope I have given enough information to approach the issue.

Now what on earth have I done wrong?

-MIGI0027

##### Share on other sites

Try using input.Tex * 2.0 - 1.0 instead of input.Tex - 0.5. ATM you're using a [-0.5, 0.5] range, you should be using [-1,1]. At least that's what I've always done for vignetting and it works, so maybe it'll help. :)

Edited by Styves

##### Share on other sites

Not that a problem, it just gives a different radius/scale for the fade out. Shader works fine actually (tried it with a white background, also using the full screen triangle VS) so I guess there's a different problem. There's a warning for the pow argument which can be eliminated by abs or saturate the argument, but it's not really an issue the argument never goes below zero.

I assume you want alpha blending. How does your blend state look ?

##### Share on other sites

Using input.Tex * 2.0f - 1.0f.

So something else (and maybe that was a step closer to the solution) must be wrong. But thanks!

My Blend State:

post.RenderTarget[0].BlendEnable = true;
post.RenderTarget[0].SrcBlend       = D3D11_BLEND_SRC_ALPHA;
post.RenderTarget[0].DestBlend      = D3D11_BLEND_INV_SRC_ALPHA;
post.RenderTarget[0].SrcBlendAlpha  = D3D11_BLEND_ONE;
post.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;


-MIGI0027

##### Share on other sites

Now the pow argument goes subzero

Hmmm, my blend state isn't that much different, and even using your setting doesn't create such an artifact.

Oh wait. AlphaToCoverage does that (never used it). You must have it enabled currently.

Ah, of course. At alpha < 0.5 the pixel gets discarded completely. That's why.

Edited by unbird

##### Share on other sites

Yeah, I figured it would just change the size of the vignette but I wanted to be safe so I suggested it. Looks like it helped. :D

##### Share on other sites

Alright, I'll try it tomorrow, thanks guys!

##### Share on other sites

Alright, got it fixed thanks to you guys!

PS. The issue was the AlphaToCoverage being set to true.

Thanks!

-MIGI0027

• 9
• 17
• 10
• 11
• 18