Scopes

MGL distinguish two types of scopes:

  • Serial
  • Parallel

Serial scope

Statements involving only host variables, input and output operations are performed in serial scope. It means this type of expressions are handled by single thread.

int i = inInt[0];
vector v = inVector[0];
v.x += i;
outVector[0] = v;

Parallel scope

While performing operations on point set, interpreter enters into parallel scope. Statements that involves point field are executed simultaneously, one thread per point instance:

vert p = inMesh[0]; // Serial scope
p.position.x += 1; // Parallel scope
if(p.position.x < 0) // Parallel scope
{
    p.position.y += 1;
}
outMesh[0] = p; // Serial scope

Because per-particle operations are executed simultaneously, it is forbidden to make an assignments from parallel scope to host variables.

Previous: Default variables and point fields | Language reference | Next: Built-in functions