Advertisement Jump to content
Sign in to follow this  
Quaid Tseng

Modulus in assembly shader? How?

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


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.


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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!