Skip to content

Add support for adjusting color intensity with Color::apply_intensity method#1264

Merged
Arctis-Fireblight merged 1 commit into
Redot-Engine:masterfrom
Arctis-Fireblight:add-color-intensity
May 20, 2026
Merged

Add support for adjusting color intensity with Color::apply_intensity method#1264
Arctis-Fireblight merged 1 commit into
Redot-Engine:masterfrom
Arctis-Fireblight:add-color-intensity

Conversation

@Arctis-Fireblight
Copy link
Copy Markdown
Contributor

@Arctis-Fireblight Arctis-Fireblight commented May 20, 2026

Added Color::apply_intensity() method to allow applying an intensity value directly to a Color like can be done with the Color Picker.

Closes Redot-Engine/redot-proposals#117

I added bindings for both GDScript and C#, note that the C# variant is SIMD optimized.

Someone else is welcome to add SSE and NEON intrinsics for the C++ version later on.

Summary by CodeRabbit

  • New Features

    • Added a color intensity adjustment to Color (scales RGB by a power-of-two factor; RGB clamped to [0.0,1.0]; alpha preserved).
    • Exposed equivalent intensity-adjustment method in the C# Color API.
  • Documentation

    • Updated Color class docs to include the new intensity-adjustment method.
  • Chores

    • Added a rule to ignore the /.junie/ directory.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 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: 85e91a9f-1530-469d-b460-b9df46bb957e

📥 Commits

Reviewing files that changed from the base of the PR and between 259fa3a and f9ba7ba.

📒 Files selected for processing (6)
  • .gitignore
  • core/math/color.cpp
  • core/math/color.h
  • core/variant/variant_call.cpp
  • doc/classes/Color.xml
  • modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs
✅ Files skipped from review due to trivial changes (1)
  • .gitignore

Walkthrough

This PR implements the apply_intensity method on the Color type across C++, the variant system, C# bindings, and documentation. The method scales RGB channels by 2^intensity with clamping and early-exit optimization, making it available programmatically in GDScript and C#.

Changes

Color Intensity Application Method

Layer / File(s) Summary
C++ method declaration and implementation
core/math/color.h, core/math/color.cpp
Color::apply_intensity(float) declared and implemented to multiply RGB by 2^intensity, clamp to [0,1], and early-return on near-zero input; alpha unchanged.
Variant system integration
core/variant/variant_call.cpp
Built-in method apply_intensity registered in math methods to expose the Color method via the variant call mechanism.
C# binding with unsafe optimization
modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs
ApplyIntensity(float) added as an unsafe, aggressively inlined method using a Vec3 pointer cast to scale RGB and Vec3.Clamp to clamp channels.
User documentation
doc/classes/Color.xml
New method entry documents intensity adjustment using a 2^intensity multiplier and clamping RGB to [0.0, 1.0].

Sequence Diagram(s)

sequenceDiagram
  participant GDScript
  participant VariantSystem
  participant ColorCpp
  GDScript->>VariantSystem: Color.apply_intensity(intensity)
  VariantSystem->>ColorCpp: invoke Color::apply_intensity(float)
  ColorCpp-->>VariantSystem: Color (RGB scaled, alpha preserved)
  VariantSystem-->>GDScript: return Color
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

  • #117: Adds programmatic access to Color intensity — this PR implements apply_intensity across C++, bindings, and docs matching that objective.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a Color::apply_intensity method to adjust color intensity.
Linked Issues check ✅ Passed The PR implements programmatic access to intensity via apply_intensity method [#117], fulfilling the core request for a method that computes and applies intensity using the same formula as the inspector.
Out of Scope Changes check ✅ Passed All changes directly support the apply_intensity feature: header/implementation declarations, GDScript bindings, C# SIMD-optimized binding, documentation, and .gitignore update are all in-scope.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@Arctis-Fireblight
Copy link
Copy Markdown
Contributor Author

On second thought, after rereviewing the docs for Color, this implementation doesnt really match the existing APIs very well. Methods for Color tend to return a new one rather than modifying the original, suggesting some form of immutability is intended.

I am going to refactor accordingly.

@Arctis-Fireblight Arctis-Fireblight force-pushed the add-color-intensity branch 2 times, most recently from a500f7f to 259fa3a Compare May 20, 2026 06:23
@Arctis-Fireblight Arctis-Fireblight enabled auto-merge (rebase) May 20, 2026 06:25
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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.gitignore:
- Line 394: The .gitignore currently contains an unrelated entry "/.junie/"
which should be removed or justified; either delete the "/.junie/" line from
.gitignore (preferred) or, if you intend it to be a shared ignore, add a short
justification to the commit message and keep it, or move the ignore to a
developer-local exclude by adding it to .git/info/exclude instead; update the PR
accordingly and ensure the change is separate from the Color::apply_intensity
work if retained.

In `@doc/classes/Color.xml`:
- Around line 101-109: The documentation for Color::apply_intensity is
incorrect: update the <method name="apply_intensity"> entry to reflect the real
API by changing the return type from void to Color (replace <return type="void"
/> with <return type="Color" />) and mark the method as const (add the
appropriate const="true" attribute on the <method> tag or equivalent per the doc
schema); keep the existing <param name="intensity" type="float" /> and
description as-is.
🪄 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: 1d41a0c1-9e0d-484a-9de6-6159eb36a2b9

📥 Commits

Reviewing files that changed from the base of the PR and between 9d10d39 and 259fa3a.

📒 Files selected for processing (6)
  • .gitignore
  • core/math/color.cpp
  • core/math/color.h
  • core/variant/variant_call.cpp
  • doc/classes/Color.xml
  • modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs

Comment thread .gitignore Outdated
Comment thread doc/classes/Color.xml
Copy link
Copy Markdown

@OldDev78 OldDev78 left a comment

Choose a reason for hiding this comment

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

"Apply" implies that an absolute value is set, but that's not what apply_intensity does. I would personally use the verb "adjust" instead.

@Arctis-Fireblight Arctis-Fireblight merged commit a09e6a0 into Redot-Engine:master May 20, 2026
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add getter/setter for intensity on Color

2 participants