Shaders in their natural habitat. episode 1 April 3, 2012 at 10:37 pm

Feels like ions of years have past since I wrote some´ here (shame on me for being such a lazy bum) - but finally…

First of all, lotsa things changed during the last half year. Flash is deadehhhrrrr not so dead yet, HTML5 becomes the superperformant ‘jack of all trades device’ (oh yeah!) and WebGL runs on the IE (NOT). But seriously, personally I decided to give it a try and going freelance with my pet subject… a.k.a taking client-orders of projects that are in the need of Shaders (gimme gimme - frank [at] prinzipiell [dot] com).

Programming ‘just’ Shaders, wtf !!! (you´d almost think…)

But believe it or not, nowadays, it´s hardly not possible to imagine 3D-Engines/Games, programs or projects without the use of a single Shader. A Shader… what is it? To put it simply: Shaders are simple programs that describe the traits of either a vertex or a pixel (fragments). Shaders are used to program the graphics processing unit (GPU) programmable rendering pipeline and are used to primarily calculate rendering effects on graphics hardware with a high degree of flexibility.

Fair enough, but lets specify a little scope of application: Back in the good old days graphics were done in software (Hello Flash10). This might be flexible as well, but is not really performant and not very efficient because the fixed pipeline is rather limited. Something as simple as Phong-Shading already requires a shader (the shading capabilities of the fixed pipeline end with Gouraud-Shading). The possibilities that open up with shaders are huge. Some of them are: better shadowing-techniques, ambient-occlusion, normal-mapping, etc. … in other words and to say it exaggerated (!!!) modern 3D/2D-Engines/Games would look a bit lame (not to say like crap) without Shaders.

In my case, when I´ve some spare time left, I like to program more ‘experimental’ stuff with Shaders. Sound-reactive visualizations driven by WebGL f.e., like that little thingy here:

Artificial
Launch
(needs an WebGL enabled browser)

Or image processing stuff by combining Flash and Pixel Bender (Adobe´s ‘almost’ on GPU but in case Flash <11 on CPU shading solution):

big-ass Voronoi via Pixel Bender
Launch

Usually I don´t care for the language in which a Shader must be programmed (GLSL, HLSL, Pixel Bender shizzl or Assembler, sorry, I meant AGAL assembly source code for the use with Flash11), because it all depends on the target environment. When it comes to offline tasks, there are two top dogs to go for: The official OpenGL and OpenGL ES shading language is GLSL (OpenGL Shading Language), and the official Direct3D shading language is HLSL (High Level Shader Language). In case of online-usages for the internet, you can program GLSL based Shaders via WebGL for example… and, “um, errrrr…”, you could use Flash as a weapon of choice which now has GPU acceleration too (thank you Adobe, by nature the average Flash Developer likes to deal with Assembler code…).

So, “Yes M´am…”  Shaders for 3D stuff and games, but when it comes to ‘real’ projects, Shaders can be more than helpful too, doing all that nifty tasks that need performance and speed. As an example, the ‘Samsung Notassocampaign I was envolved in last winter. The nice people from the Amsterdam based agency Code D’Azur contacted me to write a bunch of Pixel Bender-based plugins to use with Flash for that project, that will do all the heavy and time-critical image processing stuff: Like automated face detection, automated cutting out detected faces from the image´s background and transform every single copy into a unique piece of art (kinda). Donkey work(!), ´cause cutting out faces automatically by preventing as much face-details as you can, a.k.a hairs, contours, neck a.s.o is not trivial at all, and doing this in Flash10 Pixel Bender non-GPU-accelerated truely IS madness… but in the end, manageable! We separated the Shader-tasks into two Plugins, one to be called ‘The Scanner’, which does all the face-detection and validation whether we detected a good face-shot or not. The second Plugin I called ‘The Composer’, which does all the hard work distributed on many little single Shader tasks (like one for edge-detection, one for skin prevention, one for the actual cut-out of the face, one for contour recovery, and many more…)

You can give it a try here:

Outputs from the Notasso Composer Plugin
Launch

