BabylonJS/Babylon.js · error · Error
Constant value must be between 0.0 and 1.0
Error message
Constant value must be between 0.0 and 1.0
What it means
In MergeTexturesAsync, a constant channel input fills an output channel with a fixed scalar that is written into an 8-bit texture, so it must be between 0.0 and 1.0. This error is thrown when channel.value falls outside that range.
Source
Thrown at packages/dev/core/src/Materials/Textures/textureMerger.ts:124
const channel = channels[channelIndex];
if (channel) {
if (IsTextureInput(channel)) {
// Validate source channel
if (channel.sourceChannel < 0 || channel.sourceChannel > 3) {
throw new Error("Source channel must be between 0 and 3 (R, G, B, A)");
}
// Find or add texture to inputs
let textureIndex = textureInputs.indexOf(channel.texture);
if (textureIndex === -1) {
textureIndex = textureInputs.length;
textureInputs.push(channel.texture);
}
textureInputMap[channelIndex] = textureIndex;
} else if (IsConstantInput(channel)) {
// Validate constant value
if (channel.value < 0 || channel.value > 1) {
throw new Error("Constant value must be between 0.0 and 1.0");
}
textureInputMap[channelIndex] = -1;
} else {
throw new Error("Invalid channel input configuration");
}
} else {
textureInputMap[channelIndex] = -1;
}
}
// Determine output size
let outputSize = config.outputSize;
if (!outputSize && textureInputs.length > 0) {
// Use the largest texture size
let maxSize = 0;
for (const texture of textureInputs) {
const size = texture.getSize();
const currentSize = Math.max(size.width, size.height);View on GitHub (pinned to 0592b347b8)
Solutions
- Convert byte-scale constants: divide by 255 (e.g. 255 -> 1.0).
- Clamp the value: Math.min(1, Math.max(0, value)) before passing it.
- Check upstream computations (factors, sliders) for units that are not normalized.
Example fix
// before
{ value: 255 }
// after
{ value: 1.0 } // or 255 / 255 Defensive patterns
Strategy: validation
Validate before calling
function clamp01(v: number): number {
return Math.min(1, Math.max(0, v));
}
const safeInput = { value: clamp01(rawFactor) }; Type guard
function isUnitValue(v: unknown): v is number {
return typeof v === "number" && Number.isFinite(v) && v >= 0 && v <= 1;
} Try / catch
try {
const tex = await MergeTexturesAsync(channels, w, h, scene);
} catch (e) {
if (String(e.message).includes("Constant value must be between 0.0 and 1.0")) {
console.error("Constant is out of 0-1 range; check 0-255 scale confusion.");
}
} Prevention
- Always normalize constants to 0-1 (divide byte values by 255).
- Clamp computed factors before building channel inputs.
- Guard against NaN/Infinity reaching the value field.
When it happens
Trigger: Passing a constant input like { value: 255 } (authoring in 0-255) or a negative value to MergeTexturesAsync / CreateMergedAnisotropyTexture / metalRough conversion.
Common situations: Porting code that used byte values (0-255), computing a factor with NaN or a bad division producing out-of-range numbers, glTF material factor units confusion.
Related errors
- Source channel must be between 0 and 3 (R, G, B, A)
- Sample2DRgbaToRef: widthPx and heightPx must be positive.
- At least one mesh is needed to create the nav mesh.
- At least one mesh is needed to create the nav mesh.
- Unable to create navmesh. No navMesh or navMeshQuery returne
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/f7193b8c86190cc9.
Report an issue: GitHub.