Skip to content

feat: add curve inputs and raise uniform limit for GLSL shader node#13158

Merged
jtydhr88 merged 3 commits into
masterfrom
feat/glsl-improve
Mar 27, 2026
Merged

feat: add curve inputs and raise uniform limit for GLSL shader node#13158
jtydhr88 merged 3 commits into
masterfrom
feat/glsl-improve

Conversation

@jtydhr88
Copy link
Copy Markdown
Contributor

@jtydhr88 jtydhr88 commented Mar 26, 2026

  • Raise MAX_UNIFORMS from 5 to 20 for complex shaders
  • Add bool uniform support (u_bool0-9)
  • Add curve input support (u_curve0-3) as 256x1 1D LUT textures
  • Mark GLSLShader as experimental
  • Add Color Balance blueprint (GIMP-compatible shadows/midtones/highlights)
image
  • Add Color Curves blueprint (GIMP-compatible per-channel + master curve)
image

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 44813777-d78f-4db1-bd8e-db0aa89a734d

📥 Commits

Reviewing files that changed from the base of the PR and between c5c284e and ac4a0a9.

📒 Files selected for processing (1)
  • comfy_extras/nodes_glsl.py

📝 Walkthrough

Walkthrough

Adds two GLSL ES 3.00 fragment shaders: blueprints/.glsl/Color_Balance_15.frag (per-pixel shadows/midtones/highlights adjustments with optional luminosity preservation via RGB↔HSL) and blueprints/.glsl/Color_Curves_8.frag (per-channel + master 256-entry LUT curve mapping using texelFetch). Adds blueprint configurations blueprints/Color Balance.json and blueprints/Color Curves.json that wire those shaders into node graphs. Extends comfy_extras/nodes_glsl.py: increases uniform capacity (MAX_UNIFORMS→20), adds MAX_BOOLS and MAX_CURVES, adds bools and curves support, updates _render_shader_batch and GLSLShader.execute signatures, and implements GL setup/cleanup for curve LUT textures.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: raising uniform limits and adding curve/bool input support to the GLSL shader node.
Description check ✅ Passed The description directly relates to the changeset, detailing the new uniforms, inputs, blueprints, and experimental status that are all present in the modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@comfy_extras/nodes_glsl.py`:
- Around line 881-885: The loop that builds curve_luts currently filters out
None entries causing sparse inputs to shift slots; in the block that iterates
over curves.values() (building curve_luts) preserve explicit slots by appending
a placeholder for None rather than skipping them — e.g., append None (or an
appropriately sized neutral LUT) when v is None so the indices of curve_luts
align with the original u_curve0/u_curve1/... slots; ensure the later GLSL
upload logic handles these None placeholders accordingly.
- Line 851: The tooltip for the curve input (io.Autogrow.Input with
template=curve_template) is misleading: update it to state that curves are 256×1
LUTs and recommend using texelFetch with manual linear interpolation as in the
built-in Color_Curves_8.frag (e.g., "Curves are available as
u_curve0-{MAX_CURVES-1} (sampler2D, 256×1 LUT). For accurate sampling, use
texelFetch with manual linear interpolation, as shown in the built-in
Color_Curves_8 shader."). In execute() (the curve binding/filtering loop) stop
silently compacting sparse curve lists: preserve original indices by either
padding missing entries with an identity LUT or binding textures explicitly to
their slot index (u_curveN) instead of using the filtered list position so that
curves[2] continues to map to u_curve2 even when curves[1] is None.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ed94803f-6785-49e3-9e52-9b45a89df3a0

📥 Commits

Reviewing files that changed from the base of the PR and between 6580a6b and 74c021f.

📒 Files selected for processing (5)
  • blueprints/.glsl/Color_Balance_15.frag
  • blueprints/.glsl/Color_Curves_8.frag
  • blueprints/Color Balance.json
  • blueprints/Color Curves.json
  • comfy_extras/nodes_glsl.py

Comment thread comfy_extras/nodes_glsl.py Outdated
Comment thread comfy_extras/nodes_glsl.py Outdated
@jtydhr88 jtydhr88 force-pushed the feat/glsl-improve branch from 74c021f to c5c284e Compare March 26, 2026 03:12
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
comfy_extras/nodes_glsl.py (1)

90-92: Extract the curve LUT width into a shared constant.

256 is now part of the public contract in both the tooltip and to_lut(...). Naming it once will make future changes less error-prone.

♻️ Proposed cleanup
 MAX_UNIFORMS = 20   # u_float0-19, u_int0-19
 MAX_BOOLS = 10      # u_bool0-9
 MAX_CURVES = 4      # u_curve0-3 (1D LUT textures)
+CURVE_LUT_WIDTH = 256
 ...
-                io.Autogrow.Input("curves", template=curve_template, tooltip=f"Curves are available as u_curve0-{MAX_CURVES-1} (sampler2D, 256x1 LUT) in the shader code. Sample with texture(u_curve0, vec2(x, 0.5)).r"),
+                io.Autogrow.Input("curves", template=curve_template, tooltip=f"Curves are available as u_curve0-{MAX_CURVES-1} (sampler2D, {CURVE_LUT_WIDTH}x1 LUT) in the shader code. Sample with texture(u_curve0, vec2(x, 0.5)).r"),
 ...
-        curve_luts = [v.to_lut(256).astype(np.float32) for v in curves.values() if v is not None] if curves else []
+        curve_luts = [v.to_lut(CURVE_LUT_WIDTH).astype(np.float32) for v in curves.values() if v is not None] if curves else []

Also applies to: 850-851, 881-881

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@comfy_extras/nodes_glsl.py` around lines 90 - 92, Introduce a shared constant
(e.g., CURVE_LUT_WIDTH = 256) in comfy_extras/nodes_glsl.py and replace
hard-coded 256 occurrences in the curve tooltip text and any usages inside the
to_lut(...) implementation (and related spots around MAX_CURVES) with that
constant; update references where the LUT width is mentioned (tooltip strings
and function logic) to use CURVE_LUT_WIDTH so the value is centralized and
future changes are safe.
blueprints/.glsl/Color_Balance_15.frag (1)

