How to sample a texture with 8 bit channel in shader?

Started by
2 comments, last by Waaayoff 10 years, 9 months ago

I want a texture with 4 8bit channels so i define it as DXGI_FORMAT_R8G8B8A8_UINT. Is this the correct format i should be using? And how do i sample it in a shader because what i'm doing is not working:

float3 tID = Alphamap.Sample(Sampler, input.uv).rgb;

I'm assuming it's because floats are 32 bit, but i couldn't find an HLSL scalar type that's 8 bit...

"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "
Advertisement

Your code is absolutely correct. The sampling hardware converts the 4 * 8-bit texture into 4 * 32-bit float (or what is the float precision hardware is using).

However, the texture format DXGI_FORMAT_R8G8B8A8_UINT isn't correct. the ending should be _UNORM.

Cheers!

Worth noting is that the 8-bit RGBA values can be normalized (i.e. 0 to 255 => 0.0 to 1.0) when presented to the shader by the sampler for different format modifiers.

See the formatting table at the bottom of this page: http://msdn.microsoft.com/en-us/library/windows/desktop/bb173059%28v=vs.85%29.aspx

Changing the format to UNORM fixed it, thanks!

"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "

This topic is closed to new replies.

Advertisement