home/ atoms/ glsl-int-float-strict-typing

GLSL does not implicitly convert `int` to `float` — mixing them in an expression is a compile error

In GLSL the integer literal 1 and the float literal 1.0 are different types with no implicit conversion. float x = 1; is a compile error — write float x = 1.0;. Mixing them in an expression such as 2.0/3 also fails to compile. This is the single most common typo-class compile error for newcomers, because the same code is legal in C or Python.

Examples

float x = 1; // error — write 1.0 float y = 2.0/3; // error — mixed types float y = 2.0/3.0; // ok

Assessment

Find the two type errors in float a = 1; float b = 2.0/3; and write corrected code, explaining the rule.

“`1` is an `int`, `1.0` is a `float`.** `float x = 1;` → error; write `1.0`. `2.0/3` mixes types → error. This is the single most common typo-class compile error.”
context/ · L1-instruments/glsl/gotchas.md · chunk 1