Advertisement

/Weirdness regarding Z-buffer/Pixel shader

Started by June 24, 2018 10:14 PM
3 comments, last by Toastmastern 6 years, 7 months ago

Hello everyone,

I'm looking for some advice since I have some issues with my textures for my mouse pointer and I'm not sure where to start to look. I have checked everything that I know off and now I'm in need of advice on what to look for in my code when I try to fix it.

I have a planet that is rendered, I have a UI that is rendered and I also have a mouse pointer that is rendered. First the planet is rendered, then the UI and then the mouse pointer last. When the planet is done rendering I turn off Z-Buffer and enable Alpha Blending while I render the UI and the Mouse Pointer. In the Mouse Pointers Pixel Shader I look for black color and if that is the case I blend it. But what seems to happen is that it also blends part of the texture that isn't supose to be blended. I'm going to provide some screenshot of the effect. In the first image you can see that the mouse pointer changes color to a more white one when behing infront of the planet. The correct color is the one that is displayed when it's not infron of the planet.

The second thing I find weird is that the mouse pointer is behind the ui text even tho it is rendered after. I also tried switching them around and it makes no difference. Also the UI doesn't have the same issues when being above the planet, it's color is displayed as it should.

Here comes the Pixel Shader code if that helps anyone get a better grip of the issue:


	float4 color;

	color = shaderTexture.Sample(sampleType, input.tex);

	if(color.b == 0.0f && color.r == 0.0f && color.g == 0.0f)
	{
		color.a = 0.0f;
	}
	else
	{
		color.a = 1.0f;
	}

	return color;

The UI uses almost the same code, but only checks the r channel of the color but I'm using all 3 channels in the Mouse Pointer due to colors might be abit more off. Should be that if the pixel is black it's should be blended. And it does work, but it's just that somehow it also does something with the parts that shouldn't be blended. Right now I'm leaning towards there being something in the Pixel Shader since I can set all pixels to white and it behaves as it should and creates a white box for me.

Any pointers of what kind of issues I'm looking at here and what to search for to find a solution will be appreciated alot

Best Regards and Thanks in Advance

Toastmastern

 

MousePointerIssueImage1.png

MousePointerIssueImage2.png

The way you are checking the RGB channels in your pixel shader seems odd to me. Can't you just upload an alpha channel with your cursor texture, for example, and just pass that alpha along when you sample your texture?

Advertisement
25 minutes ago, mellinoe said:

The way you are checking the RGB channels in your pixel shader seems odd to me. Can't you just upload an alpha channel with your cursor texture, for example, and just pass that alpha along when you sample your texture?

I started off with that, and just to be sure I went back to that now and it has the same effect. Interesting enough if I change the color red to black instead in the image it doesn't appear at all on the screen even tho I commented away any kind of manipulation in the pixel shader.

This is how I get the texture into the application:


	hResult = CreateWICTextureFromFile(device, fileName, &mMousePointerResource, &mMousePointerResourceView);
	if (FAILED(hResult))
	{
		return false;
	}

//Toastmastern

I were able to solve it, The issue was with my blend state. This question got me in the right direction:
https://gamedev.stackexchange.com/questions/107866/directx11-alphablending-rendering-problem

My blend state code now looks like this:


	blendStateDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
	blendStateDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; 

Instead of:


	blendStateDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
	blendStateDesc.RenderTarget[0].DestBlend = D3D11_BLEND_ONE;

I believe it has to do with the .DestBlend only due to the way my pixelcolor is blended. But now it works anyway. Hope this thread can help anyone else in need :)

//Toastmastern

This topic is closed to new replies.

Advertisement