---
title: "Functions and operators in GLSL ES 3.00 and TypeShade"
description: "A call carries one neutral name and each backend writes its own spelling. The derivative, texture, bit and remainder forms a GLSL author looks for."
url: https://typeshade.dev/guide/language/from-glsl/functions/
language: en
---

# Functions and operators

A call carries one neutral name through the compiler and each backend writes its own spelling, so the name to write is the one in the right column. These are the ones a GLSL author goes looking for.

GLSL ES 3.00 TypeShade Note

```glsl
dFdx(a)
```

```ts
dpdx(a)
```

The same derivative under the WGSL name.

```glsl
dFdy(a)
```

```ts
dpdy(a)
```

The same, along the other axis.

```glsl
dFdx(a)
```

```ts
dpdxCoarse(a)
```

The coarse and fine variants keep their names on WGSL and collapse here, since this target has one derivative per axis.

```glsl
dFdy(a)
```

```ts
dpdyFine(a)
```

The same collapse.

```glsl
mod(a, b)
```

```ts
mod(a, b)
```

The floor remainder, which is what this target's `mod` already is. The `%` operator is the other one.

```glsl
texture(a, c)
```

```ts
textureSample(a, b, c)
```

The sampler argument goes, because the combined sampler already holds it.

```glsl
texelFetch(a, b, int(c))
```

```ts
textureLoad(a, b, c)
```

A texel read at an integer coordinate and a mip level.

```glsl
uvec2(textureSize(a, 0))
```

```ts
textureDimensions(a)
```

The size comes back unsigned, so the writer wraps this target's signed answer.

```glsl
faceforward(a, b, c)
```

```ts
faceForward(a, b, c)
```

A spelling difference and nothing more.

```glsl
inversesqrt(a)
```

```ts
inverseSqrt(a)
```

A spelling difference and nothing more.

```glsl
roundEven(a)
```

```ts
round(a)
```

The rounding both targets share is the one that sends a half to the even neighbour.

```glsl
_popcnt(a)
```

```ts
countOneBits(a)
```

This target has none of the bit builtins, so the writer defines a small function over the shifts and masks it does have.

```glsl
_msb(a)
```

```ts
firstLeadingBit(a)
```

Another of those, defined only in a module that calls it.

The operators divide the same way. A comparison of two vectors is written with the operator and reaches this target as the function it has, and a per-component choice is `select` on both.

GLSL ES 3.00 TypeShade Note

```glsl
float floorMod = mod(uv.x, 0.5);
```

```ts
const floorMod = mod(uv.x, 0.5)
```

The floor remainder, whose sign follows the divisor.

```glsl
float truncMod = (uv.x - 0.5 * trunc(uv.x / 0.5));
```

```ts
const truncMod = uv.x % 0.5
```

The truncating remainder, whose sign follows the dividend. This target has no `%` on floats, so the writer spells it out.

```glsl
bvec2 below = lessThan(uv, vec2(0.5, 0.25));
```

```ts
const below: vec2b = uv < vec2(0.5, 0.25)
```

A vector comparison is a function on this target and an operator on the other, so it is written as the operator.

```glsl
bvec2 same = equal(uv, vec2(0.75, 0.125));
```

```ts
const same: vec2b = uv === vec2(0.75, 0.125)
```

The same, and the strict form is the one TypeScript takes.

```glsl
float picked = mix(uv.x, uv.y, below.x);
```

```ts
const picked = select(uv.x, uv.y, below.x)
```

A scalar choice is the ternary here and `select` on WGSL, so one name serves both.

```glsl
vec2 blended = mix(vec2(0.0, 0.0), vec2(1.0, 1.0), below);
```

```ts
select(vec2(0., 0.), vec2(1., 1.), below)
```

A per-component choice over a boolean vector is `mix` on this target, which is the shape a GLSL author already writes.

Every builtin the compiler can spell, with the text it writes for each one on both targets, is on [the builtin table](https://typeshade.dev/guide/language/builtins/).
