GLSL Fragment Shaders
Community Forums/Showcase/GLSL Fragment Shaders
| ||
Inspired by Iñigo Quílez’s shader toy http://www.iquilezles.org/apps/shadertoy/ (warning - needs compatible browser + GPU and can lock up your PC), I’ve written a blitzmax app that can load and display GLSL fragment shaders with a little more success and efficiency than WebGL was having with my browser. Included are 38 demo shaders. All credit for the shaders goes to Iñigo Quílez and his demoscene contributors. I’ve only managed to write one so far. I've so far been unable to test this on Windows (NC10 no go) so would be interested to hear if it works OK. Press 'V' to toggle vsync to see what FPS can be achieved. I've managed to test it on a Macbook Pro 15" AMD Radeon HD 6750M (doesn’t seem to like Mandlebulb, To The Road A Ribbon or Slisesix but 35 others worked fine and fast). Also tested on a slightly older Macbook Pro NVIDIA GeForce 9400M which worked on all 38 but had low framerates on the more involved ray traced shaders. Note that depending on your GPU hardware and OS drivers you may have varying degrees of success with this app. It would be interesting to know just how compatible GLSL shaders currently are as I'm considering using them in some future software. Download Windows http://snafoo.net/downloads/ShaderViewer_0.1_win.zip Mac OSX (x86) http://snafoo.net/downloads/ShaderViewer_0.1.dmg Some screenies : ![]() ![]() Blog post : http://spungifungi.wordpress.com/2011/04/22/glsl-shader-fun/ Last edited 2011 |
| ||
Love it, really impressive, would love to see the source :) I'd love to wrap my head round shaders at some point, and include them in some way with TimielineFX. Runs fine here on my MacBook nVidia 9400M, Good job! |
| ||
Pretty cool! Most of the effects gave me fps around 1500+ |
| ||
Blitzmax source is available here - http://snafoo.net/downloads/ShaderViewer_0.1_src.zip Used a module glsl.bmx to do the shader compilation and openGL ARB bits so my bit is mostly fluff around that. The clever stuff is in the shaders themselves. Press <spacebar> to view the shader source. Here's a simple fragment shader example. Given a 800x600 quad facing the screen, the following would get called 800x600 times, once per pixel as if it were inside a for x = 0 to 799 ; for y = 0 to 599 ; loop. gl_FragCoord.xy is the x,y coordinate of the pixel in question and to change the pixel colour you just assign a rgba value to gl_FragColor vec2, vec3 and vec4 are just simple data types encapsulating a list of 2,3 & 4 floats respectively, of which their individual components can be referenced with .x , .y or .z or combinations of those. uniform vec2 resolution; // eg (800.0,600.0) passed in by application uniform sampler2D tex0; void main(void) { // pixel xy position 0,0 -> 1,1 vec2 p = gl_FragCoord.xy / resolution.xy; // get pixel color from texture bound to mesh vec3 colour = texture2D(tex0,p).rgb; // set pixel color gl_FragColor = vec4(1.0-colour,1.0); } I find the best way to learn is simply to try changing things and see what happens. Also look at all the other examples and try and work out how they do it. Iñigo Quílez’s shader toy has a handy help page here - http://www.iquilezles.org/apps/shadertoy/help.html Hope that helps. Last edited 2011 |
| ||
Excellent, thanks for the example, really helpful! |
| ||
Cool, some examples look very good. |
| ||
Hiya, I get a blank fullscreen that doesnt do anything. I need to use CTRL-ALT-DEL to then exit the frozen program. Sony Vaio VGN-FW31M This machine is more than capable of running this kind of app but it crashes for some reason? Shame, because it looks really cool. |
| ||
These are pretty cool, I had fun with it. |
| ||
@col Hmm. Interesting. That spec machine shouldn't have any problems as far as I can see. I think the GPU for that model is an ATI Mobility Radeon HD 3470 which looks quite capable. Can you see any of the demos here? : http://www.iquilezles.org/apps/shadertoy/ If so then I'd be even more puzzled. If not, then maybe an OS OpenGL/GLSL version issue or failing that, my shoddy code :) ? |
| ||
@tesuji Hi again. I've visited the webpage and it says that i need a WebGL compatible browser ( I use Opera ). I downloaded the latest version of Opera ( 11.5 ) and it said the same. After downloading the latest version of Chrome ( 11.0.696.57 ), it works perfect in Chrome. Yes, the GPU is quite good for a laptop, full support of the SM3.0 in DirectX and OpenGL. Not the fastest gpu in the world, but by no means is it slow, and its still capable of giving some of the slighter older cards a run for their money :p I use it as my development machine. Sooooo..... I guess I've just given you a 'head scratcher' then ? ;-) Last edited 2011 |
| ||
Runs most shaders (except the intensive ones) on: Intel G41 (Stock Dell), Win7, Intel Quad core. Last edited 2011 |
| ||
I'm on my laptop, at the moment. All the b_ shaders ran at full size, 60+ FPS. Most of the c_ shaders made it to around 20%, two of them made it to full size but only ran at about 30 FPS. The mandelbulb shader caused an access violation error. Laptop specs: Processor: AMD Athlon X2 P340 GPU: ATI Mobility Radeon 4250 HD RAM: 4 gigs DDR3 |