---
title: "WGSL vs GLSL ES 3.00: differences and one source for both"
description: "WGSL and GLSL are shader languages. In browser applications, WebGPU uses WGSL, while WebGL uses GLSL ES."
url: https://typeshade.dev/guide/concepts/wgsl-and-glsl/
language: en
---

# WGSL vs GLSL ES 3.00

WGSL and GLSL are shader languages. In browser applications, WebGPU uses WGSL, while WebGL uses GLSL ES. Shader source describes a calculation within the API execution model.

## When it helps

Use the language accepted by the chosen API. When porting a shader, compare types and expressions together with entry-point inputs, outputs, and resource bindings.

## Worked example

Both local expressions interpolate between the same scalar endpoints with the same weight. The result agrees even though the variable declarations use different syntax.

WGSL

```wgsl
let value: f32 = mix(0.0, 1.0, 0.25);
```

GLSL ES

```glsl
float value = mix(0.0, 1.0, 0.25);
```

Result: `value = 0.25`

## Practical limits

Porting also requires checking buffer layouts, coordinate conventions, interpolation, and precision. GLSL ES default precision depends on the shader stage; WGSL follows its own type and accuracy rules.

One `"use typeshade"` file reaches WebGPU as WGSL and WebGL2 as GLSL ES 3.00. The compiler spells 190 builtins, and 44 of them are written the same way in both languages. The blocks on this page are compiled while the page is built, from the file above them, by the compiler pinned at af54ddad5.

## The source

A triangle, with a vertex entry that places it and a fragment entry that colours it. The two structs give each stage its output shape.

hello.shade.ts

```ts
"use typeshade";

interface Clip {
  pos: builtin<"position">;
}

interface Color {
  color: location<0, vec4>;
}

@vertex
export function vs(i: builtin<"vertex_index">): Clip {
  const x = i === 1 ? 0.8 : i === 2 ? 0. : -0.8;
  const y = i === 2 ? 0.8 : -0.8;
  return { pos: vec4(x, y, 0., 1.) };
}

@fragment
export function fs(): Color {
  return { color: vec4(1., 0., 0., 1.) };
}
```

## WGSL

WGSL is the language a WebGPU device accepts, and one module holds every stage. The structs survive as structs, each entry point keeps its stage attribute, and the builtin input stays an attribute on the parameter that receives it.

The emitted WGSL module

```wgsl
struct Clip {
  @builtin(position) pos: vec4<f32>,
}

struct Color {
  @location(0) color: vec4<f32>,
}

@vertex
fn vs(@builtin(vertex_index) i: u32) -> Clip {
  let _cse0 = (i == 2u);
  let x = select(select(-0.8, 0.0, _cse0), 0.8, (i == 1u));
  let y = select(-0.8, 0.8, _cse0);
  return Clip(vec4<f32>(x, y, 0.0, 1.0));
}

@fragment
fn fs() -> Color {
  return Color(vec4<f32>(1.0, 0.0, 0.0, 1.0));
}
```

## GLSL ES 3.00

A WebGL2 program is linked from one vertex shader and one fragment shader, so the compiler emits a separate program for each stage. Each one opens with its version line and its default precision, the vertex index arrives under the name the language reserves for it, and the fragment output becomes a declared out variable.

The emitted GLSL ES 3.00 vertex shader

```glsl
#version 300 es
precision highp float;
precision highp int;


void main() {
  uint i = uint(gl_VertexID);
  bool _cse0 = (i == 2u);
  float x = mix(mix(-0.8, 0.0, _cse0), 0.8, (i == 1u));
  float y = mix(-0.8, 0.8, _cse0);
  gl_Position = vec4(x, y, 0.0, 1.0);
}
```

The emitted GLSL ES 3.00 fragment shader

```glsl
#version 300 es
precision highp float;
precision highp int;

layout(location = 0) out vec4 color;

void main() {
  color = vec4(1.0, 0.0, 0.0, 1.0);
}
```

## Where the targets differ

