Advertisement Jump to content
Sign in to follow this  
akaitora

Can you do string compares in Shaders?

This topic is 1825 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 am using CG and am passing a string into my shader as a uniform parameter.  I would like to do a string compare in my vertex shader.  Is that possible?  Is so, how?  Thanks!

Share this post


Link to post
Share on other sites
Advertisement

I wasn't aware Cg even had a string data type, so perhaps you can elaborate on what you are doing and what you want to do. Are you passing the string as a bool array? (answer is you'd have to write your own function) Are you passing in the pointer and asking if you can use that in the shader to access the actual string that's back out in main memory? (the answer is no) Are you using some library or other tool that adds strings to Cg? (if so, your question isn't related to Cg itself, but the tool/library)

 

If the above didn't make sense, then the answer to your question is basically no, it is not possible.

Share this post


Link to post
Share on other sites
What you are doing does not make sense (a graphics card can’t read your CPU RAM) and no, it is not possible.


L. Spiro

Share this post


Link to post
Share on other sites

Sure, you can encode the string as an array of characters (or packed into an array of 32-bit words, whatever) and have your shader do a comparison and output something. But why do you want to do this? If you are thinking of having a "configuration string" that enables or disables features in your shader, that's not the right way, you want to pass this as an array of integer flags (if doing a uber-shader) OR modify the shader to your needs at compile-time with #define's and #include's. No need for strings here.

 

The main reason "string" types exist in HLSL/GLSL/Cg is to allow shader reflection tools to find and use them in some way. You can't actually do anything with them.

Share this post


Link to post
Share on other sites

Thanks guys.  Bacterius, your explanation makes a lot of sense.  Now I understand why cg has a string data type.  Thanks again!

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!