Skip to content

Shader translator: accept HLSL C-style casts like (float)k (#560, #825) - #829

Merged
CaYatur merged 1 commit into
mainfrom
fix/shader-c-cast
Oct 22, 2026
Merged

CaYatur merged 1 commit into
mainfrom
fix/shader-c-cast

Conversation

@CaYatur

@CaYatur CaYatur commented Oct 22, 2026

Copy link
Copy Markdown
Owner

MilkDrop's compiler accepts HLSL C-style casts ((float)k * 0.2, (float2)x, (int)(a + b)). Our GLSL translator did not, so the stage was dropped as "not compiled". Found while building a CaYaDev preset (#825).

Change

  • src/shared/milkdrop-shader.js: cCast() turns a cast into a GLSL constructor. It binds to the term right after the cast, as in HLSL: a name, number or parenthesised group, then calls, .members and [index]. (int) goes through the existing int( → trunc( path. A parenthesised type preceded by an identifier (sizeof(float)) is left alone.
  • tests/milkdrop-compile-gaps.test.js: two tests (scalar cast in a loop; vector, group and member-chain casts; function parameters untouched).

Verified

  • The test preset that failed (for (int k…) a += (float)k * 0.2;) now compiles in WebGL in the preview harness. Before the change it showed "comp: derlenmedi".
  • The 10,347-file corpus has no such casts (grep for (type) with optional spaces finds none), so no existing preset's shader changes.
  • npm test: 3511/3511. The test count is updated in README, README.tr and ROADMAP.

Refs #560, #825

MilkDrop's compiler accepts `(float)k * 0.2`, `(float2)x` and `(int)(a+b)`;
GLSL has only the constructor form, so the stage failed with "not compiled".
Found while building a CaYaDev preset. The cast binds to the term right after
it (name, number or parenthesised group, then calls, .members and [index]),
as in HLSL; (int) maps to trunc() like int(). A parenthesised type preceded
by an identifier is left alone. The corpus has no such casts, so no corpus
shader changes.

Co-authored-by: caganturgut <271973834+caganturgut@users.noreply.github.com>
@CaYatur
CaYatur merged commit 182ee21 into main Oct 22, 2026
5 checks passed
@CaYatur
CaYatur deleted the fix/shader-c-cast branch October 22, 2026 22:25
@cayadraft

cayadraft Bot commented Oct 22, 2026

Copy link
Copy Markdown

@CaYatur

CaYaDraft — pull request

Summary
This pull request adds support for HLSL C-style casts (e.g., (float)k) to the MilkDrop shader translator, which previously caused compilation failures. The cCast() function in milkdrop-shader.js now converts these casts into equivalent GLSL constructors by binding to the term immediately following the cast, while leaving parenthesized types preceded by identifiers unchanged.

Files

  • CHANGELOG.md
  • README.md
  • README.tr.md
  • ROADMAP.md
  • src/shared/milkdrop-shader.js
  • tests/milkdrop-compile-gaps.test.js

Note
Nothing blocking is visible from the text.


Stopping here. I will not merge, push, or change this pull request until you ask.

/caya explain describes the diff. /caya plan previews the next edit. /caya revise adds a commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant