# GLSL Syntax

## Additional shader example for understanding syntax

```

#ifdef GL_ES
precision highp float;
#endif

IN vec2 texCoord;

// Uniform variables: 
// bridge between  CPU - GPU that allows mapping external information 
// For example: time
uniform float uTime;


{{MODULES_HEAD}}

void main()
{
  
    /* Declaration of variables
       type name = value; */

    // Real numbers
    float number_0 = 1.0; // with dot
    int number_1 = 1;

    // Vectors 
    // 2 dimensions [_ ,_ ]
    vec2 v2_0 = vec2(0.,1.);
    vec2 v2_1 = vec2(number_0,number_1);

    //3 dimensions [_ ,_ ,_ ]
    vec3 v3_0 = vec3(0.,0.5,1.);
    vec3 v3_1 = vec3(v2_0,1.);
    vec3 v3_2 = vec3(v2_0,number_0);

    //4 dimensions [_ ,_ ,_ ,_ ]
    vec4 v4_0 = vec4(0.,0.25,0.5,1.);
    vec4 v4_1 = vec4(v2_0,v2_1);
    vec4 v4_2 = vec4(v3_0,0.);

    // Referencing vectors information
    // [r, g, b, a] || [x , y , z , w] 

    float numero_2 = v4_0.r; // is equivalent to v4_0.x
    vec2 v2_2 = v4_0.rg;     // is equivalent to v4_0.xy
    vec3 v3_3 = v4_0.gbr;    // is equivalent to v4_0.yzx

    gl_FragColor = vec4(0.5); // [ (r, g ,b , a) ]  with values in between 0. y 1.
}

```

## Functions to explore

Complete list of functions:&#x20;

* [https://www.shaderific.com/glsl-functions ](<https://www.shaderific.com/glsl-functions >)
* <https://thebookofshaders.com/glossary/>

### FUNCTIONS

#### Trigonometry&#x20;

cos(x)&#x20;

sin(x)

tan(x)

Power pow(x, 0.5) == sqrt(x)&#x20;

pow(x, 1.)&#x20;

pow(x, 2.)&#x20;

pow(x, n) for any n:=number&#x20;

sqrt(x): square root

&#x20;inversesqrt(x) 1./sqrt(x)

#### Exponentials&#x20;

exp(x) : base 10&#x20;

exp2(x): base 2

#### Logarithms&#x20;

log(x) : base 10&#x20;

log2(x) : base 2

#### Geometry&#x20;

length(x): length of a vector in the Euclidean norm.&#x20;

distance(x,y): distance between x and y&#x20;

dot(x,y): inner product between x and y (scalar product)

#### Other&#x20;

abs(x) : absolute value of x. E.g. abs(1)=1, abs(-1)=1&#x20;

sign(x) : sign of x. E.g. sign(1)=1 sign(-1)=0&#x20;

floor(x) : the nearest whole number that is less than x. Ex: floor(3.14) = 3&#x20;

ceiling(x):the nearest integer that is greater than x. Example: ceiling(3.14) = 4&#x20;

fract(x): the fractional part of x. Example: fract(3.14)= .14;&#x20;

min(a,b): minimum value between a and b&#x20;

max(a,b): minimum value between a and b&#x20;

clamp(x, a, b): if `x` is less than `a` returns a, if `x` is greater than `b` returns `b`, otherwise returns `x`.

mod(x, y): returns the remainder of the division of `x divided by` y\`

mix(x, y, a): x\*(1.-a)+y*a*&#x20;

*step(x, a): returns 0 if x <= a, and returns 1 if x > a.*&#x20;

*smoothstep(x,a,b): returns 0 if x\<a, interpolates between 0 and 1 if a\<x<=b, returns 1 if x > b.*&#x20;

*Example for use in function explorer:*&#x20;

*`float y = cos(cos(cos(x`*`x+u_time*.1),1.5)*10.-u_time);`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dynamics.solsarratea.world/additional-material/glsl-syntax.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