That´s it so far… the idea is to continue this article by giving you an extract from my last projects and works and to show the diverse usage of Shaders there. So this was ‘Episode 1‘ - up next… Shaders really like Dubstep, watch out!

Edit: Wanna see and know more about Shaders? Me is doing a session at upcoming ‘Beyond Tellerrand‘ conference in Cologne (is the place to be) bringing along all new fresh stuff and experiments, so maybe see you there…

*Resources: http://tinyurl.com/c67sn8m & http://en.wikipedia.org/wiki/Shader

Beatbox. October 31, 2011 at 12:49 pm

Busy days these days - filled with working on lots of exciting projects & ideas for the last weeks. One of these projects is another full visualization of an Dubstep tune (the realization of the 1st tune I showed you as realtime demo at this years Flash on the beach during my session) running in realtime. Being quite happy with my result for the tune, the record label once again gave me the freedom of developing the whole visual set for the second tune on my own *muhahahaha* - so I´ve the total freedom to go for every form, color, structure & stuff I can imagine. Simply amazing, but whilst doing all this wonderful projects the reverse of the medal is, you simply got so less time to decouple little snippets and experiments to post here…

True… by now: Lastly I took some time and uncoupled a snippet with a little audio-reactive shader sequence from my second tune visualization I´m currently working on, to test it separately. Best practice to test several options and possibilities and most perfect to use it as blog-post and sign of life here!

Well, by knowing my work you probably won´t wonder that it´s all about raymarching and deforming/displacing implicit volumes and surfaces again. Btw., want to dig deeper into this  dark matter? Inigo Quilez released a brilliant article with all the basic info´s you need to get started. But for now - lets take some WebGL and  get this little audio-reactive thingy going…

Achtung!!! May take a bit to load the sound first…

Beatbox
Launch
Side note: Best viewed in Chrome, Firefox will do as well but takes ages to validate the shader…

What else, what else… hmmm… hell yeah - just got invited to once again speak at FITC Amsterdam 2012, be sure I´ll come there with a new session topic (called: Highly Illogical) bringing along all the new FP11 & WebGL stuff I´m working on right now. ‘Early Birdies‘ are already on sale, so be quick and see you there…
 

Does not compute. August 3, 2011 at 10:39 am

Phew! There´s nothing more frustrating if thinks don´t work out the way you expect ´em to. Seems that lastly anyone but me was able to use this little piece of code written in Python by Mr. Doob right from the start. All I got by trying to run it, were tons of error-messages whilst compiling. But actually this script is very handy for effectively ‘analyzing’ audio-files for the use of then syncing them f.e. via WebGL. So lets quickly update this few lines of magic for the use with Python 3 (which I´ve installed) instead of Python 2 (Mr. Doob´s actual code is based on it). Meaning kick out xrange and replace by range and set brackets when using print(). And, most important if you don´t want to end up like me just having half a brain - check the file´s encoding before wondering while it´s still not working (or just be lazy and download the updated code here)… Hereafter, assumed you already have Python installed on your machine, open Windows command prompt, switch to your projects folder and simply execute audio.py like this:

Once you got this running lets leave this bone dry parts and switch over to the more exciting visual fun parts - meaning let´s do some with our just received audio informations and write some audio driven stuff in WebGL. As for instance following little thingy I programmed last night and called it cause of lacking a better word ‘Strange Lattice‘.

Strange Lattice
Launch
(your browser needs to support WebGL!)

I know - I know, some of you still refuse to update your system having an up to date browser that supports proper and sexy WebGL like Chrome or Firefox. All right, uploaded a video of this experiment to my vimeo account as well.

That´s it - enjoy!

!!! Edit: Updated shader for the use with Chrome Canary, but should as well execute on Chrome 12 + 13, Firefox & Safari 5.1

Bending basic volumes. July 21, 2011 at 1:30 pm

As this years Flash on the beach is coming closer, it´s about time to finalize my latest stuff and experiments for my upcoming session (… ‘and hell yeah!’, I got lots of yet unpublished things & demos to show this time). In doing so there´s lot of snippets and try-outs that I just used as tests to get certain results or insights and that didn´t make it any further.

