Skip to content

Conversation

@AlaricBaraou
Copy link
Contributor

Solve issue #353

The Problem

When using BatchedText in a Three.js project with ColorManagement.enabled (the default in recent versions ), all text colors appear washed out or significantly lighter than intended.

This is caused by a color space mismatch. The Three.js renderer operates in a linear color space, but BatchedText was packing sRGB color values into its data texture and unpacking them in the shader without converting them to linear. The renderer would then treat these sRGB values as if they were linear, leading to an incorrect final output after gamma correction was applied.

The Solution

This PR updates the BatchedText derived material to be fully aware of Three.js's color management system.

Conditional sRGB-to-Linear Conversion: The troikaFloatToColor GLSL function now checks if ColorManagement.enabled is true at material creation time.

If true, it converts the unpacked sRGB color into the linear color space using the standard sRGBTransferEOTF function.

If false, it retains the original behavior for legacy sRGB workflows.

The sRGBTransferEOTF function from three.js has been added directly to the vertex shader definitions. This ensures the fix works reliably across all Three.js versions.

Correct Normalization: The 8-bit color channel normalization has been corrected from division by 256.0 to the mathematically correct 255.0.

Result

With this change, BatchedText now renders colors correctly in both legacy sRGB and modern linear workflows, matching the behavior of standard Text components and other Three.js objects.

Let me know if I can clarify anything.

@upisfree
Copy link

Very cool! Good job!

@lojjic
Copy link
Collaborator

lojjic commented Sep 10, 2025

Wonderful, thank you!!

@lojjic lojjic merged commit b6565f4 into protectwise:main Sep 10, 2025
5 checks passed
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.

3 participants