Jump to content




Shader-Style Graphics - I.e., Pretty Lights!


  • You cannot reply to this topic
7 replies to this topic

#1 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 10 September 2015 - 07:15 PM

Link
pastebin get z4kWdiKh gfx

This graphics library is for creating fragment shader-style programs. Fragment shaders are programs which take as input a position on the screen and output a color for that pixel. Now, in ComputerCraft, we normally only have a 16 color palette to use, or maybe more if you consider some dithering techniques. However, this API allows you to setup your color palette, and it automatically maps the RGB colorspace to the palette you give it. This just means that you can talk about colors using RGB components and the rest gets handled by the color mapping algorithm.

Well that's nice, but what can you actually use this for? I think in this case, screenshots (and video!) work better than words.

Media
Spoiler

I'm going to add proper documentation for this soon, but for now, this well-commented test file should help anyone who wants to write some shaders. pastebin get Hzg5cCRF test

Let me know if you find this useful!

#2 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 10 September 2015 - 07:57 PM

I like your RGB to Lua converter :).

Seriously though, wow. Sure, it isn't the most complicated thing in the world but it looks awesome. I'm seeing the potential for some new screensavers here :).

#3 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 10 September 2015 - 11:56 PM

After updating the API (reflected in the paste, btw) with some more GLSL functions, I was able to port over a pretty looking shader I found on shadertoy.
Mine: http://yevano.me/shr...10_19-43-29.mp4
(Code)
Spoiler

Original: https://www.shadertoy.com/view/lsSGzy

Now that would make a pretty nice screensaver. :)

#4 ElvishJerricco

  • Members
  • 803 posts

Posted 11 September 2015 - 04:48 AM

Wow, great work man. I'd always wondered about something like this. Didn't think the results could be this good.

#5 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 22 December 2015 - 08:58 AM

Because of the 1.7 update, sub-cell rendering with square pixels is now possible! Therefore, I implemented render strategies. Here are all the strategies:

NOTE: STRATEGY_TWO_CELL is not implemented yet.

STRATEGY_FULL_CELL: Renders each color result into a full cell.

Posted Image

Pros:
  • Can render with text, allowing one to implement some effects and even faked dithering to some extent.
Cons:
  • Although the shader can be rendered uniformly by using getUnstretchedResolution, the non-square cells are somewhat noticeable.
  • Low resolution. 51x19 on a standard screen.
STRATEGY_HEX_CELL: Combines six color results into one cell using special characters. If more than two different CC colors are converted from the color results, only the 2 most prevalent colors will be used, and results using a different color will be replaced with the most prevalent color.

Posted Image

Pros:
  • Square pixels.
  • Higher resolution. 102x57 on a standard screen. Interestingly, this changes the pixel width and height ratio from 51:19 to 34:19.
Cons:
  • Since only two colors can be displayed per cell, some quality may be lost.
STRATEGY_TWO_CELL: Uses the same approach as STRATEGY_HEX_CELL, except that cells are divided up into thirds. If the cell is on an odd row (starting at row 1), the top two thirds will be used for a whole color result and the bottom third will be used for the top half of the color result on the next pixel data row. Else, the inverse occurs.

Pros:
  • Square pixels.
  • (Slightly) Higher resolution: 51x28
  • Doesn't lose colors due to the two color per cell limit.
Cons:
  • If height resolution is not a multiple of 3, cells on the top or bottom will only be partially used.
Note that when using higher screen resolutions you may need to use a higher color palette resolution to avoid losing quality. While 16x16x16 works okay for full cell rendering, higher values should be used for sub-cell strategies. 32x32x32 usually looks good, and 64x64x64 should look great no matter what.

Pastebin files have been updated.
pastebin get z4kWdiKh gfx
pastebin get Hzg5cCRF test

Edited by Yevano, 22 December 2015 - 10:31 AM.


#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 22 December 2015 - 10:17 AM

Lookin' good, but shouldn't two-cell have a vertical resolution of 28?

#7 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 22 December 2015 - 10:30 AM

View PostBomb Bloke, on 22 December 2015 - 10:17 AM, said:

Lookin' good, but shouldn't two-cell have a vertical resolution of 28?

Ah yep good catch.

#8 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 22 December 2015 - 11:09 AM

What can this be used for? Background?

Also, aren't shaders used as a filter? Like they modify certain pixels in a certain way.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users