sinclairzx81 / zero

A 3D renderer written in JavaScript and rendered to the terminal.
Other
2.41k stars 143 forks source link

[Feature] Color support? #7

Closed richrd closed 4 years ago

richrd commented 4 years ago

The current demo is amazing and crazy enough in itself. Frankly looking at it, I have this certain disbelief that I'm looking at an actual terminal window with 3D graphics. That said, is there any chance to push it even further with colors? Really just wondering, awesome work already!

loganzartman commented 4 years ago

You mentioned in #5 that terminals have limited support for truecolor. While it is more challenging to detect , many of them (including Windows console in Windows 10 when ENABLE_VIRTUAL_TERMINAL_PROCESSING is set) actually do support it . Alternatively, almost any terminal will support 256 color mode, and it is fairly easy to do a rough conversion from RGB.

Sorry, I can't remember which reference I used for the color palette.

sinclairzx81 commented 4 years ago

Hi, thanks for the suggestion.

I may actually take another look at this when I next get a bit of free time. It should be possible to implement ANSI true color and just have it enabled behind a --color flag. I did run a couple of tests on this and note that performance does degrade quite a bit with the color (its a lot more buffer throughput written to the terminal), but still could be interesting for terminals that support it.

sinclairzx81 commented 4 years ago

@richrd @loganzartman

I've put a rough implementation of true color in the feature/true-color branch. It needs testing and a few more optimizations. Initial tests on windows/cygwin (without TTY) and a Linux Mint terminal seem to work alright, but there is likely room to improve performance. Running true color on Windows CMD / Powershell are completely broken by default which is expected. The GIF below is running out of a VirtualBox linux instance, framerate is about on par with the GIF (with fontsize dropped to 2)

output

I don't own a OSX device so cannot test there. Open to any feedback if either of you own a Mac. Can run out of the feature/true-color branch with the following.

# clone the project
$ git checkout feature/true-color
$ npm install
$ npm run build
$ node index --color
sinclairzx81 commented 4 years ago

Have pushed a release to npm zero-demo@0.8.5. The color support is fairly experimental, so your mileage may vary depending on the capabilities of your terminal. Can test it out with..

$ npx zero-demo@latest --color

Have fun!

richrd commented 4 years ago

Wow thanks! That's amazing! Works great on my Linux machine. I might be able to test on OSX at work. You sir are a legend :)

liamdon commented 1 year ago

Greetings from 2022! I love this project.

I thought you might like to see how well true color runs these days. This is on a Mac M1 Max, in iTerm 3.0.

https://user-images.githubusercontent.com/453578/203469426-d7ef0d46-880d-4f49-b707-6e19ce1c0df7.mp4

sinclairzx81 commented 1 year ago

@liamdon Hey thanks for sharing :D That looks like it runs pretty great!