HLSL Vignetting [SOLVED]

Started by
6 comments, last by Migi0027 10 years, 6 months ago

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

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

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. :)

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 ?

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

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

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.

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

Alright, I'll try it tomorrow, thanks guys! smile.png

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Alright, got it fixed thanks to you guys!

2rz5a8i.png

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

Thanks!

-MIGI0027

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

This topic is closed to new replies.

Advertisement