Simple pixel shaders

BlitzMax Forums/MiniB3D Module/Simple pixel shaders

BlitzSupport(Posted 2016) [#1]
Hi all,

EDIT: I'm using this BMX-NG setup on Windows 7 64-bit, which includes OpenB3D/Wrapper: BlitzMaxNG_077.7z on Google Drive [86.4 MB]. In theory, you can extract anywhere and use it. In practice, however... ?



Just posting this in case it helps anyone else who wants to play with a simple pixel shader. I realise that some parts of the shader programs need future-proofing (help would be appreciated here!), but wanted to post a basic example to kick things off, since I've finally got it all working...

example.bmx



Vertex shader: basic.vert.glsl



Fragment (pixel) shader: basic.frag.glsl



Save all three files in the same folder and run the example. To play with the pixel colours, simply alter the values of pixel.r, pixel.g and pixel.b (each value ranging from 0.0 - 1.0 instead of 0 - 255) in basic.frag.glsl, as in...



Onwards to ZX Spectrum shaders, DOF and all the other toys I wanted to play with! OpenB3D and Wrapper are awesome!


BlitzSupport(Posted 2016) [#2]
Here's a set of 'proper' greyscale/grayscale algorithms (normal RGB, lightness, average, luminosity) that you can switch between via the keyboard -- the above version just used the red value for r, g and b:



example.bmx:



grey.vert.glsl:



grey.frag.glsl:




BlitzSupport(Posted 2016) [#3]
Woo-hoo, step 1 of my semi-rewritten Speccy Shader (basic colour conversion), rendered via glorious 256 x 192 texture/camera viewport!




RustyKristi(Posted 2016) [#4]
that looks nice James


BlitzSupport(Posted 2016) [#5]
Thanks, RK! Enough for tonight, though...


BlitzSupport(Posted 2016) [#6]
After many failed attempts and finally getting back to it...



Realtime ZX Spectrum shader (with attribute clash)! Turns arbitrary resolution display into 256 x 192, 8 colours (plus 8 dark variants), 1 background and one foreground colour for every 8 x 8 block, on the fly. (Doesn't take aspect ratio into account, though... yet.)

Code/media plus runnable executable (VirusTotal scan) -- no idea if/how it will run elsewhere:

http://www.hi-toro.com/blitz/speccyshader.zip

example.bmx (uses boing.png):



speccy.vert.glsl:



speccy.frag.glsl (may still be some Stupid in here):



For every pixel, the shader has to scan every 8 x 8 block of 256 x 192 texture to determine count of each of 16 colours, using highest two for background and foreground.

Still need to play about with brightness/contrast boosting of source render, but good enough for now.


col(Posted 2016) [#7]
Looks interesting.

I'm sure that pixel shader can be improved somewhat though :D
Its using a serial approach that you'd use for a cpu but gpus are parallel processors.

That would be a good exercise :O)

edit:
I can't get any of this to run on win7 x64 ng, or legacy max.
It either won't compile due to std lib errors (legacy) or I get a grey screen with 'app has stopped working' in ng ( apparently there's a heap corruption :/ )

Oh the fun :D


BlitzSupport(Posted 2016) [#8]
Wasn't sure how else to manage the reading of 8 x 8 pixels to count colours -- the problem as I see it is that for every pixel, I *must* read the 8 x 8 block it sits within, since I can't share info between each pixel's instance of the shader.

Shame it won't run -- maybe try the NG archive at the top of this thread. Does the exe fail too?


col(Posted 2016) [#9]
The archive at the top, which I would have thought to be self-contained does open the editor but when I hit compile I get 'Cannot find a valid GCC compiler' message. Shaders are shaders so I can probably get something up and running in legacy max gl, just to play with.

Off the top of my head, I was thinking of using a deferred approach... and hopefully let the rasterizer do the 8x8 colour blocks for you at the expense of rendering a quad and sampling from 2 textures.

I'll set about having a play this evening :p


BlitzSupport(Posted 2016) [#10]
I did vaguely think of using > 1 texture, though wasn't sure how exactly. The NG archive 'should' be self-contained, but... !

Be cool if you come up with a faster approach, though, as I suspect mine would be very slow on many cards... if it ran... er... would like to see a smarter way to handle it, anyway.


degac(Posted 2016) [#11]
Hi
tested the .exe - but when I press SPACE I see just a 'black' window.
Windows10 x64 AMD HD5700


Krischan(Posted 2016) [#12]
Nice examples + setup, James. Perhaps I should start playing around with GLSL, too. And you should use codeboxes for your snippets, it's easier to copy'n'paste :-D


BlitzSupport(Posted 2016) [#13]
I was going to use codeboxes, but thought that since it's not in the middle of someone else's thread, and they're meant as examples, it was better to post in full. Sort of changing my mind now, especially if you think it's easier to copy (I thought full size was easier)...

Oh, and definitely worth playing around with! Think my next job will be a depth of field shader. (I've done all this stuff in Max3D before, but none of it works now, and I've found some really dumb stuff in my old examples.)

@degac: Sorry, don't know why! Probably some sort of GLSL version thing, but with only my main PC to really test on I'm kind of stuck!


BlitzSupport(Posted 2016) [#14]
Yeah, codeboxes definitely better.