Including following little snippet which I just developed to test possible maximum speed of combining Flash10 + Pixel Bender to use for raymarching a set of basic volumes like: a torus, cubes, spheres and cylinders (all of whom formulas to create ´em can be found here). Keep in mind that prementioned combination (Flash10/Pixel Bender) is not pretty well known for it´s supersonic speed ´cause of not having GPU acceleration, so I was quite sceptic of what I could probably tease out there.

But, surprise surprise!!! …gettig it all up and running by having >55FPS on average was a big ‘aha moment’ that I didn´t expect AT ALL! This was even better then I ever expected - so I took this little test as a basis for developing a demo which will first be shown at forthcoming FOTB (…interested? Better get your ticket before last ‘Early Birds’ are out of stock).

Need an appetiser? Bon appétit… (loading the audio first of all  may take a little while)

Bending basic volumes
Launch
(origin size)

Launch (fullscreen)
 
Well, like a said before - this is probably my last post before FOTB because I´ll now take my time to finalize the demos and experiments for my talk - so, see you there!

Fog me, fog you! June 15, 2011 at 11:44 am

After I released ‘Implicit Reactions‘ a week ago, I decided to stick with  WebGL based raymarching synced to audio a bit longer and keep it rolling. There are still so many things to explore in this field, and while I was thinking of what my possible next steps could be, I remembered this GPU Gems article. I think most of you know of Perlin Noise which results from professor Ken Perlin, due to the fact it´s a ready to use build in function in Flash. And Perlin Noise is indeed a very handy function for lots of potential applications.

No need to say that Perlin Noise is heavily used for programming visual effects as well, for instance in IQ´s brilliant Leizex demo, or for generating procedural landscapes like in Elevated, a demo made by RGBA & TBC. So, gimme gimme… the logical next step for me was to implement some noise for my WebGL stuff and add it to my raymarchers. However, my evil plan was to use this noise for generating smoke-like behaviours and what should I say - I think it worked pretty good… (by strictly implementing Las´s sources & instructions from the ‘Raymarching Beginners‘ Thread which I recommended you reading a dozen times the last blogposts).

Now, by the time I´d it all working the last days I decided to write another little audio synced demo for it. Corresponding to my decision Andre Michelle just released ‘Tief Blau‘ (liked it from the start), a piece of music he created with Audiotool. Well, and after having a little chat in the small hours the setup was clear: ‘Tief Blau‘ will be used as main tune for my next demo. From where I stand now I only can say: Madness!!! What the hell has possessed me? What originally intended to be a small little tech-demo, now escalated to be a full 6 minutes demo - meaning long nights of working short of sleep.

Honestly, I must have been totally crazy, not to say nuts(!), to base a demo on Andre´s 6 minutes long track. Know what that mean? You need tons of effects. So my only solution during the past nights to cope with this task was: make, make, make…

Status quo now - The good thing: A long list of fragment shader effects featuring the music over the entire term, the bad thing: Reaching web brower´s time-limits initializing it! ;) The Solution: decouple a sneak preview of it with some effects & save the best until last… meaning - I´ll release a fully effects packed 6 minutes longplay raymarching version based on Adobe´s Molehill Flash Player in my session at Flash on the beach this year (interested? Better be there…)

Enough talk & ‘Achtung!!!‘, it´s like I said - the whole demo needs some time getting initialized by the browser! On average ~18 secs running on Google Chrome, compared to ~1.30 secs with Firefox (holy cow! How come @Firefox ? …) So Google Chrome is my weapon of choice for running/viewing this!

But for now - let´s make some noise for the next 6 minutes…

Fog.Me demo
Launch
(Have patience whilst initializing - best viewed in Google Chrome!)

And here´s a video of the whole demo for those of you not running a modern web browser yet (for whatever reason… ;) ).

Up next: relaxing a bit…

Edit: Las - hope to have put this right…
 

Implicit Reactions. June 6, 2011 at 10:18 am

