Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Waaayoff   Members   -  Reputation: 781

Like
0Likes
Like

Posted 28 June 2013 - 11:42 AM

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, 28 June 2013 - 11:44 AM.

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

Sponsor:

#2 kauna   Crossbones+   -  Reputation: 2745

Like
1Likes
Like

Posted 28 June 2013 - 01:41 PM

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!



#3 Kjell Andersson   Members   -  Reputation: 420

Like
1Likes
Like

Posted 28 June 2013 - 05:48 PM

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



#4 Waaayoff   Members   -  Reputation: 781

Like
0Likes
Like

Posted 29 June 2013 - 03:38 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS