question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: add character/word/line index attributes to the text geometry

See original GitHub issue

Custom shaders applied to Text instances could enable some really nice animation effects. For many of these, you’d want to treat each character/glyph independently, and for that you need something in the shader telling you which character is currently being rendered.

Theoretically gl_InstanceID could be used for this, since we use instancing for the glyph quads. And this kinda-sorta works: https://codesandbox.io/s/zealous-water-m8lzq?file=/src/index.js – but gl_InstanceID is only available in WebGL2, and it appears to be broken in ANGLE implementations when used within functions other than void main. So it’s not realistically usable for this right now.

Instead, we could add our own instance attribute, something like attribute float charIndex;, which just holds an incrementing character index. Custom shaders could then make use of that.

I’d probably want to make it an opt-in feature, something like textmesh.includeCharIndexInShader = true, just to avoid creating that extra attribute array if it isn’t needed.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:18

github_iconTop GitHub Comments

4reactions
ffdeadcommented, May 25, 2021

@lojjic Just want to express my interest in this feature 😺

4reactions
lojjiccommented, Feb 19, 2021

I’ve got lots of cleanup to do, but I have an initial POC of the above counts. Here are examples using the various index/total pairs to change color in a fragment shader:

charIndex / totalChars: Screen Shot 2021-02-18 at 7 18 56 PM

charInWordIndex / totalCharsInWord: Screen Shot 2021-02-18 at 7 19 01 PM

charInLineIndex / totalCharsInLine: Screen Shot 2021-02-18 at 7 19 08 PM

wordIndex / totalWords: (looks very similar to charIndex/totalChars in this example but there’s a subtle difference) Screen Shot 2021-02-18 at 7 19 16 PM

wordInLineIndex / totalWordsInLine: Screen Shot 2021-02-18 at 7 19 22 PM

lineIndex / totalLines: Screen Shot 2021-02-18 at 7 19 29 PM

I managed to get all the data into a max of 3 uniforms + 2 attributes, which is pretty good. I still want to make them optional.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add Attribute Index (Data Management)—ArcGIS Pro
ArcGIS geoprocessing tool that adds an attribute index to an existing table, feature class, shapefile, coverage, or attributed relationship class.
Read more >
Troika-3d-text: library for SDF text rendering - three.js forum
See Feature: add character/word/line index attributes to the text geometry · Issue #102 · protectwise/troika · GitHub.
Read more >
Arcade data expression to retrieve Z values - Esri Community
features [index] = { 'attributes': { 'dow_num': Hour(feature['creation_date']), 'elevation': text(geometry(feature).x), 'militaryhr': Text( ...
Read more >
TextPropertyExtractor | FME - Safe Software
Extracts the values of text attributes from input text geometry features. ... Adds one or more attributes to the feature and optionally assigns...
Read more >
11.4.10 Creating Spatial Indexes - MySQL :: Developer Zone
For InnoDB and MyISAM tables, MySQL can create spatial indexes using syntax ... geom (g GEOMETRY NOT NULL SRID 4326); ALTER TABLE geom...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found