Between ourselves: I honestly can say, I´ve never ever had such as strange days as I had the last two weeks! Why? I terribly totally lost focus on things I originally planned to do, just to run into some weird distractions that utterly gone wrong, which I now résumé as a great experience that brought me back better than before to what I wanted to do in the first place…

Anyway, to make a long story short, I´m back on track now, working on several new stuff, so what´s the news? A few weeks ago Stefan Wagner took some of my WebGL raymarching examples and synced ´em to audio. Visually a pure blast, I liked it a lot (still do!), and decided to dig deeper into that topic. The idea: Let´s create more complex raymarched forms that react on synced audio, constantly changing surface and colour. So consequent the task was: Finding interesting, sublime and pleasing looking distance field formulas to compute this forms. And well, exploring distance field formulas and find unique forms is not as easy as you might think, but that is what I intended to do in the first place.

However, like I said, started, lost focus, totally got distracted, now back on track and finally got 1st results, which I like to share with you in a tick. ‘Implicit Reactions‘ is a first early release of a demo I´m now working on for upcoming Flash on the beach in September. But at this moment in time, and coming right back from a meeting in London, I´m totally stoked to say that this demo might come even more into general use as I ever expected. Curious? I´m sorry to say that this was the only rumour I´m allowed to spread on that news. I guess you all have to come to Flash on the beach and I´ll tell and show you more about it within my session.

For now - Implicit Reactions, early release studies…

Implicit Reactions
Launch
(opens in Fullscreen, takes a bit to preload audio, enjoy!)

To make this more worthwhile for all of you not having an up to date browser that supports proper and sexy WebGL I uploaded two videos on my vimeo account. The 1st one is a recording of ‘Implicit Reactions‘ and goes here, the 2nd video shows my ‘Adaptive Waves‘ Flash/Alchemy port from Karsten Schmidt´s incredible great Processing origin (got lots of mails to show that again after last FOTB 2010).

Lastly, all in all - enjoy!

Blobsphere. May 15, 2011 at 4:26 pm

…or the like, that´s what you get if you create patterns on a sphere, zoom into and point the camera at it! Bygone times I was a bit too quiet  at this place, but finally I found some time to again start with working out new ideas and snippets.

This… plus I´m working on a new demo right now for my next talk at upcoming ‘Flash on the beach - conference‘ this September, which I´m already super-excitedly looking forward to!

Well, as I mentioned already, ‘Blobsphere‘ is an odd self-given titel for a little pattern-experiment thats projected onto a sphere. We have a lightsource and bump as parameters to modify and play with. Unfortunately this whole piece wouldn´t run by programming it in Flash only, but thanks to Pixel Bender, and a nifty little trick for optimizing the bump-mapping,  we now can run that ‘baby’ on a resolution of 800×600 pixels. Yummy! ;)

Stop talking, Frank? Ok, here you go:

Blobsphere
Launch

So, until September, still lots of things and ideas to work on for me and my FOTB session, but tickets are already on sale and John once again managed to arrange a great line-up of speakers, so go and get yours as long as prices are low! See you at least in Brighton…
 

Ray marching the distance. March 22, 2011 at 10:46 am

Being right back from FITC Amsterdam and with an eye toward my upcoming talk at the FFK Cologne 2011 conference, I finally found some time the last days to get my teeth into ‘ray marching’ (ray tracing done in discrete steps) once again. It was about time to explore and modify some new or different distance field formulas.

Based on my first ‘Raymarching article‘ I now intended to experiment with various distance field formulas and see what beauty may come to light by applying them. ‘Distance fields’, never heared? Ok, put simply, distance fields provide minimum distances to any surface in a scene from any point. As a result out of this, you can use distance fields as a look up for your rays position and step at the minimum of the returned distance in its direction before a new look up is required. The key thereby lies in defining a distance field cause it offers you the freedom to shape an entire implicit volume or surface out of it. Cool?

Gee, damn cool! Just have a look at Bluflame´s ‘Lunaquatic‘ or Youth Uprising´s 4k ‘Muon Baryon‘. But what´s the catch? Let´s face it. Because when it comes to calculate distance fields, there is the need of using lots of mathematic functions like sin() and cos(), so doing this with Flash might not be your best idea ever. But to say it in advance, I went for a pure AS3 attempt as well, of which more later…

There´s another solution that´s not far to seek by using WebGL GLSL shaders (like i did here). So this time I tried diverse formulas for my distance field and added some more values to the process. For instance, by simply clicking on the generated output image, you can now square the entire field or switch back to the normal view as you like.

square my distance
Launch
(You need a modern WebGL enabled browser like Google Chrome 9+ or Firefox 4+)

And like I hinted before, I was up for coding an AS3 only based raymarcher as well. In the final analysis I must admit that this version is nothing more just like a proof of concept, as it is commonly known that too much of Math.sin() and Math.cos() or Math.sqrt() means FlashPlayer.sucks()! So it´s only logical that you can´t go for any too advanced distance field calculations at all, but still it´s fun, so here we go…

AS3 only raymarching a simple distance field
Launch

Lastly… ‘Phew,’ I can hardly wait to show you some very nice Pixel Bender, Alchemy and Molehill stuff I prepared for my upcoming FFK Cologne 2011 talk, and in the meantime, feel free to download the sources and march into the distance as you like!

All right, see you at FFK Cologne in a few weeks or maybe before that at upcoming Geekybynature conference in New York next week? Anyway, enjoy!
 

Raymarching February 21, 2011 at 6:05 pm

The recent days I had some time to  tinker with WebGL, and once again, it´s really highly enjoyable being able to write GLSL based shader effects without caring about performance too much. Therefore I decided to take some stuff I initially prepared for my upcoming FITC Amsterdam talk but that didn´t make it in my new session (RealTimeHard) by some reason, and write its GLSL equivalent.

But at first, ‘ray marching’, what is this all about? Well, using the ‘ray marching + distance fields’ technique is like the newest hot potato finding its way from the Demoscene to our beloved Flash for example. If you want to get started and get an idea of the concept behind all that, I recommend reading following article first (and maybe the concept behind distance fields called sphere tracing from John C. Hart). Beyond that, there are tons of threads and articles out there dealing with that topic, but the ‘Raymarching Beginners‘ as well as the ‘Raymarching Toolbox‘ threads are fantastic pouet.net sources to get started with.

Enough talk: Let us first enjoy how beautiful this technique looks in action, for example in FRequency´s 4k intro ‘potatro‘ or in ‘cdak‘ a 4k intro by Quite and Orange. And as I said, ray marching looks good in Flash too, like in this Raymarcher using Pixelbender from Ralph Hauwert. So being charged with all that inspiration, here are my little contributions in this field (yet again using Mr. Doob´s handy WebGL sandbox):

raymarcher#1
Launch

raymarcher#2
Launch

raymarcher#3
Launch

Feel free to grab the sourcecodes (which´s located within the HTML templates) and modify at your pleasure. Still interested? More to come in my upcoming FITC Amsterdam and FFK Cologne 2011 talks. See you!
 

WebGL excursion. February 7, 2011 at 2:48 pm

After WebGL was implemented and activated by default in the newest update of Google Chrome 9 last week, and even Firefox 4.0 Beta 9 runs it as well (and a Safari Nightly build too), I decided that now is the time to give it a try. As for me for now the most exciting feature to play around with is GLSL based shader programming. Yummy!

In case you want immidiately start programming your own Fragment- and Vertex-shaders too, Mr. Doob has written a very handy sandbox with the basic WebGL initialisation code. Most helpful if you don´t want to waste time on that and just concentrate on coding your shaders. So here are my results to date…
 

Lattice
Launch

 

And…

Synthetic berries
Launch

The lesson is clear: Using WebGL/GLSL is pure fun and I think it´s definitely worth playing around with it, but as I expect clients to be overcautious making use of this new possibilities, there´s way enough space for Flash projects in the future.

Edit: There´s a fullscreen version of the ‘Lattice’ - feel free to start it at your own risk! Warning!!! It may shut down your system.