0

I've been asked to port some old HLSL code (Shader Model 2.0/3.0) into another language.

There is a line in the code that reads - int(value) or int(x).

But it doesn't seem to be a "convert to integer" or "return integer of" or similar command.

Anyone know what int(x) does in older versions of HLSL?

Thank you very much!

EDIT: ///////////

The line in the code reads:

x = int(x / 12) * 12;

it seems intended to "step" or "toon" the value of x... this should be the same as using the 2 code lines;

int x2 = x / 12;   
x = x2 * 12;  

right after another but the result comes out different - the rendered image screws up completely when I use the 2 line version. I may be able to remove this line completely and replace it with something else... its not a very crucial operation... but I'm curious to know what

x = int(x / 12) * 12;

actually does to the value of x under HLSL Shader Model 2.0/3.0. Thanks for any help.

GLSL Dude
  • 1
  • 3
  • 1
    What makes you believe that it is not an `int` cast? – UnholySheep Apr 22 '17 at 16:22
  • please do not put relevant code into comments, [edit] it into your question, so others can see it immediately (also so it can be formatted properly) – UnholySheep Apr 22 '17 at 16:42
  • Fixed. Added code example to main question. Thanks. – GLSL Dude Apr 22 '17 at 16:47
  • Surely it is cast, asint() would be more sensible. – Hans Passant Apr 22 '17 at 16:56
  • 2
    Your two line expansion is wrong -- the second line should be `x = x2 * 12;` – Chris Dodd Apr 22 '17 at 16:57
  • I actually mistyped that while editing. Have been porting code for 8 hours, so tired, sorry. =) I have just removed this portion of the code and replaced it with some simple math that gives roughly the same visual result. This HLSL shader was written using HLSL in MPC-HC media player. So maybe the compiler MPC uses interprets the line differently from normal HLSL compilers. Anyways, the line is gone now. – GLSL Dude Apr 22 '17 at 17:06
  • Your latest edit is still different from the original code - `x2 = x2 * 12;` should be `x = x2 * 12;` – UnholySheep Apr 22 '17 at 17:07
  • Noted. Thanks. Fixing original post now. – GLSL Dude Apr 23 '17 at 18:35

1 Answers1

0

It's a construction cast, just like in C++ or C# -- in general type(arg) converts the argument to type, by constructing a value of that type from the argument (or arguments).

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226