condition with float constant return always false

More
1 year 6 months ago #1 by seri14
Input code
void test()
{
	float R;
	const float V = 10.0;
	if (V > 1.0)
		R = 1.0;
}
Result (from [Show HLSL/GLSL])
#line 63
void F__test()
{
	const float _74 = 0.00000000;
#line 65
	float R;
#line 65
	R = _74;
	const bool _79 = false;
#line 67
	if (_79)
	{
		const float _80 = 1.00000000;
#line 68
		R = _80;
	}
	return;
}
The following user(s) said Thank You: Wicked Sick

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

More
1 year 6 months ago #2 by crosire
The following user(s) said Thank You: Wicked Sick, seri14

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

More
1 year 6 months ago - 1 year 6 months ago #3 by seri14
After this commit, compile of some effects will fail.

github.com/Mortalitas/GShade-Shaders/blo...haders/MagicBloom.fx
github.com/Mortalitas/GShade-Shaders/blo...aders/qUINT_bloom.fx
github.com/Mortalitas/GShade-Shaders/blo...ers/qUINT_common.fxh
2019-03-21T13:14:33:124 [12608] | ERROR | Failed to compile "C:\...\reshade-shaders\Shaders\MagicBloom.fx":
C:\...\reshade-shaders\Shaders\MagicBloom.fx(91, 34): error X3082: int or unsigned int type required
C:\...\reshade-shaders\Shaders\MagicBloom.fx(91, 122): error X3000: syntax error: unexpected '|', expected expression
C:\...\reshade-shaders\Shaders\MagicBloom.fx(193, 10): error X3011: value must be a literal expression
C:\...\reshade-shaders\Shaders\MagicBloom.fx(216, 109): error X3538: value must be a literal scalar expression

2019-03-21T13:14:33:243 [15272] | ERROR | Failed to compile "C:\...\reshade-shaders\Shaders\qUINT_bloom.fx":
C:\...\reshade-shaders\Shaders\qUINT_bloom.fx(136, 43): error X3082: int or unsigned int type required
C:\...\reshade-shaders\Shaders\qUINT_bloom.fx(136, 113): error X3000: syntax error: unexpected '|', expected expression
C:\...\reshade-shaders\Shaders\qUINT_bloom.fx(145, 100): error X3538: value must be a literal scalar expression
Last edit: 1 year 6 months ago by seri14.
The following user(s) said Thank You: Wicked Sick

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

More
1 year 6 months ago #4 by crosire
The following user(s) said Thank You: Wicked Sick, seri14, Marot

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

More
1 year 6 months ago #5 by thrive4
Great catch!

But I'm a bit stumped, and I do hate doing the why would
you do this, but I really would like to know under which
condition you would set up code this way?

const float V = 10.0;
if (V > 1.0)

V is always going to be larger then 1.0.... :blink:

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

More
1 year 6 months ago #6 by klotim

thrive4 wrote: Great catch!

But I'm a bit stumped, and I do hate doing the why would
you do this, but I really would like to know under which
condition you would set up code this way?

const float V = 10.0;
if (V > 1.0)

V is always going to be larger then 1.0.... :blink:


Why yes ofc. But that's just to easily provide that something doesn't work.
In real-life scenarios it would be dynamic variables.

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

More
1 year 6 months ago #7 by crosire
Nah. Dynamic variables worked fine. This was a very specific case. But can happen when you are debugging with constants to check if a certain code path is working for example.

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

More
1 year 6 months ago #8 by klotim

crosire wrote: Nah. Dynamic variables worked fine. This was a very specific case. But can happen when you are debugging with constants to check if a certain code path is working for example.


Alright, Glad that it was solved!

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

More
1 year 5 months ago #9 by thrive4
Ok, a debugging method thanks for the explanation.

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