Sign in to follow this  
Waaayoff

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

Recommended Posts

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

Edited by Waaayoff

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this