HLSL: problematic pixel pixel code (alpha at zero sampling)?

I have this weird problem with a sampler in pixel shaders. When I take a sample from a sampler into an empty variable float4, I always get a black / transparent color. Therefore, if I use this, I get a black screen:

float4 PixelShaderFunction(float2 TextureCoordinate : TEXCOORD0) : COLOR0 { float2 uv = TextureCoordinate; float4 pixelColor = tex2D(implicitInputSampler, uv); //contrast pixelColor.rgb = ((pixelColor.rgb - 0.5f) * max(Contrast, 0)) + 0.5f; //brightness pixelColor.rgb = pixelColor.rgb + (Brightness - 1); // return final pixel color return pixelColor; } 

I use this, but it works fine:

 float4 PixelShaderFunction(float2 TextureCoordinate : TEXCOORD0) : COLOR0 { float2 uv = TextureCoordinate; float4 pixelColor = {0,0,0,1}; pixelColor += tex2D(implicitInputSampler, uv); //contrast pixelColor.rgb = ((pixelColor.rgb - 0.5f) * max(Contrast, 0)) + 0.5f; //brightness pixelColor.rgb = pixelColor.rgb + (Brightness - 1); // return final pixel color return pixelColor; } 

This only happens in my dev environment at home on the AMD 4850 GPU. When I try to use some nVidias or AMD5850, it works anyway ...

What is the reason for this? Am I missing some initialization of the device?

Hooray!

+4
source share
2 answers

It seems that A in the texture of the pixel shader source is really 0 ...

The texture is declared as A8R8G8B8 and device.StretchRectangle is used to fill the texture.

This method works differently depending on the hardware: /

+2
source

I would be interested to know if there is a 32 bit texture. Mostly because I ran into AMD issues against Nvidia. In fact, what would be a non-functional shader in one case would be fully functional in another (AMD worked, NVIDIA didnt) just because I had an offset in my vertex buffer declaration with 1 byte ... but I'm distracted, my question that each driver can take liberties when interpreting the alpha component if it is not declared or does not match the true 32-bit texture. Does the same thing happen if you use a different texture? Is your alpha channel set to opaque (1.0f)?

They became interested in seeing that I used to have old differences in AMD / NVIDIA drivers. What works in one may be a bug in another driver.

0
source

Source: https://habr.com/ru/post/1346434/


All Articles