Jump to content
  • Advertisement
Sign in to follow this  
Quaid Tseng

Modulus in assembly shader? How?

This topic is 4142 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

Assembly shader language has mul, add, mad,.... but there's no mod instruction, how to do that? BTW, how to use "if" in assembly shader? For example, in C++ we write: if(c1 > c2)c3 = c1; How to do this in assembly shader? Thanks to any reply!

Share this post


Link to post
Share on other sites
Advertisement
You can perform an arithmetic modulus in ps_2_0 but not in ps_1_x (as there's no frc). All vertex-shader models support the necessary operations. It's done using rcp, mul and frc. In pseudo-asm:

a % b = frc(a / b) * b

i.e.

rcp t, b
mul t, t, a
frc t, t
mul o, t, b

where a and b are the inputs, t is temporary and o is the result.

Conditionals can be performed under any pixel shader model using the cnd operator, and under any vertex shader model using slt. I trust you can work these out yourself. Bear in mind, that a copy of FX Composer is invaluable when working out the best way to express non-intrinsic shader instructions.

Admiral

Share this post


Link to post
Share on other sites
Thanks to TheAdmiral's hot and clear words.

Now I build SMVM on GPU,
I think assembly is much efficient than HLSL/Cg.
However I can't find some decent tutors.

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!