What is this syntax construction in shaders ? how do You read "?"(questionmark) in shaders ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Inces
force += length(diff) > 0.0 ? normalize(diff) *....

This is the type of syntax which You can see in Godots default particle shader.

How do You read this ? How can You mix boolean within float calculations ?

:bust_in_silhouette: Reply From: AlexTheRegent

This is ternary if operator. Basically this is shorthand for if ... then ... else ...
So if your statement is true, then instructions between ? and : are executed. If statement is false, then instructions after : and until line end are executed.

In your case this code can be rewritten as

  if length(diff) > 0.0:
    force += normalize(diff) * ...