Jump to content
  • Advertisement
Sign in to follow this  
InetRoadkill

CG (HLSL) comparing colors

This topic is 3882 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to do something similar to color keying using a fragment shader. I'm having trouble comparing two color values to see if they are equal. The problem seems to be from the fact that color values are converted from ubytes to floats. Is there a way to do this?

Share this post


Link to post
Share on other sites
Advertisement
Converting between a normalized ubyte and a float is easy: just divide or multiply by 255. However as with all floating point math, things aren't going to be exact so you may want to check for a range of numbers as opposed to a straight test for equality.

Share this post


Link to post
Share on other sites
It's the conversion that's the problem. The comparison needs to be exact because the fragment is looking for poly id numbers which are encoded into the color.

It's actually amazing that there is a no unsigned integer math available considering the colors are encoded and stored using them.

Share this post


Link to post
Share on other sites
Quote:
Original post by InetRoadkill
It's the conversion that's the problem. The comparison needs to be exact because the fragment is looking for poly id numbers which are encoded into the color.

It's actually amazing that there is a no unsigned integer math available considering the colors are encoded and stored using them.


Shaders in DX10-class hardware actually have native integer capabilities, but in older shader models you're stuck with floating-point math.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!