# Double conditional "if" on HLSL

Hi People,

I´m working on a point sprite shader with rotation based on the acceleration of the particles.
The conversion “Angle= asin (Acceleration/4)” works but it seems that the rotation of the quads is inverted for Angle > 0.25(East) and < 0.75(West).

I want to invert the angle in this part using this code, but only works the first conditional.
Am I missing something?

``````float Accel3 =normalize(tex2Dlod(SampData, TexCd).ba);
float Angle=asin (Accel/4);

if (Angle >= 0.25)
{Angle=Angle;}

else if (Angle>= 0.75)
{Angle=1-Angle;}
``````

Is it possible to use a sort of double conditional?
like:

``````if [Angle <= 0.25) "and" (Angle >= 0.75](https://vvvv.org/documentation/Angle-<=-0.25)-"and"-(Angle->=-0.75)
{Angle=Angle;}
else
{Angle=1-Angle;}
``````

Any idea would be very appreciated.

Ari.

You mean boolean math operators?

AND: &&
OR: ||

``````if ( (Angle <= 0.25) && (Angle >= 0.75) )
``````

Thanks, ft,

i´ve tried it without success, it compiles but it doesn´t change.

``````if [ Angle>=0.25) && (Angle<=0.75](https://vvvv.org/documentation/Angle>=0.25)-&&-(Angle<=0.75)
{Angle=1-Angle}

if [ Angle<0.25) && (Angle>0.75](https://vvvv.org/documentation/Angle<0.25)-&&-(Angle>0.75)
{Angle=Angle}
``````

Is there other way to write it?

Ari.

My Vertex shader looks like this,

``````vs2ps VS(
float4 Pos : POSITION ,
float4 TexCd : TEXCOORD0 ,
float4 TexCdCol : TEXCOORD1
)
{
//inititalize all fields of output struct with 0
vs2ps Out = (vs2ps)0;

//get the position info from the Position-velocity texture:
float2 particlePosition = tex2Dlod(SampData, TexCd).rg;
float Accel  =  abs[tex2Dlod(SampData, TexCd).ab)+(tex2Dlod(SampData, TexCd).ba](https://vvvv.org/documentation/tex2Dlod(SampData,-TexCd).ab)+(tex2Dlod(SampData,-TexCd).ba)*10*Gamma;
float Accel2 =  max (1,(1/(abs[tex2Dlod(SampData, TexCd).ab)+(tex2Dlod(SampData, TexCd).ba](https://vvvv.org/documentation/tex2Dlod(SampData,-TexCd).ab)+(tex2Dlod(SampData,-TexCd).ba)*20*Gamma+MinSize)));
float Accel3 = (normalize(tex2Dlod(SampData, TexCd).ba));
float Angle  = (atan (Accel3/4));

if  [Angle >= 0.25)  && (Angle<= 0.75](https://vvvv.org/documentation/Angle->=-0.25)--&&-(Angle<=-0.75)
{Angle=1-Angle;}
else
{Angle=Angle;}

if(Accel >= MaxColor)
{ Accel= MaxColor;}
else
{ Accel= Accel; }

Pos = mul(Pos, tW);

//now apply the position taken from the texture

Pos.xy = rotate( (Pos.xyz), 0, 0, (Angle))+particlePosition.xy;   //rotate1.z does the roll
Pos = mul(Pos, tPost);

//then apply the tVP
Out.Pos = mul(Pos, tVP);
Out.TexCdCol = mul(TexCdCol, mul(tTexCol,Accel2));
Out.Vcol = (tex2Dlod(SampColPP1, TexCd)*(1-MaxColor+Accel)+ tex2Dlod(SampColPP2, TexCd)*(MaxColor-Accel));
return Out;
}``````

Angles are not between 0 and 1 in HLSL, they are in radians

• define PI 3.14159265

for PI you can also use acos(-1), works fine too.

and multiply at will ;)

Thanks a lot vux,
now i understand it better.
But still some questions,
it works well in the X axis (from Pi/2 to 2Pi/3), but when the particles move through the Y axis they doesn´t change the direction (always 0).

Maybe is this not the best way to obtain the rotation values?
Any tip?

Ari

``````float Accel3 = (normalize(tex2Dlod(SampData, TexCd).ba));
float Angle  = (atan (Accel3))/Pi;

if  [Angle >= (Pi/2](https://vvvv.org/documentation/Angle->=-(Pi/2)  && (Angle<= (TwoPi/3)))
{Angle=1-Angle;}
else
{Angle=Angle;}

if(Accel >= MaxColor)
{ Accel= MaxColor;}
else
{ Accel= Accel; }

Pos = mul(Pos, tW);

//now apply the position taken from the texture
Pos.xy = rotate( (Pos.xyz), 0, 0, (Angle))+particlePosition.xy;  //rotate1.z does the roll

Pos = mul(Pos, tPost);``````

try atan2, it gives the right angle for all directions. and first you devide by Pi, setting the angle range to 0…2 and then you check for Pi/2 which does not look right.
http://en.wikipedia.org/wiki/Atan2

Yeah!
Tonfilm, vux, ft i owe you a beer ;)

``````float2 Accel3 = normalize(tex2Dlod(SampData, TexCd).ba);
float Angle  = atan2 [Accel3.x),(-Accel3.y](https://vvvv.org/documentation/Accel3.x),(-Accel3.y)/TwoPi;
``````

It works perfect.