schell / schell/wgsl-rs

Implement mix(vecN, vecN, scalar) overload

Open
#87 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
62
Forks
5
Avg merge
1d 8h
Merged PRs (30d)
13

Description

## Description

WGSL supports a `mix` overload with a scalar blend factor applied component-wise:

```wgsl
mix(e1: vecN, e2: vecN, e3: T) -> vecN
```

This overload is documented in the spec table in `crates/wgsl-rs/src/std/numeric.rs` (line 47) but is not implemented. The current `mix` function requires all three arguments to be the same type.

This forces users to manually splat the scalar blend factor:

```rust
// Current workaround
let t = clamp(f * f * 4.0, 0.0, 1.0);
color = mix(color1, color2, vec3f(t, t, t));

// Desired
color = mix(color1, color2, t);
```

This is a very common pattern in shader code — color blending, lerping, and smooth transitions all use scalar blend factors with vector operands.

## Location

`crates/wgsl-rs/src/std/numeric.rs`, `mix` module (~line 1267).

## Suggested approach

Add a second trait or extend `NumericBuiltinMix` to support the scalar blend factor case. This could be a separate function like `mix_scalar` mapped to the same WGSL `mix` builtin via `BUILTIN_CASE_NAME_MAP`, following the existing variadic builtin pattern (similar to how `texture_sample` / `texture_sample_array` both map to `textureSample`).

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in crates/wgsl-rs/src/std/numeric.rs at the mix module around line 1267, then compare the spec table near line 47 with NumericBuiltinMix and BUILTIN_CASE_NAME_MAP. Check the existing variadic builtin pattern for texture_sample and texture_sample_array. Done means vector operands accept a scalar blend factor and map to the WGSL mix builtin without requiring a manually splatted vector.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.