Jump to content

  • Log In with Google      Sign In   
  • Create Account

Problem hlsl code


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

#1 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 18 October 2012 - 07:30 PM

[source lang="java"]this worksu = uint3(2,0, 0);r = Du.Load(u);this doesnt worksu = uint3(Cordd(2.0f), 0); //---Cordd(2.0f) return uint2(2,0)r = Du.Load(u);uint2 Cordd(float a){uint2 r;r.x=uint(a%3.0f);r.y=uint(a/3.0f);return r;}[/source]
In the complete method i return 'r' as a SV_Target, when i use the one that works the pixel is replaced by the values that 'r' has and when i use the one that doesnt the pixel mantains the same.

Sponsor:

#2 Bacterius   Crossbones+   -  Reputation: 9282

Like
0Likes
Like

Posted 18 October 2012 - 07:44 PM

The modulo operator doesn't work as you think it does on floating-point numbers. See this link, down to the floating-point modulo section.

Basically, what it does is it divides the two operands and returns the fractional part (which is always between 0 inclusive and 1 inclusive). In your case, since you are converting that to an int after, you will always get zero no matter what. Using your example, you will get 2.0f % 3.0f = Frac(2.0f / 3.0f) = Frac(0.666..) = 0.666... Truncated down to an integer, you get zero. Not two.

You want to use fmod instead, probably. Or work in sufficiently large integers instead of floating-point numbers.

Edited by Bacterius, 18 October 2012 - 07:46 PM.

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


#3 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 18 October 2012 - 08:01 PM

thanks i have been 1 complete day in this problem.
Cord() method didnt returned me 0.666 and 'r' was getting the value that i expected in the end of the method but in the end the pixel wasnt getting it, so it was impossible to me to get that mistake.

#4 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 18 October 2012 - 08:25 PM

WAIT! its still not working, and the the module operator % is working like fmod() so it was the same thing,i am always sure that the float that enters the Cordd() method nevr has decimals. What else can cause this problem

Edited by lomateron, 18 October 2012 - 08:33 PM.


#5 Bacterius   Crossbones+   -  Reputation: 9282

Like
0Likes
Like

Posted 18 October 2012 - 08:31 PM

Can you try this:

[source lang="plain"]r.x = (uint(a) % 3) + frac(a);[/source]

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


#6 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 18 October 2012 - 08:39 PM

but r.x is an uint how can i add frac(a) to it.....
YESSS!!! it fianlly worked I used
(uint(a) % 3)
the thing was that 3 wasnt really 3 but another float variable so i used
(uint(a) % uint(f))
and it worked

Edited by lomateron, 18 October 2012 - 08:40 PM.


#7 Bacterius   Crossbones+   -  Reputation: 9282

Like
0Likes
Like

Posted 18 October 2012 - 08:44 PM

Oh yes, my bad. Note this won't work if your modulus is a fractional number like 2.5f or somesuch, but most of the time you are just trying to wrap a float around some integer. Though, note if you're only going to use the arguments as integers, you may as well pass them as integers.

Unsure why fmod didn't work, it should have. How did you use it?

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


#8 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 18 October 2012 - 09:13 PM

just
r.x=uint(fmod(a,f));
and it didnt work, using fmod() or %, Cordd() returned the correct value uint(2, 0)
I still dont know why in the end they dont work, the pixel was not change.




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