Jump to content

  • Log In with Google      Sign In   
  • Create Account

Can you do string compares in Shaders?


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
4 replies to this topic

#1 akaitora   Members   -  Reputation: 162

Like
0Likes
Like

Posted 18 January 2014 - 01:55 PM

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!



Sponsor:

#2 richardurich   Members   -  Reputation: 1187

Like
0Likes
Like

Posted 18 January 2014 - 04:50 PM

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.



#3 L. Spiro   Crossbones+   -  Reputation: 15617

Like
0Likes
Like

Posted 18 January 2014 - 05:40 PM

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
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#4 Bacterius   Crossbones+   -  Reputation: 9619

Like
1Likes
Like

Posted 18 January 2014 - 06:56 PM

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.


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#5 akaitora   Members   -  Reputation: 162

Like
0Likes
Like

Posted 18 January 2014 - 07:12 PM

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






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