17-17: Use the documented fragColor0 output pattern in the blueprint shader.

GLSLShader advertises layout(location = 0) out vec4 fragColor0; using the same form here makes this built-in shader a cleaner copy/paste example and keeps it aligned with the node’s output conventions.

♻️ Proposed cleanup
-out vec4 fragColor;
+layout(location = 0) out vec4 fragColor0;
...
-    fragColor = vec4(clamp(color, 0.0, 1.0), tex.a);
+    fragColor0 = vec4(clamp(color, 0.0, 1.0), tex.a);

Also applies to: 89-89

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@blueprints/.glsl/Color_Balance_15.frag` at line 17, The shader uses the
generic output symbol "out vec4 fragColor" but the project convention and
GLSLShader docs use "layout(location = 0) out vec4 fragColor0"; update the
fragment outputs (e.g., the declaration at "out vec4 fragColor" and the other
occurrence) to "layout(location = 0) out vec4 fragColor0" so the built-in shader
matches the node output convention and is copy/paste friendly with GLSLShader.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@blueprints/.glsl/Color_Balance_15.frag`:
- Line 17: The shader uses the generic output symbol "out vec4 fragColor" but
the project convention and GLSLShader docs use "layout(location = 0) out vec4
fragColor0"; update the fragment outputs (e.g., the declaration at "out vec4
fragColor" and the other occurrence) to "layout(location = 0) out vec4
fragColor0" so the built-in shader matches the node output convention and is
copy/paste friendly with GLSLShader.

In `@comfy_extras/nodes_glsl.py`:
- Around line 90-92: Introduce a shared constant (e.g., CURVE_LUT_WIDTH = 256)
in comfy_extras/nodes_glsl.py and replace hard-coded 256 occurrences in the
curve tooltip text and any usages inside the to_lut(...) implementation (and
related spots around MAX_CURVES) with that constant; update references where the
LUT width is mentioned (tooltip strings and function logic) to use
CURVE_LUT_WIDTH so the value is centralized and future changes are safe.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 55feba84-29ec-492c-9cbe-d57ffa0259f2

📥 Commits

Reviewing files that changed from the base of the PR and between 74c021f and c5c284e.

📒 Files selected for processing (5)
  • blueprints/.glsl/Color_Balance_15.frag
  • blueprints/.glsl/Color_Curves_8.frag
  • blueprints/Color Balance.json
  • blueprints/Color Curves.json
  • comfy_extras/nodes_glsl.py
✅ Files skipped from review due to trivial changes (2)
  • blueprints/Color Curves.json
  • blueprints/Color Balance.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • blueprints/.glsl/Color_Curves_8.frag

Copy link
Copy Markdown
Member

@pythongosssss pythongosssss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@pythongosssss pythongosssss removed their assignment Mar 26, 2026
Comment thread comfy_extras/nodes_glsl.py Outdated
@jtydhr88 jtydhr88 merged commit 1dc64f3 into master Mar 27, 2026
21 checks passed
@jtydhr88 jtydhr88 deleted the feat/glsl-improve branch March 27, 2026 01:45
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.

4 participants