Does the Timer returns an actual number?

  • Posts: 59
4 years 2 months ago - 4 years 2 months ago #1 by mindu
or it is just "something" changing its value every millisecond? I'm trying to use it like an actual number, for example:
#if ( Timer > 100 ) { whatever; }
and it doesn't makes any difference if I set 0, 100 or 10000, it looks like the timer is not the actual number it shows in the info provided in reshade showstatistics, or am I doing something wrong?

before you ask of course is set up before calling it
uniform float Timer < source = "timer"; >;

Please Log in or Create an account to join the conversation.

  • Posts: 3740
4 years 2 months ago #2 by crosire
It does. But:
#if ( Timer > 100 ) { whatever; }
does not make sense. You are using the preprocessor here ("#if"), which attempts to evaluate that condition before compilation, but cannot find a "Timer" macro. "Timer" is a variable afterall, something the compiler parses, but the preprocessor runs before that. Now it is defined behavior what happens when the preprocessor comes across an identifier it cannot resolve: It acts like it was replaced with a zero. So the preprocessor now reads this:
#if ( 0 > 100 ) ...
Which is obviously false and thus skips entire code block up to the next "#endif".

If you want to make use of the "Timer" variable, use the actual "if" statement:
if (Timer > 100) ...
The following user(s) said Thank You: mindu

Please Log in or Create an account to join the conversation.

  • Posts: 59
4 years 1 month ago - 4 years 1 month ago #3 by mindu
Excuse me but I'm new with shader language... if I write the usual if(...){...} I always get syntax error unexpected 'if' .... what are the rules to use?

Please Log in or Create an account to join the conversation.

  • Posts: 3740
4 years 1 month ago - 4 years 1 month ago #4 by crosire
You can only use statements like "if" inside executable statement blocks aka inside functions. Not in the global scope (the compiler wouldn't know when and how to deal with the if there).

Valid:
void test()
{
    if (...) { ... }
}
Invalid:
if (...) { ... }
void test()
{
}

Please Log in or Create an account to join the conversation.