|
1 | 1 | import { Text } from "./Text.js"; |
2 | | -import { DataTexture, FloatType, RGBAFormat, Vector2, Box3, Color, DynamicDrawUsage } from "three"; |
| 2 | +import { ColorManagement, DataTexture, FloatType, RGBAFormat, Vector2, Box3, Color, DynamicDrawUsage } from "three"; |
3 | 3 | import { glyphBoundsAttrName, glyphIndexAttrName } from "./GlyphsGeometry.js"; |
4 | 4 | import { createDerivedMaterial } from "troika-three-utils"; |
5 | 5 | import { createTextDerivedMaterial } from "./TextDerivedMaterial.js"; |
@@ -425,8 +425,14 @@ function createBatchedTextMaterial (baseMaterial) { |
425 | 425 | // language=GLSL |
426 | 426 | vertexDefs: ` |
427 | 427 | uniform bool uTroikaIsOutline; |
| 428 | + // sRGB->Linear conversion function, from Three.js https://github.com/mrdoob/three.js/blob/dev/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js |
| 429 | + vec4 sRGBTransferEOTF( in vec4 value ) { |
| 430 | + return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a ); |
| 431 | + } |
428 | 432 | vec3 troikaFloatToColor(float v) { |
429 | | - return mod(floor(vec3(v / 65536.0, v / 256.0, v)), 256.0) / 256.0; |
| 433 | + vec3 srgbColor = mod(floor(vec3(v / 65536.0, v / 256.0, v)), 256.0) / 255.0; |
| 434 | + |
| 435 | + return ${ColorManagement.enabled ? 'sRGBTransferEOTF(vec4(srgbColor, 1.0)).rgb' : 'srgbColor'}; |
430 | 436 | } |
431 | 437 | `, |
432 | 438 | // language=GLSL prefix="void main() {" suffix="}" |
|
0 commit comments