Rezmason / matrix

matrix (web-based green code rain, made with love)
https://rezmason.github.io/matrix
MIT License
3.33k stars 217 forks source link

Request: Custom Strings #6

Open halcyonforever opened 2 years ago

halcyonforever commented 2 years ago

I have been tinkering with something similar but wondered if instead of all random glyphs it could pull strings from an array? That way we could incorporate live (or static) information into the falling code to make it a useful information display.

Rezmason commented 2 years ago

You know what? There are enough people who'd like this, that it's worth taking into serious consideration. Just gonna blue-sky brainstorm it.

So, first, there's some setup work to draw a texture containing an arbitrary string:

  1. extract the array of strings from the URL
  2. load Chicago.woff
  3. Wait till the font is loaded (FontFaceSet.check())
  4. Create a 2D canvas, style it with the loaded font and fallbacks, and render each unique character in the strings.
  5. Spoof an SDF by blurring them or something, this could look awful to be honest
  6. Assemble the texture

Then, the strings would need to be drawn in the grid somehow so that they're legible, but also look like they belong in the existing effect. The current rain pass uses mathematical functions to make waves of brightness roll down the cells in a column; the problem with this is, there is no actual relationship between any two cells, even if they're neighbors. They cycle their glyphs, but not in any way that guarantees any two characters appear next to one another, let alone for long enough and with other glyphs to be readable.

Maybe there could be a second compute shader that "overrides" the brightness and glyphs in a column, storing the result in a separate buffer of cells. This shader could basically scroll the strings down every column, either one after the other or on separate columns, with some gap between them. The open question would then be, what brightness would they be? Maybe they'd be the maximum of whatever brightness is specified in the rain pass, and some minimum brightness, to guarantee the whole thing is readable.

At the moment I'm tied up expanding the default glyph set to include the additions in The Matrix Resurrections, which adds about a hundred new symbols. So support for custom strings probably won't be possible until sometime in 2022. But as long as folks with strings that aren't in the Chicago typeface aren't bothered with some inconsistencies, and even though the existing project isn't optimized for displaying specific text, it's not an unreasonable request. Other projects might be able to more easily accommodate it in the meantime.

halcyonforever commented 2 years ago

That was quite a write up. Your code is much more complex than the ones I had tinkered with on this before. But none of them included the waves of lighting that would cause the rain to be altered. (or font atlases, learned all about them from reading your code)

Rezmason commented 2 years ago

I think what we're seeing is a classic technical tradeoff. I set a goal to render the glyphs and their cycling as faithfully as I could to what I'd seen in the trilogy, and made a series of decisions in pursuit of that goal which made the project progressively less capable of displaying dynamic information.

Fortunately, while I'll take a while to get around to experimenting with this particular idea, there are plenty of other interpretations of the code rain on Github that may be better suited for the task!

MWH-Rookie commented 2 years ago

Still, this is a great idea!

LEMONed commented 2 years ago

emojis would be great.