Jump to content
  • Advertisement
Sign in to follow this  
Migi0027

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.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys! happy.png

 

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)

 

sljuxi.png

 

The shader itself is rather simple:

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

VS_Output VShader(uint id : SV_VertexID)
{
	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 PShader(VS_Output input) : SV_TARGET
{
	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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
Share on other sites

Using input.Tex * 2.0f - 1.0f.

 

281zqlj.png

 

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].BlendOp        = D3D11_BLEND_OP_ADD;
post.RenderTarget[0].SrcBlendAlpha  = D3D11_BLEND_ONE;
post.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
post.RenderTarget[0].BlendOpAlpha   = D3D11_BLEND_OP_ADD;
post.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;

-MIGI0027

Share this post


Link to post
Share on other sites

Now the pow argument goes subzero tongue.png

 

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 this post


Link to post
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 this post


Link to post
Share on other sites

Alright, got it fixed thanks to you guys!

 

2rz5a8i.png

 

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

 

Thanks!

-MIGI0027

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!