Each difference is named by the page of the guide that handles it. Where the two disagree, WGSL defines what a construct means, and GLSL ES 3.00 is a target the compiler writes to ([Rule 1.2](https://typeshade.dev/reference/rules/1-2/) no test checks this yet).

| What differs | WGSL | GLSL ES 3.00 |
| --- | --- | --- |
| [Compute stages](https://typeshade.dev/guide/language/stages/) | A `compute` entry emits a compute shader carrying its workgroup size. | WebGL2 has no native compute stage. TypeShade runs supported compute entries through generated GLSL ES 3.00 passes. |
| [Precision](https://typeshade.dev/guide/language/gpu-types/) | A type carries its own width, so the program declares nothing. | The program opens with a default precision for floating-point and integer values. |
| [Builtin inputs](https://typeshade.dev/guide/language/stages/) | A builtin stays an attribute on the parameter that receives it. | A builtin becomes the name the language reserves for it, and the parameter goes away. |
| [Stage outputs](https://typeshade.dev/guide/language/types/) | A stage returns a struct whose fields carry their locations. | A stage writes to declared out variables, and the position goes to the reserved one. |
| [Extensions](https://typeshade.dev/guide/internals/) | A GPU feature is turned on by a declaration at the top of the module. | A GPU feature is turned on by a preprocessor line, and the host asks the context for the matching extension. |

## Names that differ

Each row is one construct. The GLSL ES 3.00 and WGSL cells are the text the compiler at af54ddad5 writes for the TypeShade cell. A spelling the compiler changes reaches this table at the next pin.

### Types

GLSL ES 3.00 WGSL TypeShade

```glsl
float
```

```wgsl
f32
```

```ts
f32
```

```glsl
int
```

```wgsl
i32
```

```ts
i32
```

```glsl
uint
```

```wgsl
u32
```

```ts
u32
```

```glsl
bool
```

```wgsl
bool
```

```ts
bool
```

```glsl
vec3
```

```wgsl
vec3<f32>
```

```ts
vec3
```

```glsl
ivec3
```

```wgsl
vec3<i32>
```

```ts
vec3i
```

```glsl
uvec3
```

```wgsl
vec3<u32>
```

```ts
vec3u
```

```glsl
bvec3
```

```wgsl
vec3<bool>
```

```ts
vec3b
```

```glsl
mat4
```

```wgsl
mat4x4<f32>
```

```ts
mat4
```

```glsl
mat2x3
```

```wgsl
mat2x3<f32>
```

```ts
mat2x3
```

```glsl
float[4]
```

```wgsl
array<f32, 4>
```

```ts
array<f32, 4>
```

```glsl
sampler2D
```

```wgsl
texture_2d<f32>
```

```ts
texture_2d<f32>
```

```glsl
samplerCube
```

```wgsl
texture_cube<f32>
```

```ts
texture_cube<f32>
```

standalone sampler — fused into the combined sampler2D

```wgsl
sampler
```

```ts
sampler
```

### Builtin variables

GLSL ES 3.00 WGSL TypeShade

```glsl
gl_Position
```

```wgsl
@builtin(position)
```

```ts
builtin<"position">
```

```glsl
gl_FragCoord
```

```wgsl
@builtin(position)
```

```ts
builtin<"position">
```

```glsl
uint(gl_VertexID)
```

```wgsl
@builtin(vertex_index)
```

```ts
builtin<"vertex_index">
```

```glsl
uint(gl_InstanceID)
```

```wgsl
@builtin(instance_index)
```

```ts
builtin<"instance_index">
```

```glsl
gl_FrontFacing
```

```wgsl
@builtin(front_facing)
```

```ts
builtin<"front_facing">
```

```glsl
gl_FragDepth
```

```wgsl
@builtin(frag_depth)
```

```ts
builtin<"frag_depth">
```

### Functions

GLSL ES 3.00 WGSL TypeShade

```glsl
atan(a, b)
```

```wgsl
atan2(a, b)
```

[`atan2(a, b)`](https://typeshade.dev/reference/functions/atan2/)

```glsl
inversesqrt(a)
```

```wgsl
inverseSqrt(a)
```

[`inverseSqrt(a)`](https://typeshade.dev/reference/functions/inverseSqrt/)

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

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

[`faceForward(a, b, c)`](https://typeshade.dev/reference/functions/faceForward/)

```glsl
dFdx(a)
```

```wgsl
dpdx(a)
```

[`dpdx(a)`](https://typeshade.dev/reference/functions/dpdx/)

```glsl
dFdy(a)
```

```wgsl
dpdy(a)
```

[`dpdy(a)`](https://typeshade.dev/reference/functions/dpdy/)

```glsl
clamp(a, 0.0, 1.0)
```

```wgsl
saturate(a)
```

[`saturate(a)`](https://typeshade.dev/reference/functions/saturate/)

```glsl
((a) * (b) + (c))
```

```wgsl
fma(a, b, c)
```

[`fma(a, b, c)`](https://typeshade.dev/reference/functions/fma/)

```glsl
(c ? b : a)
```

```wgsl
select(a, b, c)
```

[`select(a, b, c)`](https://typeshade.dev/reference/functions/select/)

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

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

[`textureSample(a, b, c)`](https://typeshade.dev/reference/functions/textureSample/)

```glsl
textureLod(a, c, d)
```

```wgsl
textureSampleLevel(a, b, c, d)
```

[`textureSampleLevel(a, b, c, d)`](https://typeshade.dev/reference/functions/textureSampleLevel/)

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

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

[`textureLoad(a, b, c)`](https://typeshade.dev/reference/functions/textureLoad/)

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

```wgsl
textureDimensions(a)
```

[`textureDimensions(a)`](https://typeshade.dev/reference/functions/textureDimensions/)

```glsl
packHalf2x16(a)
```

```wgsl
pack2x16float(a)
```

[`pack2x16float(a)`](https://typeshade.dev/reference/functions/pack2x16float/)

```glsl
float(a)
```

```wgsl
f32(a)
```

[`f32(a)`](https://typeshade.dev/reference/functions/f32/)

```glsl
lessThan(uv, vec2(0.5, 0.25))
```

```wgsl
(uv < vec2<f32>(0.5, 0.25))
```

```ts
uv < vec2(0.5, 0.25)
```

### Same name, other meaning

GLSL ES 3.00 WGSL TypeShade

```glsl
mod(uv.x, 0.5)
```

```wgsl
(uv.x - 0.5 * floor(uv.x / 0.5))
```

```ts
mod(uv.x, 0.5)
```

```glsl
(uv.x - 0.5 * trunc(uv.x / 0.5))
```

```wgsl
(uv.x % 0.5)
```

```ts
uv.x % 0.5
```

```glsl
roundEven(uv.x)
```

```wgsl
round(uv.x)
```

```ts
round(uv.x)
```

A few names are in both languages and mean different things. GLSL's `mod` rounds the quotient down, and WGSL's `%` truncates it toward zero. WGSL's `round` sends a half to the even integer and GLSL's may send it either way, so the compiler writes `roundEven`. TypeShade has `mod` and `%`, and the compiler writes each target the text that keeps the meaning.

GLSL can assign to several components at once, as in `c.xy = uv`, and so can TypeShade (change 0106): the compiler reads the old components the operation needs into a `let`, then writes each destination component in turn, so WGSL needs no `swizzle_assignment` extension. A swizzle that names a component twice, `c.xx = uv`, is refused with [`TS8018`](https://typeshade.dev/reference/errors/ts8018/).

## Converting a shader

`compile()` reads one kind of source, a `"use typeshade"` file, which is TypeScript. The compiler has no GLSL or WGSL front end, so a shader in either language is written once more in TypeScript. The compiler then writes the WGSL and the GLSL ES 3.00 from that one file.

- From GLSL: [Migrating a GLSL shader](https://typeshade.dev/guide/internals/migrating-a-glsl-shader/) covers what a whole shader carries, such as uniform blocks, `#ifdef`, `#include` and `#extension`. [GLSL ES 3.00 in TypeShade](https://typeshade.dev/guide/language/from-glsl/) has the types, uniforms, builtin variables and functions.
- From WGSL: [WGSL in TypeShade](https://typeshade.dev/guide/language/from-wgsl/) gives each WGSL construct its TypeShade spelling.
- Only in WGSL: a file that uses such a construct still compiles. A scalar uniform, a `"read_write"` storage binding in a draw and `{ interpolate: "linear" }` are examples. `compile()` then keeps the WGSL, leaves `glsl` undefined and says why in a [`TS8015`](https://typeshade.dev/reference/errors/ts8015/) warning.

## Further reading

Learn what `precision highp float;` means, compare stage defaults, and inspect browser capabilities in the [GLSL precision guide](https://typeshade.dev/guide/concepts/glsl-precision/).

- [WGSL specification](https://www.w3.org/TR/WGSL/) defines the first of the two targets.
- [GLSL ES 3.00 specification](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf) and the [WebGL2 specification](https://registry.khronos.org/webgl/specs/latest/2.0/) define the second.
- [MDN WebGPU API](https://developer.mozilla.org/en-US/docs/Web/API/WebGPU_API) and [MDN WebGL2RenderingContext](https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext) show how a host hands each of them to a driver.
- [Functions](https://typeshade.dev/reference/functions/) in the language reference gives each builtin with the WGSL and GLSL ES 3.00 text the compiler writes for it, and [Types](https://typeshade.dev/reference/types/) does the same for every type.
- [Builtin functions](https://typeshade.dev/guide/language/builtins/) lists all 190 builtins on one page, with the text each backend writes. 64 of them have no GLSL ES 3.00 form of their own: the writer has none, or a pass rewrites the call before the writer runs.

Next: [Examples](https://typeshade.dev/guide/examples/), where every example in the compiler’s registry names the targets it emits.
